Hello,

i need access to the dolby vision decoder info.
This includes the Dolby Vision Configuration Box and decoder configuration 
record (dvcC/dvvC).
Also includes the DOVI Video Stream Descriptor.
Here is my approach attached as a patch.

Best regards
[Ein einzigartiges Sounderlebnis mit Loewe und Mimi 
Defined™]<https://www.loewe.tv/mimi>
________________________________
Visit our website: https://www.loewe.tv/int

[Facebook]<https://www.facebook.com/LoeweDeutschland>  [Instagram] 
<https://www.instagram.com/loewe.international/>   [Pinterest] 
<https://www.pinterest.com/loewetv/>   [YouTube] 
<http://www.youtube.com/user/loewe>

Loewe Technologies GmbH, Industriestraße 11, 96317 Kronach
Tel. +49 9261 99-500 • Fax +49 9261 99-515
c...@loewe.de<mailto:c...@loewe.de> • www.loewe.tv<https://www.loewe.tv>

Executive Management: Dr. Ralf Vogt, Peter Nortmann • Registered Office: 
Kronach • Commercial Register: Amtsgericht Coburg HRB 5443
From 8193bc14390d7e36a768b0f19b99f8374e83b5f2 Mon Sep 17 00:00:00 2001
From: gressermdm <dmitrij.gresser...@loewe.de>
Date: Thu, 31 Jan 2019 20:28:25 +0100
Subject: [PATCH 2/2] Access to the dolby vision decoder info

