History

avcodec/dovi_rpu: move ext blocks into dedicated struct

Slightly re-organize the logic around extension blocks in order to allow expanding the state tracking in a following commit.

Niklas Haas committed 2 years ago

Commit f5d6eb41 parent b3d33f14 files · +38 −23Browse files

Unified · Split

4 files
  1. libavcodec/dovi_rpu.c +0 −1
  2. libavcodec/dovi_rpu.h +7 −2
  3. libavcodec/dovi_rpudec.c +22 −13
  4. libavcodec/dovi_rpuenc.c +9 −7
libavcodec/dovi_rpu.c+0−1
@@ -66,7 +66,6 @@ void ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0) · 65 unmodified lines
6666 for (int i = 0; i <= DOVI_MAX_DM_ID; i++)
6767 ff_refstruct_replace(&s->vdr[i], s0->vdr[i]);
6868 ff_refstruct_replace(&s->ext_blocks, s0->ext_blocks);
69− s->num_ext_blocks = s0->num_ext_blocks;
7069 }
7170
7271 int ff_dovi_guess_profile_hevc(const AVDOVIRpuDataHeader *hdr)
libavcodec/dovi_rpu.h+7−2
@@ -31,6 +31,12 @@ · 30 unmodified lines
3131 #include "codec_par.h"
3232
3333 #define DOVI_MAX_DM_ID 15
34+
35+typedef struct DOVIExt {
36+ AVDOVIDmData dm[AV_DOVI_MAX_EXT_BLOCKS];
37+ int num_dm;
38+} DOVIExt;
39+
3440 typedef struct DOVIContext {
3541 void *logctx;
3642
@@ -70,8 +76,7 @@ typedef struct DOVIContext { · 33 unmodified lines
7076 * Currently active extension blocks, updates on every ff_dovi_rpu_parse()
7177 * or ff_dovi_rpu_generate().
7278 */
73− AVDOVIDmData *ext_blocks;
74− int num_ext_blocks;
79+ DOVIExt *ext_blocks; ///< RefStruct, or NULL if no extension blocks
7580
7681 /**
7782 * Private fields internal to dovi_rpu.c
libavcodec/dovi_rpudec.c+22−13
@@ -33,7 +33,7 @@ · 32 unmodified lines
3333 int ff_dovi_get_metadata(DOVIContext *s, AVDOVIMetadata **out_metadata)
3434 {
3535 AVDOVIMetadata *dovi;
36− size_t dovi_size, ext_sz;
36+ size_t dovi_size;
3737
3838 if (!s->mapping || !s->color)
3939 return 0; /* incomplete dovi metadata */
@@ -47,10 +47,14 @@ int ff_dovi_get_metadata(DOVIContext *s, AVDOVIMetadata **out_metadata) · 7 unmodified lines
4747 COPY(AVDOVIRpuDataHeader, av_dovi_get_header(dovi), &s->header, ext_mapping_idc_5_7);
4848 COPY(AVDOVIDataMapping, av_dovi_get_mapping(dovi), s->mapping, nlq_pivots);
4949 COPY(AVDOVIColorMetadata, av_dovi_get_color(dovi), s->color, source_diagonal);
50− ext_sz = FFMIN(sizeof(AVDOVIDmData), dovi->ext_block_size);
51− for (int i = 0; i < s->num_ext_blocks; i++)
52− memcpy(av_dovi_get_ext(dovi, i), &s->ext_blocks[i], ext_sz);
53− dovi->num_ext_blocks = s->num_ext_blocks;
50+
51+ if (s->ext_blocks) {
52+ const DOVIExt *ext = s->ext_blocks;
53+ size_t ext_sz = FFMIN(sizeof(AVDOVIDmData), dovi->ext_block_size);
54+ for (int i = 0; i < ext->num_dm; i++)
55+ memcpy(av_dovi_get_ext(dovi, i), &ext->dm[i], ext_sz);
56+ dovi->num_ext_blocks = ext->num_dm;
57+ }
5458
5559 *out_metadata = dovi;
5660 return dovi_size;
@@ -279,20 +283,24 @@ static int parse_ext_v2(DOVIContext *s, GetBitContext *gb, AVDOVIDmData *dm, · 222 unmodified lines
279283 static int parse_ext_blocks(DOVIContext *s, GetBitContext *gb, int ver)
280284 {
281285 int num_ext_blocks, ext_block_length, start_pos, parsed_bits, ret;
286+ DOVIExt *ext = s->ext_blocks;
282287
283288 num_ext_blocks = get_ue_golomb_31(gb);
284289 align_get_bits(gb);
285− if (s->num_ext_blocks + num_ext_blocks > AV_DOVI_MAX_EXT_BLOCKS)
286− return AVERROR_INVALIDDATA;
287290
288− if (!s->ext_blocks) {
289− s->ext_blocks = ff_refstruct_allocz(sizeof(AVDOVIDmData) * AV_DOVI_MAX_EXT_BLOCKS);
290− if (!s->ext_blocks)
291+ if (!ext) {
292+ ext = s->ext_blocks = ff_refstruct_allocz(sizeof(*s->ext_blocks));
293+ if (!ext)
291294 return AVERROR(ENOMEM);
292295 }
293296
294297 while (num_ext_blocks--) {
295− AVDOVIDmData *dm = &s->ext_blocks[s->num_ext_blocks++];
298+ AVDOVIDmData *dm;
299+
300+ if (ext->num_dm >= FF_ARRAY_ELEMS(ext->dm))
301+ return AVERROR_INVALIDDATA;
302+ dm = &ext->dm[ext->num_dm++];
303+
296304 ext_block_length = get_ue_golomb_31(gb);
297305 dm->level = get_bits(gb, 8);
298306 start_pos = get_bits_count(gb);
@@ -666,7 +674,8 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, · 367 unmodified lines
666674 color->source_diagonal = get_bits(gb, 10);
667675
668676 /* Parse extension blocks */
669− s->num_ext_blocks = 0;
677+ if (s->ext_blocks)
678+ s->ext_blocks->num_dm = 0;
670679 if ((ret = parse_ext_blocks(s, gb, 1)) < 0) {
671680 ff_dovi_ctx_unref(s);
672681 return ret;
@@ -680,7 +689,7 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, · 7 unmodified lines
680689 }
681690 } else {
682691 s->color = &ff_dovi_color_default;
683− s->num_ext_blocks = 0;
692+ ff_refstruct_unref(&s->ext_blocks);
684693 }
685694
686695 return 0;
libavcodec/dovi_rpuenc.c+9−7
@@ -583,7 +583,7 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata, · 582 unmodified lines
583583 }
584584
585585 if (metadata->num_ext_blocks && !s->ext_blocks) {
586− s->ext_blocks = ff_refstruct_allocz(sizeof(AVDOVIDmData) * AV_DOVI_MAX_EXT_BLOCKS);
586+ s->ext_blocks = ff_refstruct_allocz(sizeof(*s->ext_blocks));
587587 if (!s->ext_blocks)
588588 return AVERROR(ENOMEM);
589589 }
@@ -717,7 +717,7 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata, · 127 unmodified lines
717717 }
718718
719719 if (vdr_dm_metadata_present) {
720− size_t ext_sz;
720+ DOVIExt *ext = s->ext_blocks;
721721 const int denom = profile == 4 ? (1 << 30) : (1 << 28);
722722 set_ue_golomb(pb, color->dm_metadata_id); /* affected_dm_id */
723723 set_ue_golomb(pb, color->dm_metadata_id); /* current_dm_id */
@@ -756,13 +756,15 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata, · 32 unmodified lines
756756 generate_ext_v2(pb, av_dovi_get_ext(metadata, i));
757757 }
758758
759− ext_sz = FFMIN(sizeof(AVDOVIDmData), metadata->ext_block_size);
760− for (int i = 0; i < metadata->num_ext_blocks; i++)
761− memcpy(&s->ext_blocks[i], av_dovi_get_ext(metadata, i), ext_sz);
762− s->num_ext_blocks = metadata->num_ext_blocks;
759+ if (ext) {
760+ size_t ext_sz = FFMIN(sizeof(AVDOVIDmData), metadata->ext_block_size);
761+ for (int i = 0; i < metadata->num_ext_blocks; i++)
762+ memcpy(&ext->dm[i], av_dovi_get_ext(metadata, i), ext_sz);
763+ ext->num_dm = metadata->num_ext_blocks;
764+ }
763765 } else {
764766 s->color = &ff_dovi_color_default;
765− s->num_ext_blocks = 0;
767+ ff_refstruct_unref(&s->ext_blocks);
766768 }
767769
768770 flush_put_bits(pb);

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