Re: [FFmpeg-devel] [PATCH 2/4] libavdevice/decklink: add support for -sources and -sinks arguments

2017-10-04 Thread Devin Heitmueller

> On Sep 30, 2017, at 4:02 PM, Marton Balint  wrote:
> 
> 
> 
> On Tue, 26 Sep 2017, Devin Heitmueller wrote:
> 
>> Add support for enumerating the sources/sinks via the ffmpeg
>> command line options, as opposed to having to create a real pipeline
>> and use the "-list_devices" option which does exit() after dumping
>> out the options.
>> 
>> Note that this patch preserves the existing "-list_devices" option,
>> but now shares common code for the actual enumeration.
>> 
>> Signed-off-by: Devin Heitmueller 
>> ---
>> libavdevice/decklink_common.cpp | 52 
>> +
>> libavdevice/decklink_common.h   |  2 +-
>> libavdevice/decklink_dec.cpp| 22 -
>> libavdevice/decklink_dec.h  |  1 +
>> libavdevice/decklink_dec_c.c|  1 +
>> libavdevice/decklink_enc.cpp| 22 -
>> libavdevice/decklink_enc.h  |  1 +
>> libavdevice/decklink_enc_c.c|  1 +
>> 8 files changed, 95 insertions(+), 7 deletions(-)
>> 
>> diff --git a/libavdevice/decklink_common.cpp 
>> b/libavdevice/decklink_common.cpp
>> index 7745575d0e..86d6fbb74b 100644
>> --- a/libavdevice/decklink_common.cpp
>> +++ b/libavdevice/decklink_common.cpp
>> @@ -37,6 +37,7 @@ extern "C" {
>> #include "libavutil/imgutils.h"
>> #include "libavutil/intreadwrite.h"
>> #include "libavutil/bswap.h"
>> +#include "avdevice.h"
>> }
>> #include "decklink_common.h"
>> @@ -261,24 +262,67 @@ int ff_decklink_set_format(AVFormatContext *avctx, 
>> decklink_direction_t directio
>>return ff_decklink_set_format(avctx, 0, 0, 0, 0, AV_FIELD_UNKNOWN, 
>> direction, num);
>> }
>> -int ff_decklink_list_devices(AVFormatContext *avctx)
>> +int ff_decklink_list_devices(AVFormatContext *avctx,
>> + struct AVDeviceInfoList *device_list,
>> + int show_inputs, int show_outputs)
>> {
>>IDeckLink *dl = NULL;
>>IDeckLinkIterator *iter = CreateDeckLinkIteratorInstance();
>> +int ret = 0;
>> +
>>if (!iter) {
>>av_log(avctx, AV_LOG_ERROR, "Could not create DeckLink iterator\n");
>>return AVERROR(EIO);
>>}
>> -av_log(avctx, AV_LOG_INFO, "Blackmagic DeckLink devices:\n");
>> +
>>while (iter->Next() == S_OK) {
> 
> This probably needs an additional && ret == 0 condition, if there was an 
> ENOMEM error, you want to return instantly instead of trying with the next 
> device, and ignoring the ENOMEM.
> 
>> +IDeckLinkOutput *output_config;
>> +IDeckLinkInput *input_config;
>>const char *displayName;
>> +AVDeviceInfo *new_device = NULL;
>> +int add = 0;
>> +
>>ff_decklink_get_display_name(dl, );
>> -av_log(avctx, AV_LOG_INFO, "\t'%s'\n", displayName);
>> +
>> +if (show_outputs) {
>> +if (dl->QueryInterface(IID_IDeckLinkOutput, (void 
>> **)_config) == S_OK) {
>> +output_config->Release();
>> +add = 1;
>> +}
>> +}
>> +
>> +if (show_inputs) {
>> +if (dl->QueryInterface(IID_IDeckLinkInput, (void 
>> **)_config) == S_OK) {
>> +input_config->Release();
>> +add = 1;
>> +}
>> +}
>> +
>> +if (add == 1) {
>> +new_device = (AVDeviceInfo *) av_mallocz(sizeof(AVDeviceInfo));
>> +if (!new_device) {
>> +ret = AVERROR(ENOMEM);
>> +goto next;
>> +}
>> +new_device->device_name = av_strdup(displayName);
>> +new_device->device_description = av_strdup(displayName);
>> +if (!new_device->device_description || 
>> !new_device->device_name) {
> 
> you might leak device_name here.
> 
>> +ret = AVERROR(ENOMEM);
>> +goto next;
>> +}
>> +
>> +if ((ret = av_dynarray_add_nofree(_list->devices,
>> +  _list->nb_devices, 
>> new_device)) < 0) {
> 
> you should free the struct on error here I think
> 
>> +goto next;
>> +}
>> +}
>> +
>> +next:
>>av_free((void *) displayName);
> 
> av_freep
> 
>>dl->Release();
>>}
>>iter->Release();
>> -return 0;
>> +return ret;
>> }
>> int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t 
>> direction)
>> diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
>> index 749eb0f8b8..f81b33ada4 100644
>> --- a/libavdevice/decklink_common.h
>> +++ b/libavdevice/decklink_common.h
>> @@ -135,7 +135,7 @@ static const BMDVideoConnection 
>> decklink_video_connection_map[] = {
>> HRESULT ff_decklink_get_display_name(IDeckLink *This, const char 
>> **displayName);
>> int ff_decklink_set_format(AVFormatContext *avctx, int width, int height, 
>> int tb_num, int tb_den, enum AVFieldOrder field_order, decklink_direction_t 
>> direction = DIRECTION_OUT, int num = 0);
>> int 

Re: [FFmpeg-devel] [PATCH 2/4] libavdevice/decklink: add support for -sources and -sinks arguments

2017-09-30 Thread Marton Balint



On Tue, 26 Sep 2017, Devin Heitmueller wrote:


Add support for enumerating the sources/sinks via the ffmpeg
command line options, as opposed to having to create a real pipeline
and use the "-list_devices" option which does exit() after dumping
out the options.

Note that this patch preserves the existing "-list_devices" option,
but now shares common code for the actual enumeration.

Signed-off-by: Devin Heitmueller 
---
libavdevice/decklink_common.cpp | 52 +
libavdevice/decklink_common.h   |  2 +-
libavdevice/decklink_dec.cpp| 22 -
libavdevice/decklink_dec.h  |  1 +
libavdevice/decklink_dec_c.c|  1 +
libavdevice/decklink_enc.cpp| 22 -
libavdevice/decklink_enc.h  |  1 +
libavdevice/decklink_enc_c.c|  1 +
8 files changed, 95 insertions(+), 7 deletions(-)

diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index 7745575d0e..86d6fbb74b 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -37,6 +37,7 @@ extern "C" {
#include "libavutil/imgutils.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/bswap.h"
+#include "avdevice.h"
}

#include "decklink_common.h"
@@ -261,24 +262,67 @@ int ff_decklink_set_format(AVFormatContext *avctx, 
decklink_direction_t directio
return ff_decklink_set_format(avctx, 0, 0, 0, 0, AV_FIELD_UNKNOWN, 
direction, num);
}

-int ff_decklink_list_devices(AVFormatContext *avctx)
+int ff_decklink_list_devices(AVFormatContext *avctx,
+struct AVDeviceInfoList *device_list,
+int show_inputs, int show_outputs)
{
IDeckLink *dl = NULL;
IDeckLinkIterator *iter = CreateDeckLinkIteratorInstance();
+int ret = 0;
+
if (!iter) {
av_log(avctx, AV_LOG_ERROR, "Could not create DeckLink iterator\n");
return AVERROR(EIO);
}
-av_log(avctx, AV_LOG_INFO, "Blackmagic DeckLink devices:\n");
+
while (iter->Next() == S_OK) {


This probably needs an additional && ret == 0 condition, if there was an 
ENOMEM error, you want to return instantly instead of trying with the next 
device, and ignoring the ENOMEM.



+IDeckLinkOutput *output_config;
+IDeckLinkInput *input_config;
const char *displayName;
+AVDeviceInfo *new_device = NULL;
+int add = 0;
+
ff_decklink_get_display_name(dl, );
-av_log(avctx, AV_LOG_INFO, "\t'%s'\n", displayName);
+
+if (show_outputs) {
+if (dl->QueryInterface(IID_IDeckLinkOutput, (void 
**)_config) == S_OK) {
+output_config->Release();
+add = 1;
+}
+}
+
+if (show_inputs) {
+if (dl->QueryInterface(IID_IDeckLinkInput, (void **)_config) 
== S_OK) {
+input_config->Release();
+add = 1;
+}
+}
+
+if (add == 1) {
+new_device = (AVDeviceInfo *) av_mallocz(sizeof(AVDeviceInfo));
+if (!new_device) {
+ret = AVERROR(ENOMEM);
+goto next;
+}
+new_device->device_name = av_strdup(displayName);
+new_device->device_description = av_strdup(displayName);
+if (!new_device->device_description || !new_device->device_name) {


you might leak device_name here.


+ret = AVERROR(ENOMEM);
+goto next;
+}
+
+if ((ret = av_dynarray_add_nofree(_list->devices,
+  _list->nb_devices, 
new_device)) < 0) {


you should free the struct on error here I think


+goto next;
+}
+}
+
+next:
av_free((void *) displayName);


av_freep


dl->Release();
}
iter->Release();
-return 0;
+return ret;
}

int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t 
direction)
diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
index 749eb0f8b8..f81b33ada4 100644
--- a/libavdevice/decklink_common.h
+++ b/libavdevice/decklink_common.h
@@ -135,7 +135,7 @@ static const BMDVideoConnection 
decklink_video_connection_map[] = {
HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName);
int ff_decklink_set_format(AVFormatContext *avctx, int width, int height, int 
tb_num, int tb_den, enum AVFieldOrder field_order, decklink_direction_t 
direction = DIRECTION_OUT, int num = 0);
int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t 
direction, int num);
-int ff_decklink_list_devices(AVFormatContext *avctx);
+int ff_decklink_list_devices(AVFormatContext *avctx, struct AVDeviceInfoList 
*device_list, int show_inputs, int show_outputs);
int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t 
direction = DIRECTION_OUT);
void ff_decklink_cleanup(AVFormatContext *avctx);
int 

