Statistics
| Branch: | Revision:

ffmpeg / libavcodec / amr.c @ ee4c54a3

History | View | Annotate | Download (18.1 KB)

1
/*
2
 * AMR Audio decoder stub
3
 * Copyright (c) 2003 the ffmpeg project
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with FFmpeg; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21

    
22
 /** @file
23
 * Adaptive Multi-Rate (AMR) Audio decoder stub.
24
 *
25
 * This code implements both an AMR-NarrowBand (AMR-NB) and an AMR-WideBand
26
 * (AMR-WB) audio encoder/decoder through external reference code from
27
 * http://www.3gpp.org/. The license of the code from 3gpp is unclear so you
28
 * have to download the code separately. Two versions exists: One fixed-point
29
 * and one floating-point. For some reason the float encoder is significantly
30
 * faster at least on a P4 1.5GHz (0.9s instead of 9.9s on a 30s audio clip
31
 * at MR102). Both float and fixed point are supported for AMR-NB, but only
32
 * float for AMR-WB.
33
 *
34
 * \section AMR-NB
35
 *
36
 * \subsection Float
37
 * The float version (default) can be downloaded from:
38
 * http://www.3gpp.org/ftp/Specs/archive/26_series/26.104/26104-610.zip
39
 * Extract the source into \c "ffmpeg/libavcodec/amr_float".
40
 * Enable it by passing \c "--enable-amr-nb" to \c "./configure".
41
 * If you try this on Alpha, you may need to change \c "Word32" to
42
 * \c "int" in \c "amr/typedef.h".
43
 *
44
 * \subsection Fixed-point
45
 * The fixed-point (TS26.073) can be downloaded from:
46
 * http://www.3gpp.org/ftp/Specs/archive/26_series/26.073/26073-600.zip
47
 * Extract the source into \c "ffmpeg/libavcodec/amr" and add \c "-DMMS_IO" to
48
 * \c "CFLAGS" in \c "libavcodec/amr/makefile", i.e.
49
 * \c "CFLAGS = -Wall -pedantic-errors -I. $(CFLAGS_$(MODE)) -D$(VAD) -DMMS_IO".
50
 * Enable it by passing \c "--enable-amr-nb-fixed" to \c "./configure".
51
 *
52
 * \subsection Specification
53
 * The specification for AMR-NB can be found in TS 26.071
54
 * (http://www.3gpp.org/ftp/Specs/html-info/26071.htm) and some other
55
 * info at http://www.3gpp.org/ftp/Specs/html-info/26-series.htm.
56
 *
57
 * \section AMR-WB
58
 * \subsection Float
59
 * The reference code can be downloaded from:
60
 * http://www.3gpp.org/ftp/Specs/archive/26_series/26.204/26204-600.zip
61
 * It should be extracted to \c "ffmpeg/libavcodec/amrwb_float".
62
 * Enable it by passing \c "--enable-amr-wb" to \c "./configure".
63
 *
64
 * \subsection Fixed-point
65
 * If someone wants to use the fixed point version it can be downloaded from:
66
 * http://www.3gpp.org/ftp/Specs/archive/26_series/26.173/26173-571.zip.
67
 *
68
 * \subsection Specification
69
 * The specification for AMR-WB can be found in TS 26.171
70
 * (http://www.3gpp.org/ftp/Specs/html-info/26171.htm) and some other
71
 * info at http://www.3gpp.org/ftp/Specs/html-info/26-series.htm.
72
 *
73
 */
74

    
75
#include "avcodec.h"
76

    
77
#ifdef CONFIG_AMR_NB_FIXED
78

    
79
#define MMS_IO
80

    
81
#include "amr/sp_dec.h"
82
#include "amr/d_homing.h"
83
#include "amr/typedef.h"
84
#include "amr/sp_enc.h"
85
#include "amr/sid_sync.h"
86
#include "amr/e_homing.h"
87

    
88
#else
89
#include <amrnb/interf_dec.h>
90
#include <amrnb/interf_enc.h>
91
#endif
92

    
93
static const char *nb_bitrate_unsupported =
94
    "bitrate not supported: use one of 4.75k, 5.15k, 5.9k, 6.7k, 7.4k, 7.95k, 10.2k or 12.2k\n";
95
static const char *wb_bitrate_unsupported =
96
    "bitrate not supported: use one of 6.6k, 8.85k, 12.65k, 14.25k, 15.85k, 18.25k, 19.85k, 23.05k, or 23.85k\n";
97

    
98
/* Common code for fixed and float version*/
99
typedef struct AMR_bitrates
100
{
101
    int rate;
102
    enum Mode mode;
103
} AMR_bitrates;
104

    
105
/* Match desired bitrate */
106
static int getBitrateMode(int bitrate)
107
{
108
    /* make the correspondance between bitrate and mode */
109
    AMR_bitrates rates[]={ {4750,MR475},
110
                           {5150,MR515},
111
                           {5900,MR59},
112
                           {6700,MR67},
113
                           {7400,MR74},
114
                           {7950,MR795},
115
                           {10200,MR102},
116
                           {12200,MR122},
117
                         };
118
    int i;
119

    
120
    for(i=0;i<8;i++)
121
    {
122
        if(rates[i].rate==bitrate)
123
        {
124
            return(rates[i].mode);
125
        }
126
    }
127
    /* no bitrate matching, return an error */
128
    return -1;
129
}
130

    
131
static void amr_decode_fix_avctx(AVCodecContext * avctx)
132
{
133
    const int is_amr_wb = 1 + (avctx->codec_id == CODEC_ID_AMR_WB);
134

    
135
    if(avctx->sample_rate == 0)
136
    {
137
        avctx->sample_rate = 8000 * is_amr_wb;
138
    }
139

    
140
    if(avctx->channels == 0)
141
    {
142
        avctx->channels = 1;
143
    }
144

    
145
    avctx->frame_size = 160 * is_amr_wb;
146
}
147

    
148
#ifdef CONFIG_AMR_NB_FIXED
149
/* fixed point version*/
150
/* frame size in serial bitstream file (frame type + serial stream + flags) */
151
#define SERIAL_FRAMESIZE (1+MAX_SERIAL_SIZE+5)
152

    
153
typedef struct AMRContext {
154
    int frameCount;
155
    Speech_Decode_FrameState *speech_decoder_state;
156
    enum RXFrameType rx_type;
157
    enum Mode mode;
158
    Word16 reset_flag;
159
    Word16 reset_flag_old;
160

    
161
    int enc_bitrate;
162
    Speech_Encode_FrameState *enstate;
163
    sid_syncState *sidstate;
164
    enum TXFrameType tx_frametype;
165
} AMRContext;
166

    
167
static int amr_nb_decode_init(AVCodecContext * avctx)
168
{
169
    AMRContext *s = avctx->priv_data;
170

    
171
    s->frameCount=0;
172
    s->speech_decoder_state=NULL;
173
    s->rx_type = (enum RXFrameType)0;
174
    s->mode= (enum Mode)0;
175
    s->reset_flag=0;
176
    s->reset_flag_old=1;
177

    
178
    if(Speech_Decode_Frame_init(&s->speech_decoder_state, "Decoder"))
179
    {
180
        av_log(avctx, AV_LOG_ERROR, "Speech_Decode_Frame_init error\n");
181
        return -1;
182
    }
183

    
184
    amr_decode_fix_avctx(avctx);
185

    
186
    if(avctx->channels > 1)
187
    {
188
        av_log(avctx, AV_LOG_ERROR, "amr_nb: multichannel decoding not supported\n");
189
        return -1;
190
    }
191

    
192
    return 0;
193
}
194

    
195
static int amr_nb_encode_init(AVCodecContext * avctx)
196
{
197
    AMRContext *s = avctx->priv_data;
198

    
199
    s->frameCount=0;
200
    s->speech_decoder_state=NULL;
201
    s->rx_type = (enum RXFrameType)0;
202
    s->mode= (enum Mode)0;
203
    s->reset_flag=0;
204
    s->reset_flag_old=1;
205

    
206
    if(avctx->sample_rate!=8000)
207
    {
208
        av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n");
209
        return -1;
210
    }
211

    
212
    if(avctx->channels!=1)
213
    {
214
        av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
215
        return -1;
216
    }
217

    
218
    avctx->frame_size=160;
219
    avctx->coded_frame= avcodec_alloc_frame();
220

    
221
    if(Speech_Encode_Frame_init(&s->enstate, 0, "encoder") || sid_sync_init (&s->sidstate))
222
    {
223
        av_log(avctx, AV_LOG_ERROR, "Speech_Encode_Frame_init error\n");
224
        return -1;
225
    }
226

    
227
    if((s->enc_bitrate=getBitrateMode(avctx->bit_rate))<0)
228
    {
229
        av_log(avctx, AV_LOG_ERROR, nb_bitrate_unsupported);
230
        return -1;
231
    }
232

    
233
    return 0;
234
}
235

    
236
static int amr_nb_encode_close(AVCodecContext * avctx)
237
{
238
    AMRContext *s = avctx->priv_data;
239

    
240
    Speech_Encode_Frame_exit(&s->enstate);
241
    sid_sync_exit (&s->sidstate);
242
    av_freep(&avctx->coded_frame);
243
    return 0;
244
}
245

    
246
static int amr_nb_decode_close(AVCodecContext * avctx)
247
{
248
    AMRContext *s = avctx->priv_data;
249

    
250
    Speech_Decode_Frame_exit(&s->speech_decoder_state);
251
    return 0;
252
}
253

    
254
static int amr_nb_decode_frame(AVCodecContext * avctx,
255
            void *data, int *data_size,
256
            uint8_t * buf, int buf_size)
257
{
258
    AMRContext *s = avctx->priv_data;
259
    uint8_t*amrData=buf;
260
    int offset=0;
261
    UWord8 toc, q, ft;
262
    Word16 serial[SERIAL_FRAMESIZE];   /* coded bits */
263
    Word16 *synth;
264
    UWord8 *packed_bits;
265
    static Word16 packed_size[16] = {12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0};
266
    int i;
267

    
268
    //printf("amr_decode_frame data_size=%i buf=0x%X buf_size=%d frameCount=%d!!\n",*data_size,buf,buf_size,s->frameCount);
269

    
270
    synth=data;
271

    
272
    toc=amrData[offset];
273
    /* read rest of the frame based on ToC byte */
274
    q  = (toc >> 2) & 0x01;
275
    ft = (toc >> 3) & 0x0F;
276

    
277
    //printf("offset=%d, packet_size=%d amrData= 0x%X %X %X %X\n",offset,packed_size[ft],amrData[offset],amrData[offset+1],amrData[offset+2],amrData[offset+3]);
278

    
279
    offset++;
280

    
281
    packed_bits=amrData+offset;
282

    
283
    offset+=packed_size[ft];
284

    
285
    //Unsort and unpack bits
286
    s->rx_type = UnpackBits(q, ft, packed_bits, &s->mode, &serial[1]);
287

    
288
    //We have a new frame
289
    s->frameCount++;
290

    
291
    if (s->rx_type == RX_NO_DATA)
292
    {
293
        s->mode = s->speech_decoder_state->prev_mode;
294
    }
295
    else {
296
        s->speech_decoder_state->prev_mode = s->mode;
297
    }
298

    
299
    /* if homed: check if this frame is another homing frame */
300
    if (s->reset_flag_old == 1)
301
    {
302
        /* only check until end of first subframe */
303
        s->reset_flag = decoder_homing_frame_test_first(&serial[1], s->mode);
304
    }
305
    /* produce encoder homing frame if homed & input=decoder homing frame */
306
    if ((s->reset_flag != 0) && (s->reset_flag_old != 0))
307
    {
308
        for (i = 0; i < L_FRAME; i++)
309
        {
310
            synth[i] = EHF_MASK;
311
        }
312
    }
313
    else
314
    {
315
        /* decode frame */
316
        Speech_Decode_Frame(s->speech_decoder_state, s->mode, &serial[1], s->rx_type, synth);
317
    }
318

    
319
    //Each AMR-frame results in 160 16-bit samples
320
    *data_size=160*2;
321

    
322
    /* if not homed: check whether current frame is a homing frame */
323
    if (s->reset_flag_old == 0)
324
    {
325
        /* check whole frame */
326
        s->reset_flag = decoder_homing_frame_test(&serial[1], s->mode);
327
    }
328
    /* reset decoder if current frame is a homing frame */
329
    if (s->reset_flag != 0)
330
    {
331
        Speech_Decode_Frame_reset(s->speech_decoder_state);
332
    }
333
    s->reset_flag_old = s->reset_flag;
334

    
335
    return offset;
336
}
337

    
338

    
339
static int amr_nb_encode_frame(AVCodecContext *avctx,
340
                            unsigned char *frame/*out*/, int buf_size, void *data/*in*/)
