Thread-safe ChannelManager.GetSupportedFormats, used by VideoSource

VideoSource was using VideoCapturer's GetSupportedFormats in a non-thread safe manner.
Now this is handled to (new method) ChannelManager.GetSupportedFormats.

BUG=
R=perkj@webrtc.org, tommi@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/42079004

Cr-Commit-Position: refs/heads/master@{#8495}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8495 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
hbos@webrtc.org 2015-02-25 09:49:41 +00:00
parent 0a3ff7976b
commit 1e64263b90
3 changed files with 38 additions and 15 deletions

View File

@ -363,21 +363,21 @@ VideoSource::~VideoSource() {
void VideoSource::Initialize(
const webrtc::MediaConstraintsInterface* constraints) {
std::vector<cricket::VideoFormat> formats;
if (video_capturer_->GetSupportedFormats() &&
video_capturer_->GetSupportedFormats()->size() > 0) {
formats = *video_capturer_->GetSupportedFormats();
} else if (video_capturer_->IsScreencast()) {
// The screen capturer can accept any resolution and we will derive the
// format from the constraints if any.
// Note that this only affects tab capturing, not desktop capturing,
// since desktop capturer does not respect the VideoFormat passed in.
formats.push_back(cricket::VideoFormat(kDefaultFormat));
} else {
// The VideoCapturer implementation doesn't support capability enumeration.
// We need to guess what the camera support.
for (int i = 0; i < ARRAY_SIZE(kVideoFormats); ++i) {
formats.push_back(cricket::VideoFormat(kVideoFormats[i]));
std::vector<cricket::VideoFormat> formats =
channel_manager_->GetSupportedFormats(video_capturer_.get());
if (formats.empty()) {
if (video_capturer_->IsScreencast()) {
// The screen capturer can accept any resolution and we will derive the
// format from the constraints if any.
// Note that this only affects tab capturing, not desktop capturing,
// since the desktop capturer does not respect the VideoFormat passed in.
formats.push_back(cricket::VideoFormat(kDefaultFormat));
} else {
// The VideoCapturer implementation doesn't support capability
// enumeration. We need to guess what the camera supports.
for (int i = 0; i < ARRAY_SIZE(kVideoFormats); ++i) {
formats.push_back(cricket::VideoFormat(kVideoFormats[i]));
}
}
}

View File

@ -816,6 +816,23 @@ void ChannelManager::SetVideoLogging(int level, const char* filter) {
}
}
std::vector<cricket::VideoFormat> ChannelManager::GetSupportedFormats(
VideoCapturer* capturer) const {
ASSERT(capturer != NULL);
std::vector<VideoFormat> formats;
worker_thread_->Invoke<void>(rtc::Bind(&ChannelManager::GetSupportedFormats_w,
this, capturer, &formats));
return formats;
}
void ChannelManager::GetSupportedFormats_w(
VideoCapturer* capturer,
std::vector<cricket::VideoFormat>* out_formats) const {
const std::vector<VideoFormat>* formats = capturer->GetSupportedFormats();
if (formats != NULL)
*out_formats = *formats;
}
// TODO(janahan): For now pass this request through the mediaengine to the
// voice and video engines to do the real work. Once the capturer refactoring
// is done, we will access the capturer using the ssrc (similar to how the

View File

@ -183,6 +183,9 @@ class ChannelManager : public rtc::MessageHandler,
void SetVoiceLogging(int level, const char* filter);
void SetVideoLogging(int level, const char* filter);
// Gets capturer's supported formats in a thread safe manner
std::vector<cricket::VideoFormat> GetSupportedFormats(
VideoCapturer* capturer) const;
// The channel manager handles the Tx side for Video processing,
// as well as Tx and Rx side for Voice processing.
// (The Rx Video processing will go throug the simplerenderingmanager,
@ -288,6 +291,9 @@ class ChannelManager : public rtc::MessageHandler,
bool SetCaptureDevice_w(const Device* cam_device);
void OnVideoCaptureStateChange(VideoCapturer* capturer,
CaptureState result);
void GetSupportedFormats_w(
VideoCapturer* capturer,
std::vector<cricket::VideoFormat>* out_formats) const;
bool RegisterVideoProcessor_w(VideoCapturer* capturer,
VideoProcessor* processor);
bool UnregisterVideoProcessor_w(VideoCapturer* capturer,