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"
8 #include "base/callback_helpers.h"
9 #include "base/location.h"
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 attempted_to_start_(false) {
19 supported_formats_
.push_back(
20 media::VideoCaptureFormat(
21 gfx::Size(MediaStreamVideoSource::kDefaultWidth
,
22 MediaStreamVideoSource::kDefaultHeight
),
23 MediaStreamVideoSource::kDefaultFrameRate
,
24 media::PIXEL_FORMAT_I420
));
27 MockMediaStreamVideoSource::~MockMediaStreamVideoSource() {}
29 void MockMediaStreamVideoSource::StartMockedSource() {
30 DCHECK(attempted_to_start_
);
31 attempted_to_start_
= false;
35 void MockMediaStreamVideoSource::FailToStartMockedSource() {
36 DCHECK(attempted_to_start_
);
37 attempted_to_start_
= false;
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 const VideoCaptureDeviceFormatsCB
& callback
) {
50 DCHECK(formats_callback_
.is_null());
51 max_requested_height_
= max_requested_height
;
52 max_requested_width_
= max_requested_width
;
54 if (manual_get_supported_formats_
) {
55 formats_callback_
= callback
;
58 callback
.Run(supported_formats_
);
61 void MockMediaStreamVideoSource::StartSourceImpl(
62 const media::VideoCaptureParams
& params
,
63 const VideoCaptureDeliverFrameCB
& frame_callback
) {
64 DCHECK(frame_callback_
.is_null());
66 attempted_to_start_
= true;
67 frame_callback_
= frame_callback
;
70 void MockMediaStreamVideoSource::StopSourceImpl() {
73 void MockMediaStreamVideoSource::DeliverVideoFrame(
74 const scoped_refptr
<media::VideoFrame
>& frame
) {
75 DCHECK(!frame_callback_
.is_null());
76 io_message_loop()->PostTask(
78 base::Bind(&MockMediaStreamVideoSource::DeliverVideoFrameOnIO
,
79 base::Unretained(this), frame
, params_
.requested_format
,
80 base::TimeTicks(), frame_callback_
));
83 void MockMediaStreamVideoSource::DeliverVideoFrameOnIO(
84 const scoped_refptr
<media::VideoFrame
>& frame
,
85 media::VideoCaptureFormat format
,
86 const base::TimeTicks
& estimated_capture_time
,
87 const VideoCaptureDeliverFrameCB
& frame_callback
) {
88 frame_callback
.Run(frame
, format
, estimated_capture_time
);
91 } // namespace content