It avoids allocations and the corresponding error checks. Also avoids casts and indirections.
Showing the changes to libavcodec (3 of 3 files). Show all
Unified · Split
| @@ -26,6 +26,7 @@ · 25 unmodified lines | |||
| 26 | #include "dovi_rpu.h" | 26 | #include "dovi_rpu.h" |
| 27 | #include "golomb.h" | 27 | #include "golomb.h" |
| 28 | #include "get_bits.h" | 28 | #include "get_bits.h" |
| 29 | #include "refstruct.h" | ||
| 29 | 30 | ||
| 30 | enum { | 31 | enum { |
| 31 | RPU_COEFF_FIXED = 0, | 32 | RPU_COEFF_FIXED = 0, |
| @@ -33,17 +34,17 @@ enum { · 1 unmodified line | |||
| 33 | }; | 34 | }; |
| 34 | 35 | ||
| 35 | /** | 36 | /** |
| 36 | * Private contents of vdr_ref. | 37 | * Private contents of vdr. |
| 37 | */ | 38 | */ |
| 38 | typedef struct DOVIVdrRef { | 39 | typedef struct DOVIVdr { |
| 39 | AVDOVIDataMapping mapping; | 40 | AVDOVIDataMapping mapping; |
| 40 | AVDOVIColorMetadata color; | 41 | AVDOVIColorMetadata color; |
| 41 | } DOVIVdrRef; | 42 | } DOVIVdr; |
| 42 | 43 | ||
| 43 | void ff_dovi_ctx_unref(DOVIContext *s) | 44 | void ff_dovi_ctx_unref(DOVIContext *s) |
| 44 | { | 45 | { |
| 45 | for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr_ref); i++) | 46 | for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++) |
| 46 | av_buffer_unref(&s->vdr_ref[i]); | 47 | ff_refstruct_unref(&s->vdr[i]); |
| 47 | 48 | ||
| 48 | *s = (DOVIContext) { | 49 | *s = (DOVIContext) { |
| 49 | .logctx = s->logctx, | 50 | .logctx = s->logctx, |
| @@ -52,8 +53,8 @@ void ff_dovi_ctx_unref(DOVIContext *s) · 2 unmodified lines | |||
| 52 | 53 | ||
| 53 | void ff_dovi_ctx_flush(DOVIContext *s) | 54 | void ff_dovi_ctx_flush(DOVIContext *s) |
| 54 | { | 55 | { |
| 55 | for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr_ref); i++) | 56 | for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++) |
| 56 | av_buffer_unref(&s->vdr_ref[i]); | 57 | ff_refstruct_unref(&s->vdr[i]); |
| 57 | 58 | ||
| 58 | *s = (DOVIContext) { | 59 | *s = (DOVIContext) { |
| 59 | .logctx = s->logctx, | 60 | .logctx = s->logctx, |
| @@ -61,23 +62,14 @@ void ff_dovi_ctx_flush(DOVIContext *s) · 1 unmodified line | |||
| 61 | }; | 62 | }; |
| 62 | } | 63 | } |
| 63 | 64 | ||
| 64 | int ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0) | 65 | void ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0) |
| 65 | { | 66 | { |
| 66 | int ret; | ||
| 67 | s->logctx = s0->logctx; | 67 | s->logctx = s0->logctx; |
| 68 | s->mapping = s0->mapping; | 68 | s->mapping = s0->mapping; |
| 69 | s->color = s0->color; | 69 | s->color = s0->color; |
| 70 | s->dv_profile = s0->dv_profile; | 70 | s->dv_profile = s0->dv_profile; |
| 71 | for (int i = 0; i < DOVI_MAX_DM_ID; i++) { | 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) | 72 | ff_refstruct_replace(&s->vdr[i], s0->vdr[i]); |
| 73 | goto fail; | ||
| 74 | } | ||
| 75 | |||
| 76 | return 0; | ||
| 77 | |||
| 78 | fail: | ||
| 79 | ff_dovi_ctx_unref(s); | ||
| 80 | return ret; | ||
| 81 | } | 73 | } |
| 82 | 74 | ||
| 83 | void ff_dovi_update_cfg(DOVIContext *s, const AVDOVIDecoderConfigurationRecord *cfg) | 75 | 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 | |||
| 195 | { | 187 | { |
| 196 | AVDOVIRpuDataHeader *hdr = &s->header; | 188 | AVDOVIRpuDataHeader *hdr = &s->header; |
| 197 | GetBitContext *gb = &(GetBitContext){0}; | 189 | GetBitContext *gb = &(GetBitContext){0}; |
| 198 | DOVIVdrRef *vdr; | 190 | DOVIVdr *vdr; |
| 199 | int ret; | 191 | int ret; |
| 200 | 192 | ||
| 201 | uint8_t nal_prefix; | 193 | 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 | |||
| 278 | if (use_prev_vdr_rpu) { | 270 | if (use_prev_vdr_rpu) { |
| 279 | int prev_vdr_rpu_id = get_ue_golomb_31(gb); | 271 | int prev_vdr_rpu_id = get_ue_golomb_31(gb); |
| 280 | VALIDATE(prev_vdr_rpu_id, 0, DOVI_MAX_DM_ID); | 272 | 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]) { |
| 282 | av_log(s->logctx, AV_LOG_ERROR, "Unknown previous RPU ID: %u\n", | 274 | av_log(s->logctx, AV_LOG_ERROR, "Unknown previous RPU ID: %u\n", |
| 283 | prev_vdr_rpu_id); | 275 | prev_vdr_rpu_id); |
| 284 | goto fail; | 276 | goto fail; |
| 285 | } | 277 | } |
| 286 | vdr = (DOVIVdrRef *) s->vdr_ref[prev_vdr_rpu_id]->data; | 278 | vdr = s->vdr[prev_vdr_rpu_id]; |
| 287 | s->mapping = &vdr->mapping; | 279 | s->mapping = &vdr->mapping; |
| 288 | } else { | 280 | } else { |
| 289 | int vdr_rpu_id = get_ue_golomb_31(gb); | 281 | int vdr_rpu_id = get_ue_golomb_31(gb); |
| 290 | VALIDATE(vdr_rpu_id, 0, DOVI_MAX_DM_ID); | 282 | VALIDATE(vdr_rpu_id, 0, DOVI_MAX_DM_ID); |
| 291 | if (!s->vdr_ref[vdr_rpu_id]) { | 283 | if (!s->vdr[vdr_rpu_id]) { |
| 292 | s->vdr_ref[vdr_rpu_id] = av_buffer_allocz(sizeof(DOVIVdrRef)); | 284 | s->vdr[vdr_rpu_id] = ff_refstruct_allocz(sizeof(DOVIVdr)); |
| 293 | if (!s->vdr_ref[vdr_rpu_id]) | 285 | if (!s->vdr[vdr_rpu_id]) |
| 294 | return AVERROR(ENOMEM); | 286 | return AVERROR(ENOMEM); |
| 295 | } | 287 | } |
| 296 | 288 | ||
| 297 | vdr = (DOVIVdrRef *) s->vdr_ref[vdr_rpu_id]->data; | 289 | vdr = s->vdr[vdr_rpu_id]; |
| 298 | s->mapping = &vdr->mapping; | 290 | s->mapping = &vdr->mapping; |
| 299 | 291 | ||
| 300 | vdr->mapping.vdr_rpu_id = vdr_rpu_id; | 292 | 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 | |||
| 390 | int current_dm_id = get_ue_golomb_31(gb); | 382 | int current_dm_id = get_ue_golomb_31(gb); |
| 391 | VALIDATE(affected_dm_id, 0, DOVI_MAX_DM_ID); | 383 | VALIDATE(affected_dm_id, 0, DOVI_MAX_DM_ID); |
| 392 | VALIDATE(current_dm_id, 0, DOVI_MAX_DM_ID); | 384 | VALIDATE(current_dm_id, 0, DOVI_MAX_DM_ID); |
| 393 | if (!s->vdr_ref[affected_dm_id]) { | 385 | if (!s->vdr[affected_dm_id]) { |
| 394 | s->vdr_ref[affected_dm_id] = av_buffer_allocz(sizeof(DOVIVdrRef)); | 386 | s->vdr[affected_dm_id] = ff_refstruct_allocz(sizeof(DOVIVdr)); |
| 395 | if (!s->vdr_ref[affected_dm_id]) | 387 | if (!s->vdr[affected_dm_id]) |
| 396 | return AVERROR(ENOMEM); | 388 | return AVERROR(ENOMEM); |
| 397 | } | 389 | } |
| 398 | 390 | ||
| 399 | if (!s->vdr_ref[current_dm_id]) { | 391 | if (!s->vdr[current_dm_id]) { |
| 400 | av_log(s->logctx, AV_LOG_ERROR, "Unknown previous RPU DM ID: %u\n", | 392 | av_log(s->logctx, AV_LOG_ERROR, "Unknown previous RPU DM ID: %u\n", |
| 401 | current_dm_id); | 393 | current_dm_id); |
| 402 | goto fail; | 394 | goto fail; |
| 403 | } | 395 | } |
| 404 | 396 | ||
| 405 | /* Update current pointer based on current_dm_id */ | 397 | /* 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]; |
| 407 | s->color = &vdr->color; | 399 | s->color = &vdr->color; |
| 408 | 400 | ||
| 409 | /* Update values of affected_dm_id */ | 401 | /* Update values of affected_dm_id */ |
| 410 | vdr = (DOVIVdrRef *) s->vdr_ref[affected_dm_id]->data; | 402 | vdr = s->vdr[affected_dm_id]; |
| 411 | color = &vdr->color; | 403 | color = &vdr->color; |
| 412 | color->dm_metadata_id = affected_dm_id; | 404 | color->dm_metadata_id = affected_dm_id; |
| 413 | color->scene_refresh_flag = get_ue_golomb_31(gb); | 405 | color->scene_refresh_flag = get_ue_golomb_31(gb); |
| @@ -47,12 +47,12 @@ typedef struct DOVIContext { · 46 unmodified lines | |||
| 47 | /** | 47 | /** |
| 48 | * Private fields internal to dovi_rpu.c | 48 | * Private fields internal to dovi_rpu.c |
| 49 | */ | 49 | */ |
| 50 | AVBufferRef *vdr_ref[DOVI_MAX_DM_ID+1]; | 50 | struct DOVIVdr *vdr[DOVI_MAX_DM_ID+1]; ///< RefStruct references |
| 51 | uint8_t dv_profile; | 51 | uint8_t dv_profile; |
| 52 | 52 | ||
| 53 | } DOVIContext; | 53 | } DOVIContext; |
| 54 | 54 | ||
| 55 | int ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0); | 55 | void ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0); |
| 56 | 56 | ||
| 57 | /** | 57 | /** |
| 58 | * Completely reset a DOVIContext, preserving only logctx. | 58 | * Completely reset a DOVIContext, preserving only logctx. |
| @@ -3596,9 +3596,7 @@ static int hevc_update_thread_context(AVCodecContext *dst, · 3595 unmodified lines | |||
| 3596 | if (ret < 0) | 3596 | if (ret < 0) |
| 3597 | return ret; | 3597 | return ret; |
| 3598 | 3598 | ||
| 3599 | ret = ff_dovi_ctx_replace(&s->dovi_ctx, &s0->dovi_ctx); | 3599 | ff_dovi_ctx_replace(&s->dovi_ctx, &s0->dovi_ctx); |
| 3600 | if (ret < 0) | ||
| 3601 | return ret; | ||
| 3602 | 3600 | ||
| 3603 | ret = av_buffer_replace(&s->sei.common.dynamic_hdr_vivid.info, | 3601 | ret = av_buffer_replace(&s->sei.common.dynamic_hdr_vivid.info, |
| 3604 | s0->sei.common.dynamic_hdr_vivid.info); | 3602 | s0->sei.common.dynamic_hdr_vivid.info); |