[FFmpeg-devel] [PATCH 2/4] libavdevice/decklink: add support for -sources and -sinks arguments

2017-09-26 Thread Devin Heitmueller
Add support for enumerating the sources/sinks via the ffmpeg
command line options, as opposed to having to create a real pipeline
and use the "-list_devices" option which does exit() after dumping
out the options.

Note that this patch preserves the existing "-list_devices" option,
but now shares common code for the actual enumeration.

Signed-off-by: Devin Heitmueller 
---
 libavdevice/decklink_common.cpp | 52 +
 libavdevice/decklink_common.h   |  2 +-
 libavdevice/decklink_dec.cpp| 22 -
 libavdevice/decklink_dec.h  |  1 +
 libavdevice/decklink_dec_c.c|  1 +
 libavdevice/decklink_enc.cpp| 22 -
 libavdevice/decklink_enc.h  |  1 +
 libavdevice/decklink_enc_c.c|  1 +
 8 files changed, 95 insertions(+), 7 deletions(-)

diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp
index 7745575d0e..86d6fbb74b 100644
--- a/libavdevice/decklink_common.cpp
+++ b/libavdevice/decklink_common.cpp
@@ -37,6 +37,7 @@ extern "C" {
 #include "libavutil/imgutils.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/bswap.h"
+#include "avdevice.h"
 }
 
 #include "decklink_common.h"
