And ensure the buffer is synced between threads. Based on a patch by Dale Curtis <dalecurtis@chromium.org>
Unified · Split
| @@ -42,6 +42,7 @@ · 41 unmodified lines | ||
| 42 | 42 | #include "golomb.h" |
| 43 | 43 | #include "h2645_sei.h" |
| 44 | 44 | #include "itut35.h" |
| 45 | +#include "refstruct.h" | |
| 45 | 46 | |
| 46 | 47 | #define IS_H264(codec_id) (CONFIG_H264_SEI && CONFIG_HEVC_SEI ? codec_id == AV_CODEC_ID_H264 : CONFIG_H264_SEI) |
| 47 | 48 | #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 | ||
| 495 | 496 | case SEI_TYPE_DISPLAY_ORIENTATION: |
| 496 | 497 | return decode_display_orientation(&h->display_orientation, gb); |
| 497 | 498 | 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); | |
| 499 | 504 | case SEI_TYPE_FRAME_PACKING_ARRANGEMENT: |
| 500 | 505 | return decode_frame_packing_arrangement(&h->frame_packing, gb, codec_id); |
| 501 | 506 | case SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS: |
| @@ -551,6 +556,9 @@ int ff_h2645_sei_ctx_replace(H2645SEI *dst, const H2645SEI *src) · 49 unmodified lines | ||
| 551 | 556 | } |
| 552 | 557 | dst->aom_film_grain.enable = src->aom_film_grain.enable; |
| 553 | 558 | |
| 559 | + ff_refstruct_replace(&dst->film_grain_characteristics, | |
| 560 | + src->film_grain_characteristics); | |
| 561 | + | |
| 554 | 562 | return 0; |
| 555 | 563 | } |
| 556 | 564 | |
| @@ -820,8 +828,8 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei, · 263 unmodified lines | ||
| 820 | 828 | return ret; |
| 821 | 829 | } |
| 822 | 830 | |
| 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; | |
| 825 | 833 | AVFilmGrainParams *fgp = av_film_grain_params_create_side_data(frame); |
| 826 | 834 | AVFilmGrainH274Params *h274; |
| 827 | 835 | |
| @@ -923,5 +931,6 @@ void ff_h2645_sei_reset(H2645SEI *s) · 95 unmodified lines | ||
| 923 | 931 | s->mastering_display.present = 0; |
| 924 | 932 | s->content_light.present = 0; |
| 925 | 933 | |
| 934 | + ff_refstruct_unref(&s->film_grain_characteristics); | |
| 926 | 935 | ff_aom_uninit_film_grain_params(&s->aom_film_grain); |
| 927 | 936 | } |
| @@ -135,11 +135,13 @@ typedef struct H2645SEI { · 134 unmodified lines | ||
| 135 | 135 | H2645SEIFramePacking frame_packing; |
| 136 | 136 | H2645SEIDisplayOrientation display_orientation; |
| 137 | 137 | H2645SEIAlternativeTransfer alternative_transfer; |
| 138 | − H2645SEIFilmGrainCharacteristics film_grain_characteristics; | |
| 139 | 138 | H2645SEIAmbientViewingEnvironment ambient_viewing_environment; |
| 140 | 139 | H2645SEIMasteringDisplay mastering_display; |
| 141 | 140 | H2645SEIContentLight content_light; |
| 142 | 141 | AVFilmGrainAFGS1Params aom_film_grain; |
| 142 | + | |
| 143 | + // Dynamic allocations due to large size. | |
| 144 | + H2645SEIFilmGrainCharacteristics *film_grain_characteristics; | |
| 143 | 145 | } H2645SEI; |
| 144 | 146 | |
| 145 | 147 | enum { |
| @@ -55,7 +55,6 @@ void ff_h264_sei_uninit(H264SEIContext *h) · 54 unmodified lines | ||
| 55 | 55 | h->picture_timing.present = 0; |
| 56 | 56 | h->buffering_period.present = 0; |
| 57 | 57 | h->common.frame_packing.present = 0; |
| 58 | − h->common.film_grain_characteristics.present = 0; | |
| 59 | 58 | h->common.display_orientation.present = 0; |
| 60 | 59 | h->common.afd.present = 0; |
| 61 | 60 | |
| @@ -516,7 +516,10 @@ static int h264_frame_start(H264Context *h) · 515 unmodified lines | ||
| 516 | 516 | pic->f->crop_top = h->crop_top; |
| 517 | 517 | pic->f->crop_bottom = h->crop_bottom; |
| 518 | 518 | |
| 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 && | |
| 520 | 523 | !(h->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN); |
| 521 | 524 | |
| 522 | 525 | if ((ret = alloc_picture(h, pic)) < 0) |
| @@ -412,7 +412,7 @@ static int export_stream_params_from_sei(HEVCContext *s) · 411 unmodified lines | ||
| 412 | 412 | avctx->color_trc = s->sei.common.alternative_transfer.preferred_transfer_characteristics; |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | − if (s->sei.common.film_grain_characteristics.present || | |
| 415 | + if ((s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present) || | |
| 416 | 416 | s->sei.common.aom_film_grain.enable) |
| 417 | 417 | avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN; |
| 418 | 418 | |
| @@ -3267,7 +3267,8 @@ static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l, · 2848 unmodified lines | ||
| 3267 | 3267 | else |
| 3268 | 3268 | s->cur_frame->f->flags &= ~AV_FRAME_FLAG_KEY; |
| 3269 | 3269 | |
| 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) || | |
| 3271 | 3272 | s->sei.common.aom_film_grain.enable) && |
| 3272 | 3273 | !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) && |
| 3273 | 3274 | !s->avctx->hwaccel; |
| @@ -3277,8 +3278,8 @@ static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l, · 3 unmodified lines | ||
| 3277 | 3278 | goto fail; |
| 3278 | 3279 | |
| 3279 | 3280 | 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, | |
| 3282 | 3283 | s->cur_frame->f->format) || |
| 3283 | 3284 | !av_film_grain_params_select(s->cur_frame->f))) { |
| 3284 | 3285 | av_log_once(s->avctx, AV_LOG_WARNING, AV_LOG_DEBUG, &s->film_grain_warning_shown, |