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/neteq/decoder_database.h" | 11 #include "webrtc/modules/audio_coding/neteq/decoder_database.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <utility> // pair | 14 #include <utility> // pair |
15 | 15 |
| 16 #include "webrtc/base/checks.h" |
16 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
17 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" | 18 #include "webrtc/modules/audio_coding/codecs/audio_decoder.h" |
18 | 19 |
19 namespace webrtc { | 20 namespace webrtc { |
20 | 21 |
21 DecoderDatabase::DecoderDatabase() | 22 DecoderDatabase::DecoderDatabase() |
22 : active_decoder_(-1), active_cng_decoder_(-1) {} | 23 : active_decoder_(-1), active_cng_decoder_(-1) {} |
23 | 24 |
24 DecoderDatabase::~DecoderDatabase() {} | 25 DecoderDatabase::~DecoderDatabase() {} |
25 | 26 |
26 DecoderDatabase::DecoderInfo::~DecoderInfo() { | 27 DecoderDatabase::DecoderInfo::~DecoderInfo() { |
27 if (!external) delete decoder; | 28 if (!external) delete decoder; |
28 } | 29 } |
29 | 30 |
30 bool DecoderDatabase::Empty() const { return decoders_.empty(); } | 31 bool DecoderDatabase::Empty() const { return decoders_.empty(); } |
31 | 32 |
32 int DecoderDatabase::Size() const { return static_cast<int>(decoders_.size()); } | 33 int DecoderDatabase::Size() const { return static_cast<int>(decoders_.size()); } |
33 | 34 |
34 void DecoderDatabase::Reset() { | 35 void DecoderDatabase::Reset() { |
35 decoders_.clear(); | 36 decoders_.clear(); |
36 active_decoder_ = -1; | 37 active_decoder_ = -1; |
37 active_cng_decoder_ = -1; | 38 active_cng_decoder_ = -1; |
38 } | 39 } |
39 | 40 |
40 int DecoderDatabase::RegisterPayload(uint8_t rtp_payload_type, | 41 int DecoderDatabase::RegisterPayload(uint8_t rtp_payload_type, |
41 NetEqDecoder codec_type) { | 42 NetEqDecoder codec_type, |
| 43 const std::string& name) { |
42 if (rtp_payload_type > 0x7F) { | 44 if (rtp_payload_type > 0x7F) { |
43 return kInvalidRtpPayloadType; | 45 return kInvalidRtpPayloadType; |
44 } | 46 } |
45 if (!CodecSupported(codec_type)) { | 47 if (!CodecSupported(codec_type)) { |
46 return kCodecNotSupported; | 48 return kCodecNotSupported; |
47 } | 49 } |
48 int fs_hz = CodecSampleRateHz(codec_type); | 50 const int fs_hz = CodecSampleRateHz(codec_type); |
49 std::pair<DecoderMap::iterator, bool> ret; | 51 DecoderInfo info(codec_type, name, fs_hz, NULL, false); |
50 DecoderInfo info(codec_type, fs_hz, NULL, false); | 52 auto ret = decoders_.insert(std::make_pair(rtp_payload_type, info)); |
51 ret = decoders_.insert(std::make_pair(rtp_payload_type, info)); | |
52 if (ret.second == false) { | 53 if (ret.second == false) { |
53 // Database already contains a decoder with type |rtp_payload_type|. | 54 // Database already contains a decoder with type |rtp_payload_type|. |
54 return kDecoderExists; | 55 return kDecoderExists; |
55 } | 56 } |
56 return kOK; | 57 return kOK; |
57 } | 58 } |
58 | 59 |
59 int DecoderDatabase::InsertExternal(uint8_t rtp_payload_type, | 60 int DecoderDatabase::InsertExternal(uint8_t rtp_payload_type, |
60 NetEqDecoder codec_type, | 61 NetEqDecoder codec_type, |
| 62 const std::string& codec_name, |
61 int fs_hz, | 63 int fs_hz, |
62 AudioDecoder* decoder) { | 64 AudioDecoder* decoder) { |
63 if (rtp_payload_type > 0x7F) { | 65 if (rtp_payload_type > 0x7F) { |
64 return kInvalidRtpPayloadType; | 66 return kInvalidRtpPayloadType; |
65 } | 67 } |
66 if (!CodecSupported(codec_type)) { | 68 if (!CodecSupported(codec_type)) { |
67 return kCodecNotSupported; | 69 return kCodecNotSupported; |
68 } | 70 } |
69 if (fs_hz != 8000 && fs_hz != 16000 && fs_hz != 32000 && fs_hz != 48000) { | 71 if (fs_hz != 8000 && fs_hz != 16000 && fs_hz != 32000 && fs_hz != 48000) { |
70 return kInvalidSampleRate; | 72 return kInvalidSampleRate; |
71 } | 73 } |
72 if (!decoder) { | 74 if (!decoder) { |
73 return kInvalidPointer; | 75 return kInvalidPointer; |
74 } | 76 } |
75 std::pair<DecoderMap::iterator, bool> ret; | 77 std::pair<DecoderMap::iterator, bool> ret; |
76 DecoderInfo info(codec_type, fs_hz, decoder, true); | 78 DecoderInfo info(codec_type, codec_name, fs_hz, decoder, true); |
77 ret = decoders_.insert(std::make_pair(rtp_payload_type, info)); | 79 ret = decoders_.insert(std::make_pair(rtp_payload_type, info)); |
78 if (ret.second == false) { | 80 if (ret.second == false) { |
79 // Database already contains a decoder with type |rtp_payload_type|. | 81 // Database already contains a decoder with type |rtp_payload_type|. |
80 return kDecoderExists; | 82 return kDecoderExists; |
81 } | 83 } |
82 return kOK; | 84 return kOK; |
83 } | 85 } |
84 | 86 |
85 int DecoderDatabase::Remove(uint8_t rtp_payload_type) { | 87 int DecoderDatabase::Remove(uint8_t rtp_payload_type) { |
86 if (decoders_.erase(rtp_payload_type) == 0) { | 88 if (decoders_.erase(rtp_payload_type) == 0) { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 LOG(LS_WARNING) << "CheckPayloadTypes: unknown RTP payload type " | 253 LOG(LS_WARNING) << "CheckPayloadTypes: unknown RTP payload type " |
252 << static_cast<int>((*it)->header.payloadType); | 254 << static_cast<int>((*it)->header.payloadType); |
253 return kDecoderNotFound; | 255 return kDecoderNotFound; |
254 } | 256 } |
255 } | 257 } |
256 return kOK; | 258 return kOK; |
257 } | 259 } |
258 | 260 |
259 | 261 |
260 } // namespace webrtc | 262 } // namespace webrtc |
OLD | NEW |