12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #include "pch.h"
- #include "../common/comm.h"
- #include "video_frame_observer.h"
- constexpr int kBufferAlignment = 64;
- ArgbBuffer::ArgbBuffer(int width, int height, int stride)
- : width_(width),
- height_(height),
- stride_(stride),
- data_(static_cast<uint8_t*>(
- webrtc::AlignedMalloc(ArgbDataSize(height, stride),
- kBufferAlignment))) {
- RTC_DCHECK_GT(width, 0);
- RTC_DCHECK_GT(height, 0);
- RTC_DCHECK_GE(stride, 4 * width);
- }
- rtc::scoped_refptr<webrtc::I420BufferInterface> ArgbBuffer::ToI420() {
- rtc::scoped_refptr<webrtc::I420Buffer> i420_buffer =
- webrtc::I420Buffer::Create(width_, height_, stride_, stride_ / 2,
- stride_ / 2);
- libyuv::ARGBToI420(Data(), Stride(), i420_buffer->MutableDataY(),
- i420_buffer->StrideY(), i420_buffer->MutableDataU(),
- i420_buffer->StrideU(), i420_buffer->MutableDataV(),
- i420_buffer->StrideV(), width_, height_);
- return i420_buffer;
- }
- void VideoFrameObserver::SetCallback(VideoFrameReadyCallback callback) {
- std::lock_guard<std::mutex> lock{ mutex_ };
- frame_callback_ = std::move(callback);
- }
- /*
- void VideoFrameObserver::SetCallback(ARGBFrameReadyCallback callback) {
- std::lock_guard<std::mutex> lock{ mutex_ };
- argb_callback_ = std::move(callback);
- }
- */
- ArgbBuffer* VideoFrameObserver::GetArgbScratchBuffer(int width, int height) {
- const size_t needed_size = ArgbDataSize(width, height);
- if (auto* buffer = argb_scratch_buffer_.get()) {
- if (buffer->Size() >= needed_size) {
- return buffer;
- }
- }
- argb_scratch_buffer_ = ArgbBuffer::Create(width, height);
- return argb_scratch_buffer_.get();
- }
- void VideoFrameObserver::OnFrame(const webrtc::VideoFrame& frame) {
-
- std::lock_guard<std::mutex> lock{ mutex_ };
- if (!frame_callback_)
- return;
- frame_callback_(frame);
- /*rtc::scoped_refptr<webrtc::VideoFrameBuffer> buffer(
- frame.video_frame_buffer());
- const int width = frame.width();
- const int height = frame.height();
- if (buffer->type() != webrtc::VideoFrameBuffer::Type::kI420A) {
-
- rtc::scoped_refptr<webrtc::I420BufferInterface> i420_buffer =
- buffer->ToI420();
- const uint8_t* yptr = i420_buffer->DataY();
- const uint8_t* uptr = i420_buffer->DataU();
- const uint8_t* vptr = i420_buffer->DataV();
- const uint8_t* aptr = nullptr;
-
- if (argb_callback_) {
-
- argb_callback_(yptr,i420_buffer->StrideY(),uptr,i420_buffer->StrideU(),vptr,i420_buffer->StrideV(), width*4, width, height);
- }
- }
- else {
-
- const webrtc::I420ABufferInterface* i420a_buffer = buffer->GetI420A();
- const uint8_t* yptr = i420a_buffer->DataY();
- const uint8_t* uptr = i420a_buffer->DataU();
- const uint8_t* vptr = i420a_buffer->DataV();
- const uint8_t* aptr = i420a_buffer->DataA();
-
- if (argb_callback_) {
- argb_callback_(yptr, i420a_buffer->StrideY(), uptr, i420a_buffer->StrideU(), vptr, i420a_buffer->StrideV(), width * 4, width, height);
- }
- }
- */
- }
|