You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
paf: decode directly to the user-provided AVFrame
Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
@@ -377,22 +377,14 @@ static av_cold int paf_vid_close(AVCodecContext *avctx)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct PAFAudioDecContext {
|
|
||||||
AVFrame frame;
|
|
||||||
} PAFAudioDecContext;
|
|
||||||
|
|
||||||
static av_cold int paf_aud_init(AVCodecContext *avctx)
|
static av_cold int paf_aud_init(AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
PAFAudioDecContext *c = avctx->priv_data;
|
|
||||||
|
|
||||||
if (avctx->channels != 2) {
|
if (avctx->channels != 2) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
|
av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
avcodec_get_frame_defaults(&c->frame);
|
|
||||||
avctx->channel_layout = AV_CH_LAYOUT_STEREO;
|
avctx->channel_layout = AV_CH_LAYOUT_STEREO;
|
||||||
avctx->coded_frame = &c->frame;
|
|
||||||
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
|
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -401,7 +393,7 @@ static av_cold int paf_aud_init(AVCodecContext *avctx)
|
|||||||
static int paf_aud_decode(AVCodecContext *avctx, void *data,
|
static int paf_aud_decode(AVCodecContext *avctx, void *data,
|
||||||
int *got_frame_ptr, AVPacket *pkt)
|
int *got_frame_ptr, AVPacket *pkt)
|
||||||
{
|
{
|
||||||
PAFAudioDecContext *c = avctx->priv_data;
|
AVFrame *frame = data;
|
||||||
uint8_t *buf = pkt->data;
|
uint8_t *buf = pkt->data;
|
||||||
int16_t *output_samples;
|
int16_t *output_samples;
|
||||||
const uint8_t *t;
|
const uint8_t *t;
|
||||||
@@ -411,11 +403,11 @@ static int paf_aud_decode(AVCodecContext *avctx, void *data,
|
|||||||
if (frames < 1)
|
if (frames < 1)
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
|
|
||||||
c->frame.nb_samples = PAF_SOUND_SAMPLES * frames;
|
frame->nb_samples = PAF_SOUND_SAMPLES * frames;
|
||||||
if ((ret = ff_get_buffer(avctx, &c->frame)) < 0)
|
if ((ret = ff_get_buffer(avctx, frame)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
output_samples = (int16_t *)c->frame.data[0];
|
output_samples = (int16_t *)frame->data[0];
|
||||||
for (i = 0; i < frames; i++) {
|
for (i = 0; i < frames; i++) {
|
||||||
t = buf + 256 * sizeof(uint16_t);
|
t = buf + 256 * sizeof(uint16_t);
|
||||||
for (j = 0; j < PAF_SOUND_SAMPLES; j++) {
|
for (j = 0; j < PAF_SOUND_SAMPLES; j++) {
|
||||||
@@ -428,7 +420,6 @@ static int paf_aud_decode(AVCodecContext *avctx, void *data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
*got_frame_ptr = 1;
|
*got_frame_ptr = 1;
|
||||||
*(AVFrame *)data = c->frame;
|
|
||||||
|
|
||||||
return pkt->size;
|
return pkt->size;
|
||||||
}
|
}
|
||||||
@@ -449,7 +440,6 @@ AVCodec ff_paf_audio_decoder = {
|
|||||||
.name = "paf_audio",
|
.name = "paf_audio",
|
||||||
.type = AVMEDIA_TYPE_AUDIO,
|
.type = AVMEDIA_TYPE_AUDIO,
|
||||||
.id = AV_CODEC_ID_PAF_AUDIO,
|
.id = AV_CODEC_ID_PAF_AUDIO,
|
||||||
.priv_data_size = sizeof(PAFAudioDecContext),
|
|
||||||
.init = paf_aud_init,
|
.init = paf_aud_init,
|
||||||
.decode = paf_aud_decode,
|
.decode = paf_aud_decode,
|
||||||
.capabilities = CODEC_CAP_DR1,
|
.capabilities = CODEC_CAP_DR1,
|
||||||
|
Reference in New Issue
Block a user