Opus mono/stereo on the same payloadtype, and fix of memory bug

During call setup Opus should always be signaled as a 48000 Hz stereo codec, not depending on what we plan to send, or how we plan to decode received packets.
The previous implementation had different payload types for mono and stereo, which breaks the proposed standard.

While working on this CL I ran in to the problem reported earlier, that we could get a crash related to deleting decoder memory. This should now be solved in Patch Set 3.

BUG=issue1013, issue1112

Review URL: https://webrtc-codereview.appspot.com/933022

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3177 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
tina.legrand@webrtc.org
2012-11-28 12:23:29 +00:00
parent 81fb7bfd8b
commit c4590580e8
14 changed files with 161 additions and 60 deletions

View File

@ -55,6 +55,7 @@ int16_t WebRtcOpus_EncoderCreate(OpusEncInst** inst, int32_t channels) {
int16_t WebRtcOpus_EncoderFree(OpusEncInst* inst) {
opus_encoder_destroy(inst->encoder);
free(inst);
return 0;
}
@ -90,23 +91,36 @@ struct WebRtcOpusDecInst {
};
int16_t WebRtcOpus_DecoderCreate(OpusDecInst** inst, int channels) {
int error_l;
int error_r;
OpusDecInst* state;
// Create Opus decoder memory.
state = (OpusDecInst*) calloc(1, sizeof(OpusDecInst));
if (state) {
int error_l;
int error_r;
// Always create a 48000 Hz Opus decoder.
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) {
state->channels = channels;
*inst = state;
return 0;
}
free(state);
state = NULL;
if (state == NULL) {
return -1;
}
// 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;
*inst = state;
return 0;
}
// If memory allocation was unsuccessful, free the entire state.
if (state->decoder_left) {
opus_decoder_destroy(state->decoder_left);
}
if (state->decoder_right) {
opus_decoder_destroy(state->decoder_right);
}
free(state);
state = NULL;
return -1;
}
@ -117,6 +131,10 @@ int16_t WebRtcOpus_DecoderFree(OpusDecInst* inst) {
return 0;
}
int WebRtcOpus_DecoderChannels(OpusDecInst* inst) {
return inst->channels;
}
int16_t WebRtcOpus_DecoderInit(OpusDecInst* inst) {
int error = opus_decoder_ctl(inst->decoder_left, OPUS_RESET_STATE);
if (error == OPUS_OK) {