| 1 | // Copyright 2025 LiveKit, Inc. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #[allow(clippy::too_many_arguments)] |
| 16 | #[allow(clippy::missing_safety_doc)] |
| 17 | #[cxx::bridge(namespace = "livekit_ffi")] |
| 18 | pub mod ffi { |
| 19 | unsafe extern "C++" { |
| 20 | include!("livekit/yuv_helper.h"); |
| 21 | |
| 22 | unsafe fn i420_to_argb( |
| 23 | src_y: *const u8, |
| 24 | src_stride_y: i32, |
| 25 | src_u: *const u8, |
| 26 | src_stride_u: i32, |
| 27 | src_v: *const u8, |
| 28 | src_stride_v: i32, |
| 29 | dst_argb: *mut u8, |
| 30 | dst_stride_argb: i32, |
| 31 | width: i32, |
| 32 | height: i32, |
| 33 | ) -> Result<()>; |
| 34 | |
| 35 | unsafe fn i420_to_bgra( |
| 36 | src_y: *const u8, |
| 37 | src_stride_y: i32, |
| 38 | src_u: *const u8, |
| 39 | src_stride_u: i32, |
| 40 | src_v: *const u8, |
| 41 | src_stride_v: i32, |
| 42 | dst_bgra: *mut u8, |
| 43 | dst_stride_bgra: i32, |
| 44 | width: i32, |
| 45 | height: i32, |
| 46 | ) -> Result<()>; |
| 47 | |
| 48 | unsafe fn i420_to_abgr( |
| 49 | src_y: *const u8, |
| 50 | src_stride_y: i32, |
| 51 | src_u: *const u8, |
| 52 | src_stride_u: i32, |
| 53 | src_v: *const u8, |
| 54 | src_stride_v: i32, |
| 55 | dst_abgr: *mut u8, |
| 56 | dst_stride_abgr: i32, |
| 57 | width: i32, |
| 58 | height: i32, |
| 59 | ) -> Result<()>; |
| 60 | |
| 61 | unsafe fn i420_to_rgba( |
| 62 | src_y: *const u8, |
| 63 | src_stride_y: i32, |
| 64 | src_u: *const u8, |
| 65 | src_stride_u: i32, |
| 66 | src_v: *const u8, |
| 67 | src_stride_v: i32, |
| 68 | dst_rgba: *mut u8, |
| 69 | dst_stride_rgba: i32, |
| 70 | width: i32, |
| 71 | height: i32, |
| 72 | ) -> Result<()>; |
| 73 | |
| 74 | unsafe fn argb_to_i420( |
| 75 | src_argb: *const u8, |
| 76 | src_stride_argb: i32, |
| 77 | dst_y: *mut u8, |
| 78 | dst_stride_y: i32, |
| 79 | dst_u: *mut u8, |
| 80 | dst_stride_u: i32, |
| 81 | dst_v: *mut u8, |
| 82 | dst_stride_v: i32, |
| 83 | width: i32, |
| 84 | height: i32, |
| 85 | ) -> Result<()>; |
| 86 | |
| 87 | unsafe fn abgr_to_i420( |
| 88 | src_abgr: *const u8, |
| 89 | src_stride_abgr: i32, |
| 90 | dst_y: *mut u8, |
| 91 | dst_stride_y: i32, |
| 92 | dst_u: *mut u8, |
| 93 | dst_stride_u: i32, |
| 94 | dst_v: *mut u8, |
| 95 | dst_stride_v: i32, |
| 96 | width: i32, |
| 97 | height: i32, |
| 98 | ) -> Result<()>; |
| 99 | |
| 100 | unsafe fn argb_to_rgb24( |
| 101 | src_argb: *const u8, |
| 102 | src_stride_argb: i32, |
| 103 | dst_rgb24: *mut u8, |
| 104 | dst_stride_rgb24: i32, |
| 105 | width: i32, |
| 106 | height: i32, |
| 107 | ) -> Result<()>; |
| 108 | |
| 109 | unsafe fn nv12_to_i420( |
| 110 | src_y: *const u8, |
| 111 | src_stride_y: i32, |
| 112 | src_uv: *const u8, |
| 113 | src_stride_uv: i32, |
| 114 | dst_y: *mut u8, |
| 115 | dst_stride_y: i32, |
| 116 | dst_u: *mut u8, |
| 117 | dst_stride_u: i32, |
| 118 | dst_v: *mut u8, |
| 119 | dst_stride_v: i32, |
| 120 | width: i32, |
| 121 | height: i32, |
| 122 | ) -> Result<()>; |
| 123 | |
| 124 | unsafe fn i420_to_nv12( |
| 125 | src_y: *const u8, |
| 126 | src_stride_y: i32, |
| 127 | src_u: *const u8, |
| 128 | src_stride_u: i32, |
| 129 | src_v: *const u8, |
| 130 | src_stride_v: i32, |
| 131 | dst_y: *mut u8, |
| 132 | dst_stride_y: i32, |
| 133 | dst_uv: *mut u8, |
| 134 | dst_stride_uv: i32, |
| 135 | width: i32, |
| 136 | height: i32, |
| 137 | ) -> Result<()>; |
| 138 | |
| 139 | unsafe fn i444_to_i420( |
| 140 | src_y: *const u8, |
| 141 | src_stride_y: i32, |
| 142 | src_u: *const u8, |
| 143 | src_stride_u: i32, |
| 144 | src_v: *const u8, |
| 145 | src_stride_v: i32, |
| 146 | dst_y: *mut u8, |
| 147 | dst_stride_y: i32, |
| 148 | dst_u: *mut u8, |
| 149 | dst_stride_u: i32, |
| 150 | dst_v: *mut u8, |
| 151 | dst_stride_v: i32, |
| 152 | width: i32, |
| 153 | height: i32, |
| 154 | ) -> Result<()>; |
| 155 | |
| 156 | unsafe fn i422_to_i420( |
| 157 | src_y: *const u8, |
| 158 | src_stride_y: i32, |
| 159 | src_u: *const u8, |
| 160 | src_stride_u: i32, |
| 161 | src_v: *const u8, |
| 162 | src_stride_v: i32, |
| 163 | dst_y: *mut u8, |
| 164 | dst_stride_y: i32, |
| 165 | dst_u: *mut u8, |
| 166 | dst_stride_u: i32, |
| 167 | dst_v: *mut u8, |
| 168 | dst_stride_v: i32, |
| 169 | width: i32, |
| 170 | height: i32, |
| 171 | ) -> Result<()>; |
| 172 | |
| 173 | unsafe fn i010_to_i420( |
| 174 | src_y: *const u16, |
| 175 | src_stride_y: i32, |
| 176 | src_u: *const u16, |
| 177 | src_stride_u: i32, |
| 178 | src_v: *const u16, |
| 179 | src_stride_v: i32, |
| 180 | dst_y: *mut u8, |
| 181 | dst_stride_y: i32, |
| 182 | dst_u: *mut u8, |
| 183 | dst_stride_u: i32, |
| 184 | dst_v: *mut u8, |
| 185 | dst_stride_v: i32, |
| 186 | width: i32, |
| 187 | height: i32, |
| 188 | ) -> Result<()>; |
| 189 | |
| 190 | unsafe fn nv12_to_argb( |
| 191 | src_y: *const u8, |
| 192 | src_stride_y: i32, |
| 193 | src_uv: *const u8, |
| 194 | src_stride_uv: i32, |
| 195 | dst_argb: *mut u8, |
| 196 | dst_stride_argb: i32, |
| 197 | width: i32, |
| 198 | height: i32, |
| 199 | ) -> Result<()>; |
| 200 | |
| 201 | unsafe fn nv12_to_abgr( |
| 202 | src_y: *const u8, |
| 203 | src_stride_y: i32, |
| 204 | src_uv: *const u8, |
| 205 | src_stride_uv: i32, |
| 206 | dst_abgr: *mut u8, |
| 207 | dst_stride_abgr: i32, |
| 208 | width: i32, |
| 209 | height: i32, |
| 210 | ) -> Result<()>; |
| 211 | |
| 212 | unsafe fn i444_to_argb( |
| 213 | src_y: *const u8, |
| 214 | src_stride_y: i32, |
| 215 | src_u: *const u8, |
| 216 | src_stride_u: i32, |
| 217 | src_v: *const u8, |
| 218 | src_stride_v: i32, |
| 219 | dst_abgr: *mut u8, |
| 220 | dst_stride_abgr: i32, |
| 221 | width: i32, |
| 222 | height: i32, |
| 223 | ) -> Result<()>; |
| 224 | |
| 225 | unsafe fn i444_to_abgr( |
| 226 | src_y: *const u8, |
| 227 | src_stride_y: i32, |
| 228 | src_u: *const u8, |
| 229 | src_stride_u: i32, |
| 230 | src_v: *const u8, |
| 231 | src_stride_v: i32, |
| 232 | dst_abgr: *mut u8, |
| 233 | dst_stride_abgr: i32, |
| 234 | width: i32, |
| 235 | height: i32, |
| 236 | ) -> Result<()>; |
| 237 | |
| 238 | unsafe fn i422_to_argb( |
| 239 | src_y: *const u8, |
| 240 | src_stride_y: i32, |
| 241 | src_u: *const u8, |
| 242 | src_stride_u: i32, |
| 243 | src_v: *const u8, |
| 244 | src_stride_v: i32, |
| 245 | dst_argb: *mut u8, |
| 246 | dst_stride_argb: i32, |
| 247 | width: i32, |
| 248 | height: i32, |
| 249 | ) -> Result<()>; |
| 250 | |
| 251 | unsafe fn i422_to_abgr( |
| 252 | src_y: *const u8, |
| 253 | src_stride_y: i32, |
| 254 | src_u: *const u8, |
| 255 | src_stride_u: i32, |
| 256 | src_v: *const u8, |
| 257 | src_stride_v: i32, |
| 258 | dst_abgr: *mut u8, |
| 259 | dst_stride_abgr: i32, |
| 260 | width: i32, |
| 261 | height: i32, |
| 262 | ) -> Result<()>; |
| 263 | |
| 264 | unsafe fn i010_to_argb( |
| 265 | src_y: *const u16, |
| 266 | src_stride_y: i32, |
| 267 | src_u: *const u16, |
| 268 | src_stride_u: i32, |
| 269 | src_v: *const u16, |
| 270 | src_stride_v: i32, |
| 271 | dst_argb: *mut u8, |
| 272 | dst_stride_argb: i32, |
| 273 | width: i32, |
| 274 | height: i32, |
| 275 | ) -> Result<()>; |
| 276 | |
| 277 | unsafe fn i010_to_abgr( |
| 278 | src_y: *const u16, |
| 279 | src_stride_y: i32, |
| 280 | src_u: *const u16, |
| 281 | src_stride_u: i32, |
| 282 | src_v: *const u16, |
| 283 | src_stride_v: i32, |
| 284 | dst_abgr: *mut u8, |
| 285 | dst_stride_abgr: i32, |
| 286 | width: i32, |
| 287 | height: i32, |
| 288 | ) -> Result<()>; |
| 289 | |
| 290 | unsafe fn abgr_to_nv12( |
| 291 | src_abgr: *const u8, |
| 292 | src_stride_abgr: i32, |
| 293 | dst_y: *mut u8, |
| 294 | dst_stride_y: i32, |
| 295 | dst_uv: *mut u8, |
| 296 | dst_stride_uv: i32, |
| 297 | width: i32, |
| 298 | height: i32, |
| 299 | ) -> Result<()>; |
| 300 | |
| 301 | unsafe fn argb_to_nv12( |
| 302 | src_argb: *const u8, |
| 303 | src_stride_argb: i32, |
| 304 | dst_y: *mut u8, |
| 305 | dst_stride_y: i32, |
| 306 | dst_uv: *mut u8, |
| 307 | dst_stride_uv: i32, |
| 308 | width: i32, |
| 309 | height: i32, |
| 310 | ) -> Result<()>; |
| 311 | |
| 312 | unsafe fn yuy2_to_i420( |
| 313 | src_yuy2: *const u8, |
| 314 | src_stride_yuy2: i32, |
| 315 | dst_y: *mut u8, |
| 316 | dst_stride_y: i32, |
| 317 | dst_u: *mut u8, |
| 318 | dst_stride_u: i32, |
| 319 | dst_v: *mut u8, |
| 320 | dst_stride_v: i32, |
| 321 | width: i32, |
| 322 | height: i32, |
| 323 | ) -> Result<()>; |
| 324 | |
| 325 | unsafe fn argb_scale( |
| 326 | src_argb: *const u8, |
| 327 | src_stride_argb: i32, |
| 328 | src_width: i32, |
| 329 | src_height: i32, |
| 330 | dst_argb: *mut u8, |
| 331 | dst_stride_argb: i32, |
| 332 | dst_width: i32, |
| 333 | dst_height: i32, |
| 334 | ) -> Result<()>; |
| 335 | } |
| 336 | } |