Signed-off-by: James Almer <jamr...@gmail.com> --- libavdevice/dshow.c | 52 +++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 28 deletions(-)
diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index d7f5bd7069..ab158b13b6 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -58,7 +58,6 @@ static int dshow_read_close(AVFormatContext *s) { struct dshow_ctx *ctx = s->priv_data; - AVPacketList *pktl; if (ctx->control) { IMediaControl_Stop(ctx->control); @@ -116,13 +115,7 @@ dshow_read_close(AVFormatContext *s) if(ctx->event[1]) CloseHandle(ctx->event[1]); - pktl = ctx->pktl; - while (pktl) { - AVPacketList *next = pktl->next; - av_packet_unref(&pktl->pkt); - av_free(pktl); - pktl = next; - } + av_packet_list_free(&ctx->pktl); CoUninitialize(); @@ -162,7 +155,8 @@ 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; + AVPacket pkt = { 0 }; + int ret; // dump_videohdr(s, vdhdr); @@ -171,21 +165,19 @@ 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)); - if(!pktl_next) + if (av_new_packet(&pkt, buf_size) < 0) goto fail; - if(av_new_packet(&pktl_next->pkt, buf_size) < 0) { - av_free(pktl_next); + pkt.stream_index = index; + pkt.pts = time; + memcpy(pkt.data, buf, buf_size); + + ret = av_packet_list_put(ctx->pktl, &pkt, NULL, 0); + if (ret < 0) { + av_packet_unref(&pkt); goto fail; } - pktl_next->pkt.stream_index = index; - pktl_next->pkt.pts = time; - memcpy(pktl_next->pkt.data, buf, buf_size); - - for(ppktl = &ctx->pktl ; *ppktl ; ppktl = &(*ppktl)->next); - *ppktl = pktl_next; ctx->curbufsize[index] += buf_size; SetEvent(ctx->event[1]); @@ -1113,6 +1105,12 @@ static int dshow_read_header(AVFormatContext *avctx) } } + ctx->pktl = av_packet_list_alloc(); + if (!ctx->pktl) { + ret = AVERROR(ENOMEM); + goto error; + } + r = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, &IID_IGraphBuilder, (void **) &graph); if (r != S_OK) { @@ -1262,20 +1260,18 @@ 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; + int ret = AVERROR(EAGAIN); - while (!ctx->eof && !pktl) { + while (!ctx->eof && ret) { WaitForSingleObject(ctx->mutex, INFINITE); - pktl = ctx->pktl; - if (pktl) { - *pkt = pktl->pkt; - ctx->pktl = ctx->pktl->next; - av_free(pktl); + + ret = av_packet_list_get(ctx->pktl, pkt, 0); + if (!ret) ctx->curbufsize[pkt->stream_index] -= pkt->size; - } + ResetEvent(ctx->event[1]); ReleaseMutex(ctx->mutex); - if (!pktl) { + if (ret) { if (dshow_check_event_queue(ctx->media_event) < 0) { ctx->eof = 1; } else if (s->flags & AVFMT_FLAG_NONBLOCK) { -- 2.29.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".