jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 9 | */ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 10 | |
kjellander@webrtc.org | 5ad1297 | 2016-02-12 06:39:40 +0100 | [diff] [blame] | 11 | #ifndef WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOCAPTURER_H_ |
| 12 | #define WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOCAPTURER_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 14 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
solenberg | 8ad582d | 2016-03-16 09:34:56 -0700 | [diff] [blame] | 19 | #include "webrtc/media/base/device.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 20 | #include "webrtc/media/base/videocapturer.h" |
Henrik Kjellander | 5dda80a | 2015-11-12 12:46:09 +0100 | [diff] [blame] | 21 | #include "webrtc/modules/video_capture/video_capture.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 22 | #include "webrtc/rtc_base/asyncinvoker.h" |
| 23 | #include "webrtc/rtc_base/messagehandler.h" |
| 24 | #include "webrtc/rtc_base/scoped_ref_ptr.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 25 | |
| 26 | namespace cricket { |
| 27 | |
| 28 | // Factory to allow injection of a VCM impl into WebRtcVideoCapturer. |
| 29 | // DeviceInfos do not have a Release() and therefore need an explicit Destroy(). |
| 30 | class WebRtcVcmFactoryInterface { |
| 31 | public: |
| 32 | virtual ~WebRtcVcmFactoryInterface() {} |
Peter Boström | 09c3a1e | 2016-03-22 17:17:39 +0100 | [diff] [blame] | 33 | virtual rtc::scoped_refptr<webrtc::VideoCaptureModule> Create( |
Peter Boström | 09c3a1e | 2016-03-22 17:17:39 +0100 | [diff] [blame] | 34 | const char* device) = 0; |
nisse | b29b9c8 | 2016-12-12 00:22:56 -0800 | [diff] [blame] | 35 | virtual webrtc::VideoCaptureModule::DeviceInfo* CreateDeviceInfo() = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 36 | virtual void DestroyDeviceInfo( |
| 37 | webrtc::VideoCaptureModule::DeviceInfo* info) = 0; |
| 38 | }; |
| 39 | |
| 40 | // WebRTC-based implementation of VideoCapturer. |
| 41 | class WebRtcVideoCapturer : public VideoCapturer, |
nisse | b29b9c8 | 2016-12-12 00:22:56 -0800 | [diff] [blame] | 42 | public rtc::VideoSinkInterface<webrtc::VideoFrame> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 43 | public: |
| 44 | WebRtcVideoCapturer(); |
| 45 | explicit WebRtcVideoCapturer(WebRtcVcmFactoryInterface* factory); |
| 46 | virtual ~WebRtcVideoCapturer(); |
| 47 | |
| 48 | bool Init(const Device& device); |
Peter Boström | 09c3a1e | 2016-03-22 17:17:39 +0100 | [diff] [blame] | 49 | bool Init(const rtc::scoped_refptr<webrtc::VideoCaptureModule>& module); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 50 | |
| 51 | // Override virtual methods of the parent class VideoCapturer. |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 52 | bool GetBestCaptureFormat(const VideoFormat& desired, |
| 53 | VideoFormat* best_format) override; |
| 54 | CaptureState Start(const VideoFormat& capture_format) override; |
| 55 | void Stop() override; |
| 56 | bool IsRunning() override; |
| 57 | bool IsScreencast() const override { return false; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 58 | |
| 59 | protected: |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 60 | void OnSinkWantsChanged(const rtc::VideoSinkWants& wants) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 61 | // Override virtual methods of the parent class VideoCapturer. |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 62 | bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 63 | |
| 64 | private: |
| 65 | // Callback when a frame is captured by camera. |
nisse | b29b9c8 | 2016-12-12 00:22:56 -0800 | [diff] [blame] | 66 | void OnFrame(const webrtc::VideoFrame& frame) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 67 | |
tommi@webrtc.org | e07710c | 2015-02-19 17:43:25 +0000 | [diff] [blame] | 68 | // Used to signal captured frames on the same thread as invoked Start(). |
| 69 | // With WebRTC's current VideoCapturer implementations, this will mean a |
| 70 | // thread hop, but in other implementations (e.g. Chrome) it will be called |
| 71 | // directly from OnIncomingCapturedFrame. |
| 72 | // TODO(tommi): Remove this workaround when we've updated the WebRTC capturers |
| 73 | // to follow the same contract. |
noahric | 5d9b92b | 2015-10-24 11:14:46 -0700 | [diff] [blame] | 74 | void SignalFrameCapturedOnStartThread(const webrtc::VideoFrame& frame); |
tommi@webrtc.org | e07710c | 2015-02-19 17:43:25 +0000 | [diff] [blame] | 75 | |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 76 | std::unique_ptr<WebRtcVcmFactoryInterface> factory_; |
Peter Boström | 09c3a1e | 2016-03-22 17:17:39 +0100 | [diff] [blame] | 77 | rtc::scoped_refptr<webrtc::VideoCaptureModule> module_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 78 | int captured_frames_; |
wu@webrtc.org | 16d6254 | 2013-11-05 23:45:14 +0000 | [diff] [blame] | 79 | std::vector<uint8_t> capture_buffer_; |
tommi@webrtc.org | e07710c | 2015-02-19 17:43:25 +0000 | [diff] [blame] | 80 | rtc::Thread* start_thread_; // Set in Start(), unset in Stop(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | } // namespace cricket |
| 84 | |
Per | a509241 | 2016-02-12 13:30:57 +0100 | [diff] [blame] | 85 | #endif // WEBRTC_MEDIA_WEBRTC_WEBRTCVIDEOCAPTURER_H_ |