~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavcodec/ra144dec.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-01-12 22:23:28 UTC
  • mfrom: (0.4.7 sid)
  • mto: This revision was merged to the branch mainline in revision 76.
  • Revision ID: package-import@ubuntu.com-20120112222328-8jqdyodym3p84ygu
Tags: 2:1.0~rc4.dfsg1+svn34540-1
* New upstream snapshot
* upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    ractx->lpc_coef[1] = ractx->lpc_tables[1];
39
39
 
40
40
    avctx->sample_fmt = AV_SAMPLE_FMT_S16;
 
41
 
 
42
    avcodec_get_frame_defaults(&ractx->frame);
 
43
    avctx->coded_frame = &ractx->frame;
 
44
 
41
45
    return 0;
42
46
}
43
47
 
54
58
}
55
59
 
56
60
/** Uncompress one block (20 bytes -> 160*2 bytes). */
57
 
static int ra144_decode_frame(AVCodecContext * avctx, void *vdata,
58
 
                              int *data_size, AVPacket *avpkt)
 
61
static int ra144_decode_frame(AVCodecContext * avctx, void *data,
 
62
                              int *got_frame_ptr, AVPacket *avpkt)
59
63
{
60
64
    const uint8_t *buf = avpkt->data;
61
65
    int buf_size = avpkt->size;
62
 
    static const uint8_t sizes[10] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2};
63
 
    unsigned int refl_rms[4];    // RMS of the reflection coefficients
64
 
    uint16_t block_coefs[4][10]; // LPC coefficients of each sub-block
65
 
    unsigned int lpc_refl[10];   // LPC reflection coefficients of the frame
 
66
    static const uint8_t sizes[LPC_ORDER] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2};
 
67
    unsigned int refl_rms[NBLOCKS];           // RMS of the reflection coefficients
 
68
    uint16_t block_coefs[NBLOCKS][LPC_ORDER]; // LPC coefficients of each sub-block
 
69
    unsigned int lpc_refl[LPC_ORDER];         // LPC reflection coefficients of the frame
66
70
    int i, j;
67
 
    int16_t *data = vdata;
 
71
    int ret;
 
72
    int16_t *samples;
68
73
    unsigned int energy;
69
74
 
70
75
    RA144Context *ractx = avctx->priv_data;
71
76
    GetBitContext gb;
72
77
 
73
 
    if (*data_size < 2*160)
74
 
        return -1;
 
78
    /* get output buffer */
 
79
    ractx->frame.nb_samples = NBLOCKS * BLOCKSIZE;
 
80
    if ((ret = avctx->get_buffer(avctx, &ractx->frame)) < 0) {
 
81
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
 
82
        return ret;
 
83
    }
 
84
    samples = (int16_t *)ractx->frame.data[0];
75
85
 
76
 
    if(buf_size < 20) {
 
86
    if(buf_size < FRAMESIZE) {
77
87
        av_log(avctx, AV_LOG_ERROR,
78
88
               "Frame too small (%d bytes). Truncated file?\n", buf_size);
79
 
        *data_size = 0;
 
89
        *got_frame_ptr = 0;
80
90
        return buf_size;
81
91
    }
82
 
    init_get_bits(&gb, buf, 20 * 8);
 
92
    init_get_bits(&gb, buf, FRAMESIZE * 8);
83
93
 
84
 
    for (i=0; i<10; i++)
 
94
    for (i = 0; i < LPC_ORDER; i++)
85
95
        lpc_refl[i] = ff_lpc_refl_cb[i][get_bits(&gb, sizes[i])];
86
96
 
87
97
    ff_eval_coefs(ractx->lpc_coef[0], lpc_refl);
98
108
 
99
109
    ff_int_to_int16(block_coefs[3], ractx->lpc_coef[0]);
100
110
 
101
 
    for (i=0; i < 4; i++) {
 
111
    for (i=0; i < NBLOCKS; i++) {
102
112
        do_output_subblock(ractx, block_coefs[i], refl_rms[i], &gb);
103
113
 
104
114
        for (j=0; j < BLOCKSIZE; j++)
105
 
            *data++ = av_clip_int16(ractx->curr_sblock[j + 10] << 2);
 
115
            *samples++ = av_clip_int16(ractx->curr_sblock[j + 10] << 2);
106
116
    }
107
117
 
108
118
    ractx->old_energy = energy;
110
120
 
111
121
    FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]);
112
122
 
113
 
    *data_size = 2*160;
114
 
    return 20;
 
123
    *got_frame_ptr   = 1;
 
124
    *(AVFrame *)data = ractx->frame;
 
125
 
 
126
    return FRAMESIZE;
115
127
}
116
128
 
117
 
AVCodec ff_ra_144_decoder =
118
 
{
119
 
    "real_144",
120
 
    AVMEDIA_TYPE_AUDIO,
121
 
    CODEC_ID_RA_144,
122
 
    sizeof(RA144Context),
123
 
    ra144_decode_init,
124
 
    NULL,
125
 
    NULL,
126
 
    ra144_decode_frame,
127
 
    .long_name = NULL_IF_CONFIG_SMALL("RealAudio 1.0 (14.4K)"),
 
129
AVCodec ff_ra_144_decoder = {
 
130
    .name           = "real_144",
 
131
    .type           = AVMEDIA_TYPE_AUDIO,
 
132
    .id             = CODEC_ID_RA_144,
 
133
    .priv_data_size = sizeof(RA144Context),
 
134
    .init           = ra144_decode_init,
 
135
    .decode         = ra144_decode_frame,
 
136
    .capabilities   = CODEC_CAP_DR1,
 
137
    .long_name      = NULL_IF_CONFIG_SMALL("RealAudio 1.0 (14.4K)"),
128
138
};