@@ -1061,24 +1061,28 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u
10611061
10621062 { /* Encode */
10631063 vpx_image_t img ;
1064- img .w = 0 ;
1065- img .h = 0 ;
1066- img .d_w = 0 ;
1067- img .d_h = 0 ;
1068- if (vpx_img_alloc (& img , VPX_IMG_FMT_I420 , width , height , 0 ) == nullptr ) {
1069- pthread_mutex_unlock (call -> mutex_video );
1070- LOGGER_ERROR (av -> log , "Could not allocate image for frame" );
1071- rc = TOXAV_ERR_SEND_FRAME_INVALID ;
1072- goto RETURN ;
1064+ // TODO(Green-Sky): figure out stride_align
1065+ // TODO(Green-Sky): check memory alignment?
1066+ if (vpx_img_wrap (& img , VPX_IMG_FMT_I420 , width , height , 0 , (uint8_t * )y ) != nullptr ) {
1067+ // vpx_img_wrap assumes contigues memory, so we fix that
1068+ img .planes [VPX_PLANE_U ] = (uint8_t * )u ;
1069+ img .planes [VPX_PLANE_V ] = (uint8_t * )v ;
1070+ } else {
1071+ // call to wrap failed, falling back to copy
1072+ img .w = 0 ;
1073+ img .h = 0 ;
1074+ img .d_w = 0 ;
1075+ img .d_h = 0 ;
1076+ vpx_img_alloc (& img , VPX_IMG_FMT_I420 , width , height , 0 );
1077+
1078+ /* I420 "It comprises an NxM Y plane followed by (N/2)x(M/2) V and U planes."
1079+ * http://fourcc.org/yuv.php#IYUV
1080+ */
1081+ memcpy (img .planes [VPX_PLANE_Y ], y , width * height );
1082+ memcpy (img .planes [VPX_PLANE_U ], u , (width / 2 ) * (height / 2 ));
1083+ memcpy (img .planes [VPX_PLANE_V ], v , (width / 2 ) * (height / 2 ));
10731084 }
10741085
1075- /* I420 "It comprises an NxM Y plane followed by (N/2)x(M/2) V and U planes."
1076- * http://fourcc.org/yuv.php#IYUV
1077- */
1078- memcpy (img .planes [VPX_PLANE_Y ], y , width * height );
1079- memcpy (img .planes [VPX_PLANE_U ], u , (width / 2 ) * (height / 2 ));
1080- memcpy (img .planes [VPX_PLANE_V ], v , (width / 2 ) * (height / 2 ));
1081-
10821086 const vpx_codec_err_t vrc = vpx_codec_encode (call -> video -> encoder , & img ,
10831087 call -> video -> frame_counter , 1 , vpx_encode_flags , VPX_DL_REALTIME );
10841088
0 commit comments