Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android 4.0 UnpupportedOperationException #39

Closed
aydinkn opened this issue Sep 18, 2015 · 7 comments
Closed

Android 4.0 UnpupportedOperationException #39

aydinkn opened this issue Sep 18, 2015 · 7 comments
Labels

Comments

@aydinkn
Copy link

aydinkn commented Sep 18, 2015

Hi,

I am developing broadcaster software on Android with FFmpegFrameRecorder. It works well on Android 4.0 > Phones but when I try it on Android 4.0.4 tablet (Samsung Galaxy Tab GT-P5110) this error raised:

java.lang.UnsupportedOperationException
09-18 11:48:17.078  12919-12919/ W/System.err﹕ at java.nio.DirectByteBuffer.protectedArray(DirectByteBuffer.java:211)
09-18 11:48:17.078  12919-12919/ W/System.err﹕ at java.nio.DirectByteBuffer.protectedHasArray(DirectByteBuffer.java:222)
09-18 11:48:17.078  12919-12919/ W/System.err﹕ at java.nio.ByteBuffer.hasArray(ByteBuffer.java:597)
09-18 11:48:17.078  12919-12919/ W/System.err﹕ at org.bytedeco.javacpp.BytePointer.<init>(BytePointer.java:79)
09-18 11:48:17.078  12919-12919/ W/System.err﹕ at org.bytedeco.javacv.FFmpegFrameRecorder.recordImage(FFmpegFrameRecorder.java:706)
09-18 11:48:17.078  12919-12919/ W/System.err﹕ at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:684)
09-18 11:48:17.078  12919-12919/ W/System.err﹕ at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:677)
@saudet
Copy link
Member

saudet commented Sep 18, 2015

Looks like a bug in Android 4.0: https://code.google.com/p/android/issues/detail?id=24327

So if you cannot update to 4.1 at least, it looks like the workaround is to recreate the buffers you are using, in Java.

@szitguy
Copy link

szitguy commented Oct 21, 2015

@aydinkn I get the same problem. Do you use FFmpegFrameFilter?
On Android4.0.4, I removed FFmpegFrameFilter process code, and it worked, but certainly no more crop process.

@aydinkn
Copy link
Author

aydinkn commented Oct 21, 2015

@szitguy my application need FFmpegFrameFilter (for transpose). I changed application min android version to >= 4.1 for now.

@szitguy
Copy link

szitguy commented Oct 21, 2015

@aydinkn OK, but my app still want to support from Android4.0.
I am trying to find some way to fix it.

@szitguy
Copy link

szitguy commented Oct 21, 2015

@aydinkn I fixed the problem just now, i modified the "pull" method of class FFmpegFrameFilter, here is my "pull" code(look at the line writing "if (SystemVersionUtil.hasJellyBean())"):

public Frame pull() throws Exception {
    av_frame_unref(filt_frame);

    /* pull a filtered frame from the filtergraph */
    int ret = av_buffersink_get_frame(buffersink_ctx, filt_frame);
    if (ret == -11 /*AVERROR(EAGAIN)*/ || ret == AVERROR_EOF) {
        return null;
    } else if (ret < 0) {
        throw new Exception("av_buffersink_get_frame(): Error occurred: "
                + av_make_error_string(new BytePointer(256), 256, ret).getString());
    }
    frame.imageWidth  = filt_frame.width();
    frame.imageHeight = filt_frame.height();
    frame.imageDepth = Frame.DEPTH_UBYTE;
    if (filt_frame.data(1) == null) {
        frame.imageStride = filt_frame.linesize(0);
        BytePointer ptr = filt_frame.data(0);
        if (ptr != null && !ptr.equals(image_ptr[0])) {
            image_ptr[0] = ptr.capacity(frame.imageHeight * frame.imageStride);
            image_buf[0] = ptr.asBuffer();
        }
        frame.image = image_buf;
        frame.image[0].position(0).limit(frame.imageHeight * frame.imageStride);
        frame.imageChannels = frame.imageStride / frame.imageWidth;
    } else {
        frame.imageStride = frame.imageWidth;
        int size = avpicture_get_size(filt_frame.format(), frame.imageWidth, frame.imageHeight);
        // Fix bug on Android4.0,check out https://github.com/bytedeco/javacpp/issues/39
        if (SystemVersionUtil.hasJellyBean()) {
            if (image_ptr[0] == null || image_ptr[0].capacity() < size) {
                image_ptr[0] = new BytePointer(size);
                image_buf[0] = image_ptr[0].asBuffer();
            }
            frame.image = image_buf;
            frame.image[0].position(0).limit(size);
            frame.imageChannels = 2;
            ret = avpicture_layout(new AVPicture(filt_frame), filt_frame.format(),
                    frame.imageWidth, frame.imageHeight, image_ptr[0].position(0), image_ptr[0].capacity());
        } else {
            if (image_buf[0] == null || image_buf[0].capacity() < size) {
                image_buf[0] = ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());
            }
            frame.image = image_buf;
            frame.image[0].position(0).limit(size);
            frame.imageChannels = 2;
            ret = avpicture_layout(new AVPicture(filt_frame), filt_frame.format(),
                    frame.imageWidth, frame.imageHeight, (ByteBuffer) frame.image[0].position(0), frame.image[0].capacity());
        }
    }
    return frame;
}

szitguy added a commit to szitguy/RecordVideoDemo that referenced this issue Oct 21, 2015
@saudet
Copy link
Member

saudet commented Oct 21, 2015

@szitguy Your fix looks to me, no need to keep the old code around. So, remove the SystemVersionUtil.hasJellyBean() check that doesn't work on Java SE anyway, and send me a pull request. I'll merge that in, thanks!

szitguy added a commit to szitguy/javacv that referenced this issue Oct 22, 2015
Replace method "pull" of class FFmpegFrameFilter to fix bug when using
it on Android4.0.
Check bytedeco/javacpp#39 for details.
@szitguy
Copy link

szitguy commented Oct 22, 2015

@saudet OK!

szitguy added a commit to szitguy/javacv that referenced this issue Oct 23, 2015
Replace method "pull" of class FFmpegFrameFilter to fix bug when using
it on Android4.0.
Check bytedeco/javacpp#39 for details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants