~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavcodec/libopencore-amr.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:
79
79
 
80
80
typedef struct AMRContext {
81
81
    AVClass *av_class;
82
 
    int   frame_count;
 
82
    AVFrame frame;
83
83
    void *dec_state;
84
84
    void *enc_state;
85
85
    int   enc_bitrate;
88
88
} AMRContext;
89
89
 
90
90
static const AVOption options[] = {
91
 
    { "dtx", "Allow DTX (generate comfort noise)", offsetof(AMRContext, enc_dtx), FF_OPT_TYPE_INT, 0, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
 
91
    { "dtx", "Allow DTX (generate comfort noise)", offsetof(AMRContext, enc_dtx), AV_OPT_TYPE_INT, { 0 }, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
92
92
    { NULL }
93
93
};
94
94
 
100
100
{
101
101
    AMRContext *s  = avctx->priv_data;
102
102
 
103
 
    s->frame_count = 0;
104
103
    s->dec_state   = Decoder_Interface_init();
105
104
    if (!s->dec_state) {
106
105
        av_log(avctx, AV_LOG_ERROR, "Decoder_Interface_init error\n");
114
113
        return AVERROR(ENOSYS);
115
114
    }
116
115
 
 
116
    avcodec_get_frame_defaults(&s->frame);
 
117
    avctx->coded_frame = &s->frame;
 
118
 
117
119
    return 0;
118
120
}
119
121
 
122
124
    AMRContext *s = avctx->priv_data;
123
125
 
124
126
    Decoder_Interface_exit(s->dec_state);
 
127
 
125
128
    return 0;
126
129
}
127
130
 
128
131
static int amr_nb_decode_frame(AVCodecContext *avctx, void *data,
129
 
                               int *data_size, AVPacket *avpkt)
 
132
                               int *got_frame_ptr, AVPacket *avpkt)
130
133
{
131
134
    const uint8_t *buf = avpkt->data;
132
135
    int buf_size       = avpkt->size;
133
136
    AMRContext *s      = avctx->priv_data;
134
137
    static const uint8_t block_size[16] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 };
135
138
    enum Mode dec_mode;
136
 
    int packet_size;
 
139
    int packet_size, ret;
137
140
 
138
141
    av_dlog(avctx, "amr_decode_frame buf=%p buf_size=%d frame_count=%d!!\n",
139
 
            buf, buf_size, s->frame_count);
 
142
            buf, buf_size, avctx->frame_number);
 
143
 
 
144
    /* get output buffer */
 
145
    s->frame.nb_samples = 160;
 
146
    if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) {
 
147
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
 
148
        return ret;
 
149
    }
140
150
 
141
151
    dec_mode    = (buf[0] >> 3) & 0x000F;
142
152
    packet_size = block_size[dec_mode] + 1;
147
157
        return AVERROR_INVALIDDATA;
148
158
    }
149
159
 
150
 
    s->frame_count++;
151
160
    av_dlog(avctx, "packet_size=%d buf= 0x%X %X %X %X\n",
152
161
              packet_size, buf[0], buf[1], buf[2], buf[3]);
153
162
    /* call decoder */
154
 
    Decoder_Interface_Decode(s->dec_state, buf, data, 0);
155
 
    *data_size = 160 * 2;
 
163
    Decoder_Interface_Decode(s->dec_state, buf, (short *)s->frame.data[0], 0);
 
164
 
 
165
    *got_frame_ptr   = 1;
 
166
    *(AVFrame *)data = s->frame;
156
167
 
157
168
    return packet_size;
158
169
}
159
170
 
160
171
AVCodec ff_libopencore_amrnb_decoder = {
161
 
    "libopencore_amrnb",
162
 
    AVMEDIA_TYPE_AUDIO,
163
 
    CODEC_ID_AMR_NB,
164
 
    sizeof(AMRContext),
165
 
    amr_nb_decode_init,
166
 
    NULL,
167
 
    amr_nb_decode_close,
168
 
    amr_nb_decode_frame,
 
172
    .name           = "libopencore_amrnb",
 
173
    .type           = AVMEDIA_TYPE_AUDIO,
 
174
    .id             = CODEC_ID_AMR_NB,
 
175
    .priv_data_size = sizeof(AMRContext),
 
176
    .init           = amr_nb_decode_init,
 
177
    .close          = amr_nb_decode_close,
 
178
    .decode         = amr_nb_decode_frame,
 
179
    .capabilities   = CODEC_CAP_DR1,
169
180
    .long_name = NULL_IF_CONFIG_SMALL("OpenCORE Adaptive Multi-Rate (AMR) Narrow-Band"),
170
181
};
171
182
 
