Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork56.4k
Java VideoCapture buffered stream constructor#27284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from8 commits
Commits
Show all changes
17 commits Select commitHold shift + click to select a range
1f1cd89 initial commit
dkurt17b2886 dummy java wrapper
dkurtcb2e2a9 Keep jclass in wrapper
dkurt66cc8c5 working test
dkurt8a44f4f Revert unused files
dkurta52ebc9 Remove size argument from read
dkurtb6faec7 Check backend available before test
dkurt4822844 Try print exception
dkurtc499ed2 Revert "Try print exception"
dkurtfaddefc Use NewLocalRef for Java stream object
dkurteed126c Wrap native seek and read
dkurta603bce Try create global ref
dkurt79afad9 Fix long long in Python
dkurtb9b0310 Default IStreamReader constructor
dkurtfeee794 Use JavaVM
dkurtf9cb6d4 Add AttachCurrentThread in case of JNI_EDETACHED error
dkurtc3be053 Add constructor note
dkurtFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletionsmodules/python/src2/typing_stubs_generation/predefined_types.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionmodules/videoio/include/opencv2/videoio.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -721,7 +721,7 @@ enum VideoCaptureOBSensorProperties{ | ||
| /** @brief Read data stream interface | ||
| */ | ||
| classCV_EXPORTS IStreamReader | ||
dkurt marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| { | ||
| public: | ||
| virtual ~IStreamReader(); | ||
1 change: 1 addition & 0 deletionsmodules/videoio/misc/java/filelist_common
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| misc/java/src/cpp/videoio_converters.hpp |
20 changes: 20 additions & 0 deletionsmodules/videoio/misc/java/gen_dict.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "type_dict": { | ||
| "Ptr_IStreamReader": { | ||
| "j_type": "IStreamReader", | ||
| "jn_type": "IStreamReader", | ||
| "jni_name": "n_%(n)s", | ||
| "jni_type": "jclass", | ||
| "jni_var": "auto n_%(n)s = makePtr<JavaStreamReader>(env, source)", | ||
| "j_import": "org.opencv.videoio.IStreamReader" | ||
| }, | ||
| "vector_VideoCaptureAPIs": { | ||
| "j_type": "List<Integer>", | ||
| "jn_type": "List<Integer>", | ||
| "jni_type": "jobject", | ||
| "jni_var": "std::vector< cv::VideoCaptureAPIs > %(n)s", | ||
| "suffix": "Ljava_util_List", | ||
| "v_type": "vector_VideoCaptureAPIs" | ||
| } | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletionsmodules/videoio/misc/java/src/cpp/videoio_converters.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #include "videoio_converters.hpp" | ||
| JavaStreamReader::JavaStreamReader(JNIEnv* _env, jclass _obj) : env(_env), obj(_obj) {} | ||
| long long JavaStreamReader::read(char* buffer, long long size) | ||
| { | ||
| jmethodID m_read = env->GetMethodID(env->GetObjectClass(obj), "read", "([B)J"); | ||
| if (!m_read) | ||
| return 0; | ||
| jbyteArray jBuffer = env->NewByteArray(static_cast<jsize>(size)); | ||
| if (!jBuffer) | ||
| return 0; | ||
| jlong res = env->CallIntMethod(obj, m_read, jBuffer); | ||
| env->GetByteArrayRegion(jBuffer, 0, static_cast<jsize>(size), reinterpret_cast<jbyte*>(buffer)); | ||
| env->DeleteLocalRef(jBuffer); | ||
| return res; | ||
| } | ||
| long long JavaStreamReader::seek(long long offset, int way) | ||
| { | ||
| jmethodID m_seek = env->GetMethodID(env->GetObjectClass(obj), "seek", "(JJ)J"); | ||
| if (!m_seek) | ||
| return 0; | ||
| jlong res = env->CallIntMethod(obj, m_seek, offset, way); | ||
| return res; | ||
| } | ||
| // Same as dnn::vector_Target_to_List | ||
| jobject vector_VideoCaptureAPIs_to_List(JNIEnv* env, std::vector<cv::VideoCaptureAPIs>& vs) | ||
| { | ||
| static jclass juArrayList = ARRAYLIST(env); | ||
| static jmethodID m_create = CONSTRUCTOR(env, juArrayList); | ||
| jmethodID m_add = LIST_ADD(env, juArrayList); | ||
| static jclass jInteger = env->FindClass("java/lang/Integer"); | ||
| static jmethodID m_create_Integer = env->GetMethodID(jInteger, "<init>", "(I)V"); | ||
| jobject result = env->NewObject(juArrayList, m_create, vs.size()); | ||
| for (size_t i = 0; i < vs.size(); ++i) | ||
| { | ||
| jobject element = env->NewObject(jInteger, m_create_Integer, vs[i]); | ||
| env->CallBooleanMethod(result, m_add, element); | ||
| env->DeleteLocalRef(element); | ||
| } | ||
| return result; | ||
| } |
23 changes: 23 additions & 0 deletionsmodules/videoio/misc/java/src/cpp/videoio_converters.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #ifndef VIDEOIO_CONVERTERS_HPP | ||
| #define VIDEOIO_CONVERTERS_HPP | ||
| #include <jni.h> | ||
| #include "opencv_java.hpp" | ||
| #include "opencv2/core.hpp" | ||
| #include "opencv2/videoio/videoio.hpp" | ||
| class JavaStreamReader : public cv::IStreamReader | ||
| { | ||
| public: | ||
| JavaStreamReader(JNIEnv* env, jclass obj); | ||
| long long read(char* buffer, long long size) CV_OVERRIDE; | ||
| long long seek(long long offset, int way) CV_OVERRIDE; | ||
| private: | ||
| JNIEnv* env; | ||
| jclass obj; | ||
| }; | ||
| jobject vector_VideoCaptureAPIs_to_List(JNIEnv* env, std::vector<cv::VideoCaptureAPIs>& vs); | ||
| #endif |
6 changes: 6 additions & 0 deletionsmodules/videoio/misc/java/src/java/videoio+IStreamReader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package org.opencv.videoio; | ||
| public interface IStreamReader { | ||
| public long read(byte[] buffer); | ||
| public long seek(long offset, long origin); | ||
| } |
85 changes: 84 additions & 1 deletionmodules/videoio/misc/java/test/VideoCaptureTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletionsmodules/videoio/src/backend_plugin.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.