Commit 886b40b9 authored by Michael Niedermayer's avatar Michael Niedermayer

wmalossless: Switch to new audio API

Partially fixes Ticket1000
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent b240866c
...@@ -160,6 +160,7 @@ typedef struct WmallDecodeCtx { ...@@ -160,6 +160,7 @@ typedef struct WmallDecodeCtx {
/* generic decoder variables */ /* generic decoder variables */
AVCodecContext* avctx; ///< codec context for av_log AVCodecContext* avctx; ///< codec context for av_log
DSPContext dsp; ///< accelerated DSP functions DSPContext dsp; ///< accelerated DSP functions
AVFrame frame;
uint8_t frame_data[MAX_FRAMESIZE + uint8_t frame_data[MAX_FRAMESIZE +
FF_INPUT_BUFFER_PADDING_SIZE];///< compressed frame data FF_INPUT_BUFFER_PADDING_SIZE];///< compressed frame data
PutBitContext pb; ///< context for filling the frame_data buffer PutBitContext pb; ///< context for filling the frame_data buffer
...@@ -437,6 +438,9 @@ static av_cold int decode_init(AVCodecContext *avctx) ...@@ -437,6 +438,9 @@ static av_cold int decode_init(AVCodecContext *avctx)
return AVERROR_PATCHWELCOME; return AVERROR_PATCHWELCOME;
} }
avcodec_get_frame_defaults(&s->frame);
avctx->coded_frame = &s->frame;
avctx->channel_layout = channel_mask; avctx->channel_layout = channel_mask;
return 0; return 0;
} }
...@@ -1245,21 +1249,18 @@ static int decode_frame(WmallDecodeCtx *s) ...@@ -1245,21 +1249,18 @@ static int decode_frame(WmallDecodeCtx *s)
GetBitContext* gb = &s->gb; GetBitContext* gb = &s->gb;
int more_frames = 0; int more_frames = 0;
int len = 0; int len = 0;
int i; int i, ret;
int buffer_len;
/** check for potential output buffer overflow */ s->frame.nb_samples = s->samples_per_frame;
if (s->bits_per_sample == 16) if ((ret = s->avctx->get_buffer(s->avctx, &s->frame)) < 0) {
buffer_len = s->samples_16_end - s->samples_16;
else
buffer_len = s->samples_32_end - s->samples_32;
if (s->num_channels * s->samples_per_frame > buffer_len) {
/** return an error if no frame could be decoded at all */ /** return an error if no frame could be decoded at all */
av_log(s->avctx, AV_LOG_ERROR, av_log(s->avctx, AV_LOG_ERROR,
"not enough space for the output samples\n"); "not enough space for the output samples\n");
s->packet_loss = 1; s->packet_loss = 1;
return 0; return 0;
} }
s->samples_16 = (int16_t *)s->frame.data[0];
s->samples_32 = (int32_t *)s->frame.data[0];
/** get frame length */ /** get frame length */
if (s->len_prefix) if (s->len_prefix)
...@@ -1415,7 +1416,7 @@ static void save_bits(WmallDecodeCtx *s, GetBitContext* gb, int len, ...@@ -1415,7 +1416,7 @@ static void save_bits(WmallDecodeCtx *s, GetBitContext* gb, int len,
*@return number of bytes that were read from the input buffer *@return number of bytes that were read from the input buffer
*/ */
static int decode_packet(AVCodecContext *avctx, static int decode_packet(AVCodecContext *avctx,
void *data, int *data_size, AVPacket* avpkt) void *data, int *got_frame_ptr, AVPacket* avpkt)
{ {
WmallDecodeCtx *s = avctx->priv_data; WmallDecodeCtx *s = avctx->priv_data;
GetBitContext* gb = &s->pgb; GetBitContext* gb = &s->pgb;
...@@ -1426,15 +1427,6 @@ static int decode_packet(AVCodecContext *avctx, ...@@ -1426,15 +1427,6 @@ static int decode_packet(AVCodecContext *avctx,
int seekable_frame_in_packet; int seekable_frame_in_packet;
int spliced_packet; int spliced_packet;
if (s->bits_per_sample == 16) {
s->samples_16 = (int16_t *) data;
s->samples_16_end = (int16_t *) ((int8_t*)data + *data_size);
} else {
s->samples_32 = (void *) data;
s->samples_32_end = (void *) ((int8_t*)data + *data_size);
}
*data_size = 0;
if (s->packet_done || s->packet_loss) { if (s->packet_done || s->packet_loss) {
int seekable_frame_in_packet, spliced_packet; int seekable_frame_in_packet, spliced_packet;
s->packet_done = 0; s->packet_done = 0;
...@@ -1526,10 +1518,8 @@ static int decode_packet(AVCodecContext *avctx, ...@@ -1526,10 +1518,8 @@ static int decode_packet(AVCodecContext *avctx,
save_bits(s, gb, remaining_bits(s, gb), 0); save_bits(s, gb, remaining_bits(s, gb), 0);
} }
if (s->bits_per_sample == 16) *(AVFrame *)data = s->frame;
*data_size = (int8_t *)s->samples_16 - (int8_t *)data; *got_frame_ptr = 1;
else
*data_size = (int8_t *)s->samples_32 - (int8_t *)data;
s->packet_offset = get_bits_count(gb) & 7; s->packet_offset = get_bits_count(gb) & 7;
return (s->packet_loss) ? AVERROR_INVALIDDATA : get_bits_count(gb) >> 3; return (s->packet_loss) ? AVERROR_INVALIDDATA : get_bits_count(gb) >> 3;
...@@ -1564,6 +1554,6 @@ AVCodec ff_wmalossless_decoder = { ...@@ -1564,6 +1554,6 @@ AVCodec ff_wmalossless_decoder = {
.close = decode_end, .close = decode_end,
.decode = decode_packet, .decode = decode_packet,
.flush = flush, .flush = flush,
.capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_EXPERIMENTAL, .capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_EXPERIMENTAL | CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 9 Lossless"), .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 9 Lossless"),
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment