Home | History | Annotate | Download | only in media
      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.
      4 
      5 #include "content/renderer/media/mock_media_stream_video_source.h"
      6 
      7 #include "base/bind.h"
      8 #include "base/callback_helpers.h"
      9 #include "base/location.h"
     10 
     11 namespace content {
     12 
     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));
     25 }
     26 
     27 MockMediaStreamVideoSource::~MockMediaStreamVideoSource() {}
     28 
     29 void MockMediaStreamVideoSource::StartMockedSource() {
     30   DCHECK(attempted_to_start_);
     31   attempted_to_start_ = false;
     32   OnStartDone(true);
     33 }
     34 
     35 void MockMediaStreamVideoSource::FailToStartMockedSource() {
     36   DCHECK(attempted_to_start_);
     37   attempted_to_start_ = false;
     38   OnStartDone(false);
     39 }
     40 
     41 void MockMediaStreamVideoSource::CompleteGetSupportedFormats() {
     42   DCHECK(!formats_callback_.is_null());
     43   base::ResetAndReturn(&formats_callback_).Run(supported_formats_);
     44 }
     45 
     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;
     53 
     54   if (manual_get_supported_formats_) {
     55     formats_callback_ = callback;
     56     return;
     57   }
     58   callback.Run(supported_formats_);
     59 }
     60 
     61 void MockMediaStreamVideoSource::StartSourceImpl(
     62     const media::VideoCaptureParams& params,
     63     const VideoCaptureDeliverFrameCB& frame_callback) {
     64   DCHECK(frame_callback_.is_null());
     65   params_ = params;
     66   attempted_to_start_ = true;
     67   frame_callback_ = frame_callback;
     68 }
     69 
     70 void MockMediaStreamVideoSource::StopSourceImpl() {
     71 }
     72 
     73 void MockMediaStreamVideoSource::DeliverVideoFrame(
     74     const scoped_refptr<media::VideoFrame>& frame) {
     75   DCHECK(!frame_callback_.is_null());
     76   io_message_loop()->PostTask(
     77       FROM_HERE,
     78       base::Bind(&MockMediaStreamVideoSource::DeliverVideoFrameOnIO,
     79                  base::Unretained(this), frame, params_.requested_format,
     80                  base::TimeTicks(), frame_callback_));
     81 }
     82 
     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);
     89 }
     90 
     91 }  // namespace content
     92