You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
Accept only existing bitrates.
patch by Benoit Fouet, benoit.fouet purplelabs com Originally committed as revision 8543 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
committed by
Diego Biurrun
parent
f5ad81f527
commit
db56acd480
@@ -87,36 +87,34 @@
|
|||||||
/* Common code for fixed and float version*/
|
/* Common code for fixed and float version*/
|
||||||
typedef struct AMR_bitrates
|
typedef struct AMR_bitrates
|
||||||
{
|
{
|
||||||
int startrate;
|
int rate;
|
||||||
int stoprate;
|
|
||||||
enum Mode mode;
|
enum Mode mode;
|
||||||
} AMR_bitrates;
|
} AMR_bitrates;
|
||||||
|
|
||||||
/* Match desired bitrate with closest one*/
|
/* Match desired bitrate */
|
||||||
static enum Mode getBitrateMode(int bitrate)
|
static int getBitrateMode(int bitrate)
|
||||||
{
|
{
|
||||||
/* Adjusted so that all bitrates can be used from commandline where
|
/* make the correspondance between bitrate and mode */
|
||||||
only a multiple of 1000 can be specified*/
|
AMR_bitrates rates[]={ {4750,MR475},
|
||||||
AMR_bitrates rates[]={ {0,4999,MR475}, //4
|
{5150,MR515},
|
||||||
{5000,5899,MR515},//5
|
{5900,MR59},
|
||||||
{5900,6699,MR59},//6
|
{6700,MR67},
|
||||||
{6700,7000,MR67},//7
|
{7400,MR74},
|
||||||
{7001,7949,MR74},//8
|
{7950,MR795},
|
||||||
{7950,9999,MR795},//9
|
{10200,MR102},
|
||||||
{10000,11999,MR102},//10
|
{12200,MR122},
|
||||||
{12000,64000,MR122},//12
|
|
||||||
};
|
};
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i=0;i<8;i++)
|
for(i=0;i<8;i++)
|
||||||
{
|
{
|
||||||
if(rates[i].startrate<=bitrate && rates[i].stoprate>=bitrate)
|
if(rates[i].rate==bitrate)
|
||||||
{
|
{
|
||||||
return(rates[i].mode);
|
return(rates[i].mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*Return highest possible*/
|
/* no bitrate matching, return an error */
|
||||||
return(MR122);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void amr_decode_fix_avctx(AVCodecContext * avctx)
|
static void amr_decode_fix_avctx(AVCodecContext * avctx)
|
||||||
@@ -149,7 +147,7 @@ typedef struct AMRContext {
|
|||||||
Word16 reset_flag;
|
Word16 reset_flag;
|
||||||
Word16 reset_flag_old;
|
Word16 reset_flag_old;
|
||||||
|
|
||||||
enum Mode enc_bitrate;
|
int enc_bitrate;
|
||||||
Speech_Encode_FrameState *enstate;
|
Speech_Encode_FrameState *enstate;
|
||||||
sid_syncState *sidstate;
|
sid_syncState *sidstate;
|
||||||
enum TXFrameType tx_frametype;
|
enum TXFrameType tx_frametype;
|
||||||
@@ -215,7 +213,11 @@ static int amr_nb_encode_init(AVCodecContext * avctx)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->enc_bitrate=getBitrateMode(avctx->bit_rate);
|
if((s->enc_bitrate=getBitrateMode(avctx->bit_rate))<0)
|
||||||
|
{
|
||||||
|
av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -358,7 +360,7 @@ typedef struct AMRContext {
|
|||||||
int frameCount;
|
int frameCount;
|
||||||
void * decState;
|
void * decState;
|
||||||
int *enstate;
|
int *enstate;
|
||||||
enum Mode enc_bitrate;
|
int enc_bitrate;
|
||||||
} AMRContext;
|
} AMRContext;
|
||||||
|
|
||||||
static int amr_nb_decode_init(AVCodecContext * avctx)
|
static int amr_nb_decode_init(AVCodecContext * avctx)
|
||||||
@@ -412,7 +414,11 @@ static int amr_nb_encode_init(AVCodecContext * avctx)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->enc_bitrate=getBitrateMode(avctx->bit_rate);
|
if((s->enc_bitrate=getBitrateMode(avctx->bit_rate))<0)
|
||||||
|
{
|
||||||
|
av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -469,7 +475,11 @@ static int amr_nb_encode_frame(AVCodecContext *avctx,
|
|||||||
AMRContext *s = avctx->priv_data;
|
AMRContext *s = avctx->priv_data;
|
||||||
int written;
|
int written;
|
||||||
|
|
||||||
s->enc_bitrate=getBitrateMode(avctx->bit_rate);
|
if((s->enc_bitrate=getBitrateMode(avctx->bit_rate))<0)
|
||||||
|
{
|
||||||
|
av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
written = Encoder_Interface_Encode(s->enstate,
|
written = Encoder_Interface_Encode(s->enstate,
|
||||||
s->enc_bitrate,
|
s->enc_bitrate,
|
||||||
@@ -525,36 +535,34 @@ AVCodec amr_nb_encoder =
|
|||||||
/* Common code for fixed and float version*/
|
/* Common code for fixed and float version*/
|
||||||
typedef struct AMRWB_bitrates
|
typedef struct AMRWB_bitrates
|
||||||
{
|
{
|
||||||
int startrate;
|
int rate;
|
||||||
int stoprate;
|
|
||||||
int mode;
|
int mode;
|
||||||
} AMRWB_bitrates;
|
} AMRWB_bitrates;
|
||||||
|
|
||||||
static int getWBBitrateMode(int bitrate)
|
static int getWBBitrateMode(int bitrate)
|
||||||
{
|
{
|
||||||
/* Adjusted so that all bitrates can be used from commandline where
|
/* make the correspondance between bitrate and mode */
|
||||||
only a multiple of 1000 can be specified*/
|
AMRWB_bitrates rates[]={ {6600,0},
|
||||||
AMRWB_bitrates rates[]={ {0,7999,0}, //6.6kHz
|
{8850,1},
|
||||||
{8000,9999,1},//8.85
|
{12650,2},
|
||||||
{10000,13000,2},//12.65
|
{14250,3},
|
||||||
{13001,14999,3},//14.25
|
{15850,4},
|
||||||
{15000,17000,4},//15.85
|
{18250,5},
|
||||||
{17001,18000,5},//18.25
|
{19850,6},
|
||||||
{18001,22000,6},//19.85
|
{23050,7},
|
||||||
{22001,23000,7},//23.05
|
{23850,8},
|
||||||
{23001,24000,8},//23.85
|
|
||||||
};
|
};
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i=0;i<9;i++)
|
for(i=0;i<9;i++)
|
||||||
{
|
{
|
||||||
if(rates[i].startrate<=bitrate && rates[i].stoprate>=bitrate)
|
if(rates[i].rate==bitrate)
|
||||||
{
|
{
|
||||||
return(rates[i].mode);
|
return(rates[i].mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*Return highest possible*/
|
/* no bitrate matching, return an error */
|
||||||
return(8);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -583,11 +591,16 @@ static int amr_wb_encode_init(AVCodecContext * avctx)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if((s->mode=getWBBitrateMode(avctx->bit_rate))<0)
|
||||||
|
{
|
||||||
|
av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
avctx->frame_size=320;
|
avctx->frame_size=320;
|
||||||
avctx->coded_frame= avcodec_alloc_frame();
|
avctx->coded_frame= avcodec_alloc_frame();
|
||||||
|
|
||||||
s->state = E_IF_init();
|
s->state = E_IF_init();
|
||||||
s->mode=getWBBitrateMode(avctx->bit_rate);
|
|
||||||
s->allow_dtx=0;
|
s->allow_dtx=0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -609,7 +622,11 @@ static int amr_wb_encode_frame(AVCodecContext *avctx,
|
|||||||
AMRWBContext *s = avctx->priv_data;
|
AMRWBContext *s = avctx->priv_data;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
s->mode=getWBBitrateMode(avctx->bit_rate);
|
if((s->mode=getWBBitrateMode(avctx->bit_rate))<0)
|
||||||
|
{
|
||||||
|
av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
size = E_IF_encode(s->state, s->mode, data, frame, s->allow_dtx);
|
size = E_IF_encode(s->state, s->mode, data, frame, s->allow_dtx);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user