Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / renderer / media / webrtc / webrtc_video_capturer_adapter.h
blob847dc74920c210dc245887f140e86cb1583c6a69
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_WEBRTC_WEBRTC_VIDEO_CAPTURER_ADAPTER_H_
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_VIDEO_CAPTURER_ADAPTER_H_
8 #include <vector>
10 #include "base/compiler_specific.h"
11 #include "base/message_loop/message_loop_proxy.h"
12 #include "base/threading/thread_checker.h"
13 #include "content/common/content_export.h"
14 #include "media/base/video_capture_types.h"
15 #include "media/base/video_frame.h"
16 #include "third_party/libjingle/source/talk/media/base/videocapturer.h"
18 namespace content {
20 // WebRtcVideoCapturerAdapter implements a simple cricket::VideoCapturer that is
21 // used for VideoCapturing in libJingle and especially in PeerConnections.
22 // The class is created and destroyed on the main render thread.
23 // PeerConnection access cricket::VideoCapturer from a libJingle worker thread.
24 // An instance of WebRtcVideoCapturerAdapter is owned by an instance of
25 // webrtc::VideoSourceInterface in libJingle. The implementation of
26 // webrtc::VideoSourceInterface guarantees that this object is not deleted
27 // while it is still used in libJingle.
28 class CONTENT_EXPORT WebRtcVideoCapturerAdapter
29 : NON_EXPORTED_BASE(public cricket::VideoCapturer) {
30 public:
31 explicit WebRtcVideoCapturerAdapter(bool is_screencast);
32 ~WebRtcVideoCapturerAdapter() override;
34 // OnFrameCaptured delivers video frames to libjingle. It must be called on
35 // libjingles worker thread.
36 // This method is virtual for testing purposes.
37 virtual void OnFrameCaptured(const scoped_refptr<media::VideoFrame>& frame);
39 private:
40 // cricket::VideoCapturer implementation.
41 // These methods are accessed from a libJingle worker thread.
42 cricket::CaptureState Start(
43 const cricket::VideoFormat& capture_format) override;
44 void Stop() override;
45 bool IsRunning() override;
46 bool GetPreferredFourccs(std::vector<uint32>* fourccs) override;
47 bool GetBestCaptureFormat(const cricket::VideoFormat& desired,
48 cricket::VideoFormat* best_format) override;
49 bool IsScreencast() const override;
51 // |thread_checker_| is bound to the libjingle worker thread.
52 base::ThreadChecker thread_checker_;
54 const bool is_screencast_;
55 bool running_;
56 base::TimeDelta first_frame_timestamp_;
58 // This is an alias to the frame_factory_ in the base class
59 // cricket::VideoCapturer.
60 class MediaVideoFrameFactory;
61 MediaVideoFrameFactory* frame_factory_;
63 DISALLOW_COPY_AND_ASSIGN(WebRtcVideoCapturerAdapter);
66 } // namespace content
68 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_VIDEO_CAPTURER_ADAPTER_H_