Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH v2 3/6] avformat/flvdec: Put FLVMetaVideoColor inside FLVContext directly
@ 2025-03-11  2:35 Zhao Zhili
  0 siblings, 0 replies; only message in thread
From: Zhao Zhili @ 2025-03-11  2:35 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Zhao Zhili

From: Zhao Zhili <zhilizhao@tencent.com>

1. Rename metaVideoColor to meta_color_info
2. Allocated FLVMetaVideoColor together with FLVContext
3. Improve the use of meta_color_info_flag. Do a sequence of strcmp
only if meta_color_info_flag is FLV_COLOR_INFO_FLAG_PARSING.
4. Check return value of amf_parse_object().
---
 libavformat/flvdec.c | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index 7ea4275784..fcc8403db7 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -68,6 +68,12 @@ typedef struct FLVMetaVideoColor {
     FLVMasteringMeta mastering_meta;
 } FLVMetaVideoColor;
 
+enum FLVMetaColorInfoFlag {
+    FLV_COLOR_INFO_FLAG_NONE = 0,
+    FLV_COLOR_INFO_FLAG_GOT = 1,
+    FLV_COLOR_INFO_FLAG_PARSING = 2,
+};
+
 typedef struct FLVContext {
     const AVClass *class; ///< Class for private options.
     int trust_metadata;   ///< configure streams according onMetaData
@@ -102,8 +108,8 @@ typedef struct FLVContext {
     int64_t time_offset;
     int64_t time_pos;
 
-    FLVMetaVideoColor *metaVideoColor;
-    int meta_color_info_flag;
+    FLVMetaVideoColor meta_color_info;
+    enum FLVMetaColorInfoFlag meta_color_info_flag;
 
     uint8_t **mt_extradata;
     int *mt_extradata_sz;
@@ -600,7 +606,6 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream,
     FLVContext *flv = s->priv_data;
     AVIOContext *ioc;
     AMFDataType amf_type;
-    FLVMetaVideoColor *meta_video_color = flv->metaVideoColor;
     char str_val[1024];
     double num_val;
     amf_date date;
@@ -749,7 +754,9 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream,
             }
         }
 
-        if (meta_video_color) {
+        if (flv->meta_color_info_flag == FLV_COLOR_INFO_FLAG_PARSING) {
+            FLVMetaVideoColor *meta_video_color = &flv->meta_color_info;
+
             if (amf_type == AMF_DATA_TYPE_NUMBER ||
                 amf_type == AMF_DATA_TYPE_BOOL) {
                 if (!strcmp(key, "colorPrimaries")) {
@@ -943,7 +950,6 @@ static int flv_read_close(AVFormatContext *s)
     av_freep(&flv->mt_extradata_sz);
     av_freep(&flv->keyframe_times);
     av_freep(&flv->keyframe_filepositions);
-    av_freep(&flv->metaVideoColor);
     return 0;
 }
 
@@ -1183,6 +1189,7 @@ static int resync(AVFormatContext *s)
 
 static int flv_parse_video_color_info(AVFormatContext *s, AVStream *st, int64_t next_pos)
 {
+    int ret;
     FLVContext *flv = s->priv_data;
     AMFDataType type;
     AVIOContext *ioc;
@@ -1200,19 +1207,22 @@ static int flv_parse_video_color_info(AVFormatContext *s, AVStream *st, int64_t
         return TYPE_UNKNOWN;
     }
 
-    av_free(flv->metaVideoColor);
-    if (!(flv->metaVideoColor = av_mallocz(sizeof(FLVMetaVideoColor)))) {
-        return AVERROR(ENOMEM);
+    flv->meta_color_info_flag = FLV_COLOR_INFO_FLAG_PARSING;
+    ret = amf_parse_object(s, NULL, NULL, buffer, next_pos, 0); // parse metadata
+    if (ret < 0) {
+        flv->meta_color_info_flag = FLV_COLOR_INFO_FLAG_NONE;
+        return ret;
     }
-    flv->meta_color_info_flag = 1;
-    amf_parse_object(s, NULL, NULL, buffer, next_pos, 0); // parse metadata
+
+    flv->meta_color_info_flag = FLV_COLOR_INFO_FLAG_GOT;
+
     return 0;
 }
 
 static int flv_update_video_color_info(AVFormatContext *s, AVStream *st)
 {
     FLVContext *flv = s->priv_data;
-    const FLVMetaVideoColor* meta_video_color = flv->metaVideoColor;
+    const FLVMetaVideoColor* meta_video_color = &flv->meta_color_info;
     const FLVMasteringMeta *mastering_meta = &meta_video_color->mastering_meta;
 
     int has_mastering_primaries, has_mastering_luminance;
@@ -1735,9 +1745,10 @@ retry_duration:
                 goto leave;
             }
 
-            if (enhanced_flv && stream_type == FLV_STREAM_TYPE_VIDEO && flv->meta_color_info_flag) {
+            if (enhanced_flv && stream_type == FLV_STREAM_TYPE_VIDEO &&
+                flv->meta_color_info_flag == FLV_COLOR_INFO_FLAG_GOT) {
                 flv_update_video_color_info(s, st); // update av packet side data
-                flv->meta_color_info_flag = 0;
+                flv->meta_color_info_flag = FLV_COLOR_INFO_FLAG_NONE;
             }
 
             if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4 ||
-- 
2.46.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-03-11  2:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-11  2:35 [FFmpeg-devel] [PATCH v2 3/6] avformat/flvdec: Put FLVMetaVideoColor inside FLVContext directly Zhao Zhili

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git