@@ -261,24 +262,67 @@ int ff_decklink_set_format(AVFormatContext *avctx, 
decklink_direction_t directio
 return ff_decklink_set_format(avctx, 0, 0, 0, 0, AV_FIELD_UNKNOWN, 
direction, num);
 }
 
-int ff_decklink_list_devices(AVFormatContext *avctx)
+int ff_decklink_list_devices(AVFormatContext *avctx,
+struct AVDeviceInfoList *device_list,
+int show_inputs, int show_outputs)
 {
 IDeckLink *dl = NULL;
 IDeckLinkIterator *iter = CreateDeckLinkIteratorInstance();
+int ret = 0;
+
 if (!iter) {
 av_log(avctx, AV_LOG_ERROR, "Could not create DeckLink iterator\n");
 return AVERROR(EIO);
 }
-av_log(avctx, AV_LOG_INFO, "Blackmagic DeckLink devices:\n");
+
 while (iter->Next() == S_OK) {
+IDeckLinkOutput *output_config;
+IDeckLinkInput *input_config;
 const char *displayName;
+AVDeviceInfo *new_device = NULL;
+int add = 0;
+
 ff_decklink_get_display_name(dl, );
-av_log(avctx, AV_LOG_INFO, "\t'%s'\n", displayName);
+
+if (show_outputs) {
+if (dl->QueryInterface(IID_IDeckLinkOutput, (void 
**)_config) == S_OK) {
+output_config->Release();
+add = 1;
+}
+}
+
+if (show_inputs) {
+if (dl->QueryInterface(IID_IDeckLinkInput, (void **)_config) 
== S_OK) {
+input_config->Release();
+add = 1;
+}
+}
+
+if (add == 1) {
+new_device = (AVDeviceInfo *) av_mallocz(sizeof(AVDeviceInfo));
+if (!new_device) {
+ret = AVERROR(ENOMEM);
+goto next;
+}
+new_device->device_name = av_strdup(displayName);
+new_device->device_description = av_strdup(displayName);
+if (!new_device->device_description || !new_device->device_name) {
+ret = AVERROR(ENOMEM);
+goto next;
+}
+
+if ((ret = av_dynarray_add_nofree(_list->devices,
+  _list->nb_devices, 
new_device)) < 0) {
+goto next;
+}
+}
+
+next:
 av_free((void *) displayName);
 dl->Release();
 }
 iter->Release();
-return 0;
+return ret;
 }
 
 int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t 