173
184
{
174
185
    AMRContext *s = avctx->priv_data;
175
186
 
176
 
    s->frame_count = 0;
177
 
 
178
187
    if (avctx->sample_rate != 8000) {
179
188
        av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n");
180
189
        return AVERROR(ENOSYS);
230
239
}
231
240
 
232
241
AVCodec ff_libopencore_amrnb_encoder = {
233
 
    "libopencore_amrnb",
234
 
    AVMEDIA_TYPE_AUDIO,
235
 
    CODEC_ID_AMR_NB,
236
 
    sizeof(AMRContext),
237
 
    amr_nb_encode_init,
238
 
    amr_nb_encode_frame,
239
 
    amr_nb_encode_close,
240
 
    NULL,
 
242
    .name           = "libopencore_amrnb",
 
243
    .type           = AVMEDIA_TYPE_AUDIO,
 
244
    .id             = CODEC_ID_AMR_NB,
 
245
    .priv_data_size = sizeof(AMRContext),
 
246
    .init           = amr_nb_encode_init,
 
247
    .encode         = amr_nb_encode_frame,
 
248
    .close          = amr_nb_encode_close,
241
249
    .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
242
250
    .long_name = NULL_IF_CONFIG_SMALL("OpenCORE Adaptive Multi-Rate (AMR) Narrow-Band"),
243
251
    .priv_class = &class,
252
260
#include <opencore-amrwb/if_rom.h>
253
261
 
254
262
typedef struct AMRWBContext {
 
263
    AVFrame frame;
255
264
    void  *state;
256
265
} AMRWBContext;
257
266
 
268
277
        return AVERROR(ENOSYS);
269
278
    }
270
279
 
 
280
    avcodec_get_frame_defaults(&s->frame);
 
281
    avctx->coded_frame = &s->frame;
 
282
 
271
283
    return 0;
272
284
}
273
285
 
274
286
static int amr_wb_decode_frame(AVCodecContext *avctx, void *data,
275
 
                               int *data_size, AVPacket *avpkt)
 
287
                               int *got_frame_ptr, AVPacket *avpkt)
276
288
{
277
289
    const uint8_t *buf = avpkt->data;
278
290
    int buf_size       = avpkt->size;
279
291
    AMRWBContext *s    = avctx->priv_data;
280
 
    int mode;
 
292
    int mode, ret;
281
293
    int packet_size;
282
294
    static const uint8_t block_size[16] = {18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1};
283
295
 
284
 
    if (!buf_size)
285
 
        /* nothing to do */
286
 
        return 0;
 
296
    /* get output buffer */
 
297
    s->frame.nb_samples = 320;
 
298
    if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) {
 
299
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
 
300
        return ret;
 
301
    }
287
302
 
288
303
    mode        = (buf[0] >> 3) & 0x000F;
289
304
    packet_size = block_size[mode];
294
309
        return AVERROR_INVALIDDATA;
295
310
    }
296
311
 
297
 
    D_IF_decode(s->state, buf, data, _good_frame);
298
 
    *data_size = 320 * 2;
 
312
    D_IF_decode(s->state, buf, (short *)s->frame.data[0], _good_frame);
 
313
 
 
314
    *got_frame_ptr   = 1;
 
315
    *(AVFrame *)data = s->frame;
 
316
 
299
317
    return packet_size;
300
318
}
301
319
 
308
326
}
309
327
 
310
328
AVCodec ff_libopencore_amrwb_decoder = {
311
 
    "libopencore_amrwb",
312
 
    AVMEDIA_TYPE_AUDIO,
313
 
    CODEC_ID_AMR_WB,
314
 
    sizeof(AMRWBContext),
315
 
    amr_wb_decode_init,
316
 
    NULL,
317
 
    amr_wb_decode_close,
318
 
    amr_wb_decode_frame,
 
329
    .name           = "libopencore_amrwb",
 
330
    .type           = AVMEDIA_TYPE_AUDIO,
 
331
    .id             = CODEC_ID_AMR_WB,
 
332
    .priv_data_size = sizeof(AMRWBContext),
 
333
    .init           = amr_wb_decode_init,
 
334
    .close          = amr_wb_decode_close,
 
335
    .decode         = amr_wb_decode_frame,
 
336
    .capabilities   = CODEC_CAP_DR1,
319
337
    .long_name = NULL_IF_CONFIG_SMALL("OpenCORE Adaptive Multi-Rate (AMR) Wide-Band"),
320
338
};
321
339