1616
1717package dev .onvoid .webrtc .media .video ;
1818
19- import dev .onvoid .webrtc .media .FourCC ;
20-
2119import java .nio .ByteBuffer ;
2220
21+ import dev .onvoid .webrtc .media .FourCC ;
22+
23+ /**
24+ * Utility methods to convert between I420 video frame buffers and other pixel
25+ * formats represented by a FourCC. Delegates actual conversion work to native
26+ * methods for performance.
27+ *
28+ * @author Alex Andres
29+ */
2330public final class VideoBufferConverter {
2431
32+ /**
33+ * Convert an arbitrary {@link VideoFrameBuffer} to the specified pixel format
34+ * (given by {@code fourCC}) and write the result into a destination byte array.
35+ * <p>
36+ * The source buffer is first converted (if necessary) to an intermediate
37+ * I420 layout via {@link VideoFrameBuffer#toI420()} and then transformed.
38+ *
39+ * @param src Source video frame buffer (will be converted to I420 if not already).
40+ * @param dst Destination byte array expected to be large enough to hold the converted frame.
41+ * @param fourCC Target FourCC format identifier.
42+ *
43+ * @throws NullPointerException if {@code src} or {@code dst} is {@code null}.
44+ * @throws Exception if the native conversion fails.
45+ */
2546 public static void convertFromI420 (VideoFrameBuffer src , byte [] dst , FourCC fourCC ) throws Exception {
2647 if (src == null ) {
2748 throw new NullPointerException ("Source buffer must not be null" );
@@ -40,7 +61,21 @@ public static void convertFromI420(VideoFrameBuffer src, byte[] dst, FourCC four
4061 i420 .getWidth (), i420 .getHeight (),
4162 fourCC .value ());
4263 }
43-
64+
65+ /**
66+ * Convert an arbitrary {@link VideoFrameBuffer} to the specified pixel format
67+ * and write the result into a {@link ByteBuffer}. If the destination buffer
68+ * is a direct buffer, a native direct path is used; otherwise its backing
69+ * array (or a temporary array) is employed.
70+ *
71+ * @param src Source video frame buffer.
72+ * @param dst Writable destination {@link ByteBuffer}. Must not be read-only.
73+ * @param fourCC Target FourCC format identifier.
74+ *
75+ * @throws NullPointerException if {@code src} or {@code dst} is {@code null}.
76+ * @throws IllegalArgumentException if {@code dst} is read-only.
77+ * @throws Exception if the native conversion fails.
78+ */
4479 public static void convertFromI420 (VideoFrameBuffer src , ByteBuffer dst , FourCC fourCC ) throws Exception {
4580 if (src == null ) {
4681 throw new NullPointerException ("Source buffer must not be null" );
@@ -84,6 +119,17 @@ public static void convertFromI420(VideoFrameBuffer src, ByteBuffer dst, FourCC
84119 }
85120 }
86121
122+ /**
123+ * Convert a source frame stored in a byte array (encoded in the format indicated
124+ * by {@code fourCC}) to I420 and write the planes into the provided {@link I420Buffer}.
125+ *
126+ * @param src Source pixel data in the specified FourCC format.
127+ * @param dst Destination I420 buffer (pre-allocated).
128+ * @param fourCC FourCC describing the layout of {@code src}.
129+ *
130+ * @throws NullPointerException if {@code src} or {@code dst} is {@code null}.
131+ * @throws Exception if the native conversion fails.
132+ */
87133 public static void convertToI420 (byte [] src , I420Buffer dst , FourCC fourCC ) throws Exception {
88134 if (src == null ) {
89135 throw new NullPointerException ("Source buffer must not be null" );
@@ -101,6 +147,19 @@ public static void convertToI420(byte[] src, I420Buffer dst, FourCC fourCC) thro
101147 fourCC .value ());
102148 }
103149
150+ /**
151+ * Convert a source frame stored in a {@link ByteBuffer} (encoded in the format
152+ * specified by {@code fourCC}) to I420 and write the result into the provided
153+ * {@link I420Buffer}. Uses a direct native path for direct buffers; otherwise
154+ * reads from the backing or a temporary array.
155+ *
156+ * @param src Source pixel data buffer.
157+ * @param dst Destination I420 buffer (pre-allocated).
158+ * @param fourCC FourCC describing the layout of {@code src}.
159+ *
160+ * @throws NullPointerException if {@code src} or {@code dst} is {@code null}.
161+ * @throws Exception if the native conversion fails.
162+ */
104163 public static void convertToI420 (ByteBuffer src , I420Buffer dst , FourCC fourCC ) throws Exception {
105164 if (src == null ) {
106165 throw new NullPointerException ("Source buffer must not be null" );
0 commit comments