Commit 68bc8c04 authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Making RESTRICTED_LOWDELAY an "application" that's set at init time

Also ./test_opus now takes a string for the application
parent d970a85c
......@@ -103,8 +103,6 @@ extern "C" {
#define OPUS_SET_DTX_REQUEST 4016
#define OPUS_GET_DTX_REQUEST 4017
#define OPUS_GET_FINAL_RANGE_REQUEST 4031
#define OPUS_SET_RESTRICTED_LOWDELAY_REQUEST 4032
#define OPUS_GET_RESTRICTED_LOWDELAY_REQUEST 4033
/* Macros to trigger compilation errors when the wrong types are provided to a CTL */
#define __opus_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x))
......@@ -120,15 +118,18 @@ extern "C" {
/* Values for the varrious encoder CTLs */
#define OPUS_AUTO -1000 /**<Auto bitrate @hideinitializer*/
#define OPUS_BITRATE_MAX -1 /**<Maximum bitrate @hideinitializer*/
#define OPUS_APPLICATION_VOIP 2000
#define OPUS_APPLICATION_AUDIO 2001
#define OPUS_APPLICATION_VOIP 2048
#define OPUS_APPLICATION_AUDIO 2049
#define OPUS_APPLICATION_RESTRICTED_LOWDELAY 2051
#define OPUS_SIGNAL_VOICE 3001
#define OPUS_SIGNAL_MUSIC 3002
#define OPUS_BANDWIDTH_NARROWBAND 1101 /**< 4kHz bandpass @hideinitializer*/
#define OPUS_BANDWIDTH_MEDIUMBAND 1102 /**< 6kHz bandpass @hideinitializer*/
#define OPUS_BANDWIDTH_WIDEBAND 1103 /**< 8kHz bandpass @hideinitializer*/
#define OPUS_BANDWIDTH_SUPERWIDEBAND 1104 /**<12kHz bandpass @hideinitializer*/
#define OPUS_BANDWIDTH_FULLBAND 1105 /**<24kHz bandpass @hideinitializer*/
#define OPUS_BANDWIDTH_FULLBAND 1105 /**<20kHz bandpass @hideinitializer*/
/** \endcond */
/** Configures the encoder's computational complexity.
......
......@@ -67,7 +67,6 @@ struct OpusEncoder {
int vbr_constraint;
int bitrate_bps;
int user_bitrate_bps;
int lowdelay;
int encoder_buffer;
#define OPUS_ENCODER_RESET_START stream_channels
......@@ -145,7 +144,8 @@ int opus_encoder_init(OpusEncoder* st, opus_int32 Fs, int channels, int applicat
if (channels > 2 || channels < 1)
return OPUS_BAD_ARG;
if (application < OPUS_APPLICATION_VOIP || application > OPUS_APPLICATION_AUDIO)
if (application != OPUS_APPLICATION_VOIP && application != OPUS_APPLICATION_AUDIO
&& application != OPUS_APPLICATION_RESTRICTED_LOWDELAY)
return OPUS_BAD_ARG;
if (Fs != 8000 && Fs != 12000 && Fs != 16000 && Fs != 24000 && Fs != 48000)
return OPUS_BAD_ARG;
......@@ -390,7 +390,7 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
silk_enc = (char*)st+st->silk_enc_offset;
celt_enc = (CELTEncoder*)((char*)st+st->celt_enc_offset);
if (st->lowdelay)
if (st->application == OPUS_APPLICATION_RESTRICTED_LOWDELAY)
delay_compensation = 0;
else
delay_compensation = st->delay_compensation;
......@@ -455,7 +455,7 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
}
#else
/* Mode selection depending on application and signal type */
if (st->lowdelay)
if (st->application == OPUS_APPLICATION_RESTRICTED_LOWDELAY)
{
st->mode = MODE_CELT_ONLY;
} else if (st->user_forced_mode == OPUS_AUTO)
......@@ -994,6 +994,13 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...)
case OPUS_SET_APPLICATION_REQUEST:
{
opus_int32 value = va_arg(ap, opus_int32);
if ( (value != OPUS_APPLICATION_VOIP && value != OPUS_APPLICATION_AUDIO
&& value != OPUS_APPLICATION_RESTRICTED_LOWDELAY)
|| (!st->first && st->application != value))
{
ret = OPUS_BAD_ARG;
break;
}
st->application = value;
}
break;
......@@ -1164,7 +1171,7 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...)
{
opus_int32 *value = va_arg(ap, opus_int32*);
*value = st->Fs/400;
if (!st->lowdelay)
if (st->application != OPUS_APPLICATION_RESTRICTED_LOWDELAY)
*value += st->delay_compensation;
}
break;
......@@ -1202,23 +1209,6 @@ int opus_encoder_ctl(OpusEncoder *st, int request, ...)
st->user_forced_mode = value;
}
break;
case OPUS_SET_RESTRICTED_LOWDELAY_REQUEST:
{
opus_int32 value = va_arg(ap, opus_int32);
if (!st->first && st->lowdelay != !!value)
{
ret = OPUS_BAD_ARG;
break;
}
st->lowdelay = !!value;
}
break;
case OPUS_GET_RESTRICTED_LOWDELAY_REQUEST:
{
opus_int32 *value = va_arg(ap, opus_int32*);
*value = st->lowdelay;
}
break;
default:
/* fprintf(stderr, "unknown opus_encoder_ctl() request: %d", request);*/
ret = OPUS_UNIMPLEMENTED;
......
......@@ -42,9 +42,9 @@
void print_usage( char* argv[] )
{
fprintf(stderr, "Usage: %s [-e | -d] <application (0/1)> <sampling rate (Hz)> <channels (1/2)> "
fprintf(stderr, "Usage: %s [-e | -d] <application> <sampling rate (Hz)> <channels (1/2)> "
"<bits per second> [options] <input> <output>\n\n", argv[0]);
fprintf(stderr, "mode: 0 for VoIP, 1 for audio:\n" );
fprintf(stderr, "mode: voip | audio | restricted-lowdelay\n" );
fprintf(stderr, "options:\n" );
fprintf(stderr, "-e : only runs the encoder (output the bit-stream)\n" );
fprintf(stderr, "-d : only runs the decoder (reads the bit-stream as input)\n" );
......@@ -118,7 +118,6 @@ int main(int argc, char *argv[])
int max_frame_size = 960*6;
int curr_read=0;
int sweep_bps = 0;
int lowdelay = 0;
if (argc < 7 )
{
......@@ -139,7 +138,17 @@ int main(int argc, char *argv[])
argv++;
argc--;
}
application = atoi(argv[1]) + OPUS_APPLICATION_VOIP;
if (strcmp(argv[1], "voip")==0)
application = OPUS_APPLICATION_VOIP;
else if (strcmp(argv[1], "audio")==0)
application = OPUS_APPLICATION_AUDIO;
else if (strcmp(argv[1], "restricted-lowdelay")==0)
application = OPUS_APPLICATION_RESTRICTED_LOWDELAY;
else {
fprintf(stderr, "unknown application: %s\n", argv[1]);
print_usage(argv);
return 1;
}
sampling_rate = (opus_int32)atol(argv[2]);
channels = atoi(argv[3]);
bitrate_bps = (opus_int32)atol(argv[4]);
......@@ -217,9 +226,6 @@ int main(int argc, char *argv[])
} else if( STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-forcemono" ) == 0 ) {
forcechannels = 1;
args++;
} else if( STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-lowdelay" ) == 0 ) {
lowdelay = 1;
args++;
} else if( STR_CASEINSENSITIVE_COMPARE( argv[ args ], "-cvbr" ) == 0 ) {
cvbr = 1;
args++;
......@@ -239,8 +245,8 @@ int main(int argc, char *argv[])
}
}
if( application < OPUS_APPLICATION_VOIP || application > OPUS_APPLICATION_AUDIO) {
fprintf (stderr, "mode must be: 0 or 1\n");
if( application < OPUS_APPLICATION_VOIP || application > OPUS_APPLICATION_RESTRICTED_LOWDELAY) {
fprintf (stderr, "mode must be: 0, 1, or 2\n");
return 1;
}
......@@ -299,7 +305,6 @@ int main(int argc, char *argv[])
opus_encoder_ctl(enc, OPUS_SET_FORCE_CHANNELS(forcechannels));
opus_encoder_ctl(enc, OPUS_SET_DTX(use_dtx));
opus_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC(packet_loss_perc));
opus_encoder_ctl(enc, OPUS_SET_RESTRICTED_LOWDELAY(lowdelay));
opus_encoder_ctl(enc, OPUS_GET_LOOKAHEAD(&skip));
......
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