Line | Branch | Exec | Source |
---|---|---|---|
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 | 8 | int ff_isom_parse_dvcc_dvvc(void *logctx, AVStream *st, | |
33 | const uint8_t *buf_ptr, uint64_t size) | ||
34 | { | ||
35 | uint32_t buf; | ||
36 | AVDOVIDecoderConfigurationRecord *dovi; | ||
37 | size_t dovi_size; | ||
38 | |||
39 |
2/4✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
|
8 | if (size > (1 << 30) || size < 4) |
40 | ✗ | return AVERROR_INVALIDDATA; | |
41 | |||
42 | 8 | dovi = av_dovi_alloc(&dovi_size); | |
43 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (!dovi) |
44 | ✗ | return AVERROR(ENOMEM); | |
45 | |||
46 | 8 | dovi->dv_version_major = *buf_ptr++; // 8 bits | |
47 | 8 | dovi->dv_version_minor = *buf_ptr++; // 8 bits | |
48 | |||
49 | 8 | buf = *buf_ptr++ << 8; | |
50 | 8 | buf |= *buf_ptr++; | |
51 | |||
52 | 8 | dovi->dv_profile = (buf >> 9) & 0x7f; // 7 bits | |
53 | 8 | dovi->dv_level = (buf >> 3) & 0x3f; // 6 bits | |
54 | 8 | dovi->rpu_present_flag = (buf >> 2) & 0x01; // 1 bit | |
55 | 8 | dovi->el_present_flag = (buf >> 1) & 0x01; // 1 bit | |
56 | 8 | dovi->bl_present_flag = buf & 0x01; // 1 bit | |
57 | |||
58 | // Has enough remaining data | ||
59 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | if (size >= 5) { |
60 | 8 | uint8_t buf = *buf_ptr++; | |
61 | 8 | dovi->dv_bl_signal_compatibility_id = (buf >> 4) & 0x0f; // 4 bits | |
62 | 8 | 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 | ||
66 | ✗ | dovi->dv_bl_signal_compatibility_id = 0; | |
67 | ✗ | dovi->dv_md_compression = AV_DOVI_COMPRESSION_NONE; | |
68 | } | ||
69 | |||
70 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
|
8 | if (!av_packet_side_data_add(&st->codecpar->coded_side_data, &st->codecpar->nb_coded_side_data, |
71 | AV_PKT_DATA_DOVI_CONF, (uint8_t *)dovi, dovi_size, 0)) { | ||
72 | ✗ | av_free(dovi); | |
73 | ✗ | return AVERROR(ENOMEM); | |
74 | } | ||
75 | |||
76 | 8 | 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", | ||
78 | 8 | dovi->dv_version_major, dovi->dv_version_minor, | |
79 | 8 | dovi->dv_profile, dovi->dv_level, | |
80 | 8 | dovi->rpu_present_flag, | |
81 | 8 | dovi->el_present_flag, | |
82 | 8 | dovi->bl_present_flag, | |
83 | 8 | dovi->dv_bl_signal_compatibility_id, | |
84 | 8 | dovi->dv_md_compression); | |
85 | |||
86 | 8 | return 0; | |
87 | } | ||
88 | |||
89 | 2 | void ff_isom_put_dvcc_dvvc(void *logctx, uint8_t out[ISOM_DVCC_DVVC_SIZE], | |
90 | const AVDOVIDecoderConfigurationRecord *dovi) | ||
91 | { | ||
92 | PutBitContext pb; | ||
93 | |||
94 | 2 | init_put_bits(&pb, out, ISOM_DVCC_DVVC_SIZE); | |
95 | |||
96 | 2 | put_bits(&pb, 8, dovi->dv_version_major); | |
97 | 2 | put_bits(&pb, 8, dovi->dv_version_minor); | |
98 | 2 | put_bits(&pb, 7, dovi->dv_profile & 0x7f); | |
99 | 2 | put_bits(&pb, 6, dovi->dv_level & 0x3f); | |
100 | 2 | put_bits(&pb, 1, !!dovi->rpu_present_flag); | |
101 | 2 | put_bits(&pb, 1, !!dovi->el_present_flag); | |
102 | 2 | put_bits(&pb, 1, !!dovi->bl_present_flag); | |
103 | 2 | put_bits(&pb, 4, dovi->dv_bl_signal_compatibility_id & 0x0f); | |
104 | 2 | put_bits(&pb, 2, dovi->dv_md_compression & 0x03); | |
105 | |||
106 | 2 | put_bits(&pb, 26, 0); /* reserved */ | |
107 | 2 | put_bits32(&pb, 0); /* reserved */ | |
108 | 2 | put_bits32(&pb, 0); /* reserved */ | |
109 | 2 | put_bits32(&pb, 0); /* reserved */ | |
110 | 2 | put_bits32(&pb, 0); /* reserved */ | |
111 | |||
112 | 2 | flush_put_bits(&pb); | |
113 | |||
114 | 2 | 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 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | dovi->dv_profile > 10 ? "dvwC" : (dovi->dv_profile > 7 ? "dvvC" : "dvcC"), |
119 | 2 | dovi->dv_version_major, dovi->dv_version_minor, | |
120 | 2 | dovi->dv_profile, dovi->dv_level, | |
121 | 2 | dovi->rpu_present_flag, | |
122 | 2 | dovi->el_present_flag, | |
123 | 2 | dovi->bl_present_flag, | |
124 | 2 | dovi->dv_bl_signal_compatibility_id, | |
125 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | dovi->dv_md_compression); |
126 | 2 | } | |
127 |