mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-02-20 22:06:59 +00:00
fftools/ffmpeg_dec: add decoder private data
Move InputStream.decoded_frame to it. Analogous to what has been previously done for all the other major components.
This commit is contained in:
parent
335688a3d3
commit
dadeb28e25
@ -324,6 +324,8 @@ typedef struct FilterGraph {
|
||||
int nb_outputs;
|
||||
} FilterGraph;
|
||||
|
||||
typedef struct Decoder Decoder;
|
||||
|
||||
typedef struct InputStream {
|
||||
const AVClass *class;
|
||||
|
||||
@ -343,10 +345,10 @@ typedef struct InputStream {
|
||||
* concurrently by the demuxing thread.
|
||||
*/
|
||||
AVCodecParameters *par;
|
||||
Decoder *decoder;
|
||||
AVCodecContext *dec_ctx;
|
||||
const AVCodec *dec;
|
||||
const AVCodecDescriptor *codec_desc;
|
||||
AVFrame *decoded_frame;
|
||||
AVPacket *pkt;
|
||||
|
||||
AVRational framerate_guessed;
|
||||
@ -812,6 +814,7 @@ AVBufferRef *hw_device_for_filter(void);
|
||||
int hwaccel_decode_init(AVCodecContext *avctx);
|
||||
|
||||
int dec_open(InputStream *ist);
|
||||
void dec_free(Decoder **pdec);
|
||||
|
||||
/**
|
||||
* Submit a packet for decoding
|
||||
|
@ -31,6 +31,45 @@
|
||||
|
||||
#include "ffmpeg.h"
|
||||
|
||||
struct Decoder {
|
||||
AVFrame *frame;
|
||||
};
|
||||
|
||||
void dec_free(Decoder **pdec)
|
||||
{
|
||||
Decoder *dec = *pdec;
|
||||
|
||||
if (!dec)
|
||||
return;
|
||||
|
||||
av_frame_free(&dec->frame);
|
||||
|
||||
av_freep(pdec);
|
||||
}
|
||||
|
||||
static int dec_alloc(Decoder **pdec)
|
||||
{
|
||||
Decoder *dec;
|
||||
|
||||
*pdec = NULL;
|
||||
|
||||
dec = av_mallocz(sizeof(*dec));
|
||||
if (!dec)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
dec->frame = av_frame_alloc();
|
||||
if (!dec->frame)
|
||||
goto fail;
|
||||
|
||||
|
||||
*pdec = dec;
|
||||
|
||||
return 0;
|
||||
fail:
|
||||
dec_free(&dec);
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
static int send_frame_to_filters(InputStream *ist, AVFrame *decoded_frame)
|
||||
{
|
||||
int i, ret;
|
||||
@ -373,6 +412,7 @@ static int send_filter_eof(InputStream *ist)
|
||||
|
||||
int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof)
|
||||
{
|
||||
Decoder *d = ist->decoder;
|
||||
AVCodecContext *dec = ist->dec_ctx;
|
||||
const char *type_desc = av_get_media_type_string(dec->codec_type);
|
||||
int ret;
|
||||
@ -407,7 +447,7 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof)
|
||||
}
|
||||
|
||||
while (1) {
|
||||
AVFrame *frame = ist->decoded_frame;
|
||||
AVFrame *frame = d->frame;
|
||||
|
||||
update_benchmark(NULL);
|
||||
ret = avcodec_receive_frame(dec, frame);
|
||||
@ -690,6 +730,10 @@ int dec_open(InputStream *ist)
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
|
||||
ret = dec_alloc(&ist->decoder);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ist->dec_ctx->opaque = ist;
|
||||
ist->dec_ctx->get_format = get_format;
|
||||
|
||||
|
@ -815,7 +815,8 @@ static void ist_free(InputStream **pist)
|
||||
if (!ist)
|
||||
return;
|
||||
|
||||
av_frame_free(&ist->decoded_frame);
|
||||
dec_free(&ist->decoder);
|
||||
|
||||
av_packet_free(&ist->pkt);
|
||||
av_dict_free(&ist->decoder_opts);
|
||||
avsubtitle_free(&ist->prev_sub.subtitle);
|
||||
@ -1196,10 +1197,6 @@ static void add_input_streams(const OptionsContext *o, Demuxer *d)
|
||||
exit_program(1);
|
||||
}
|
||||
|
||||
ist->decoded_frame = av_frame_alloc();
|
||||
if (!ist->decoded_frame)
|
||||
report_and_exit(AVERROR(ENOMEM));
|
||||
|
||||
ist->pkt = av_packet_alloc();
|
||||
if (!ist->pkt)
|
||||
report_and_exit(AVERROR(ENOMEM));
|
||||
|
Loading…
Reference in New Issue
Block a user