341
{
342
    short serial_data[250] = {0};
343
    AMRContext *s = avctx->priv_data;
344
    int written;
345

    
346
    s->reset_flag = encoder_homing_frame_test(data);
347

    
348
    Speech_Encode_Frame(s->enstate, s->enc_bitrate, data, &serial_data[1], &s->mode);
349

    
350
    /* add frame type and mode */
351
    sid_sync (s->sidstate, s->mode, &s->tx_frametype);
352

    
353
    written = PackBits(s->mode, s->enc_bitrate, s->tx_frametype, &serial_data[1], frame);
354

    
355
    if (s->reset_flag != 0)
356
    {
357
        Speech_Encode_Frame_reset(s->enstate);
358
        sid_sync_reset(s->sidstate);
359
    }
360
    return written;
361
}
362

    
363

    
364
#elif defined(CONFIG_AMR_NB) /* Float point version*/
365

    
366
typedef struct AMRContext {
367
    int frameCount;
368
    void * decState;
369
    int *enstate;
370
    int enc_bitrate;
371
} AMRContext;
372

    
373
static int amr_nb_decode_init(AVCodecContext * avctx)
374
{
375
    AMRContext *s = avctx->priv_data;
376

    
377
    s->frameCount=0;
378
    s->decState=Decoder_Interface_init();
379
    if(!s->decState)
380
    {
381
        av_log(avctx, AV_LOG_ERROR, "Decoder_Interface_init error\r\n");
382
        return -1;
383
    }
384

    
385
    amr_decode_fix_avctx(avctx);
386

    
387
    if(avctx->channels > 1)
388
    {
389
        av_log(avctx, AV_LOG_ERROR, "amr_nb: multichannel decoding not supported\n");
390
        return -1;
391
    }
392

    
393
    return 0;
394
}
395

    
396
static int amr_nb_encode_init(AVCodecContext * avctx)
397
{
398
    AMRContext *s = avctx->priv_data;
399

    
400
    s->frameCount=0;
401

    
402
    if(avctx->sample_rate!=8000)
403
    {
404
        av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n");
405
        return -1;
406
    }
407

    
408
    if(avctx->channels!=1)
409
    {
410
        av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
411
        return -1;
412
    }
413

    
414
    avctx->frame_size=160;
415
    avctx->coded_frame= avcodec_alloc_frame();
416

    
417
    s->enstate=Encoder_Interface_init(0);
418
    if(!s->enstate)
419
    {
420
        av_log(avctx, AV_LOG_ERROR, "Encoder_Interface_init error\n");
421
        return -1;
422
    }
423

    
424
    if((s->enc_bitrate=getBitrateMode(avctx->bit_rate))<0)
425
    {
426
        av_log(avctx, AV_LOG_ERROR, nb_bitrate_unsupported);
427
        return -1;
428
    }
429

    
430
    return 0;
431
}
432

    
433
static int amr_nb_decode_close(AVCodecContext * avctx)
434
{
435
    AMRContext *s = avctx->priv_data;
436

    
437
    Decoder_Interface_exit(s->decState);
438
    return 0;
439
}
440

    
441
static int amr_nb_encode_close(AVCodecContext * avctx)
442
{
443
    AMRContext *s = avctx->priv_data;
444

    
445
    Encoder_Interface_exit(s->enstate);
446
    av_freep(&avctx->coded_frame);
447
    return 0;
448
}
449

    
450
static int amr_nb_decode_frame(AVCodecContext * avctx,
451
            void *data, int *data_size,
452
            uint8_t * buf, int buf_size)
