From af50ce9200235158e54399c7f9cb8c2c5dab8008 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin <jmvalin@jmvalin.ca> Date: Sun, 11 Sep 2011 20:13:47 -0400 Subject: [PATCH] Implements OPUS_MULTISTREAM_{EN|DE}CODER_GET_STATE Untested --- src/opus_multistream.c | 40 ++++++++++++++++++++++++++++++++++++++-- src/opus_multistream.h | 9 +++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/opus_multistream.c b/src/opus_multistream.c index 16c11182b..c1238ae71 100644 --- a/src/opus_multistream.c +++ b/src/opus_multistream.c @@ -443,6 +443,25 @@ int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) } } break; + case OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST: + { + int s; + opus_int32 stream_id; + OpusEncoder **value; + stream_id = va_arg(ap, opus_int32); + if (stream_id<0 || stream_id >= st->layout.nb_streams) + ret = OPUS_BAD_ARG; + value = va_arg(ap, OpusEncoder**); + for (s=0;s<stream_id;s++) + { + if (s < st->layout.nb_coupled_streams) + ptr += align(coupled_size); + else + ptr += align(mono_size); + } + *value = (OpusEncoder*)ptr; + } + break; default: ret = OPUS_UNIMPLEMENTED; break; @@ -728,7 +747,6 @@ int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...) case OPUS_GET_FINAL_RANGE_REQUEST: { int s; - /* This only works for int32* params, but that's all we have right now */ opus_uint32 *value = va_arg(ap, opus_uint32*); for (s=0;s<st->layout.nb_streams;s++) { @@ -748,7 +766,6 @@ int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...) case OPUS_RESET_STATE: { int s; - /* This only works for int32* params, but that's all we have right now */ for (s=0;s<st->layout.nb_streams;s++) { OpusDecoder *dec; @@ -764,6 +781,25 @@ int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...) } } break; + case OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST: + { + int s; + opus_int32 stream_id; + OpusDecoder **value; + stream_id = va_arg(ap, opus_int32); + if (stream_id<0 || stream_id >= st->layout.nb_streams) + ret = OPUS_BAD_ARG; + value = va_arg(ap, OpusDecoder**); + for (s=0;s<stream_id;s++) + { + if (s < st->layout.nb_coupled_streams) + ptr += align(coupled_size); + else + ptr += align(mono_size); + } + *value = (OpusDecoder*)ptr; + } + break; default: ret = OPUS_UNIMPLEMENTED; break; diff --git a/src/opus_multistream.h b/src/opus_multistream.h index c68ecd68a..2723154de 100644 --- a/src/opus_multistream.h +++ b/src/opus_multistream.h @@ -38,6 +38,15 @@ typedef struct OpusMSEncoder OpusMSEncoder; typedef struct OpusMSDecoder OpusMSDecoder; +#define __opus_check_encstate_ptr(ptr) ((ptr) + ((ptr) - (OpusEncoder**)(ptr))) +#define __opus_check_decstate_ptr(ptr) ((ptr) + ((ptr) - (OpusDecoder**)(ptr))) + +#define OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST 5120 +#define OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST 5122 + +#define OPUS_MULTISTREAM_GET_ENCODER_STATE(x,y) OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST, __opus_check_int(x), __opus_check_encstate_ptr(y) +#define OPUS_MULTISTREAM_GET_DECODER_STATE(x,y) OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST, __opus_check_int(x), __opus_check_decstate_ptr(y) + OPUS_EXPORT OpusMSEncoder *opus_multistream_encoder_create( opus_int32 Fs, /**< Sampling rate of input signal (Hz) */ int channels, /**< Number of channels (1/2) in input signal */ -- GitLab