History

lavc/hevcdec: use a ContainerFifo to hold frames scheduled for output

Instead of a single AVFrame. Will be useful in future commits, where we will want to produce multiple output frames for a single coded frame.

Anton Khirnov committed 2 years ago

Commit 79afc451 parent 4bda7f24 files · +28 −21Browse files

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

Unified · Split

4 files
  1. libavcodec/Makefile +1 −1
  2. libavcodec/hevc/hevcdec.c +21 −10
  3. libavcodec/hevc/hevcdec.h +2 −2
  4. libavcodec/hevc/refs.c +4 −8
libavcodec/Makefile+1−1
@@ -431,7 +431,7 @@ OBJS-$(CONFIG_HCA_DECODER) += hcadec.o · 430 unmodified lines
431431 OBJS-$(CONFIG_HCOM_DECODER) += hcom.o
432432 OBJS-$(CONFIG_HDR_DECODER) += hdrdec.o
433433 OBJS-$(CONFIG_HDR_ENCODER) += hdrenc.o
434−OBJS-$(CONFIG_HEVC_DECODER) += aom_film_grain.o h274.o
434+OBJS-$(CONFIG_HEVC_DECODER) += aom_film_grain.o h274.o container_fifo.o
435435 OBJS-$(CONFIG_HEVC_AMF_ENCODER) += amfenc_hevc.o
436436 OBJS-$(CONFIG_HEVC_CUVID_DECODER) += cuviddec.o
437437 OBJS-$(CONFIG_HEVC_D3D12VA_ENCODER) += d3d12va_encode_hevc.o h265_profile_level.o \
libavcodec/hevc/hevcdec.c+21−10
@@ -40,6 +40,7 @@ · 39 unmodified lines
4040 #include "bswapdsp.h"
4141 #include "cabac_functions.h"
4242 #include "codec_internal.h"
43+#include "container_fifo.h"
4344 #include "decode.h"
4445 #include "golomb.h"
4546 #include "hevc.h"
@@ -3007,6 +3008,10 @@ static int hevc_frame_start(HEVCContext *s) · 2961 unmodified lines
30073008 s->cur_frame->frame_grain->height = s->cur_frame->f->height;
30083009 if ((ret = ff_thread_get_buffer(s->avctx, s->cur_frame->frame_grain, 0)) < 0)
30093010 goto fail;
3011+
3012+ ret = av_frame_copy_props(s->cur_frame->frame_grain, s->cur_frame->f);
3013+ if (ret < 0)
3014+ goto fail;
30103015 }
30113016
30123017 s->cur_frame->f->pict_type = 3 - s->sh.slice_type;
@@ -3014,8 +3019,7 @@ static int hevc_frame_start(HEVCContext *s) · 1 unmodified line
30143019 if (!IS_IRAP(s))
30153020 ff_hevc_bump_frame(s);
30163021
3017− av_frame_unref(s->output_frame);
3018− ret = ff_hevc_output_frame(s, s->output_frame, 0);
3022+ ret = ff_hevc_output_frame(s, 0);
30193023 if (ret < 0)
30203024 goto fail;
30213025
@@ -3415,13 +3419,16 @@ static int hevc_receive_frame(AVCodecContext *avctx, AVFrame *frame) · 393 unmodified lines
34153419 uint8_t *sd;
34163420 size_t sd_size;
34173421
3422+ if (ff_container_fifo_can_read(s->output_fifo))
3423+ goto do_output;
3424+
34183425 av_packet_unref(avpkt);
34193426 ret = ff_decode_get_packet(avctx, avpkt);
34203427 if (ret == AVERROR_EOF) {
3421− ret = ff_hevc_output_frame(s, frame, 1);
3428+ ret = ff_hevc_output_frame(s, 1);
34223429 if (ret < 0)
34233430 return ret;
3424− return (ret > 0) ? 0 : AVERROR_EOF;
3431+ goto do_output;
34253432 } else if (ret < 0)
34263433 return ret;
34273434
@@ -3446,12 +3453,15 @@ static int hevc_receive_frame(AVCodecContext *avctx, AVFrame *frame) · 18 unmodified lines
34463453 if (ret < 0)
34473454 return ret;
34483455
3449− if (s->output_frame->buf[0]) {
3450− av_frame_move_ref(frame, s->output_frame);
3456+do_output:
3457+ if (ff_container_fifo_read(s->output_fifo, frame) >= 0) {
3458+ if (!(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN))
3459+ av_frame_remove_side_data(frame, AV_FRAME_DATA_FILM_GRAIN_PARAMS);
3460+
34513461 return 0;
34523462 }
34533463
3454− return AVERROR(EAGAIN);
3464+ return avci->draining ? AVERROR_EOF : AVERROR(EAGAIN);
34553465 }
34563466
34573467 static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src)
@@ -3503,7 +3513,8 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx) · 45 unmodified lines
35033513 av_freep(&s->sao_pixel_buffer_h[i]);
35043514 av_freep(&s->sao_pixel_buffer_v[i]);
35053515 }
3506− av_frame_free(&s->output_frame);
3516+
3517+ ff_container_fifo_free(&s->output_fifo);
35073518
35083519 for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
35093520 ff_hevc_unref_frame(&s->DPB[i], ~0);
@@ -3541,8 +3552,8 @@ static av_cold int hevc_init_context(AVCodecContext *avctx) · 31 unmodified lines
35413552 s->local_ctx[0].logctx = avctx;
35423553 s->local_ctx[0].common_cabac_state = &s->cabac;
35433554
3544− s->output_frame = av_frame_alloc();
3545− if (!s->output_frame)
3555+ s->output_fifo = ff_container_fifo_alloc_avframe(0);
3556+ if (!s->output_fifo)
35463557 return AVERROR(ENOMEM);
35473558
35483559 for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
libavcodec/hevc/hevcdec.h+2−2
@@ -457,7 +457,7 @@ typedef struct HEVCContext { · 456 unmodified lines
457457 /** 1 if the independent slice segment header was successfully parsed */
458458 uint8_t slice_initialized;
459459
460− AVFrame *output_frame;
460+ struct ContainerFifo *output_fifo;
461461 uint8_t *sao_pixel_buffer_h[3];
462462 uint8_t *sao_pixel_buffer_v[3];
463463
@@ -636,7 +636,7 @@ static av_always_inline int ff_hevc_nal_is_nonref(enum HEVCNALUnitType type) · 172 unmodified lines
636636 * Find next frame in output order and put a reference to it in frame.
637637 * @return 1 if a frame was output, 0 otherwise
638638 */
639−int ff_hevc_output_frame(HEVCContext *s, AVFrame *frame, int flush);
639+int ff_hevc_output_frame(HEVCContext *s, int flush);
640640
641641 void ff_hevc_bump_frame(HEVCContext *s);
642642
libavcodec/hevc/refs.c+4−8
@@ -23,6 +23,7 @@ · 22 unmodified lines
2323
2424 #include "libavutil/mem.h"
2525
26+#include "container_fifo.h"
2627 #include "decode.h"
2728 #include "hevc.h"
2829 #include "hevcdec.h"
@@ -171,7 +172,7 @@ static void unref_missing_refs(HEVCContext *s) · 142 unmodified lines
171172 }
172173 }
173174
174−int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, int flush)
175+int ff_hevc_output_frame(HEVCContext *s, int flush)
175176 {
176177 if (IS_IRAP(s) && s->no_rasl_output_flag == 1) {
177178 const static int mask = HEVC_FRAME_FLAG_BUMPING | HEVC_FRAME_FLAG_OUTPUT;
@@ -211,7 +212,8 @@ int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, int flush) · 33 unmodified lines
211212 if (nb_output) {
212213 HEVCFrame *frame = &s->DPB[min_idx];
213214
214− ret = av_frame_ref(out, frame->needs_fg ? frame->frame_grain : frame->f);
215+ ret = ff_container_fifo_write(s->output_fifo,
216+ frame->needs_fg ? frame->frame_grain : frame->f);
215217 if (frame->flags & HEVC_FRAME_FLAG_BUMPING)
216218 ff_hevc_unref_frame(frame, HEVC_FRAME_FLAG_OUTPUT | HEVC_FRAME_FLAG_BUMPING);
217219 else
@@ -219,12 +221,6 @@ int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, int flush) · 1 unmodified line
219221 if (ret < 0)
220222 return ret;
221223
222− if (frame->needs_fg && (ret = av_frame_copy_props(out, frame->f)) < 0)
223− return ret;
224−
225− if (!(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN))
226− av_frame_remove_side_data(out, AV_FRAME_DATA_FILM_GRAIN_PARAMS);
227−
228224 av_log(s->avctx, AV_LOG_DEBUG,
229225 "Output frame with POC %d.\n", frame->poc);
230226 return 1;

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