dynamically set nb_samples by samplerate
This commit is contained in:
parent
9d20ce9b59
commit
999400dc53
|
@ -143,19 +143,20 @@ recording::MediaRet recording::MediaRecorder::setup_audio_stream()
|
||||||
aenc->channel_layout = AV_CH_LAYOUT_STEREO;
|
aenc->channel_layout = AV_CH_LAYOUT_STEREO;
|
||||||
aenc->channels = 2;
|
aenc->channels = 2;
|
||||||
#endif
|
#endif
|
||||||
aenc->time_base = { 1, aenc->sample_rate };
|
aenc->time_base = (AVRational){1, aenc->sample_rate};
|
||||||
ast->time_base = { 1, STREAM_FRAME_RATE };
|
ast->time_base = (AVRational){1, STREAM_FRAME_RATE};
|
||||||
// open and use codec on stream
|
|
||||||
|
// Open and use codec on stream
|
||||||
int nb_samples;
|
int nb_samples;
|
||||||
if (avcodec_open2(aenc, acodec, NULL) < 0)
|
if (avcodec_open2(aenc, acodec, NULL) < 0)
|
||||||
return MRET_ERR_NOCODEC;
|
return MRET_ERR_NOCODEC;
|
||||||
if (avcodec_parameters_from_context(ast->codecpar, aenc) < 0)
|
if (avcodec_parameters_from_context(ast->codecpar, aenc) < 0)
|
||||||
return MRET_ERR_BUFSIZE;
|
return MRET_ERR_BUFSIZE;
|
||||||
// number of samples per frame
|
|
||||||
|
// Calculate number of samples per frame based on sample rate
|
||||||
if (aenc->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)
|
if (aenc->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)
|
||||||
{
|
{
|
||||||
//nb_samples = 10000; // can be any value, but we use our aud buffer size
|
nb_samples = (int)(aenc->sample_rate / STREAM_FRAME_RATE);
|
||||||
nb_samples = 1470;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
nb_samples = aenc->frame_size;
|
nb_samples = aenc->frame_size;
|
||||||
|
|
Loading…
Reference in New Issue