blob: 641c10f3cccc2a53bbebe9699530013c61f09b1c [file] [log] [blame]
Sami Kalliomaki16032122016-07-20 16:13:08 +02001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef API_ANDROID_JNI_ANDROIDVIDEOTRACKSOURCE_H_
12#define API_ANDROID_JNI_ANDROIDVIDEOTRACKSOURCE_H_
Sami Kalliomaki16032122016-07-20 16:13:08 +020013
sakalbe910462017-08-11 00:26:05 -070014#include <jni.h>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#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 Bonadei92ea95e2017-09-15 06:47:31 +020023#include "sdk/android/src/jni/surfacetexturehelper_jni.h"
Magnus Jedvertc2ac3c62017-11-14 17:08:59 +010024#include "sdk/android/src/jni/videoframe.h"
Sami Kalliomaki16032122016-07-20 16:13:08 +020025
26namespace webrtc {
magjeda3d4f682017-08-28 16:24:06 -070027namespace jni {
Sami Kalliomaki16032122016-07-20 16:13:08 +020028
nisse6f5a6c32016-09-22 01:25:59 -070029class AndroidVideoTrackSource : public rtc::AdaptedVideoTrackSource {
Sami Kalliomaki16032122016-07-20 16:13:08 +020030 public:
31 AndroidVideoTrackSource(rtc::Thread* signaling_thread,
32 JNIEnv* jni,
Sami Kalliomäki58c742c2017-06-02 09:51:39 +020033 jobject j_surface_texture_helper,
arsanyb75f2542016-08-31 18:50:52 -070034 bool is_screencast = false);
Sami Kalliomaki16032122016-07-20 16:13:08 +020035
arsanyb75f2542016-08-31 18:50:52 -070036 bool is_screencast() const override { return is_screencast_; }
Sami Kalliomaki16032122016-07-20 16:13:08 +020037
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 Kalliomaki16032122016-07-20 16:13:08 +020045 // 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 Kalliomaki16032122016-07-20 16:13:08 +020052 void OnByteBufferFrameCaptured(const void* frame_data,
53 int length,
54 int width,
55 int height,
Magnus Jedvert3093ef12017-06-19 15:04:19 +020056 VideoRotation rotation,
Sami Kalliomaki16032122016-07-20 16:13:08 +020057 int64_t timestamp_ns);
58
59 void OnTextureFrameCaptured(int width,
60 int height,
Magnus Jedvert3093ef12017-06-19 15:04:19 +020061 VideoRotation rotation,
Sami Kalliomaki16032122016-07-20 16:13:08 +020062 int64_t timestamp_ns,
magjeda3d4f682017-08-28 16:24:06 -070063 const NativeHandleImpl& handle);
Sami Kalliomaki16032122016-07-20 16:13:08 +020064
sakalbe910462017-08-11 00:26:05 -070065 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 Kalliomaki16032122016-07-20 16:13:08 +020072 void OnOutputFormatRequest(int width, int height, int fps);
73
magjeda3d4f682017-08-28 16:24:06 -070074 rtc::scoped_refptr<SurfaceTextureHelper> surface_texture_helper() {
Sami Kalliomaki16032122016-07-20 16:13:08 +020075 return surface_texture_helper_;
76 }
77
78 private:
79 rtc::Thread* signaling_thread_;
80 rtc::AsyncInvoker invoker_;
Sami Kalliomaki16032122016-07-20 16:13:08 +020081 rtc::ThreadChecker camera_thread_checker_;
Sami Kalliomaki16032122016-07-20 16:13:08 +020082 SourceState state_;
Sami Kalliomaki16032122016-07-20 16:13:08 +020083 rtc::TimestampAligner timestamp_aligner_;
Magnus Jedvert3093ef12017-06-19 15:04:19 +020084 NV12ToI420Scaler nv12toi420_scaler_;
85 I420BufferPool buffer_pool_;
magjeda3d4f682017-08-28 16:24:06 -070086 rtc::scoped_refptr<SurfaceTextureHelper> surface_texture_helper_;
arsanyb75f2542016-08-31 18:50:52 -070087 const bool is_screencast_;
sakalbe910462017-08-11 00:26:05 -070088
89 jmethodID j_crop_and_scale_id_;
Sami Kalliomaki16032122016-07-20 16:13:08 +020090};
91
magjeda3d4f682017-08-28 16:24:06 -070092} // namespace jni
Sami Kalliomaki16032122016-07-20 16:13:08 +020093} // namespace webrtc
94
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020095#endif // API_ANDROID_JNI_ANDROIDVIDEOTRACKSOURCE_H_