@@ -495,17 +495,26 @@ int vc_encode(VCSession *vc, uint16_t width, uint16_t height, const uint8_t *y,
495495{
496496 vpx_image_t img ;
497497
498- if (vpx_img_alloc (& img , VPX_IMG_FMT_I420 , width , height , 0 ) == nullptr ) {
499- LOGGER_ERROR (vc -> log , "Could not allocate image for frame" );
500- return -1 ;
501- }
498+ // TODO(Green-Sky): figure out stride_align
499+ // TODO(Green-Sky): check memory alignment?
500+ if (vpx_img_wrap (& img , VPX_IMG_FMT_I420 , width , height , 0 , (uint8_t * )y ) != nullptr ) {
501+ // vpx_img_wrap assumes contigues memory, so we fix that
502+ img .planes [VPX_PLANE_U ] = (uint8_t * )u ;
503+ img .planes [VPX_PLANE_V ] = (uint8_t * )v ;
504+ } else {
505+ // call to wrap failed, falling back to copy
506+ if (vpx_img_alloc (& img , VPX_IMG_FMT_I420 , width , height , 0 ) == nullptr ) {
507+ LOGGER_ERROR (vc -> log , "Could not allocate image for frame" );
508+ return -1 ;
509+ }
502510
503- /* I420 "It comprises an NxM Y plane followed by (N/2)x(M/2) V and U planes."
504- * http://fourcc.org/yuv.php#IYUV
505- */
506- memcpy (img .planes [VPX_PLANE_Y ], y , (size_t )width * height );
507- memcpy (img .planes [VPX_PLANE_U ], u , ((size_t )width / 2 ) * (height / 2 ));
508- memcpy (img .planes [VPX_PLANE_V ], v , ((size_t )width / 2 ) * (height / 2 ));
511+ /* I420 "It comprises an NxM Y plane followed by (N/2)x(M/2) V and U planes."
512+ * http://fourcc.org/yuv.php#IYUV
513+ */
514+ memcpy (img .planes [VPX_PLANE_Y ], y , (size_t )width * height );
515+ memcpy (img .planes [VPX_PLANE_U ], u , ((size_t )width / 2 ) * (height / 2 ));
516+ memcpy (img .planes [VPX_PLANE_V ], v , ((size_t )width / 2 ) * (height / 2 ));
517+ }
509518
510519 int vpx_flags = 0 ;
511520
0 commit comments