FFmpeg
dovi_isom.c
Go to the documentation of this file.
1 /*
2  * DOVI ISO Media common code
3  *
4  * Copyright (c) 2020 Vacing Fang <vacingfang@tencent.com>
5  * Copyright (c) 2021 quietvoid
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include "libavutil/dovi_meta.h"
25 
26 #include "libavcodec/put_bits.h"
27 
28 #include "avformat.h"
29 #include "dovi_isom.h"
30 
31 int ff_isom_parse_dvcc_dvvc(void *logctx, AVStream *st,
32  const uint8_t *buf_ptr, uint64_t size)
33 {
34  uint32_t buf;
36  size_t dovi_size;
37 
38  if (size > (1 << 30) || size < 4)
39  return AVERROR_INVALIDDATA;
40 
41  dovi = av_dovi_alloc(&dovi_size);
42  if (!dovi)
43  return AVERROR(ENOMEM);
44 
45  dovi->dv_version_major = *buf_ptr++; // 8 bits
46  dovi->dv_version_minor = *buf_ptr++; // 8 bits
47 
48  buf = *buf_ptr++ << 8;
49  buf |= *buf_ptr++;
50 
51  dovi->dv_profile = (buf >> 9) & 0x7f; // 7 bits
52  dovi->dv_level = (buf >> 3) & 0x3f; // 6 bits
53  dovi->rpu_present_flag = (buf >> 2) & 0x01; // 1 bit
54  dovi->el_present_flag = (buf >> 1) & 0x01; // 1 bit
55  dovi->bl_present_flag = buf & 0x01; // 1 bit
56 
57  // Has enough remaining data
58  if (size >= 5) {
59  dovi->dv_bl_signal_compatibility_id = ((*buf_ptr++) >> 4) & 0x0f; // 4 bits
60  } else {
61  // 0 stands for None
62  // Dolby Vision V1.2.93 profiles and levels
64  }
65 
67  AV_PKT_DATA_DOVI_CONF, (uint8_t *)dovi, dovi_size, 0)) {
68  av_free(dovi);
69  return AVERROR(ENOMEM);
70  }
71 
72  av_log(logctx, AV_LOG_TRACE, "DOVI in dvcC/dvvC/dvwC box, version: %d.%d, profile: %d, level: %d, "
73  "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d\n",
75  dovi->dv_profile, dovi->dv_level,
76  dovi->rpu_present_flag,
77  dovi->el_present_flag,
78  dovi->bl_present_flag,
80 
81  return 0;
82 }
83 
84 void ff_isom_put_dvcc_dvvc(void *logctx, uint8_t out[ISOM_DVCC_DVVC_SIZE],
86 {
87  PutBitContext pb;
88 
90 
91  put_bits(&pb, 8, dovi->dv_version_major);
92  put_bits(&pb, 8, dovi->dv_version_minor);
93  put_bits(&pb, 7, dovi->dv_profile & 0x7f);
94  put_bits(&pb, 6, dovi->dv_level & 0x3f);
95  put_bits(&pb, 1, !!dovi->rpu_present_flag);
96  put_bits(&pb, 1, !!dovi->el_present_flag);
97  put_bits(&pb, 1, !!dovi->bl_present_flag);
98  put_bits(&pb, 4, dovi->dv_bl_signal_compatibility_id & 0x0f);
99 
100  put_bits(&pb, 28, 0); /* reserved */
101  put_bits32(&pb, 0); /* reserved */
102  put_bits32(&pb, 0); /* reserved */
103  put_bits32(&pb, 0); /* reserved */
104  put_bits32(&pb, 0); /* reserved */
105 
106  flush_put_bits(&pb);
107 
108  av_log(logctx, AV_LOG_DEBUG,
109  "DOVI in %s box, version: %d.%d, profile: %d, level: %d, "
110  "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d\n",
111  dovi->dv_profile > 10 ? "dvwC" : (dovi->dv_profile > 7 ? "dvvC" : "dvcC"),
112  dovi->dv_version_major, dovi->dv_version_minor,
113  dovi->dv_profile, dovi->dv_level,
114  dovi->rpu_present_flag,
115  dovi->el_present_flag,
116  dovi->bl_present_flag,
118 }
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
put_bits32
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
Definition: put_bits.h:291
out
FILE * out
Definition: movenc.c:54
init_put_bits
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:62
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:222
AV_PKT_DATA_DOVI_CONF
@ AV_PKT_DATA_DOVI_CONF
DOVI configuration ref: dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2....
Definition: packet.h:284
av_dovi_alloc
AVDOVIDecoderConfigurationRecord * av_dovi_alloc(size_t *size)
Allocate a AVDOVIDecoderConfigurationRecord structure and initialize its fields to default values.
Definition: dovi_meta.c:24
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:206
ff_isom_put_dvcc_dvvc
void ff_isom_put_dvcc_dvvc(void *logctx, uint8_t out[ISOM_DVCC_DVVC_SIZE], const AVDOVIDecoderConfigurationRecord *dovi)
Definition: dovi_isom.c:84
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
AVDOVIDecoderConfigurationRecord::dv_profile
uint8_t dv_profile
Definition: dovi_meta.h:55
AVCodecParameters::nb_coded_side_data
int nb_coded_side_data
Amount of entries in coded_side_data.
Definition: codec_par.h:86
PutBitContext
Definition: put_bits.h:50
AVDOVIDecoderConfigurationRecord::dv_version_major
uint8_t dv_version_major
Definition: dovi_meta.h:53
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:766
AVDOVIDecoderConfigurationRecord::dv_level
uint8_t dv_level
Definition: dovi_meta.h:56
AVDOVIDecoderConfigurationRecord::dv_bl_signal_compatibility_id
uint8_t dv_bl_signal_compatibility_id
Definition: dovi_meta.h:60
size
int size
Definition: twinvq_data.h:10344
dovi_isom.h
av_packet_side_data_add
AVPacketSideData * av_packet_side_data_add(AVPacketSideData **psd, int *pnb_sd, enum AVPacketSideDataType type, void *data, size_t size, int flags)
Wrap existing data as packet side data.
Definition: avpacket.c:697
ff_isom_parse_dvcc_dvvc
int ff_isom_parse_dvcc_dvvc(void *logctx, AVStream *st, const uint8_t *buf_ptr, uint64_t size)
Definition: dovi_isom.c:31
AVCodecParameters::coded_side_data
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
Definition: codec_par.h:81
AVStream
Stream structure.
Definition: avformat.h:743
avformat.h
dovi_meta.h
ISOM_DVCC_DVVC_SIZE
#define ISOM_DVCC_DVVC_SIZE
Definition: dovi_isom.h:29
AVDOVIDecoderConfigurationRecord::bl_present_flag
uint8_t bl_present_flag
Definition: dovi_meta.h:59
AVDOVIDecoderConfigurationRecord::rpu_present_flag
uint8_t rpu_present_flag
Definition: dovi_meta.h:57
AVDOVIDecoderConfigurationRecord::el_present_flag
uint8_t el_present_flag
Definition: dovi_meta.h:58
AVDOVIDecoderConfigurationRecord::dv_version_minor
uint8_t dv_version_minor
Definition: dovi_meta.h:54
flush_put_bits
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:143
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
put_bits.h
AVDOVIDecoderConfigurationRecord
Definition: dovi_meta.h:52