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

Double RTSP Stream #86

Open
MustafaKollu1975 opened this issue Feb 15, 2023 · 1 comment
Open

Double RTSP Stream #86

MustafaKollu1975 opened this issue Feb 15, 2023 · 1 comment

Comments

@MustafaKollu1975
Copy link

MustafaKollu1975 commented Feb 15, 2023

Hi Pedro,

I am confused. Where do you put video frame for feed video media codec? I can't get the structure. I am using Camera2API Can you help me?

@MustafaKollu1975
Copy link
Author

MustafaKollu1975 commented Feb 15, 2023

I want to change structure. Because I need double stream. One stream is high resolution and other stream is low resolution. I don't want to use two Video Encoder. It needs too much CPU. So, I will change structure a little simpler. Like

private final ImageReader.OnImageAvailableListener mOnGetPreviewListener
= reader -> {

	Object[] objects = measureFPS.initFPSNew(imageReaderLogFile,"Measure fps in ImageReader --> ", frameTime, frameCount, TAG);

	frameTime=(long)objects[0];
	frameCount=(int)objects[1];

	Image image = reader.acquireLatestImage();

	if (image == null){
		Log.i(TAG, "image is null: ");
	}

	else{
		final Image.Plane[] planes = image.getPlanes();
		Image.Plane yPlane = planes[0];
		Image.Plane uPlane = planes[1];
		Image.Plane vPlane = planes[2];
		byte[] mBuffer
				= yuvToBuffer(yPlane.getBuffer(),
				uPlane.getBuffer(),
				vPlane.getBuffer(),
				yPlane.getPixelStride(),
				yPlane.getRowStride(),
				uPlane.getPixelStride(),
				uPlane.getRowStride(),
				vPlane.getPixelStride(),
				vPlane.getRowStride(),
				image.getWidth(),
				image.getHeight());
		
		image.close();

		if(mStreaming){

			if (initInputBuffers){
				Log.i(TAG, "imagereader: init successful");
				inputBuffers = mMediaCodec.getInputBuffers();
				initInputBuffers =false;
			}

			long now = System.nanoTime() / 1000;

			int bufferIndex = mMediaCodec.dequeueInputBuffer(RtspServerActivity.globalBitrate);

			if (bufferIndex >= 0) {
				inputBuffers[bufferIndex].clear();
				int min = Math.min(inputBuffers[bufferIndex].capacity(), mBuffer.length);
				inputBuffers[bufferIndex].put(mBuffer, 0, min);
				mMediaCodec.queueInputBuffer(bufferIndex, 0, inputBuffers[bufferIndex].position(), now, 0);

			} else {
				mMediaCodec.queueInputBuffer(bufferIndex, 0, 0, 0, 0);
				Log.e(TAG, "No buffer available from MediaCodec!");
			}

			if (initPacketizer){
				Log.i(TAG, "imagereader: packetizer started");
				mPacketizer.setInputStream(new MediaCodecInputStream(mMediaCodec, videoFrames));
				mPacketizer.start();
				initPacketizer = false;

			}
		}
	}
};

@MustafaKollu1975 MustafaKollu1975 changed the title Video frame Double RTSP Stream Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant