History

lavc: add lavfi metadata support.

This commit introduces a new AVPacket side data type: AV_PKT_DATA_STRINGS_METADATA. Its main goal is to provide a way to transmit the metadata from the AVFilterBufferRef up to the AVFrame. This is at the moment "only" useful for lavfi input from libavdevice: lavd/lavfi only outputs packets, and the metadata from the buffer ref kept in its context needs to be transmitted from the packet to the frame by the decoders. The buffer ref can be destroyed at any time (along with the metadata), and a duplication of the AVPacket needs to duplicate the metadata as well, so the choice of using the side data to store them was selected. Making sure lavd/lavfi raises the metadata is useful to allow tools like ffprobe to access the filters metadata (it is at the moment the only way); ffprobe will now automatically show the AVFrame metadata in any customizable output format for users. API users will also be able to access the AVFrame->metadata pointer the same way ffprobe does (av_frame_get_metadata). All the changes are done in this single commit to avoid some memory leaks: for instances, the changes in lavfi/avcodec.c are meant to duplicate the metadata from the buffer ref into the AVFrame. Unless we have an internal way of freeing the AVFrame->metadata automatically, it will leak in most of the user apps. To fix this problem, we introduce AVCodecContext->metadata and link avctx->metadata to the current frame->metadata and free it at each decode frame call (and in the codec closing callback for the last one). But doing this also means to update the way the tiff decoder already handles the AVFrame->metadata (it's the only one decoder with frame metadata at the moment), by making sure it is not trying to free a pointer already freed by the lavc internals. The lavfi/avcodec.c buffer ref code is based on an old Thomas Kühnel work, the rest of the code belongs to the commit author.

Clément Bœsch committed 14 years ago

Commit 6fb2fd81 parent d7b8a9a10 files · +90 −7Browse files

Showing the changes to libavfilter/buffer.c (1 of 10 files). Show all

Unified · Split

libavfilter/buffer.c+8−0
@@ -54,6 +54,10 @@ AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask) · 53 unmodified lines
5454 if (!ret)
5555 return NULL;
5656 *ret = *ref;
57+
58+ ret->metadata = NULL;
59+ av_dict_copy(&ret->metadata, ref->metadata, 0);
60+
5761 if (ref->type == AVMEDIA_TYPE_VIDEO) {
5862 ret->video = av_malloc(sizeof(AVFilterBufferRefVideoProps));
5963 if (!ret->video) {
@@ -172,6 +176,7 @@ void avfilter_unref_buffer(AVFilterBufferRef *ref) · 112 unmodified lines
172176 av_freep(&ref->video->qp_table);
173177 av_freep(&ref->video);
174178 av_freep(&ref->audio);
179+ av_dict_free(&ref->metadata);
175180 av_free(ref);
176181 }
177182
@@ -197,6 +202,9 @@ void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *s · 19 unmodified lines
197202 case AVMEDIA_TYPE_AUDIO: *dst->audio = *src->audio; break;
198203 default: break;
199204 }
205+
206+ av_dict_free(&dst->metadata);
207+ av_dict_copy(&dst->metadata, src->metadata, 0);
200208 }
201209
202210 AVFilterBufferRef *ff_copy_buffer_ref(AVFilterLink *outlink,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t