]> git.sesse.net Git - ffmpeg/blobdiff - libavdevice/dshow.c
avcodec/codec, allcodecs: Constify the AVCodec API
[ffmpeg] / libavdevice / dshow.c
index de910c09943440475d23e3c13f5f0b693b09324a..3f1e9f61d237ec279e7a607796e5d6c4e7089bbc 100644 (file)
@@ -58,7 +58,7 @@ static int
 dshow_read_close(AVFormatContext *s)
 {
     struct dshow_ctx *ctx = s->priv_data;
-    AVPacketList *pktl;
+    PacketList *pktl;
 
     if (ctx->control) {
         IMediaControl_Stop(ctx->control);
@@ -87,13 +87,13 @@ dshow_read_close(AVFormatContext *s)
     }
 
     if (ctx->capture_pin[VideoDevice])
-        libAVPin_Release(ctx->capture_pin[VideoDevice]);
+        ff_dshow_pin_Release(ctx->capture_pin[VideoDevice]);
     if (ctx->capture_pin[AudioDevice])
-        libAVPin_Release(ctx->capture_pin[AudioDevice]);
+        ff_dshow_pin_Release(ctx->capture_pin[AudioDevice]);
     if (ctx->capture_filter[VideoDevice])
-        libAVFilter_Release(ctx->capture_filter[VideoDevice]);
+        ff_dshow_filter_Release(ctx->capture_filter[VideoDevice]);
     if (ctx->capture_filter[AudioDevice])
-        libAVFilter_Release(ctx->capture_filter[AudioDevice]);
+        ff_dshow_filter_Release(ctx->capture_filter[AudioDevice]);
 
     if (ctx->device_pin[VideoDevice])
         IPin_Release(ctx->device_pin[VideoDevice]);
@@ -118,7 +118,7 @@ dshow_read_close(AVFormatContext *s)
 
     pktl = ctx->pktl;
     while (pktl) {
-        AVPacketList *next = pktl->next;
+        PacketList *next = pktl->next;
         av_packet_unref(&pktl->pkt);
         av_free(pktl);
         pktl = next;
@@ -162,7 +162,7 @@ callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time, e
 {
     AVFormatContext *s = priv_data;
     struct dshow_ctx *ctx = s->priv_data;
-    AVPacketList **ppktl, *pktl_next;
+    PacketList **ppktl, *pktl_next;
 
 //    dump_videohdr(s, vdhdr);
 
@@ -171,7 +171,7 @@ callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time, e
     if(shall_we_drop(s, index, devtype))
         goto fail;
 
-    pktl_next = av_mallocz(sizeof(AVPacketList));
+    pktl_next = av_mallocz(sizeof(PacketList));
     if(!pktl_next)
         goto fail;
 
@@ -278,12 +278,12 @@ dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum,
                     goto fail1;
                 }
                 *device_unique_name = unique_name;
+                unique_name = NULL;
                 // success, loop will end now
             }
         } else {
             av_log(avctx, AV_LOG_INFO, " \"%s\"\n", friendly_name);
             av_log(avctx, AV_LOG_INFO, "    Alternative name \"%s\"\n", unique_name);
-            av_free(unique_name);
         }
 
 fail1:
@@ -291,7 +291,8 @@ fail1:
             IMalloc_Free(co_malloc, olestr);
         if (bind_ctx)
             IBindCtx_Release(bind_ctx);
-        av_free(friendly_name);
+        av_freep(&friendly_name);
+        av_freep(&unique_name);
         if (bag)
             IPropertyBag_Release(bag);
         IMoniker_Release(m);
