Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(517)

Side by Side Diff: webrtc/api/audio_codecs/audio_format.h

Issue 2695243005: Injectable audio encoders: BuiltinAudioEncoderFactory (Closed)
Patch Set: Fix build problems on Windows, Android and downstream. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/api/DEPS ('k') | webrtc/api/audio_codecs/audio_format.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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_API_AUDIO_CODECS_AUDIO_FORMAT_H_ 11 #ifndef WEBRTC_API_AUDIO_CODECS_AUDIO_FORMAT_H_
12 #define WEBRTC_API_AUDIO_CODECS_AUDIO_FORMAT_H_ 12 #define WEBRTC_API_AUDIO_CODECS_AUDIO_FORMAT_H_
13 13
14 #include <map> 14 #include <map>
15 #include <ostream> 15 #include <ostream>
16 #include <string> 16 #include <string>
17 #include <utility> 17 #include <utility>
18 18
19 #include "webrtc/base/optional.h"
20
19 namespace webrtc { 21 namespace webrtc {
20 22
21 // SDP specification for a single audio codec. 23 // SDP specification for a single audio codec.
22 // NOTE: This class is still under development and may change without notice. 24 // NOTE: This class is still under development and may change without notice.
23 struct SdpAudioFormat { 25 struct SdpAudioFormat {
24 using Parameters = std::map<std::string, std::string>; 26 using Parameters = std::map<std::string, std::string>;
25 27
26 SdpAudioFormat(const SdpAudioFormat&); 28 SdpAudioFormat(const SdpAudioFormat&);
27 SdpAudioFormat(SdpAudioFormat&&); 29 SdpAudioFormat(SdpAudioFormat&&);
28 SdpAudioFormat(const char* name, int clockrate_hz, int num_channels); 30 SdpAudioFormat(const char* name, int clockrate_hz, size_t num_channels);
29 SdpAudioFormat(const std::string& name, int clockrate_hz, int num_channels); 31 SdpAudioFormat(const std::string& name,
32 int clockrate_hz,
33 size_t num_channels);
30 SdpAudioFormat(const char* name, 34 SdpAudioFormat(const char* name,
31 int clockrate_hz, 35 int clockrate_hz,
32 int num_channels, 36 size_t num_channels,
33 const Parameters& param); 37 const Parameters& param);
34 SdpAudioFormat(const std::string& name, 38 SdpAudioFormat(const std::string& name,
35 int clockrate_hz, 39 int clockrate_hz,
36 int num_channels, 40 size_t num_channels,
37 const Parameters& param); 41 const Parameters& param);
38 ~SdpAudioFormat(); 42 ~SdpAudioFormat();
39 43
40 SdpAudioFormat& operator=(const SdpAudioFormat&); 44 SdpAudioFormat& operator=(const SdpAudioFormat&);
41 SdpAudioFormat& operator=(SdpAudioFormat&&); 45 SdpAudioFormat& operator=(SdpAudioFormat&&);
42 46
43 friend bool operator==(const SdpAudioFormat& a, const SdpAudioFormat& b); 47 friend bool operator==(const SdpAudioFormat& a, const SdpAudioFormat& b);
44 friend bool operator!=(const SdpAudioFormat& a, const SdpAudioFormat& b) { 48 friend bool operator!=(const SdpAudioFormat& a, const SdpAudioFormat& b) {
45 return !(a == b); 49 return !(a == b);
46 } 50 }
47 51
48 std::string name; 52 std::string name;
49 int clockrate_hz; 53 int clockrate_hz;
50 int num_channels; 54 size_t num_channels;
51 Parameters parameters; 55 Parameters parameters;
52 }; 56 };
53 57
54 void swap(SdpAudioFormat& a, SdpAudioFormat& b); 58 void swap(SdpAudioFormat& a, SdpAudioFormat& b);
55 std::ostream& operator<<(std::ostream& os, const SdpAudioFormat& saf); 59 std::ostream& operator<<(std::ostream& os, const SdpAudioFormat& saf);
56 60
57 // To avoid API breakage, and make the code clearer, AudioCodecSpec should not 61 // Information about how an audio format is treated by the codec implementation.
62 // Contains basic information, such as sample rate and number of channels, which
63 // isn't uniformly presented by SDP. Also contains flags indicating support for
64 // integrating with other parts of WebRTC, like external VAD and comfort noise
65 // level calculation.
66 //
67 // To avoid API breakage, and make the code clearer, AudioCodecInfo should not
58 // be directly initializable with any flags indicating optional support. If it 68 // be directly initializable with any flags indicating optional support. If it
59 // were, these initializers would break any time a new flag was added. It's also 69 // were, these initializers would break any time a new flag was added. It's also
60 // more difficult to understand: 70 // more difficult to understand:
61 // AudioCodecSpec spec{{"format", 8000, 1}, true, false, false, true, true}; 71 // AudioCodecInfo info{16000, 1, 32000, true, false, false, true, true};
62 // than 72 // than
63 // AudioCodecSpec spec({"format", 8000, 1}); 73 // AudioCodecInfo info(16000, 1, 32000);
64 // spec.allow_comfort_noise = true; 74 // info.allow_comfort_noise = true;
65 // spec.future_flag_b = true; 75 // info.future_flag_b = true;
66 // spec.future_flag_c = true; 76 // info.future_flag_c = true;
67 struct AudioCodecSpec { 77 struct AudioCodecInfo {
68 explicit AudioCodecSpec(const SdpAudioFormat& format); 78 AudioCodecInfo(int sample_rate_hz, size_t num_channels, int bitrate_bps);
69 explicit AudioCodecSpec(SdpAudioFormat&& format); 79 AudioCodecInfo(int sample_rate_hz,
70 ~AudioCodecSpec() = default; 80 size_t num_channels,
81 int default_bitrate_bps,
82 int min_bitrate_bps,
83 int max_bitrate_bps);
84 AudioCodecInfo(const AudioCodecInfo& b) = default;
85 ~AudioCodecInfo() = default;
71 86
72 SdpAudioFormat format; 87 bool operator==(const AudioCodecInfo& b) const {
88 return sample_rate_hz == b.sample_rate_hz &&
89 num_channels == b.num_channels &&
90 default_bitrate_bps == b.default_bitrate_bps &&
91 min_bitrate_bps == b.min_bitrate_bps &&
92 max_bitrate_bps == b.max_bitrate_bps &&
93 allow_comfort_noise == b.allow_comfort_noise &&
94 supports_network_adaption == b.supports_network_adaption;
95 }
96
97 bool operator!=(const AudioCodecInfo& b) const { return !(*this == b); }
98
99 bool HasFixedBitrate() const {
100 RTC_DCHECK_GE(min_bitrate_bps, 0);
101 RTC_DCHECK_LE(min_bitrate_bps, default_bitrate_bps);
102 RTC_DCHECK_GE(max_bitrate_bps, default_bitrate_bps);
103 return min_bitrate_bps == max_bitrate_bps;
104 }
105
106 int sample_rate_hz;
107 size_t num_channels;
108 int default_bitrate_bps;
109 int min_bitrate_bps;
110 int max_bitrate_bps;
111
73 bool allow_comfort_noise = true; // This codec can be used with an external 112 bool allow_comfort_noise = true; // This codec can be used with an external
74 // comfort noise generator. 113 // comfort noise generator.
75 bool supports_network_adaption = false; // This codec can adapt to varying 114 bool supports_network_adaption = false; // This codec can adapt to varying
76 // network conditions. 115 // network conditions.
77 }; 116 };
78 117
118 // AudioCodecSpec ties an audio format to specific information about the codec
119 // and its implementation.
120 struct AudioCodecSpec {
121 bool operator==(const AudioCodecSpec& b) const {
122 return format == b.format && info == b.info;
123 }
124
125 bool operator!=(const AudioCodecSpec& b) const { return !(*this == b); }
126
127 SdpAudioFormat format;
128 AudioCodecInfo info;
129 };
130
79 } // namespace webrtc 131 } // namespace webrtc
80 132
81 #endif // WEBRTC_API_AUDIO_CODECS_AUDIO_FORMAT_H_ 133 #endif // WEBRTC_API_AUDIO_CODECS_AUDIO_FORMAT_H_
OLDNEW
« no previous file with comments | « webrtc/api/DEPS ('k') | webrtc/api/audio_codecs/audio_format.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698