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_
10 #include "base/compiler_specific.h"
11 #include "base/threading/thread_checker.h"
12 #include "content/common/content_export.h"
13 #include "media/base/video_capture_types.h"
14 #include "media/base/video_frame.h"
15 #include "third_party/libjingle/source/talk/media/base/videocapturer.h"
19 // WebRtcVideoCapturerAdapter implements a simple cricket::VideoCapturer that is
20 // used for VideoCapturing in libJingle and especially in PeerConnections.
21 // The class is created and destroyed on the main render thread.
22 // PeerConnection access cricket::VideoCapturer from a libJingle worker thread.
23 // An instance of WebRtcVideoCapturerAdapter is owned by an instance of
24 // webrtc::VideoSourceInterface in libJingle. The implementation of
25 // webrtc::VideoSourceInterface guarantees that this object is not deleted
26 // while it is still used in libJingle.
27 class CONTENT_EXPORT WebRtcVideoCapturerAdapter
28 : NON_EXPORTED_BASE(public cricket::VideoCapturer
) {
30 explicit WebRtcVideoCapturerAdapter(bool is_screencast
);
31 ~WebRtcVideoCapturerAdapter() override
;
33 // OnFrameCaptured delivers video frames to libjingle. It must be called on
34 // libjingles worker thread.
35 // This method is virtual for testing purposes.
36 virtual void OnFrameCaptured(const scoped_refptr
<media::VideoFrame
>& frame
);
39 // cricket::VideoCapturer implementation.
40 // These methods are accessed from a libJingle worker thread.
41 cricket::CaptureState
Start(
42 const cricket::VideoFormat
& capture_format
) override
;
44 bool IsRunning() override
;
45 bool GetPreferredFourccs(std::vector
<uint32
>* fourccs
) override
;
46 bool GetBestCaptureFormat(const cricket::VideoFormat
& desired
,
47 cricket::VideoFormat
* best_format
) override
;
48 bool IsScreencast() const override
;
50 // |thread_checker_| is bound to the libjingle worker thread.
51 base::ThreadChecker thread_checker_
;
53 const bool is_screencast_
;
55 base::TimeDelta first_frame_timestamp_
;
57 class MediaVideoFrameFactory
;
59 DISALLOW_COPY_AND_ASSIGN(WebRtcVideoCapturerAdapter
);
62 } // namespace content
64 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_VIDEO_CAPTURER_ADAPTER_H_