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().
Unified · Split
| @@ -68,6 +68,12 @@ typedef struct FLVMetaVideoColor { · 67 unmodified lines | |||
| 68 | FLVMasteringMeta mastering_meta; | 68 | FLVMasteringMeta mastering_meta; |
| 69 | } FLVMetaVideoColor; | 69 | } FLVMetaVideoColor; |
| 70 | 70 | ||
| 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 | |||
| 71 | typedef struct FLVContext { | 77 | typedef struct FLVContext { |
| 72 | const AVClass *class; ///< Class for private options. | 78 | const AVClass *class; ///< Class for private options. |
| 73 | int trust_metadata; ///< configure streams according onMetaData | 79 | int trust_metadata; ///< configure streams according onMetaData |
| @@ -102,8 +108,8 @@ typedef struct FLVContext { · 28 unmodified lines | |||
| 102 | int64_t time_offset; | 108 | int64_t time_offset; |
| 103 | int64_t time_pos; | 109 | int64_t time_pos; |
| 104 | 110 | ||
| 105 | FLVMetaVideoColor *metaVideoColor; | 111 | FLVMetaVideoColor meta_color_info; |
| 106 | int meta_color_info_flag; | 112 | enum FLVMetaColorInfoFlag meta_color_info_flag; |
| 107 | 113 | ||
| 108 | uint8_t **mt_extradata; | 114 | uint8_t **mt_extradata; |
| 109 | int *mt_extradata_sz; | 115 | int *mt_extradata_sz; |
| @@ -600,7 +606,6 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, · 490 unmodified lines | |||
| 600 | FLVContext *flv = s->priv_data; | 606 | FLVContext *flv = s->priv_data; |
| 601 | AVIOContext *ioc; | 607 | AVIOContext *ioc; |
| 602 | AMFDataType amf_type; | 608 | AMFDataType amf_type; |
| 603 | FLVMetaVideoColor *meta_video_color = flv->metaVideoColor; | ||
| 604 | char str_val[1024]; | 609 | char str_val[1024]; |
| 605 | double num_val; | 610 | double num_val; |
| 606 | amf_date date; | 611 | amf_date date; |
| @@ -749,7 +754,9 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, · 142 unmodified lines | |||
| 749 | } | 754 | } |
| 750 | } | 755 | } |
| 751 | 756 | ||
| 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 | |||
| 753 | if (amf_type == AMF_DATA_TYPE_NUMBER || | 760 | if (amf_type == AMF_DATA_TYPE_NUMBER || |
| 754 | amf_type == AMF_DATA_TYPE_BOOL) { | 761 | amf_type == AMF_DATA_TYPE_BOOL) { |
| 755 | if (!strcmp(key, "colorPrimaries")) { | 762 | if (!strcmp(key, "colorPrimaries")) { |
| @@ -943,7 +950,6 @@ static int flv_read_close(AVFormatContext *s) · 187 unmodified lines | |||
| 943 | av_freep(&flv->mt_extradata_sz); | 950 | av_freep(&flv->mt_extradata_sz); |
| 944 | av_freep(&flv->keyframe_times); | 951 | av_freep(&flv->keyframe_times); |
| 945 | av_freep(&flv->keyframe_filepositions); | 952 | av_freep(&flv->keyframe_filepositions); |
| 946 | av_freep(&flv->metaVideoColor); | ||
| 947 | return 0; | 953 | return 0; |
| 948 | } | 954 | } |
| 949 | 955 | ||
| @@ -1183,6 +1189,7 @@ static int resync(AVFormatContext *s) · 233 unmodified lines | |||
| 1183 | 1189 | ||
| 1184 | static int flv_parse_video_color_info(AVFormatContext *s, AVStream *st, int64_t next_pos) | 1190 | static int flv_parse_video_color_info(AVFormatContext *s, AVStream *st, int64_t next_pos) |
| 1185 | { | 1191 | { |
| 1192 | int ret; | ||
| 1186 | FLVContext *flv = s->priv_data; | 1193 | FLVContext *flv = s->priv_data; |
| 1187 | AMFDataType type; | 1194 | AMFDataType type; |
| 1188 | AVIOContext *ioc; | 1195 | AVIOContext *ioc; |
| @@ -1200,19 +1207,22 @@ static int flv_parse_video_color_info(AVFormatContext *s, AVStream *st, int64_t · 11 unmodified lines | |||
| 1200 | return TYPE_UNKNOWN; | 1207 | return TYPE_UNKNOWN; |
| 1201 | } | 1208 | } |
| 1202 | 1209 | ||
| 1203 | av_free(flv->metaVideoColor); | 1210 | flv->meta_color_info_flag = FLV_COLOR_INFO_FLAG_PARSING; |
| 1204 | if (!(flv->metaVideoColor = av_mallocz(sizeof(FLVMetaVideoColor)))) { | 1211 | ret = amf_parse_object(s, NULL, NULL, buffer, next_pos, 0); // parse metadata |
| 1205 | return AVERROR(ENOMEM); | 1212 | if (ret < 0) { |
| 1213 | flv->meta_color_info_flag = FLV_COLOR_INFO_FLAG_NONE; | ||
| 1214 | return ret; | ||
| 1206 | } | 1215 | } |
| 1207 | flv->meta_color_info_flag = 1; | 1216 | |
| 1208 | amf_parse_object(s, NULL, NULL, buffer, next_pos, 0); // parse metadata | 1217 | flv->meta_color_info_flag = FLV_COLOR_INFO_FLAG_GOT; |
| 1218 | |||
| 1209 | return 0; | 1219 | return 0; |
| 1210 | } | 1220 | } |
| 1211 | 1221 | ||
| 1212 | static int flv_update_video_color_info(AVFormatContext *s, AVStream *st) | 1222 | static int flv_update_video_color_info(AVFormatContext *s, AVStream *st) |
| 1213 | { | 1223 | { |
| 1214 | FLVContext *flv = s->priv_data; | 1224 | FLVContext *flv = s->priv_data; |
| 1215 | const FLVMetaVideoColor* meta_video_color = flv->metaVideoColor; | 1225 | const FLVMetaVideoColor* meta_video_color = &flv->meta_color_info; |
| 1216 | const FLVMasteringMeta *mastering_meta = &meta_video_color->mastering_meta; | 1226 | const FLVMasteringMeta *mastering_meta = &meta_video_color->mastering_meta; |
| 1217 | 1227 | ||
| 1218 | int has_mastering_primaries, has_mastering_luminance; | 1228 | int has_mastering_primaries, has_mastering_luminance; |
| @@ -1735,9 +1745,10 @@ retry_duration: · 516 unmodified lines | |||
| 1735 | goto leave; | 1745 | goto leave; |
| 1736 | } | 1746 | } |
| 1737 | 1747 | ||
| 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) { | ||
| 1739 | flv_update_video_color_info(s, st); // update av packet side data | 1750 | 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; |
| 1741 | } | 1752 | } |
| 1742 | 1753 | ||
| 1743 | if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4 || | 1754 | if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4 || |