~ubuntu-branches/ubuntu/precise/libav/precise-updates

« back to all changes in this revision

Viewing changes to libavcodec/qdm2.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-01-12 22:30:00 UTC
  • mfrom: (1.2.8) (1.1.13 experimental)
  • Revision ID: package-import@ubuntu.com-20120112223000-cmfo7w78q13i2fd9
Tags: 4:0.8~beta2-1ubuntu1
* Merge from debian, remaining changes:
  - don't build against libdirac, lame, libopenjpeg, librtmp, 
    x264, and xvid  (all in universe)

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 * @file
27
27
 * QDM2 decoder
28
28
 * @author Ewald Snel, Benjamin Larsson, Alex Beregszaszi, Roberto Togni
 
29
 *
29
30
 * The decoder is not perfect yet, there are still some distortions
30
31
 * especially on files encoded with 16 or 8 subbands.
31
32
 */
34
35
#include <stddef.h>
35
36
#include <stdio.h>
36
37
 
37
 
#define ALT_BITSTREAM_READER_LE
 
38
#define BITSTREAM_READER_LE
38
39
#include "avcodec.h"
39
40
#include "get_bits.h"
40
41
#include "dsputil.h"
129
130
 * QDM2 decoder context
130
131
 */
131
132
typedef struct {
 
133
    AVFrame frame;
 
134
 
132
135
    /// Parameters from codec header, do not change during playback
133
136
    int nb_channels;         ///< number of channels
134
137
    int channels;            ///< number of channels
1874
1877
 
1875
1878
    avctx->sample_fmt = AV_SAMPLE_FMT_S16;
1876
1879
 
 
1880
    avcodec_get_frame_defaults(&s->frame);
 
1881
    avctx->coded_frame = &s->frame;
 
1882
 
1877
1883
//    dump_context(s);
1878
1884
    return 0;
1879
1885
}
1951
1957
}
1952
1958
 
1953
1959
 
1954
 
static int qdm2_decode_frame(AVCodecContext *avctx,
1955
 
            void *data, int *data_size,
1956
 
            AVPacket *avpkt)
 
1960
static int qdm2_decode_frame(AVCodecContext *avctx, void *data,
 
1961
                             int *got_frame_ptr, AVPacket *avpkt)
1957
1962
{
1958
1963
    const uint8_t *buf = avpkt->data;
1959
1964
    int buf_size = avpkt->size;
1960
1965
    QDM2Context *s = avctx->priv_data;
1961
 
    int16_t *out = data;
1962
 
    int i, out_size;
 
1966
    int16_t *out;
 
1967
    int i, ret;
1963
1968
 
1964
1969
    if(!buf)
1965
1970
        return 0;
1966
1971
    if(buf_size < s->checksum_size)
1967
1972
        return -1;
1968
1973
 
1969
 
    out_size = 16 * s->channels * s->frame_size *
1970
 
               av_get_bytes_per_sample(avctx->sample_fmt);
1971
 
    if (*data_size < out_size) {
1972
 
        av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n");
1973
 
        return AVERROR(EINVAL);
 
1974
    /* get output buffer */
 
1975
    s->frame.nb_samples = 16 * s->frame_size;
 
1976
    if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) {
 
1977
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
 
1978
        return ret;
1974
1979
    }
1975
 
 
1976
 
    av_log(avctx, AV_LOG_DEBUG, "decode(%d): %p[%d] -> %p[%d]\n",
1977
 
       buf_size, buf, s->checksum_size, data, *data_size);
 
1980
    out = (int16_t *)s->frame.data[0];
1978
1981
 
1979
1982
    for (i = 0; i < 16; i++) {
1980
1983
        if (qdm2_decode(s, buf, out) < 0)
1982
1985
        out += s->channels * s->frame_size;
1983
1986
    }
1984
1987
 
1985
 
    *data_size = out_size;
 
1988
    *got_frame_ptr   = 1;
 
1989
    *(AVFrame *)data = s->frame;
1986
1990
 
1987
1991
    return s->checksum_size;
1988
1992
}
1996
2000
    .init = qdm2_decode_init,
1997
2001
    .close = qdm2_decode_close,
1998
2002
    .decode = qdm2_decode_frame,
 
2003
    .capabilities = CODEC_CAP_DR1,
1999
2004
    .long_name = NULL_IF_CONFIG_SMALL("QDesign Music Codec 2"),
2000
2005
};