diff --git a/media/webrtc/signaling/src/media-conduit/WebrtcImageBuffer.h b/media/webrtc/signaling/src/media-conduit/WebrtcImageBuffer.h new file mode 100644 index 000000000000..7637bf0faf9a --- /dev/null +++ b/media/webrtc/signaling/src/media-conduit/WebrtcImageBuffer.h @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WebrtcImageBuffer_h__ +#define WebrtcImageBuffer_h__ + +#include "webrtc/common_video/include/video_frame_buffer.h" +#include "webrtc/rtc_base/keep_ref_until_done.h" + +namespace mozilla { +namespace layers { + class Image; +} + +class ImageBuffer : public webrtc::VideoFrameBuffer +{ +public: + explicit ImageBuffer(RefPtr&& aImage) + : mImage(std::move(aImage)) + { + } + + rtc::scoped_refptr ToI420() override + { + RefPtr image = mImage->AsPlanarYCbCrImage(); + MOZ_ASSERT(image); + if (!image) { + // TODO. YUV420 ReadBack, Image only provides a RGB readback. + return nullptr; + } + const layers::PlanarYCbCrData* data = image->GetData(); + rtc::scoped_refptr buf( + new rtc::RefCountedObject( + data->mPicSize.width, + data->mPicSize.height, + data->mYChannel, + data->mYStride, + data->mCbChannel, + data->mCbCrStride, + data->mCrChannel, + data->mCbCrStride, + rtc::KeepRefUntilDone(image.get()))); + return buf; + } + + Type type() const override + { + return Type::kNative; + } + + int width() const override + { + return mImage->GetSize().width; + } + + int height() const override + { + return mImage->GetSize().height; + } + + RefPtr GetNativeImage() const + { + return mImage; + } + +private: + const RefPtr mImage; +}; + +} // namespace mozilla + +#endif // WebrtcImageBuffer_h__ diff --git a/media/webrtc/signaling/src/media-conduit/WebrtcMediaDataDecoderCodec.cpp b/media/webrtc/signaling/src/media-conduit/WebrtcMediaDataDecoderCodec.cpp index 50d77a6c2176..a2ee453ad6a0 100644 --- a/media/webrtc/signaling/src/media-conduit/WebrtcMediaDataDecoderCodec.cpp +++ b/media/webrtc/signaling/src/media-conduit/WebrtcMediaDataDecoderCodec.cpp @@ -9,7 +9,7 @@ #include "VideoUtils.h" #include "mozilla/media/MediaUtils.h" #include "mozilla/layers/ImageBridgeChild.h" -#include "webrtc/base/keep_ref_until_done.h" +#include "webrtc/rtc_base/keep_ref_until_done.h" namespace mozilla { @@ -172,36 +172,4 @@ WebrtcMediaDataDecoder::OnTaskQueue() const return OwnerThread()->IsCurrentThreadIn(); } -ImageBuffer::ImageBuffer(RefPtr&& aImage) - : webrtc::NativeHandleBuffer(aImage, - aImage->GetSize().width, - aImage->GetSize().height) - , mImage(std::move(aImage)) -{ -} - -rtc::scoped_refptr -ImageBuffer::NativeToI420Buffer() -{ - RefPtr image = mImage->AsPlanarYCbCrImage(); - if (!image) { - // TODO. YUV420 ReadBack, Image only provides a RGB readback. - return nullptr; - } - rtc::scoped_refptr refImage(image); - const layers::PlanarYCbCrData* data = image->GetData(); - rtc::scoped_refptr buf( - new rtc::RefCountedObject( - data->mPicSize.width, - data->mPicSize.height, - data->mYChannel, - data->mYStride, - data->mCbChannel, - data->mCbCrStride, - data->mCrChannel, - data->mCbCrStride, - rtc::KeepRefUntilDone(refImage))); - return buf; -} - } // namespace mozilla diff --git a/media/webrtc/signaling/src/media-conduit/WebrtcMediaDataDecoderCodec.h b/media/webrtc/signaling/src/media-conduit/WebrtcMediaDataDecoderCodec.h index 99c57e9819ed..bcd4ed53468f 100644 --- a/media/webrtc/signaling/src/media-conduit/WebrtcMediaDataDecoderCodec.h +++ b/media/webrtc/signaling/src/media-conduit/WebrtcMediaDataDecoderCodec.h @@ -9,6 +9,7 @@ #include "MediaInfo.h" #include "MediaResult.h" #include "PlatformDecoderModule.h" +#include "WebrtcImageBuffer.h" #include "webrtc/common_video/include/video_frame_buffer.h" #include "webrtc/modules/video_coding/include/video_codec_interface.h" @@ -25,16 +26,6 @@ class PDMFactory; class SharedThreadPool; class TaskQueue; -class ImageBuffer : public webrtc::NativeHandleBuffer -{ -public: - explicit ImageBuffer(RefPtr&& aImage); - rtc::scoped_refptr NativeToI420Buffer() override; - -private: - RefPtr mImage; -}; - class WebrtcMediaDataDecoder : public WebrtcVideoDecoder { public: diff --git a/media/webrtc/signaling/src/media-conduit/moz.build b/media/webrtc/signaling/src/media-conduit/moz.build index 80396201d93f..71fc1cbcf6fe 100644 --- a/media/webrtc/signaling/src/media-conduit/moz.build +++ b/media/webrtc/signaling/src/media-conduit/moz.build @@ -14,6 +14,7 @@ LOCAL_INCLUDES += [ '/media/webrtc/signaling/src/common', '/media/webrtc/signaling/src/common/browser_logging', '/media/webrtc/signaling/src/common/time_profiling', + '/media/webrtc/signaling/src/media-conduit', '/media/webrtc/signaling/src/peerconnection', '/media/webrtc/trunk', '/media/webrtc/trunk/webrtc', diff --git a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp index bead7920885b..c64671ffb83a 100644 --- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp +++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp @@ -47,6 +47,7 @@ #include "runnable_utils.h" #include "signaling/src/peerconnection/MediaTransportHandler.h" #include "Tracing.h" +#include "WebrtcImageBuffer.h" #include "webrtc/base/bind.h" #include "webrtc/base/keep_ref_until_done.h" @@ -2040,15 +2041,18 @@ public: uint32_t aTimeStamp, int64_t aRenderTime) { - if (aBuffer.native_handle()) { + if (aBuffer.type() == webrtc::VideoFrameBuffer::Type::kNative) { // We assume that only native handles are used with the // WebrtcMediaDataDecoderCodec decoder. - RefPtr image = static_cast(aBuffer.native_handle()); + const ImageBuffer *imageBuffer = static_cast(&aBuffer); MutexAutoLock lock(mMutex); - mImage = image; + mImage = imageBuffer->GetNativeImage(); return; } + MOZ_ASSERT(aBuffer.type() == webrtc::VideoFrameBuffer::Type::kI420); + rtc::scoped_refptr i420 = aBuffer.GetI420(); + MOZ_ASSERT(aBuffer.DataY()); // Create a video frame using |buffer|. RefPtr yuvImage =