@@ -368,7 +369,7 @@ dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype,
                 enum AVPixelFormat pix_fmt = dshow_pixfmt(bih->biCompression, bih->biBitCount);
                 if (pix_fmt == AV_PIX_FMT_NONE) {
                     enum AVCodecID codec_id = av_codec_get_id(tags, bih->biCompression);
-                    AVCodec *codec = avcodec_find_decoder(codec_id);
+                    const AVCodec *codec = avcodec_find_decoder(codec_id);
                     if (codec_id == AV_CODEC_ID_NONE || !codec) {
                         av_log(avctx, AV_LOG_INFO, "  unknown compression type 0x%X", (int) bih->biCompression);
                     } else {
@@ -509,7 +510,7 @@ end:
  * Pops up a user dialog allowing them to adjust properties for the given filter, if possible.
  */
 void
-dshow_show_filter_properties(IBaseFilter *device_filter, AVFormatContext *avctx) {
+ff_dshow_show_filter_properties(IBaseFilter *device_filter, AVFormatContext *avctx) {
     ISpecifyPropertyPages *property_pages = NULL;
     IUnknown *device_filter_iunknown = NULL;
     HRESULT hr;
@@ -581,7 +582,7 @@ dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype,
     int should_show_properties = (devtype == VideoDevice) ? ctx->show_video_device_dialog : ctx->show_audio_device_dialog;
 
     if (should_show_properties)
-        dshow_show_filter_properties(device_filter, avctx);
+        ff_dshow_show_filter_properties(device_filter, avctx);
 
     r = IBaseFilter_EnumPins(device_filter, &pins);
     if (r != S_OK) {
@@ -730,8 +731,8 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum,
     char *device_filter_unique_name = NULL;
     IGraphBuilder *graph = ctx->graph;
     IPin *device_pin = NULL;
-    libAVPin *capture_pin = NULL;
-    libAVFilter *capture_filter = NULL;
+    DShowPin *capture_pin = NULL;
+    DShowFilter *capture_filter = NULL;
     ICaptureGraphBuilder2 *graph_builder2 = NULL;
     int ret = AVERROR(EIO);
     int r;
@@ -806,7 +807,7 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum,
 
     ctx->device_pin[devtype] = device_pin;
 
-    capture_filter = libAVFilter_Create(avctx, callback, devtype);
+    capture_filter = ff_dshow_filter_Create(avctx, callback, devtype);
     if (!capture_filter) {
         av_log(avctx, AV_LOG_ERROR, "Could not create grabber filter.\n");
         goto error;
@@ -862,7 +863,7 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum,
         goto error;
     }
 
-    libAVPin_AddRef(capture_filter->pin);
+    ff_dshow_pin_AddRef(capture_filter->pin);
     capture_pin = capture_filter->pin;
     ctx->capture_pin[devtype] = capture_pin;
 
@@ -886,7 +887,7 @@ dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum,
         goto error;
     }
 
-    r = dshow_try_setup_crossbar_options(graph_builder2, device_filter, devtype, avctx);
+    r = ff_dshow_try_setup_crossbar_options(graph_builder2, device_filter, devtype, avctx);
 
     if (r != S_OK) {
         av_log(avctx, AV_LOG_ERROR, "Could not setup CrossBar\n");
@@ -941,6 +942,8 @@ dshow_add_device(AVFormatContext *avctx,
     AVStream *st;
     int ret = AVERROR(EIO);
 
+    type.pbFormat = NULL;
+
     st = avformat_new_stream(avctx, NULL);
     if (!st) {
         ret = AVERROR(ENOMEM);
@@ -950,7 +953,7 @@ dshow_add_device(AVFormatContext *avctx,
 
     ctx->capture_filter[devtype]->stream_index = st->index;
 
-    libAVPin_ConnectionMediaType(ctx->capture_pin[devtype], &type);
+    ff_dshow_pin_ConnectionMediaType(ctx->capture_pin[devtype], &type);
 
     par = st->codecpar;
     if (devtype == VideoDevice) {
@@ -989,17 +992,22 @@ dshow_add_device(AVFormatContext *avctx,
             if (par->codec_id == AV_CODEC_ID_NONE) {
                 av_log(avctx, AV_LOG_ERROR, "Unknown compression type. "
                                  "Please report type 0x%X.\n", (int) bih->biCompression);
-                return AVERROR_PATCHWELCOME;
+                ret = AVERROR_PATCHWELCOME;
+                goto error;
             }
             par->bits_per_coded_sample = bih->biBitCount;
         } else {
             par->codec_id = AV_CODEC_ID_RAWVIDEO;
             if (bih->biCompression == BI_RGB || bih->biCompression == BI_BITFIELDS) {
                 par->bits_per_coded_sample = bih->biBitCount;
-                par->extradata = av_malloc(9 + AV_INPUT_BUFFER_PADDING_SIZE);
-                if (par->extradata) {
-                    par->extradata_size = 9;
-                    memcpy(par->extradata, "BottomUp", 9);
+                if (par->height < 0) {
+                    par->height *= -1;
+                } else {
+                    par->extradata = av_malloc(9 + AV_INPUT_BUFFER_PADDING_SIZE);
+                    if (par->extradata) {
+                        par->extradata_size = 9;
+                        memcpy(par->extradata, "BottomUp", 9);
+                    }
                 }
             }
         }
@@ -1026,6 +1034,8 @@ dshow_add_device(AVFormatContext *avctx,
     ret = 0;
 
 error:
+    if (type.pbFormat)
+        CoTaskMemFree(type.pbFormat);
     return ret;
 }
 
@@ -1252,7 +1262,7 @@ static int dshow_check_event_queue(IMediaEvent *media_event)
 static int dshow_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     struct dshow_ctx *ctx = s->priv_data;
-    AVPacketList *pktl = NULL;
+    PacketList *pktl = NULL;
 
     while (!ctx->eof && !pktl) {
         WaitForSingleObject(ctx->mutex, INFINITE);