History

avformat/flvdec: Put FLVMetaVideoColor inside FLVContext directly

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().

Zhao Zhili committed 1 year ago

Commit 4f53ecf1 parent f3429481 file · +24 −13Browse files

Unified · Split

libavformat/flvdec.c+24−13
@@ -68,6 +68,12 @@ typedef struct FLVMetaVideoColor { · 67 unmodified lines
6868 FLVMasteringMeta mastering_meta;
6969 } FLVMetaVideoColor;
7070
71+enum FLVMetaColorInfoFlag {
72+ FLV_COLOR_INFO_FLAG_NONE = 0,
73+ FLV_COLOR_INFO_FLAG_GOT = 1,
74+ FLV_COLOR_INFO_FLAG_PARSING = 2,
75+};
76+
7177 typedef struct FLVContext {
7278 const AVClass *class; ///< Class for private options.
7379 int trust_metadata; ///< configure streams according onMetaData
@@ -102,8 +108,8 @@ typedef struct FLVContext { · 28 unmodified lines
102108 int64_t time_offset;
103109 int64_t time_pos;
104110
105− FLVMetaVideoColor *metaVideoColor;
106− int meta_color_info_flag;
111+ FLVMetaVideoColor meta_color_info;
112+ enum FLVMetaColorInfoFlag meta_color_info_flag;
107113
108114 uint8_t **mt_extradata;
109115 int *mt_extradata_sz;
@@ -600,7 +606,6 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, · 490 unmodified lines
600606 FLVContext *flv = s->priv_data;
601607 AVIOContext *ioc;
602608 AMFDataType amf_type;
603− FLVMetaVideoColor *meta_video_color = flv->metaVideoColor;
604609 char str_val[1024];
605610 double num_val;
606611 amf_date date;
@@ -749,7 +754,9 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, · 142 unmodified lines
749754 }
750755 }
751756
752− if (meta_video_color) {
757+ if (flv->meta_color_info_flag == FLV_COLOR_INFO_FLAG_PARSING) {
758+ FLVMetaVideoColor *meta_video_color = &flv->meta_color_info;
759+
753760 if (amf_type == AMF_DATA_TYPE_NUMBER ||
754761 amf_type == AMF_DATA_TYPE_BOOL) {
755762 if (!strcmp(key, "colorPrimaries")) {
@@ -943,7 +950,6 @@ static int flv_read_close(AVFormatContext *s) · 187 unmodified lines
943950 av_freep(&flv->mt_extradata_sz);
944951 av_freep(&flv->keyframe_times);
945952 av_freep(&flv->keyframe_filepositions);
946− av_freep(&flv->metaVideoColor);
947953 return 0;
948954 }
949955
@@ -1183,6 +1189,7 @@ static int resync(AVFormatContext *s) · 233 unmodified lines
11831189
11841190 static int flv_parse_video_color_info(AVFormatContext *s, AVStream *st, int64_t next_pos)
11851191 {
1192+ int ret;
11861193 FLVContext *flv = s->priv_data;
11871194 AMFDataType type;
11881195 AVIOContext *ioc;
@@ -1200,19 +1207,22 @@ static int flv_parse_video_color_info(AVFormatContext *s, AVStream *st, int64_t · 11 unmodified lines
12001207 return TYPE_UNKNOWN;
12011208 }
12021209
1203− av_free(flv->metaVideoColor);
1204− if (!(flv->metaVideoColor = av_mallocz(sizeof(FLVMetaVideoColor)))) {
1205− return AVERROR(ENOMEM);
1210+ flv->meta_color_info_flag = FLV_COLOR_INFO_FLAG_PARSING;
1211+ ret = amf_parse_object(s, NULL, NULL, buffer, next_pos, 0); // parse metadata
1212+ if (ret < 0) {
1213+ flv->meta_color_info_flag = FLV_COLOR_INFO_FLAG_NONE;
1214+ return ret;
12061215 }
1207− flv->meta_color_info_flag = 1;
1208− amf_parse_object(s, NULL, NULL, buffer, next_pos, 0); // parse metadata
1216+
1217+ flv->meta_color_info_flag = FLV_COLOR_INFO_FLAG_GOT;
1218+
12091219 return 0;
12101220 }
12111221
12121222 static int flv_update_video_color_info(AVFormatContext *s, AVStream *st)
12131223 {
12141224 FLVContext *flv = s->priv_data;
1215− const FLVMetaVideoColor* meta_video_color = flv->metaVideoColor;
1225+ const FLVMetaVideoColor* meta_video_color = &flv->meta_color_info;
12161226 const FLVMasteringMeta *mastering_meta = &meta_video_color->mastering_meta;
12171227
12181228 int has_mastering_primaries, has_mastering_luminance;
@@ -1735,9 +1745,10 @@ retry_duration: · 516 unmodified lines
17351745 goto leave;
17361746 }
17371747
1738− if (enhanced_flv && stream_type == FLV_STREAM_TYPE_VIDEO && flv->meta_color_info_flag) {
1748+ if (enhanced_flv && stream_type == FLV_STREAM_TYPE_VIDEO &&
1749+ flv->meta_color_info_flag == FLV_COLOR_INFO_FLAG_GOT) {
17391750 flv_update_video_color_info(s, st); // update av packet side data
1740− flv->meta_color_info_flag = 0;
1751+ flv->meta_color_info_flag = FLV_COLOR_INFO_FLAG_NONE;
17411752 }
17421753
17431754 if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4 ||

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