Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / renderer / media / mock_media_stream_video_source.h
blob0ae75074e0162055ea63b2890ca09bbf86884762
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 #ifndef CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_VIDEO_SOURCE_H_
6 #define CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_VIDEO_SOURCE_H_
8 #include "content/renderer/media/media_stream_video_source.h"
10 #include "testing/gmock/include/gmock/gmock.h"
12 namespace content {
14 class MockMediaStreamVideoSource : public MediaStreamVideoSource {
15 public:
16 explicit MockMediaStreamVideoSource(bool manual_get_supported_formats);
17 virtual ~MockMediaStreamVideoSource();
19 MOCK_METHOD1(DoSetMutedState, void(bool muted_state));
21 // Simulate that the underlying source start successfully.
22 void StartMockedSource();
24 // Simulate that the underlying source fail to start.
25 void FailToStartMockedSource();
27 // Returns true if StartSource has been called and StartMockedSource
28 // or FailToStartMockedSource has not been called.
29 bool SourceHasAttemptedToStart() { return attempted_to_start_; }
31 void SetSupportedFormats(const media::VideoCaptureFormats& formats) {
32 supported_formats_ = formats;
35 // Delivers |frame| to all registered tracks on the IO thread. Its up to the
36 // call to make sure MockMediaStreamVideoSource is not destroyed before the
37 // frame has been delivered.
38 void DeliverVideoFrame(const scoped_refptr<media::VideoFrame>& frame);
40 void CompleteGetSupportedFormats();
42 const media::VideoCaptureFormat& start_format() const { return format_; }
43 int max_requested_height() const { return max_requested_height_; }
44 int max_requested_width() const { return max_requested_width_; }
45 double max_requested_frame_rate() const { return max_requested_frame_rate_; }
47 virtual void SetMutedState(bool muted_state) override {
48 MediaStreamVideoSource::SetMutedState(muted_state);
49 DoSetMutedState(muted_state);
52 protected:
53 // Implements MediaStreamVideoSource.
54 virtual void GetCurrentSupportedFormats(
55 int max_requested_height,
56 int max_requested_width,
57 double max_requested_frame_rate,
58 const VideoCaptureDeviceFormatsCB& callback) override;
59 virtual void StartSourceImpl(
60 const media::VideoCaptureFormat& format,
61 const VideoCaptureDeliverFrameCB& frame_callback) override;
62 virtual void StopSourceImpl() override;
64 private:
65 media::VideoCaptureFormat format_;
66 media::VideoCaptureFormats supported_formats_;
67 bool manual_get_supported_formats_;
68 int max_requested_height_;
69 int max_requested_width_;
70 double max_requested_frame_rate_;
71 bool attempted_to_start_;
72 VideoCaptureDeviceFormatsCB formats_callback_;
73 VideoCaptureDeliverFrameCB frame_callback_;
75 DISALLOW_COPY_AND_ASSIGN(MockMediaStreamVideoSource);
78 } // namespace content
80 #endif // CONTENT_RENDERER_MEDIA_MOCK_MEDIA_STREAM_VIDEO_SOURCE_H_