History

avcodec/h2645_sei: use the RefStruct API for film_grain_characteristics

And ensure the buffer is synced between threads. Based on a patch by Dale Curtis <dalecurtis@chromium.org>

James Almer committed 2 years ago

Commit e33b1621 parent fd4a2c95 files · +24 −10Browse files

Showing the changes to libavcodec (5 of 5 files). Show all

Unified · Split

5 files
  1. libavcodec/h2645_sei.c +12 −3
  2. libavcodec/h2645_sei.h +3 −1
  3. libavcodec/h264_sei.c +0 −1
  4. libavcodec/h264_slice.c +4 −1
  5. libavcodec/hevc/hevcdec.c +5 −4
libavcodec/h2645_sei.c+12−3
@@ -42,6 +42,7 @@ · 41 unmodified lines
4242 #include "golomb.h"
4343 #include "h2645_sei.h"
4444 #include "itut35.h"
45+#include "refstruct.h"
4546
4647 #define IS_H264(codec_id) (CONFIG_H264_SEI && CONFIG_HEVC_SEI ? codec_id == AV_CODEC_ID_H264 : CONFIG_H264_SEI)
4748 #define IS_HEVC(codec_id) (CONFIG_H264_SEI && CONFIG_HEVC_SEI ? codec_id == AV_CODEC_ID_HEVC : CONFIG_HEVC_SEI)
@@ -495,7 +496,11 @@ int ff_h2645_sei_message_decode(H2645SEI *h, enum SEIType type, · 447 unmodified lines
495496 case SEI_TYPE_DISPLAY_ORIENTATION:
496497 return decode_display_orientation(&h->display_orientation, gb);
497498 case SEI_TYPE_FILM_GRAIN_CHARACTERISTICS:
498− return decode_film_grain_characteristics(&h->film_grain_characteristics, codec_id, gb);
499+ ff_refstruct_unref(&h->film_grain_characteristics);
500+ h->film_grain_characteristics = ff_refstruct_allocz(sizeof(*h->film_grain_characteristics));
501+ if (!h->film_grain_characteristics)
502+ return AVERROR(ENOMEM);
503+ return decode_film_grain_characteristics(h->film_grain_characteristics, codec_id, gb);
499504 case SEI_TYPE_FRAME_PACKING_ARRANGEMENT:
500505 return decode_frame_packing_arrangement(&h->frame_packing, gb, codec_id);
501506 case SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS:
@@ -551,6 +556,9 @@ int ff_h2645_sei_ctx_replace(H2645SEI *dst, const H2645SEI *src) · 49 unmodified lines
551556 }
552557 dst->aom_film_grain.enable = src->aom_film_grain.enable;
553558
559+ ff_refstruct_replace(&dst->film_grain_characteristics,
560+ src->film_grain_characteristics);
561+
554562 return 0;
555563 }
556564
@@ -820,8 +828,8 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei, · 263 unmodified lines
820828 return ret;
821829 }
822830
823− if (sei->film_grain_characteristics.present) {
824− H2645SEIFilmGrainCharacteristics *fgc = &sei->film_grain_characteristics;
831+ if (sei->film_grain_characteristics && sei->film_grain_characteristics->present) {
832+ H2645SEIFilmGrainCharacteristics *fgc = sei->film_grain_characteristics;
825833 AVFilmGrainParams *fgp = av_film_grain_params_create_side_data(frame);
826834 AVFilmGrainH274Params *h274;
827835
@@ -923,5 +931,6 @@ void ff_h2645_sei_reset(H2645SEI *s) · 95 unmodified lines
923931 s->mastering_display.present = 0;
924932 s->content_light.present = 0;
925933
934+ ff_refstruct_unref(&s->film_grain_characteristics);
926935 ff_aom_uninit_film_grain_params(&s->aom_film_grain);
927936 }
libavcodec/h2645_sei.h+3−1
@@ -135,11 +135,13 @@ typedef struct H2645SEI { · 134 unmodified lines
135135 H2645SEIFramePacking frame_packing;
136136 H2645SEIDisplayOrientation display_orientation;
137137 H2645SEIAlternativeTransfer alternative_transfer;
138− H2645SEIFilmGrainCharacteristics film_grain_characteristics;
139138 H2645SEIAmbientViewingEnvironment ambient_viewing_environment;
140139 H2645SEIMasteringDisplay mastering_display;
141140 H2645SEIContentLight content_light;
142141 AVFilmGrainAFGS1Params aom_film_grain;
142+
143+ // Dynamic allocations due to large size.
144+ H2645SEIFilmGrainCharacteristics *film_grain_characteristics;
143145 } H2645SEI;
144146
145147 enum {
libavcodec/h264_sei.c+0−1
@@ -55,7 +55,6 @@ void ff_h264_sei_uninit(H264SEIContext *h) · 54 unmodified lines
5555 h->picture_timing.present = 0;
5656 h->buffering_period.present = 0;
5757 h->common.frame_packing.present = 0;
58− h->common.film_grain_characteristics.present = 0;
5958 h->common.display_orientation.present = 0;
6059 h->common.afd.present = 0;
6160
libavcodec/h264_slice.c+4−1
@@ -516,7 +516,10 @@ static int h264_frame_start(H264Context *h) · 515 unmodified lines
516516 pic->f->crop_top = h->crop_top;
517517 pic->f->crop_bottom = h->crop_bottom;
518518
519− pic->needs_fg = h->sei.common.film_grain_characteristics.present && !h->avctx->hwaccel &&
519+ pic->needs_fg =
520+ h->sei.common.film_grain_characteristics &&
521+ h->sei.common.film_grain_characteristics->present &&
522+ !h->avctx->hwaccel &&
520523 !(h->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN);
521524
522525 if ((ret = alloc_picture(h, pic)) < 0)
libavcodec/hevc/hevcdec.c+5−4
@@ -412,7 +412,7 @@ static int export_stream_params_from_sei(HEVCContext *s) · 411 unmodified lines
412412 avctx->color_trc = s->sei.common.alternative_transfer.preferred_transfer_characteristics;
413413 }
414414
415− if (s->sei.common.film_grain_characteristics.present ||
415+ if ((s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present) ||
416416 s->sei.common.aom_film_grain.enable)
417417 avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
418418
@@ -3267,7 +3267,8 @@ static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l, · 2848 unmodified lines
32673267 else
32683268 s->cur_frame->f->flags &= ~AV_FRAME_FLAG_KEY;
32693269
3270− s->cur_frame->needs_fg = (s->sei.common.film_grain_characteristics.present ||
3270+ s->cur_frame->needs_fg = ((s->sei.common.film_grain_characteristics &&
3271+ s->sei.common.film_grain_characteristics->present) ||
32713272 s->sei.common.aom_film_grain.enable) &&
32723273 !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) &&
32733274 !s->avctx->hwaccel;
@@ -3277,8 +3278,8 @@ static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l, · 3 unmodified lines
32773278 goto fail;
32783279
32793280 if (s->cur_frame->needs_fg &&
3280− (s->sei.common.film_grain_characteristics.present &&
3281− !ff_h274_film_grain_params_supported(s->sei.common.film_grain_characteristics.model_id,
3281+ (s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present &&
3282+ !ff_h274_film_grain_params_supported(s->sei.common.film_grain_characteristics->model_id,
32823283 s->cur_frame->f->format) ||
32833284 !av_film_grain_params_select(s->cur_frame->f))) {
32843285 av_log_once(s->avctx, AV_LOG_WARNING, AV_LOG_DEBUG, &s->film_grain_warning_shown,

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