Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / content / renderer / media / mock_media_stream_video_source.cc
blobe6c0a7f1d5ac7689f809e72c6bd146a2a80a40f7
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/media/mock_media_stream_video_source.h"
7 #include "base/bind.h"
8 #include "base/callback_helpers.h"
9 #include "base/location.h"
11 namespace content {
13 MockMediaStreamVideoSource::MockMediaStreamVideoSource(
14 bool manual_get_supported_formats)
15 : manual_get_supported_formats_(manual_get_supported_formats),
16 max_requested_height_(0),
17 max_requested_width_(0),
18 max_requested_frame_rate_(0.0),
19 attempted_to_start_(false) {
20 supported_formats_.push_back(media::VideoCaptureFormat(
21 gfx::Size(MediaStreamVideoSource::kDefaultWidth,
22 MediaStreamVideoSource::kDefaultHeight),
23 MediaStreamVideoSource::kDefaultFrameRate,
24 media::VIDEO_CAPTURE_PIXEL_FORMAT_I420));
27 MockMediaStreamVideoSource::~MockMediaStreamVideoSource() {}
29 void MockMediaStreamVideoSource::StartMockedSource() {
30 DCHECK(attempted_to_start_);
31 attempted_to_start_ = false;
32 OnStartDone(MEDIA_DEVICE_OK);
35 void MockMediaStreamVideoSource::FailToStartMockedSource() {
36 DCHECK(attempted_to_start_);
37 attempted_to_start_ = false;
38 OnStartDone(MEDIA_DEVICE_TRACK_START_FAILURE);
41 void MockMediaStreamVideoSource::CompleteGetSupportedFormats() {
42 DCHECK(!formats_callback_.is_null());
43 base::ResetAndReturn(&formats_callback_).Run(supported_formats_);
46 void MockMediaStreamVideoSource::GetCurrentSupportedFormats(
47 int max_requested_height,
48 int max_requested_width,
49 double max_requested_frame_rate,
50 const VideoCaptureDeviceFormatsCB& callback) {
51 DCHECK(formats_callback_.is_null());
52 max_requested_height_ = max_requested_height;
53 max_requested_width_ = max_requested_width;
54 max_requested_frame_rate_ = max_requested_frame_rate;
56 if (manual_get_supported_formats_) {
57 formats_callback_ = callback;
58 return;
60 callback.Run(supported_formats_);
63 void MockMediaStreamVideoSource::StartSourceImpl(
64 const media::VideoCaptureFormat& format,
65 const blink::WebMediaConstraints& constraints,
66 const VideoCaptureDeliverFrameCB& frame_callback) {
67 DCHECK(frame_callback_.is_null());
68 format_ = format;
69 attempted_to_start_ = true;
70 frame_callback_ = frame_callback;
73 void MockMediaStreamVideoSource::StopSourceImpl() {
76 void MockMediaStreamVideoSource::DeliverVideoFrame(
77 const scoped_refptr<media::VideoFrame>& frame) {
78 DCHECK(!frame_callback_.is_null());
79 io_task_runner()->PostTask(
80 FROM_HERE, base::Bind(frame_callback_, frame, base::TimeTicks()));
83 } // namespace content