Remove use of DeviceManager from ChannelManager.

BUG=webrtc:4690

Review URL: https://codereview.webrtc.org/1346153002

Cr-Commit-Position: refs/heads/master@{#10042}
This commit is contained in:
solenberg 2015-09-24 00:41:50 -07:00 committed by Commit bot
parent 7603c76ab0
commit facbbecb51
10 changed files with 19 additions and 565 deletions

View File

@ -33,7 +33,6 @@
#include "talk/app/webrtc/test/fakeconstraints.h"
#include "talk/media/base/fakemediaengine.h"
#include "talk/media/base/fakevideorenderer.h"
#include "talk/media/devices/fakedevicemanager.h"
#include "webrtc/base/gunit.h"
using webrtc::LocalAudioSource;

View File

@ -37,7 +37,6 @@
#include "talk/app/webrtc/test/fakedatachannelprovider.h"
#include "talk/app/webrtc/videotrack.h"
#include "talk/media/base/fakemediaengine.h"
#include "talk/media/devices/fakedevicemanager.h"
#include "webrtc/p2p/base/constants.h"
#include "webrtc/p2p/base/sessiondescription.h"
#include "talk/session/media/channelmanager.h"
@ -482,7 +481,6 @@ class MediaStreamSignalingTest: public testing::Test {
observer_.reset(new MockSignalingObserver());
channel_manager_.reset(
new cricket::ChannelManager(new cricket::FakeMediaEngine(),
new cricket::FakeDeviceManager(),
rtc::Thread::Current()));
signaling_.reset(new MediaStreamSignalingForTest(observer_.get(),
channel_manager_.get()));

View File

@ -38,7 +38,6 @@
#include "talk/app/webrtc/videosource.h"
#include "talk/app/webrtc/videosourceproxy.h"
#include "talk/app/webrtc/videotrack.h"
#include "talk/media/devices/dummydevicemanager.h"
#include "talk/media/webrtc/webrtcmediaengine.h"
#include "talk/media/webrtc/webrtcvideodecoderfactory.h"
#include "talk/media/webrtc/webrtcvideoencoderfactory.h"
@ -174,17 +173,14 @@ bool PeerConnectionFactory::Initialize() {
if (!default_allocator_factory_)
return false;
cricket::DummyDeviceManager* device_manager(
new cricket::DummyDeviceManager());
// TODO: Need to make sure only one VoE is created inside
// WebRtcMediaEngine.
cricket::MediaEngineInterface* media_engine =
worker_thread_->Invoke<cricket::MediaEngineInterface*>(rtc::Bind(
&PeerConnectionFactory::CreateMediaEngine_w, this));
channel_manager_.reset(new cricket::ChannelManager(
media_engine, device_manager, worker_thread_));
channel_manager_.reset(
new cricket::ChannelManager(media_engine, worker_thread_));
channel_manager_->SetVideoRtxEnabled(true);
if (!channel_manager_->Init()) {

View File

@ -39,7 +39,6 @@
#include "talk/app/webrtc/test/fakemediastreamsignaling.h"
#include "talk/app/webrtc/videotrack.h"
#include "talk/media/base/fakemediaengine.h"
#include "talk/media/devices/fakedevicemanager.h"
#include "talk/session/media/channelmanager.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@ -63,7 +62,6 @@ using webrtc::StatsReports;
namespace cricket {
class ChannelManager;
class FakeDeviceManager;
} // namespace cricket
@ -486,9 +484,7 @@ class StatsCollectorTest : public testing::Test {
StatsCollectorTest()
: media_engine_(new cricket::FakeMediaEngine()),
channel_manager_(
new cricket::ChannelManager(media_engine_,
new cricket::FakeDeviceManager(),
rtc::Thread::Current())),
new cricket::ChannelManager(media_engine_, rtc::Thread::Current())),
session_(channel_manager_.get()),
signaling_(channel_manager_.get()) {
// By default, we ignore session GetStats calls.

View File

@ -32,8 +32,8 @@
#include "talk/app/webrtc/test/fakeconstraints.h"
#include "talk/app/webrtc/videosource.h"
#include "talk/media/base/fakemediaengine.h"
#include "talk/media/base/fakevideocapturer.h"
#include "talk/media/base/fakevideorenderer.h"
#include "talk/media/devices/fakedevicemanager.h"
#include "talk/media/webrtc/webrtcvideoframe.h"
#include "talk/session/media/channelmanager.h"
#include "webrtc/base/gunit.h"
@ -130,8 +130,7 @@ class VideoSourceTest : public testing::Test {
: capturer_cleanup_(new TestVideoCapturer()),
capturer_(capturer_cleanup_.get()),
channel_manager_(new cricket::ChannelManager(
new cricket::FakeMediaEngine(),
new cricket::FakeDeviceManager(), rtc::Thread::Current())) {
new cricket::FakeMediaEngine(), rtc::Thread::Current())) {
}
void SetUp() {

View File

@ -32,7 +32,6 @@
#include "talk/app/webrtc/videosource.h"
#include "talk/app/webrtc/videotrack.h"
#include "talk/media/base/fakemediaengine.h"
#include "talk/media/devices/fakedevicemanager.h"
#include "talk/media/webrtc/webrtcvideoframe.h"
#include "talk/session/media/channelmanager.h"
#include "webrtc/base/gunit.h"
@ -58,8 +57,7 @@ class VideoTrackTest : public testing::Test {
static const char kVideoTrackId[] = "track_id";
channel_manager_.reset(new cricket::ChannelManager(
new cricket::FakeMediaEngine(), new cricket::FakeDeviceManager(),
rtc::Thread::Current()));
new cricket::FakeMediaEngine(), rtc::Thread::Current()));
EXPECT_TRUE(channel_manager_->Init());
video_track_ = VideoTrack::Create(
kVideoTrackId,

View File

@ -42,7 +42,6 @@
#include "talk/media/base/fakemediaengine.h"
#include "talk/media/base/fakevideorenderer.h"
#include "talk/media/base/mediachannel.h"
#include "talk/media/devices/fakedevicemanager.h"
#include "webrtc/p2p/base/stunserver.h"
#include "webrtc/p2p/base/teststunserver.h"
#include "webrtc/p2p/base/testturnserver.h"
@ -362,10 +361,9 @@ class WebRtcSessionTest
WebRtcSessionTest()
: media_engine_(new cricket::FakeMediaEngine()),
data_engine_(new cricket::FakeDataEngine()),
device_manager_(new cricket::FakeDeviceManager()),
channel_manager_(new cricket::ChannelManager(
media_engine_, data_engine_, device_manager_,
new cricket::CaptureManager(), rtc::Thread::Current())),
media_engine_, data_engine_, new cricket::CaptureManager(),
rtc::Thread::Current())),
tdesc_factory_(new cricket::TransportDescriptionFactory()),
desc_factory_(new cricket::MediaSessionDescriptionFactory(
channel_manager_.get(), tdesc_factory_.get())),
@ -1303,7 +1301,6 @@ class WebRtcSessionTest
cricket::FakeMediaEngine* media_engine_;
cricket::FakeDataEngine* data_engine_;
cricket::FakeDeviceManager* device_manager_;
rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;

View File

@ -35,10 +35,10 @@
#include "talk/app/webrtc/mediacontroller.h"
#include "talk/media/base/capturemanager.h"
#include "talk/media/base/device.h"
#include "talk/media/base/hybriddataengine.h"
#include "talk/media/base/rtpdataengine.h"
#include "talk/media/base/videocapturer.h"
#include "talk/media/devices/devicemanager.h"
#ifdef HAVE_SCTP
#include "talk/media/sctp/sctpdataengine.h"
#endif
@ -78,48 +78,37 @@ static DataEngineInterface* ConstructDataEngine() {
ChannelManager::ChannelManager(MediaEngineInterface* me,
DataEngineInterface* dme,
DeviceManagerInterface* dm,
CaptureManager* cm,
rtc::Thread* worker_thread) {
Construct(me, dme, dm, cm, worker_thread);
Construct(me, dme, cm, worker_thread);
}
ChannelManager::ChannelManager(MediaEngineInterface* me,
DeviceManagerInterface* dm,
rtc::Thread* worker_thread) {
Construct(me,
ConstructDataEngine(),
dm,
new CaptureManager(),
worker_thread);
}
void ChannelManager::Construct(MediaEngineInterface* me,
DataEngineInterface* dme,
DeviceManagerInterface* dm,
CaptureManager* cm,
rtc::Thread* worker_thread) {
media_engine_.reset(me);
data_media_engine_.reset(dme);
device_manager_.reset(dm);
capture_manager_.reset(cm);
initialized_ = false;
main_thread_ = rtc::Thread::Current();
worker_thread_ = worker_thread;
// Get the default audio options from the media engine.
audio_options_ = media_engine_->GetAudioOptions();
audio_in_device_ = DeviceManagerInterface::kDefaultDeviceName;
audio_out_device_ = DeviceManagerInterface::kDefaultDeviceName;
audio_delay_offset_ = kDefaultAudioDelayOffset;
audio_output_volume_ = kNotSetOutputVolume;
local_renderer_ = NULL;
capturing_ = false;
enable_rtx_ = false;
// Init the device manager immediately, and set up our default video device.
SignalDevicesChange.repeat(device_manager_->SignalDevicesChange);
device_manager_->Init();
capture_manager_->SignalCapturerStateChange.connect(
this, &ChannelManager::OnVideoCaptureStateChange);
}
@ -156,7 +145,7 @@ bool ChannelManager::SetVideoRtxEnabled(bool enable) {
}
int ChannelManager::GetCapabilities() {
return media_engine_->GetCapabilities() & device_manager_->GetCapabilities();
return media_engine_->GetCapabilities();
}
void ChannelManager::GetSupportedAudioCodecs(
@ -221,37 +210,8 @@ bool ChannelManager::Init() {
return false;
}
// Now that we're initialized, apply any stored preferences. A preferred
// device might have been unplugged. In this case, we fallback to the
// default device but keep the user preferences. The preferences are
// changed only when the Javascript FE changes them.
const std::string preferred_audio_in_device = audio_in_device_;
const std::string preferred_audio_out_device = audio_out_device_;
const std::string preferred_camera_device = camera_device_;
Device device;
if (!device_manager_->GetAudioInputDevice(audio_in_device_, &device)) {
LOG(LS_WARNING) << "The preferred microphone '" << audio_in_device_
<< "' is unavailable. Fall back to the default.";
audio_in_device_ = DeviceManagerInterface::kDefaultDeviceName;
}
if (!device_manager_->GetAudioOutputDevice(audio_out_device_, &device)) {
LOG(LS_WARNING) << "The preferred speaker '" << audio_out_device_
<< "' is unavailable. Fall back to the default.";
audio_out_device_ = DeviceManagerInterface::kDefaultDeviceName;
}
if (!device_manager_->GetVideoCaptureDevice(camera_device_, &device)) {
if (!camera_device_.empty()) {
LOG(LS_WARNING) << "The preferred camera '" << camera_device_
<< "' is unavailable. Fall back to the default.";
}
camera_device_ = DeviceManagerInterface::kDefaultDeviceName;
}
if (!SetAudioOptions(audio_in_device_, audio_out_device_,
audio_options_, audio_delay_offset_)) {
if (!SetAudioOptions(audio_options_, audio_delay_offset_)) {
LOG(LS_WARNING) << "Failed to SetAudioOptions with"
<< " microphone: " << audio_in_device_
<< " speaker: " << audio_out_device_
<< " options: " << audio_options_.ToString()
<< " delay: " << audio_delay_offset_;
}
@ -263,15 +223,6 @@ bool ChannelManager::Init() {
LOG(LS_WARNING) << "Failed to SetOutputVolume to "
<< audio_output_volume_;
}
if (!SetCaptureDevice(camera_device_) && !camera_device_.empty()) {
LOG(LS_WARNING) << "Failed to SetCaptureDevice with camera: "
<< camera_device_;
}
// Restore the user preferences.
audio_in_device_ = preferred_audio_in_device;
audio_out_device_ = preferred_audio_out_device;
camera_device_ = preferred_camera_device;
// Now apply the default video codec that has been set earlier.
if (default_video_encoder_config_.max_codec.id != 0) {
@ -310,9 +261,6 @@ void ChannelManager::Terminate_w() {
while (!voice_channels_.empty()) {
DestroyVoiceChannel_w(voice_channels_.back());
}
if (!SetCaptureDevice_w(NULL)) {
LOG(LS_WARNING) << "failed to delete video capturer";
}
media_engine_->Terminate();
}
@ -485,38 +433,11 @@ void ChannelManager::DestroyDataChannel_w(DataChannel* data_channel) {
delete data_channel;
}
bool ChannelManager::GetAudioOptions(std::string* in_name,
std::string* out_name,
AudioOptions* options) {
if (in_name)
*in_name = audio_in_device_;
if (out_name)
*out_name = audio_out_device_;
if (options)
*options = audio_options_;
return true;
}
bool ChannelManager::SetAudioOptions(const std::string& in_name,
const std::string& out_name,
const AudioOptions& options) {
return SetAudioOptions(in_name, out_name, options, audio_delay_offset_);
}
bool ChannelManager::SetAudioOptions(const std::string& in_name,
const std::string& out_name,
const AudioOptions& options,
bool ChannelManager::SetAudioOptions(const AudioOptions& options,
int delay_offset) {
// Get device ids from DeviceManager.
Device in_dev, out_dev;
if (!device_manager_->GetAudioInputDevice(in_name, &in_dev)) {
LOG(LS_WARNING) << "Failed to GetAudioInputDevice: " << in_name;
return false;
}
if (!device_manager_->GetAudioOutputDevice(out_name, &out_dev)) {
LOG(LS_WARNING) << "Failed to GetAudioOutputDevice: " << out_name;
return false;
}
// "Get device ids from DeviceManager" - these are the defaults returned.
Device in_dev("", -1);
Device out_dev("", -1);
// If we're initialized, pass the settings to the media engine.
bool ret = true;
@ -529,8 +450,6 @@ bool ChannelManager::SetAudioOptions(const std::string& in_name,
// If all worked well, save the values for use in GetAudioOptions.
if (ret) {
audio_options_ = options;
audio_in_device_ = in_name;
audio_out_device_ = out_name;
audio_delay_offset_ = delay_offset;
}
return ret;
@ -580,113 +499,6 @@ bool ChannelManager::SetOutputVolume(int level) {
return ret;
}
bool ChannelManager::IsSameCapturer(const std::string& capturer_name,
VideoCapturer* capturer) {
if (capturer == NULL) {
return false;
}
Device device;
if (!device_manager_->GetVideoCaptureDevice(capturer_name, &device)) {
return false;
}
return capturer->GetId() == device.id;
}
bool ChannelManager::GetVideoCaptureDevice(Device* device) {
std::string device_name;
if (!GetCaptureDevice(&device_name)) {
return false;
}
return device_manager_->GetVideoCaptureDevice(device_name, device);
}
bool ChannelManager::GetCaptureDevice(std::string* cam_name) {
if (camera_device_.empty()) {
// Initialize camera_device_ with default.
Device device;
if (!device_manager_->GetVideoCaptureDevice(
DeviceManagerInterface::kDefaultDeviceName, &device)) {
LOG(LS_WARNING) << "Device manager can't find default camera: " <<
DeviceManagerInterface::kDefaultDeviceName;
return false;
}
camera_device_ = device.name;
}
*cam_name = camera_device_;
return true;
}
bool ChannelManager::SetCaptureDevice(const std::string& cam_name) {
Device device;
bool ret = true;
if (!device_manager_->GetVideoCaptureDevice(cam_name, &device)) {
if (!cam_name.empty()) {
LOG(LS_WARNING) << "Device manager can't find camera: " << cam_name;
}
ret = false;
}
// If we're running, tell the media engine about it.
if (initialized_ && ret) {
ret = worker_thread_->Invoke<bool>(
Bind(&ChannelManager::SetCaptureDevice_w, this, &device));
}
// If everything worked, retain the name of the selected camera.
if (ret) {
camera_device_ = device.name;
} else if (camera_device_.empty()) {
// When video option setting fails, we still want camera_device_ to be in a
// good state, so we initialize it with default if it's empty.
Device default_device;
if (!device_manager_->GetVideoCaptureDevice(
DeviceManagerInterface::kDefaultDeviceName, &default_device)) {
LOG(LS_WARNING) << "Device manager can't find default camera: " <<
DeviceManagerInterface::kDefaultDeviceName;
}
camera_device_ = default_device.name;
}
return ret;
}
VideoCapturer* ChannelManager::CreateVideoCapturer() {
Device device;
if (!device_manager_->GetVideoCaptureDevice(camera_device_, &device)) {
if (!camera_device_.empty()) {
LOG(LS_WARNING) << "Device manager can't find camera: " << camera_device_;
}
return NULL;
}
VideoCapturer* capturer = device_manager_->CreateVideoCapturer(device);
if (capturer && default_video_encoder_config_.max_codec.id != 0) {
// For now, use the aspect ratio of the default_video_encoder_config_,
// which may be different than the native aspect ratio of the start
// format the camera may use.
capturer->UpdateAspectRatio(
default_video_encoder_config_.max_codec.width,
default_video_encoder_config_.max_codec.height);
}
return capturer;
}
VideoCapturer* ChannelManager::CreateScreenCapturer(
const ScreencastId& screenid) {
return device_manager_->CreateScreenCapturer(screenid);
}
bool ChannelManager::SetCaptureDevice_w(const Device* cam_device) {
ASSERT(worker_thread_ == rtc::Thread::Current());
ASSERT(initialized_);
if (!cam_device) {
video_device_name_.clear();
return true;
}
video_device_name_ = cam_device->name;
return true;
}
bool ChannelManager::SetDefaultVideoEncoderConfig(const VideoEncoderConfig& c) {
bool ret = true;
if (initialized_) {
@ -834,42 +646,6 @@ static void GetDeviceNames(const std::vector<Device>& devs,
}
}
bool ChannelManager::GetAudioInputDevices(std::vector<std::string>* names) {
names->clear();
std::vector<Device> devs;
bool ret = device_manager_->GetAudioInputDevices(&devs);
if (ret)
GetDeviceNames(devs, names);
return ret;
}
bool ChannelManager::GetAudioOutputDevices(std::vector<std::string>* names) {
names->clear();
std::vector<Device> devs;
bool ret = device_manager_->GetAudioOutputDevices(&devs);
if (ret)
GetDeviceNames(devs, names);
return ret;
}
bool ChannelManager::GetVideoCaptureDevices(std::vector<std::string>* names) {
names->clear();
std::vector<Device> devs;
bool ret = device_manager_->GetVideoCaptureDevices(&devs);
if (ret)
GetDeviceNames(devs, names);
return ret;
}
void ChannelManager::SetVideoCaptureDeviceMaxFormat(
const std::string& usb_id,
const VideoFormat& max_format) {
device_manager_->SetVideoCaptureDeviceMaxFormat(usb_id, max_format);
}
bool ChannelManager::StartAecDump(rtc::PlatformFile file) {
return worker_thread_->Invoke<bool>(
Bind(&MediaEngineInterface::StartAecDump, media_engine_.get(), file));

View File

@ -65,12 +65,10 @@ class ChannelManager : public rtc::MessageHandler,
// ownership of these objects.
ChannelManager(MediaEngineInterface* me,
DataEngineInterface* dme,
DeviceManagerInterface* dm,
CaptureManager* cm,
rtc::Thread* worker);
// Same as above, but gives an easier default DataEngine.
ChannelManager(MediaEngineInterface* me,
DeviceManagerInterface* dm,
rtc::Thread* worker);
~ChannelManager();
@ -135,29 +133,8 @@ class ChannelManager : public rtc::MessageHandler,
return (!voice_channels_.empty() || !video_channels_.empty());
}
// Configures the audio and video devices. A null pointer can be passed to
// GetAudioOptions() for any parameter of no interest.
bool GetAudioOptions(std::string* wave_in_device,
std::string* wave_out_device,
AudioOptions* options);
bool SetAudioOptions(const std::string& wave_in_device,
const std::string& wave_out_device,
const AudioOptions& options);
bool GetOutputVolume(int* level);
bool SetOutputVolume(int level);
bool IsSameCapturer(const std::string& capturer_name,
VideoCapturer* capturer);
// TODO(noahric): Nearly everything called "device" in this API is actually a
// device name, so this should really be GetCaptureDeviceName, and the
// next method should be GetCaptureDevice.
bool GetCaptureDevice(std::string* cam_device);
// Gets the current capture Device.
bool GetVideoCaptureDevice(Device* device);
// Create capturer based on what has been set in SetCaptureDevice().
VideoCapturer* CreateVideoCapturer();
// Create capturer from a screen.
VideoCapturer* CreateScreenCapturer(const ScreencastId& screenid);
bool SetCaptureDevice(const std::string& cam_device);
bool SetDefaultVideoEncoderConfig(const VideoEncoderConfig& config);
// RTX will be enabled/disabled in engines that support it. The supporting
// engines will start offering an RTX codec. Must be called before Init().
@ -196,35 +173,16 @@ class ChannelManager : public rtc::MessageHandler,
// The operations below occur on the main thread.
bool GetAudioInputDevices(std::vector<std::string>* names);
bool GetAudioOutputDevices(std::vector<std::string>* names);
bool GetVideoCaptureDevices(std::vector<std::string>* names);
void SetVideoCaptureDeviceMaxFormat(const std::string& usb_id,
const VideoFormat& max_format);
// Starts AEC dump using existing file.
bool StartAecDump(rtc::PlatformFile file);
sigslot::repeater0<> SignalDevicesChange;
sigslot::signal2<VideoCapturer*, CaptureState> SignalVideoCaptureStateChange;
// Returns the current selected device. Note: Subtly different from
// GetCaptureDevice(). See member video_device_ for more details.
// This API is mainly a hook used by unittests.
const std::string& video_device_name() const { return video_device_name_; }
protected:
// Adds non-transient parameters which can only be changed through the
// options store.
bool SetAudioOptions(const std::string& wave_in_device,
const std::string& wave_out_device,
const AudioOptions& options,
int delay_offset);
bool SetAudioOptions(const AudioOptions& options, int delay_offset);
int audio_delay_offset() const { return audio_delay_offset_; }
// This is here so that ChannelManager subclasses can set the video
// capturer factories to use.
DeviceManagerInterface* device_manager() { return device_manager_.get(); }
private:
typedef std::vector<VoiceChannel*> VoiceChannels;
@ -233,7 +191,6 @@ class ChannelManager : public rtc::MessageHandler,
void Construct(MediaEngineInterface* me,
DataEngineInterface* dme,
DeviceManagerInterface* dm,
CaptureManager* cm,
rtc::Thread* worker_thread);
bool InitMediaEngine_w();
@ -260,7 +217,6 @@ class ChannelManager : public rtc::MessageHandler,
void DestroyDataChannel_w(DataChannel* data_channel);
bool SetAudioOptions_w(const AudioOptions& options, int delay_offset,
const Device* in_dev, const Device* out_dev);
bool SetCaptureDevice_w(const Device* cam_device);
void OnVideoCaptureStateChange(VideoCapturer* capturer,
CaptureState result);
void GetSupportedFormats_w(
@ -271,7 +227,6 @@ class ChannelManager : public rtc::MessageHandler,
rtc::scoped_ptr<MediaEngineInterface> media_engine_;
rtc::scoped_ptr<DataEngineInterface> data_media_engine_;
rtc::scoped_ptr<DeviceManagerInterface> device_manager_;
rtc::scoped_ptr<CaptureManager> capture_manager_;
bool initialized_;
rtc::Thread* main_thread_;
@ -281,25 +236,14 @@ class ChannelManager : public rtc::MessageHandler,
VideoChannels video_channels_;
DataChannels data_channels_;
std::string audio_in_device_;
std::string audio_out_device_;
AudioOptions audio_options_;
int audio_delay_offset_;
int audio_output_volume_;
std::string camera_device_;
VideoEncoderConfig default_video_encoder_config_;
VideoRenderer* local_renderer_;
bool enable_rtx_;
bool capturing_;
// String containing currently set device. Note that this string is subtly
// different from camera_device_. E.g. camera_device_ will list unplugged
// but selected devices while this sting will be empty or contain current
// selected device.
// TODO(hellner): refactor the code such that there is no need to keep two
// strings for video devices that have subtle differences in behavior.
std::string video_device_name_;
};
} // namespace cricket

View File

@ -28,8 +28,8 @@
#include "talk/app/webrtc/mediacontroller.h"
#include "talk/media/base/fakecapturemanager.h"
#include "talk/media/base/fakemediaengine.h"
#include "talk/media/base/fakevideocapturer.h"
#include "talk/media/base/testutils.h"
#include "talk/media/devices/fakedevicemanager.h"
#include "talk/media/webrtc/fakewebrtccall.h"
#include "talk/session/media/channelmanager.h"
#include "webrtc/base/gunit.h"
@ -68,7 +68,6 @@ class ChannelManagerTest : public testing::Test {
: fake_call_(webrtc::Call::Config()),
fake_mc_(&fake_call_),
fme_(NULL),
fdm_(NULL),
fcm_(NULL),
cm_(NULL) {}
@ -77,30 +76,17 @@ class ChannelManagerTest : public testing::Test {
fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs));
fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs));
fdme_ = new cricket::FakeDataEngine();
fdm_ = new cricket::FakeDeviceManager();
fcm_ = new cricket::FakeCaptureManager();
cm_ = new cricket::ChannelManager(
fme_, fdme_, fdm_, fcm_, rtc::Thread::Current());
fme_, fdme_, fcm_, rtc::Thread::Current());
transport_controller_ =
new cricket::FakeTransportController(ICEROLE_CONTROLLING);
std::vector<std::string> in_device_list, out_device_list, vid_device_list;
in_device_list.push_back("audio-in1");
in_device_list.push_back("audio-in2");
out_device_list.push_back("audio-out1");
out_device_list.push_back("audio-out2");
vid_device_list.push_back("video-in1");
vid_device_list.push_back("video-in2");
fdm_->SetAudioInputDevices(in_device_list);
fdm_->SetAudioOutputDevices(out_device_list);
fdm_->SetVideoCaptureDevices(vid_device_list);
}
virtual void TearDown() {
delete transport_controller_;
delete cm_;
cm_ = NULL;
fdm_ = NULL;
fcm_ = NULL;
fdme_ = NULL;
fme_ = NULL;
@ -111,7 +97,6 @@ class ChannelManagerTest : public testing::Test {
cricket::FakeMediaController fake_mc_;
cricket::FakeMediaEngine* fme_;
cricket::FakeDataEngine* fdme_;
cricket::FakeDeviceManager* fdm_;
cricket::FakeCaptureManager* fcm_;
cricket::ChannelManager* cm_;
cricket::FakeTransportController* transport_controller_;
@ -234,31 +219,6 @@ struct GetCapturerFrameSize : public sigslot::has_slots<> {
size_t height;
};
TEST_F(ChannelManagerTest, DefaultCapturerAspectRatio) {
VideoCodec codec(100, "VP8", 640, 360, 30, 0);
VideoFormat format(640, 360, 33, FOURCC_ANY);
VideoEncoderConfig config(codec, 1, 2);
EXPECT_TRUE(cm_->Init());
// A capturer created before the default encoder config is set will have no
// set aspect ratio, so it'll be 4:3 (based on the fake video capture impl).
VideoCapturer* capturer = cm_->CreateVideoCapturer();
ASSERT_TRUE(capturer != NULL);
EXPECT_EQ(CS_RUNNING, capturer->Start(format));
GetCapturerFrameSize size(capturer);
EXPECT_EQ(640u, size.width);
EXPECT_EQ(480u, size.height);
delete capturer;
// Try again, but with the encoder config set to 16:9.
EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config));
capturer = cm_->CreateVideoCapturer();
ASSERT_TRUE(capturer != NULL);
EXPECT_EQ(CS_RUNNING, capturer->Start(format));
GetCapturerFrameSize cropped_size(capturer);
EXPECT_EQ(640u, cropped_size.width);
EXPECT_EQ(360u, cropped_size.height);
delete capturer;
}
// Test that SetDefaultVideoCodec passes through the right values.
TEST_F(ChannelManagerTest, SetDefaultVideoCodecBeforeInit) {
cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0);
@ -268,215 +228,6 @@ TEST_F(ChannelManagerTest, SetDefaultVideoCodecBeforeInit) {
EXPECT_EQ(config, fme_->default_video_encoder_config());
}
TEST_F(ChannelManagerTest, SetAudioOptionsBeforeInit) {
// Test that values that we set before Init are applied.
AudioOptions options;
options.auto_gain_control.Set(true);
options.echo_cancellation.Set(false);
EXPECT_TRUE(cm_->SetAudioOptions("audio-in1", "audio-out1", options));
std::string audio_in, audio_out;
AudioOptions set_options;
// Check options before Init.
EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, &set_options));
EXPECT_EQ("audio-in1", audio_in);
EXPECT_EQ("audio-out1", audio_out);
EXPECT_EQ(options, set_options);
EXPECT_TRUE(cm_->Init());
// Check options after Init.
EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, &set_options));
EXPECT_EQ("audio-in1", audio_in);
EXPECT_EQ("audio-out1", audio_out);
EXPECT_EQ(options, set_options);
// At this point, the media engine should also be initialized.
EXPECT_EQ(options, fme_->audio_options());
EXPECT_EQ(cricket::kDefaultAudioDelayOffset,
fme_->audio_delay_offset());
}
TEST_F(ChannelManagerTest, GetAudioOptionsWithNullParameters) {
std::string audio_in, audio_out;
AudioOptions options;
options.echo_cancellation.Set(true);
EXPECT_TRUE(cm_->SetAudioOptions("audio-in2", "audio-out2", options));
EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, NULL, NULL));
EXPECT_EQ("audio-in2", audio_in);
EXPECT_TRUE(cm_->GetAudioOptions(NULL, &audio_out, NULL));
EXPECT_EQ("audio-out2", audio_out);
AudioOptions out_options;
EXPECT_TRUE(cm_->GetAudioOptions(NULL, NULL, &out_options));
bool echo_cancellation = false;
EXPECT_TRUE(out_options.echo_cancellation.Get(&echo_cancellation));
EXPECT_TRUE(echo_cancellation);
}
TEST_F(ChannelManagerTest, SetAudioOptions) {
// Test initial state.
EXPECT_TRUE(cm_->Init());
EXPECT_EQ(std::string(cricket::DeviceManagerInterface::kDefaultDeviceName),
fme_->audio_in_device());
EXPECT_EQ(std::string(cricket::DeviceManagerInterface::kDefaultDeviceName),
fme_->audio_out_device());
EXPECT_EQ(cricket::kDefaultAudioDelayOffset,
fme_->audio_delay_offset());
// Test setting specific values.
AudioOptions options;
options.auto_gain_control.Set(true);
EXPECT_TRUE(cm_->SetAudioOptions("audio-in1", "audio-out1", options));
EXPECT_EQ("audio-in1", fme_->audio_in_device());
EXPECT_EQ("audio-out1", fme_->audio_out_device());
bool auto_gain_control = false;
EXPECT_TRUE(
fme_->audio_options().auto_gain_control.Get(&auto_gain_control));
EXPECT_TRUE(auto_gain_control);
EXPECT_EQ(cricket::kDefaultAudioDelayOffset,
fme_->audio_delay_offset());
// Test setting bad values.
EXPECT_FALSE(cm_->SetAudioOptions("audio-in9", "audio-out2", options));
}
TEST_F(ChannelManagerTest, SetCaptureDeviceBeforeInit) {
// Test that values that we set before Init are applied.
EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
EXPECT_TRUE(cm_->Init());
EXPECT_EQ("video-in2", cm_->video_device_name());
}
TEST_F(ChannelManagerTest, GetCaptureDeviceBeforeInit) {
std::string video_in;
// Test that GetCaptureDevice works before Init.
EXPECT_TRUE(cm_->SetCaptureDevice("video-in1"));
EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
EXPECT_EQ("video-in1", video_in);
// Test that options set before Init can be gotten after Init.
EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
EXPECT_TRUE(cm_->Init());
EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
EXPECT_EQ("video-in2", video_in);
}
TEST_F(ChannelManagerTest, SetCaptureDevice) {
// Test setting defaults.
EXPECT_TRUE(cm_->Init());
EXPECT_TRUE(cm_->SetCaptureDevice("")); // will use DeviceManager default
EXPECT_EQ("video-in1", cm_->video_device_name());
// Test setting specific values.
EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
EXPECT_EQ("video-in2", cm_->video_device_name());
// TODO(juberti): Add test for invalid value here.
}
// Test unplugging and plugging back the preferred devices. When the preferred
// device is unplugged, we fall back to the default device. When the preferred
// device is plugged back, we use it.
TEST_F(ChannelManagerTest, SetAudioOptionsUnplugPlug) {
// Set preferences "audio-in1" and "audio-out1" before init.
AudioOptions options;
EXPECT_TRUE(cm_->SetAudioOptions("audio-in1", "audio-out1", options));
// Unplug device "audio-in1" and "audio-out1".
std::vector<std::string> in_device_list, out_device_list;
in_device_list.push_back("audio-in2");
out_device_list.push_back("audio-out2");
fdm_->SetAudioInputDevices(in_device_list);
fdm_->SetAudioOutputDevices(out_device_list);
// Init should fall back to default devices.
EXPECT_TRUE(cm_->Init());
// The media engine should use the default.
EXPECT_EQ("", fme_->audio_in_device());
EXPECT_EQ("", fme_->audio_out_device());
// The channel manager keeps the preferences "audio-in1" and "audio-out1".
std::string audio_in, audio_out;
EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, NULL));
EXPECT_EQ("audio-in1", audio_in);
EXPECT_EQ("audio-out1", audio_out);
cm_->Terminate();
// Plug devices "audio-in2" and "audio-out2" back.
in_device_list.push_back("audio-in1");
out_device_list.push_back("audio-out1");
fdm_->SetAudioInputDevices(in_device_list);
fdm_->SetAudioOutputDevices(out_device_list);
// Init again. The preferences, "audio-in2" and "audio-out2", are used.
EXPECT_TRUE(cm_->Init());
EXPECT_EQ("audio-in1", fme_->audio_in_device());
EXPECT_EQ("audio-out1", fme_->audio_out_device());
EXPECT_TRUE(cm_->GetAudioOptions(&audio_in, &audio_out, NULL));
EXPECT_EQ("audio-in1", audio_in);
EXPECT_EQ("audio-out1", audio_out);
}
// We have one camera. Unplug it, fall back to no camera.
TEST_F(ChannelManagerTest, SetCaptureDeviceUnplugPlugOneCamera) {
// Set preferences "video-in1" before init.
std::vector<std::string> vid_device_list;
vid_device_list.push_back("video-in1");
fdm_->SetVideoCaptureDevices(vid_device_list);
EXPECT_TRUE(cm_->SetCaptureDevice("video-in1"));
// Unplug "video-in1".
vid_device_list.clear();
fdm_->SetVideoCaptureDevices(vid_device_list);
// Init should fall back to avatar.
EXPECT_TRUE(cm_->Init());
// The media engine should use no camera.
EXPECT_EQ("", cm_->video_device_name());
// The channel manager keeps the user preference "video-in".
std::string video_in;
EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
EXPECT_EQ("video-in1", video_in);
cm_->Terminate();
// Plug device "video-in1" back.
vid_device_list.push_back("video-in1");
fdm_->SetVideoCaptureDevices(vid_device_list);
// Init again. The user preferred device, "video-in1", is used.
EXPECT_TRUE(cm_->Init());
EXPECT_EQ("video-in1", cm_->video_device_name());
EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
EXPECT_EQ("video-in1", video_in);
}
// We have multiple cameras. Unplug the preferred, fall back to another camera.
TEST_F(ChannelManagerTest, SetCaptureDeviceUnplugPlugTwoDevices) {
// Set video device to "video-in1" before init.
EXPECT_TRUE(cm_->SetCaptureDevice("video-in1"));
// Unplug device "video-in1".
std::vector<std::string> vid_device_list;
vid_device_list.push_back("video-in2");
fdm_->SetVideoCaptureDevices(vid_device_list);
// Init should fall back to default device "video-in2".
EXPECT_TRUE(cm_->Init());
// The media engine should use the default device "video-in2".
EXPECT_EQ("video-in2", cm_->video_device_name());
// The channel manager keeps the user preference "video-in".
std::string video_in;
EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
EXPECT_EQ("video-in1", video_in);
cm_->Terminate();
// Plug device "video-in1" back.
vid_device_list.push_back("video-in1");
fdm_->SetVideoCaptureDevices(vid_device_list);
// Init again. The user preferred device, "video-in1", is used.
EXPECT_TRUE(cm_->Init());
EXPECT_EQ("video-in1", cm_->video_device_name());
EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
EXPECT_EQ("video-in1", video_in);
}
TEST_F(ChannelManagerTest, GetCaptureDevice) {
std::string video_in;
// Test setting/getting defaults.
EXPECT_TRUE(cm_->Init());
EXPECT_TRUE(cm_->SetCaptureDevice(""));
EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
EXPECT_EQ("video-in1", video_in);
// Test setting/getting specific values.
EXPECT_TRUE(cm_->SetCaptureDevice("video-in2"));
EXPECT_TRUE(cm_->GetCaptureDevice(&video_in));
EXPECT_EQ("video-in2", video_in);
}
TEST_F(ChannelManagerTest, GetSetOutputVolumeBeforeInit) {
int level;
// Before init, SetOutputVolume() remembers the volume but does not change the