diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-02 05:03:49 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-02 05:03:49 +0000 |
commit | 570085f735b5c22f35001c922dbab5e55d7de3d4 (patch) | |
tree | f9db7f72861e337116d0abb97c4fe64f91f5c81f /media/video | |
parent | 833f9d48636f001c456821a8320015260abc213f (diff) | |
download | chromium_src-570085f735b5c22f35001c922dbab5e55d7de3d4.zip chromium_src-570085f735b5c22f35001c922dbab5e55d7de3d4.tar.gz chromium_src-570085f735b5c22f35001c922dbab5e55d7de3d4.tar.bz2 |
Implement audio/video sync instrumentation for WebRTC
Draw a sweeping circle animation and elapsed time in the fake
video stream. Combined with a synchronized beep sound in the fake
audio stream.
Tested local-to-local PeerConnection to show that audio/video are
in sync.
BUG=159053
Review URL: https://chromiumcodereview.appspot.com/11358018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165619 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/video')
-rw-r--r-- | media/video/capture/fake_video_capture_device.cc | 66 | ||||
-rw-r--r-- | media/video/capture/fake_video_capture_device.h | 2 |
2 files changed, 58 insertions, 10 deletions
diff --git a/media/video/capture/fake_video_capture_device.cc b/media/video/capture/fake_video_capture_device.cc index 77afe8e..b137192 100644 --- a/media/video/capture/fake_video_capture_device.cc +++ b/media/video/capture/fake_video_capture_device.cc @@ -9,6 +9,10 @@ #include "base/bind.h" #include "base/memory/scoped_ptr.h" #include "base/stringprintf.h" +#include "media/audio/fake_audio_input_stream.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "third_party/skia/include/core/SkCanvas.h" +#include "third_party/skia/include/core/SkPaint.h" namespace media { @@ -54,7 +58,9 @@ FakeVideoCaptureDevice::FakeVideoCaptureDevice(const Name& device_name) state_(kIdle), capture_thread_("CaptureThread"), frame_size_(0), - frame_count_(0) { + frame_count_(0), + frame_width_(0), + frame_height_(0) { } FakeVideoCaptureDevice::~FakeVideoCaptureDevice() { @@ -91,6 +97,8 @@ void FakeVideoCaptureDevice::Allocate(int width, fake_frame_.reset(new uint8[fake_frame_size]); memset(fake_frame_.get(), 0, fake_frame_size); frame_size_ = fake_frame_size; + frame_width_ = current_settings.width; + frame_height_ = current_settings.height; state_ = kAllocated; observer_->OnFrameInfo(current_settings); @@ -133,12 +141,54 @@ void FakeVideoCaptureDevice::OnCaptureTask() { return; } - bool beep = false; + memset(fake_frame_.get(), 0, frame_size_); + + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kA8_Config, frame_width_, frame_height_, + frame_width_); + bitmap.setPixels(fake_frame_.get()); + + SkCanvas canvas(bitmap); + + // Draw a sweeping circle to show an animation. + int radius = std::min(frame_width_, frame_height_) / 4; + SkRect rect = SkRect::MakeXYWH( + frame_width_ / 2 - radius, frame_height_ / 2 - radius, + 2 * radius, 2 * radius); + + SkPaint paint; + paint.setStyle(SkPaint::kFill_Style); + + // Only Y plane is being drawn and this gives 50% grey on the Y + // plane. The result is a light green color in RGB space. + paint.setAlpha(128); + + int end_angle = (frame_count_ % kFakeCaptureBeepCycle * 360) / + kFakeCaptureBeepCycle; + if (!end_angle) + end_angle = 360; + canvas.drawArc(rect, 0, end_angle, true, paint); + + // Draw current time. + int elapsed_ms = kFakeCaptureTimeoutMs * frame_count_; + int milliseconds = elapsed_ms % 1000; + int seconds = (elapsed_ms / 1000) % 60; + int minutes = (elapsed_ms / 1000 / 60) % 60; + int hours = (elapsed_ms / 1000 / 60 / 60) % 60; + + std::string time_string = + base::StringPrintf("%d:%02d:%02d:%03d %d", hours, minutes, + seconds, milliseconds, frame_count_); + canvas.scale(3, 3); + canvas.drawText(time_string.data(), time_string.length(), 30, 20, + paint); + if (frame_count_ % kFakeCaptureBeepCycle == 0) { - beep = true; - // This will fill the frame in grey. - memset(fake_frame_.get(), 128, frame_size_); - } + // Generate a synchronized beep sound if there is one audio input + // stream created. + FakeAudioInputStream::BeepOnce(); + } + frame_count_++; // Give the captured frame to the observer. @@ -151,10 +201,6 @@ void FakeVideoCaptureDevice::OnCaptureTask() { base::Bind(&FakeVideoCaptureDevice::OnCaptureTask, base::Unretained(this)), base::TimeDelta::FromMilliseconds(kFakeCaptureTimeoutMs)); - - if (beep) { - memset(fake_frame_.get(), 0, frame_size_); - } } } // namespace media diff --git a/media/video/capture/fake_video_capture_device.h b/media/video/capture/fake_video_capture_device.h index 082bc0e..7350982 100644 --- a/media/video/capture/fake_video_capture_device.h +++ b/media/video/capture/fake_video_capture_device.h @@ -56,6 +56,8 @@ class MEDIA_EXPORT FakeVideoCaptureDevice : public VideoCaptureDevice { int frame_size_; scoped_array<uint8> fake_frame_; int frame_count_; + int frame_width_; + int frame_height_; static bool fail_next_create_; |