diff options
Diffstat (limited to 'talk/media/base')
26 files changed, 308 insertions, 992 deletions
diff --git a/talk/media/base/audiorenderer.h b/talk/media/base/audiorenderer.h index 229c36e8b1..a42cd7de8f 100644 --- a/talk/media/base/audiorenderer.h +++ b/talk/media/base/audiorenderer.h @@ -41,7 +41,7 @@ class AudioRenderer { virtual void OnData(const void* audio_data, int bits_per_sample, int sample_rate, - int number_of_channels, + size_t number_of_channels, size_t number_of_frames) = 0; // Called when the AudioRenderer is going away. diff --git a/talk/media/base/capturemanager_unittest.cc b/talk/media/base/capturemanager_unittest.cc index e9903425b8..84086abae4 100644 --- a/talk/media/base/capturemanager_unittest.cc +++ b/talk/media/base/capturemanager_unittest.cc @@ -29,6 +29,7 @@ #include "talk/media/base/fakevideocapturer.h" #include "talk/media/base/fakevideorenderer.h" +#include "webrtc/base/arraysize.h" #include "webrtc/base/gunit.h" #include "webrtc/base/sigslot.h" @@ -57,7 +58,7 @@ class CaptureManagerTest : public ::testing::Test, public sigslot::has_slots<> { } void PopulateSupportedFormats() { std::vector<cricket::VideoFormat> formats; - for (int i = 0; i < ARRAY_SIZE(kCameraFormats); ++i) { + for (int i = 0; i < arraysize(kCameraFormats); ++i) { formats.push_back(cricket::VideoFormat(kCameraFormats[i])); } video_capturer_.ResetSupportedFormats(formats); diff --git a/talk/media/base/codec.cc b/talk/media/base/codec.cc index 5b747d1917..59708b37dd 100644 --- a/talk/media/base/codec.cc +++ b/talk/media/base/codec.cc @@ -163,13 +163,15 @@ void Codec::IntersectFeedbackParams(const Codec& other) { feedback_params.Intersect(other.feedback_params); } -AudioCodec::AudioCodec(int pt, - const std::string& nm, - int cr, - int br, - int cs, - int pr) - : Codec(pt, nm, cr, pr), bitrate(br), channels(cs) { +AudioCodec::AudioCodec(int id, + const std::string& name, + int clockrate, + int bitrate, + size_t channels, + int preference) + : Codec(id, name, clockrate, preference), + bitrate(bitrate), + channels(channels) { } AudioCodec::AudioCodec() : Codec(), bitrate(0), channels(0) { @@ -219,20 +221,20 @@ std::string VideoCodec::ToString() const { return os.str(); } -VideoCodec::VideoCodec(int pt, - const std::string& nm, - int w, - int h, - int fr, - int pr) - : Codec(pt, nm, kVideoCodecClockrate, pr), - width(w), - height(h), - framerate(fr) { +VideoCodec::VideoCodec(int id, + const std::string& name, + int width, + int height, + int framerate, + int preference) + : Codec(id, name, kVideoCodecClockrate, preference), + width(width), + height(height), + framerate(framerate) { } -VideoCodec::VideoCodec(int pt, const std::string& nm) - : Codec(pt, nm, kVideoCodecClockrate, 0), +VideoCodec::VideoCodec(int id, const std::string& name) + : Codec(id, name, kVideoCodecClockrate, 0), width(0), height(0), framerate(0) { @@ -334,6 +336,11 @@ bool HasRemb(const VideoCodec& codec) { FeedbackParam(kRtcpFbParamRemb, kParamValueEmpty)); } +bool HasTransportCc(const VideoCodec& codec) { + return codec.HasFeedbackParam( + FeedbackParam(kRtcpFbParamTransportCc, kParamValueEmpty)); +} + bool CodecNamesEq(const std::string& name1, const std::string& name2) { return _stricmp(name1.c_str(), name2.c_str()) == 0; } diff --git a/talk/media/base/codec.h b/talk/media/base/codec.h index 3bb08e7c7a..da78e1c627 100644 --- a/talk/media/base/codec.h +++ b/talk/media/base/codec.h @@ -128,10 +128,15 @@ struct Codec { struct AudioCodec : public Codec { int bitrate; - int channels; + size_t channels; // Creates a codec with the given parameters. - AudioCodec(int pt, const std::string& nm, int cr, int br, int cs, int pr); + AudioCodec(int id, + const std::string& name, + int clockrate, + int bitrate, + size_t channels, + int preference); // Creates an empty codec. AudioCodec(); AudioCodec(const AudioCodec& c); @@ -161,8 +166,13 @@ struct VideoCodec : public Codec { int framerate; // Creates a codec with the given parameters. - VideoCodec(int pt, const std::string& nm, int w, int h, int fr, int pr); - VideoCodec(int pt, const std::string& nm); + VideoCodec(int id, + const std::string& name, + int width, + int height, + int framerate, + int preference); + VideoCodec(int id, const std::string& name); // Creates an empty codec. VideoCodec(); VideoCodec(const VideoCodec& c); @@ -209,50 +219,6 @@ struct DataCodec : public Codec { std::string ToString() const; }; -struct VideoEncoderConfig { - static const int kDefaultMaxThreads = -1; - static const int kDefaultCpuProfile = -1; - - VideoEncoderConfig() - : max_codec(), - num_threads(kDefaultMaxThreads), - cpu_profile(kDefaultCpuProfile) { - } - - VideoEncoderConfig(const VideoCodec& c) - : max_codec(c), - num_threads(kDefaultMaxThreads), - cpu_profile(kDefaultCpuProfile) { - } - - VideoEncoderConfig(const VideoCodec& c, int t, int p) - : max_codec(c), - num_threads(t), - cpu_profile(p) { - } - - VideoEncoderConfig& operator=(const VideoEncoderConfig& config) { - max_codec = config.max_codec; - num_threads = config.num_threads; - cpu_profile = config.cpu_profile; - return *this; - } - - bool operator==(const VideoEncoderConfig& config) const { - return max_codec == config.max_codec && - num_threads == config.num_threads && - cpu_profile == config.cpu_profile; - } - - bool operator!=(const VideoEncoderConfig& config) const { - return !(*this == config); - } - - VideoCodec max_codec; - int num_threads; - int cpu_profile; -}; - // Get the codec setting associated with |payload_type|. If there // is no codec associated with that payload type it returns false. template <class Codec> @@ -271,6 +237,7 @@ bool FindCodecById(const std::vector<Codec>& codecs, bool CodecNamesEq(const std::string& name1, const std::string& name2); bool HasNack(const VideoCodec& codec); bool HasRemb(const VideoCodec& codec); +bool HasTransportCc(const VideoCodec& codec); } // namespace cricket diff --git a/talk/media/base/codec_unittest.cc b/talk/media/base/codec_unittest.cc index 7bd3735a9b..b2aff507ea 100644 --- a/talk/media/base/codec_unittest.cc +++ b/talk/media/base/codec_unittest.cc @@ -33,7 +33,6 @@ using cricket::Codec; using cricket::DataCodec; using cricket::FeedbackParam; using cricket::VideoCodec; -using cricket::VideoEncoderConfig; using cricket::kCodecParamAssociatedPayloadType; using cricket::kCodecParamMaxBitrate; using cricket::kCodecParamMinBitrate; @@ -214,54 +213,6 @@ TEST_F(CodecTest, TestVideoCodecMatches) { EXPECT_FALSE(c1.Matches(VideoCodec(95, "V", 640, 400, 15, 0))); } -TEST_F(CodecTest, TestVideoEncoderConfigOperators) { - VideoEncoderConfig c1(VideoCodec( - 96, "SVC", 320, 200, 30, 3), 1, 2); - VideoEncoderConfig c2(VideoCodec( - 95, "SVC", 320, 200, 30, 3), 1, 2); - VideoEncoderConfig c3(VideoCodec( - 96, "xxx", 320, 200, 30, 3), 1, 2); - VideoEncoderConfig c4(VideoCodec( - 96, "SVC", 120, 200, 30, 3), 1, 2); - VideoEncoderConfig c5(VideoCodec( - 96, "SVC", 320, 100, 30, 3), 1, 2); - VideoEncoderConfig c6(VideoCodec( - 96, "SVC", 320, 200, 10, 3), 1, 2); - VideoEncoderConfig c7(VideoCodec( - 96, "SVC", 320, 200, 30, 1), 1, 2); - VideoEncoderConfig c8(VideoCodec( - 96, "SVC", 320, 200, 30, 3), 0, 2); - VideoEncoderConfig c9(VideoCodec( - 96, "SVC", 320, 200, 30, 3), 1, 1); - EXPECT_TRUE(c1 != c2); - EXPECT_TRUE(c1 != c2); - EXPECT_TRUE(c1 != c3); - EXPECT_TRUE(c1 != c4); - EXPECT_TRUE(c1 != c5); - EXPECT_TRUE(c1 != c6); - EXPECT_TRUE(c1 != c7); - EXPECT_TRUE(c1 != c8); - EXPECT_TRUE(c1 != c9); - - VideoEncoderConfig c10; - VideoEncoderConfig c11(VideoCodec( - 0, "", 0, 0, 0, 0)); - VideoEncoderConfig c12(VideoCodec( - 0, "", 0, 0, 0, 0), - VideoEncoderConfig::kDefaultMaxThreads, - VideoEncoderConfig::kDefaultCpuProfile); - VideoEncoderConfig c13 = c1; - VideoEncoderConfig c14(VideoCodec( - 0, "", 0, 0, 0, 0), 0, 0); - - EXPECT_TRUE(c11 == c10); - EXPECT_TRUE(c12 == c10); - EXPECT_TRUE(c13 != c10); - EXPECT_TRUE(c13 == c1); - EXPECT_TRUE(c14 != c11); - EXPECT_TRUE(c14 != c12); -} - TEST_F(CodecTest, TestDataCodecMatches) { // Test a codec with a static payload type. DataCodec c0(95, "D", 0); diff --git a/talk/media/base/constants.cc b/talk/media/base/constants.cc index 4063004968..2361be6f50 100644 --- a/talk/media/base/constants.cc +++ b/talk/media/base/constants.cc @@ -90,6 +90,7 @@ const int kPreferredUseInbandFec = 0; const char kRtcpFbParamNack[] = "nack"; const char kRtcpFbNackParamPli[] = "pli"; const char kRtcpFbParamRemb[] = "goog-remb"; +const char kRtcpFbParamTransportCc[] = "transport-cc"; const char kRtcpFbParamCcm[] = "ccm"; const char kRtcpFbCcmParamFir[] = "fir"; diff --git a/talk/media/base/constants.h b/talk/media/base/constants.h index b6a9e5681f..706a7bdc87 100644 --- a/talk/media/base/constants.h +++ b/talk/media/base/constants.h @@ -107,6 +107,9 @@ extern const char kRtcpFbNackParamPli[]; // rtcp-fb messages according to // http://tools.ietf.org/html/draft-alvestrand-rmcat-remb-00 extern const char kRtcpFbParamRemb[]; +// rtcp-fb messages according to +// https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01 +extern const char kRtcpFbParamTransportCc[]; // ccm submessages according to RFC 5104 extern const char kRtcpFbParamCcm[]; extern const char kRtcpFbCcmParamFir[]; diff --git a/talk/media/base/cryptoparams.h b/talk/media/base/cryptoparams.h index 9dd1db5166..589953db3e 100644 --- a/talk/media/base/cryptoparams.h +++ b/talk/media/base/cryptoparams.h @@ -35,8 +35,10 @@ namespace cricket { // Parameters for SRTP negotiation, as described in RFC 4568. struct CryptoParams { CryptoParams() : tag(0) {} - CryptoParams(int t, const std::string& cs, - const std::string& kp, const std::string& sp) + CryptoParams(int t, + const std::string& cs, + const std::string& kp, + const std::string& sp) : tag(t), cipher_suite(cs), key_params(kp), session_params(sp) {} bool Matches(const CryptoParams& params) const { diff --git a/talk/media/base/executablehelpers.h b/talk/media/base/executablehelpers.h index 401890f4e8..dd165c25da 100644 --- a/talk/media/base/executablehelpers.h +++ b/talk/media/base/executablehelpers.h @@ -28,7 +28,7 @@ #ifndef TALK_MEDIA_BASE_EXECUTABLEHELPERS_H_ #define TALK_MEDIA_BASE_EXECUTABLEHELPERS_H_ -#ifdef OSX +#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) #include <mach-o/dyld.h> #endif @@ -62,15 +62,15 @@ inline Pathname GetExecutablePath() { #else // UNICODE rtc::Pathname path(exe_path_buffer); #endif // UNICODE -#elif defined(OSX) || defined(LINUX) +#elif (defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)) || defined(WEBRTC_LINUX) char exe_path_buffer[kMaxExePathSize]; -#ifdef OSX +#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) uint32_t copied_length = kMaxExePathSize - 1; if (_NSGetExecutablePath(exe_path_buffer, &copied_length) == -1) { LOG(LS_ERROR) << "Buffer too small"; return rtc::Pathname(); } -#elif defined LINUX +#elif defined WEBRTC_LINUX int32_t copied_length = kMaxExePathSize - 1; const char* kProcExeFmt = "/proc/%d/exe"; char proc_exe_link[40]; @@ -86,11 +86,11 @@ inline Pathname GetExecutablePath() { return rtc::Pathname(); } exe_path_buffer[copied_length] = '\0'; -#endif // LINUX +#endif // WEBRTC_LINUX rtc::Pathname path(exe_path_buffer); -#else // Android || IOS +#else // Android || iOS rtc::Pathname path; -#endif // OSX || LINUX +#endif // Mac || Linux return path; } diff --git a/talk/media/base/fakemediaengine.h b/talk/media/base/fakemediaengine.h index a6fa960dee..149704f92d 100644 --- a/talk/media/base/fakemediaengine.h +++ b/talk/media/base/fakemediaengine.h @@ -38,9 +38,10 @@ #include "talk/media/base/mediaengine.h" #include "talk/media/base/rtputils.h" #include "talk/media/base/streamparams.h" -#include "webrtc/p2p/base/sessiondescription.h" +#include "webrtc/audio/audio_sink.h" #include "webrtc/base/buffer.h" #include "webrtc/base/stringutils.h" +#include "webrtc/p2p/base/sessiondescription.h" namespace cricket { @@ -229,15 +230,13 @@ template <class Base> class RtpHelper : public Base { class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> { public: struct DtmfInfo { - DtmfInfo(uint32_t ssrc, int event_code, int duration, int flags) + DtmfInfo(uint32_t ssrc, int event_code, int duration) : ssrc(ssrc), event_code(event_code), - duration(duration), - flags(flags) {} + duration(duration) {} uint32_t ssrc; int event_code; int duration; - int flags; }; explicit FakeVoiceMediaChannel(FakeVoiceEngine* engine, const AudioOptions& options) @@ -321,9 +320,8 @@ class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> { } virtual bool InsertDtmf(uint32_t ssrc, int event_code, - int duration, - int flags) { - dtmf_info_queue_.push_back(DtmfInfo(ssrc, event_code, duration, flags)); + int duration) { + dtmf_info_queue_.push_back(DtmfInfo(ssrc, event_code, duration)); return true; } @@ -349,6 +347,12 @@ class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> { virtual bool GetStats(VoiceMediaInfo* info) { return false; } + virtual void SetRawAudioSink( + uint32_t ssrc, + rtc::scoped_ptr<webrtc::AudioSinkInterface> sink) { + sink_ = std::move(sink); + } + private: class VoiceChannelAudioSink : public AudioRenderer::Sink { public: @@ -364,7 +368,7 @@ class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> { void OnData(const void* audio_data, int bits_per_sample, int sample_rate, - int number_of_channels, + size_t number_of_channels, size_t number_of_frames) override {} void OnClose() override { renderer_ = NULL; } AudioRenderer* renderer() const { return renderer_; } @@ -421,16 +425,16 @@ class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> { int time_since_last_typing_; AudioOptions options_; std::map<uint32_t, VoiceChannelAudioSink*> local_renderers_; + rtc::scoped_ptr<webrtc::AudioSinkInterface> sink_; }; // A helper function to compare the FakeVoiceMediaChannel::DtmfInfo. inline bool CompareDtmfInfo(const FakeVoiceMediaChannel::DtmfInfo& info, uint32_t ssrc, int event_code, - int duration, - int flags) { + int duration) { return (info.duration == duration && info.event_code == event_code && - info.flags == flags && info.ssrc == ssrc); + info.ssrc == ssrc); } class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> { @@ -694,33 +698,23 @@ class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> { class FakeBaseEngine { public: FakeBaseEngine() - : loglevel_(-1), - options_changed_(false), + : options_changed_(false), fail_create_channel_(false) {} - void SetLogging(int level, const char* filter) { - loglevel_ = level; - logfilter_ = filter; - } - void set_fail_create_channel(bool fail) { fail_create_channel_ = fail; } - const std::vector<RtpHeaderExtension>& rtp_header_extensions() const { - return rtp_header_extensions_; - } + RtpCapabilities GetCapabilities() const { return capabilities_; } void set_rtp_header_extensions( const std::vector<RtpHeaderExtension>& extensions) { - rtp_header_extensions_ = extensions; + capabilities_.header_extensions = extensions; } protected: - int loglevel_; - std::string logfilter_; // Flag used by optionsmessagehandler_unittest for checking whether any // relevant setting has been updated. // TODO(thaloun): Replace with explicit checks of before & after values. bool options_changed_; bool fail_create_channel_; - std::vector<RtpHeaderExtension> rtp_header_extensions_; + RtpCapabilities capabilities_; }; class FakeVoiceEngine : public FakeBaseEngine { @@ -733,14 +727,8 @@ class FakeVoiceEngine : public FakeBaseEngine { } bool Init(rtc::Thread* worker_thread) { return true; } void Terminate() {} - webrtc::VoiceEngine* GetVoE() { return nullptr; } - AudioOptions GetOptions() const { - return options_; - } - bool SetOptions(const AudioOptions& options) { - options_ = options; - options_changed_ = true; - return true; + rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const { + return rtc::scoped_refptr<webrtc::AudioState>(); } VoiceMediaChannel* CreateChannel(webrtc::Call* call, @@ -763,21 +751,12 @@ class FakeVoiceEngine : public FakeBaseEngine { const std::vector<AudioCodec>& codecs() { return codecs_; } void SetCodecs(const std::vector<AudioCodec> codecs) { codecs_ = codecs; } - bool SetDevices(const Device* in_device, const Device* out_device) { - in_device_ = (in_device) ? in_device->name : ""; - out_device_ = (out_device) ? out_device->name : ""; - options_changed_ = true; - return true; - } - bool GetOutputVolume(int* level) { *level = output_volume_; return true; } - bool SetOutputVolume(int level) { output_volume_ = level; - options_changed_ = true; return true; } @@ -795,9 +774,6 @@ class FakeVoiceEngine : public FakeBaseEngine { std::vector<FakeVoiceMediaChannel*> channels_; std::vector<AudioCodec> codecs_; int output_volume_; - std::string in_device_; - std::string out_device_; - AudioOptions options_; friend class FakeMediaEngine; }; @@ -815,13 +791,6 @@ class FakeVideoEngine : public FakeBaseEngine { options_changed_ = true; return true; } - bool SetDefaultEncoderConfig(const VideoEncoderConfig& config) { - default_encoder_config_ = config; - return true; - } - const VideoEncoderConfig& default_encoder_config() const { - return default_encoder_config_; - } VideoMediaChannel* CreateChannel(webrtc::Call* call, const VideoOptions& options) { @@ -864,7 +833,6 @@ class FakeVideoEngine : public FakeBaseEngine { private: std::vector<FakeVideoMediaChannel*> channels_; std::vector<VideoCodec> codecs_; - VideoEncoderConfig default_encoder_config_; std::string in_device_; bool capture_; VideoOptions options_; @@ -875,10 +843,7 @@ class FakeVideoEngine : public FakeBaseEngine { class FakeMediaEngine : public CompositeMediaEngine<FakeVoiceEngine, FakeVideoEngine> { public: - FakeMediaEngine() { - voice_ = FakeVoiceEngine(); - video_ = FakeVideoEngine(); - } + FakeMediaEngine() {} virtual ~FakeMediaEngine() {} void SetAudioCodecs(const std::vector<AudioCodec>& codecs) { @@ -904,24 +869,13 @@ class FakeMediaEngine : return video_.GetChannel(index); } - AudioOptions audio_options() const { return voice_.options_; } int output_volume() const { return voice_.output_volume_; } - const VideoEncoderConfig& default_video_encoder_config() const { - return video_.default_encoder_config_; - } - const std::string& audio_in_device() const { return voice_.in_device_; } - const std::string& audio_out_device() const { return voice_.out_device_; } - int voice_loglevel() const { return voice_.loglevel_; } - const std::string& voice_logfilter() const { return voice_.logfilter_; } - int video_loglevel() const { return video_.loglevel_; } - const std::string& video_logfilter() const { return video_.logfilter_; } bool capture() const { return video_.capture_; } bool options_changed() const { - return voice_.options_changed_ || video_.options_changed_; + return video_.options_changed_; } void clear_options_changed() { video_.options_changed_ = false; - voice_.options_changed_ = false; } void set_fail_create_channel(bool fail) { voice_.set_fail_create_channel(fail); diff --git a/talk/media/base/fakemediaprocessor.h b/talk/media/base/fakemediaprocessor.h deleted file mode 100644 index 8de2678c95..0000000000 --- a/talk/media/base/fakemediaprocessor.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * libjingle - * Copyright 2004 Google Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -// TODO(solenberg): Remove this file once Chromium's libjingle.gyp/.gn are -// updated. diff --git a/talk/media/base/mediachannel.h b/talk/media/base/mediachannel.h index 14660847fa..f6fb77d8a6 100644 --- a/talk/media/base/mediachannel.h +++ b/talk/media/base/mediachannel.h @@ -38,6 +38,7 @@ #include "webrtc/base/buffer.h" #include "webrtc/base/dscp.h" #include "webrtc/base/logging.h" +#include "webrtc/base/optional.h" #include "webrtc/base/sigslot.h" #include "webrtc/base/socket.h" #include "webrtc/base/window.h" @@ -50,88 +51,30 @@ class RateLimiter; class Timing; } +namespace webrtc { +class AudioSinkInterface; +} + namespace cricket { class AudioRenderer; -struct RtpHeader; class ScreencastId; -struct VideoFormat; class VideoCapturer; class VideoRenderer; +struct RtpHeader; +struct VideoFormat; const int kMinRtpHeaderExtensionId = 1; const int kMaxRtpHeaderExtensionId = 255; const int kScreencastDefaultFps = 5; -// Used in AudioOptions and VideoOptions to signify "unset" values. -template <class T> -class Settable { - public: - Settable() : set_(false), val_() {} - explicit Settable(T val) : set_(true), val_(val) {} - - bool IsSet() const { - return set_; - } - - bool Get(T* out) const { - *out = val_; - return set_; - } - - T GetWithDefaultIfUnset(const T& default_value) const { - return set_ ? val_ : default_value; - } - - void Set(T val) { - set_ = true; - val_ = val; - } - - void Clear() { - Set(T()); - set_ = false; - } - - void SetFrom(const Settable<T>& o) { - // Set this value based on the value of o, iff o is set. If this value is - // set and o is unset, the current value will be unchanged. - T val; - if (o.Get(&val)) { - Set(val); - } - } - - std::string ToString() const { - return set_ ? rtc::ToString(val_) : ""; - } - - bool operator==(const Settable<T>& o) const { - // Equal if both are unset with any value or both set with the same value. - return (set_ == o.set_) && (!set_ || (val_ == o.val_)); - } - - bool operator!=(const Settable<T>& o) const { - return !operator==(o); - } - - protected: - void InitializeValue(const T &val) { - val_ = val; - } - - private: - bool set_; - T val_; -}; - template <class T> -static std::string ToStringIfSet(const char* key, const Settable<T>& val) { +static std::string ToStringIfSet(const char* key, const rtc::Optional<T>& val) { std::string str; - if (val.IsSet()) { + if (val) { str = key; str += ": "; - str += val.ToString(); + str += val ? rtc::ToString(*val) : ""; str += ", "; } return str; @@ -157,32 +100,32 @@ static std::string VectorToString(const std::vector<T>& vals) { // but some things currently still use flags. struct AudioOptions { void SetAll(const AudioOptions& change) { - echo_cancellation.SetFrom(change.echo_cancellation); - auto_gain_control.SetFrom(change.auto_gain_control); - noise_suppression.SetFrom(change.noise_suppression); - highpass_filter.SetFrom(change.highpass_filter); - stereo_swapping.SetFrom(change.stereo_swapping); - audio_jitter_buffer_max_packets.SetFrom( - change.audio_jitter_buffer_max_packets); - audio_jitter_buffer_fast_accelerate.SetFrom( - change.audio_jitter_buffer_fast_accelerate); - typing_detection.SetFrom(change.typing_detection); - aecm_generate_comfort_noise.SetFrom(change.aecm_generate_comfort_noise); - conference_mode.SetFrom(change.conference_mode); - adjust_agc_delta.SetFrom(change.adjust_agc_delta); - experimental_agc.SetFrom(change.experimental_agc); - extended_filter_aec.SetFrom(change.extended_filter_aec); - delay_agnostic_aec.SetFrom(change.delay_agnostic_aec); - experimental_ns.SetFrom(change.experimental_ns); - aec_dump.SetFrom(change.aec_dump); - tx_agc_target_dbov.SetFrom(change.tx_agc_target_dbov); - tx_agc_digital_compression_gain.SetFrom( - change.tx_agc_digital_compression_gain); - tx_agc_limiter.SetFrom(change.tx_agc_limiter); - recording_sample_rate.SetFrom(change.recording_sample_rate); - playout_sample_rate.SetFrom(change.playout_sample_rate); - dscp.SetFrom(change.dscp); - combined_audio_video_bwe.SetFrom(change.combined_audio_video_bwe); + SetFrom(&echo_cancellation, change.echo_cancellation); + SetFrom(&auto_gain_control, change.auto_gain_control); + SetFrom(&noise_suppression, change.noise_suppression); + SetFrom(&highpass_filter, change.highpass_filter); + SetFrom(&stereo_swapping, change.stereo_swapping); + SetFrom(&audio_jitter_buffer_max_packets, + change.audio_jitter_buffer_max_packets); + SetFrom(&audio_jitter_buffer_fast_accelerate, + change.audio_jitter_buffer_fast_accelerate); + SetFrom(&typing_detection, change.typing_detection); + SetFrom(&aecm_generate_comfort_noise, change.aecm_generate_comfort_noise); + SetFrom(&conference_mode, change.conference_mode); + SetFrom(&adjust_agc_delta, change.adjust_agc_delta); + SetFrom(&experimental_agc, change.experimental_agc); + SetFrom(&extended_filter_aec, change.extended_filter_aec); + SetFrom(&delay_agnostic_aec, change.delay_agnostic_aec); + SetFrom(&experimental_ns, change.experimental_ns); + SetFrom(&aec_dump, change.aec_dump); + SetFrom(&tx_agc_target_dbov, change.tx_agc_target_dbov); + SetFrom(&tx_agc_digital_compression_gain, + change.tx_agc_digital_compression_gain); + SetFrom(&tx_agc_limiter, change.tx_agc_limiter); + SetFrom(&recording_sample_rate, change.recording_sample_rate); + SetFrom(&playout_sample_rate, change.playout_sample_rate); + SetFrom(&dscp, change.dscp); + SetFrom(&combined_audio_video_bwe, change.combined_audio_video_bwe); } bool operator==(const AudioOptions& o) const { @@ -247,39 +190,47 @@ struct AudioOptions { // Audio processing that attempts to filter away the output signal from // later inbound pickup. - Settable<bool> echo_cancellation; + rtc::Optional<bool> echo_cancellation; // Audio processing to adjust the sensitivity of the local mic dynamically. - Settable<bool> auto_gain_control; + rtc::Optional<bool> auto_gain_control; // Audio processing to filter out background noise. - Settable<bool> noise_suppression; + rtc::Optional<bool> noise_suppression; // Audio processing to remove background noise of lower frequencies. - Settable<bool> highpass_filter; + rtc::Optional<bool> highpass_filter; // Audio processing to swap the left and right channels. - Settable<bool> stereo_swapping; + rtc::Optional<bool> stereo_swapping; // Audio receiver jitter buffer (NetEq) max capacity in number of packets. - Settable<int> audio_jitter_buffer_max_packets; + rtc::Optional<int> audio_jitter_buffer_max_packets; // Audio receiver jitter buffer (NetEq) fast accelerate mode. - Settable<bool> audio_jitter_buffer_fast_accelerate; + rtc::Optional<bool> audio_jitter_buffer_fast_accelerate; // Audio processing to detect typing. - Settable<bool> typing_detection; - Settable<bool> aecm_generate_comfort_noise; - Settable<bool> conference_mode; - Settable<int> adjust_agc_delta; - Settable<bool> experimental_agc; - Settable<bool> extended_filter_aec; - Settable<bool> delay_agnostic_aec; - Settable<bool> experimental_ns; - Settable<bool> aec_dump; + rtc::Optional<bool> typing_detection; + rtc::Optional<bool> aecm_generate_comfort_noise; + rtc::Optional<bool> conference_mode; + rtc::Optional<int> adjust_agc_delta; + rtc::Optional<bool> experimental_agc; + rtc::Optional<bool> extended_filter_aec; + rtc::Optional<bool> delay_agnostic_aec; + rtc::Optional<bool> experimental_ns; + rtc::Optional<bool> aec_dump; // Note that tx_agc_* only applies to non-experimental AGC. - Settable<uint16_t> tx_agc_target_dbov; - Settable<uint16_t> tx_agc_digital_compression_gain; - Settable<bool> tx_agc_limiter; - Settable<uint32_t> recording_sample_rate; - Settable<uint32_t> playout_sample_rate; + rtc::Optional<uint16_t> tx_agc_target_dbov; + rtc::Optional<uint16_t> tx_agc_digital_compression_gain; + rtc::Optional<bool> tx_agc_limiter; + rtc::Optional<uint32_t> recording_sample_rate; + rtc::Optional<uint32_t> playout_sample_rate; // Set DSCP value for packet sent from audio channel. - Settable<bool> dscp; + rtc::Optional<bool> dscp; // Enable combined audio+bandwidth BWE. - Settable<bool> combined_audio_video_bwe; + rtc::Optional<bool> combined_audio_video_bwe; + + private: + template <typename T> + static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) { + if (o) { + *s = o; + } + } }; // Options that can be applied to a VideoMediaChannel or a VideoMediaEngine. @@ -287,38 +238,41 @@ struct AudioOptions { // We are moving all of the setting of options to structs like this, // but some things currently still use flags. struct VideoOptions { - VideoOptions() { - process_adaptation_threshhold.Set(kProcessCpuThreshold); - system_low_adaptation_threshhold.Set(kLowSystemCpuThreshold); - system_high_adaptation_threshhold.Set(kHighSystemCpuThreshold); - unsignalled_recv_stream_limit.Set(kNumDefaultUnsignalledVideoRecvStreams); - } + VideoOptions() + : process_adaptation_threshhold(kProcessCpuThreshold), + system_low_adaptation_threshhold(kLowSystemCpuThreshold), + system_high_adaptation_threshhold(kHighSystemCpuThreshold), + unsignalled_recv_stream_limit(kNumDefaultUnsignalledVideoRecvStreams) {} void SetAll(const VideoOptions& change) { - adapt_input_to_cpu_usage.SetFrom(change.adapt_input_to_cpu_usage); - adapt_cpu_with_smoothing.SetFrom(change.adapt_cpu_with_smoothing); - video_adapt_third.SetFrom(change.video_adapt_third); - video_noise_reduction.SetFrom(change.video_noise_reduction); - video_start_bitrate.SetFrom(change.video_start_bitrate); - cpu_overuse_detection.SetFrom(change.cpu_overuse_detection); - cpu_underuse_threshold.SetFrom(change.cpu_underuse_threshold); - cpu_overuse_threshold.SetFrom(change.cpu_overuse_threshold); - cpu_underuse_encode_rsd_threshold.SetFrom( - change.cpu_underuse_encode_rsd_threshold); - cpu_overuse_encode_rsd_threshold.SetFrom( - change.cpu_overuse_encode_rsd_threshold); - cpu_overuse_encode_usage.SetFrom(change.cpu_overuse_encode_usage); - conference_mode.SetFrom(change.conference_mode); - process_adaptation_threshhold.SetFrom(change.process_adaptation_threshhold); - system_low_adaptation_threshhold.SetFrom( - change.system_low_adaptation_threshhold); - system_high_adaptation_threshhold.SetFrom( - change.system_high_adaptation_threshhold); - dscp.SetFrom(change.dscp); - suspend_below_min_bitrate.SetFrom(change.suspend_below_min_bitrate); - unsignalled_recv_stream_limit.SetFrom(change.unsignalled_recv_stream_limit); - use_simulcast_adapter.SetFrom(change.use_simulcast_adapter); - screencast_min_bitrate.SetFrom(change.screencast_min_bitrate); + SetFrom(&adapt_input_to_cpu_usage, change.adapt_input_to_cpu_usage); + SetFrom(&adapt_cpu_with_smoothing, change.adapt_cpu_with_smoothing); + SetFrom(&video_adapt_third, change.video_adapt_third); + SetFrom(&video_noise_reduction, change.video_noise_reduction); + SetFrom(&video_start_bitrate, change.video_start_bitrate); + SetFrom(&cpu_overuse_detection, change.cpu_overuse_detection); + SetFrom(&cpu_underuse_threshold, change.cpu_underuse_threshold); + SetFrom(&cpu_overuse_threshold, change.cpu_overuse_threshold); + SetFrom(&cpu_underuse_encode_rsd_threshold, + change.cpu_underuse_encode_rsd_threshold); + SetFrom(&cpu_overuse_encode_rsd_threshold, + change.cpu_overuse_encode_rsd_threshold); + SetFrom(&cpu_overuse_encode_usage, change.cpu_overuse_encode_usage); + SetFrom(&conference_mode, change.conference_mode); + SetFrom(&process_adaptation_threshhold, + change.process_adaptation_threshhold); + SetFrom(&system_low_adaptation_threshhold, + change.system_low_adaptation_threshhold); + SetFrom(&system_high_adaptation_threshhold, + change.system_high_adaptation_threshhold); + SetFrom(&dscp, change.dscp); + SetFrom(&suspend_below_min_bitrate, change.suspend_below_min_bitrate); + SetFrom(&unsignalled_recv_stream_limit, + change.unsignalled_recv_stream_limit); + SetFrom(&use_simulcast_adapter, change.use_simulcast_adapter); + SetFrom(&screencast_min_bitrate, change.screencast_min_bitrate); + SetFrom(&disable_prerenderer_smoothing, + change.disable_prerenderer_smoothing); } bool operator==(const VideoOptions& o) const { @@ -345,7 +299,8 @@ struct VideoOptions { suspend_below_min_bitrate == o.suspend_below_min_bitrate && unsignalled_recv_stream_limit == o.unsignalled_recv_stream_limit && use_simulcast_adapter == o.use_simulcast_adapter && - screencast_min_bitrate == o.screencast_min_bitrate; + screencast_min_bitrate == o.screencast_min_bitrate && + disable_prerenderer_smoothing == o.disable_prerenderer_smoothing; } std::string ToString() const { @@ -381,56 +336,71 @@ struct VideoOptions { } // Enable CPU adaptation? - Settable<bool> adapt_input_to_cpu_usage; + rtc::Optional<bool> adapt_input_to_cpu_usage; // Enable CPU adaptation smoothing? - Settable<bool> adapt_cpu_with_smoothing; + rtc::Optional<bool> adapt_cpu_with_smoothing; // Enable video adapt third? - Settable<bool> video_adapt_third; + rtc::Optional<bool> video_adapt_third; // Enable denoising? - Settable<bool> video_noise_reduction; + rtc::Optional<bool> video_noise_reduction; // Experimental: Enable WebRtc higher start bitrate? - Settable<int> video_start_bitrate; + rtc::Optional<int> video_start_bitrate; // Enable WebRTC Cpu Overuse Detection, which is a new version of the CPU // adaptation algorithm. So this option will override the // |adapt_input_to_cpu_usage|. - Settable<bool> cpu_overuse_detection; + rtc::Optional<bool> cpu_overuse_detection; // Low threshold (t1) for cpu overuse adaptation. (Adapt up) // Metric: encode usage (m1). m1 < t1 => underuse. - Settable<int> cpu_underuse_threshold; + rtc::Optional<int> cpu_underuse_threshold; // High threshold (t1) for cpu overuse adaptation. (Adapt down) // Metric: encode usage (m1). m1 > t1 => overuse. - Settable<int> cpu_overuse_threshold; + rtc::Optional<int> cpu_overuse_threshold; // Low threshold (t2) for cpu overuse adaptation. (Adapt up) // Metric: relative standard deviation of encode time (m2). // Optional threshold. If set, (m1 < t1 && m2 < t2) => underuse. // Note: t2 will have no effect if t1 is not set. - Settable<int> cpu_underuse_encode_rsd_threshold; + rtc::Optional<int> cpu_underuse_encode_rsd_threshold; // High threshold (t2) for cpu overuse adaptation. (Adapt down) // Metric: relative standard deviation of encode time (m2). // Optional threshold. If set, (m1 > t1 || m2 > t2) => overuse. // Note: t2 will have no effect if t1 is not set. - Settable<int> cpu_overuse_encode_rsd_threshold; + rtc::Optional<int> cpu_overuse_encode_rsd_threshold; // Use encode usage for cpu detection. - Settable<bool> cpu_overuse_encode_usage; + rtc::Optional<bool> cpu_overuse_encode_usage; // Use conference mode? - Settable<bool> conference_mode; + rtc::Optional<bool> conference_mode; // Threshhold for process cpu adaptation. (Process limit) - Settable<float> process_adaptation_threshhold; + rtc::Optional<float> process_adaptation_threshhold; // Low threshhold for cpu adaptation. (Adapt up) - Settable<float> system_low_adaptation_threshhold; + rtc::Optional<float> system_low_adaptation_threshhold; // High threshhold for cpu adaptation. (Adapt down) - Settable<float> system_high_adaptation_threshhold; + rtc::Optional<float> system_high_adaptation_threshhold; // Set DSCP value for packet sent from video channel. - Settable<bool> dscp; + rtc::Optional<bool> dscp; // Enable WebRTC suspension of video. No video frames will be sent when the // bitrate is below the configured minimum bitrate. - Settable<bool> suspend_below_min_bitrate; + rtc::Optional<bool> suspend_below_min_bitrate; // Limit on the number of early receive channels that can be created. - Settable<int> unsignalled_recv_stream_limit; + rtc::Optional<int> unsignalled_recv_stream_limit; // Enable use of simulcast adapter. - Settable<bool> use_simulcast_adapter; + rtc::Optional<bool> use_simulcast_adapter; // Force screencast to use a minimum bitrate - Settable<int> screencast_min_bitrate; + rtc::Optional<int> screencast_min_bitrate; + // Set to true if the renderer has an algorithm of frame selection. + // If the value is true, then WebRTC will hand over a frame as soon as + // possible without delay, and rendering smoothness is completely the duty + // of the renderer; + // If the value is false, then WebRTC is responsible to delay frame release + // in order to increase rendering smoothness. + rtc::Optional<bool> disable_prerenderer_smoothing; + + private: + template <typename T> + static void SetFrom(rtc::Optional<T>* s, const rtc::Optional<T>& o) { + if (o) { + *s = o; + } + } }; struct RtpHeaderExtension { @@ -447,8 +417,8 @@ struct RtpHeaderExtension { std::string ToString() const { std::ostringstream ost; ost << "{"; - ost << "id: , " << id; ost << "uri: " << uri; + ost << ", id: " << id; ost << "}"; return ost.str(); } @@ -481,12 +451,6 @@ enum VoiceMediaChannelOptions { OPT_AGC_MINUS_10DB = 0x80000000 }; -// DTMF flags to control if a DTMF tone should be played and/or sent. -enum DtmfFlags { - DF_PLAY = 0x01, - DF_SEND = 0x02, -}; - class MediaChannel : public sigslot::has_slots<> { public: class NetworkInterface { @@ -593,7 +557,6 @@ class MediaChannel : public sigslot::has_slots<> { enum SendFlags { SEND_NOTHING, - SEND_RINGBACKTONE, SEND_MICROPHONE }; @@ -820,6 +783,7 @@ struct VideoSenderInfo : public MediaSenderInfo { } std::vector<SsrcGroup> ssrc_groups; + std::string encoder_implementation_name; int packets_cached; int firs_rcvd; int plis_rcvd; @@ -865,6 +829,7 @@ struct VideoReceiverInfo : public MediaReceiverInfo { } std::vector<SsrcGroup> ssrc_groups; + std::string decoder_implementation_name; int packets_concealed; int firs_sent; int plis_sent; @@ -968,9 +933,13 @@ struct DataMediaInfo { std::vector<DataReceiverInfo> receivers; }; +struct RtcpParameters { + bool reduced_size = false; +}; + template <class Codec> struct RtpParameters { - virtual std::string ToString() { + virtual std::string ToString() const { std::ostringstream ost; ost << "{"; ost << "codecs: " << VectorToString(codecs) << ", "; @@ -982,11 +951,12 @@ struct RtpParameters { std::vector<Codec> codecs; std::vector<RtpHeaderExtension> extensions; // TODO(pthatcher): Add streams. + RtcpParameters rtcp; }; template <class Codec, class Options> struct RtpSendParameters : RtpParameters<Codec> { - std::string ToString() override { + std::string ToString() const override { std::ostringstream ost; ost << "{"; ost << "codecs: " << VectorToString(this->codecs) << ", "; @@ -1056,18 +1026,18 @@ class VoiceMediaChannel : public MediaChannel { // Set speaker output volume of the specified ssrc. virtual bool SetOutputVolume(uint32_t ssrc, double volume) = 0; // Returns if the telephone-event has been negotiated. - virtual bool CanInsertDtmf() { return false; } - // Send and/or play a DTMF |event| according to the |flags|. - // The DTMF out-of-band signal will be used on sending. + virtual bool CanInsertDtmf() = 0; + // Send a DTMF |event|. The DTMF out-of-band signal will be used. // The |ssrc| should be either 0 or a valid send stream ssrc. // The valid value for the |event| are 0 to 15 which corresponding to // DTMF event 0-9, *, #, A-D. - virtual bool InsertDtmf(uint32_t ssrc, - int event, - int duration, - int flags) = 0; + virtual bool InsertDtmf(uint32_t ssrc, int event, int duration) = 0; // Gets quality stats for the channel. virtual bool GetStats(VoiceMediaInfo* info) = 0; + + virtual void SetRawAudioSink( + uint32_t ssrc, + rtc::scoped_ptr<webrtc::AudioSinkInterface> sink) = 0; }; struct VideoSendParameters : RtpSendParameters<VideoCodec, VideoOptions> { @@ -1194,13 +1164,13 @@ struct SendDataParams { enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK }; struct DataOptions { - std::string ToString() { + std::string ToString() const { return "{}"; } }; struct DataSendParameters : RtpSendParameters<DataCodec, DataOptions> { - std::string ToString() { + std::string ToString() const { std::ostringstream ost; // Options and extensions aren't used. ost << "{"; diff --git a/talk/media/base/mediaengine.h b/talk/media/base/mediaengine.h index 1a992d7d4a..467614bb3e 100644 --- a/talk/media/base/mediaengine.h +++ b/talk/media/base/mediaengine.h @@ -28,7 +28,7 @@ #ifndef TALK_MEDIA_BASE_MEDIAENGINE_H_ #define TALK_MEDIA_BASE_MEDIAENGINE_H_ -#ifdef OSX +#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) #include <CoreAudio/CoreAudio.h> #endif @@ -40,8 +40,8 @@ #include "talk/media/base/mediacommon.h" #include "talk/media/base/videocapturer.h" #include "talk/media/base/videocommon.h" -#include "talk/media/base/voiceprocessor.h" #include "talk/media/devices/devicemanager.h" +#include "webrtc/audio_state.h" #include "webrtc/base/fileutils.h" #include "webrtc/base/sigslotrepeater.h" @@ -51,13 +51,16 @@ namespace webrtc { class Call; -class VoiceEngine; } namespace cricket { class VideoCapturer; +struct RtpCapabilities { + std::vector<RtpHeaderExtension> header_extensions; +}; + // MediaEngineInterface is an abstraction of a media engine which can be // subclassed to support different media componentry backends. // It supports voice and video operations in the same class to facilitate @@ -72,7 +75,7 @@ class MediaEngineInterface { // Shuts down the engine. virtual void Terminate() = 0; // TODO(solenberg): Remove once VoE API refactoring is done. - virtual webrtc::VoiceEngine* GetVoE() = 0; + virtual rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const = 0; // MediaChannel creation // Creates a voice media channel. Returns NULL on failure. @@ -85,20 +88,6 @@ class MediaEngineInterface { webrtc::Call* call, const VideoOptions& options) = 0; - // Configuration - // Gets global audio options. - virtual AudioOptions GetAudioOptions() const = 0; - // Sets global audio options. "options" are from AudioOptions, above. - virtual bool SetAudioOptions(const AudioOptions& options) = 0; - // Sets the default (maximum) codec/resolution and encoder option to capture - // and encode video. - virtual bool SetDefaultVideoEncoderConfig(const VideoEncoderConfig& config) - = 0; - - // Device selection - virtual bool SetSoundDevices(const Device* in_device, - const Device* out_device) = 0; - // Device configuration // Gets the current speaker volume, as a value between 0 and 255. virtual bool GetOutputVolume(int* level) = 0; @@ -109,15 +98,9 @@ class MediaEngineInterface { virtual int GetInputLevel() = 0; virtual const std::vector<AudioCodec>& audio_codecs() = 0; - virtual const std::vector<RtpHeaderExtension>& - audio_rtp_header_extensions() = 0; + virtual RtpCapabilities GetAudioCapabilities() = 0; virtual const std::vector<VideoCodec>& video_codecs() = 0; - virtual const std::vector<RtpHeaderExtension>& - video_rtp_header_extensions() = 0; - - // Logging control - virtual void SetVoiceLogging(int min_sev, const char* filter) = 0; - virtual void SetVideoLogging(int min_sev, const char* filter) = 0; + virtual RtpCapabilities GetVideoCapabilities() = 0; // Starts AEC dump using existing file. virtual bool StartAecDump(rtc::PlatformFile file) = 0; @@ -167,8 +150,8 @@ class CompositeMediaEngine : public MediaEngineInterface { voice_.Terminate(); } - virtual webrtc::VoiceEngine* GetVoE() { - return voice_.GetVoE(); + virtual rtc::scoped_refptr<webrtc::AudioState> GetAudioState() const { + return voice_.GetAudioState(); } virtual VoiceMediaChannel* CreateChannel(webrtc::Call* call, const AudioOptions& options) { @@ -179,21 +162,6 @@ class CompositeMediaEngine : public MediaEngineInterface { return video_.CreateChannel(call, options); } - virtual AudioOptions GetAudioOptions() const { - return voice_.GetOptions(); - } - virtual bool SetAudioOptions(const AudioOptions& options) { - return voice_.SetOptions(options); - } - virtual bool SetDefaultVideoEncoderConfig(const VideoEncoderConfig& config) { - return video_.SetDefaultEncoderConfig(config); - } - - virtual bool SetSoundDevices(const Device* in_device, - const Device* out_device) { - return voice_.SetDevices(in_device, out_device); - } - virtual bool GetOutputVolume(int* level) { return voice_.GetOutputVolume(level); } @@ -207,21 +175,14 @@ class CompositeMediaEngine : public MediaEngineInterface { virtual const std::vector<AudioCodec>& audio_codecs() { return voice_.codecs(); } - virtual const std::vector<RtpHeaderExtension>& audio_rtp_header_extensions() { - return voice_.rtp_header_extensions(); + virtual RtpCapabilities GetAudioCapabilities() { + return voice_.GetCapabilities(); } virtual const std::vector<VideoCodec>& video_codecs() { return video_.codecs(); } - virtual const std::vector<RtpHeaderExtension>& video_rtp_header_extensions() { - return video_.rtp_header_extensions(); - } - - virtual void SetVoiceLogging(int min_sev, const char* filter) { - voice_.SetLogging(min_sev, filter); - } - virtual void SetVideoLogging(int min_sev, const char* filter) { - video_.SetLogging(min_sev, filter); + virtual RtpCapabilities GetVideoCapabilities() { + return video_.GetCapabilities(); } virtual bool StartAecDump(rtc::PlatformFile file) { @@ -243,70 +204,6 @@ class CompositeMediaEngine : public MediaEngineInterface { VIDEO video_; }; -// NullVoiceEngine can be used with CompositeMediaEngine in the case where only -// a video engine is desired. -class NullVoiceEngine { - public: - bool Init(rtc::Thread* worker_thread) { return true; } - void Terminate() {} - // If you need this to return an actual channel, use FakeMediaEngine instead. - VoiceMediaChannel* CreateChannel(const AudioOptions& options) { - return nullptr; - } - AudioOptions GetOptions() const { return AudioOptions(); } - bool SetOptions(const AudioOptions& options) { return true; } - bool SetDevices(const Device* in_device, const Device* out_device) { - return true; - } - bool GetOutputVolume(int* level) { - *level = 0; - return true; - } - bool SetOutputVolume(int level) { return true; } - int GetInputLevel() { return 0; } - const std::vector<AudioCodec>& codecs() { return codecs_; } - const std::vector<RtpHeaderExtension>& rtp_header_extensions() { - return rtp_header_extensions_; - } - void SetLogging(int min_sev, const char* filter) {} - bool StartAecDump(rtc::PlatformFile file) { return false; } - bool StartRtcEventLog(rtc::PlatformFile file) { return false; } - void StopRtcEventLog() {} - - private: - std::vector<AudioCodec> codecs_; - std::vector<RtpHeaderExtension> rtp_header_extensions_; -}; - -// NullVideoEngine can be used with CompositeMediaEngine in the case where only -// a voice engine is desired. -class NullVideoEngine { - public: - bool Init(rtc::Thread* worker_thread) { return true; } - void Terminate() {} - // If you need this to return an actual channel, use FakeMediaEngine instead. - VideoMediaChannel* CreateChannel( - const VideoOptions& options, - VoiceMediaChannel* voice_media_channel) { - return NULL; - } - bool SetOptions(const VideoOptions& options) { return true; } - bool SetDefaultEncoderConfig(const VideoEncoderConfig& config) { - return true; - } - const std::vector<VideoCodec>& codecs() { return codecs_; } - const std::vector<RtpHeaderExtension>& rtp_header_extensions() { - return rtp_header_extensions_; - } - void SetLogging(int min_sev, const char* filter) {} - - private: - std::vector<VideoCodec> codecs_; - std::vector<RtpHeaderExtension> rtp_header_extensions_; -}; - -typedef CompositeMediaEngine<NullVoiceEngine, NullVideoEngine> NullMediaEngine; - enum DataChannelType { DCT_NONE = 0, DCT_RTP = 1, diff --git a/talk/media/base/streamparams_unittest.cc b/talk/media/base/streamparams_unittest.cc index a9e1ce3531..a0164733d4 100644 --- a/talk/media/base/streamparams_unittest.cc +++ b/talk/media/base/streamparams_unittest.cc @@ -27,6 +27,7 @@ #include "talk/media/base/streamparams.h" #include "talk/media/base/testutils.h" +#include "webrtc/base/arraysize.h" #include "webrtc/base/gunit.h" static const uint32_t kSsrcs1[] = {1}; @@ -54,8 +55,8 @@ TEST(SsrcGroup, EqualNotEqual) { cricket::SsrcGroup("abc", MAKE_VECTOR(kSsrcs2)), }; - for (size_t i = 0; i < ARRAY_SIZE(ssrc_groups); ++i) { - for (size_t j = 0; j < ARRAY_SIZE(ssrc_groups); ++j) { + for (size_t i = 0; i < arraysize(ssrc_groups); ++i) { + for (size_t j = 0; j < arraysize(ssrc_groups); ++j) { EXPECT_EQ((ssrc_groups[i] == ssrc_groups[j]), (i == j)); EXPECT_EQ((ssrc_groups[i] != ssrc_groups[j]), (i != j)); } @@ -92,7 +93,7 @@ TEST(StreamParams, CreateLegacy) { TEST(StreamParams, HasSsrcGroup) { cricket::StreamParams sp = - CreateStreamParamsWithSsrcGroup("XYZ", kSsrcs2, ARRAY_SIZE(kSsrcs2)); + CreateStreamParamsWithSsrcGroup("XYZ", kSsrcs2, arraysize(kSsrcs2)); EXPECT_EQ(2U, sp.ssrcs.size()); EXPECT_EQ(kSsrcs2[0], sp.first_ssrc()); EXPECT_TRUE(sp.has_ssrcs()); @@ -107,7 +108,7 @@ TEST(StreamParams, HasSsrcGroup) { TEST(StreamParams, GetSsrcGroup) { cricket::StreamParams sp = - CreateStreamParamsWithSsrcGroup("XYZ", kSsrcs2, ARRAY_SIZE(kSsrcs2)); + CreateStreamParamsWithSsrcGroup("XYZ", kSsrcs2, arraysize(kSsrcs2)); EXPECT_EQ(NULL, sp.get_ssrc_group("xyz")); EXPECT_EQ(&sp.ssrc_groups[0], sp.get_ssrc_group("XYZ")); } @@ -116,17 +117,17 @@ TEST(StreamParams, EqualNotEqual) { cricket::StreamParams l1 = cricket::StreamParams::CreateLegacy(1); cricket::StreamParams l2 = cricket::StreamParams::CreateLegacy(2); cricket::StreamParams sg1 = - CreateStreamParamsWithSsrcGroup("ABC", kSsrcs1, ARRAY_SIZE(kSsrcs1)); + CreateStreamParamsWithSsrcGroup("ABC", kSsrcs1, arraysize(kSsrcs1)); cricket::StreamParams sg2 = - CreateStreamParamsWithSsrcGroup("ABC", kSsrcs2, ARRAY_SIZE(kSsrcs2)); + CreateStreamParamsWithSsrcGroup("ABC", kSsrcs2, arraysize(kSsrcs2)); cricket::StreamParams sg3 = - CreateStreamParamsWithSsrcGroup("Abc", kSsrcs2, ARRAY_SIZE(kSsrcs2)); + CreateStreamParamsWithSsrcGroup("Abc", kSsrcs2, arraysize(kSsrcs2)); cricket::StreamParams sg4 = - CreateStreamParamsWithSsrcGroup("abc", kSsrcs2, ARRAY_SIZE(kSsrcs2)); + CreateStreamParamsWithSsrcGroup("abc", kSsrcs2, arraysize(kSsrcs2)); cricket::StreamParams sps[] = {l1, l2, sg1, sg2, sg3, sg4}; - for (size_t i = 0; i < ARRAY_SIZE(sps); ++i) { - for (size_t j = 0; j < ARRAY_SIZE(sps); ++j) { + for (size_t i = 0; i < arraysize(sps); ++i) { + for (size_t j = 0; j < arraysize(sps); ++j) { EXPECT_EQ((sps[i] == sps[j]), (i == j)); EXPECT_EQ((sps[i] != sps[j]), (i != j)); } @@ -195,7 +196,7 @@ TEST(StreamParams, GetPrimaryAndFidSsrcs) { TEST(StreamParams, ToString) { cricket::StreamParams sp = - CreateStreamParamsWithSsrcGroup("XYZ", kSsrcs2, ARRAY_SIZE(kSsrcs2)); + CreateStreamParamsWithSsrcGroup("XYZ", kSsrcs2, arraysize(kSsrcs2)); EXPECT_STREQ("{ssrcs:[1,2];ssrc_groups:{semantics:XYZ;ssrcs:[1,2]};}", sp.ToString().c_str()); } diff --git a/talk/media/base/testutils.cc b/talk/media/base/testutils.cc index 3b1fcf0513..49a78e63dd 100644 --- a/talk/media/base/testutils.cc +++ b/talk/media/base/testutils.cc @@ -132,8 +132,8 @@ const RawRtcpPacket RtpTestUtility::kTestRawRtcpPackets[] = { }; size_t RtpTestUtility::GetTestPacketCount() { - return std::min(ARRAY_SIZE(kTestRawRtpPackets), - ARRAY_SIZE(kTestRawRtcpPackets)); + return std::min(arraysize(kTestRawRtpPackets), + arraysize(kTestRawRtcpPackets)); } bool RtpTestUtility::WriteTestPackets(size_t count, diff --git a/talk/media/base/testutils.h b/talk/media/base/testutils.h index cb4146d707..20c0d62ab7 100644 --- a/talk/media/base/testutils.h +++ b/talk/media/base/testutils.h @@ -35,6 +35,7 @@ #include "talk/media/base/mediachannel.h" #include "talk/media/base/videocapturer.h" #include "talk/media/base/videocommon.h" +#include "webrtc/base/arraysize.h" #include "webrtc/base/basictypes.h" #include "webrtc/base/sigslot.h" #include "webrtc/base/window.h" @@ -54,7 +55,7 @@ namespace cricket { template <class T> inline std::vector<T> MakeVector(const T a[], size_t s) { return std::vector<T>(a, a + s); } -#define MAKE_VECTOR(a) cricket::MakeVector(a, ARRAY_SIZE(a)) +#define MAKE_VECTOR(a) cricket::MakeVector(a, arraysize(a)) struct RtpDumpPacket; class RtpDumpWriter; diff --git a/talk/media/base/videocapturer.cc b/talk/media/base/videocapturer.cc index ca4b9069f1..d525a4188e 100644 --- a/talk/media/base/videocapturer.cc +++ b/talk/media/base/videocapturer.cc @@ -59,7 +59,7 @@ enum { }; static const int64_t kMaxDistance = ~(static_cast<int64_t>(1) << 63); -#ifdef LINUX +#ifdef WEBRTC_LINUX static const int kYU12Penalty = 16; // Needs to be higher than MJPG index. #endif static const int kDefaultScreencastFps = 5; @@ -82,7 +82,7 @@ CapturedFrame::CapturedFrame() pixel_height(0), time_stamp(0), data_size(0), - rotation(0), + rotation(webrtc::kVideoRotation_0), data(NULL) {} // TODO(fbarchard): Remove this function once lmimediaengine stops using it. @@ -94,11 +94,6 @@ bool CapturedFrame::GetDataSize(uint32_t* size) const { return true; } -webrtc::VideoRotation CapturedFrame::GetRotation() const { - ASSERT(rotation == 0 || rotation == 90 || rotation == 180 || rotation == 270); - return static_cast<webrtc::VideoRotation>(rotation); -} - ///////////////////////////////////////////////////////////////////// // Implementation of class VideoCapturer ///////////////////////////////////////////////////////////////////// @@ -126,7 +121,6 @@ void VideoCapturer::Construct() { SignalFrameCaptured.connect(this, &VideoCapturer::OnFrameCaptured); scaled_width_ = 0; scaled_height_ = 0; - screencast_max_pixels_ = 0; muted_ = false; black_frame_count_down_ = kNumBlackFramesOnMute; enable_video_adapter_ = true; @@ -365,16 +359,11 @@ void VideoCapturer::OnFrameCaptured(VideoCapturer*, if (IsScreencast()) { int scaled_width, scaled_height; - if (screencast_max_pixels_ > 0) { - ComputeScaleMaxPixels(captured_frame->width, captured_frame->height, - screencast_max_pixels_, &scaled_width, &scaled_height); - } else { - int desired_screencast_fps = capture_format_.get() ? - VideoFormat::IntervalToFps(capture_format_->interval) : - kDefaultScreencastFps; - ComputeScale(captured_frame->width, captured_frame->height, - desired_screencast_fps, &scaled_width, &scaled_height); - } + int desired_screencast_fps = capture_format_.get() ? + VideoFormat::IntervalToFps(capture_format_->interval) : + kDefaultScreencastFps; + ComputeScale(captured_frame->width, captured_frame->height, + desired_screencast_fps, &scaled_width, &scaled_height); if (FOURCC_ARGB == captured_frame->fourcc && (scaled_width != captured_frame->width || @@ -605,7 +594,7 @@ int64_t VideoCapturer::GetFormatDistance(const VideoFormat& desired, for (size_t i = 0; i < preferred_fourccs.size(); ++i) { if (supported_fourcc == CanonicalFourCC(preferred_fourccs[i])) { delta_fourcc = i; -#ifdef LINUX +#ifdef WEBRTC_LINUX // For HD avoid YU12 which is a software conversion and has 2 bugs // b/7326348 b/6960899. Reenable when fixed. if (supported.height >= 720 && (supported_fourcc == FOURCC_YU12 || diff --git a/talk/media/base/videocapturer.h b/talk/media/base/videocapturer.h index 0a11ed09c1..a13c201b8b 100644 --- a/talk/media/base/videocapturer.h +++ b/talk/media/base/videocapturer.h @@ -78,10 +78,6 @@ struct CapturedFrame { // fourcc. Return true if succeeded. bool GetDataSize(uint32_t* size) const; - // TODO(guoweis): Change the type of |rotation| from int to - // webrtc::VideoRotation once chromium gets the code. - webrtc::VideoRotation GetRotation() const; - // The width and height of the captured frame could be different from those // of VideoFormat. Once the first frame is captured, the width, height, // fourcc, pixel_width, and pixel_height should keep the same over frames. @@ -90,15 +86,11 @@ struct CapturedFrame { uint32_t fourcc; // compression uint32_t pixel_width; // width of a pixel, default is 1 uint32_t pixel_height; // height of a pixel, default is 1 - // TODO(magjed): |elapsed_time| is deprecated - remove once not used anymore. - int64_t elapsed_time; int64_t time_stamp; // timestamp of when the frame was captured, in unix // time with nanosecond units. uint32_t data_size; // number of bytes of the frame data - // TODO(guoweis): This can't be converted to VideoRotation yet as it's - // used by chrome now. - int rotation; // rotation in degrees of the frame (0, 90, 180, 270) + webrtc::VideoRotation rotation; // rotation in degrees of the frame. void* data; // pointer to the frame data. This object allocates the // memory or points to an existing memory. @@ -270,17 +262,6 @@ class VideoCapturer sigslot::signal2<VideoCapturer*, const VideoFrame*, sigslot::multi_threaded_local> SignalVideoFrame; - // If 'screencast_max_pixels' is set greater than zero, screencasts will be - // scaled to be no larger than this value. - // If set to zero, the max pixels will be limited to - // Retina MacBookPro 15" resolution of 2880 x 1800. - // For high fps, maximum pixels limit is set based on common 24" monitor - // resolution of 2048 x 1280. - int screencast_max_pixels() const { return screencast_max_pixels_; } - void set_screencast_max_pixels(int p) { - screencast_max_pixels_ = std::max(0, p); - } - // If true, run video adaptation. By default, video adaptation is enabled // and users must call video_adapter()->OnOutputFormatRequest() // to receive frames. @@ -377,7 +358,6 @@ class VideoCapturer bool square_pixel_aspect_ratio_; // Enable scaling to square pixels. int scaled_width_; // Current output size from ComputeScale. int scaled_height_; - int screencast_max_pixels_; // Downscale screencasts further if requested. bool muted_; int black_frame_count_down_; diff --git a/talk/media/base/videocapturer_unittest.cc b/talk/media/base/videocapturer_unittest.cc index 359fe9552a..6d1d8aa395 100644 --- a/talk/media/base/videocapturer_unittest.cc +++ b/talk/media/base/videocapturer_unittest.cc @@ -196,39 +196,6 @@ TEST_F(VideoCapturerTest, CameraOffOnMute) { EXPECT_EQ(33, video_frames_received()); } -TEST_F(VideoCapturerTest, ScreencastScaledMaxPixels) { - capturer_.SetScreencast(true); - - int kWidth = 1280; - int kHeight = 720; - - // Screencasts usually have large weird dimensions and are ARGB. - std::vector<cricket::VideoFormat> formats; - formats.push_back(cricket::VideoFormat(kWidth, kHeight, - cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_ARGB)); - formats.push_back(cricket::VideoFormat(2 * kWidth, 2 * kHeight, - cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_ARGB)); - capturer_.ResetSupportedFormats(formats); - - - EXPECT_EQ(0, capturer_.screencast_max_pixels()); - EXPECT_EQ(cricket::CS_RUNNING, capturer_.Start(cricket::VideoFormat( - 2 * kWidth, - 2 * kHeight, - cricket::VideoFormat::FpsToInterval(30), - cricket::FOURCC_ARGB))); - EXPECT_TRUE(capturer_.IsRunning()); - EXPECT_EQ(0, renderer_.num_rendered_frames()); - renderer_.SetSize(2 * kWidth, 2 * kHeight, 0); - EXPECT_TRUE(capturer_.CaptureFrame()); - EXPECT_EQ(1, renderer_.num_rendered_frames()); - - capturer_.set_screencast_max_pixels(kWidth * kHeight); - renderer_.SetSize(kWidth, kHeight, 0); - EXPECT_TRUE(capturer_.CaptureFrame()); - EXPECT_EQ(2, renderer_.num_rendered_frames()); -} - TEST_F(VideoCapturerTest, ScreencastScaledOddWidth) { capturer_.SetScreencast(true); diff --git a/talk/media/base/videocommon.cc b/talk/media/base/videocommon.cc index 7b6aac206b..faf6450b56 100644 --- a/talk/media/base/videocommon.cc +++ b/talk/media/base/videocommon.cc @@ -31,6 +31,7 @@ #include <math.h> #include <sstream> +#include "webrtc/base/arraysize.h" #include "webrtc/base/common.h" namespace cricket { @@ -58,7 +59,7 @@ static const FourCCAliasEntry kFourCCAliases[] = { }; uint32_t CanonicalFourCC(uint32_t fourcc) { - for (int i = 0; i < ARRAY_SIZE(kFourCCAliases); ++i) { + for (int i = 0; i < arraysize(kFourCCAliases); ++i) { if (kFourCCAliases[i].alias == fourcc) { return kFourCCAliases[i].canonical; } @@ -75,7 +76,7 @@ static float kScaleFactors[] = { 1.f / 16.f // 1/16 scale. }; -static const int kNumScaleFactors = ARRAY_SIZE(kScaleFactors); +static const int kNumScaleFactors = arraysize(kScaleFactors); // Finds the scale factor that, when applied to width and height, produces // fewer than num_pixels. @@ -106,9 +107,6 @@ void ComputeScaleMaxPixels(int frame_width, int frame_height, int max_pixels, ASSERT(scaled_width != NULL); ASSERT(scaled_height != NULL); ASSERT(max_pixels > 0); - // For VP8 the values for max width and height can be found here - // webrtc/src/video_engine/vie_defines.h (kViEMaxCodecWidth and - // kViEMaxCodecHeight) const int kMaxWidth = 4096; const int kMaxHeight = 3072; int new_frame_width = frame_width; diff --git a/talk/media/base/videoengine_unittest.h b/talk/media/base/videoengine_unittest.h index d89b3e6f43..d7fa00d558 100644 --- a/talk/media/base/videoengine_unittest.h +++ b/talk/media/base/videoengine_unittest.h @@ -126,327 +126,6 @@ class VideoEngineOverride : public T { } }; -template<class E> -class VideoEngineTest : public testing::Test { - protected: - // Tests starting and stopping the engine, and creating a channel. - void StartupShutdown() { - EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); - cricket::VideoMediaChannel* channel = engine_.CreateChannel(NULL); - EXPECT_TRUE(channel != NULL); - delete channel; - engine_.Terminate(); - } - - void ConstrainNewCodecBody() { - cricket::VideoCodec empty, in, out; - cricket::VideoCodec max_settings(engine_.codecs()[0].id, - engine_.codecs()[0].name, - 1280, 800, 30, 0); - - // set max settings of 1280x800x30 - EXPECT_TRUE(engine_.SetDefaultEncoderConfig( - cricket::VideoEncoderConfig(max_settings))); - - // don't constrain the max resolution - in = max_settings; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED2(IsEqualCodec, out, in); - - // constrain resolution greater than the max and wider aspect, - // picking best aspect (16:10) - in.width = 1380; - in.height = 800; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED4(IsEqualRes, out, 1280, 720, 30); - - // constrain resolution greater than the max and narrow aspect, - // picking best aspect (16:9) - in.width = 1280; - in.height = 740; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED4(IsEqualRes, out, 1280, 720, 30); - - // constrain resolution greater than the max, picking equal aspect (4:3) - in.width = 1280; - in.height = 960; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED4(IsEqualRes, out, 1280, 800, 30); - - // constrain resolution greater than the max, picking equal aspect (16:10) - in.width = 1280; - in.height = 800; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED4(IsEqualRes, out, 1280, 800, 30); - - // reduce max settings to 640x480x30 - max_settings.width = 640; - max_settings.height = 480; - EXPECT_TRUE(engine_.SetDefaultEncoderConfig( - cricket::VideoEncoderConfig(max_settings))); - - // don't constrain the max resolution - in = max_settings; - in.width = 640; - in.height = 480; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED2(IsEqualCodec, out, in); - - // keep 16:10 if they request it - in.height = 400; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED2(IsEqualCodec, out, in); - - // don't constrain lesser 4:3 resolutions - in.width = 320; - in.height = 240; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED2(IsEqualCodec, out, in); - - // don't constrain lesser 16:10 resolutions - in.width = 320; - in.height = 200; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED2(IsEqualCodec, out, in); - - // requested resolution of 0x0 succeeds - in.width = 0; - in.height = 0; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED2(IsEqualCodec, out, in); - - // constrain resolution lesser than the max and wider aspect, - // picking best aspect (16:9) - in.width = 350; - in.height = 201; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED4(IsEqualRes, out, 320, 180, 30); - - // constrain resolution greater than the max and narrow aspect, - // picking best aspect (4:3) - in.width = 350; - in.height = 300; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED4(IsEqualRes, out, 320, 240, 30); - - // constrain resolution greater than the max and wider aspect, - // picking best aspect (16:9) - in.width = 1380; - in.height = 800; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED4(IsEqualRes, out, 640, 360, 30); - - // constrain resolution greater than the max and narrow aspect, - // picking best aspect (4:3) - in.width = 1280; - in.height = 900; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED4(IsEqualRes, out, 640, 480, 30); - - // constrain resolution greater than the max, picking equal aspect (4:3) - in.width = 1280; - in.height = 960; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED4(IsEqualRes, out, 640, 480, 30); - - // constrain resolution greater than the max, picking equal aspect (16:10) - in.width = 1280; - in.height = 800; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED4(IsEqualRes, out, 640, 400, 30); - - // constrain res & fps greater than the max - in.framerate = 50; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED4(IsEqualRes, out, 640, 400, 30); - - // reduce max settings to 160x100x10 - max_settings.width = 160; - max_settings.height = 100; - max_settings.framerate = 10; - EXPECT_TRUE(engine_.SetDefaultEncoderConfig( - cricket::VideoEncoderConfig(max_settings))); - - // constrain res & fps to new max - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED4(IsEqualRes, out, 160, 100, 10); - - // allow 4:3 "comparable" resolutions - in.width = 160; - in.height = 120; - in.framerate = 10; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED4(IsEqualRes, out, 160, 120, 10); - } - - // This is the new way of constraining codec size, where we no longer maintain - // a list of the supported formats. Instead, CanSendCodec will just downscale - // the resolution by 2 until the width is below clamp. - void ConstrainNewCodec2Body() { - cricket::VideoCodec empty, in, out; - cricket::VideoCodec max_settings(engine_.codecs()[0].id, - engine_.codecs()[0].name, - 1280, 800, 30, 0); - - // Set max settings of 1280x800x30 - EXPECT_TRUE(engine_.SetDefaultEncoderConfig( - cricket::VideoEncoderConfig(max_settings))); - - // Don't constrain the max resolution - in = max_settings; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED2(IsEqualCodec, out, in); - - // Constrain resolution greater than the max width. - in.width = 1380; - in.height = 800; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED4(IsEqualRes, out, 690, 400, 30); - - // Don't constrain resolution when only the height is greater than max. - in.width = 960; - in.height = 1280; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED4(IsEqualRes, out, 960, 1280, 30); - - // Don't constrain smaller format. - in.width = 640; - in.height = 480; - EXPECT_TRUE(engine_.CanSendCodec(in, empty, &out)); - EXPECT_PRED4(IsEqualRes, out, 640, 480, 30); - } - - void ConstrainRunningCodecBody() { - cricket::VideoCodec in, out, current; - cricket::VideoCodec max_settings(engine_.codecs()[0].id, - engine_.codecs()[0].name, - 1280, 800, 30, 0); - - // set max settings of 1280x960x30 - EXPECT_TRUE(engine_.SetDefaultEncoderConfig( - cricket::VideoEncoderConfig(max_settings))); - - // establish current call at 1280x800x30 (16:10) - current = max_settings; - current.height = 800; - - // Don't constrain current resolution - in = current; - EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); - EXPECT_PRED2(IsEqualCodec, out, in); - - // requested resolution of 0x0 succeeds - in.width = 0; - in.height = 0; - EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); - EXPECT_PRED2(IsEqualCodec, out, in); - - // Reduce an intermediate resolution down to the next lowest one, preserving - // aspect ratio. - in.width = 800; - in.height = 600; - EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); - EXPECT_PRED4(IsEqualRes, out, 640, 400, 30); - - // Clamping by aspect ratio, but still never return a dimension higher than - // requested. - in.width = 1280; - in.height = 720; - EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); - EXPECT_PRED4(IsEqualRes, out, 1280, 720, 30); - - in.width = 1279; - EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); - EXPECT_PRED4(IsEqualRes, out, 960, 600, 30); - - in.width = 1281; - EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); - EXPECT_PRED4(IsEqualRes, out, 1280, 720, 30); - - // Clamp large resolutions down, always preserving aspect - in.width = 1920; - in.height = 1080; - EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); - EXPECT_PRED4(IsEqualRes, out, 1280, 800, 30); - - in.width = 1921; - EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); - EXPECT_PRED4(IsEqualRes, out, 1280, 800, 30); - - in.width = 1919; - EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); - EXPECT_PRED4(IsEqualRes, out, 1280, 800, 30); - - // reduce max settings to 640x480x30 - max_settings.width = 640; - max_settings.height = 480; - EXPECT_TRUE(engine_.SetDefaultEncoderConfig( - cricket::VideoEncoderConfig(max_settings))); - - // establish current call at 640x400x30 (16:10) - current = max_settings; - current.height = 400; - - // Don't constrain current resolution - in = current; - EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); - EXPECT_PRED2(IsEqualCodec, out, in); - - // requested resolution of 0x0 succeeds - in.width = 0; - in.height = 0; - EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); - EXPECT_PRED2(IsEqualCodec, out, in); - - // Reduce an intermediate resolution down to the next lowest one, preserving - // aspect ratio. - in.width = 400; - in.height = 300; - EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); - EXPECT_PRED4(IsEqualRes, out, 320, 200, 30); - - // Clamping by aspect ratio, but still never return a dimension higher than - // requested. - in.width = 640; - in.height = 360; - EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); - EXPECT_PRED4(IsEqualRes, out, 640, 360, 30); - - in.width = 639; - EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); - EXPECT_PRED4(IsEqualRes, out, 480, 300, 30); - - in.width = 641; - EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); - EXPECT_PRED4(IsEqualRes, out, 640, 360, 30); - - // Clamp large resolutions down, always preserving aspect - in.width = 1280; - in.height = 800; - EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); - EXPECT_PRED4(IsEqualRes, out, 640, 400, 30); - - in.width = 1281; - EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); - EXPECT_PRED4(IsEqualRes, out, 640, 400, 30); - - in.width = 1279; - EXPECT_TRUE(engine_.CanSendCodec(in, current, &out)); - EXPECT_PRED4(IsEqualRes, out, 640, 400, 30); - - // Should fail for any that are smaller than our supported formats - in.width = 80; - in.height = 80; - EXPECT_FALSE(engine_.CanSendCodec(in, current, &out)); - - in.height = 50; - EXPECT_FALSE(engine_.CanSendCodec(in, current, &out)); - } - - VideoEngineOverride<E> engine_; - rtc::scoped_ptr<cricket::FakeVideoCapturer> video_capturer_; -}; - template<class E, class C> class VideoMediaChannelTest : public testing::Test, public sigslot::has_slots<> { @@ -875,7 +554,7 @@ class VideoMediaChannelTest : public testing::Test, EXPECT_TRUE(SetOneCodec(DefaultCodec())); cricket::VideoSendParameters parameters; parameters.codecs.push_back(DefaultCodec()); - parameters.options.conference_mode.Set(true); + parameters.options.conference_mode = rtc::Optional<bool>(true); EXPECT_TRUE(channel_->SetSendParameters(parameters)); EXPECT_TRUE(SetSend(true)); EXPECT_TRUE(channel_->AddRecvStream( @@ -926,7 +605,7 @@ class VideoMediaChannelTest : public testing::Test, EXPECT_TRUE(SetOneCodec(DefaultCodec())); cricket::VideoSendParameters parameters; parameters.codecs.push_back(DefaultCodec()); - parameters.options.conference_mode.Set(true); + parameters.options.conference_mode = rtc::Optional<bool>(true); EXPECT_TRUE(channel_->SetSendParameters(parameters)); EXPECT_TRUE(channel_->AddRecvStream( cricket::StreamParams::CreateLegacy(kSsrc))); @@ -1009,8 +688,10 @@ class VideoMediaChannelTest : public testing::Test, rtc::scoped_ptr<const rtc::Buffer> p(GetRtpPacket(0)); ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); EXPECT_EQ(kSsrc, ssrc); - EXPECT_EQ(NumRtpPackets(), NumRtpPackets(ssrc)); - EXPECT_EQ(NumRtpBytes(), NumRtpBytes(ssrc)); + // Packets are being paced out, so these can mismatch between the first and + // second call to NumRtpPackets until pending packets are paced out. + EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(ssrc), kTimeout); + EXPECT_EQ_WAIT(NumRtpBytes(), NumRtpBytes(ssrc), kTimeout); EXPECT_EQ(1, NumSentSsrcs()); EXPECT_EQ(0, NumRtpPackets(kSsrc - 1)); EXPECT_EQ(0, NumRtpBytes(kSsrc - 1)); @@ -1031,8 +712,10 @@ class VideoMediaChannelTest : public testing::Test, rtc::scoped_ptr<const rtc::Buffer> p(GetRtpPacket(0)); ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); EXPECT_EQ(999u, ssrc); - EXPECT_EQ(NumRtpPackets(), NumRtpPackets(ssrc)); - EXPECT_EQ(NumRtpBytes(), NumRtpBytes(ssrc)); + // Packets are being paced out, so these can mismatch between the first and + // second call to NumRtpPackets until pending packets are paced out. + EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(ssrc), kTimeout); + EXPECT_EQ_WAIT(NumRtpBytes(), NumRtpBytes(ssrc), kTimeout); EXPECT_EQ(1, NumSentSsrcs()); EXPECT_EQ(0, NumRtpPackets(kSsrc)); EXPECT_EQ(0, NumRtpBytes(kSsrc)); @@ -1236,7 +919,7 @@ class VideoMediaChannelTest : public testing::Test, EXPECT_TRUE(SetDefaultCodec()); cricket::VideoSendParameters parameters; parameters.codecs.push_back(DefaultCodec()); - parameters.options.conference_mode.Set(true); + parameters.options.conference_mode = rtc::Optional<bool>(true); EXPECT_TRUE(channel_->SetSendParameters(parameters)); EXPECT_TRUE(SetSend(true)); EXPECT_TRUE(channel_->AddRecvStream( @@ -1746,8 +1429,8 @@ class VideoMediaChannelTest : public testing::Test, // Tests that we can send and receive frames with early receive. void TwoStreamsSendAndUnsignalledRecv(const cricket::VideoCodec& codec) { cricket::VideoSendParameters parameters; - parameters.options.conference_mode.Set(true); - parameters.options.unsignalled_recv_stream_limit.Set(1); + parameters.options.conference_mode = rtc::Optional<bool>(true); + parameters.options.unsignalled_recv_stream_limit = rtc::Optional<int>(1); EXPECT_TRUE(channel_->SetSendParameters(parameters)); SetUpSecondStreamWithNoRecv(); // Test sending and receiving on first stream. @@ -1780,8 +1463,8 @@ class VideoMediaChannelTest : public testing::Test, void TwoStreamsAddAndRemoveUnsignalledRecv( const cricket::VideoCodec& codec) { cricket::VideoOptions vmo; - vmo.conference_mode.Set(true); - vmo.unsignalled_recv_stream_limit.Set(1); + vmo.conference_mode = rtc::Optional<bool>(true); + vmo.unsignalled_recv_stream_limit = rtc::Optional<int>(1); EXPECT_TRUE(channel_->SetOptions(vmo)); SetUpSecondStreamWithNoRecv(); // Sending and receiving on first stream. diff --git a/talk/media/base/videoframe.cc b/talk/media/base/videoframe.cc index 2b604b085b..3e4d60a258 100644 --- a/talk/media/base/videoframe.cc +++ b/talk/media/base/videoframe.cc @@ -33,6 +33,7 @@ #include "libyuv/planar_functions.h" #include "libyuv/scale.h" #include "talk/media/base/videocommon.h" +#include "webrtc/base/arraysize.h" #include "webrtc/base/checks.h" #include "webrtc/base/logging.h" @@ -318,7 +319,7 @@ bool VideoFrame::Validate(uint32_t fourcc, } // TODO(fbarchard): Make function to dump information about frames. uint8_t four_samples[4] = {0, 0, 0, 0}; - for (size_t i = 0; i < ARRAY_SIZE(four_samples) && i < sample_size; ++i) { + for (size_t i = 0; i < arraysize(four_samples) && i < sample_size; ++i) { four_samples[i] = sample[i]; } if (sample_size < expected_size) { diff --git a/talk/media/base/videoframe.h b/talk/media/base/videoframe.h index 217732fa18..f81c678d61 100644 --- a/talk/media/base/videoframe.h +++ b/talk/media/base/videoframe.h @@ -30,7 +30,7 @@ #include "webrtc/base/basictypes.h" #include "webrtc/base/stream.h" -#include "webrtc/common_video/interface/video_frame_buffer.h" +#include "webrtc/common_video/include/video_frame_buffer.h" #include "webrtc/common_video/rotation.h" namespace cricket { diff --git a/talk/media/base/videoframefactory.cc b/talk/media/base/videoframefactory.cc index dfd97c6faa..fb81096c31 100644 --- a/talk/media/base/videoframefactory.cc +++ b/talk/media/base/videoframefactory.cc @@ -51,8 +51,8 @@ VideoFrame* VideoFrameFactory::CreateAliasedFrame( // If the frame is rotated, we need to switch the width and height. if (apply_rotation_ && - (input_frame->GetRotation() == webrtc::kVideoRotation_90 || - input_frame->GetRotation() == webrtc::kVideoRotation_270)) { + (input_frame->rotation == webrtc::kVideoRotation_90 || + input_frame->rotation == webrtc::kVideoRotation_270)) { std::swap(output_width, output_height); } diff --git a/talk/media/base/videorenderer.h b/talk/media/base/videorenderer.h index 0a0ee51817..a18c4e3c29 100644 --- a/talk/media/base/videorenderer.h +++ b/talk/media/base/videorenderer.h @@ -42,11 +42,12 @@ class VideoFrame; class VideoRenderer { public: virtual ~VideoRenderer() {} - // Called when the video has changed size. This is also used as an - // initialization method to set the UI size before any video frame - // rendered. webrtc::ExternalRenderer's FrameSizeChange will invoke this when - // it's called or later when a VideoRenderer is attached. - virtual bool SetSize(int width, int height, int reserved) = 0; + // Called when the video has changed size. + // TODO(nisse): This method is not really used, and should be + // deleted. Provide a default do-nothing implementation, to easy the + // transition as the method is deleted in subclasses, in particular, + // chrome's MockVideoRenderer class. + virtual bool SetSize(int width, int height, int reserved) { return true; }; // Called when a new frame is available for display. virtual bool RenderFrame(const VideoFrame *frame) = 0; diff --git a/talk/media/base/voiceprocessor.h b/talk/media/base/voiceprocessor.h deleted file mode 100755 index 8de2678c95..0000000000 --- a/talk/media/base/voiceprocessor.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * libjingle - * Copyright 2004 Google Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -// TODO(solenberg): Remove this file once Chromium's libjingle.gyp/.gn are -// updated. |