OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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_ANDROIDVIDEOTRACKSOURCE_H_ | 11 #ifndef WEBRTC_API_ANDROIDVIDEOTRACKSOURCE_H_ |
12 #define WEBRTC_API_ANDROIDVIDEOTRACKSOURCE_H_ | 12 #define WEBRTC_API_ANDROIDVIDEOTRACKSOURCE_H_ |
13 | 13 |
14 #include "webrtc/api/android/jni/native_handle_impl.h" | 14 #include "webrtc/api/android/jni/native_handle_impl.h" |
15 #include "webrtc/api/android/jni/surfacetexturehelper_jni.h" | 15 #include "webrtc/api/android/jni/surfacetexturehelper_jni.h" |
16 #include "webrtc/api/mediastreaminterface.h" | |
17 #include "webrtc/api/notifier.h" | |
18 #include "webrtc/base/asyncinvoker.h" | 16 #include "webrtc/base/asyncinvoker.h" |
19 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
20 #include "webrtc/base/thread_checker.h" | 18 #include "webrtc/base/thread_checker.h" |
21 #include "webrtc/base/timestampaligner.h" | 19 #include "webrtc/base/timestampaligner.h" |
22 #include "webrtc/common_video/include/i420_buffer_pool.h" | 20 #include "webrtc/common_video/include/i420_buffer_pool.h" |
23 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 21 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
24 #include "webrtc/media/base/videoadapter.h" | 22 #include "webrtc/media/base/adaptedvideotracksource.h" |
25 #include "webrtc/media/base/videobroadcaster.h" | |
26 #include "webrtc/media/base/videosinkinterface.h" | |
27 | 23 |
28 namespace webrtc { | 24 namespace webrtc { |
29 | 25 |
30 class AndroidVideoTrackSource : public Notifier<VideoTrackSourceInterface> { | 26 class AndroidVideoTrackSource : public rtc::AdaptedVideoTrackSource { |
31 public: | 27 public: |
32 AndroidVideoTrackSource(rtc::Thread* signaling_thread, | 28 AndroidVideoTrackSource(rtc::Thread* signaling_thread, |
33 JNIEnv* jni, | 29 JNIEnv* jni, |
34 jobject j_egl_context, | 30 jobject j_egl_context, |
35 bool is_screencast = false); | 31 bool is_screencast = false); |
36 | 32 |
37 bool is_screencast() const override { return is_screencast_; } | 33 bool is_screencast() const override { return is_screencast_; } |
38 | 34 |
39 // Indicates that the encoder should denoise video before encoding it. | 35 // Indicates that the encoder should denoise video before encoding it. |
40 // If it is not set, the default configuration is used which is different | 36 // If it is not set, the default configuration is used which is different |
41 // depending on video codec. | 37 // depending on video codec. |
42 rtc::Optional<bool> needs_denoising() const override { | 38 rtc::Optional<bool> needs_denoising() const override { |
43 return rtc::Optional<bool>(false); | 39 return rtc::Optional<bool>(false); |
44 } | 40 } |
45 | 41 |
46 // Returns false if no stats are available, e.g, for a remote | |
47 // source, or a source which has not seen its first frame yet. | |
48 // Should avoid blocking. | |
49 bool GetStats(Stats* stats) override; | |
50 | |
51 // Called by the native capture observer | 42 // Called by the native capture observer |
52 void SetState(SourceState state); | 43 void SetState(SourceState state); |
53 | 44 |
54 SourceState state() const override { return state_; } | 45 SourceState state() const override { return state_; } |
55 | 46 |
56 bool remote() const override { return false; } | 47 bool remote() const override { return false; } |
57 | 48 |
58 void AddOrUpdateSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink, | |
59 const rtc::VideoSinkWants& wants) override; | |
60 void RemoveSink(rtc::VideoSinkInterface<cricket::VideoFrame>* sink) override; | |
61 | |
62 void OnByteBufferFrameCaptured(const void* frame_data, | 49 void OnByteBufferFrameCaptured(const void* frame_data, |
63 int length, | 50 int length, |
64 int width, | 51 int width, |
65 int height, | 52 int height, |
66 int rotation, | 53 int rotation, |
67 int64_t timestamp_ns); | 54 int64_t timestamp_ns); |
68 | 55 |
69 void OnTextureFrameCaptured(int width, | 56 void OnTextureFrameCaptured(int width, |
70 int height, | 57 int height, |
71 int rotation, | 58 int rotation, |
72 int64_t timestamp_ns, | 59 int64_t timestamp_ns, |
73 const webrtc_jni::NativeHandleImpl& handle); | 60 const webrtc_jni::NativeHandleImpl& handle); |
74 | 61 |
75 void OnOutputFormatRequest(int width, int height, int fps); | 62 void OnOutputFormatRequest(int width, int height, int fps); |
76 | 63 |
77 rtc::scoped_refptr<webrtc_jni::SurfaceTextureHelper> | 64 rtc::scoped_refptr<webrtc_jni::SurfaceTextureHelper> |
78 surface_texture_helper() { | 65 surface_texture_helper() { |
79 return surface_texture_helper_; | 66 return surface_texture_helper_; |
80 } | 67 } |
81 | 68 |
82 private: | 69 private: |
83 rtc::Thread* signaling_thread_; | 70 rtc::Thread* signaling_thread_; |
84 rtc::AsyncInvoker invoker_; | 71 rtc::AsyncInvoker invoker_; |
85 rtc::ThreadChecker worker_thread_checker_; | |
86 rtc::ThreadChecker camera_thread_checker_; | 72 rtc::ThreadChecker camera_thread_checker_; |
87 rtc::CriticalSection stats_crit_; | |
88 rtc::Optional<Stats> stats_ GUARDED_BY(stats_crit_); | |
89 SourceState state_; | 73 SourceState state_; |
90 rtc::VideoBroadcaster broadcaster_; | 74 rtc::VideoBroadcaster broadcaster_; |
91 rtc::TimestampAligner timestamp_aligner_; | 75 rtc::TimestampAligner timestamp_aligner_; |
92 cricket::VideoAdapter video_adapter_; | |
93 rtc::CriticalSection apply_rotation_crit_; | |
94 bool apply_rotation_ GUARDED_BY(apply_rotation_crit_); | |
95 webrtc::NV12ToI420Scaler nv12toi420_scaler_; | 76 webrtc::NV12ToI420Scaler nv12toi420_scaler_; |
96 webrtc::I420BufferPool buffer_pool_; | 77 webrtc::I420BufferPool buffer_pool_; |
97 rtc::scoped_refptr<webrtc_jni::SurfaceTextureHelper> surface_texture_helper_; | 78 rtc::scoped_refptr<webrtc_jni::SurfaceTextureHelper> surface_texture_helper_; |
98 const bool is_screencast_; | 79 const bool is_screencast_; |
99 | |
100 void OnFrame(const cricket::VideoFrame& frame, int width, int height); | |
101 | |
102 void OnSinkWantsChanged(const rtc::VideoSinkWants& wants); | |
103 | |
104 bool AdaptFrame(int width, | |
105 int height, | |
106 int64_t camera_time_us, | |
107 int* out_width, | |
108 int* out_height, | |
109 int* crop_width, | |
110 int* crop_height, | |
111 int* crop_x, | |
112 int* crop_y, | |
113 int64_t* translated_camera_time_us); | |
114 }; | 80 }; |
115 | 81 |
116 } // namespace webrtc | 82 } // namespace webrtc |
117 | 83 |
118 #endif // WEBRTC_API_ANDROIDVIDEOTRACKSOURCE_H_ | 84 #endif // WEBRTC_API_ANDROIDVIDEOTRACKSOURCE_H_ |
OLD | NEW |