direction)
diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h
index 749eb0f8b8..f81b33ada4 100644
--- a/libavdevice/decklink_common.h
+++ b/libavdevice/decklink_common.h
@@ -135,7 +135,7 @@ static const BMDVideoConnection 
decklink_video_connection_map[] = {
 HRESULT ff_decklink_get_display_name(IDeckLink *This, const char 
**displayName);
 int ff_decklink_set_format(AVFormatContext *avctx, int width, int height, int 
tb_num, int tb_den, enum AVFieldOrder field_order, decklink_direction_t 
direction = DIRECTION_OUT, int num = 0);
 int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t 
direction, int num);
-int ff_decklink_list_devices(AVFormatContext *avctx);
+int ff_decklink_list_devices(AVFormatContext *avctx, struct AVDeviceInfoList 
*device_list, int show_inputs, int show_outputs);
 int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t 
direction = DIRECTION_OUT);
 void ff_decklink_cleanup(AVFormatContext *avctx);
 int ff_decklink_init_device(AVFormatContext *avctx, const char* name);
diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp
index c271ff3639..cb282055c6 100644
--- a/libavdevice/decklink_dec.cpp
+++ b/libavdevice/decklink_dec.cpp
@@ -38,6 +38,7 @@ extern "C" {
 #include "libavutil/time.h"
 #include