s302m: decode directly to the user-provided AVFrame
This commit is contained in:
parent
79fb2a1f17
commit
5d5c248c3d
@ -28,10 +28,6 @@
|
||||
|
||||
#define AES3_HEADER_LEN 4
|
||||
|
||||
typedef struct S302MDecodeContext {
|
||||
AVFrame frame;
|
||||
} S302MDecodeContext;
|
||||
|
||||
static int s302m_parse_frame_header(AVCodecContext *avctx, const uint8_t *buf,
|
||||
int buf_size)
|
||||
{
|
||||
@ -82,7 +78,7 @@ static int s302m_parse_frame_header(AVCodecContext *avctx, const uint8_t *buf,
|
||||
static int s302m_decode_frame(AVCodecContext *avctx, void *data,
|
||||
int *got_frame_ptr, AVPacket *avpkt)
|
||||
{
|
||||
S302MDecodeContext *s = avctx->priv_data;
|
||||
AVFrame *frame = data;
|
||||
const uint8_t *buf = avpkt->data;
|
||||
int buf_size = avpkt->size;
|
||||
int block_size, ret;
|
||||
@ -96,16 +92,16 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data,
|
||||
|
||||
/* get output buffer */
|
||||
block_size = (avctx->bits_per_coded_sample + 4) / 4;
|
||||
s->frame.nb_samples = 2 * (buf_size / block_size) / avctx->channels;
|
||||
if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
|
||||
frame->nb_samples = 2 * (buf_size / block_size) / avctx->channels;
|
||||
if ((ret = ff_get_buffer(avctx, frame)) < 0) {
|
||||
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
buf_size = (s->frame.nb_samples * avctx->channels / 2) * block_size;
|
||||
buf_size = (frame->nb_samples * avctx->channels / 2) * block_size;
|
||||
|
||||
if (avctx->bits_per_coded_sample == 24) {
|
||||
uint32_t *o = (uint32_t *)s->frame.data[0];
|
||||
uint32_t *o = (uint32_t *)frame->data[0];
|
||||
for (; buf_size > 6; buf_size -= 7) {
|
||||
*o++ = (ff_reverse[buf[2]] << 24) |
|
||||
(ff_reverse[buf[1]] << 16) |
|
||||
@ -117,7 +113,7 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data,
|
||||
buf += 7;
|
||||
}
|
||||
} else if (avctx->bits_per_coded_sample == 20) {
|
||||
uint32_t *o = (uint32_t *)s->frame.data[0];
|
||||
uint32_t *o = (uint32_t *)frame->data[0];
|
||||
for (; buf_size > 5; buf_size -= 6) {
|
||||
*o++ = (ff_reverse[buf[2] & 0xf0] << 28) |
|
||||
(ff_reverse[buf[1]] << 20) |
|
||||
@ -128,7 +124,7 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data,
|
||||
buf += 6;
|
||||
}
|
||||
} else {
|
||||
uint16_t *o = (uint16_t *)s->frame.data[0];
|
||||
uint16_t *o = (uint16_t *)frame->data[0];
|
||||
for (; buf_size > 4; buf_size -= 5) {
|
||||
*o++ = (ff_reverse[buf[1]] << 8) |
|
||||
ff_reverse[buf[0]];
|
||||
@ -139,29 +135,15 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data,
|
||||
}
|
||||
}
|
||||
|
||||
*got_frame_ptr = 1;
|
||||
*(AVFrame *)data = s->frame;
|
||||
*got_frame_ptr = 1;
|
||||
|
||||
return avpkt->size;
|
||||
}
|
||||
|
||||
static int s302m_decode_init(AVCodecContext *avctx)
|
||||
{
|
||||
S302MDecodeContext *s = avctx->priv_data;
|
||||
|
||||
avcodec_get_frame_defaults(&s->frame);
|
||||
avctx->coded_frame = &s->frame;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
AVCodec ff_s302m_decoder = {
|
||||
.name = "s302m",
|
||||
.type = AVMEDIA_TYPE_AUDIO,
|
||||
.id = AV_CODEC_ID_S302M,
|
||||
.priv_data_size = sizeof(S302MDecodeContext),
|
||||
.init = s302m_decode_init,
|
||||
.decode = s302m_decode_frame,
|
||||
.capabilities = CODEC_CAP_DR1,
|
||||
.long_name = NULL_IF_CONFIG_SMALL("SMPTE 302M"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user