blob: 4dc921aee30989125a21f3baea1479c4d6c56a1a [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
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 Kalliomaki16032122016-07-20 16:13:08 +020016#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"
magjed1a7ef1f2016-09-17 02:39:03 -070021#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
nisse6f5a6c32016-09-22 01:25:59 -070022#include "webrtc/media/base/adaptedvideotracksource.h"
Sami Kalliomaki16032122016-07-20 16:13:08 +020023
24namespace webrtc {
25
nisse6f5a6c32016-09-22 01:25:59 -070026class AndroidVideoTrackSource : public rtc::AdaptedVideoTrackSource {
Sami Kalliomaki16032122016-07-20 16:13:08 +020027 public:
28 AndroidVideoTrackSource(rtc::Thread* signaling_thread,
29 JNIEnv* jni,
arsanyb75f2542016-08-31 18:50:52 -070030 jobject j_egl_context,
31 bool is_screencast = false);
Sami Kalliomaki16032122016-07-20 16:13:08 +020032
arsanyb75f2542016-08-31 18:50:52 -070033 bool is_screencast() const override { return is_screencast_; }
Sami Kalliomaki16032122016-07-20 16:13:08 +020034
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 Kalliomaki16032122016-07-20 16:13:08 +020042 // 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 Kalliomaki16032122016-07-20 16:13:08 +020049 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 Kalliomaki16032122016-07-20 16:13:08 +020072 rtc::ThreadChecker camera_thread_checker_;
Sami Kalliomaki16032122016-07-20 16:13:08 +020073 SourceState state_;
74 rtc::VideoBroadcaster broadcaster_;
75 rtc::TimestampAligner timestamp_aligner_;
magjed1a7ef1f2016-09-17 02:39:03 -070076 webrtc::NV12ToI420Scaler nv12toi420_scaler_;
77 webrtc::I420BufferPool buffer_pool_;
Sami Kalliomaki16032122016-07-20 16:13:08 +020078 rtc::scoped_refptr<webrtc_jni::SurfaceTextureHelper> surface_texture_helper_;
arsanyb75f2542016-08-31 18:50:52 -070079 const bool is_screencast_;
Sami Kalliomaki16032122016-07-20 16:13:08 +020080};
81
82} // namespace webrtc
83
84#endif // WEBRTC_API_ANDROIDVIDEOTRACKSOURCE_H_