I have an implementation of cricket::VideoCapturer that pulls video frames arriving over a custom input channel. Video frames arrive in RGB format, and I convert them to YUV before passing them to cricket::VideoCapturer::OnFrame. Currently I am allocating a new YUV frame each time:
auto dst_buffer = webrtc::I420Buffer::Create(dst_width, dst_height, stride_y, stride_uv, stride_uv);
...
libyuv::ConvertToI420(src_frame, sample_size, dst_buffer->MutableDataY(), ...)
...
OnFrame(webrtc::VideoFrame(dst_buffer, 0, rtc::TimeMillis(), webrtc::kVideoRotation_0), dst_width, dst_height);
I would like to re-use the same I420Buffer rather than re-allocating for each frame. The function above is itself only called from one thread, so I am not concerned about the thread safety of webrtc::I420Buffer itself. Instead, I am wondering whether cricket::VideoCapturer::OnFrame retains the data on another thread, or otherwise does anything that would prevent me from re-using the same buffer each time. Is it safe for me to re-use the same instance of webrtc::I420Buffer on each loop through this function?