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 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_DECODER_DATABASE_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_DECODER_DATABASE_H_ |
12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_DECODER_DATABASE_H_ | 12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_DECODER_DATABASE_H_ |
13 | 13 |
14 #include <map> | 14 #include <map> |
| 15 #include <string> |
15 | 16 |
16 #include "webrtc/base/constructormagic.h" | 17 #include "webrtc/base/constructormagic.h" |
| 18 #include "webrtc/base/scoped_ptr.h" |
17 #include "webrtc/common_types.h" // NULL | 19 #include "webrtc/common_types.h" // NULL |
18 #include "webrtc/modules/audio_coding/neteq/audio_decoder_impl.h" | 20 #include "webrtc/modules/audio_coding/neteq/audio_decoder_impl.h" |
19 #include "webrtc/modules/audio_coding/neteq/packet.h" | 21 #include "webrtc/modules/audio_coding/neteq/packet.h" |
20 #include "webrtc/typedefs.h" | 22 #include "webrtc/typedefs.h" |
21 | 23 |
22 namespace webrtc { | 24 namespace webrtc { |
23 | 25 |
24 class DecoderDatabase { | 26 class DecoderDatabase { |
25 public: | 27 public: |
26 enum DatabaseReturnCodes { | 28 enum DatabaseReturnCodes { |
27 kOK = 0, | 29 kOK = 0, |
28 kInvalidRtpPayloadType = -1, | 30 kInvalidRtpPayloadType = -1, |
29 kCodecNotSupported = -2, | 31 kCodecNotSupported = -2, |
30 kInvalidSampleRate = -3, | 32 kInvalidSampleRate = -3, |
31 kDecoderExists = -4, | 33 kDecoderExists = -4, |
32 kDecoderNotFound = -5, | 34 kDecoderNotFound = -5, |
33 kInvalidPointer = -6 | 35 kInvalidPointer = -6 |
34 }; | 36 }; |
35 | 37 |
36 // Struct used to store decoder info in the database. | 38 // Struct used to store decoder info in the database. |
37 struct DecoderInfo { | 39 struct DecoderInfo { |
38 // Constructors. | 40 DecoderInfo() = default; |
39 DecoderInfo() | |
40 : codec_type(NetEqDecoder::kDecoderArbitrary), | |
41 fs_hz(8000), | |
42 decoder(NULL), | |
43 external(false) {} | |
44 DecoderInfo(NetEqDecoder ct, int fs, AudioDecoder* dec, bool ext) | 41 DecoderInfo(NetEqDecoder ct, int fs, AudioDecoder* dec, bool ext) |
| 42 : DecoderInfo(ct, "", fs, dec, ext) {} |
| 43 DecoderInfo(NetEqDecoder ct, |
| 44 const std::string& nm, |
| 45 int fs, |
| 46 AudioDecoder* dec, |
| 47 bool ext) |
45 : codec_type(ct), | 48 : codec_type(ct), |
| 49 name(nm), |
46 fs_hz(fs), | 50 fs_hz(fs), |
| 51 rtp_sample_rate_hz(fs), |
47 decoder(dec), | 52 decoder(dec), |
48 external(ext) { | 53 external(ext) {} |
49 } | |
50 // Destructor. (Defined in decoder_database.cc.) | |
51 ~DecoderInfo(); | 54 ~DecoderInfo(); |
52 | 55 |
53 NetEqDecoder codec_type; | 56 NetEqDecoder codec_type = NetEqDecoder::kDecoderArbitrary; |
54 int fs_hz; | 57 std::string name; |
55 AudioDecoder* decoder; | 58 int fs_hz = 8000; |
56 bool external; | 59 int rtp_sample_rate_hz = 8000; |
| 60 AudioDecoder* decoder = nullptr; |
| 61 bool external = false; |
57 }; | 62 }; |
58 | 63 |
59 // Maximum value for 8 bits, and an invalid RTP payload type (since it is | 64 // Maximum value for 8 bits, and an invalid RTP payload type (since it is |
60 // only 7 bits). | 65 // only 7 bits). |
61 static const uint8_t kRtpPayloadTypeError = 0xFF; | 66 static const uint8_t kRtpPayloadTypeError = 0xFF; |
62 | 67 |
63 DecoderDatabase(); | 68 DecoderDatabase(); |
64 | 69 |
65 virtual ~DecoderDatabase(); | 70 virtual ~DecoderDatabase(); |
66 | 71 |
67 // Returns true if the database is empty. | 72 // Returns true if the database is empty. |
68 virtual bool Empty() const; | 73 virtual bool Empty() const; |
69 | 74 |
70 // Returns the number of decoders registered in the database. | 75 // Returns the number of decoders registered in the database. |
71 virtual int Size() const; | 76 virtual int Size() const; |
72 | 77 |
73 // Resets the database, erasing all registered payload types, and deleting | 78 // Resets the database, erasing all registered payload types, and deleting |
74 // any AudioDecoder objects that were not externally created and inserted | 79 // any AudioDecoder objects that were not externally created and inserted |
75 // using InsertExternal(). | 80 // using InsertExternal(). |
76 virtual void Reset(); | 81 virtual void Reset(); |
77 | 82 |
78 // Registers |rtp_payload_type| as a decoder of type |codec_type|. Returns | 83 // Registers |rtp_payload_type| as a decoder of type |codec_type|. The |name| |
79 // kOK on success; otherwise an error code. | 84 // is only used to populate the name field in the DecoderInfo struct in the |
| 85 // database, and can be arbitrary (including empty). Returns kOK on success; |
| 86 // otherwise an error code. |
80 virtual int RegisterPayload(uint8_t rtp_payload_type, | 87 virtual int RegisterPayload(uint8_t rtp_payload_type, |
81 NetEqDecoder codec_type); | 88 NetEqDecoder codec_type, |
| 89 const std::string& name); |
82 | 90 |
83 // Registers an externally created AudioDecoder object, and associates it | 91 // Registers an externally created AudioDecoder object, and associates it |
84 // as a decoder of type |codec_type| with |rtp_payload_type|. | 92 // as a decoder of type |codec_type| with |rtp_payload_type|. |
85 virtual int InsertExternal(uint8_t rtp_payload_type, | 93 virtual int InsertExternal(uint8_t rtp_payload_type, |
86 NetEqDecoder codec_type, | 94 NetEqDecoder codec_type, |
87 int fs_hz, AudioDecoder* decoder); | 95 const std::string& codec_name, |
| 96 int fs_hz, |
| 97 AudioDecoder* decoder); |
88 | 98 |
89 // Removes the entry for |rtp_payload_type| from the database. | 99 // Removes the entry for |rtp_payload_type| from the database. |
90 // Returns kDecoderNotFound or kOK depending on the outcome of the operation. | 100 // Returns kDecoderNotFound or kOK depending on the outcome of the operation. |
91 virtual int Remove(uint8_t rtp_payload_type); | 101 virtual int Remove(uint8_t rtp_payload_type); |
92 | 102 |
93 // Returns a pointer to the DecoderInfo struct for |rtp_payload_type|. If | 103 // Returns a pointer to the DecoderInfo struct for |rtp_payload_type|. If |
94 // no decoder is registered with that |rtp_payload_type|, NULL is returned. | 104 // no decoder is registered with that |rtp_payload_type|, NULL is returned. |
95 virtual const DecoderInfo* GetDecoderInfo(uint8_t rtp_payload_type) const; | 105 virtual const DecoderInfo* GetDecoderInfo(uint8_t rtp_payload_type) const; |
96 | 106 |
97 // Returns one RTP payload type associated with |codec_type|, or | 107 // Returns one RTP payload type associated with |codec_type|, or |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 154 |
145 DecoderMap decoders_; | 155 DecoderMap decoders_; |
146 int active_decoder_; | 156 int active_decoder_; |
147 int active_cng_decoder_; | 157 int active_cng_decoder_; |
148 | 158 |
149 RTC_DISALLOW_COPY_AND_ASSIGN(DecoderDatabase); | 159 RTC_DISALLOW_COPY_AND_ASSIGN(DecoderDatabase); |
150 }; | 160 }; |
151 | 161 |
152 } // namespace webrtc | 162 } // namespace webrtc |
153 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_DECODER_DATABASE_H_ | 163 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_DECODER_DATABASE_H_ |
OLD | NEW |