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 #ifndef CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_VIDEO_SOURCE_H_
      6 #define CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_VIDEO_SOURCE_H_
      7 
      8 #include "content/renderer/media/media_stream_video_source.h"
      9 
     10 namespace content {
     11 
     12 class MockMediaStreamVideoSource : public MediaStreamVideoSource {
     13  public:
     14   explicit MockMediaStreamVideoSource(bool manual_get_supported_formats);
     15   virtual ~MockMediaStreamVideoSource();
     16 
     17   // Simulate that the underlying source start successfully.
     18   void StartMockedSource();
     19 
     20   // Simulate that the underlying source fail to start.
     21   void FailToStartMockedSource();
     22 
     23   // Returns true if StartSource  has been called and StartMockedSource
     24   // or FailToStartMockedSource has not been called.
     25   bool SourceHasAttemptedToStart() { return attempted_to_start_; }
     26 
     27   void SetSupportedFormats(const media::VideoCaptureFormats& formats) {
     28     supported_formats_ = formats;
     29   }
     30 
     31   // Delivers |frame| to all registered tracks on the IO thread. Its up to the
     32   // call to make sure MockMediaStreamVideoSource is not destroyed before the
     33   // frame has been delivered.
     34   void DeliverVideoFrame(const scoped_refptr<media::VideoFrame>& frame);
     35 
     36   void CompleteGetSupportedFormats();
     37 
     38   const media::VideoCaptureParams& start_params() const { return params_; }
     39   int max_requested_height() const { return max_requested_height_; }
     40   int max_requested_width() const { return max_requested_width_; }
     41 
     42  protected:
     43   void DeliverVideoFrameOnIO(const scoped_refptr<media::VideoFrame>& frame,
     44                              media::VideoCaptureFormat format,
     45                              const base::TimeTicks& estimated_capture_time,
     46                              const VideoCaptureDeliverFrameCB& frame_callback);
     47 
     48   // Implements MediaStreamVideoSource.
     49   virtual void GetCurrentSupportedFormats(
     50       int max_requested_height,
     51       int max_requested_width,
     52       const VideoCaptureDeviceFormatsCB& callback) OVERRIDE;
     53   virtual void StartSourceImpl(
     54       const media::VideoCaptureParams& params,
     55       const VideoCaptureDeliverFrameCB& frame_callback) OVERRIDE;
     56   virtual void StopSourceImpl() OVERRIDE;
     57 
     58  private:
     59   media::VideoCaptureParams params_;
     60   media::VideoCaptureFormats supported_formats_;
     61   bool manual_get_supported_formats_;
     62   int max_requested_height_;
     63   int max_requested_width_;
     64   bool attempted_to_start_;
     65   VideoCaptureDeviceFormatsCB formats_callback_;
     66   VideoCaptureDeliverFrameCB frame_callback_;
     67 
     68   DISALLOW_COPY_AND_ASSIGN(MockMediaStreamVideoSource);
     69 };
     70 
     71 }  // namespace content
     72 
     73 #endif  // CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_VIDEO_SOURCE_H_
     74