blob: ea70997c14e9d321c73fcfb942fef686aae7cf04 [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()
kwibergee1879c2015-10-29 06:20:28 -070040 : codec_type(NetEqDecoder::kDecoderArbitrary),
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000041 fs_hz(8000),
42 decoder(NULL),
kwibergee1879c2015-10-29 06:20:28 -070043 external(false) {}
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000044 DecoderInfo(NetEqDecoder ct, int fs, AudioDecoder* dec, bool ext)
45 : codec_type(ct),
46 fs_hz(fs),
47 decoder(dec),
48 external(ext) {
49 }
50 // Destructor. (Defined in decoder_database.cc.)
51 ~DecoderInfo();
52
53 NetEqDecoder codec_type;
54 int fs_hz;
55 AudioDecoder* decoder;
56 bool external;
57 };
58
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000059 // Maximum value for 8 bits, and an invalid RTP payload type (since it is
60 // only 7 bits).
61 static const uint8_t kRtpPayloadTypeError = 0xFF;
62
pbos@webrtc.org2d1a55c2013-07-31 15:54:00 +000063 DecoderDatabase();
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000064
pbos@webrtc.org2d1a55c2013-07-31 15:54:00 +000065 virtual ~DecoderDatabase();
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000066
67 // Returns true if the database is empty.
pbos@webrtc.org2d1a55c2013-07-31 15:54:00 +000068 virtual bool Empty() const;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000069
70 // Returns the number of decoders registered in the database.
pbos@webrtc.org2d1a55c2013-07-31 15:54:00 +000071 virtual int Size() const;
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +000072
73 // Resets the database, erasing all registered payload types, and deleting
74 // any AudioDecoder objects that were not externally created and inserted
75 // using InsertExternal().
76 virtual void Reset();
77
78 // Registers |rtp_payload_type| as a decoder of type |codec_type|. Returns
79 // kOK on success; otherwise an error code.
80 virtual int RegisterPayload(uint8_t rtp_payload_type,
81 NetEqDecoder codec_type);
82
83 // Registers an externally created AudioDecoder object, and associates it
84 // as a decoder of type |codec_type| with |rtp_payload_type|.
85 virtual int InsertExternal(uint8_t rtp_payload_type,
86 NetEqDecoder codec_type,
87 int fs_hz, AudioDecoder* decoder);
88
89 // Removes the entry for |rtp_payload_type| from the database.
90 // Returns kDecoderNotFound or kOK depending on the outcome of the operation.
91 virtual int Remove(uint8_t rtp_payload_type);
92
93 // 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.
95 virtual const DecoderInfo* GetDecoderInfo(uint8_t rtp_payload_type) const;
96
97 // Returns one RTP payload type associated with |codec_type|, or
98 // kDecoderNotFound if no entry exists for that value. Note that one
99 // |codec_type| may be registered with several RTP payload types, and the
100 // method may return any of them.
101 virtual uint8_t GetRtpPayloadType(NetEqDecoder codec_type) const;
102
103 // Returns a pointer to the AudioDecoder object associated with
104 // |rtp_payload_type|, or NULL if none is registered. If the AudioDecoder
105 // object does not exist for that decoder, the object is created.
106 virtual AudioDecoder* GetDecoder(uint8_t rtp_payload_type);
107
108 // Returns true if |rtp_payload_type| is registered as a |codec_type|.
109 virtual bool IsType(uint8_t rtp_payload_type,
110 NetEqDecoder codec_type) const;
111
112 // Returns true if |rtp_payload_type| is registered as comfort noise.
113 virtual bool IsComfortNoise(uint8_t rtp_payload_type) const;
114
115 // Returns true if |rtp_payload_type| is registered as DTMF.
116 virtual bool IsDtmf(uint8_t rtp_payload_type) const;
117
118 // Returns true if |rtp_payload_type| is registered as RED.
119 virtual bool IsRed(uint8_t rtp_payload_type) const;
120
121 // Sets the active decoder to be |rtp_payload_type|. If this call results in a
122 // change of active decoder, |new_decoder| is set to true. The previous active
123 // decoder's AudioDecoder object is deleted.
124 virtual int SetActiveDecoder(uint8_t rtp_payload_type, bool* new_decoder);
125
126 // Returns the current active decoder, or NULL if no active decoder exists.
127 virtual AudioDecoder* GetActiveDecoder();
128
129 // Sets the active comfort noise decoder to be |rtp_payload_type|. If this
130 // call results in a change of active comfort noise decoder, the previous
131 // active decoder's AudioDecoder object is deleted.
132 virtual int SetActiveCngDecoder(uint8_t rtp_payload_type);
133
134 // Returns the current active comfort noise decoder, or NULL if no active
135 // comfort noise decoder exists.
136 virtual AudioDecoder* GetActiveCngDecoder();
137
138 // Returns kOK if all packets in |packet_list| carry payload types that are
139 // registered in the database. Otherwise, returns kDecoderNotFound.
140 virtual int CheckPayloadTypes(const PacketList& packet_list) const;
141
142 private:
143 typedef std::map<uint8_t, DecoderInfo> DecoderMap;
144
145 DecoderMap decoders_;
146 int active_decoder_;
147 int active_cng_decoder_;
148
henrikg3c089d72015-09-16 05:37:44 -0700149 RTC_DISALLOW_COPY_AND_ASSIGN(DecoderDatabase);
henrik.lundin@webrtc.orgd94659d2013-01-29 12:09:21 +0000150};
151
152} // namespace webrtc
henrik.lundin@webrtc.org9c55f0f2014-06-09 08:10:28 +0000153#endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_DECODER_DATABASE_H_