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 | #include "golomb.h" | 42 | #include "golomb.h" |
| 43 | #include "h2645_sei.h" | 43 | #include "h2645_sei.h" |
| 44 | #include "itut35.h" | 44 | #include "itut35.h" |
| 45 | #include "refstruct.h" | ||
| 45 | 46 | ||
| 46 | #define IS_H264(codec_id) (CONFIG_H264_SEI && CONFIG_HEVC_SEI ? codec_id == AV_CODEC_ID_H264 : CONFIG_H264_SEI) | 47 | #define IS_H264(codec_id) (CONFIG_H264_SEI && CONFIG_HEVC_SEI ? codec_id == AV_CODEC_ID_H264 : CONFIG_H264_SEI) |
| 47 | #define IS_HEVC(codec_id) (CONFIG_H264_SEI && CONFIG_HEVC_SEI ? codec_id == AV_CODEC_ID_HEVC : CONFIG_HEVC_SEI) | 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 | case SEI_TYPE_DISPLAY_ORIENTATION: | 496 | case SEI_TYPE_DISPLAY_ORIENTATION: |
| 496 | return decode_display_orientation(&h->display_orientation, gb); | 497 | return decode_display_orientation(&h->display_orientation, gb); |
| 497 | case SEI_TYPE_FILM_GRAIN_CHARACTERISTICS: | 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 | case SEI_TYPE_FRAME_PACKING_ARRANGEMENT: | 504 | case SEI_TYPE_FRAME_PACKING_ARRANGEMENT: |
| 500 | return decode_frame_packing_arrangement(&h->frame_packing, gb, codec_id); | 505 | return decode_frame_packing_arrangement(&h->frame_packing, gb, codec_id); |
| 501 | case SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS: | 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 | dst->aom_film_grain.enable = src->aom_film_grain.enable; | 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 | return 0; | 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 | return ret; | 828 | return ret; |
| 821 | } | 829 | } |
| 822 | 830 | ||
| 823 | if (sei->film_grain_characteristics.present) { | 831 | if (sei->film_grain_characteristics && sei->film_grain_characteristics->present) { |
| 824 | H2645SEIFilmGrainCharacteristics *fgc = &sei->film_grain_characteristics; | 832 | H2645SEIFilmGrainCharacteristics *fgc = sei->film_grain_characteristics; |
| 825 | AVFilmGrainParams *fgp = av_film_grain_params_create_side_data(frame); | 833 | AVFilmGrainParams *fgp = av_film_grain_params_create_side_data(frame); |
| 826 | AVFilmGrainH274Params *h274; | 834 | AVFilmGrainH274Params *h274; |
| 827 | 835 | ||
| @@ -923,5 +931,6 @@ void ff_h2645_sei_reset(H2645SEI *s) · 95 unmodified lines | |||
| 923 | s->mastering_display.present = 0; | 931 | s->mastering_display.present = 0; |
| 924 | s->content_light.present = 0; | 932 | s->content_light.present = 0; |
| 925 | 933 | ||
| 934 | ff_refstruct_unref(&s->film_grain_characteristics); | ||
| 926 | ff_aom_uninit_film_grain_params(&s->aom_film_grain); | 935 | ff_aom_uninit_film_grain_params(&s->aom_film_grain); |
| 927 | } | 936 | } |
| @@ -135,11 +135,13 @@ typedef struct H2645SEI { · 134 unmodified lines | |||
| 135 | H2645SEIFramePacking frame_packing; | 135 | H2645SEIFramePacking frame_packing; |
| 136 | H2645SEIDisplayOrientation display_orientation; | 136 | H2645SEIDisplayOrientation display_orientation; |
| 137 | H2645SEIAlternativeTransfer alternative_transfer; | 137 | H2645SEIAlternativeTransfer alternative_transfer; |
| 138 | H2645SEIFilmGrainCharacteristics film_grain_characteristics; | ||
| 139 | H2645SEIAmbientViewingEnvironment ambient_viewing_environment; | 138 | H2645SEIAmbientViewingEnvironment ambient_viewing_environment; |
| 140 | H2645SEIMasteringDisplay mastering_display; | 139 | H2645SEIMasteringDisplay mastering_display; |
| 141 | H2645SEIContentLight content_light; | 140 | H2645SEIContentLight content_light; |
| 142 | AVFilmGrainAFGS1Params aom_film_grain; | 141 | AVFilmGrainAFGS1Params aom_film_grain; |
| 142 | |||
| 143 | // Dynamic allocations due to large size. | ||
| 144 | H2645SEIFilmGrainCharacteristics *film_grain_characteristics; | ||
| 143 | } H2645SEI; | 145 | } H2645SEI; |
| 144 | 146 | ||
| 145 | enum { | 147 | enum { |
| @@ -55,7 +55,6 @@ void ff_h264_sei_uninit(H264SEIContext *h) · 54 unmodified lines | |||
| 55 | h->picture_timing.present = 0; | 55 | h->picture_timing.present = 0; |
| 56 | h->buffering_period.present = 0; | 56 | h->buffering_period.present = 0; |
| 57 | h->common.frame_packing.present = 0; | 57 | h->common.frame_packing.present = 0; |
| 58 | h->common.film_grain_characteristics.present = 0; | ||
| 59 | h->common.display_orientation.present = 0; | 58 | h->common.display_orientation.present = 0; |
| 60 | h->common.afd.present = 0; | 59 | h->common.afd.present = 0; |
| 61 | 60 | ||
| @@ -516,7 +516,10 @@ static int h264_frame_start(H264Context *h) · 515 unmodified lines | |||
| 516 | pic->f->crop_top = h->crop_top; | 516 | pic->f->crop_top = h->crop_top; |
| 517 | pic->f->crop_bottom = h->crop_bottom; | 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 | !(h->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN); | 523 | !(h->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN); |
| 521 | 524 | ||
| 522 | if ((ret = alloc_picture(h, pic)) < 0) | 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 | avctx->color_trc = s->sei.common.alternative_transfer.preferred_transfer_characteristics; | 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 | s->sei.common.aom_film_grain.enable) | 416 | s->sei.common.aom_film_grain.enable) |
| 417 | avctx->properties |= FF_CODEC_PROPERTY_FILM_GRAIN; | 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 | else | 3267 | else |
| 3268 | s->cur_frame->f->flags &= ~AV_FRAME_FLAG_KEY; | 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 | s->sei.common.aom_film_grain.enable) && | 3272 | s->sei.common.aom_film_grain.enable) && |
| 3272 | !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) && | 3273 | !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) && |
| 3273 | !s->avctx->hwaccel; | 3274 | !s->avctx->hwaccel; |
| @@ -3277,8 +3278,8 @@ static int hevc_frame_start(HEVCContext *s, HEVCLayerContext *l, · 3 unmodified lines | |||
| 3277 | goto fail; | 3278 | goto fail; |
| 3278 | 3279 | ||
| 3279 | if (s->cur_frame->needs_fg && | 3280 | if (s->cur_frame->needs_fg && |
| 3280 | (s->sei.common.film_grain_characteristics.present && | 3281 | (s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present && |
| 3281 | !ff_h274_film_grain_params_supported(s->sei.common.film_grain_characteristics.model_id, | 3282 | !ff_h274_film_grain_params_supported(s->sei.common.film_grain_characteristics->model_id, |
| 3282 | s->cur_frame->f->format) || | 3283 | s->cur_frame->f->format) || |
| 3283 | !av_film_grain_params_select(s->cur_frame->f))) { | 3284 | !av_film_grain_params_select(s->cur_frame->f))) { |
| 3284 | av_log_once(s->avctx, AV_LOG_WARNING, AV_LOG_DEBUG, &s->film_grain_warning_shown, | 3285 | av_log_once(s->avctx, AV_LOG_WARNING, AV_LOG_DEBUG, &s->film_grain_warning_shown, |