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

Unified Diff: webrtc/api/audio_codecs/audio_format.h

Issue 2695243005: Injectable audio encoders: BuiltinAudioEncoderFactory (Closed)
Patch Set: Moved ANA frame length calculation into its own function. Improved "ptime" parsing in non-opus codeā€¦ Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/api/audio_codecs/audio_format.h
diff --git a/webrtc/api/audio_codecs/audio_format.h b/webrtc/api/audio_codecs/audio_format.h
index db3990f1143bf5fffc5ff233abb837dda79b533c..0e2f47e104c6f79185131bc8f0a64470fbe2aea9 100644
--- a/webrtc/api/audio_codecs/audio_format.h
+++ b/webrtc/api/audio_codecs/audio_format.h
@@ -16,6 +16,8 @@
#include <string>
#include <utility>
+#include "webrtc/base/optional.h"
+
namespace webrtc {
// SDP specification for a single audio codec.
@@ -54,28 +56,80 @@ struct SdpAudioFormat {
void swap(SdpAudioFormat& a, SdpAudioFormat& b);
std::ostream& operator<<(std::ostream& os, const SdpAudioFormat& saf);
-// To avoid API breakage, and make the code clearer, AudioCodecSpec should not
+// Information about how an audio format is treated by the codec implementation.
+// Contains basic information, such as sample rate and number of channels, which
+// isn't uniformly presented by SDP. Also contains flags indicating support for
+// integrating with other parts of WebRTC, like external VAD and comfort noise
+// level calculation.
+//
+// To avoid API breakage, and make the code clearer, AudioCodecInfo should not
// be directly initializable with any flags indicating optional support. If it
// were, these initializers would break any time a new flag was added. It's also
// more difficult to understand:
-// AudioCodecSpec spec{{"format", 8000, 1}, true, false, false, true, true};
+// AudioCodecInfo info{16000, 1, 32000, true, false, false, true, true};
// than
-// AudioCodecSpec spec({"format", 8000, 1});
-// spec.allow_comfort_noise = true;
-// spec.future_flag_b = true;
-// spec.future_flag_c = true;
-struct AudioCodecSpec {
- explicit AudioCodecSpec(const SdpAudioFormat& format);
- explicit AudioCodecSpec(SdpAudioFormat&& format);
- ~AudioCodecSpec() = default;
+// AudioCodecInfo info(16000, 1, 32000);
+// info.allow_comfort_noise = true;
+// info.future_flag_b = true;
+// info.future_flag_c = true;
+struct AudioCodecInfo {
+ AudioCodecInfo(int sample_rate_hz, int num_channels, int bitrate_bps);
+ AudioCodecInfo(int sample_rate_hz,
+ int num_channels,
+ int default_bitrate_bps,
+ int min_bitrate_bps,
+ int max_bitrate_bps);
+ AudioCodecInfo(const AudioCodecInfo& b) = default;
+ ~AudioCodecInfo() = default;
- SdpAudioFormat format;
- bool allow_comfort_noise = true; // This codec can be used with an external
- // comfort noise generator.
+ bool operator==(const AudioCodecInfo& b) const {
+ return sample_rate_hz == b.sample_rate_hz &&
+ num_channels == b.num_channels &&
+ default_bitrate_bps == b.default_bitrate_bps &&
+ min_bitrate_bps == b.min_bitrate_bps &&
+ max_bitrate_bps == b.max_bitrate_bps &&
+ allow_comfort_noise == b.allow_comfort_noise &&
+ supports_network_adaption == b.supports_network_adaption;
+ }
+
+ bool operator!=(const AudioCodecInfo& b) const {
+ return !(*this == b);
+ }
+
+ bool HasFixedBitrate() const {
+ RTC_DCHECK_GE(min_bitrate_bps, 0);
+ RTC_DCHECK_LE(min_bitrate_bps, default_bitrate_bps);
+ RTC_DCHECK_GE(max_bitrate_bps, default_bitrate_bps);
+ return min_bitrate_bps == max_bitrate_bps;
+ }
+
+ int sample_rate_hz;
+ int num_channels;
+ int default_bitrate_bps;
+ int min_bitrate_bps;
+ int max_bitrate_bps;
+
+ bool allow_comfort_noise = true; // This codec can be used with an external
+ // comfort noise generator.
bool supports_network_adaption = false; // This codec can adapt to varying
// network conditions.
};
+// AudioCodecSpec ties an audio format to specific information about the codec
+// and its implementation.
+struct AudioCodecSpec {
+ bool operator==(const AudioCodecSpec& b) const {
+ return format == b.format && info == b.info;
+ }
+
+ bool operator!=(const AudioCodecSpec& b) const {
+ return !(*this == b);
+ }
+
+ SdpAudioFormat format;
+ AudioCodecInfo info;
+};
+
} // namespace webrtc
#endif // WEBRTC_API_AUDIO_CODECS_AUDIO_FORMAT_H_

Powered by Google App Engine
This is Rietveld 408576698