Revert 7807 "Removing unused opus wrapper APIs."
> Removing unused opus wrapper APIs. > > WebRtcOpus_DecodeNew(), WebRtcOpus_DecoderInitNew() have become the APIs and are ready to replace old WebRtcOpus_Decode() and WebRtcOpus_DecoderInit(). > > WebRtcOpus_DecodePlcMaster/Slave() are also removed. > > BUG= > R=henrik.lundin@webrtc.org > > Review URL: https://webrtc-codereview.appspot.com/28139004 TBR=minyue@webrtc.org Review URL: https://webrtc-codereview.appspot.com/31119004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7809 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@ -149,7 +149,8 @@ int16_t WebRtcOpus_SetComplexity(OpusEncInst* inst, int32_t complexity) {
|
||||
}
|
||||
|
||||
int16_t WebRtcOpus_DecoderCreate(OpusDecInst** inst, int channels) {
|
||||
int error;
|
||||
int error_l;
|
||||
int error_r;
|
||||
OpusDecInst* state;
|
||||
|
||||
if (inst != NULL) {
|
||||
@ -159,9 +160,11 @@ int16_t WebRtcOpus_DecoderCreate(OpusDecInst** inst, int channels) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Create new memory, always at 48000 Hz. */
|
||||
state->decoder = opus_decoder_create(48000, channels, &error);
|
||||
if (error == OPUS_OK && state->decoder != NULL) {
|
||||
/* Create new memory for left and right channel, always at 48000 Hz. */
|
||||
state->decoder_left = opus_decoder_create(48000, channels, &error_l);
|
||||
state->decoder_right = opus_decoder_create(48000, channels, &error_r);
|
||||
if (error_l == OPUS_OK && error_r == OPUS_OK && state->decoder_left != NULL
|
||||
&& state->decoder_right != NULL) {
|
||||
/* Creation of memory all ok. */
|
||||
state->channels = channels;
|
||||
state->prev_decoded_samples = kWebRtcOpusDefaultFrameSize;
|
||||
@ -170,8 +173,11 @@ int16_t WebRtcOpus_DecoderCreate(OpusDecInst** inst, int channels) {
|
||||
}
|
||||
|
||||
/* If memory allocation was unsuccessful, free the entire state. */
|
||||
if (state->decoder) {
|
||||
opus_decoder_destroy(state->decoder);
|
||||
if (state->decoder_left) {
|
||||
opus_decoder_destroy(state->decoder_left);
|
||||
}
|
||||
if (state->decoder_right) {
|
||||
opus_decoder_destroy(state->decoder_right);
|
||||
}
|
||||
free(state);
|
||||
}
|
||||
@ -180,7 +186,8 @@ int16_t WebRtcOpus_DecoderCreate(OpusDecInst** inst, int channels) {
|
||||
|
||||
int16_t WebRtcOpus_DecoderFree(OpusDecInst* inst) {
|
||||
if (inst) {
|
||||
opus_decoder_destroy(inst->decoder);
|
||||
opus_decoder_destroy(inst->decoder_left);
|
||||
opus_decoder_destroy(inst->decoder_right);
|
||||
free(inst);
|
||||
return 0;
|
||||
} else {
|
||||
@ -192,8 +199,24 @@ int WebRtcOpus_DecoderChannels(OpusDecInst* inst) {
|
||||
return inst->channels;
|
||||
}
|
||||
|
||||
int16_t WebRtcOpus_DecoderInitNew(OpusDecInst* inst) {
|
||||
int error = opus_decoder_ctl(inst->decoder_left, OPUS_RESET_STATE);
|
||||
if (error == OPUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int16_t WebRtcOpus_DecoderInit(OpusDecInst* inst) {
|
||||
int error = opus_decoder_ctl(inst->decoder, OPUS_RESET_STATE);
|
||||
int error = opus_decoder_ctl(inst->decoder_left, OPUS_RESET_STATE);
|
||||
if (error == OPUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int16_t WebRtcOpus_DecoderInitSlave(OpusDecInst* inst) {
|
||||
int error = opus_decoder_ctl(inst->decoder_right, OPUS_RESET_STATE);
|
||||
if (error == OPUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
@ -233,10 +256,10 @@ static int DecodeFec(OpusDecoder* inst, const uint8_t* encoded,
|
||||
return -1;
|
||||
}
|
||||
|
||||
int16_t WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded,
|
||||
int16_t encoded_bytes, int16_t* decoded,
|
||||
int16_t* audio_type) {
|
||||
int decoded_samples = DecodeNative(inst->decoder,
|
||||
int16_t WebRtcOpus_DecodeNew(OpusDecInst* inst, const uint8_t* encoded,
|
||||
int16_t encoded_bytes, int16_t* decoded,
|
||||
int16_t* audio_type) {
|
||||
int decoded_samples = DecodeNative(inst->decoder_left,
|
||||
encoded,
|
||||
encoded_bytes,
|
||||
kWebRtcOpusMaxFrameSizePerChannel,
|
||||
@ -252,6 +275,70 @@ int16_t WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded,
|
||||
return decoded_samples;
|
||||
}
|
||||
|
||||
int16_t WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded,
|
||||
int16_t encoded_bytes, int16_t* decoded,
|
||||
int16_t* audio_type) {
|
||||
int decoded_samples;
|
||||
int i;
|
||||
|
||||
/* If mono case, just do a regular call to the decoder.
|
||||
* If stereo, call to WebRtcOpus_Decode() gives left channel as output, and
|
||||
* calls to WebRtcOpus_Decode_slave() give right channel as output.
|
||||
* This is to make stereo work with the current setup of NetEQ, which
|
||||
* requires two calls to the decoder to produce stereo. */
|
||||
|
||||
decoded_samples = DecodeNative(inst->decoder_left, encoded, encoded_bytes,
|
||||
kWebRtcOpusMaxFrameSizePerChannel, decoded,
|
||||
audio_type);
|
||||
if (decoded_samples < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (inst->channels == 2) {
|
||||
/* The parameter |decoded_samples| holds the number of samples pairs, in
|
||||
* case of stereo. Number of samples in |decoded| equals |decoded_samples|
|
||||
* times 2. */
|
||||
for (i = 0; i < decoded_samples; i++) {
|
||||
/* Take every second sample, starting at the first sample. This gives
|
||||
* the left channel. */
|
||||
decoded[i] = decoded[i * 2];
|
||||
}
|
||||
}
|
||||
|
||||
/* Update decoded sample memory, to be used by the PLC in case of losses. */
|
||||
inst->prev_decoded_samples = decoded_samples;
|
||||
|
||||
return decoded_samples;
|
||||
}
|
||||
|
||||
int16_t WebRtcOpus_DecodeSlave(OpusDecInst* inst, const uint8_t* encoded,
|
||||
int16_t encoded_bytes, int16_t* decoded,
|
||||
int16_t* audio_type) {
|
||||
int decoded_samples;
|
||||
int i;
|
||||
|
||||
decoded_samples = DecodeNative(inst->decoder_right, encoded, encoded_bytes,
|
||||
kWebRtcOpusMaxFrameSizePerChannel, decoded,
|
||||
audio_type);
|
||||
if (decoded_samples < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (inst->channels == 2) {
|
||||
/* The parameter |decoded_samples| holds the number of samples pairs, in
|
||||
* case of stereo. Number of samples in |decoded| equals |decoded_samples|
|
||||
* times 2. */
|
||||
for (i = 0; i < decoded_samples; i++) {
|
||||
/* Take every second sample, starting at the second sample. This gives
|
||||
* the right channel. */
|
||||
decoded[i] = decoded[i * 2 + 1];
|
||||
}
|
||||
} else {
|
||||
/* Decode slave should never be called for mono packets. */
|
||||
return -1;
|
||||
}
|
||||
|
||||
return decoded_samples;
|
||||
}
|
||||
|
||||
int16_t WebRtcOpus_DecodePlc(OpusDecInst* inst, int16_t* decoded,
|
||||
int16_t number_of_lost_frames) {
|
||||
int16_t audio_type = 0;
|
||||
@ -264,7 +351,7 @@ int16_t WebRtcOpus_DecodePlc(OpusDecInst* inst, int16_t* decoded,
|
||||
plc_samples = number_of_lost_frames * inst->prev_decoded_samples;
|
||||
plc_samples = (plc_samples <= kWebRtcOpusMaxFrameSizePerChannel) ?
|
||||
plc_samples : kWebRtcOpusMaxFrameSizePerChannel;
|
||||
decoded_samples = DecodeNative(inst->decoder, NULL, 0, plc_samples,
|
||||
decoded_samples = DecodeNative(inst->decoder_left, NULL, 0, plc_samples,
|
||||
decoded, &audio_type);
|
||||
if (decoded_samples < 0) {
|
||||
return -1;
|
||||
@ -273,6 +360,82 @@ int16_t WebRtcOpus_DecodePlc(OpusDecInst* inst, int16_t* decoded,
|
||||
return decoded_samples;
|
||||
}
|
||||
|
||||
int16_t WebRtcOpus_DecodePlcMaster(OpusDecInst* inst, int16_t* decoded,
|
||||
int16_t number_of_lost_frames) {
|
||||
int decoded_samples;
|
||||
int16_t audio_type = 0;
|
||||
int plc_samples;
|
||||
int i;
|
||||
|
||||
/* If mono case, just do a regular call to the decoder.
|
||||
* If stereo, call to WebRtcOpus_DecodePlcMaster() gives left channel as
|
||||
* output, and calls to WebRtcOpus_DecodePlcSlave() give right channel as
|
||||
* output. This is to make stereo work with the current setup of NetEQ, which
|
||||
* requires two calls to the decoder to produce stereo. */
|
||||
|
||||
/* The number of samples we ask for is |number_of_lost_frames| times
|
||||
* |prev_decoded_samples_|. Limit the number of samples to maximum
|
||||
* |kWebRtcOpusMaxFrameSizePerChannel|. */
|
||||
plc_samples = number_of_lost_frames * inst->prev_decoded_samples;
|
||||
plc_samples = (plc_samples <= kWebRtcOpusMaxFrameSizePerChannel) ?
|
||||
plc_samples : kWebRtcOpusMaxFrameSizePerChannel;
|
||||
decoded_samples = DecodeNative(inst->decoder_left, NULL, 0, plc_samples,
|
||||
decoded, &audio_type);
|
||||
if (decoded_samples < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (inst->channels == 2) {
|
||||
/* The parameter |decoded_samples| holds the number of sample pairs, in
|
||||
* case of stereo. The original number of samples in |decoded| equals
|
||||
* |decoded_samples| times 2. */
|
||||
for (i = 0; i < decoded_samples; i++) {
|
||||
/* Take every second sample, starting at the first sample. This gives
|
||||
* the left channel. */
|
||||
decoded[i] = decoded[i * 2];
|
||||
}
|
||||
}
|
||||
|
||||
return decoded_samples;
|
||||
}
|
||||
|
||||
int16_t WebRtcOpus_DecodePlcSlave(OpusDecInst* inst, int16_t* decoded,
|
||||
int16_t number_of_lost_frames) {
|
||||
int decoded_samples;
|
||||
int16_t audio_type = 0;
|
||||
int plc_samples;
|
||||
int i;
|
||||
|
||||
/* Calls to WebRtcOpus_DecodePlcSlave() give right channel as output.
|
||||
* The function should never be called in the mono case. */
|
||||
if (inst->channels != 2) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* The number of samples we ask for is |number_of_lost_frames| times
|
||||
* |prev_decoded_samples_|. Limit the number of samples to maximum
|
||||
* |kWebRtcOpusMaxFrameSizePerChannel|. */
|
||||
plc_samples = number_of_lost_frames * inst->prev_decoded_samples;
|
||||
plc_samples = (plc_samples <= kWebRtcOpusMaxFrameSizePerChannel)
|
||||
? plc_samples : kWebRtcOpusMaxFrameSizePerChannel;
|
||||
decoded_samples = DecodeNative(inst->decoder_right, NULL, 0, plc_samples,
|
||||
decoded, &audio_type);
|
||||
if (decoded_samples < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* The parameter |decoded_samples| holds the number of sample pairs,
|
||||
* The original number of samples in |decoded| equals |decoded_samples|
|
||||
* times 2. */
|
||||
for (i = 0; i < decoded_samples; i++) {
|
||||
/* Take every second sample, starting at the second sample. This gives
|
||||
* the right channel. */
|
||||
decoded[i] = decoded[i * 2 + 1];
|
||||
}
|
||||
|
||||
return decoded_samples;
|
||||
}
|
||||
|
||||
int16_t WebRtcOpus_DecodeFec(OpusDecInst* inst, const uint8_t* encoded,
|
||||
int16_t encoded_bytes, int16_t* decoded,
|
||||
int16_t* audio_type) {
|
||||
@ -285,7 +448,7 @@ int16_t WebRtcOpus_DecodeFec(OpusDecInst* inst, const uint8_t* encoded,
|
||||
|
||||
fec_samples = opus_packet_get_samples_per_frame(encoded, 48000);
|
||||
|
||||
decoded_samples = DecodeFec(inst->decoder, encoded, encoded_bytes,
|
||||
decoded_samples = DecodeFec(inst->decoder_left, encoded, encoded_bytes,
|
||||
fec_samples, decoded, audio_type);
|
||||
if (decoded_samples < 0) {
|
||||
return -1;
|
||||
|
Reference in New Issue
Block a user