FFmpeg
Loading...
Searching...
No Matches
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
32int 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)
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 byte = *buf_ptr++;
61 dovi->dv_bl_signal_compatibility_id = (byte >> 4) & 0x0f; // 4 bits
62 dovi->dv_md_compression = (byte >> 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
89void ff_isom_put_dvcc_dvvc(void *logctx, uint8_t out[ISOM_DVCC_DVVC_SIZE],
91{
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"),
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}
Main libavformat public API header.
int ff_isom_parse_dvcc_dvvc(void *logctx, AVStream *st, const uint8_t *buf_ptr, uint64_t size)
Definition dovi_isom.c:32
void ff_isom_put_dvcc_dvvc(void *logctx, uint8_t out[ISOM_DVCC_DVVC_SIZE], const AVDOVIDecoderConfigurationRecord *dovi)
Definition dovi_isom.c:89
#define ISOM_DVCC_DVVC_SIZE
Definition dovi_isom.h:29
AVDOVIDecoderConfigurationRecord * av_dovi_alloc(size_t *size)
Allocate a AVDOVIDecoderConfigurationRecord structure and initialize its fields to default values.
Definition dovi_meta.c:26
DOVI configuration.
@ AV_DOVI_COMPRESSION_NONE
Definition dovi_meta.h:68
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:613
@ AV_PKT_DATA_DOVI_CONF
DOVI configuration ref: dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2....
Definition packet.h:280
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition log.h:236
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition j2kenc.c:154
Memory handling functions.
bitstream writer API
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition put_bits.h:62
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition put_bits.h:153
static av_unused void put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
Definition put_bits.h:301
int nb_coded_side_data
Amount of entries in coded_side_data.
Definition codec_par.h:88
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
Definition codec_par.h:83
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
#define av_free(p)
#define av_log(a,...)
static FILE * out
Definition movenc.c:55
int size