Bug 1660336 Implement DMABufSurfaceWrapper and VAAPIDisplayHolder as templates, r=jya

Implemented DMABufSurfaceWrapper and VAAPIDisplayHolder as a versioned class templates
as they are going to be used by both system ffmpeg and bundled ffvpx decoders.

Depends on D90554

Differential Revision: https://phabricator.services.mozilla.com/D90555
This commit is contained in:
Martin Stransky 2020-12-04 09:41:54 +00:00
Родитель 6780cbc0cd
Коммит 46886a9bae
2 изменённых файлов: 30 добавлений и 14 удалений

Просмотреть файл

@ -126,7 +126,7 @@ static AVPixelFormat ChooseVAAPIPixelFormat(AVCodecContext* aCodecContext,
return AV_PIX_FMT_NONE; return AV_PIX_FMT_NONE;
} }
DMABufSurfaceWrapper::DMABufSurfaceWrapper(DMABufSurface* aSurface, DMABufSurfaceWrapper<LIBAV_VER>::DMABufSurfaceWrapper(DMABufSurface* aSurface,
FFmpegLibWrapper* aLib) FFmpegLibWrapper* aLib)
: mSurface(aSurface), : mSurface(aSurface),
mLib(aLib), mLib(aLib),
@ -140,8 +140,8 @@ DMABufSurfaceWrapper::DMABufSurfaceWrapper(DMABufSurface* aSurface,
mSurface->GetUID()); mSurface->GetUID());
} }
void DMABufSurfaceWrapper::LockVAAPIData(AVCodecContext* aAVCodecContext, void DMABufSurfaceWrapper<LIBAV_VER>::LockVAAPIData(
AVFrame* aAVFrame) { AVCodecContext* aAVCodecContext, AVFrame* aAVFrame) {
FFMPEG_LOG("DMABufSurfaceWrapper: VAAPI locking dmabuf surface UID = %d", FFMPEG_LOG("DMABufSurfaceWrapper: VAAPI locking dmabuf surface UID = %d",
mSurface->GetUID()); mSurface->GetUID());
if (aAVCodecContext && aAVFrame) { if (aAVCodecContext && aAVFrame) {
@ -150,7 +150,7 @@ void DMABufSurfaceWrapper::LockVAAPIData(AVCodecContext* aAVCodecContext,
} }
} }
void DMABufSurfaceWrapper::ReleaseVAAPIData() { void DMABufSurfaceWrapper<LIBAV_VER>::ReleaseVAAPIData() {
FFMPEG_LOG("DMABufSurfaceWrapper: VAAPI releasing dmabuf surface UID = %d", FFMPEG_LOG("DMABufSurfaceWrapper: VAAPI releasing dmabuf surface UID = %d",
mSurface->GetUID()); mSurface->GetUID());
if (mHWAVBuffer && mAVHWFramesContext) { if (mHWAVBuffer && mAVHWFramesContext) {
@ -160,7 +160,7 @@ void DMABufSurfaceWrapper::ReleaseVAAPIData() {
mSurface->ReleaseSurface(); mSurface->ReleaseSurface();
} }
DMABufSurfaceWrapper::~DMABufSurfaceWrapper() { DMABufSurfaceWrapper<LIBAV_VER>::~DMABufSurfaceWrapper() {
FFMPEG_LOG("DMABufSurfaceWrapper: deleting dmabuf surface UID = %d", FFMPEG_LOG("DMABufSurfaceWrapper: deleting dmabuf surface UID = %d",
mSurface->GetUID()); mSurface->GetUID());
ReleaseVAAPIData(); ReleaseVAAPIData();
@ -183,7 +183,14 @@ AVCodec* FFmpegVideoDecoder<LIBAV_VER>::FindVAAPICodec() {
return nullptr; return nullptr;
} }
class VAAPIDisplayHolder { template <int V>
class VAAPIDisplayHolder {};
template <>
class VAAPIDisplayHolder<LIBAV_VER>;
template <>
class VAAPIDisplayHolder<LIBAV_VER> {
public: public:
VAAPIDisplayHolder(FFmpegLibWrapper* aLib, VADisplay aDisplay) VAAPIDisplayHolder(FFmpegLibWrapper* aLib, VADisplay aDisplay)
: mLib(aLib), mDisplay(aDisplay){}; : mLib(aLib), mDisplay(aDisplay){};
@ -195,7 +202,8 @@ class VAAPIDisplayHolder {
}; };
static void VAAPIDisplayReleaseCallback(struct AVHWDeviceContext* hwctx) { static void VAAPIDisplayReleaseCallback(struct AVHWDeviceContext* hwctx) {
auto displayHolder = static_cast<VAAPIDisplayHolder*>(hwctx->user_opaque); auto displayHolder =
static_cast<VAAPIDisplayHolder<LIBAV_VER>*>(hwctx->user_opaque);
delete displayHolder; delete displayHolder;
} }
@ -231,7 +239,7 @@ bool FFmpegVideoDecoder<LIBAV_VER>::CreateVAAPIDeviceContext() {
} }
} }
hwctx->user_opaque = new VAAPIDisplayHolder(mLib, mDisplay); hwctx->user_opaque = new VAAPIDisplayHolder<LIBAV_VER>(mLib, mDisplay);
hwctx->free = VAAPIDisplayReleaseCallback; hwctx->free = VAAPIDisplayReleaseCallback;
int major, minor; int major, minor;
@ -705,7 +713,7 @@ void FFmpegVideoDecoder<LIBAV_VER>::ReleaseUnusedVAAPIFrames() {
} }
} }
DMABufSurfaceWrapper* DMABufSurfaceWrapper<LIBAV_VER>*
FFmpegVideoDecoder<LIBAV_VER>::GetUnusedDMABufSurfaceWrapper() { FFmpegVideoDecoder<LIBAV_VER>::GetUnusedDMABufSurfaceWrapper() {
int len = mDMABufSurfaces.Length(); int len = mDMABufSurfaces.Length();
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
@ -771,7 +779,8 @@ MediaResult FFmpegVideoDecoder<LIBAV_VER>::CreateImageDMABuf(
RefPtr<DMABufSurfaceYUV> surface; RefPtr<DMABufSurfaceYUV> surface;
DMABufSurfaceWrapper* surfaceWrapper = GetUnusedDMABufSurfaceWrapper(); DMABufSurfaceWrapper<LIBAV_VER>* surfaceWrapper =
GetUnusedDMABufSurfaceWrapper();
if (!surfaceWrapper) { if (!surfaceWrapper) {
if (mVAAPIDeviceContext) { if (mVAAPIDeviceContext) {
surface = DMABufSurfaceYUV::CreateYUVSurface(vaDesc); surface = DMABufSurfaceYUV::CreateYUVSurface(vaDesc);

Просмотреть файл

@ -55,7 +55,14 @@ namespace mozilla {
// We own the DMABufSurface underlying GPU data and we use it for // We own the DMABufSurface underlying GPU data and we use it for
// repeated rendering of video frames. // repeated rendering of video frames.
// //
class DMABufSurfaceWrapper final { template <int V>
class DMABufSurfaceWrapper {};
template <>
class DMABufSurfaceWrapper<LIBAV_VER>;
template <>
class DMABufSurfaceWrapper<LIBAV_VER> final {
public: public:
DMABufSurfaceWrapper(DMABufSurface* aSurface, FFmpegLibWrapper* aLib); DMABufSurfaceWrapper(DMABufSurface* aSurface, FFmpegLibWrapper* aLib);
~DMABufSurfaceWrapper(); ~DMABufSurfaceWrapper();
@ -162,7 +169,7 @@ class FFmpegVideoDecoder<LIBAV_VER>
MediaDataDecoder::DecodedData& aResults); MediaDataDecoder::DecodedData& aResults);
void ReleaseUnusedVAAPIFrames(); void ReleaseUnusedVAAPIFrames();
DMABufSurfaceWrapper* GetUnusedDMABufSurfaceWrapper(); DMABufSurfaceWrapper<LIBAV_VER>* GetUnusedDMABufSurfaceWrapper();
void ReleaseDMABufSurfaces(); void ReleaseDMABufSurfaces();
#endif #endif
@ -180,7 +187,7 @@ class FFmpegVideoDecoder<LIBAV_VER>
const bool mDisableHardwareDecoding; const bool mDisableHardwareDecoding;
VADisplay mDisplay; VADisplay mDisplay;
bool mUseDMABufSurfaces; bool mUseDMABufSurfaces;
nsTArray<DMABufSurfaceWrapper> mDMABufSurfaces; nsTArray<DMABufSurfaceWrapper<LIBAV_VER>> mDMABufSurfaces;
#endif #endif
RefPtr<KnowsCompositor> mImageAllocator; RefPtr<KnowsCompositor> mImageAllocator;
RefPtr<ImageContainer> mImageContainer; RefPtr<ImageContainer> mImageContainer;