OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_API_ANDROIDVIDEOCAPTURER_H_ | 11 #ifndef WEBRTC_API_ANDROIDVIDEOCAPTURER_H_ |
12 #define WEBRTC_API_ANDROIDVIDEOCAPTURER_H_ | 12 #define WEBRTC_API_ANDROIDVIDEOCAPTURER_H_ |
13 | 13 |
14 #include <string> | 14 #include <string> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "webrtc/base/thread_checker.h" | 17 #include "webrtc/base/thread_checker.h" |
18 #include "webrtc/common_video/include/video_frame_buffer.h" | 18 #include "webrtc/common_video/include/video_frame_buffer.h" |
19 #include "webrtc/media/base/videocapturer.h" | 19 #include "webrtc/media/base/videocapturer.h" |
| 20 #include "third_party/libyuv/include/libyuv/rotate.h" |
| 21 |
| 22 namespace webrtc_jni { |
| 23 |
| 24 struct NativeHandleImpl; |
| 25 class SurfaceTextureHelper; |
| 26 |
| 27 } // namespace webrtc_jni |
20 | 28 |
21 namespace webrtc { | 29 namespace webrtc { |
22 | 30 |
23 class AndroidVideoCapturer; | 31 class AndroidVideoCapturer; |
24 | 32 |
25 class AndroidVideoCapturerDelegate : public rtc::RefCountInterface { | 33 class AndroidVideoCapturerDelegate : public rtc::RefCountInterface { |
26 public: | 34 public: |
27 virtual ~AndroidVideoCapturerDelegate() {} | 35 virtual ~AndroidVideoCapturerDelegate() {} |
28 // Start capturing. The implementation of the delegate must call | 36 // Start capturing. The implementation of the delegate must call |
29 // AndroidVideoCapturer::OnCapturerStarted with the result of this request. | 37 // AndroidVideoCapturer::OnCapturerStarted with the result of this request. |
30 virtual void Start(int width, int height, int framerate, | 38 virtual void Start(int width, int height, int framerate, |
31 AndroidVideoCapturer* capturer) = 0; | 39 AndroidVideoCapturer* capturer) = 0; |
32 | 40 |
33 // Stops capturing. | 41 // Stops capturing. |
34 // The delegate may not call into AndroidVideoCapturer after this call. | 42 // The delegate may not call into AndroidVideoCapturer after this call. |
35 virtual void Stop() = 0; | 43 virtual void Stop() = 0; |
36 | 44 |
37 virtual std::vector<cricket::VideoFormat> GetSupportedFormats() = 0; | 45 virtual std::vector<cricket::VideoFormat> GetSupportedFormats() = 0; |
38 }; | 46 }; |
39 | 47 |
40 // Android implementation of cricket::VideoCapturer for use with WebRtc | 48 // Android implementation of cricket::VideoCapturer for use with WebRtc |
41 // PeerConnection. | 49 // PeerConnection. |
42 class AndroidVideoCapturer : public cricket::VideoCapturer { | 50 class AndroidVideoCapturer : public cricket::VideoCapturer { |
43 public: | 51 public: |
44 explicit AndroidVideoCapturer( | 52 AndroidVideoCapturer( |
45 const rtc::scoped_refptr<AndroidVideoCapturerDelegate>& delegate); | 53 const rtc::scoped_refptr<AndroidVideoCapturerDelegate>& delegate, |
| 54 rtc::scoped_refptr<webrtc_jni::SurfaceTextureHelper> helper); |
46 virtual ~AndroidVideoCapturer(); | 55 virtual ~AndroidVideoCapturer(); |
47 | 56 |
48 // Called from JNI when the capturer has been started. | 57 // Called from JNI when the capturer has been started. |
49 void OnCapturerStarted(bool success); | 58 void OnCapturerStarted(bool success); |
50 | 59 |
51 // Called from JNI when a new frame has been captured. | 60 // Called from JNI when a new frame has been captured. |
52 // Argument |buffer| is intentionally by value, for use with rtc::Bind. | 61 void OnNV21Frame(const uint8_t* video_frame, |
53 void OnIncomingFrame( | 62 int length, |
54 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer, | 63 int width, |
55 int rotation, | 64 int height, |
56 int64_t time_stamp); | 65 webrtc::VideoRotation rotation, |
| 66 int64_t timestamp_ns); |
| 67 |
| 68 // Called from JNI when a new frame has been captured. |
| 69 void OnTextureFrame(int width, |
| 70 int height, |
| 71 webrtc::VideoRotation rotation, |
| 72 int64_t timestamp_ns, |
| 73 const webrtc_jni::NativeHandleImpl& handle); |
57 | 74 |
58 // Called from JNI to request a new video format. | 75 // Called from JNI to request a new video format. |
59 void OnOutputFormatRequest(int width, int height, int fps); | 76 void OnOutputFormatRequest(int width, int height, int fps); |
60 | 77 |
61 AndroidVideoCapturerDelegate* delegate() { return delegate_.get(); } | 78 AndroidVideoCapturerDelegate* delegate() { return delegate_.get(); } |
62 | 79 |
63 // cricket::VideoCapturer implementation. | 80 // cricket::VideoCapturer implementation. |
64 bool GetBestCaptureFormat(const cricket::VideoFormat& desired, | 81 bool GetBestCaptureFormat(const cricket::VideoFormat& desired, |
65 cricket::VideoFormat* best_format) override; | 82 cricket::VideoFormat* best_format) override; |
66 | 83 |
67 private: | 84 private: |
68 // cricket::VideoCapturer implementation. | 85 // cricket::VideoCapturer implementation. |
69 // Video frames will be delivered using | 86 // Video frames will be delivered using |
70 // cricket::VideoCapturer::SignalFrameCaptured on the thread that calls Start. | 87 // cricket::VideoCapturer::SignalFrameCaptured on the thread that calls Start. |
71 cricket::CaptureState Start( | 88 cricket::CaptureState Start( |
72 const cricket::VideoFormat& capture_format) override; | 89 const cricket::VideoFormat& capture_format) override; |
73 void Stop() override; | 90 void Stop() override; |
74 bool IsRunning() override; | 91 bool IsRunning() override; |
75 bool IsScreencast() const override { return false; } | 92 bool IsScreencast() const override { return false; } |
76 bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) override; | 93 bool GetPreferredFourccs(std::vector<uint32_t>* fourccs) override; |
77 | 94 |
78 bool running_; | 95 bool running_; |
79 rtc::scoped_refptr<AndroidVideoCapturerDelegate> delegate_; | 96 rtc::scoped_refptr<AndroidVideoCapturerDelegate> delegate_; |
80 | 97 rtc::scoped_refptr<webrtc_jni::SurfaceTextureHelper> surface_texture_helper_; |
81 rtc::ThreadChecker thread_checker_; | 98 rtc::ThreadChecker thread_checker_; |
82 | 99 |
83 class FrameFactory; | |
84 FrameFactory* frame_factory_; // Owned by cricket::VideoCapturer. | |
85 | |
86 cricket::CaptureState current_state_; | 100 cricket::CaptureState current_state_; |
87 }; | 101 }; |
88 | 102 |
89 } // namespace webrtc | 103 } // namespace webrtc |
90 | 104 |
91 #endif // WEBRTC_API_ANDROIDVIDEOCAPTURER_H_ | 105 #endif // WEBRTC_API_ANDROIDVIDEOCAPTURER_H_ |
OLD | NEW |