453
{
454
    AMRContext *s = avctx->priv_data;
455
    uint8_t*amrData=buf;
456
    static short block_size[16]={ 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 };
457
    enum Mode dec_mode;
458
    int packet_size;
459

    
460
    /* av_log(NULL,AV_LOG_DEBUG,"amr_decode_frame buf=%p buf_size=%d frameCount=%d!!\n",buf,buf_size,s->frameCount); */
461

    
462
    dec_mode = (buf[0] >> 3) & 0x000F;
463
    packet_size = block_size[dec_mode]+1;
464

    
465
    if(packet_size > buf_size) {
466
        av_log(avctx, AV_LOG_ERROR, "amr frame too short (%u, should be %u)\n", buf_size, packet_size);
467
        return -1;
468
    }
469

    
470
    s->frameCount++;
471
    /* av_log(NULL,AV_LOG_DEBUG,"packet_size=%d amrData= 0x%X %X %X %X\n",packet_size,amrData[0],amrData[1],amrData[2],amrData[3]); */
472
    /* call decoder */
473
    Decoder_Interface_Decode(s->decState, amrData, data, 0);
474
    *data_size=160*2;
475

    
476
    return packet_size;
477
}
478

    
479
static int amr_nb_encode_frame(AVCodecContext *avctx,
480
                            unsigned char *frame/*out*/, int buf_size, void *data/*in*/)
481
{
482
    AMRContext *s = avctx->priv_data;
483
    int written;
484

    
485
    if((s->enc_bitrate=getBitrateMode(avctx->bit_rate))<0)
486
    {
487
        av_log(avctx, AV_LOG_ERROR, nb_bitrate_unsupported);
488
        return -1;
489
    }
490

    
491
    written = Encoder_Interface_Encode(s->enstate,
492
        s->enc_bitrate,
493
        data,
494
        frame,
495
        0);
496
    /* av_log(NULL,AV_LOG_DEBUG,"amr_nb_encode_frame encoded %u bytes, bitrate %u, first byte was %#02x\n",written, s->enc_bitrate, frame[0] ); */
497

    
498
    return written;
499
}
500

    
501
#endif
502

    
503
#if defined(CONFIG_AMR_NB) || defined(CONFIG_AMR_NB_FIXED)
504

    
505
AVCodec amr_nb_decoder =
506
{
507
    "amr_nb",
508
    CODEC_TYPE_AUDIO,
509
    CODEC_ID_AMR_NB,
510
    sizeof(AMRContext),
511
    amr_nb_decode_init,
512
    NULL,
513
    amr_nb_decode_close,
514
    amr_nb_decode_frame,
515
};
516

    
517
AVCodec amr_nb_encoder =
518
{
519
    "amr_nb",
520
    CODEC_TYPE_AUDIO,
521
    CODEC_ID_AMR_NB,
522
    sizeof(AMRContext),
523
    amr_nb_encode_init,
524
    amr_nb_encode_frame,
525
    amr_nb_encode_close,
526
    NULL,
527
};
528

    
529
#endif
530

    
531
/* -----------AMR wideband ------------*/
532
#ifdef CONFIG_AMR_WB
533

    
534
#ifdef _TYPEDEF_H
535
//To avoid duplicate typedefs from typdef in amr-nb
536
#define typedef_h
537
#endif
538

    
539
#include <amrwb/enc_if.h>
540
#include <amrwb/dec_if.h>
541
#include <amrwb/if_rom.h>
542

    
543
/* Common code for fixed and float version*/
544
typedef struct AMRWB_bitrates
545
{
546
    int rate;
547
    int mode;
548
} AMRWB_bitrates;
549

    
550
static int getWBBitrateMode(int bitrate)
551
{
552
    /* make the correspondance between bitrate and mode */
553
    AMRWB_bitrates rates[]={ {6600,0},
554
                           {8850,1},
555
                           {12650,2},
556
                           {14250,3},
557
                           {15850,4},
558
                           {18250,5},
559
                           {19850,6},
560
                           {23050,7},
561
                           {23850,8},
562
                         };
563
    int i;
564

    
565
    for(i=0;i<9;i++)
566
    {
567
        if(rates[i].rate==bitrate)
568
        {
569
            return(rates[i].mode);
570
        }
571
    }
572
    /* no bitrate matching, return an error */
573
    return -1;
574
}
575

    
576

    
577
typedef struct AMRWBContext {
578
    int frameCount;
579
    void *state;
580
    int mode;
581
    Word16 allow_dtx;
582
} AMRWBContext;
583

    
584
static int amr_wb_encode_init(AVCodecContext * avctx)
585
{
586
    AMRWBContext *s = avctx->priv_data;
587

    
588
    s->frameCount=0;
589

    
590
    if(avctx->sample_rate!=16000)
591
    {
592
        av_log(avctx, AV_LOG_ERROR, "Only 16000Hz sample rate supported\n");
593
        return -1;
594
    }
595

    
596
    if(avctx->channels!=1)
597
    {
598
        av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
599
        return -1;
600
    }
601

    
602
    if((s->mode=getWBBitrateMode(avctx->bit_rate))<0)
603
    {
604
        av_log(avctx, AV_LOG_ERROR, wb_bitrate_unsupported);
605
        return -1;
606
    }
607

    
608
    avctx->frame_size=320;
609
    avctx->coded_frame= avcodec_alloc_frame();
610

    
611
    s->state = E_IF_init();
612
    s->allow_dtx=0;
613

    
614
    return 0;
615
}
616

    
617
static int amr_wb_encode_close(AVCodecContext * avctx)
618
{
619
    AMRWBContext *s = avctx->priv_data;
620

    
621
    E_IF_exit(s->state);
622
    av_freep(&avctx->coded_frame);
623
    s->frameCount++;
624
    return 0;
625
}
626

    
627
static int amr_wb_encode_frame(AVCodecContext *avctx,
628
                            unsigned char *frame/*out*/, int buf_size, void *data/*in*/)
