Revision db56acd4
libavcodec/amr.c  

87  87 
/* Common code for fixed and float version*/ 
88  88 
typedef struct AMR_bitrates 
89  89 
{ 
90 
int startrate; 

91 
int stoprate; 

90 
int rate; 

92  91 
enum Mode mode; 
93  92 
} AMR_bitrates; 
94  93  
95 
/* Match desired bitrate with closest one*/


96 
static enum Mode getBitrateMode(int bitrate)


94 
/* Match desired bitrate */ 

95 
static int getBitrateMode(int bitrate)


97  96 
{ 
98 
/* Adjusted so that all bitrates can be used from commandline where 

99 
only a multiple of 1000 can be specified*/ 

100 
AMR_bitrates rates[]={ {0,4999,MR475}, //4 

101 
{5000,5899,MR515},//5 

102 
{5900,6699,MR59},//6 

103 
{6700,7000,MR67},//7 

104 
{7001,7949,MR74},//8 

105 
{7950,9999,MR795},//9 

106 
{10000,11999,MR102},//10 

107 
{12000,64000,MR122},//12 

97 
/* make the correspondance between bitrate and mode */ 

98 
AMR_bitrates rates[]={ {4750,MR475}, 

99 
{5150,MR515}, 

100 
{5900,MR59}, 

101 
{6700,MR67}, 

102 
{7400,MR74}, 

103 
{7950,MR795}, 

104 
{10200,MR102}, 

105 
{12200,MR122}, 

108  106 
}; 
109  107 
int i; 
110  108  
111  109 
for(i=0;i<8;i++) 
112  110 
{ 
113 
if(rates[i].startrate<=bitrate && rates[i].stoprate>=bitrate)


111 
if(rates[i].rate==bitrate)


114  112 
{ 
115  113 
return(rates[i].mode); 
116  114 
} 
117  115 
} 
118 
/*Return highest possible*/


119 
return(MR122);


116 
/* no bitrate matching, return an error */


117 
return 1;


120  118 
} 
121  119  
122  120 
static void amr_decode_fix_avctx(AVCodecContext * avctx) 
...  ...  
149  147 
Word16 reset_flag; 
150  148 
Word16 reset_flag_old; 
151  149  
152 
enum Mode enc_bitrate;


150 
int enc_bitrate;


153  151 
Speech_Encode_FrameState *enstate; 
154  152 
sid_syncState *sidstate; 
155  153 
enum TXFrameType tx_frametype; 
...  ...  
215  213 
return 1; 
216  214 
} 
217  215  
218 
s>enc_bitrate=getBitrateMode(avctx>bit_rate); 

216 
if((s>enc_bitrate=getBitrateMode(avctx>bit_rate))<0) 

217 
{ 

218 
av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n"); 

219 
return 1; 

220 
} 

219  221  
220  222 
return 0; 
221  223 
} 
...  ...  
358  360 
int frameCount; 
359  361 
void * decState; 
360  362 
int *enstate; 
361 
enum Mode enc_bitrate;


363 
int enc_bitrate;


362  364 
} AMRContext; 
363  365  
364  366 
static int amr_nb_decode_init(AVCodecContext * avctx) 
...  ...  
412  414 
return 1; 
413  415 
} 
414  416  
415 
s>enc_bitrate=getBitrateMode(avctx>bit_rate); 

417 
if((s>enc_bitrate=getBitrateMode(avctx>bit_rate))<0) 

418 
{ 

419 
av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n"); 

420 
return 1; 

421 
} 

416  422  
417  423 
return 0; 
418  424 
} 
...  ...  
469  475 
AMRContext *s = avctx>priv_data; 
470  476 
int written; 
471  477  
472 
s>enc_bitrate=getBitrateMode(avctx>bit_rate); 

478 
if((s>enc_bitrate=getBitrateMode(avctx>bit_rate))<0) 

479 
{ 

480 
av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n"); 

481 
return 1; 

482 
} 

473  483  
474  484 
written = Encoder_Interface_Encode(s>enstate, 
475  485 
s>enc_bitrate, 
...  ...  
525  535 
/* Common code for fixed and float version*/ 
526  536 
typedef struct AMRWB_bitrates 
527  537 
{ 
528 
int startrate; 

529 
int stoprate; 

538 
int rate; 

530  539 
int mode; 
531  540 
} AMRWB_bitrates; 
532  541  
533  542 
static int getWBBitrateMode(int bitrate) 
534  543 
{ 
535 
/* Adjusted so that all bitrates can be used from commandline where 

536 
only a multiple of 1000 can be specified*/ 

537 
AMRWB_bitrates rates[]={ {0,7999,0}, //6.6kHz 

538 
{8000,9999,1},//8.85 

539 
{10000,13000,2},//12.65 

540 
{13001,14999,3},//14.25 

541 
{15000,17000,4},//15.85 

542 
{17001,18000,5},//18.25 

543 
{18001,22000,6},//19.85 

544 
{22001,23000,7},//23.05 

545 
{23001,24000,8},//23.85 

544 
/* make the correspondance between bitrate and mode */ 

545 
AMRWB_bitrates rates[]={ {6600,0}, 

546 
{8850,1}, 

547 
{12650,2}, 

548 
{14250,3}, 

549 
{15850,4}, 

550 
{18250,5}, 

551 
{19850,6}, 

552 
{23050,7}, 

553 
{23850,8}, 

546  554 
}; 
547  555 
int i; 
548  556  
549  557 
for(i=0;i<9;i++) 
550  558 
{ 
551 
if(rates[i].startrate<=bitrate && rates[i].stoprate>=bitrate)


559 
if(rates[i].rate==bitrate)


552  560 
{ 
553  561 
return(rates[i].mode); 
554  562 
} 
555  563 
} 
556 
/*Return highest possible*/


557 
return(8);


564 
/* no bitrate matching, return an error */


565 
return 1;


558  566 
} 
559  567  
560  568  
...  ...  
583  591 
return 1; 
584  592 
} 
585  593  
594 
if((s>mode=getWBBitrateMode(avctx>bit_rate))<0) 

595 
{ 

596 
av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n"); 

597 
return 1; 

598 
} 

599  
586  600 
avctx>frame_size=320; 
587  601 
avctx>coded_frame= avcodec_alloc_frame(); 
588  602  
589  603 
s>state = E_IF_init(); 
590 
s>mode=getWBBitrateMode(avctx>bit_rate); 

591  604 
s>allow_dtx=0; 
592  605  
593  606 
return 0; 
...  ...  
609  622 
AMRWBContext *s = avctx>priv_data; 
610  623 
int size; 
611  624  
612 
s>mode=getWBBitrateMode(avctx>bit_rate); 

625 
if((s>mode=getWBBitrateMode(avctx>bit_rate))<0) 

626 
{ 

627 
av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n"); 

628 
return 1; 

629 
} 

613  630 
size = E_IF_encode(s>state, s>mode, data, frame, s>allow_dtx); 
614  631 
return size; 
615  632 
} 
Also available in: Unified diff