[FFmpeg-devel] [PATCH 3/5] avdevice/lavfi: Use av_packet_pack_dictionary() to pack dictionary
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Sat Sep 5 02:23:55 EEST 2020
Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> ---
> av_packet_pack_dictionary() returns NULL in case the dictionary's count
> is zero; but given that the dict API does not return such dicts at all,
> I have not added any check for this.
>
> libavdevice/lavfi.c | 25 ++++++++-----------------
> 1 file changed, 8 insertions(+), 17 deletions(-)
>
> diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c
> index 5e814eada8..bafc3275c9 100644
> --- a/libavdevice/lavfi.c
> +++ b/libavdevice/lavfi.c
> @@ -444,25 +444,16 @@ static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt)
>
> frame_metadata = frame->metadata;
> if (frame_metadata) {
> - uint8_t *metadata;
> - AVDictionaryEntry *e = NULL;
> - AVBPrint meta_buf;
> -
> - av_bprint_init(&meta_buf, 0, AV_BPRINT_SIZE_UNLIMITED);
> - while ((e = av_dict_get(frame_metadata, "", e, AV_DICT_IGNORE_SUFFIX))) {
> - av_bprintf(&meta_buf, "%s", e->key);
> - av_bprint_chars(&meta_buf, '\0', 1);
> - av_bprintf(&meta_buf, "%s", e->value);
> - av_bprint_chars(&meta_buf, '\0', 1);
> - }
> - if (!av_bprint_is_complete(&meta_buf) ||
> - !(metadata = av_packet_new_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA,
> - meta_buf.len))) {
> - av_bprint_finalize(&meta_buf, NULL);
> + int size;
> + uint8_t *metadata = av_packet_pack_dictionary(frame_metadata, &size);
> +
> + if (!metadata)
> return AVERROR(ENOMEM);
> + if ((ret = av_packet_add_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA,
> + metadata, size)) < 0) {
> + av_freep(&metadata);
> + return ret;
> }
> - memcpy(metadata, meta_buf.str, meta_buf.len);
> - av_bprint_finalize(&meta_buf, NULL);
> }
>
> if ((ret = create_subcc_packet(avctx, frame, min_pts_sink_idx)) < 0) {
>
Will apply the two outstanding patches (i.e. this and 4/5 [1]) of this
patchset tomorrow unless there are objections.
- Andreas
[1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2020-August/268930.html
More information about the ffmpeg-devel
mailing list