History

avcodec/dovi_rpu: Use RefStruct API for Vdr data

It avoids allocations and the corresponding error checks. Also avoids casts and indirections.

Andreas Rheinhardt committed 4 years ago

Commit 61bc8761 parent 05f557b3 files · +27 −37Browse files

Unified · Split

3 files
  1. libavcodec/dovi_rpu.c +24 −32
  2. libavcodec/dovi_rpu.h +2 −2
  3. libavcodec/hevcdec.c +1 −3
libavcodec/dovi_rpu.c+24−32
@@ -26,6 +26,7 @@ · 25 unmodified lines
2626 #include "dovi_rpu.h"
2727 #include "golomb.h"
2828 #include "get_bits.h"
29+#include "refstruct.h"
2930
3031 enum {
3132 RPU_COEFF_FIXED = 0,
@@ -33,17 +34,17 @@ enum { · 1 unmodified line
3334 };
3435
3536 /**
36− * Private contents of vdr_ref.
37+ * Private contents of vdr.
3738 */
38−typedef struct DOVIVdrRef {
39+typedef struct DOVIVdr {
3940 AVDOVIDataMapping mapping;
4041 AVDOVIColorMetadata color;
41−} DOVIVdrRef;
42+} DOVIVdr;
4243
4344 void ff_dovi_ctx_unref(DOVIContext *s)
4445 {
45− for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr_ref); i++)
46− av_buffer_unref(&s->vdr_ref[i]);
46+ for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++)
47+ ff_refstruct_unref(&s->vdr[i]);
4748
4849 *s = (DOVIContext) {
4950 .logctx = s->logctx,
@@ -52,8 +53,8 @@ void ff_dovi_ctx_unref(DOVIContext *s) · 2 unmodified lines
5253
5354 void ff_dovi_ctx_flush(DOVIContext *s)
5455 {
55− for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr_ref); i++)
56− av_buffer_unref(&s->vdr_ref[i]);
56+ for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++)
57+ ff_refstruct_unref(&s->vdr[i]);
5758
5859 *s = (DOVIContext) {
5960 .logctx = s->logctx,
@@ -61,23 +62,14 @@ void ff_dovi_ctx_flush(DOVIContext *s) · 1 unmodified line
6162 };
6263 }
6364
64−int ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0)
65+void ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0)
6566 {
66− int ret;
6767 s->logctx = s0->logctx;
6868 s->mapping = s0->mapping;
6969 s->color = s0->color;
7070 s->dv_profile = s0->dv_profile;
71− for (int i = 0; i < DOVI_MAX_DM_ID; i++) {
72− if ((ret = av_buffer_replace(&s->vdr_ref[i], s0->vdr_ref[i])) < 0)
73− goto fail;
74− }
75−
76− return 0;
77−
78−fail:
79− ff_dovi_ctx_unref(s);
80− return ret;
71+ for (int i = 0; i < DOVI_MAX_DM_ID; i++)
72+ ff_refstruct_replace(&s->vdr[i], s0->vdr[i]);
8173 }
8274
8375 void ff_dovi_update_cfg(DOVIContext *s, const AVDOVIDecoderConfigurationRecord *cfg)
@@ -195,7 +187,7 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size) · 111 unmodified lines
195187 {
196188 AVDOVIRpuDataHeader *hdr = &s->header;
197189 GetBitContext *gb = &(GetBitContext){0};
198− DOVIVdrRef *vdr;
190+ DOVIVdr *vdr;
199191 int ret;
200192
201193 uint8_t nal_prefix;
@@ -278,23 +270,23 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size) · 76 unmodified lines
278270 if (use_prev_vdr_rpu) {
279271 int prev_vdr_rpu_id = get_ue_golomb_31(gb);
280272 VALIDATE(prev_vdr_rpu_id, 0, DOVI_MAX_DM_ID);
281− if (!s->vdr_ref[prev_vdr_rpu_id]) {
273+ if (!s->vdr[prev_vdr_rpu_id]) {
282274 av_log(s->logctx, AV_LOG_ERROR, "Unknown previous RPU ID: %u\n",
283275 prev_vdr_rpu_id);
284276 goto fail;
285277 }
286− vdr = (DOVIVdrRef *) s->vdr_ref[prev_vdr_rpu_id]->data;
278+ vdr = s->vdr[prev_vdr_rpu_id];
287279 s->mapping = &vdr->mapping;
288280 } else {
289281 int vdr_rpu_id = get_ue_golomb_31(gb);
290282 VALIDATE(vdr_rpu_id, 0, DOVI_MAX_DM_ID);
291− if (!s->vdr_ref[vdr_rpu_id]) {
292− s->vdr_ref[vdr_rpu_id] = av_buffer_allocz(sizeof(DOVIVdrRef));
293− if (!s->vdr_ref[vdr_rpu_id])
283+ if (!s->vdr[vdr_rpu_id]) {
284+ s->vdr[vdr_rpu_id] = ff_refstruct_allocz(sizeof(DOVIVdr));
285+ if (!s->vdr[vdr_rpu_id])
294286 return AVERROR(ENOMEM);
295287 }
296288
297− vdr = (DOVIVdrRef *) s->vdr_ref[vdr_rpu_id]->data;
289+ vdr = s->vdr[vdr_rpu_id];
298290 s->mapping = &vdr->mapping;
299291
300292 vdr->mapping.vdr_rpu_id = vdr_rpu_id;
@@ -390,24 +382,24 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size) · 89 unmodified lines
390382 int current_dm_id = get_ue_golomb_31(gb);
391383 VALIDATE(affected_dm_id, 0, DOVI_MAX_DM_ID);
392384 VALIDATE(current_dm_id, 0, DOVI_MAX_DM_ID);
393− if (!s->vdr_ref[affected_dm_id]) {
394− s->vdr_ref[affected_dm_id] = av_buffer_allocz(sizeof(DOVIVdrRef));
395− if (!s->vdr_ref[affected_dm_id])
385+ if (!s->vdr[affected_dm_id]) {
386+ s->vdr[affected_dm_id] = ff_refstruct_allocz(sizeof(DOVIVdr));
387+ if (!s->vdr[affected_dm_id])
396388 return AVERROR(ENOMEM);
397389 }
398390
399− if (!s->vdr_ref[current_dm_id]) {
391+ if (!s->vdr[current_dm_id]) {
400392 av_log(s->logctx, AV_LOG_ERROR, "Unknown previous RPU DM ID: %u\n",
401393 current_dm_id);
402394 goto fail;
403395 }
404396
405397 /* Update current pointer based on current_dm_id */
406− vdr = (DOVIVdrRef *) s->vdr_ref[current_dm_id]->data;
398+ vdr = s->vdr[current_dm_id];
407399 s->color = &vdr->color;
408400
409401 /* Update values of affected_dm_id */
410− vdr = (DOVIVdrRef *) s->vdr_ref[affected_dm_id]->data;
402+ vdr = s->vdr[affected_dm_id];
411403 color = &vdr->color;
412404 color->dm_metadata_id = affected_dm_id;
413405 color->scene_refresh_flag = get_ue_golomb_31(gb);
libavcodec/dovi_rpu.h+2−2
@@ -47,12 +47,12 @@ typedef struct DOVIContext { · 46 unmodified lines
4747 /**
4848 * Private fields internal to dovi_rpu.c
4949 */
50− AVBufferRef *vdr_ref[DOVI_MAX_DM_ID+1];
50+ struct DOVIVdr *vdr[DOVI_MAX_DM_ID+1]; ///< RefStruct references
5151 uint8_t dv_profile;
5252
5353 } DOVIContext;
5454
55−int ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0);
55+void ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0);
5656
5757 /**
5858 * Completely reset a DOVIContext, preserving only logctx.
libavcodec/hevcdec.c+1−3
@@ -3596,9 +3596,7 @@ static int hevc_update_thread_context(AVCodecContext *dst, · 3595 unmodified lines
35963596 if (ret < 0)
35973597 return ret;
35983598
3599− ret = ff_dovi_ctx_replace(&s->dovi_ctx, &s0->dovi_ctx);
3600− if (ret < 0)
3601− return ret;
3599+ ff_dovi_ctx_replace(&s->dovi_ctx, &s0->dovi_ctx);
36023600
36033601 ret = av_buffer_replace(&s->sei.common.dynamic_hdr_vivid.info,
36043602 s0->sei.common.dynamic_hdr_vivid.info);

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