Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #ifndef TALK_APP_WEBRTC_JAVA_JNI_ANDROIDVIDEOCAPTURER_JNI_H_ | 29 #ifndef TALK_APP_WEBRTC_JAVA_JNI_ANDROIDVIDEOCAPTURER_JNI_H_ |
| 30 #define TALK_APP_WEBRTC_JAVA_JNI_ANDROIDVIDEOCAPTURER_JNI_H_ | 30 #define TALK_APP_WEBRTC_JAVA_JNI_ANDROIDVIDEOCAPTURER_JNI_H_ |
| 31 | 31 |
| 32 #include <string> | 32 #include <string> |
| 33 | 33 |
| 34 #include "talk/app/webrtc/androidvideocapturer.h" | 34 #include "talk/app/webrtc/androidvideocapturer.h" |
| 35 #include "talk/app/webrtc/java/jni/jni_helpers.h" | 35 #include "talk/app/webrtc/java/jni/jni_helpers.h" |
| 36 #include "webrtc/base/asyncinvoker.h" | 36 #include "webrtc/base/asyncinvoker.h" |
| 37 #include "webrtc/base/criticalsection.h" | |
| 37 #include "webrtc/base/thread_checker.h" | 38 #include "webrtc/base/thread_checker.h" |
| 38 | 39 |
| 39 namespace webrtc_jni { | 40 namespace webrtc_jni { |
| 40 | 41 |
| 41 // AndroidVideoCapturerJni implements AndroidVideoCapturerDelegate. | 42 // AndroidVideoCapturerJni implements AndroidVideoCapturerDelegate. |
| 42 // The purpose of the delegate is to hide the JNI specifics from the C++ only | 43 // The purpose of the delegate is to hide the JNI specifics from the C++ only |
| 43 // AndroidVideoCapturer. | 44 // AndroidVideoCapturer. |
| 44 class AndroidVideoCapturerJni : public webrtc::AndroidVideoCapturerDelegate { | 45 class AndroidVideoCapturerJni : public webrtc::AndroidVideoCapturerDelegate { |
| 45 public: | 46 public: |
| 46 static int SetAndroidObjects(JNIEnv* jni, jobject appliction_context); | 47 static int SetAndroidObjects(JNIEnv* jni, jobject appliction_context); |
| 47 | 48 |
| 48 // Creates a new instance of AndroidVideoCapturerJni. Returns a nullptr if | 49 // Creates a new instance of AndroidVideoCapturerJni. Returns a nullptr if |
| 49 // it can't be created. This happens if |device_name| is invalid. | 50 // it can't be created. This happens if |device_name| is invalid. |
| 50 static rtc::scoped_refptr<AndroidVideoCapturerJni> Create( | 51 static rtc::scoped_refptr<AndroidVideoCapturerJni> Create( |
| 51 JNIEnv* jni, | 52 JNIEnv* jni, |
| 52 jobject j_video_capture, // Instance of VideoCapturerAndroid | 53 jobject j_video_capture, // Instance of VideoCapturerAndroid |
| 53 jstring device_name); // Name of the camera to use. | 54 jstring device_name); // Name of the camera to use. |
| 54 | 55 |
| 55 void Start(int width, int height, int framerate, | 56 void Start(int width, int height, int framerate, |
| 56 webrtc::AndroidVideoCapturer* capturer) override; | 57 webrtc::AndroidVideoCapturer* capturer) override; |
| 57 void Stop() override; | 58 void Stop() override; |
| 58 | 59 |
| 59 void ReturnBuffer(int64 time_stamp) override; | |
| 60 | |
| 61 std::string GetSupportedFormats() override; | 60 std::string GetSupportedFormats() override; |
| 62 | 61 |
| 63 // Called from VideoCapturerAndroid::NativeObserver on a Java thread. | 62 // Called from VideoCapturerAndroid::NativeObserver on a Java thread. |
| 64 void OnCapturerStarted(bool success); | 63 void OnCapturerStarted(bool success); |
| 65 void OnIncomingFrame(void* video_frame, | 64 void OnIncomingFrame(void* video_frame, |
| 66 int length, | 65 int length, |
| 67 int width, | 66 int width, |
| 68 int height, | 67 int height, |
| 69 int rotation, | 68 int rotation, |
| 70 int64 time_stamp); | 69 int64 time_stamp); |
| 71 void OnOutputFormatRequest(int width, int height, int fps); | 70 void OnOutputFormatRequest(int width, int height, int fps); |
| 72 protected: | 71 protected: |
| 73 AndroidVideoCapturerJni(JNIEnv* jni, jobject j_video_capturer); | 72 AndroidVideoCapturerJni(JNIEnv* jni, jobject j_video_capturer); |
| 74 ~AndroidVideoCapturerJni(); | 73 ~AndroidVideoCapturerJni(); |
| 75 | 74 |
| 76 private: | 75 private: |
| 77 bool Init(jstring device_name); | 76 bool Init(jstring device_name); |
| 77 void ReturnBuffer(int64 time_stamp); | |
| 78 JNIEnv* jni(); | |
| 78 | 79 |
| 79 void OnCapturerStarted_w(bool success); | 80 // Helper function to make safe asynchronous calls to |capturer_|. The calls |
| 80 void OnCapturerStopped_w(); | 81 // are not guaranteed to be delivered. |
| 81 void OnIncomingFrame_w(void* video_frame, | 82 template <typename... Args> |
|
tommi
2015/08/24 09:14:42
ah, it was only a matter of time...
| |
| 82 int length, | 83 void AsyncCapturerInvoke( |
| 83 int width, | 84 const char* method_name, |
| 84 int height, | 85 void (webrtc::AndroidVideoCapturer::*method)(Args...), |
| 85 int rotation, | 86 Args... args); |
| 86 int64 time_stamp); | |
| 87 void OnOutputFormatRequest_w(int width, int height, int fps); | |
| 88 void ReturnBuffer_w(int64 time_stamp); | |
| 89 | |
| 90 JNIEnv* jni(); | |
| 91 | 87 |
| 92 const ScopedGlobalRef<jobject> j_capturer_global_; | 88 const ScopedGlobalRef<jobject> j_capturer_global_; |
| 93 const ScopedGlobalRef<jclass> j_video_capturer_class_; | 89 const ScopedGlobalRef<jclass> j_video_capturer_class_; |
| 94 const ScopedGlobalRef<jclass> j_observer_class_; | 90 const ScopedGlobalRef<jclass> j_observer_class_; |
| 95 volatile bool valid_global_refs_; | |
| 96 jobject j_frame_observer_; | |
| 97 | 91 |
| 98 rtc::ThreadChecker thread_checker_; | 92 rtc::ThreadChecker thread_checker_; |
| 99 | 93 |
| 100 rtc::Thread* thread_; // The thread where Start is called on. | |
| 101 // |capturer| is a guaranteed to be a valid pointer between a call to | 94 // |capturer| is a guaranteed to be a valid pointer between a call to |
| 102 // AndroidVideoCapturerDelegate::Start | 95 // AndroidVideoCapturerDelegate::Start |
| 103 // until AndroidVideoCapturerDelegate::Stop. | 96 // until AndroidVideoCapturerDelegate::Stop. |
| 104 webrtc::AndroidVideoCapturer* capturer_; | 97 rtc::CriticalSection capturer_lock_; |
| 105 rtc::AsyncInvoker invoker_; | 98 webrtc::AndroidVideoCapturer* capturer_ GUARDED_BY(capturer_lock_); |
| 99 // |invoker_| is used to communicate with |capturer_| on the thread Start() is | |
| 100 // called on. | |
| 101 rtc::scoped_ptr<rtc::GuardedAsyncInvoker> invoker_ GUARDED_BY(capturer_lock_); | |
| 106 | 102 |
| 107 static jobject application_context_; | 103 static jobject application_context_; |
| 108 | 104 |
| 109 DISALLOW_COPY_AND_ASSIGN(AndroidVideoCapturerJni); | 105 DISALLOW_COPY_AND_ASSIGN(AndroidVideoCapturerJni); |
| 110 }; | 106 }; |
| 111 | 107 |
| 112 } // namespace webrtc_jni | 108 } // namespace webrtc_jni |
| 113 | 109 |
| 114 #endif // TALK_APP_WEBRTC_JAVA_JNI_ANDROIDVIDEOCAPTURER_JNI_H_ | 110 #endif // TALK_APP_WEBRTC_JAVA_JNI_ANDROIDVIDEOCAPTURER_JNI_H_ |
| OLD | NEW |