YUV/NV21 drawing

Open
#13 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
android, java

Research direction

Read JavaI420Buffer, VideoFrameDrawer, and EglRenderer from the reported stack, then trace how SurfaceViewRenderer.onFrame handles supplied buffers across successive callbacks. Reproduce the second-frame failure with the custom YUV callback; done means consecutive frames render without “buffer is inaccessible” and the buffer ownership behavior is covered by a test or documented.

Written by the indexing model from the issue text.

Description

I have some rendering issue in fact isolated from WebRTC protocol, but related to this lib... I want to draw raw YUV frames, which are live video Full HD 30 fps obtained from some 3rd party

I've placed SurfaceViewRenderer in my Fragment and in onCreateView

    mSurfaceViewRenderer = rootView.findViewById(R.id.surfaceViewRenderer);
    mSurfaceViewRenderer.init(EglBase.create().getEglBaseContext(), null);

and I'm trying to feed this surface with prepared frames (callback called in own Thread, not main) like below:

@Override
public void onYuvDataByteBuffer(MediaFormat mediaFormat, ByteBuffer data, int dataSize, int width, int height) {
	int rowStrideY = width;
	int rowStrideU = width / 2;
	int rowStrideV = width / 2;

	int basicOffset = data.remaining() / 6;
	int offsetY = 0;
	int offsetU = basicOffset * 4;
	int offsetV = basicOffset * 5;

	ByteBuffer i420ByteBuffer = data;
	i420ByteBuffer.position(offsetY);
	final ByteBuffer dataY = i420ByteBuffer.slice();
	i420ByteBuffer.position(offsetU);
	final ByteBuffer dataU = i420ByteBuffer.slice();
	i420ByteBuffer.position(offsetV);
	final ByteBuffer dataV = i420ByteBuffer.slice();

	JavaI420Buffer javaI420Buffer = JavaI420Buffer.wrap(width, height,
			dataY, rowStrideY,
			dataU, rowStrideU,
			dataV, rowStrideV,
			null
			/*() -> {
					JniCommon.nativeFreeByteBuffer(i420ByteBuffer);
	}*/);

	VideoFrame frame = new VideoFrame(javaI420Buffer, 0, System.currentTimeMillis());
	mSurfaceViewRenderer.onFrame(frame);
}

yes, some ugly hardcodes for now, but it works, kind of... first frame is rendered properly, no issues. but second call will further cause a throw

FATAL EXCEPTION: SurfaceViewRendererEglRenderer
   Process: thats.my.package, PID: 12970
   java.lang.IllegalStateException: buffer is inaccessible
	at java.nio.DirectByteBuffer.slice(DirectByteBuffer.java:159)
	at org.webrtc.JavaI420Buffer.getDataY(JavaI420Buffer.java:118)
	at org.webrtc.VideoFrameDrawer$YuvUploader.uploadFromBuffer(VideoFrameDrawer.java:114)
	at org.webrtc.VideoFrameDrawer.drawFrame(VideoFrameDrawer.java:221)
	at org.webrtc.EglRenderer.renderFrameOnRenderThread(EglRenderer.java:664)
	at org.webrtc.EglRenderer.lambda$im8Sa54i366ODPy-soB9Bg4O-w4(Unknown Source:0)
	at org.webrtc.-$$Lambda$EglRenderer$im8Sa54i366ODPy-soB9Bg4O-w4.run(Unknown Source:2)
	at android.os.Handler.handleCallback(Handler.java:883)
	at android.os.Handler.dispatchMessage(Handler.java:100)
	at org.webrtc.EglRenderer$HandlerWithExceptionCallback.dispatchMessage(EglRenderer.java:103)
	at android.os.Looper.loop(Looper.java:214)
	at android.os.HandlerThread.run(HandlerThread.java:67

that happens with your dependency as well as with official current release (1.0.+), but I'm just glad I've found a space where I can post my problem and I do believe someone with knowledge will read this in here :)

so: is there a way to use WebRTC lib just for drawing YUV, as it contains all needed breadcrumbs for sure? Currently it looks to me like rendering part of code is tightened to protocol and API methods/ways for obtaining video (from stream or file, not from some custom callback). Maybe there is some sample somewhere showing built-in Camera preview rendered "manually", not by setPreviewSurface?

btw. more details and tries in my SO question, currently with bounty :)

Dominant language
Kotlin
Stars
890
Forks
109
Avg merge
11m
Merged PRs (30d)
2

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from GetStream/webrtc-android

All issues in GetStream/webrtc-android

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.