fftools/ffmpeg: move OutputStream.sq_frame to Encoder

It is audio/video encoding-only and does not need to be visible outside
of ffmpeg_enc.c
pull/389/head
Anton Khirnov 2 years ago
parent 710da200fc
commit 87ae84e4af
  1. 1
      fftools/ffmpeg.h
  2. 17
      fftools/ffmpeg_enc.c
  3. 1
      fftools/ffmpeg_mux.c
  4. 4
      fftools/ffmpeg_mux_init.c

@ -588,7 +588,6 @@ typedef struct OutputStream {
Encoder *enc; Encoder *enc;
AVCodecContext *enc_ctx; AVCodecContext *enc_ctx;
AVFrame *filtered_frame; AVFrame *filtered_frame;
AVFrame *sq_frame;
AVPacket *pkt; AVPacket *pkt;
int64_t last_dropped; int64_t last_dropped;
int64_t last_nb0_frames[3]; int64_t last_nb0_frames[3];

@ -50,6 +50,8 @@ struct Encoder {
AVFrame *last_frame; AVFrame *last_frame;
/* number of frames emitted by the video-encoding sync code */ /* number of frames emitted by the video-encoding sync code */
int64_t vsync_frame_number; int64_t vsync_frame_number;
AVFrame *sq_frame;
}; };
static uint64_t dup_warning = 1000; static uint64_t dup_warning = 1000;
@ -62,6 +64,7 @@ void enc_free(Encoder **penc)
return; return;
av_frame_free(&enc->last_frame); av_frame_free(&enc->last_frame);
av_frame_free(&enc->sq_frame);
av_freep(penc); av_freep(penc);
} }
@ -139,6 +142,7 @@ static void init_encoder_time_base(OutputStream *ost, AVRational default_time_ba
int enc_open(OutputStream *ost, AVFrame *frame) int enc_open(OutputStream *ost, AVFrame *frame)
{ {
InputStream *ist = ost->ist; InputStream *ist = ost->ist;
Encoder *e = ost->enc;
AVCodecContext *enc_ctx = ost->enc_ctx; AVCodecContext *enc_ctx = ost->enc_ctx;
AVCodecContext *dec_ctx = NULL; AVCodecContext *dec_ctx = NULL;
const AVCodec *enc = enc_ctx->codec; const AVCodec *enc = enc_ctx->codec;
@ -328,6 +332,12 @@ int enc_open(OutputStream *ost, AVFrame *frame)
return ret; return ret;
} }
if (ost->sq_idx_encode >= 0) {
e->sq_frame = av_frame_alloc();
if (!e->sq_frame)
return AVERROR(ENOMEM);
}
if (ost->enc_ctx->frame_size) { if (ost->enc_ctx->frame_size) {
av_assert0(ost->sq_idx_encode >= 0); av_assert0(ost->sq_idx_encode >= 0);
sq_frame_samples(output_files[ost->file_index]->sq_encode, sq_frame_samples(output_files[ost->file_index]->sq_encode,
@ -718,16 +728,17 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame)
static int submit_encode_frame(OutputFile *of, OutputStream *ost, static int submit_encode_frame(OutputFile *of, OutputStream *ost,
AVFrame *frame) AVFrame *frame)
{ {
Encoder *e = ost->enc;
int ret; int ret;
if (ost->sq_idx_encode < 0) if (ost->sq_idx_encode < 0)
return encode_frame(of, ost, frame); return encode_frame(of, ost, frame);
if (frame) { if (frame) {
ret = av_frame_ref(ost->sq_frame, frame); ret = av_frame_ref(e->sq_frame, frame);
if (ret < 0) if (ret < 0)
return ret; return ret;
frame = ost->sq_frame; frame = e->sq_frame;
} }
ret = sq_send(of->sq_encode, ost->sq_idx_encode, ret = sq_send(of->sq_encode, ost->sq_idx_encode,
@ -740,7 +751,7 @@ static int submit_encode_frame(OutputFile *of, OutputStream *ost,
} }
while (1) { while (1) {
AVFrame *enc_frame = ost->sq_frame; AVFrame *enc_frame = e->sq_frame;
ret = sq_receive(of->sq_encode, ost->sq_idx_encode, ret = sq_receive(of->sq_encode, ost->sq_idx_encode,
SQFRAME(enc_frame)); SQFRAME(enc_frame));

@ -663,7 +663,6 @@ static void ost_free(OutputStream **post)
av_bsf_free(&ms->bsf_ctx); av_bsf_free(&ms->bsf_ctx);
av_frame_free(&ost->filtered_frame); av_frame_free(&ost->filtered_frame);
av_frame_free(&ost->sq_frame);
av_packet_free(&ost->pkt); av_packet_free(&ost->pkt);
av_dict_free(&ost->encoder_opts); av_dict_free(&ost->encoder_opts);

@ -1505,10 +1505,6 @@ static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_u
if (ost->sq_idx_encode < 0) if (ost->sq_idx_encode < 0)
return ost->sq_idx_encode; return ost->sq_idx_encode;
ost->sq_frame = av_frame_alloc();
if (!ost->sq_frame)
return AVERROR(ENOMEM);
if (ms->max_frames != INT64_MAX) if (ms->max_frames != INT64_MAX)
sq_limit_frames(of->sq_encode, ost->sq_idx_encode, ms->max_frames); sq_limit_frames(of->sq_encode, ost->sq_idx_encode, ms->max_frames);
} }

Loading…
Cancel
Save