CameraEnumerator enumerator = new Camera1Enumerator(false);VideoCapturer videoCapturer = enumerator.createCapturer(deviceName, null);VideoSource videoSource = peerConnectionFactory.createVideoSource(false);
videoCapturer.initialize(surfaceTextureHelper, this.getApplicationContext(), videoSource.getCapturerObserver());VideoTrack localVideoTrack = peerConnectionFactory.createVideoTrack(VideoTrackID, videoSource);public void onReceive(byte[] videoBuffer, int size) {}How would I be able to send this byte array buffer via WebRTC? I'm not sure about the solution, but I think I would have to implement custom VideoCapturer?
How would I be able to send this byte array buffer via WebRTC? I'm not sure about the solution, but I think I would have to implement custom VideoCapturer?Yes, you will need to implement VideoCapturer and create VideoFrame using your []byte buffer.
public void onYuvDataReceived(MediaFormat mediaFormat, ByteBuffer yuvFrame, int dataSize, int width, int height) {
long timestampNS = TimeUnit.MILLISECONDS.toNanos(SystemClock.elapsedRealtime());
Log.d("DJIFRAME", "Got new Yuv frame " + yuvFrame + ", dataSize: " + dataSize + ", width: " + width + ", height: " + height + " at time: " + timestampNS);
NV21Buffer buffer = new NV21Buffer(yuvFrame.array(), width, height, null);
Log.d("DJIFRAME", "Start constructing video frame");
VideoFrame videoFrame = new VideoFrame(buffer, 0, timestampNS);
videoSource.getCapturerObserver().onFrameCaptured(videoFrame);
videoFrame.release();
}
In the end I didn't use custom VideoCapturer as I'm just using onFrameCaptured to register receiving frame on VideoSource. I'm receiving frames in yuvFrame, but when I construct a NV21Buffer from received yuvFrame byte array, I can see in the logs the following:
2020-04-27 14:27:13.466 29437-29890/com.amazonaws.kinesisvideo.demoapp D/DJIFRAME: Got new Yuv frame java.nio.DirectByteBuffer[pos=0 lim=3110400 cap=3110400], dataSize: 3110400, width: 1920, height: 1080 at time: 827459643000000
2020-04-27 14:27:13.466 29437-29890/com.amazonaws.kinesisvideo.demoapp D/DJIDecodeServer: releaseDecoder() start
2020-04-27 14:27:13.488 29437-29890/com.amazonaws.kinesisvideo.demoapp D/DJIDecodeServer: releaseDecoder() end
2020-04-27 14:27:13.607 29437-30146/com.amazonaws.kinesisvideo.demoapp D/CCodec: allocate(c2.qti.avc.decoder)
2020-04-27 14:27:13.607 29437-30146/com.amazonaws.kinesisvideo.demoapp I/Codec2Client: Creating a Codec2 client to service "default"
2020-04-27 14:27:13.611 29437-30146/com.amazonaws.kinesisvideo.demoapp I/Codec2Client: Client to Codec2 service "default" created
2020-04-27 14:27:13.612 29437-30146/com.amazonaws.kinesisvideo.demoapp I/CCodec: setting up 'default' as default (vendor) store
2020-04-27 14:27:13.615 29437-30146/com.amazonaws.kinesisvideo.demoapp I/CCodec: Created component [c2.qti.avc.decoder]
2020-04-27 14:27:13.615 29437-30146/com.amazonaws.kinesisvideo.demoapp D/CCodecConfig: read media type: video/avc
2020-04-27 14:27:13.616 29437-30146/com.amazonaws.kinesisvideo.demoapp D/ReflectedParamUpdater: extent() != 1 for single value type: output.buffers.pool-ids.values
2020-04-27 14:27:13.621 29437-30146/com.amazonaws.kinesisvideo.demoapp D/CCodecConfig: ignoring local param raw.size (0xd2001800) as it is already supported
2020-04-27 14:27:13.621 29437-30146/com.amazonaws.kinesisvideo.demoapp D/CCodecConfig: ignoring local param raw.color (0xd2001809) as it is already supported
2020-04-27 14:27:13.621 29437-30146/com.amazonaws.kinesisvideo.demoapp D/CCodecConfig: ignoring local param raw.hdr-static-info (0xd200180a) as it is already supported
2020-04-27 14:27:13.622 29437-30146/com.amazonaws.kinesisvideo.demoapp I/CCodecConfig: query failed after returning 17 values (BAD_INDEX)
2020-04-27 14:27:13.623 29437-30146/com.amazonaws.kinesisvideo.demoapp D/CCodecConfig: c2 config diff is Dict {
c2::i32 algo.priority.value = -1
c2::float algo.rate.value = 4.2039e-44
c2::u32 algo.secure-mode.value = 0
c2::float coded.frame-rate.value = 30
c2::u32 coded.pl.level = 20480
c2::u32 coded.pl.profile = 20480
c2::u32 coded.vui.color.matrix = 0
c2::u32 coded.vui.color.primaries = 0
c2::u32 coded.vui.color.range = 0
c2::u32 coded.vui.color.transfer = 0
c2::u32 default.color.matrix = 0
c2::u32 default.color.primaries = 3
c2::u32 default.color.range = 2
c2::u32 default.color.transfer = 0
c2::u32 input.buffers.max-size.value = 13271040
c2::u32 input.delay.value = 4
string input.media-type.value = "video/avc"
c2::u32 output.delay.value = 18
string output.media-type.value = "video/raw"
c2::u32 raw.color.matrix = 0
c2::u32 raw.color.primaries = 0
c2::u32 raw.color.range = 0
c2::u32 raw.color.transfer = 0
c2::float raw.hdr-static-info.mastering.blue.x = 1.4013e-45
c2::float raw.hdr-static-info.mastering.blue.y = 1.4013e-45
c2::float raw.hdr-
2020-04-27 14:27:13.623 29437-30146/com.amazonaws.kinesisvideo.demoapp W/ColorUtils: expected specified color aspects (0:0:0:0)
2020-04-27 14:27:13.625 29437-29890/com.amazonaws.kinesisvideo.demoapp E/VideoDecoder: initVideoDecoder create
2020-04-27 14:27:13.626 29437-30146/com.amazonaws.kinesisvideo.demoapp D/CCodecConfig: no c2 equivalents for color-format
2020-04-27 14:27:13.626 29437-30146/com.amazonaws.kinesisvideo.demoapp D/CCodecConfig: no c2 equivalents for flags
2020-04-27 14:27:13.628 29437-30146/com.amazonaws.kinesisvideo.demoapp D/CCodecConfig: c2 config diff is c2::u32 raw.pixel-format.value = 842094169
c2::u32 raw.size.height = 1088
2020-04-27 14:27:13.628 29437-30146/com.amazonaws.kinesisvideo.demoapp W/ColorUtils: expected specified color aspects (0:0:0:0)
2020-04-27 14:27:13.629 29437-30146/com.amazonaws.kinesisvideo.demoapp W/Codec2Client: query -- param skipped: index = 1107298332.
2020-04-27 14:27:13.629 29437-30146/com.amazonaws.kinesisvideo.demoapp D/CCodec: setup formats input: AMessage(what = 0x00000000) = {
int32_t feature-secure-playback = 0
int32_t frame-rate = 30
int32_t height = 1088
int32_t level = 1
int32_t max-input-size = 3317760
string mime = "video/avc"
int32_t priority = 1
int32_t profile = 1
int32_t width = 1920
Rect crop(0, 0, 1919, 1087)
} and output: AMessage(what = 0x00000000) = {
int32_t android._video-scaling = 1
Rect crop(0, 0, 1919, 1087)
int32_t color-standard = 0
int32_t color-range = 0
int32_t color-transfer = 0
int32_t android._dataspace = 0
int32_t width = 1920
int32_t feature-secure-playback = 0
int32_t frame-rate = 30
int32_t height = 1088
int32_t max-height = 1080
int32_t max-width = 1920
string mime = "video/raw"
int32_t priority = 1
int32_t rotation-degrees = 0
Buffer hdr-static-info = {
00000000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000010: 00 00 00 00 00 00 00 00 00 .........
}
int32_t android._color-format =
2020-04-27 14:27:13.630 29437-29890/com.amazonaws.kinesisvideo.demoapp E/VideoDecoder: initVideoDecoder configure
2020-04-27 14:27:13.630 29437-30145/com.amazonaws.kinesisvideo.demoapp I/MediaCodec: MediaCodec will operate in async mode
2020-04-27 14:27:13.652 29437-30146/com.amazonaws.kinesisvideo.demoapp W/Codec2Client: query -- param skipped: index = 1342179345.
2020-04-27 14:27:13.653 29437-30146/com.amazonaws.kinesisvideo.demoapp W/Codec2Client: query -- param skipped: index = 2415921170.
2020-04-27 14:27:13.653 29437-30146/com.amazonaws.kinesisvideo.demoapp W/Codec2Client: query -- param skipped: index = 1610614798.
2020-04-27 14:27:13.653 29437-30146/com.amazonaws.kinesisvideo.demoapp D/CCodecBufferChannel: [c2.qti.avc.decoder#355] Query input allocators returned 0 params => BAD_INDEX (6)
2020-04-27 14:27:13.654 29437-30146/com.amazonaws.kinesisvideo.demoapp D/CCodecBufferChannel: [c2.qti.avc.decoder#355] Created input block pool with allocatorID 16 => poolID 42 - OK (0)
2020-04-27 14:27:13.655 29437-30146/com.amazonaws.kinesisvideo.demoapp D/CCodecBufferChannel: [c2.qti.avc.decoder#355] Query output allocators returned 0 params => BAD_INDEX (6)
2020-04-27 14:27:13.655 29437-30146/com.amazonaws.kinesisvideo.demoapp D/CCodecBufferChannel: [c2.qti.avc.decoder#355] Configured output block pool ids 1 => OK
2020-04-27 14:27:13.715 29437-30146/com.amazonaws.kinesisvideo.demoapp D/CCodecConfig: c2 config diff is c2::u32 raw.color.matrix = 1
c2::u32 raw.color.primaries = 1
c2::u32 raw.color.range = 2
c2::u32 raw.color.transfer = 3
c2::u32 raw.crop.height = 1080
c2::u32 raw.crop.left = 0
c2::u32 raw.crop.top = 0
c2::u32 raw.crop.width = 1920
c2::u32 raw.size.height = 1080
2020-04-27 14:27:13.715 29437-30146/com.amazonaws.kinesisvideo.demoapp D/CCodecBufferChannel: [c2.qti.avc.decoder#355] onWorkDone: output format changed to AMessage(what = 0x00000000) = {
int32_t android._video-scaling = 1
Rect crop(0, 0, 1919, 1079)
int32_t color-standard = 1
int32_t color-range = 2
int32_t color-transfer = 3
int32_t android._dataspace = 260
int32_t width = 1920
int32_t feature-secure-playback = 0
int32_t frame-rate = 30
int32_t height = 1080
int32_t max-height = 1080
int32_t max-width = 1920
string mime = "video/raw"
int32_t priority = 1
int32_t rotation-degrees = 0
Buffer hdr-static-info = {
00000000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000010: 00 00 00 00 00 00 00 00 00 .........
}
int32_t android._color-format = 2135033992
int32_t color-format = 19
}
2020-04-27 14:27:13.743 29437-30146/com.amazonaws.kinesisvideo.demoapp D/CCodecBuffers: [c2.qti.avc.decoder#355:2D-BB-Output] updating image-data
2020-04-27 14:27:13.743 29437-30146/com.amazonaws.kinesisvideo.demoapp D/CCodecBuffers: [c2.qti.avc.decoder#355:2D-BB-Output] updating stride = 1920
2020-04-27 14:27:13.743 29437-30146/com.amazonaws.kinesisvideo.demoapp D/CCodecBuffers: [c2.qti.avc.decoder#355:2D-BB-Output] updating vstride = 1080
2020-04-27 14:27:13.746 29437-29890/com.amazonaws.kinesisvideo.demoapp E/DJIDecodeServer: dequeueOutputBuffer INFO_OUTPUT_FORMAT_CHANGED