Chromium Code Reviews| 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 |
| 11 #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h" | 11 #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h" |
| 12 | 12 |
| 13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/common_types.h" | 14 #include "webrtc/common_types.h" |
| 15 #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h" | |
| 16 #include "webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h" | 15 #include "webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h" |
| 16 #include "webrtc/modules/audio_coding/main/acm2/rent_a_codec.h" | |
| 17 #include "webrtc/system_wrappers/interface/clock.h" | 17 #include "webrtc/system_wrappers/interface/clock.h" |
| 18 #include "webrtc/system_wrappers/interface/trace.h" | 18 #include "webrtc/system_wrappers/interface/trace.h" |
| 19 | 19 |
| 20 namespace webrtc { | 20 namespace webrtc { |
| 21 | 21 |
| 22 // Create module | 22 // Create module |
| 23 AudioCodingModule* AudioCodingModule::Create(int id) { | 23 AudioCodingModule* AudioCodingModule::Create(int id) { |
| 24 Config config; | 24 Config config; |
| 25 config.id = id; | 25 config.id = id; |
| 26 config.clock = Clock::GetRealTimeClock(); | 26 config.clock = Clock::GetRealTimeClock(); |
| 27 return Create(config); | 27 return Create(config); |
| 28 } | 28 } |
| 29 | 29 |
| 30 AudioCodingModule* AudioCodingModule::Create(int id, Clock* clock) { | 30 AudioCodingModule* AudioCodingModule::Create(int id, Clock* clock) { |
| 31 Config config; | 31 Config config; |
| 32 config.id = id; | 32 config.id = id; |
| 33 config.clock = clock; | 33 config.clock = clock; |
| 34 return Create(config); | 34 return Create(config); |
| 35 } | 35 } |
| 36 | 36 |
| 37 AudioCodingModule* AudioCodingModule::Create(const Config& config) { | 37 AudioCodingModule* AudioCodingModule::Create(const Config& config) { |
| 38 return new acm2::AudioCodingModuleImpl(config); | 38 return new acm2::AudioCodingModuleImpl(config); |
| 39 } | 39 } |
| 40 | 40 |
| 41 // Get number of supported codecs | |
| 42 int AudioCodingModule::NumberOfCodecs() { | 41 int AudioCodingModule::NumberOfCodecs() { |
| 43 return acm2::ACMCodecDB::kNumCodecs; | 42 return static_cast<int>(acm2::RentACodec::NumberOfCodecs()); |
| 44 } | 43 } |
| 45 | 44 |
| 46 // Get supported codec parameters with id | |
| 47 int AudioCodingModule::Codec(int list_id, CodecInst* codec) { | 45 int AudioCodingModule::Codec(int list_id, CodecInst* codec) { |
| 48 // Get the codec settings for the codec with the given list ID | 46 auto codec_id = acm2::RentACodec::CodecIdFromIndex(list_id); |
| 49 return acm2::ACMCodecDB::Codec(list_id, codec); | 47 if (!codec_id) |
| 48 return -1; | |
| 49 auto ci = acm2::RentACodec::CodecInstById(*codec_id); | |
| 50 if (!ci) | |
| 51 return -1; | |
| 52 *codec = *ci; | |
| 53 return 0; | |
| 50 } | 54 } |
| 51 | 55 |
| 52 // Get supported codec parameters with name, frequency and number of channels. | |
| 53 int AudioCodingModule::Codec(const char* payload_name, | 56 int AudioCodingModule::Codec(const char* payload_name, |
| 54 CodecInst* codec, | 57 CodecInst* codec, |
|
hlundin-webrtc
2015/10/27 13:52:02
Order of parameters is wrong for this method. |cod
kwiberg-webrtc
2015/10/27 14:43:23
This method is going away, so I decided to not cha
hlundin-webrtc
2015/10/27 15:31:27
Acknowledged.
| |
| 55 int sampling_freq_hz, | 58 int sampling_freq_hz, |
| 56 int channels) { | 59 int channels) { |
| 57 int codec_id; | 60 rtc::Maybe<CodecInst> ci = acm2::RentACodec::CodecInstByParams( |
| 58 | |
| 59 // Get the id of the codec from the database. | |
| 60 codec_id = acm2::ACMCodecDB::CodecId( | |
| 61 payload_name, sampling_freq_hz, channels); | 61 payload_name, sampling_freq_hz, channels); |
| 62 if (codec_id < 0) { | 62 if (ci) { |
| 63 // We couldn't find a matching codec, set the parameters to unacceptable | 63 *codec = *ci; |
| 64 return 0; | |
| 65 } else { | |
| 66 // We couldn't find a matching codec, so set the parameters to unacceptable | |
| 64 // values and return. | 67 // values and return. |
| 65 codec->plname[0] = '\0'; | 68 codec->plname[0] = '\0'; |
| 66 codec->pltype = -1; | 69 codec->pltype = -1; |
| 67 codec->pacsize = 0; | 70 codec->pacsize = 0; |
| 68 codec->rate = 0; | 71 codec->rate = 0; |
| 69 codec->plfreq = 0; | 72 codec->plfreq = 0; |
| 70 return -1; | 73 return -1; |
| 71 } | 74 } |
| 72 | |
| 73 // Get default codec settings. | |
| 74 acm2::ACMCodecDB::Codec(codec_id, codec); | |
| 75 | |
| 76 // Keep the number of channels from the function call. For most codecs it | |
| 77 // will be the same value as in default codec settings, but not for all. | |
| 78 codec->channels = channels; | |
| 79 | |
| 80 return 0; | |
| 81 } | 75 } |
| 82 | 76 |
| 83 // Get supported codec Index with name, frequency and number of channels. | |
| 84 int AudioCodingModule::Codec(const char* payload_name, | 77 int AudioCodingModule::Codec(const char* payload_name, |
| 85 int sampling_freq_hz, | 78 int sampling_freq_hz, |
| 86 int channels) { | 79 int channels) { |
| 87 return acm2::ACMCodecDB::CodecId(payload_name, sampling_freq_hz, channels); | 80 rtc::Maybe<acm2::RentACodec::CodecId> ci = acm2::RentACodec::CodecIdByParams( |
| 81 payload_name, sampling_freq_hz, channels); | |
| 82 if (!ci) | |
| 83 return -1; | |
| 84 rtc::Maybe<int> i = acm2::RentACodec::CodecIndexFromId(*ci); | |
| 85 return i ? *i : -1; | |
| 88 } | 86 } |
| 89 | 87 |
| 90 // Checks the validity of the parameters of the given codec | 88 // Checks the validity of the parameters of the given codec |
| 91 bool AudioCodingModule::IsCodecValid(const CodecInst& codec) { | 89 bool AudioCodingModule::IsCodecValid(const CodecInst& codec) { |
| 92 int codec_number = acm2::ACMCodecDB::CodecNumber(codec); | 90 bool valid = acm2::RentACodec::IsCodecValid(codec); |
| 93 | 91 if (!valid) |
| 94 if (codec_number < 0) { | |
| 95 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, -1, | 92 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, -1, |
| 96 "Invalid codec setting"); | 93 "Invalid codec setting"); |
| 97 return false; | 94 return valid; |
| 98 } else { | |
| 99 return true; | |
| 100 } | |
| 101 } | 95 } |
| 102 | 96 |
| 103 } // namespace webrtc | 97 } // namespace webrtc |
| OLD | NEW |