Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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. |
| 9 | */ |
| 10 | |
| 11 | #ifndef WEBRTC_API_ANDROIDVIDEOTRACKSOURCE_H_ |
| 12 | #define WEBRTC_API_ANDROIDVIDEOTRACKSOURCE_H_ |
| 13 | |
| 14 | #include "webrtc/api/android/jni/native_handle_impl.h" |
| 15 | #include "webrtc/api/android/jni/surfacetexturehelper_jni.h" |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 16 | #include "webrtc/base/asyncinvoker.h" |
| 17 | #include "webrtc/base/checks.h" |
| 18 | #include "webrtc/base/thread_checker.h" |
| 19 | #include "webrtc/base/timestampaligner.h" |
| 20 | #include "webrtc/common_video/include/i420_buffer_pool.h" |
magjed | 1a7ef1f | 2016-09-17 02:39:03 -0700 | [diff] [blame] | 21 | #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
nisse | 6f5a6c3 | 2016-09-22 01:25:59 -0700 | [diff] [blame^] | 22 | #include "webrtc/media/base/adaptedvideotracksource.h" |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
nisse | 6f5a6c3 | 2016-09-22 01:25:59 -0700 | [diff] [blame^] | 26 | class AndroidVideoTrackSource : public rtc::AdaptedVideoTrackSource { |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 27 | public: |
| 28 | AndroidVideoTrackSource(rtc::Thread* signaling_thread, |
| 29 | JNIEnv* jni, |
arsany | b75f254 | 2016-08-31 18:50:52 -0700 | [diff] [blame] | 30 | jobject j_egl_context, |
| 31 | bool is_screencast = false); |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 32 | |
arsany | b75f254 | 2016-08-31 18:50:52 -0700 | [diff] [blame] | 33 | bool is_screencast() const override { return is_screencast_; } |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 34 | |
| 35 | // Indicates that the encoder should denoise video before encoding it. |
| 36 | // If it is not set, the default configuration is used which is different |
| 37 | // depending on video codec. |
| 38 | rtc::Optional<bool> needs_denoising() const override { |
| 39 | return rtc::Optional<bool>(false); |
| 40 | } |
| 41 | |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 42 | // Called by the native capture observer |
| 43 | void SetState(SourceState state); |
| 44 | |
| 45 | SourceState state() const override { return state_; } |
| 46 | |
| 47 | bool remote() const override { return false; } |
| 48 | |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 49 | void OnByteBufferFrameCaptured(const void* frame_data, |
| 50 | int length, |
| 51 | int width, |
| 52 | int height, |
| 53 | int rotation, |
| 54 | int64_t timestamp_ns); |
| 55 | |
| 56 | void OnTextureFrameCaptured(int width, |
| 57 | int height, |
| 58 | int rotation, |
| 59 | int64_t timestamp_ns, |
| 60 | const webrtc_jni::NativeHandleImpl& handle); |
| 61 | |
| 62 | void OnOutputFormatRequest(int width, int height, int fps); |
| 63 | |
| 64 | rtc::scoped_refptr<webrtc_jni::SurfaceTextureHelper> |
| 65 | surface_texture_helper() { |
| 66 | return surface_texture_helper_; |
| 67 | } |
| 68 | |
| 69 | private: |
| 70 | rtc::Thread* signaling_thread_; |
| 71 | rtc::AsyncInvoker invoker_; |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 72 | rtc::ThreadChecker camera_thread_checker_; |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 73 | SourceState state_; |
| 74 | rtc::VideoBroadcaster broadcaster_; |
| 75 | rtc::TimestampAligner timestamp_aligner_; |
magjed | 1a7ef1f | 2016-09-17 02:39:03 -0700 | [diff] [blame] | 76 | webrtc::NV12ToI420Scaler nv12toi420_scaler_; |
| 77 | webrtc::I420BufferPool buffer_pool_; |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 78 | rtc::scoped_refptr<webrtc_jni::SurfaceTextureHelper> surface_texture_helper_; |
arsany | b75f254 | 2016-08-31 18:50:52 -0700 | [diff] [blame] | 79 | const bool is_screencast_; |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | } // namespace webrtc |
| 83 | |
| 84 | #endif // WEBRTC_API_ANDROIDVIDEOTRACKSOURCE_H_ |