[FFmpeg-devel,2/6] avformat/matroskadec: use mastering display metadata's own alloc function

Submitted by James Almer on Dec. 11, 2016, 3:33 a.m.

Details

Message ID 20161211033308.8592-2-jamrial@gmail.com
State New
Headers show

Commit Message

James Almer Dec. 11, 2016, 3:33 a.m.
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/matroskadec.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 58731aa..493d63f 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -1867,14 +1867,12 @@  static int mkv_parse_video_color(AVStream *st, const MatroskaTrack *track) {
         // Use similar rationals as other standards.
         const int chroma_den = 50000;
         const int luma_den = 10000;
-        AVMasteringDisplayMetadata *metadata =
-            (AVMasteringDisplayMetadata*) av_stream_new_side_data(
-                st, AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
-                sizeof(AVMasteringDisplayMetadata));
+        size_t mastering_size;
+        int ret;
+        AVMasteringDisplayMetadata *metadata = av_mastering_display_metadata_alloc2(&mastering_size);
         if (!metadata) {
             return AVERROR(ENOMEM);
         }
-        memset(metadata, 0, sizeof(AVMasteringDisplayMetadata));
         if (has_mastering_primaries) {
             metadata->display_primaries[0][0] = av_make_q(
                 round(mastering_meta->r_x * chroma_den), chroma_den);
@@ -1901,6 +1899,13 @@  static int mkv_parse_video_color(AVStream *st, const MatroskaTrack *track) {
                 round(mastering_meta->min_luminance * luma_den), luma_den);
             metadata->has_luminance = 1;
         }
+
+        ret = av_stream_add_side_data(st, AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
+                                      (uint8_t *)metadata, mastering_size);
+        if (ret < 0) {
+            av_freep(&metadata);
+            return ret;
+        }
     }
     return 0;
 }