| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/media/mock_media_stream_video_source.h" | 5 #include "content/renderer/media/mock_media_stream_video_source.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 | 12 |
| 13 MockMediaStreamVideoSource::MockMediaStreamVideoSource( | 13 MockMediaStreamVideoSource::MockMediaStreamVideoSource() |
| 14 bool manual_get_supported_formats) | 14 : MockMediaStreamVideoSource(false) {} |
| 15 : MockMediaStreamVideoSource(manual_get_supported_formats, false) {} | |
| 16 | 15 |
| 17 MockMediaStreamVideoSource::MockMediaStreamVideoSource( | 16 MockMediaStreamVideoSource::MockMediaStreamVideoSource( |
| 18 bool manual_get_supported_formats, | |
| 19 bool respond_to_request_refresh_frame) | 17 bool respond_to_request_refresh_frame) |
| 20 : manual_get_supported_formats_(manual_get_supported_formats), | 18 : respond_to_request_refresh_frame_(respond_to_request_refresh_frame), |
| 21 respond_to_request_refresh_frame_(respond_to_request_refresh_frame), | |
| 22 max_requested_height_(0), | 19 max_requested_height_(0), |
| 23 max_requested_width_(0), | 20 max_requested_width_(0), |
| 24 max_requested_frame_rate_(0.0), | 21 max_requested_frame_rate_(0.0), |
| 25 attempted_to_start_(false) { | 22 attempted_to_start_(false) {} |
| 26 supported_formats_.push_back(media::VideoCaptureFormat( | |
| 27 gfx::Size(MediaStreamVideoSource::kDefaultWidth, | |
| 28 MediaStreamVideoSource::kDefaultHeight), | |
| 29 MediaStreamVideoSource::kDefaultFrameRate, media::PIXEL_FORMAT_I420)); | |
| 30 } | |
| 31 | 23 |
| 32 MockMediaStreamVideoSource::MockMediaStreamVideoSource( | 24 MockMediaStreamVideoSource::MockMediaStreamVideoSource( |
| 33 const media::VideoCaptureFormat& format, | 25 const media::VideoCaptureFormat& format, |
| 34 bool respond_to_request_refresh_frame) | 26 bool respond_to_request_refresh_frame) |
| 35 : format_(format), | 27 : format_(format), |
| 36 manual_get_supported_formats_(false), | |
| 37 respond_to_request_refresh_frame_(respond_to_request_refresh_frame), | 28 respond_to_request_refresh_frame_(respond_to_request_refresh_frame), |
| 38 max_requested_height_(format.frame_size.height()), | 29 max_requested_height_(format.frame_size.height()), |
| 39 max_requested_width_(format.frame_size.width()), | 30 max_requested_width_(format.frame_size.width()), |
| 40 max_requested_frame_rate_(format.frame_rate), | 31 max_requested_frame_rate_(format.frame_rate), |
| 41 attempted_to_start_(false) {} | 32 attempted_to_start_(false) {} |
| 42 | 33 |
| 43 MockMediaStreamVideoSource::~MockMediaStreamVideoSource() {} | 34 MockMediaStreamVideoSource::~MockMediaStreamVideoSource() {} |
| 44 | 35 |
| 45 void MockMediaStreamVideoSource::StartMockedSource() { | 36 void MockMediaStreamVideoSource::StartMockedSource() { |
| 46 DCHECK(attempted_to_start_); | 37 DCHECK(attempted_to_start_); |
| 47 attempted_to_start_ = false; | 38 attempted_to_start_ = false; |
| 48 OnStartDone(MEDIA_DEVICE_OK); | 39 OnStartDone(MEDIA_DEVICE_OK); |
| 49 } | 40 } |
| 50 | 41 |
| 51 void MockMediaStreamVideoSource::FailToStartMockedSource() { | 42 void MockMediaStreamVideoSource::FailToStartMockedSource() { |
| 52 DCHECK(attempted_to_start_); | 43 DCHECK(attempted_to_start_); |
| 53 attempted_to_start_ = false; | 44 attempted_to_start_ = false; |
| 54 OnStartDone(MEDIA_DEVICE_TRACK_START_FAILURE); | 45 OnStartDone(MEDIA_DEVICE_TRACK_START_FAILURE); |
| 55 } | 46 } |
| 56 | 47 |
| 57 void MockMediaStreamVideoSource::CompleteGetSupportedFormats() { | |
| 58 DCHECK(!formats_callback_.is_null()); | |
| 59 base::ResetAndReturn(&formats_callback_).Run(supported_formats_); | |
| 60 } | |
| 61 | |
| 62 void MockMediaStreamVideoSource::RequestRefreshFrame() { | 48 void MockMediaStreamVideoSource::RequestRefreshFrame() { |
| 63 DCHECK(!frame_callback_.is_null()); | 49 DCHECK(!frame_callback_.is_null()); |
| 64 if (respond_to_request_refresh_frame_) { | 50 if (respond_to_request_refresh_frame_) { |
| 65 const scoped_refptr<media::VideoFrame> frame = | 51 const scoped_refptr<media::VideoFrame> frame = |
| 66 media::VideoFrame::CreateColorFrame(format_.frame_size, 0, 0, 0, | 52 media::VideoFrame::CreateColorFrame(format_.frame_size, 0, 0, 0, |
| 67 base::TimeDelta()); | 53 base::TimeDelta()); |
| 68 io_task_runner()->PostTask( | 54 io_task_runner()->PostTask( |
| 69 FROM_HERE, base::Bind(frame_callback_, frame, base::TimeTicks())); | 55 FROM_HERE, base::Bind(frame_callback_, frame, base::TimeTicks())); |
| 70 } | 56 } |
| 71 } | 57 } |
| 72 | 58 |
| 73 void MockMediaStreamVideoSource::GetCurrentSupportedFormats( | |
| 74 int max_requested_height, | |
| 75 int max_requested_width, | |
| 76 double max_requested_frame_rate, | |
| 77 const VideoCaptureDeviceFormatsCB& callback) { | |
| 78 DCHECK(formats_callback_.is_null()); | |
| 79 max_requested_height_ = max_requested_height; | |
| 80 max_requested_width_ = max_requested_width; | |
| 81 max_requested_frame_rate_ = max_requested_frame_rate; | |
| 82 | |
| 83 if (manual_get_supported_formats_) { | |
| 84 formats_callback_ = callback; | |
| 85 return; | |
| 86 } | |
| 87 callback.Run(supported_formats_); | |
| 88 } | |
| 89 | |
| 90 void MockMediaStreamVideoSource::StartSourceImpl( | 59 void MockMediaStreamVideoSource::StartSourceImpl( |
| 91 const media::VideoCaptureFormat& format, | 60 const media::VideoCaptureFormat& format, |
| 92 const blink::WebMediaConstraints& constraints, | 61 const blink::WebMediaConstraints& constraints, |
| 93 const VideoCaptureDeliverFrameCB& frame_callback) { | 62 const VideoCaptureDeliverFrameCB& frame_callback) { |
| 94 DCHECK(frame_callback_.is_null()); | 63 DCHECK(frame_callback_.is_null()); |
| 95 attempted_to_start_ = true; | 64 attempted_to_start_ = true; |
| 96 frame_callback_ = frame_callback; | 65 frame_callback_ = frame_callback; |
| 97 } | 66 } |
| 98 | 67 |
| 99 void MockMediaStreamVideoSource::StopSourceImpl() { | 68 void MockMediaStreamVideoSource::StopSourceImpl() { |
| 100 } | 69 } |
| 101 | 70 |
| 102 base::Optional<media::VideoCaptureFormat> | 71 base::Optional<media::VideoCaptureFormat> |
| 103 MockMediaStreamVideoSource::GetCurrentFormatImpl() const { | 72 MockMediaStreamVideoSource::GetCurrentFormatImpl() const { |
| 104 return base::Optional<media::VideoCaptureFormat>(format_); | 73 return base::Optional<media::VideoCaptureFormat>(format_); |
| 105 } | 74 } |
| 106 | 75 |
| 107 void MockMediaStreamVideoSource::DeliverVideoFrame( | 76 void MockMediaStreamVideoSource::DeliverVideoFrame( |
| 108 const scoped_refptr<media::VideoFrame>& frame) { | 77 const scoped_refptr<media::VideoFrame>& frame) { |
| 109 DCHECK(!frame_callback_.is_null()); | 78 DCHECK(!frame_callback_.is_null()); |
| 110 io_task_runner()->PostTask( | 79 io_task_runner()->PostTask( |
| 111 FROM_HERE, base::Bind(frame_callback_, frame, base::TimeTicks())); | 80 FROM_HERE, base::Bind(frame_callback_, frame, base::TimeTicks())); |
| 112 } | 81 } |
| 113 | 82 |
| 114 } // namespace content | 83 } // namespace content |
| OLD | NEW |