Commit 19cd01c9 authored by Simon Morlat's avatar Simon Morlat
Browse files

let opus encoder decide about its internal bandwidth.

detect number of configured cpus instead of only active ones.
parent 22374b29
......@@ -306,47 +306,33 @@ static void apply_max_bitrate(OpusEncData *d) {
ms_message("Setting opus codec bitrate to [%i] from network bitrate [%i] with ptime [%i]", d->bitrate, d->max_network_bitrate, d->ptime);
/* give the bitrate to the encoder if exists*/
if (d->state) {
opus_int32 maxBandwidth;
opus_int32 maxBandwidth=0;
/*tell the target bitrate, opus will choose internally the bandwidth to use*/
int error = opus_encoder_ctl(d->state, OPUS_SET_BITRATE(d->bitrate));
if (error != OPUS_OK) {
ms_error("could not set bit rate to opus encoder: %s", opus_strerror(error));
}
/* set output sampling rate according to bitrate and RFC section 3.1.1 */
if (d->bitrate<12000) {
/* implement maxplaybackrate parameter, which is constraint on top of bitrate */
if (d->maxplaybackrate <= 8000) {
maxBandwidth = OPUS_BANDWIDTH_NARROWBAND;
} else if (d->bitrate<20000) {
} else if (d->maxplaybackrate <= 12000) {
maxBandwidth = OPUS_BANDWIDTH_MEDIUMBAND;
} else if (d->maxplaybackrate <= 16000) {
maxBandwidth = OPUS_BANDWIDTH_WIDEBAND;
} else if (d->bitrate<40000) {
maxBandwidth = OPUS_BANDWIDTH_FULLBAND;
} else if (d->bitrate<64000) {
maxBandwidth = OPUS_BANDWIDTH_FULLBAND;
} else if (d->maxplaybackrate <= 24000) {
maxBandwidth = OPUS_BANDWIDTH_SUPERWIDEBAND;
} else {
maxBandwidth = OPUS_BANDWIDTH_FULLBAND;
}
/* check if selected maxBandwidth is compatible with the maxplaybackrate parameter */
if (d->maxplaybackrate < 12000) {
maxBandwidth = OPUS_BANDWIDTH_NARROWBAND;
} else if (d->maxplaybackrate < 16000) {
if (maxBandwidth != OPUS_BANDWIDTH_NARROWBAND) {
maxBandwidth = OPUS_BANDWIDTH_MEDIUMBAND;
}
} else if (d->maxplaybackrate < 24000) {
if (maxBandwidth != OPUS_BANDWIDTH_NARROWBAND) {
maxBandwidth = OPUS_BANDWIDTH_WIDEBAND;
}
} else if (d->maxplaybackrate < 48000) {
if (maxBandwidth == OPUS_BANDWIDTH_FULLBAND) {
maxBandwidth = OPUS_BANDWIDTH_SUPERWIDEBAND;
if (maxBandwidth!=0){
error = opus_encoder_ctl(d->state, OPUS_SET_MAX_BANDWIDTH(maxBandwidth));
if (error != OPUS_OK) {
ms_error("could not set max bandwidth to opus encoder: %s", opus_strerror(error));
}
}
error = opus_encoder_ctl(d->state, OPUS_SET_MAX_BANDWIDTH(maxBandwidth));
if (error != OPUS_OK) {
ms_error("could not set max bandwidth to opus encoder: %s", opus_strerror(error));
}
}
}
......@@ -379,9 +365,6 @@ static int ms_opus_enc_set_bitrate(MSFilter *f, void *arg) {
int ptimeTarget = d->ptime;
int bitrate = *((int *)arg); // the argument is the network bitrate requested
/* this function also manage the ptime, check if we are increasing or decreasing the bitrate in order to possibly decrease or increase ptime */
if (d->bitrate>0 && d->ptime>0) { /* at first call to set_bitrate(bitrate is initialised at -1), do not modify ptime, neither if it wasn't initialised too */
if (bitrate > d->max_network_bitrate ) {
......
......@@ -154,7 +154,7 @@ void ms_factory_init(MSFactory *obj){
num_cpu = sysinfo.dwNumberOfProcessors;
#elif __APPLE__ || __linux
num_cpu = sysconf( _SC_NPROCESSORS_ONLN );
num_cpu = sysconf( _SC_NPROCESSORS_CONF); /*check the number of processors configured, not just the one that are currently active.*/
#elif __QNX__
num_cpu = _syspage_ptr->num_cpu;
#else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment