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 #include "libavutil/mem.h"
26 
27 #include "libavcodec/put_bits.h"
28 
29 #include "avformat.h"
30 #include "dovi_isom.h"
31 
32 int ff_isom_parse_dvcc_dvvc(void *logctx, AVStream *st,
33  const uint8_t *buf_ptr, uint64_t size)
34 {
35  uint32_t buf;
37  size_t dovi_size;
38 
39  if (size > (1 << 30) || size < 4)
40  return AVERROR_INVALIDDATA;
41 
42  dovi = av_dovi_alloc(&dovi_size);
43  if (!dovi)
44  return AVERROR(ENOMEM);
45 
46  dovi->dv_version_major = *buf_ptr++; // 8 bits
47  dovi->dv_version_minor = *buf_ptr++; // 8 bits
48 
49  buf = *buf_ptr++ << 8;
50  buf |= *buf_ptr++;
51 
52  dovi->dv_profile = (buf >> 9) & 0x7f; // 7 bits
53  dovi->dv_level = (buf >> 3) & 0x3f; // 6 bits
54  dovi->rpu_present_flag = (buf >> 2) & 0x01; // 1 bit
55  dovi->el_present_flag = (buf >> 1) & 0x01; // 1 bit
56  dovi->bl_present_flag = buf & 0x01; // 1 bit
57 
58  // Has enough remaining data
59  if (size >= 5) {
60  uint8_t buf = *buf_ptr++;
61  dovi->dv_bl_signal_compatibility_id = (buf >> 4) & 0x0f; // 4 bits
62  dovi->dv_md_compression = (buf >> 2) & 0x03; // 2 bits
63  } else {
64  // 0 stands for None
65  // Dolby Vision V1.2.93 profiles and levels
68  }
69 
71  AV_PKT_DATA_DOVI_CONF, (uint8_t *)dovi, dovi_size, 0)) {
72  av_free(dovi);
73  return AVERROR(ENOMEM);
74  }
75 
76  av_log(logctx, AV_LOG_TRACE, "DOVI in dvcC/dvvC/dvwC box, version: %d.%d, profile: %d, level: %d, "
77  "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d, compression: %d\n",
79  dovi->dv_profile, dovi->dv_level,
80  dovi->rpu_present_flag,
81  dovi->el_present_flag,
82  dovi->bl_present_flag,
84  dovi->dv_md_compression);
85 
86  return 0;
87 }
88 
89 void ff_isom_put_dvcc_dvvc(void *logctx, uint8_t out[ISOM_DVCC_DVVC_SIZE],
91 {
92  PutBitContext pb;
93 
95 
96  put_bits(&pb, 8, dovi->dv_version_major);
97  put_bits(&pb, 8, dovi->dv_version_minor);
98  put_bits(&pb, 7, dovi->dv_profile & 0x7f);
99  put_bits(&pb, 6, dovi->dv_level & 0x3f);
100  put_bits(&pb, 1, !!dovi->rpu_present_flag);
101  put_bits(&pb, 1, !!dovi->el_present_flag);
102  put_bits(&pb, 1, !!dovi->bl_present_flag);
103  put_bits(&pb, 4, dovi->dv_bl_signal_compatibility_id & 0x0f);
104  put_bits(&pb, 2, dovi->dv_md_compression & 0x03);
105 
106  put_bits(&pb, 26, 0); /* reserved */
107  put_bits32(&pb, 0); /* reserved */
108  put_bits32(&pb, 0); /* reserved */
109  put_bits32(&pb, 0); /* reserved */
110  put_bits32(&pb, 0); /* reserved */
111 
112  flush_put_bits(&pb);
113 
114  av_log(logctx, AV_LOG_DEBUG,
115  "DOVI in %s box, version: %d.%d, profile: %d, level: %d, "
116  "rpu flag: %d, el flag: %d, bl flag: %d, compatibility id: %d, "
117  "compression: %d\n",
118  dovi->dv_profile > 10 ? "dvwC" : (dovi->dv_profile > 7 ? "dvvC" : "dvcC"),
119  dovi->dv_version_major, dovi->dv_version_minor,
120  dovi->dv_profile, dovi->dv_level,
121  dovi->rpu_present_flag,
122  dovi->el_present_flag,
123  dovi->bl_present_flag,
125  dovi->dv_md_compression);
126 }
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:55
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:223
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:280
AVDOVIDecoderConfigurationRecord::dv_md_compression
uint8_t dv_md_compression
Definition: dovi_meta.h:64
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:26
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:235
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:89
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
AVDOVIDecoderConfigurationRecord::dv_profile
uint8_t dv_profile
Definition: dovi_meta.h:58
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:56
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:771
AVDOVIDecoderConfigurationRecord::dv_level
uint8_t dv_level
Definition: dovi_meta.h:59
AVDOVIDecoderConfigurationRecord::dv_bl_signal_compatibility_id
uint8_t dv_bl_signal_compatibility_id
Definition: dovi_meta.h:63
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: packet.c:700
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:32
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:748
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:62
AVDOVIDecoderConfigurationRecord::rpu_present_flag
uint8_t rpu_present_flag
Definition: dovi_meta.h:60
AVDOVIDecoderConfigurationRecord::el_present_flag
uint8_t el_present_flag
Definition: dovi_meta.h:61
AVDOVIDecoderConfigurationRecord::dv_version_minor
uint8_t dv_version_minor
Definition: dovi_meta.h:57
mem.h
AV_DOVI_COMPRESSION_NONE
@ AV_DOVI_COMPRESSION_NONE
Definition: dovi_meta.h:68
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:55