---
 libavcodec/avcodec.h |  9 +++++++
 libavformat/dump.c   | 39 +++++++++++++++++++++++++++++
 libavformat/mov.c    | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 libavformat/mpegts.c | 31 +++++++++++++++++++++++
 4 files changed, 148 insertions(+)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 81b30dc..f2f3d93 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1378,6 +1378,15 @@ enum AVPacketSideDataType {
     AV_PKT_DATA_REFERENCE_TRACK,
 
     /**
+     * This side data contains an unsigned integer byte stream of the
+     * DOVI Descriptor or Dolby Vision Configuration Box.
+     * In addition the type of the Descriptor/Box is also added as FourCC
+     * to the begin of the stream as 4 bytes.
+     * This information can be used to configure the decoder for Dolby Vision.
+     */
+    AV_PKT_DOLBY_VISION_DECODER_INFO,
+
+    /**
      * The number of side data types.
      * This is not part of the public API/ABI in the sense that it may
      * change when new side data types are added.
diff --git a/libavformat/dump.c b/libavformat/dump.c
index ef20070..974ccfb 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -398,6 +398,41 @@ static void dump_reference_track(void *ctx, AVPacketSideData *sd)
     av_log(ctx, AV_LOG_INFO, "%"PRIu32"", *track_id);
 }
 
+static void dump_dolby_vision_decoder_info(void *ctx, AVStream *st, AVPacketSideData *sd)
+{
+    uint8_t *dolby_data;
+
+    uint8_t dv_profile;
+    uint8_t dv_level;
+    uint8_t rpu_present_flag;
+    uint8_t el_presenet_flag;
+    uint8_t bl_present_flag;
+
+    if (sd->size < 8){
+        av_log(ctx, AV_LOG_INFO, "invalid data");
+        return;
+    }
+
+    dolby_data = sd->data;
+    if (!dolby_data) {
+        av_log(ctx, AV_LOG_INFO, "invalid data");
+        return;
+    }
+
+    av_log(ctx, AV_LOG_INFO, "(0x%"PRIx8"%"PRIx8"%"PRIx8"%"PRIx8") ",
+            dolby_data[0], dolby_data[1], dolby_data[2], dolby_data[3]);
+    dolby_data += 4;
+
+    dv_profile = dolby_data[2] >> 1;
+    dv_level = ( dolby_data[2] << 7 ) + ( dolby_data[3] >> 3 );
+    rpu_present_flag = dolby_data[3] & 4;
+    el_presenet_flag = dolby_data[3] & 2;
+    bl_present_flag = dolby_data[3] & 1;
+
+    av_log(ctx, AV_LOG_INFO, "profile:%"PRIx8" level:%"PRIx8"%s%s%s", dv_profile, dv_level,
+            rpu_present_flag ? " rpu" : "", el_presenet_flag ? " el" : "", bl_present_flag ? " bl" : "");
+}
+
 static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
 {
     int i;
@@ -461,6 +496,10 @@ static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
             av_log(ctx, AV_LOG_INFO, "reference track: ");
             dump_reference_track(ctx, &sd);
             break;
+        case AV_PKT_DOLBY_VISION_DECODER_INFO:
+            av_log(ctx, AV_LOG_INFO, "dolby vision: ");
+            dump_dolby_vision_decoder_info(ctx, st, &sd);
+            break;
         default:
             av_log(ctx, AV_LOG_INFO,
                    "unknown side data type %d (%d bytes)", sd.type, sd.size);
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 922776e..057968f 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -6669,6 +6669,8 @@ static int mov_read_vdep(MOVContext *c, AVIOContext *pb, MOVAtom atom)
         return AVERROR(ENOMEM);
     *track_id = (uint32_t)avio_rb32(pb);
 
+    if (c->fc->nb_streams < 1)
+        return AVERROR_INVALIDDATA;
     st = c->fc->streams[c->fc->nb_streams-1];
     ret = av_stream_add_side_data(st, AV_PKT_DATA_REFERENCE_TRACK,
                                   (uint8_t *)track_id, sizeof(uint32_t));
@@ -6680,6 +6682,71 @@ static int mov_read_vdep(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     return 0;
 }
 
+static uint8_t *mov_read_dv_config(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+    uint8_t *dolby_data;
+    AVStream *st;
+    size_t size_total;
+    int ret;
+
+    if (c->fc->nb_streams < 1)
+        return NULL;
+    st = c->fc->streams[c->fc->nb_streams-1];
+
+    if (atom.size < 4)
+        return NULL;
+
+    size_total = atom.size + 4;
+
+    dolby_data = av_mallocz(size_total);
+    if (!dolby_data)
+        return NULL;
+    avio_read(pb, dolby_data+4, atom.size);
+
+    ret = av_stream_add_side_data(st, AV_PKT_DOLBY_VISION_DECODER_INFO,
+                                  (uint8_t *)dolby_data, size_total);
+    if (ret < 0) {
+        av_free(dolby_data);
+        return NULL;
+    }
+
+    return dolby_data;
+}
+
+static int mov_read_dvcC(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+    uint8_t *dolby_data;
+    dolby_data = mov_read_dv_config(c, pb, atom);
+
+    if (dolby_data) {
+        dolby_data[0] = 'd';
+        dolby_data[1] = 'v';
+        dolby_data[2] = 'c';
+        dolby_data[3] = 'C';
+    } else {
+        return AVERROR_INVALIDDATA;
+    }
+
+    return 0;
+}
+
+static int mov_read_dvvC(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+    uint8_t *dolby_data;
+    dolby_data = mov_read_dv_config(c, pb, atom);
+
+    if (dolby_data) {
+        dolby_data[0] = 'd';
+        dolby_data[1] = 'v';
+        dolby_data[2] = 'v';
+        dolby_data[3] = 'C';
+    } else {
+        return AVERROR_INVALIDDATA;
+    }
+
+    return 0;
+}
+
 static const MOVParseTableEntry mov_default_parse_table[] = {
 { MKTAG('A','C','L','R'), mov_read_aclr },
 { MKTAG('A','P','R','G'), mov_read_avid },
@@ -6774,6 +6841,8 @@ static const MOVParseTableEntry mov_default_parse_table[] = {
 { MKTAG('m','d','c','v'), mov_read_mdcv },
 { MKTAG('c','l','l','i'), mov_read_clli },
 { MKTAG('v','d','e','p'), mov_read_vdep },
+{ MKTAG('d','v','c','C'), mov_read_dvcC },
+{ MKTAG('d','v','v','C'), mov_read_dvvC },
 { 0, NULL }
 };
 
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index edf6b57..af6ae5e 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -2002,6 +2002,37 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
             }
         }
         break;
+    case 0xb0: /* dovi descriptor */
+        {
+            uint8_t *dolby_data;
+            size_t size_total;
+            int ret;
+
+            if (desc_len < 4)
+                return AVERROR_INVALIDDATA;
+            size_total = desc_len + 4;
+
+            dolby_data = av_mallocz(size_total);
+            if (!dolby_data)
+                return AVERROR(ENOMEM);
+
+            dolby_data[0] = 'D';
+            dolby_data[1] = 'O';
+            dolby_data[2] = 'V';
+            dolby_data[3] = 'I';
+
+            for ( int i = 4; i < size_total; i++ ) {
+                dolby_data[i] = get8(pp, desc_end);
+            }
+
+            ret = av_stream_add_side_data(st, AV_PKT_DOLBY_VISION_DECODER_INFO,
+                                          (uint8_t *)dolby_data, size_total);
+            if (ret < 0) {
+                av_free(dolby_data);
+                return ret;
+            }
+        }
+        break;
     default:
         break;
     }
-- 
2.7.4

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

Reply via email to