* Shorten decoder
* Copyright (c) 2005 Jeff Muizelaar
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
typedef struct ShortenContext {
AVCodecContext *avctx;
+ AVFrame frame;
GetBitContext gb;
int min_framesize, max_framesize;
s->avctx = avctx;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+ avcodec_get_frame_defaults(&s->frame);
+ avctx->coded_frame = &s->frame;
+
return 0;
}
return 0;
}
-static int16_t * interleave_buffer(int16_t *samples, int nchan, int blocksize, int32_t **buffer) {
+static void interleave_buffer(int16_t *samples, int nchan, int blocksize,
+ int32_t **buffer)
+{
int i, chan;
for (i=0; i<blocksize; i++)
for (chan=0; chan < nchan; chan++)
*samples++ = av_clip_int16(buffer[chan][i]);
- return samples;
}
static const int fixed_coeffs[3][3] = {
s->lpcqoffset = 0;
s->blocksize = DEFAULT_BLOCK_SIZE;
- s->channels = 1;
s->nmean = -1;
s->version = get_bits(&s->gb, 8);
s->internal_ftype = get_uint(s, TYPESIZE);
return 0;
}
-static int shorten_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- AVPacket *avpkt)
+static int shorten_decode_frame(AVCodecContext *avctx, void *data,
+ int *got_frame_ptr, AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
ShortenContext *s = avctx->priv_data;
int i, input_buf_size = 0;
- int16_t *samples = data;
int ret;
/* allocate internal bitstream buffer */
/* do not decode until buffer has at least max_framesize bytes or
the end of the file has been reached */
if (buf_size < s->max_framesize && avpkt->data) {
- *data_size = 0;
+ *got_frame_ptr = 0;
return input_buf_size;
}
}
if (!s->got_header) {
if ((ret = read_header(s)) < 0)
return ret;
- *data_size = 0;
+ *got_frame_ptr = 0;
goto finish_frame;
}
/* if quit command was read previously, don't decode anything */
if (s->got_quit_command) {
- *data_size = 0;
+ *got_frame_ptr = 0;
return avpkt->size;
}
int len;
if (get_bits_left(&s->gb) < 3+FNSIZE) {
- *data_size = 0;
+ *got_frame_ptr = 0;
break;
}
if (cmd > FN_VERBATIM) {
av_log(avctx, AV_LOG_ERROR, "unknown shorten function %d\n", cmd);
- *data_size = 0;
+ *got_frame_ptr = 0;
break;
}
break;
}
if (cmd == FN_BLOCKSIZE || cmd == FN_QUIT) {
- *data_size = 0;
+ *got_frame_ptr = 0;
break;
}
} else {
/* if this is the last channel in the block, output the samples */
s->cur_chan++;
if (s->cur_chan == s->channels) {
- int out_size = s->blocksize * s->channels *
- av_get_bytes_per_sample(avctx->sample_fmt);
- if (*data_size < out_size) {
- av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n");
- return AVERROR(EINVAL);
+ /* get output buffer */
+ s->frame.nb_samples = s->blocksize;
+ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) {
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ return ret;
}
- samples = interleave_buffer(samples, s->channels, s->blocksize, s->decoded);
- *data_size = out_size;
+ /* interleave output */
+ interleave_buffer((int16_t *)s->frame.data[0], s->channels,
+ s->blocksize, s->decoded);
+
+ *got_frame_ptr = 1;
+ *(AVFrame *)data = s->frame;
}
}
}
if (s->cur_chan < s->channels)
- *data_size = 0;
+ *got_frame_ptr = 0;
finish_frame:
s->bitindex = get_bits_count(&s->gb) - 8*((get_bits_count(&s->gb))/8);
}
av_freep(&s->bitstream);
av_freep(&s->coeffs);
+
return 0;
}
.init = shorten_decode_init,
.close = shorten_decode_close,
.decode = shorten_decode_frame,
- .capabilities = CODEC_CAP_DELAY,
+ .capabilities = CODEC_CAP_DELAY | CODEC_CAP_DR1,
.long_name= NULL_IF_CONFIG_SMALL("Shorten"),
};