@@ -1072,24 +1072,28 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u
10721072
10731073 { /* Encode */
10741074 vpx_image_t img ;
1075- img .w = 0 ;
1076- img .h = 0 ;
1077- img .d_w = 0 ;
1078- img .d_h = 0 ;
1079- if (vpx_img_alloc (& img , VPX_IMG_FMT_I420 , width , height , 0 ) == nullptr ) {
1080- pthread_mutex_unlock (call -> mutex_video );
1081- LOGGER_ERROR (av -> log , "Could not allocate image for frame" );
1082- rc = TOXAV_ERR_SEND_FRAME_INVALID ;
1083- goto RETURN ;
1075+ // TODO(Green-Sky): figure out stride_align
1076+ // TODO(Green-Sky): check memory alignment?
1077+ if (vpx_img_wrap (& img , VPX_IMG_FMT_I420 , width , height , 0 , (uint8_t * )y ) != nullptr ) {
1078+ // vpx_img_wrap assumes contigues memory, so we fix that
1079+ img .planes [VPX_PLANE_U ] = (uint8_t * )u ;
1080+ img .planes [VPX_PLANE_V ] = (uint8_t * )v ;
1081+ } else {
1082+ // call to wrap failed, falling back to copy
1083+ img .w = 0 ;
1084+ img .h = 0 ;
1085+ img .d_w = 0 ;
1086+ img .d_h = 0 ;
1087+ vpx_img_alloc (& img , VPX_IMG_FMT_I420 , width , height , 0 );
1088+
1089+ /* I420 "It comprises an NxM Y plane followed by (N/2)x(M/2) V and U planes."
1090+ * http://fourcc.org/yuv.php#IYUV
1091+ */
1092+ memcpy (img .planes [VPX_PLANE_Y ], y , width * height );
1093+ memcpy (img .planes [VPX_PLANE_U ], u , (width / 2 ) * (height / 2 ));
1094+ memcpy (img .planes [VPX_PLANE_V ], v , (width / 2 ) * (height / 2 ));
10841095 }
10851096
1086- /* I420 "It comprises an NxM Y plane followed by (N/2)x(M/2) V and U planes."
1087- * http://fourcc.org/yuv.php#IYUV
1088- */
1089- memcpy (img .planes [VPX_PLANE_Y ], y , width * height );
1090- memcpy (img .planes [VPX_PLANE_U ], u , (width / 2 ) * (height / 2 ));
1091- memcpy (img .planes [VPX_PLANE_V ], v , (width / 2 ) * (height / 2 ));
1092-
10931097 const vpx_codec_err_t vrc = vpx_codec_encode (call -> video -> encoder , & img ,
10941098 call -> video -> frame_counter , 1 , vpx_encode_flags , MAX_ENCODE_TIME_US );
10951099
0 commit comments