diff mbox

[FFmpeg-devel,1/2] avformat/matroskaenc: don't write an empty Colour master element

Message ID 20160927234903.4184-1-jamrial@gmail.com
State Accepted
Commit 9b8ac526f6b283024327de27167dfd465f1ab158
Headers show

Commit Message

James Almer Sept. 27, 2016, 11:49 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/matroskaenc.c | 53 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 34 insertions(+), 19 deletions(-)

Comments

James Almer Oct. 2, 2016, 11:14 p.m. UTC | #1
On 9/27/2016 8:49 PM, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/matroskaenc.c | 53 ++++++++++++++++++++++++++++++-----------------
>  1 file changed, 34 insertions(+), 19 deletions(-)

Ping for patchset.
James Almer Oct. 6, 2016, 5:18 p.m. UTC | #2
On 10/2/2016 8:14 PM, James Almer wrote:
> On 9/27/2016 8:49 PM, James Almer wrote:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>  libavformat/matroskaenc.c | 53 ++++++++++++++++++++++++++++++-----------------
>>  1 file changed, 34 insertions(+), 19 deletions(-)
> 
> Ping for patchset.

Pushed.
diff mbox

Patch

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 3eeb09b..3cbc437 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -734,60 +734,73 @@  static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb,
 }
 
 static int mkv_write_video_color(AVIOContext *pb, AVCodecParameters *par, AVStream *st) {
+    AVIOContext *dyn_cp;
+    uint8_t *colorinfo_ptr;
     int side_data_size = 0;
+    int ret, colorinfo_size;
     const uint8_t *side_data = av_stream_get_side_data(
         st, AV_PKT_DATA_MASTERING_DISPLAY_METADATA, &side_data_size);
-    ebml_master colorinfo = start_ebml_master(pb, MATROSKA_ID_VIDEOCOLOR, 0);
+
+    ret = avio_open_dyn_buf(&dyn_cp);
+    if (ret < 0)
+        return ret;
 
     if (par->color_trc != AVCOL_TRC_UNSPECIFIED &&
         par->color_trc < AVCOL_TRC_NB) {
-        put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORTRANSFERCHARACTERISTICS,
+        put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOCOLORTRANSFERCHARACTERISTICS,
                       par->color_trc);
     }
     if (par->color_space != AVCOL_SPC_UNSPECIFIED &&
         par->color_space < AVCOL_SPC_NB) {
-        put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORMATRIXCOEFF, par->color_space);
+        put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOCOLORMATRIXCOEFF, par->color_space);
     }
     if (par->color_primaries != AVCOL_PRI_UNSPECIFIED &&
         par->color_primaries < AVCOL_PRI_NB) {
-        put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORPRIMARIES, par->color_primaries);
+        put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOCOLORPRIMARIES, par->color_primaries);
     }
     if (par->color_range != AVCOL_RANGE_UNSPECIFIED &&
         par->color_range < AVCOL_RANGE_NB) {
-        put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORRANGE, par->color_range);
+        put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOCOLORRANGE, par->color_range);
     }
     if (side_data_size == sizeof(AVMasteringDisplayMetadata)) {
         ebml_master meta_element = start_ebml_master(
-            pb, MATROSKA_ID_VIDEOCOLORMASTERINGMETA, 0);
+            dyn_cp, MATROSKA_ID_VIDEOCOLORMASTERINGMETA, 0);
         const AVMasteringDisplayMetadata *metadata =
             (const AVMasteringDisplayMetadata*)side_data;
         if (metadata->has_primaries) {
-            put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_RX,
+            put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_RX,
                            av_q2d(metadata->display_primaries[0][0]));
-            put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_RY,
+            put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_RY,
                            av_q2d(metadata->display_primaries[0][1]));
-            put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_GX,
+            put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_GX,
                            av_q2d(metadata->display_primaries[1][0]));
-            put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_GY,
+            put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_GY,
                            av_q2d(metadata->display_primaries[1][1]));
-            put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_BX,
+            put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_BX,
                            av_q2d(metadata->display_primaries[2][0]));
-            put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_BY,
+            put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_BY,
                            av_q2d(metadata->display_primaries[2][1]));
-            put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_WHITEX,
+            put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_WHITEX,
                            av_q2d(metadata->white_point[0]));
-            put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_WHITEY,
+            put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_WHITEY,
                            av_q2d(metadata->white_point[1]));
         }
         if (metadata->has_luminance) {
-            put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_LUMINANCEMAX,
+            put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_LUMINANCEMAX,
                            av_q2d(metadata->max_luminance));
-            put_ebml_float(pb, MATROSKA_ID_VIDEOCOLOR_LUMINANCEMIN,
+            put_ebml_float(dyn_cp, MATROSKA_ID_VIDEOCOLOR_LUMINANCEMIN,
                            av_q2d(metadata->min_luminance));
         }
-        end_ebml_master(pb, meta_element);
+        end_ebml_master(dyn_cp, meta_element);
     }
-    end_ebml_master(pb, colorinfo);
+
+    colorinfo_size = avio_close_dyn_buf(dyn_cp, &colorinfo_ptr);
+    if (colorinfo_size) {
+        ebml_master colorinfo = start_ebml_master(pb, MATROSKA_ID_VIDEOCOLOR, 0);
+        avio_write(pb, colorinfo_ptr, colorinfo_size);
+        end_ebml_master(pb, colorinfo);
+    }
+    av_free(colorinfo_ptr);
     return 0;
 }
 
@@ -1125,7 +1138,9 @@  static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
             put_ebml_binary(pb, MATROSKA_ID_VIDEOCOLORSPACE, &color_space, sizeof(color_space));
         }
         if (s->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL) {
-            mkv_write_video_color(pb, par, st);
+            ret = mkv_write_video_color(pb, par, st);
+            if (ret < 0)
+                return ret;
         }
         end_ebml_master(pb, subinfo);
         break;