629
{
630
    AMRWBContext *s = avctx->priv_data;
631
    int size;
632

    
633
    if((s->mode=getWBBitrateMode(avctx->bit_rate))<0)
634
    {
635
        av_log(avctx, AV_LOG_ERROR, wb_bitrate_unsupported);
636
        return -1;
637
    }
638
    size = E_IF_encode(s->state, s->mode, data, frame, s->allow_dtx);
639
    return size;
640
}
641

    
642
static int amr_wb_decode_init(AVCodecContext * avctx)
643
{
644
    AMRWBContext *s = avctx->priv_data;
645

    
646
    s->frameCount=0;
647
    s->state = D_IF_init();
648

    
649
    amr_decode_fix_avctx(avctx);
650

    
651
    if(avctx->channels > 1)
652
    {
653
        av_log(avctx, AV_LOG_ERROR, "amr_wb: multichannel decoding not supported\n");
654
        return -1;
655
    }
656

    
657
    return 0;
658
}
659

    
660
static int amr_wb_decode_frame(AVCodecContext * avctx,
661
            void *data, int *data_size,
662
            uint8_t * buf, int buf_size)
663
{
664
    AMRWBContext *s = avctx->priv_data;
665
    uint8_t*amrData=buf;
666
    int mode;
667
    int packet_size;
668

    
669
    if(buf_size==0) {
670
        /* nothing to do */
671
        return 0;
672
    }
673

    
674
    mode = (amrData[0] >> 3) & 0x000F;
675
    packet_size = block_size[mode];
676

    
677
    if(packet_size > buf_size) {
678
        av_log(avctx, AV_LOG_ERROR, "amr frame too short (%u, should be %u)\n", buf_size, packet_size+1);
679
        return -1;
680
    }
681

    
682
    s->frameCount++;
683
    D_IF_decode( s->state, amrData, data, _good_frame);
684
    *data_size=320*2;
685
    return packet_size;
686
}
687

    
688
static int amr_wb_decode_close(AVCodecContext * avctx)
689
{
690
    AMRWBContext *s = avctx->priv_data;
691

    
692
    D_IF_exit(s->state);
693
    return 0;
694
}
695

    
696
AVCodec amr_wb_decoder =
697
{
698
    "amr_wb",
699
    CODEC_TYPE_AUDIO,
700
    CODEC_ID_AMR_WB,
701
    sizeof(AMRWBContext),
702
    amr_wb_decode_init,
703
    NULL,
704
    amr_wb_decode_close,
705
    amr_wb_decode_frame,
706
};
707

    
708
AVCodec amr_wb_encoder =
709
{
710
    "amr_wb",
711
    CODEC_TYPE_AUDIO,
712
    CODEC_ID_AMR_WB,
713
    sizeof(AMRWBContext),
714
    amr_wb_encode_init,
715
    amr_wb_encode_frame,
716
    amr_wb_encode_close,
717
    NULL,
718
};
719

    
720
#endif //CONFIG_AMR_WB