fork/rust-sdks
git clone https://git.julia.blue/fork/rust-sdks
2487755
main
1/* 2* Copyright 2023 LiveKit 3* 4* Licensed under the Apache License, Version 2.0 (the “License”); 5* you may not use this file except in compliance with the License. 6* You may obtain a copy of the License at 7* 8* http://www.apache.org/licenses/LICENSE-2.0 9* 10* Unless required by applicable law or agreed to in writing, software 11* distributed under the License is distributed on an “AS IS” BASIS, 12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13* See the License for the specific language governing permissions and 14* limitations under the License. 15*/ 16 17#pragma once 18 19#include <memory> 20 21#include "api/video/i420_buffer.h" 22#include "api/video/i422_buffer.h" 23#include "api/video/i444_buffer.h" 24#include "api/video/i010_buffer.h" 25#include "api/video/nv12_buffer.h" 26#include "api/video/video_frame_buffer.h" 27 28namespace livekit { 29class VideoFrameBuffer ; 30class PlanarYuvBuffer ; 31class PlanarYuv8Buffer ; 32class PlanarYuv16BBuffer ; 33class BiplanarYuvBuffer ; 34class BiplanarYuv8Buffer ; 35class I420Buffer ; 36class I420ABuffer ; 37class I422Buffer ; 38class I444Buffer ; 39class I010Buffer ; 40class NV12Buffer ; 41}// namespace livekit 42 43#ifdef __APPLE__ 44#include <CoreVideo/CoreVideo.h> 45namespace livekit { 46typedef __CVBuffer PlatformImageBuffer ; 47}// namespace livekit 48#else 49namespace livekit { 50typedef void PlatformImageBuffer ; 51}// namespace livekit 52#endif 53 54#include "webrtc-sys/src/video_frame_buffer.rs.h" 55 56namespace livekit { 57 58class VideoFrameBuffer { 59public : 60explicit VideoFrameBuffer ( 61rtc ::scoped_refptr < webrtc ::VideoFrameBuffer > buffer ); 62 63VideoFrameBufferType buffer_type ()const ; 64 65unsigned int width ()const ; 66 unsignedint height ()const ; 67 68std ::unique_ptr < I420Buffer > to_i420 ()const ; 69 70// Requires ownership 71std ::unique_ptr < I420Buffer > get_i420 (); 72std ::unique_ptr < I420ABuffer > get_i420a (); 73std ::unique_ptr < I422Buffer > get_i422 (); 74std ::unique_ptr < I444Buffer > get_i444 (); 75std ::unique_ptr < I010Buffer > get_i010 (); 76std ::unique_ptr < NV12Buffer > get_nv12 (); 77rtc ::scoped_refptr < webrtc ::VideoFrameBuffer > get ()const ; 78 79protected : 80rtc ::scoped_refptr < webrtc ::VideoFrameBuffer > buffer_ ; 81}; 82 83class PlanarYuvBuffer :public VideoFrameBuffer { 84public : 85explicit PlanarYuvBuffer (rtc ::scoped_refptr < webrtc ::PlanarYuvBuffer > buffer ); 86 87unsigned int chroma_width ()const ; 88unsigned int chroma_height ()const ; 89 90 unsignedint stride_y ()const ; 91 unsignedint stride_u ()const ; 92 unsignedint stride_v ()const ; 93 94private : 95webrtc ::PlanarYuvBuffer * buffer ()const ; 96}; 97 98class PlanarYuv8Buffer :public PlanarYuvBuffer { 99public : 100explicit PlanarYuv8Buffer ( 101rtc ::scoped_refptr < webrtc ::PlanarYuv8Buffer > buffer ); 102 103const uint8_t * data_y ()const ; 104const uint8_t * data_u ()const ; 105const uint8_t * data_v ()const ; 106 107private : 108webrtc ::PlanarYuv8Buffer * buffer ()const ; 109}; 110 111class PlanarYuv16BBuffer :public PlanarYuvBuffer { 112public : 113explicit PlanarYuv16BBuffer ( 114rtc ::scoped_refptr < webrtc ::PlanarYuv16BBuffer > buffer ); 115 116const uint16_t * data_y ()const ; 117const uint16_t * data_u ()const ; 118const uint16_t * data_v ()const ; 119 120private : 121webrtc ::PlanarYuv16BBuffer * buffer ()const ; 122}; 123 124class BiplanarYuvBuffer :public VideoFrameBuffer { 125public : 126explicit BiplanarYuvBuffer ( 127rtc ::scoped_refptr < webrtc ::BiplanarYuvBuffer > buffer ); 128 129unsigned int chroma_width ()const ; 130unsigned int chroma_height ()const ; 131 132 unsignedint stride_y ()const ; 133 unsignedint stride_uv ()const ; 134 135private : 136webrtc ::BiplanarYuvBuffer * buffer ()const ; 137}; 138 139class BiplanarYuv8Buffer :public BiplanarYuvBuffer { 140public : 141explicit BiplanarYuv8Buffer ( 142rtc ::scoped_refptr < webrtc ::BiplanarYuv8Buffer > buffer ); 143 144const uint8_t * data_y ()const ; 145const uint8_t * data_uv ()const ; 146 147private : 148webrtc ::BiplanarYuv8Buffer * buffer ()const ; 149}; 150 151class I420Buffer :public PlanarYuv8Buffer { 152public : 153explicit I420Buffer (rtc ::scoped_refptr < webrtc ::I420BufferInterface > buffer ); 154}; 155 156class I420ABuffer :public I420Buffer { 157public : 158explicit I420ABuffer (rtc ::scoped_refptr < webrtc ::I420ABufferInterface > buffer ); 159 160unsigned int stride_a ()const ; 161const uint8_t * data_a ()const ; 162 163private : 164webrtc ::I420ABufferInterface * buffer ()const ; 165}; 166 167class I422Buffer :public PlanarYuv8Buffer { 168public : 169explicit I422Buffer (rtc ::scoped_refptr < webrtc ::I422BufferInterface > buffer ); 170}; 171 172class I444Buffer :public PlanarYuv8Buffer { 173public : 174explicit I444Buffer (rtc ::scoped_refptr < webrtc ::I444BufferInterface > buffer ); 175}; 176 177class I010Buffer :public PlanarYuv16BBuffer { 178public : 179explicit I010Buffer (rtc ::scoped_refptr < webrtc ::I010BufferInterface > buffer ); 180}; 181 182class NV12Buffer :public BiplanarYuv8Buffer { 183public : 184explicit NV12Buffer (rtc ::scoped_refptr < webrtc ::NV12BufferInterface > buffer ); 185}; 186 187std ::unique_ptr < I420Buffer > copy_i420_buffer ( 188const std ::unique_ptr < I420Buffer >& i420 ); 189std ::unique_ptr < I420Buffer > new_i420_buffer (int width ,int height ,int stride_y ,int stride_u ,int stride_v ); 190std ::unique_ptr < I422Buffer > new_i422_buffer (int width ,int height ,int stride_y ,int stride_u ,int stride_v ); 191std ::unique_ptr < I444Buffer > new_i444_buffer (int width ,int height ,int stride_y ,int stride_u ,int stride_v ); 192std ::unique_ptr < I010Buffer > new_i010_buffer (int width ,int height ,int stride_y ,int stride_u ,int stride_v ); 193std ::unique_ptr < NV12Buffer > new_nv12_buffer (int width ,int height ,int stride_y ,int stride_uv ); 194 195std ::unique_ptr < VideoFrameBuffer > new_native_buffer_from_platform_image_buffer (PlatformImageBuffer * buffer ); 196PlatformImageBuffer * native_buffer_to_platform_image_buffer (const std ::unique_ptr < VideoFrameBuffer > & ); 197 198static const VideoFrameBuffer * yuv_to_vfb (const PlanarYuvBuffer * yuv ) { 199return yuv ; 200} 201 202static const VideoFrameBuffer * biyuv_to_vfb (const BiplanarYuvBuffer * biyuv ) { 203return biyuv ; 204} 205 206static const PlanarYuvBuffer * yuv8_to_yuv (const PlanarYuv8Buffer * yuv8 ) { 207return yuv8 ; 208} 209 210static const PlanarYuvBuffer * yuv16b_to_yuv (const PlanarYuv16BBuffer * yuv16 ) { 211return yuv16 ; 212} 213 214static const BiplanarYuvBuffer * biyuv8_to_biyuv ( 215const BiplanarYuv8Buffer * biyuv8 ) { 216return biyuv8 ; 217} 218 219static const PlanarYuv8Buffer * i420_to_yuv8 (const I420Buffer * i420 ) { 220return i420 ; 221} 222 223static const PlanarYuv8Buffer * i420a_to_yuv8 (const I420ABuffer * i420a ) { 224return i420a ; 225} 226 227static const PlanarYuv8Buffer * i422_to_yuv8 (const I422Buffer * i422 ) { 228return i422 ; 229} 230 231static const PlanarYuv8Buffer * i444_to_yuv8 (const I444Buffer * i444 ) { 232return i444 ; 233} 234 235static const PlanarYuv16BBuffer * i010_to_yuv16b (const I010Buffer * i010 ) { 236return i010 ; 237} 238 239static const BiplanarYuv8Buffer * nv12_to_biyuv8 (const NV12Buffer * nv12 ) { 240return nv12 ; 241} 242 243static std ::unique_ptr < VideoFrameBuffer > _unique_video_frame_buffer () { 244return nullptr ; 245} 246 247}// namespace livekit