blob: cae10219930a717fc0f968f12a5228f17642d1f3 [file] [log] [blame]
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
henrik.lundin@webrtc.org9c55f0f2014-06-09 08:10:28 +000011#ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_DECODER_DATABASE_H_
12#define WEBRTC_MODULES_AUDIO_CODING_NETEQ_DECODER_DATABASE_H_
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000013
14#include <map>
15
henrike@webrtc.org88fbb2d2014-05-21 21:18:46 +000016#include "webrtc/base/constructormagic.h"
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000017#include "webrtc/common_types.h" // NULL
kwiberg@webrtc.orge04a93b2014-12-09 10:12:53 +000018#include "webrtc/modules/audio_coding/neteq/audio_decoder_impl.h"
henrik.lundin@webrtc.org9c55f0f2014-06-09 08:10:28 +000019#include "webrtc/modules/audio_coding/neteq/packet.h"
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000020#include "webrtc/typedefs.h"
21
22namespace webrtc {
23
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000024class DecoderDatabase {
25 public:
26 enum DatabaseReturnCodes {
27 kOK = 0,
28 kInvalidRtpPayloadType = -1,
29 kCodecNotSupported = -2,
30 kInvalidSampleRate = -3,
31 kDecoderExists = -4,
32 kDecoderNotFound = -5,
33 kInvalidPointer = -6
34 };
35
36 // Struct used to store decoder info in the database.
37 struct DecoderInfo {
38 // Constructors.
39 DecoderInfo()
40 : codec_type(kDecoderArbitrary),
41 fs_hz(8000),
42 decoder(NULL),
43 external(false) {
44 }
45 DecoderInfo(NetEqDecoder ct, int fs, AudioDecoder* dec, bool ext)
46 : codec_type(ct),
47 fs_hz(fs),
48 decoder(dec),
49 external(ext) {
50 }
51 // Destructor. (Defined in decoder_database.cc.)
52 ~DecoderInfo();
53
54 NetEqDecoder codec_type;
55 int fs_hz;
56 AudioDecoder* decoder;
57 bool external;
58 };
59
60 static const uint8_t kMaxRtpPayloadType = 0x7F; // Max for a 7-bit number.
61 // Maximum value for 8 bits, and an invalid RTP payload type (since it is
62 // only 7 bits).
63 static const uint8_t kRtpPayloadTypeError = 0xFF;
64
pbos@webrtc.org2d1a55c2013-07-31 15:54:00 +000065 DecoderDatabase();
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000066
pbos@webrtc.org2d1a55c2013-07-31 15:54:00 +000067 virtual ~DecoderDatabase();
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000068
69 // Returns true if the database is empty.
pbos@webrtc.org2d1a55c2013-07-31 15:54:00 +000070 virtual bool Empty() const;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000071
72 // Returns the number of decoders registered in the database.
pbos@webrtc.org2d1a55c2013-07-31 15:54:00 +000073 virtual int Size() const;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000074
75 // Resets the database, erasing all registered payload types, and deleting
76 // any AudioDecoder objects that were not externally created and inserted
77 // using InsertExternal().
78 virtual void Reset();
79
80 // Registers |rtp_payload_type| as a decoder of type |codec_type|. Returns
81 // kOK on success; otherwise an error code.
82 virtual int RegisterPayload(uint8_t rtp_payload_type,
83 NetEqDecoder codec_type);
84
85 // Registers an externally created AudioDecoder object, and associates it
86 // as a decoder of type |codec_type| with |rtp_payload_type|.
87 virtual int InsertExternal(uint8_t rtp_payload_type,
88 NetEqDecoder codec_type,
89 int fs_hz, AudioDecoder* decoder);
90
91 // Removes the entry for |rtp_payload_type| from the database.
92 // Returns kDecoderNotFound or kOK depending on the outcome of the operation.
93 virtual int Remove(uint8_t rtp_payload_type);
94
95 // Returns a pointer to the DecoderInfo struct for |rtp_payload_type|. If
96 // no decoder is registered with that |rtp_payload_type|, NULL is returned.
97 virtual const DecoderInfo* GetDecoderInfo(uint8_t rtp_payload_type) const;
98
99 // Returns one RTP payload type associated with |codec_type|, or
100 // kDecoderNotFound if no entry exists for that value. Note that one
101 // |codec_type| may be registered with several RTP payload types, and the
102 // method may return any of them.
103 virtual uint8_t GetRtpPayloadType(NetEqDecoder codec_type) const;
104
105 // Returns a pointer to the AudioDecoder object associated with
106 // |rtp_payload_type|, or NULL if none is registered. If the AudioDecoder
107 // object does not exist for that decoder, the object is created.
108 virtual AudioDecoder* GetDecoder(uint8_t rtp_payload_type);
109
110 // Returns true if |rtp_payload_type| is registered as a |codec_type|.
111 virtual bool IsType(uint8_t rtp_payload_type,
112 NetEqDecoder codec_type) const;
113
114 // Returns true if |rtp_payload_type| is registered as comfort noise.
115 virtual bool IsComfortNoise(uint8_t rtp_payload_type) const;
116
117 // Returns true if |rtp_payload_type| is registered as DTMF.
118 virtual bool IsDtmf(uint8_t rtp_payload_type) const;
119
120 // Returns true if |rtp_payload_type| is registered as RED.
121 virtual bool IsRed(uint8_t rtp_payload_type) const;
122
123 // Sets the active decoder to be |rtp_payload_type|. If this call results in a
124 // change of active decoder, |new_decoder| is set to true. The previous active
125 // decoder's AudioDecoder object is deleted.
126 virtual int SetActiveDecoder(uint8_t rtp_payload_type, bool* new_decoder);
127
128 // Returns the current active decoder, or NULL if no active decoder exists.
129 virtual AudioDecoder* GetActiveDecoder();
130
131 // Sets the active comfort noise decoder to be |rtp_payload_type|. If this
132 // call results in a change of active comfort noise decoder, the previous
133 // active decoder's AudioDecoder object is deleted.
134 virtual int SetActiveCngDecoder(uint8_t rtp_payload_type);
135
136 // Returns the current active comfort noise decoder, or NULL if no active
137 // comfort noise decoder exists.
138 virtual AudioDecoder* GetActiveCngDecoder();
139
140 // Returns kOK if all packets in |packet_list| carry payload types that are
141 // registered in the database. Otherwise, returns kDecoderNotFound.
142 virtual int CheckPayloadTypes(const PacketList& packet_list) const;
143
144 private:
145 typedef std::map<uint8_t, DecoderInfo> DecoderMap;
146
147 DecoderMap decoders_;
148 int active_decoder_;
149 int active_cng_decoder_;
150
151 DISALLOW_COPY_AND_ASSIGN(DecoderDatabase);
152};
153
154} // namespace webrtc
henrik.lundin@webrtc.org9c55f0f2014-06-09 08:10:28 +0000155#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_DECODER_DATABASE_H_