History

lavc/hevcdec: Parse DOVI RPU NALs

And expose the parsed values as frame side data. Update FATE results to match. It's worth documenting that this relies on the dovi configuration record being present on the first AVPacket fed to the decoder, which in practice is the case if if the API user has called something like av_format_inject_global_side_data, which is unfortunately not the default. This commit is not the time and place to change that behavior, though.

Niklas Haas committed 4 years ago

Commit a538df71 parent 08d15184 files · +256 −9Browse files

Unified · Split

4 files
  1. configure +1 −1
  2. libavcodec/hevcdec.c +29 −8
  3. libavcodec/hevcdec.h +2 −0
  4. tests/ref/fate/hevc-dv-rpu +224 −0
configure+1−1
@@ -2826,7 +2826,7 @@ h264_decoder_suggest="error_resilience" · 2825 unmodified lines
28262826 hap_decoder_select="snappy texturedsp"
28272827 hap_encoder_deps="libsnappy"
28282828 hap_encoder_select="texturedspenc"
2829−hevc_decoder_select="atsc_a53 bswapdsp cabac golomb hevcparse videodsp"
2829+hevc_decoder_select="atsc_a53 bswapdsp cabac dovi_rpu golomb hevcparse videodsp"
28302830 huffyuv_decoder_select="bswapdsp huffyuvdsp llviddsp"
28312831 huffyuv_encoder_select="bswapdsp huffman huffyuvencdsp llvidencdsp"
28322832 hymt_decoder_select="huffyuv_decoder"
libavcodec/hevcdec.c+29−8
@@ -2723,6 +2723,7 @@ error: · 2722 unmodified lines
27232723 static int set_side_data(HEVCContext *s)
27242724 {
27252725 AVFrame *out = s->ref->frame;
2726+ int ret;
27262727
27272728 if (s->sei.frame_packing.present &&
27282729 s->sei.frame_packing.arrangement_type >= 3 &&
@@ -2977,6 +2978,9 @@ static int set_side_data(HEVCContext *s) · 248 unmodified lines
29772978 s->rpu_buf = NULL;
29782979 }
29792980
2981+ if ((ret = ff_dovi_attach_side_data(&s->dovi_ctx, out)) < 0)
2982+ return ret;
2983+
29802984 return 0;
29812985 }
29822986
@@ -3308,16 +3312,23 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length) · 325 unmodified lines
33083312 if (s->pkt.nb_nals > 1 && s->pkt.nals[s->pkt.nb_nals - 1].type == HEVC_NAL_UNSPEC62 &&
33093313 s->pkt.nals[s->pkt.nb_nals - 1].size > 2 && !s->pkt.nals[s->pkt.nb_nals - 1].nuh_layer_id
33103314 && !s->pkt.nals[s->pkt.nb_nals - 1].temporal_id) {
3315+ H2645NAL *nal = &s->pkt.nals[s->pkt.nb_nals - 1];
33113316 if (s->rpu_buf) {
33123317 av_buffer_unref(&s->rpu_buf);
33133318 av_log(s->avctx, AV_LOG_WARNING, "Multiple Dolby Vision RPUs found in one AU. Skipping previous.\n");
33143319 }
33153320
3316− s->rpu_buf = av_buffer_alloc(s->pkt.nals[s->pkt.nb_nals - 1].raw_size - 2);
3321+ s->rpu_buf = av_buffer_alloc(nal->raw_size - 2);
33173322 if (!s->rpu_buf)
33183323 return AVERROR(ENOMEM);
3324+ memcpy(s->rpu_buf->data, nal->raw_data + 2, nal->raw_size - 2);
33193325
3320− memcpy(s->rpu_buf->data, s->pkt.nals[s->pkt.nb_nals - 1].raw_data + 2, s->pkt.nals[s->pkt.nb_nals - 1].raw_size - 2);
3326+ ret = ff_dovi_rpu_parse(&s->dovi_ctx, nal->data + 2, nal->size - 2);
3327+ if (ret < 0) {
3328+ av_buffer_unref(&s->rpu_buf);
3329+ av_log(s->avctx, AV_LOG_WARNING, "Error parsing DOVI NAL unit.\n");
3330+ /* ignore */
3331+ }
33213332 }
33223333
33233334 /* decode the NAL units */
@@ -3450,8 +3461,8 @@ static int hevc_decode_frame(AVCodecContext *avctx, void *data, int *got_output, · 126 unmodified lines
34503461 AVPacket *avpkt)
34513462 {
34523463 int ret;
3453− size_t new_extradata_size;
3454− uint8_t *new_extradata;
3464+ uint8_t *sd;
3465+ size_t sd_size;
34553466 HEVCContext *s = avctx->priv_data;
34563467
34573468 if (!avpkt->size) {
@@ -3463,14 +3474,17 @@ static int hevc_decode_frame(AVCodecContext *avctx, void *data, int *got_output, · 5 unmodified lines
34633474 return 0;
34643475 }
34653476
3466− new_extradata = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA,
3467− &new_extradata_size);
3468− if (new_extradata && new_extradata_size > 0) {
3469− ret = hevc_decode_extradata(s, new_extradata, new_extradata_size, 0);
3477+ sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &sd_size);
3478+ if (sd && sd_size > 0) {
3479+ ret = hevc_decode_extradata(s, sd, sd_size, 0);
34703480 if (ret < 0)
34713481 return ret;
34723482 }
34733483
3484+ sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_DOVI_CONF, &sd_size);
3485+ if (sd && sd_size > 0)
3486+ ff_dovi_update_cfg(&s->dovi_ctx, (AVDOVIDecoderConfigurationRecord *) sd);
3487+
34743488 s->ref = NULL;
34753489 ret = decode_nal_units(s, avpkt->data, avpkt->size);
34763490 if (ret < 0)
@@ -3563,6 +3577,7 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx) · 86 unmodified lines
35633577
35643578 pic_arrays_free(s);
35653579
3580+ ff_dovi_ctx_unref(&s->dovi_ctx);
35663581 av_buffer_unref(&s->rpu_buf);
35673582
35683583 av_freep(&s->md5_ctx);
@@ -3647,6 +3662,7 @@ static av_cold int hevc_init_context(AVCodecContext *avctx) · 78 unmodified lines
36473662
36483663 ff_bswapdsp_init(&s->bdsp);
36493664
3665+ s->dovi_ctx.logctx = avctx;
36503666 s->context_initialized = 1;
36513667 s->eos = 0;
36523668
@@ -3755,6 +3771,10 @@ static int hevc_update_thread_context(AVCodecContext *dst, · 102 unmodified lines
37553771 if (ret < 0)
37563772 return ret;
37573773
3774+ ret = ff_dovi_ctx_replace(&s->dovi_ctx, &s0->dovi_ctx);
3775+ if (ret < 0)
3776+ return ret;
3777+
37583778 s->sei.frame_packing = s0->sei.frame_packing;
37593779 s->sei.display_orientation = s0->sei.display_orientation;
37603780 s->sei.mastering_display = s0->sei.mastering_display;
@@ -3811,6 +3831,7 @@ static void hevc_decode_flush(AVCodecContext *avctx) · 50 unmodified lines
38113831 HEVCContext *s = avctx->priv_data;
38123832 ff_hevc_flush_dpb(s);
38133833 ff_hevc_reset_sei(&s->sei);
3834+ ff_dovi_ctx_flush(&s->dovi_ctx);
38143835 av_buffer_unref(&s->rpu_buf);
38153836 s->max_ra = INT_MAX;
38163837 s->eos = 1;
libavcodec/hevcdec.h+2−0
@@ -32,6 +32,7 @@ · 31 unmodified lines
3232 #include "avcodec.h"
3333 #include "bswapdsp.h"
3434 #include "cabac.h"
35+#include "dovi_rpu.h"
3536 #include "get_bits.h"
3637 #include "hevcpred.h"
3738 #include "h2645_parse.h"
@@ -574,6 +575,7 @@ typedef struct HEVCContext { · 536 unmodified lines
574575 int nuh_layer_id;
575576
576577 AVBufferRef *rpu_buf; ///< 0 or 1 Dolby Vision RPUs.
578+ DOVIContext dovi_ctx; ///< Dolby Vision decoding context
577579 } HEVCContext;
578580
579581 /**
tests/ref/fate/hevc-dv-rpu+224−0
@@ -5,9 +5,233 @@ side_data_type=H.26[45] User Data Unregistered SEI message · 4 unmodified lines
55 [SIDE_DATA]
66 side_data_type=Dolby Vision RPU Data
77 [/SIDE_DATA]
8+[SIDE_DATA]
9+side_data_type=Dolby Vision Metadata
10+rpu_type=2
11+rpu_format=18
12+vdr_rpu_profile=1
13+vdr_rpu_level=0
14+chroma_resampling_explicit_filter_flag=0
15+coef_data_type=0
16+coef_log2_denom=23
17+vdr_rpu_normalized_idc=1
18+bl_video_full_range_flag=0
19+bl_bit_depth=10
20+el_bit_depth=10
21+vdr_bit_depth=12
22+spatial_resampling_filter_flag=0
23+el_spatial_resampling_filter_flag=0
24+disable_residual_flag=1
25+vdr_rpu_id=0
26+mapping_color_space=0
27+mapping_chroma_format_idc=0
28+nlq_method_idc=-1
29+nlq_method_idc_name=none
30+num_x_partitions=1
31+num_y_partitions=1
32+[COMPONENT]
33+pivots=63 132 362 618 874 911 927 935 942
34+[SECTION]
35+mapping_idc=0
36+mapping_idc_name=polynomial
37+poly_order=2
38+poly_coef=-409680 16721463 -20276640
39+[/SECTION]
40+[SECTION]
41+mapping_idc=0
42+mapping_idc_name=polynomial
43+poly_order=2
44+poly_coef=-119056 13575212 -12867889
45+[/SECTION]
46+[SECTION]
47+mapping_idc=0
48+mapping_idc_name=polynomial
49+poly_order=2
50+poly_coef=1317527 5338528 -948122
51+[/SECTION]
52+[SECTION]
53+mapping_idc=0
54+mapping_idc_name=polynomial
55+poly_order=2
56+poly_coef=2119979 2065496 2288524
57+[/SECTION]
58+[SECTION]
59+mapping_idc=0
60+mapping_idc_name=polynomial
61+poly_order=2
62+poly_coef=7982780 -11367226 9973944
63+[/SECTION]
64+[SECTION]
65+mapping_idc=0
66+mapping_idc_name=polynomial
67+poly_order=2
68+poly_coef=53792084 -114243184 67724328
69+[/SECTION]
70+[SECTION]
71+mapping_idc=0
72+mapping_idc_name=polynomial
73+poly_order=2
74+poly_coef=112973872 -244837568 139764480
75+[/SECTION]
76+[SECTION]
77+mapping_idc=0
78+mapping_idc_name=polynomial
79+poly_order=2
80+poly_coef=236828416 -518849056 291306944
81+[/SECTION]
82+[/COMPONENT]
83+[COMPONENT]
84+pivots=0 1023
85+[SECTION]
86+mapping_idc=1
87+mapping_idc_name=mmr
88+mmr_order=3
89+mmr_constant=-4200453
90+mmr_coef=9094176 31944476 739652 -27103344 -3431599 -11015088 22758042 -2028643 -30021218 -906885 26272992 7291404 16488745 -78087176 -1487777 12496543 762460 -4281948 -5768035 -7843163 103636960
91+[/SECTION]
92+[/COMPONENT]
93+[COMPONENT]
94+pivots=0 1023
95+[SECTION]
96+mapping_idc=1
97+mapping_idc_name=mmr
98+mmr_order=3
99+mmr_constant=-10387889
100+mmr_coef=29604202 3214133 46206184 -8564340 -53383996 1628407 5426045 -21634202 -5251953 -50812292 19221972 76726656 -425892 -35041240 5917361 2863974 25030554 -14404292 -41230120 1229046 53575140
101+[/SECTION]
102+[/COMPONENT]
103+dm_metadata_id=0
104+scene_refresh_flag=1
105+ycc_to_rgb_matrix=9574/8192 0/8192 13802/8192 9574/8192 -1540/8192 -5348/8192 9574/8192 17610/8192 0/8192
106+ycc_to_rgb_offset=16777216/268435456 134217728/268435456 134217728/268435456
107+rgb_to_lms_matrix=7222/16384 8771/16384 390/16384 2654/16384 12430/16384 1300/16384 0/16384 422/16384 15962/16384
108+signal_eotf=65535
109+signal_eotf_param0=0
110+signal_eotf_param1=0
111+signal_eotf_param2=0
112+signal_bit_depth=12
113+signal_color_space=0
114+signal_chroma_format=0
115+signal_full_range_flag=1
116+source_min_pq=0
117+source_max_pq=3079
118+source_diagonal=42
119+[/SIDE_DATA]
8120 [/FRAME]
9121 [FRAME]
10122 [SIDE_DATA]
11123 side_data_type=Dolby Vision RPU Data
12124 [/SIDE_DATA]
125+[SIDE_DATA]
126+side_data_type=Dolby Vision Metadata
127+rpu_type=2
128+rpu_format=18
129+vdr_rpu_profile=1
130+vdr_rpu_level=0
131+chroma_resampling_explicit_filter_flag=0
132+coef_data_type=0
133+coef_log2_denom=23
134+vdr_rpu_normalized_idc=1
135+bl_video_full_range_flag=0
136+bl_bit_depth=10
137+el_bit_depth=10
138+vdr_bit_depth=12
139+spatial_resampling_filter_flag=0
140+el_spatial_resampling_filter_flag=0
141+disable_residual_flag=1
142+vdr_rpu_id=0
143+mapping_color_space=0
144+mapping_chroma_format_idc=0
145+nlq_method_idc=-1
146+nlq_method_idc_name=none
147+num_x_partitions=1
148+num_y_partitions=1
149+[COMPONENT]
150+pivots=63 132 362 618 874 911 927 935 942
151+[SECTION]
152+mapping_idc=0
153+mapping_idc_name=polynomial
154+poly_order=2
155+poly_coef=-409680 16721463 -20276640
156+[/SECTION]
157+[SECTION]
158+mapping_idc=0
159+mapping_idc_name=polynomial
160+poly_order=2
161+poly_coef=-119056 13575212 -12867889
162+[/SECTION]
163+[SECTION]
164+mapping_idc=0
165+mapping_idc_name=polynomial
166+poly_order=2
167+poly_coef=1317527 5338528 -948122
168+[/SECTION]
169+[SECTION]
170+mapping_idc=0
171+mapping_idc_name=polynomial
172+poly_order=2
173+poly_coef=2119979 2065496 2288524
174+[/SECTION]
175+[SECTION]
176+mapping_idc=0
177+mapping_idc_name=polynomial
178+poly_order=2
179+poly_coef=7982780 -11367226 9973944
180+[/SECTION]
181+[SECTION]
182+mapping_idc=0
183+mapping_idc_name=polynomial
184+poly_order=2
185+poly_coef=53792084 -114243184 67724328
186+[/SECTION]
187+[SECTION]
188+mapping_idc=0
189+mapping_idc_name=polynomial
190+poly_order=2
191+poly_coef=112973872 -244837568 139764480
192+[/SECTION]
193+[SECTION]
194+mapping_idc=0
195+mapping_idc_name=polynomial
196+poly_order=2
197+poly_coef=236828416 -518849056 291306944
198+[/SECTION]
199+[/COMPONENT]
200+[COMPONENT]
201+pivots=0 1023
202+[SECTION]
203+mapping_idc=1
204+mapping_idc_name=mmr
205+mmr_order=3
206+mmr_constant=-4200453
207+mmr_coef=9094176 31944476 739652 -27103344 -3431599 -11015088 22758042 -2028643 -30021218 -906885 26272992 7291404 16488745 -78087176 -1487777 12496543 762460 -4281948 -5768035 -7843163 103636960
208+[/SECTION]
209+[/COMPONENT]
210+[COMPONENT]
211+pivots=0 1023
212+[SECTION]
213+mapping_idc=1
214+mapping_idc_name=mmr
215+mmr_order=3
216+mmr_constant=-10387889
217+mmr_coef=29604202 3214133 46206184 -8564340 -53383996 1628407 5426045 -21634202 -5251953 -50812292 19221972 76726656 -425892 -35041240 5917361 2863974 25030554 -14404292 -41230120 1229046 53575140
218+[/SECTION]
219+[/COMPONENT]
220+dm_metadata_id=0
221+scene_refresh_flag=1
222+ycc_to_rgb_matrix=9574/8192 0/8192 13802/8192 9574/8192 -1540/8192 -5348/8192 9574/8192 17610/8192 0/8192
223+ycc_to_rgb_offset=16777216/268435456 134217728/268435456 134217728/268435456
224+rgb_to_lms_matrix=7222/16384 8771/16384 390/16384 2654/16384 12430/16384 1300/16384 0/16384 422/16384 15962/16384
225+signal_eotf=65535
226+signal_eotf_param0=0
227+signal_eotf_param1=0
228+signal_eotf_param2=0
229+signal_bit_depth=12
230+signal_color_space=0
231+signal_chroma_format=0
232+signal_full_range_flag=1
233+source_min_pq=0
234+source_max_pq=3079
235+source_diagonal=42
236+[/SIDE_DATA]
13237 [/FRAME]

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t