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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef API_ANDROID_JNI_ANDROIDVIDEOTRACKSOURCE_H_ |
| 12 | #define API_ANDROID_JNI_ANDROIDVIDEOTRACKSOURCE_H_ |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 13 | |
sakal | be91046 | 2017-08-11 00:26:05 -0700 | [diff] [blame] | 14 | #include <jni.h> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "common_video/include/i420_buffer_pool.h" |
| 17 | #include "common_video/libyuv/include/webrtc_libyuv.h" |
| 18 | #include "media/base/adaptedvideotracksource.h" |
| 19 | #include "rtc_base/asyncinvoker.h" |
| 20 | #include "rtc_base/checks.h" |
| 21 | #include "rtc_base/thread_checker.h" |
| 22 | #include "rtc_base/timestampaligner.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "sdk/android/src/jni/surfacetexturehelper_jni.h" |
Magnus Jedvert | c2ac3c6 | 2017-11-14 17:08:59 +0100 | [diff] [blame^] | 24 | #include "sdk/android/src/jni/videoframe.h" |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 25 | |
| 26 | namespace webrtc { |
magjed | a3d4f68 | 2017-08-28 16:24:06 -0700 | [diff] [blame] | 27 | namespace jni { |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 28 | |
nisse | 6f5a6c3 | 2016-09-22 01:25:59 -0700 | [diff] [blame] | 29 | class AndroidVideoTrackSource : public rtc::AdaptedVideoTrackSource { |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 30 | public: |
| 31 | AndroidVideoTrackSource(rtc::Thread* signaling_thread, |
| 32 | JNIEnv* jni, |
Sami Kalliomäki | 58c742c | 2017-06-02 09:51:39 +0200 | [diff] [blame] | 33 | jobject j_surface_texture_helper, |
arsany | b75f254 | 2016-08-31 18:50:52 -0700 | [diff] [blame] | 34 | bool is_screencast = false); |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 35 | |
arsany | b75f254 | 2016-08-31 18:50:52 -0700 | [diff] [blame] | 36 | bool is_screencast() const override { return is_screencast_; } |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 37 | |
| 38 | // Indicates that the encoder should denoise video before encoding it. |
| 39 | // If it is not set, the default configuration is used which is different |
| 40 | // depending on video codec. |
| 41 | rtc::Optional<bool> needs_denoising() const override { |
| 42 | return rtc::Optional<bool>(false); |
| 43 | } |
| 44 | |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 45 | // Called by the native capture observer |
| 46 | void SetState(SourceState state); |
| 47 | |
| 48 | SourceState state() const override { return state_; } |
| 49 | |
| 50 | bool remote() const override { return false; } |
| 51 | |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 52 | void OnByteBufferFrameCaptured(const void* frame_data, |
| 53 | int length, |
| 54 | int width, |
| 55 | int height, |
Magnus Jedvert | 3093ef1 | 2017-06-19 15:04:19 +0200 | [diff] [blame] | 56 | VideoRotation rotation, |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 57 | int64_t timestamp_ns); |
| 58 | |
| 59 | void OnTextureFrameCaptured(int width, |
| 60 | int height, |
Magnus Jedvert | 3093ef1 | 2017-06-19 15:04:19 +0200 | [diff] [blame] | 61 | VideoRotation rotation, |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 62 | int64_t timestamp_ns, |
magjed | a3d4f68 | 2017-08-28 16:24:06 -0700 | [diff] [blame] | 63 | const NativeHandleImpl& handle); |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 64 | |
sakal | be91046 | 2017-08-11 00:26:05 -0700 | [diff] [blame] | 65 | void OnFrameCaptured(JNIEnv* jni, |
| 66 | int width, |
| 67 | int height, |
| 68 | int64_t timestamp_ns, |
| 69 | VideoRotation rotation, |
| 70 | jobject j_video_frame_buffer); |
| 71 | |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 72 | void OnOutputFormatRequest(int width, int height, int fps); |
| 73 | |
magjed | a3d4f68 | 2017-08-28 16:24:06 -0700 | [diff] [blame] | 74 | rtc::scoped_refptr<SurfaceTextureHelper> surface_texture_helper() { |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 75 | return surface_texture_helper_; |
| 76 | } |
| 77 | |
| 78 | private: |
| 79 | rtc::Thread* signaling_thread_; |
| 80 | rtc::AsyncInvoker invoker_; |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 81 | rtc::ThreadChecker camera_thread_checker_; |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 82 | SourceState state_; |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 83 | rtc::TimestampAligner timestamp_aligner_; |
Magnus Jedvert | 3093ef1 | 2017-06-19 15:04:19 +0200 | [diff] [blame] | 84 | NV12ToI420Scaler nv12toi420_scaler_; |
| 85 | I420BufferPool buffer_pool_; |
magjed | a3d4f68 | 2017-08-28 16:24:06 -0700 | [diff] [blame] | 86 | rtc::scoped_refptr<SurfaceTextureHelper> surface_texture_helper_; |
arsany | b75f254 | 2016-08-31 18:50:52 -0700 | [diff] [blame] | 87 | const bool is_screencast_; |
sakal | be91046 | 2017-08-11 00:26:05 -0700 | [diff] [blame] | 88 | |
| 89 | jmethodID j_crop_and_scale_id_; |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 90 | }; |
| 91 | |
magjed | a3d4f68 | 2017-08-28 16:24:06 -0700 | [diff] [blame] | 92 | } // namespace jni |
Sami Kalliomaki | 1603212 | 2016-07-20 16:13:08 +0200 | [diff] [blame] | 93 | } // namespace webrtc |
| 94 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 95 | #endif // API_ANDROID_JNI_ANDROIDVIDEOTRACKSOURCE_H_ |