ref: d48277374a154fe5236825e8aa739b6ee392e3e5
parent: 06cee2b1b46d9e15d7a141fce1b76933429c076e
author: Jean-Marc Valin <[email protected]>
date: Fri Aug 19 13:07:16 EDT 2011
Final range coder state now exposed through the ctl() interface
--- a/src/opus.h
+++ b/src/opus.h
@@ -52,8 +52,9 @@
#endif
-#define __check_int(x) (((void)((x) == (int)0)), (int)(x))
-#define __check_int_ptr(ptr) ((ptr) + ((ptr) - (int*)(ptr)))
+#define __check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x))
+#define __check_int_ptr(ptr) ((ptr) + ((ptr) - (opus_int32*)(ptr)))
+#define __check_uint_ptr(ptr) ((ptr) + ((ptr) - (opus_uint32*)(ptr)))
/* Error codes */
/** No error */
@@ -132,10 +133,10 @@
#define OPUS_GET_PACKET_LOSS_PERC_REQUEST 15
#define OPUS_GET_PACKET_LOSS_PERC(x) OPUS_GET_PACKET_LOSS_PERC_REQUEST, __check_int_ptr(x)
-#define OPUS_SET_DTX_FLAG_REQUEST 16
-#define OPUS_SET_DTX_FLAG(x) OPUS_SET_DTX_FLAG_REQUEST, __check_int(x)
-#define OPUS_GET_DTX_FLAG_REQUEST 17
-#define OPUS_GET_DTX_FLAG(x) OPUS_GET_DTX_FLAG_REQUEST, __check_int_ptr(x)
+#define OPUS_SET_DTX_REQUEST 16
+#define OPUS_SET_DTX(x) OPUS_SET_DTX_REQUEST, __check_int(x)
+#define OPUS_GET_DTX_REQUEST 17
+#define OPUS_GET_DTX(x) OPUS_GET_DTX_REQUEST, __check_int_ptr(x)
#define OPUS_SET_VOICE_RATIO_REQUEST 18
#define OPUS_SET_VOICE_RATIO(x) OPUS_SET_VOICE_RATIO_REQUEST, __check_int(x)
@@ -160,6 +161,11 @@
#define OPUS_GET_LOOKAHEAD_REQUEST 27
#define OPUS_GET_LOOKAHEAD(x) OPUS_GET_LOOKAHEAD_REQUEST, __check_int_ptr(x)
+/* For testing purposes: the encoder and decoder state should
+ always be identical after coding a payload */
+#define OPUS_GET_FINAL_RANGE_REQUEST 29
+#define OPUS_GET_FINAL_RANGE(x) OPUS_GET_FINAL_RANGE_REQUEST, __check_uint_ptr(x)
+
typedef struct OpusEncoder OpusEncoder;
typedef struct OpusDecoder OpusDecoder;
@@ -262,12 +268,6 @@
OPUS_EXPORT const char *opus_strerror(int error);
OPUS_EXPORT const char *opus_get_version_string(void);
-
-/* For testing purposes: the encoder and decoder state should
- always be identical after coding a payload */
-OPUS_EXPORT int opus_encoder_get_final_range(OpusEncoder *st);
-OPUS_EXPORT int opus_decoder_get_final_range(OpusDecoder *st);
-
/* Repacketizer */
typedef struct OpusRepacketizer OpusRepacketizer;
--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -724,10 +724,16 @@
{
case OPUS_GET_BANDWIDTH_REQUEST:
{
- int *value = va_arg(ap, int*);
+ opus_int32 *value = va_arg(ap, opus_int32*);
*value = st->bandwidth;
}
break;
+ case OPUS_GET_FINAL_RANGE_REQUEST:
+ {
+ opus_uint32 *value = va_arg(ap, opus_uint32*);
+ *value = st->rangeFinal;
+ }
+ break;
default:
fprintf(stderr, "unknown opus_decoder_ctl() request: %d", request);
break;
@@ -742,10 +748,6 @@
free(st);
}
-int opus_decoder_get_final_range(OpusDecoder *st)
-{
- return st->rangeFinal;
-}
int opus_packet_get_bandwidth(const unsigned char *data)
{
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -794,19 +794,19 @@
{
case OPUS_SET_APPLICATION_REQUEST:
{
- int value = va_arg(ap, int);
+ opus_int32 value = va_arg(ap, opus_int32);
st->application = value;
}
break;
case OPUS_GET_APPLICATION_REQUEST:
{
- int *value = va_arg(ap, int*);
+ opus_int32 *value = va_arg(ap, opus_int32*);
*value = st->mode;
}
break;
case OPUS_SET_BITRATE_REQUEST:
{
- int value = va_arg(ap, int);
+ opus_int32 value = va_arg(ap, opus_int32);
if (value != OPUS_BITRATE_AUTO)
{
if (value <= 0)
@@ -819,25 +819,25 @@
break;
case OPUS_GET_BITRATE_REQUEST:
{
- int *value = va_arg(ap, int*);
+ opus_int32 *value = va_arg(ap, opus_int32*);
*value = st->bitrate_bps;
}
break;
case OPUS_SET_FORCE_MONO_REQUEST:
{
- int value = va_arg(ap, int);
+ opus_int32 value = va_arg(ap, opus_int32);
st->force_mono = value;
}
break;
case OPUS_GET_FORCE_MONO_REQUEST:
{
- int *value = va_arg(ap, int*);
+ opus_int32 *value = va_arg(ap, opus_int32*);
*value = !!st->force_mono;
}
break;
case OPUS_SET_BANDWIDTH_REQUEST:
{
- int value = va_arg(ap, int);
+ opus_int32 value = va_arg(ap, opus_int32);
if (value < OPUS_BANDWIDTH_AUTO || value > OPUS_BANDWIDTH_FULLBAND)
return OPUS_BAD_ARG;
st->user_bandwidth = value;
@@ -852,25 +852,25 @@
break;
case OPUS_GET_BANDWIDTH_REQUEST:
{
- int *value = va_arg(ap, int*);
+ opus_int32 *value = va_arg(ap, opus_int32*);
*value = st->bandwidth;
}
break;
- case OPUS_SET_DTX_FLAG_REQUEST:
+ case OPUS_SET_DTX_REQUEST:
{
- int value = va_arg(ap, int);
+ opus_int32 value = va_arg(ap, opus_int32);
st->silk_mode.useDTX = value;
}
break;
- case OPUS_GET_DTX_FLAG_REQUEST:
+ case OPUS_GET_DTX_REQUEST:
{
- int *value = va_arg(ap, int*);
+ opus_int32 *value = va_arg(ap, opus_int32*);
*value = st->silk_mode.useDTX;
}
break;
case OPUS_SET_COMPLEXITY_REQUEST:
{
- int value = va_arg(ap, int);
+ opus_int32 value = va_arg(ap, opus_int32);
st->silk_mode.complexity = value;
celt_encoder_ctl(celt_enc, CELT_SET_COMPLEXITY(value));
}
@@ -877,25 +877,25 @@
break;
case OPUS_GET_COMPLEXITY_REQUEST:
{
- int *value = va_arg(ap, int*);
+ opus_int32 *value = va_arg(ap, opus_int32*);
*value = st->silk_mode.complexity;
}
break;
case OPUS_SET_INBAND_FEC_FLAG_REQUEST:
{
- int value = va_arg(ap, int);
+ opus_int32 value = va_arg(ap, opus_int32);
st->silk_mode.useInBandFEC = value;
}
break;
case OPUS_GET_INBAND_FEC_FLAG_REQUEST:
{
- int *value = va_arg(ap, int*);
+ opus_int32 *value = va_arg(ap, opus_int32*);
*value = st->silk_mode.useInBandFEC;
}
break;
case OPUS_SET_PACKET_LOSS_PERC_REQUEST:
{
- int value = va_arg(ap, int);
+ opus_int32 value = va_arg(ap, opus_int32);
if (value < 0 || value > 100)
return OPUS_BAD_ARG;
st->silk_mode.packetLossPercentage = value;
@@ -904,13 +904,13 @@
break;
case OPUS_GET_PACKET_LOSS_PERC_REQUEST:
{
- int *value = va_arg(ap, int*);
+ opus_int32 *value = va_arg(ap, opus_int32*);
*value = st->silk_mode.packetLossPercentage;
}
break;
case OPUS_SET_VBR_REQUEST:
{
- int value = va_arg(ap, int);
+ opus_int32 value = va_arg(ap, opus_int32);
st->use_vbr = value;
st->silk_mode.useCBR = 1-value;
}
@@ -917,13 +917,13 @@
break;
case OPUS_GET_VBR_REQUEST:
{
- int *value = va_arg(ap, int*);
+ opus_int32 *value = va_arg(ap, opus_int32*);
*value = st->use_vbr;
}
break;
case OPUS_SET_VOICE_RATIO_REQUEST:
{
- int value = va_arg(ap, int);
+ opus_int32 value = va_arg(ap, opus_int32);
if (value>100 || value<0)
goto bad_arg;
st->voice_ratio = value;
@@ -931,40 +931,46 @@
break;
case OPUS_GET_VOICE_RATIO_REQUEST:
{
- int *value = va_arg(ap, int*);
+ opus_int32 *value = va_arg(ap, opus_int32*);
*value = st->voice_ratio;
}
break;
case OPUS_SET_VBR_CONSTRAINT_REQUEST:
{
- int value = va_arg(ap, int);
+ opus_int32 value = va_arg(ap, opus_int32);
st->vbr_constraint = value;
}
break;
case OPUS_GET_VBR_CONSTRAINT_REQUEST:
{
- int *value = va_arg(ap, int*);
+ opus_int32 *value = va_arg(ap, opus_int32*);
*value = st->vbr_constraint;
}
break;
case OPUS_SET_SIGNAL_REQUEST:
{
- int value = va_arg(ap, int);
+ opus_int32 value = va_arg(ap, opus_int32);
st->signal_type = value;
}
break;
case OPUS_GET_SIGNAL_REQUEST:
{
- int *value = va_arg(ap, int*);
+ opus_int32 *value = va_arg(ap, opus_int32*);
*value = st->signal_type;
}
break;
case OPUS_GET_LOOKAHEAD_REQUEST:
{
- int *value = va_arg(ap, int*);
+ opus_int32 *value = va_arg(ap, opus_int32*);
*value = st->delay_compensation+st->Fs/400;
}
break;
+ case OPUS_GET_FINAL_RANGE_REQUEST:
+ {
+ opus_uint32 *value = va_arg(ap, opus_uint32*);
+ *value = st->rangeFinal;
+ }
+ break;
default:
fprintf(stderr, "unknown opus_encoder_ctl() request: %d", request);
break;
@@ -979,9 +985,4 @@
void opus_encoder_destroy(OpusEncoder *st)
{
free(st);
-}
-
-int opus_encoder_get_final_range(OpusEncoder *st)
-{
- return st->rangeFinal;
}
--- a/src/test_opus.c
+++ b/src/test_opus.c
@@ -111,7 +111,8 @@
const char *bandwidth_string;
int lost = 0, lost_prev = 1;
int toggle = 0;
- int enc_final_range[2];
+ opus_uint32 enc_final_range[2];
+ opus_uint32 dec_final_range;
int encode_only=0, decode_only=0;
if (argc < 7 )
@@ -275,7 +276,7 @@
opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complexity));
opus_encoder_ctl(enc, OPUS_SET_INBAND_FEC_FLAG(use_inbandfec));
opus_encoder_ctl(enc, OPUS_SET_FORCE_MONO(forcemono));
- opus_encoder_ctl(enc, OPUS_SET_DTX_FLAG(use_dtx));
+ opus_encoder_ctl(enc, OPUS_SET_DTX(use_dtx));
opus_encoder_ctl(enc, OPUS_SET_PACKET_LOSS_PERC(packet_loss_perc));
skip = 5*sampling_rate/1000;
@@ -349,7 +350,7 @@
}
len[toggle] = opus_encode(enc, in, frame_size, data[toggle], max_payload_bytes);
- enc_final_range[toggle] = opus_encoder_get_final_range( enc );
+ opus_encoder_ctl(enc, OPUS_GET_FINAL_RANGE(&enc_final_range[toggle]));
if (len[toggle] < 0)
{
fprintf (stderr, "opus_encode() returned %d\n", len[toggle]);
@@ -391,10 +392,11 @@
}
}
+ opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range));
/* compare final range encoder rng values of encoder and decoder */
if( enc_final_range[toggle^use_inbandfec]!=0 && !encode_only && !lost && !lost_prev &&
- opus_decoder_get_final_range( dec ) != enc_final_range[toggle^use_inbandfec] ) {
- fprintf (stderr, "Error: Range coder state mismatch between encoder and decoder in frame %d: 0x%8x vs 0x%8x\n", count, enc_final_range[toggle^use_inbandfec], opus_decoder_get_final_range( dec ));
+ dec_final_range != enc_final_range[toggle^use_inbandfec] ) {
+ fprintf (stderr, "Error: Range coder state mismatch between encoder and decoder in frame %d: 0x%8x vs 0x%8x\n", count, enc_final_range[toggle^use_inbandfec], dec_final_range);
return 0;
}