blob: 524c36d837c37184b2ea88d227aa0f34af969f65 [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.
Oskar Sundbom057ce1d2017-11-16 10:56:15 +010041 rtc::Optional<bool> needs_denoising() const override { return false; }
Sami Kalliomaki16032122016-07-20 16:13:08 +020042
Sami Kalliomaki16032122016-07-20 16:13:08 +020043 // Called by the native capture observer
44 void SetState(SourceState state);
45
46 SourceState state() const override { return state_; }
47
48 bool remote() const override { return false; }
49
Sami Kalliomaki16032122016-07-20 16:13:08 +020050 void OnByteBufferFrameCaptured(const void* frame_data,
51 int length,
52 int width,
53 int height,
Magnus Jedvert3093ef12017-06-19 15:04:19 +020054 VideoRotation rotation,
Sami Kalliomaki16032122016-07-20 16:13:08 +020055 int64_t timestamp_ns);
56
57 void OnTextureFrameCaptured(int width,
58 int height,
Magnus Jedvert3093ef12017-06-19 15:04:19 +020059 VideoRotation rotation,
Sami Kalliomaki16032122016-07-20 16:13:08 +020060 int64_t timestamp_ns,
magjeda3d4f682017-08-28 16:24:06 -070061 const NativeHandleImpl& handle);
Sami Kalliomaki16032122016-07-20 16:13:08 +020062
sakalbe910462017-08-11 00:26:05 -070063 void OnFrameCaptured(JNIEnv* jni,
64 int width,
65 int height,
66 int64_t timestamp_ns,
67 VideoRotation rotation,
68 jobject j_video_frame_buffer);
69
Sami Kalliomaki16032122016-07-20 16:13:08 +020070 void OnOutputFormatRequest(int width, int height, int fps);
71
magjeda3d4f682017-08-28 16:24:06 -070072 rtc::scoped_refptr<SurfaceTextureHelper> surface_texture_helper() {
Sami Kalliomaki16032122016-07-20 16:13:08 +020073 return surface_texture_helper_;
74 }
75
76 private:
77 rtc::Thread* signaling_thread_;
78 rtc::AsyncInvoker invoker_;
Sami Kalliomaki16032122016-07-20 16:13:08 +020079 rtc::ThreadChecker camera_thread_checker_;
Sami Kalliomaki16032122016-07-20 16:13:08 +020080 SourceState state_;
Sami Kalliomaki16032122016-07-20 16:13:08 +020081 rtc::TimestampAligner timestamp_aligner_;
Magnus Jedvert3093ef12017-06-19 15:04:19 +020082 NV12ToI420Scaler nv12toi420_scaler_;
83 I420BufferPool buffer_pool_;
magjeda3d4f682017-08-28 16:24:06 -070084 rtc::scoped_refptr<SurfaceTextureHelper> surface_texture_helper_;
arsanyb75f2542016-08-31 18:50:52 -070085 const bool is_screencast_;
Sami Kalliomaki16032122016-07-20 16:13:08 +020086};
87
magjeda3d4f682017-08-28 16:24:06 -070088} // namespace jni
Sami Kalliomaki16032122016-07-20 16:13:08 +020089} // namespace webrtc
90
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020091#endif // API_ANDROID_JNI_ANDROIDVIDEOTRACKSOURCE_H_