Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
asmorkalov merged 17 commits intoopencv:4.xfromdkurt:java_video_capture_read
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
17 commits
Select commitHold shift + click to select a range
1f1cd89
initial commit
dkurtMay 2, 2025
17b2886
dummy java wrapper
dkurtMay 2, 2025
cb2e2a9
Keep jclass in wrapper
dkurtMay 3, 2025
66cc8c5
working test
dkurtMay 5, 2025
8a44f4f
Revert unused files
dkurtMay 5, 2025
a52ebc9
Remove size argument from read
dkurtMay 5, 2025
b6faec7
Check backend available before test
dkurtMay 5, 2025
4822844
Try print exception
dkurtMay 6, 2025
c499ed2
Revert "Try print exception"
dkurtMay 6, 2025
faddefc
Use NewLocalRef for Java stream object
dkurtMay 6, 2025
eed126c
Wrap native seek and read
dkurtMay 7, 2025
a603bce
Try create global ref
dkurtMay 7, 2025
79afad9
Fix long long in Python
dkurtMay 7, 2025
b9b0310
Default IStreamReader constructor
dkurtMay 12, 2025
feee794
Use JavaVM
dkurtMay 12, 2025
f9cb6d4
Add AttachCurrentThread in case of JNI_EDETACHED error
dkurtMay 13, 2025
c3be053
Add constructor note
dkurtMay 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Use JavaVM
  • Loading branch information
@dkurt
dkurt committedMay 12, 2025
commitfeee7949253a02a38fa76b62d75ae7890acbc7c2
8 changes: 7 additions & 1 deletionmodules/videoio/include/opencv2/videoio.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -726,7 +726,13 @@ class CV_EXPORTS_W IStreamReader
public:
virtual ~IStreamReader();

/** @brief Read bytes from stream */
/** @brief Read bytes from stream
*
* @param buffer already allocated buffer of at least @p size bytes
* @param size maximum number of bytes to read
*
* @return actual number of read bytes
*/
CV_WRAP virtual long long read(char* buffer, long long size) = 0;

/** @brief Sets the stream position
Expand Down
12 changes: 11 additions & 1 deletionmodules/videoio/misc/java/src/cpp/videoio_converters.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
#include "videoio_converters.hpp"

JavaStreamReader::JavaStreamReader(JNIEnv*_env, jobject _obj) : env(_env)
JavaStreamReader::JavaStreamReader(JNIEnv*env, jobject _obj)
{
obj = env->NewGlobalRef(_obj);
jclass cls = env->GetObjectClass(obj);
m_read = env->GetMethodID(cls, "read", "([BJ)J");
m_seek = env->GetMethodID(cls, "seek", "(JI)J");
env->GetJavaVM(&vm);
}

JavaStreamReader::~JavaStreamReader()
{
JNIEnv* env;
if (vm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK)
return;
env->DeleteGlobalRef(obj);
}

long long JavaStreamReader::read(char* buffer, long long size)
{
if (!m_read)
return 0;
JNIEnv* env;
if (vm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK)
return 0;
jbyteArray jBuffer = env->NewByteArray(static_cast<jsize>(size));
if (!jBuffer)
return 0;
Expand All@@ -28,6 +35,9 @@ long long JavaStreamReader::read(char* buffer, long long size)

long long JavaStreamReader::seek(long long offset, int way)
{
JNIEnv* env;
if (vm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK)
return 0;
if (!m_seek)
return 0;
return env->CallLongMethod(obj, m_seek, offset, way);
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,7 +15,7 @@ class JavaStreamReader : public cv::IStreamReader
long long seek(long long offset, int way) CV_OVERRIDE;

private:
JNIEnv* env;
JavaVM* vm;
jobject obj;
jmethodID m_read, m_seek;
};
Expand Down
1 change: 1 addition & 0 deletionsmodules/videoio/misc/java/test/VideoCaptureTest.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -104,6 +104,7 @@ public void testConstructorStream() throws FileNotFoundException {
@Override
public long read(byte[] buffer, long size)
{
assertEquals(buffer.length, size);
try
{
return Math.max(f.read(buffer), 0);
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp