diff mbox

[FFmpeg-devel,4/4] avformat/mov: add support for reading Content Light Level Box

Message ID 20170518004941.5140-4-jamrial@gmail.com
State Accepted
Commit 24133973fc242a2a911237957873af65ef20d086
Headers show

Commit Message

James Almer May 18, 2017, 12:49 a.m. UTC
As defined in "VP Codec ISO Media File Format Binding v1.0"
https://github.com/webmproject/vp9-dash/blob/master/VPCodecISOMediaFileFormatBinding.md

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/isom.h |  2 ++
 libavformat/mov.c  | 43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

Comments

Michael Niedermayer May 26, 2017, 11:06 p.m. UTC | #1
On Wed, May 17, 2017 at 09:49:41PM -0300, James Almer wrote:
> As defined in "VP Codec ISO Media File Format Binding v1.0"
> https://github.com/webmproject/vp9-dash/blob/master/VPCodecISOMediaFileFormatBinding.md
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/isom.h |  2 ++
>  libavformat/mov.c  | 43 +++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 45 insertions(+)

should be ok

thx

[...]
James Almer May 27, 2017, 7:17 p.m. UTC | #2
On 5/26/2017 8:06 PM, Michael Niedermayer wrote:
> On Wed, May 17, 2017 at 09:49:41PM -0300, James Almer wrote:
>> As defined in "VP Codec ISO Media File Format Binding v1.0"
>> https://github.com/webmproject/vp9-dash/blob/master/VPCodecISOMediaFileFormatBinding.md
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>  libavformat/isom.h |  2 ++
>>  libavformat/mov.c  | 43 +++++++++++++++++++++++++++++++++++++++++++
>>  2 files changed, 45 insertions(+)
> 
> should be ok
> 
> thx

Pushed.
diff mbox

Patch

diff --git a/libavformat/isom.h b/libavformat/isom.h
index 426f732247..ff009b0896 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -196,6 +196,8 @@  typedef struct MOVStreamContext {
     AVSphericalMapping *spherical;
     size_t spherical_size;
     AVMasteringDisplayMetadata *mastering;
+    AVContentLightMetadata *coll;
+    size_t coll_size;
 
     uint32_t format;
 
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 0b5fd849f3..db39890234 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4666,6 +4666,38 @@  static int mov_read_smdm(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     return 0;
 }
 
+static int mov_read_coll(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+    MOVStreamContext *sc;
+    int version;
+
+    if (c->fc->nb_streams < 1)
+        return AVERROR_INVALIDDATA;
+
+    sc = c->fc->streams[c->fc->nb_streams - 1]->priv_data;
+
+    if (atom.size < 5) {
+        av_log(c->fc, AV_LOG_ERROR, "Empty Content Light Level box\n");
+        return AVERROR_INVALIDDATA;
+    }
+
+    version = avio_r8(pb);
+    if (version) {
+        av_log(c->fc, AV_LOG_WARNING, "Unsupported Content Light Level box version %d\n", version);
+        return 0;
+    }
+    avio_skip(pb, 3); /* flags */
+
+    sc->coll = av_content_light_metadata_alloc(&sc->coll_size);
+    if (!sc->coll)
+        return AVERROR(ENOMEM);
+
+    sc->coll->MaxCLL  = avio_rb16(pb);
+    sc->coll->MaxFALL = avio_rb16(pb);
+
+    return 0;
+}
+
 static int mov_read_st3d(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
     AVStream *st;
@@ -5453,6 +5485,7 @@  static const MOVParseTableEntry mov_default_parse_table[] = {
 { MKTAG('s','v','3','d'), mov_read_sv3d }, /* spherical video box */
 { MKTAG('d','O','p','s'), mov_read_dops },
 { MKTAG('S','m','D','m'), mov_read_smdm },
+{ MKTAG('C','o','L','L'), mov_read_coll },
 { 0, NULL }
 };
 
@@ -5878,6 +5911,7 @@  static int mov_read_close(AVFormatContext *s)
         av_freep(&sc->stereo3d);
         av_freep(&sc->spherical);
         av_freep(&sc->mastering);
+        av_freep(&sc->coll);
     }
 
     if (mov->dv_demux) {
@@ -6237,6 +6271,15 @@  static int mov_read_header(AVFormatContext *s)
 
                 sc->mastering = NULL;
             }
+            if (sc->coll) {
+                err = av_stream_add_side_data(st, AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
+                                              (uint8_t *)sc->coll,
+                                              sc->coll_size);
+                if (err < 0)
+                    return err;
+
+                sc->coll = NULL;
+            }
             break;
         }
     }