OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 "~VoECodecImpl() - dtor"); | 44 "~VoECodecImpl() - dtor"); |
45 } | 45 } |
46 | 46 |
47 int VoECodecImpl::NumOfCodecs() { | 47 int VoECodecImpl::NumOfCodecs() { |
48 // Number of supported codecs in the ACM | 48 // Number of supported codecs in the ACM |
49 uint8_t nSupportedCodecs = AudioCodingModule::NumberOfCodecs(); | 49 uint8_t nSupportedCodecs = AudioCodingModule::NumberOfCodecs(); |
50 return (nSupportedCodecs); | 50 return (nSupportedCodecs); |
51 } | 51 } |
52 | 52 |
53 int VoECodecImpl::GetCodec(int index, CodecInst& codec) { | 53 int VoECodecImpl::GetCodec(int index, CodecInst& codec) { |
54 CodecInst acmCodec; | 54 if (AudioCodingModule::Codec(index, &codec) == -1) { |
55 if (AudioCodingModule::Codec(index, &acmCodec) == -1) { | |
56 _shared->SetLastError(VE_INVALID_LISTNR, kTraceError, | 55 _shared->SetLastError(VE_INVALID_LISTNR, kTraceError, |
57 "GetCodec() invalid index"); | 56 "GetCodec() invalid index"); |
58 return -1; | 57 return -1; |
59 } | 58 } |
60 ACMToExternalCodecRepresentation(codec, acmCodec); | |
61 return 0; | 59 return 0; |
62 } | 60 } |
63 | 61 |
64 int VoECodecImpl::SetSendCodec(int channel, const CodecInst& codec) { | 62 int VoECodecImpl::SetSendCodec(int channel, const CodecInst& codec) { |
65 CodecInst copyCodec; | |
66 ExternalToACMCodecRepresentation(copyCodec, codec); | |
67 | |
68 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), | 63 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
69 "SetSendCodec(channel=%d, codec)", channel); | 64 "SetSendCodec(channel=%d, codec)", channel); |
70 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), | 65 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), |
71 "codec: plname=%s, pacsize=%d, plfreq=%d, pltype=%d, " | 66 "codec: plname=%s, pacsize=%d, plfreq=%d, pltype=%d, " |
72 "channels=%d, rate=%d", | 67 "channels=%d, rate=%d", |
73 codec.plname, codec.pacsize, codec.plfreq, codec.pltype, | 68 codec.plname, codec.pacsize, codec.plfreq, codec.pltype, |
74 codec.channels, codec.rate); | 69 codec.channels, codec.rate); |
75 if (!_shared->statistics().Initialized()) { | 70 if (!_shared->statistics().Initialized()) { |
76 _shared->SetLastError(VE_NOT_INITED, kTraceError); | 71 _shared->SetLastError(VE_NOT_INITED, kTraceError); |
77 return -1; | 72 return -1; |
78 } | 73 } |
79 // External sanity checks performed outside the ACM | 74 // External sanity checks performed outside the ACM |
80 if ((STR_CASE_CMP(copyCodec.plname, "L16") == 0) && | 75 if ((STR_CASE_CMP(codec.plname, "L16") == 0) && (codec.pacsize >= 960)) { |
81 (copyCodec.pacsize >= 960)) { | |
82 _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, | 76 _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
83 "SetSendCodec() invalid L16 packet size"); | 77 "SetSendCodec() invalid L16 packet size"); |
84 return -1; | 78 return -1; |
85 } | 79 } |
86 if (!STR_CASE_CMP(copyCodec.plname, "CN") || | 80 if (!STR_CASE_CMP(codec.plname, "CN") || |
87 !STR_CASE_CMP(copyCodec.plname, "TELEPHONE-EVENT") || | 81 !STR_CASE_CMP(codec.plname, "TELEPHONE-EVENT") || |
88 !STR_CASE_CMP(copyCodec.plname, "RED")) { | 82 !STR_CASE_CMP(codec.plname, "RED")) { |
89 _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, | 83 _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
90 "SetSendCodec() invalid codec name"); | 84 "SetSendCodec() invalid codec name"); |
91 return -1; | 85 return -1; |
92 } | 86 } |
93 if ((copyCodec.channels != 1) && (copyCodec.channels != 2)) { | 87 if ((codec.channels != 1) && (codec.channels != 2)) { |
94 _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, | 88 _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
95 "SetSendCodec() invalid number of channels"); | 89 "SetSendCodec() invalid number of channels"); |
96 return -1; | 90 return -1; |
97 } | 91 } |
98 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); | 92 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
99 voe::Channel* channelPtr = ch.channel(); | 93 voe::Channel* channelPtr = ch.channel(); |
100 if (channelPtr == NULL) { | 94 if (channelPtr == NULL) { |
101 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, | 95 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
102 "GetSendCodec() failed to locate channel"); | 96 "GetSendCodec() failed to locate channel"); |
103 return -1; | 97 return -1; |
104 } | 98 } |
105 if (!AudioCodingModule::IsCodecValid((CodecInst&)copyCodec)) { | 99 if (!AudioCodingModule::IsCodecValid(codec)) { |
106 _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, | 100 _shared->SetLastError(VE_INVALID_ARGUMENT, kTraceError, |
107 "SetSendCodec() invalid codec"); | 101 "SetSendCodec() invalid codec"); |
108 return -1; | 102 return -1; |
109 } | 103 } |
110 if (channelPtr->SetSendCodec(copyCodec) != 0) { | 104 if (channelPtr->SetSendCodec(codec) != 0) { |
111 _shared->SetLastError(VE_CANNOT_SET_SEND_CODEC, kTraceError, | 105 _shared->SetLastError(VE_CANNOT_SET_SEND_CODEC, kTraceError, |
112 "SetSendCodec() failed to set send codec"); | 106 "SetSendCodec() failed to set send codec"); |
113 return -1; | 107 return -1; |
114 } | 108 } |
115 | 109 |
116 return 0; | 110 return 0; |
117 } | 111 } |
118 | 112 |
119 int VoECodecImpl::GetSendCodec(int channel, CodecInst& codec) { | 113 int VoECodecImpl::GetSendCodec(int channel, CodecInst& codec) { |
120 if (!_shared->statistics().Initialized()) { | 114 if (!_shared->statistics().Initialized()) { |
121 _shared->SetLastError(VE_NOT_INITED, kTraceError); | 115 _shared->SetLastError(VE_NOT_INITED, kTraceError); |
122 return -1; | 116 return -1; |
123 } | 117 } |
124 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); | 118 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
125 voe::Channel* channelPtr = ch.channel(); | 119 voe::Channel* channelPtr = ch.channel(); |
126 if (channelPtr == NULL) { | 120 if (channelPtr == NULL) { |
127 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, | 121 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
128 "GetSendCodec() failed to locate channel"); | 122 "GetSendCodec() failed to locate channel"); |
129 return -1; | 123 return -1; |
130 } | 124 } |
131 CodecInst acmCodec; | 125 if (channelPtr->GetSendCodec(codec) != 0) { |
132 if (channelPtr->GetSendCodec(acmCodec) != 0) { | |
133 _shared->SetLastError(VE_CANNOT_GET_SEND_CODEC, kTraceError, | 126 _shared->SetLastError(VE_CANNOT_GET_SEND_CODEC, kTraceError, |
134 "GetSendCodec() failed to get send codec"); | 127 "GetSendCodec() failed to get send codec"); |
135 return -1; | 128 return -1; |
136 } | 129 } |
137 ACMToExternalCodecRepresentation(codec, acmCodec); | |
138 return 0; | 130 return 0; |
139 } | 131 } |
140 | 132 |
141 int VoECodecImpl::SetBitRate(int channel, int bitrate_bps) { | 133 int VoECodecImpl::SetBitRate(int channel, int bitrate_bps) { |
142 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), | 134 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
143 "SetBitRate(bitrate_bps=%d)", bitrate_bps); | 135 "SetBitRate(bitrate_bps=%d)", bitrate_bps); |
144 if (!_shared->statistics().Initialized()) { | 136 if (!_shared->statistics().Initialized()) { |
145 _shared->SetLastError(VE_NOT_INITED, kTraceError); | 137 _shared->SetLastError(VE_NOT_INITED, kTraceError); |
146 return -1; | 138 return -1; |
147 } | 139 } |
148 _shared->channel_manager().GetChannel(channel).channel()->SetBitRate( | 140 _shared->channel_manager().GetChannel(channel).channel()->SetBitRate( |
149 bitrate_bps); | 141 bitrate_bps); |
150 return 0; | 142 return 0; |
151 } | 143 } |
152 | 144 |
153 int VoECodecImpl::GetRecCodec(int channel, CodecInst& codec) { | 145 int VoECodecImpl::GetRecCodec(int channel, CodecInst& codec) { |
154 if (!_shared->statistics().Initialized()) { | 146 if (!_shared->statistics().Initialized()) { |
155 _shared->SetLastError(VE_NOT_INITED, kTraceError); | 147 _shared->SetLastError(VE_NOT_INITED, kTraceError); |
156 return -1; | 148 return -1; |
157 } | 149 } |
158 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); | 150 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
159 voe::Channel* channelPtr = ch.channel(); | 151 voe::Channel* channelPtr = ch.channel(); |
160 if (channelPtr == NULL) { | 152 if (channelPtr == NULL) { |
161 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, | 153 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
162 "GetRecCodec() failed to locate channel"); | 154 "GetRecCodec() failed to locate channel"); |
163 return -1; | 155 return -1; |
164 } | 156 } |
165 CodecInst acmCodec; | 157 return channelPtr->GetRecCodec(codec); |
166 if (channelPtr->GetRecCodec(acmCodec) != 0) { | |
167 return -1; | |
168 } | |
169 ACMToExternalCodecRepresentation(codec, acmCodec); | |
170 return 0; | |
171 } | 158 } |
172 | 159 |
173 int VoECodecImpl::SetRecPayloadType(int channel, const CodecInst& codec) { | 160 int VoECodecImpl::SetRecPayloadType(int channel, const CodecInst& codec) { |
174 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), | 161 WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1), |
175 "SetRecPayloadType(channel=%d, codec)", channel); | 162 "SetRecPayloadType(channel=%d, codec)", channel); |
176 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), | 163 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1), |
177 "codec: plname=%s, plfreq=%d, pltype=%d, channels=%u, " | 164 "codec: plname=%s, plfreq=%d, pltype=%d, channels=%u, " |
178 "pacsize=%d, rate=%d", | 165 "pacsize=%d, rate=%d", |
179 codec.plname, codec.plfreq, codec.pltype, codec.channels, | 166 codec.plname, codec.plfreq, codec.pltype, codec.channels, |
180 codec.pacsize, codec.rate); | 167 codec.pacsize, codec.rate); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); | 369 voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel); |
383 voe::Channel* channelPtr = ch.channel(); | 370 voe::Channel* channelPtr = ch.channel(); |
384 if (channelPtr == NULL) { | 371 if (channelPtr == NULL) { |
385 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, | 372 _shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
386 "SetOpusDtx failed to locate channel"); | 373 "SetOpusDtx failed to locate channel"); |
387 return -1; | 374 return -1; |
388 } | 375 } |
389 return channelPtr->SetOpusDtx(enable_dtx); | 376 return channelPtr->SetOpusDtx(enable_dtx); |
390 } | 377 } |
391 | 378 |
392 void VoECodecImpl::ACMToExternalCodecRepresentation(CodecInst& toInst, | |
393 const CodecInst& fromInst) { | |
394 toInst = fromInst; | |
395 if (STR_CASE_CMP(fromInst.plname, "SILK") == 0) { | |
396 if (fromInst.plfreq == 12000) { | |
397 if (fromInst.pacsize == 320) { | |
398 toInst.pacsize = 240; | |
399 } else if (fromInst.pacsize == 640) { | |
400 toInst.pacsize = 480; | |
401 } else if (fromInst.pacsize == 960) { | |
402 toInst.pacsize = 720; | |
403 } | |
404 } else if (fromInst.plfreq == 24000) { | |
405 if (fromInst.pacsize == 640) { | |
406 toInst.pacsize = 480; | |
407 } else if (fromInst.pacsize == 1280) { | |
408 toInst.pacsize = 960; | |
409 } else if (fromInst.pacsize == 1920) { | |
410 toInst.pacsize = 1440; | |
411 } | |
412 } | |
413 } | |
414 } | |
415 | |
416 void VoECodecImpl::ExternalToACMCodecRepresentation(CodecInst& toInst, | |
417 const CodecInst& fromInst) { | |
418 toInst = fromInst; | |
419 if (STR_CASE_CMP(fromInst.plname, "SILK") == 0) { | |
420 if (fromInst.plfreq == 12000) { | |
421 if (fromInst.pacsize == 240) { | |
422 toInst.pacsize = 320; | |
423 } else if (fromInst.pacsize == 480) { | |
424 toInst.pacsize = 640; | |
425 } else if (fromInst.pacsize == 720) { | |
426 toInst.pacsize = 960; | |
427 } | |
428 } else if (fromInst.plfreq == 24000) { | |
429 if (fromInst.pacsize == 480) { | |
430 toInst.pacsize = 640; | |
431 } else if (fromInst.pacsize == 960) { | |
432 toInst.pacsize = 1280; | |
433 } else if (fromInst.pacsize == 1440) { | |
434 toInst.pacsize = 1920; | |
435 } | |
436 } | |
437 } | |
438 } | |
439 | |
440 RtcEventLog* VoECodecImpl::GetEventLog() { | 379 RtcEventLog* VoECodecImpl::GetEventLog() { |
441 return _shared->channel_manager().GetEventLog(); | 380 return _shared->channel_manager().GetEventLog(); |
442 } | 381 } |
443 | 382 |
444 #endif // WEBRTC_VOICE_ENGINE_CODEC_API | 383 #endif // WEBRTC_VOICE_ENGINE_CODEC_API |
445 | 384 |
446 } // namespace webrtc | 385 } // namespace webrtc |
OLD | NEW |