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;
}
DMABufSurfaceWrapper::DMABufSurfaceWrapper(DMABufSurface* aSurface,
DMABufSurfaceWrapper<LIBAV_VER>::DMABufSurfaceWrapper(DMABufSurface* aSurface,
FFmpegLibWrapper* aLib)
: mSurface(aSurface),
mLib(aLib),
@ -140,8 +140,8 @@ DMABufSurfaceWrapper::DMABufSurfaceWrapper(DMABufSurface* aSurface,
mSurface->GetUID());
}
void DMABufSurfaceWrapper::LockVAAPIData(AVCodecContext* aAVCodecContext,
AVFrame* aAVFrame) {
void DMABufSurfaceWrapper<LIBAV_VER>::LockVAAPIData(
AVCodecContext* aAVCodecContext, AVFrame* aAVFrame) {
FFMPEG_LOG("DMABufSurfaceWrapper: VAAPI locking dmabuf surface UID = %d",
mSurface->GetUID());
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",
mSurface->GetUID());
if (mHWAVBuffer && mAVHWFramesContext) {
@ -160,7 +160,7 @@ void DMABufSurfaceWrapper::ReleaseVAAPIData() {
mSurface->ReleaseSurface();
}
DMABufSurfaceWrapper::~DMABufSurfaceWrapper() {
DMABufSurfaceWrapper<LIBAV_VER>::~DMABufSurfaceWrapper() {
FFMPEG_LOG("DMABufSurfaceWrapper: deleting dmabuf surface UID = %d",
mSurface->GetUID());
ReleaseVAAPIData();
@ -183,7 +183,14 @@ AVCodec* FFmpegVideoDecoder<LIBAV_VER>::FindVAAPICodec() {
return nullptr;
}
class VAAPIDisplayHolder {
template <int V>
class VAAPIDisplayHolder {};
template <>
class VAAPIDisplayHolder<LIBAV_VER>;
template <>
class VAAPIDisplayHolder<LIBAV_VER> {
public:
VAAPIDisplayHolder(FFmpegLibWrapper* aLib, VADisplay aDisplay)
: mLib(aLib), mDisplay(aDisplay){};
@ -195,7 +202,8 @@ class VAAPIDisplayHolder {
};
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;
}
@ -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;
int major, minor;
@ -705,7 +713,7 @@ void FFmpegVideoDecoder<LIBAV_VER>::ReleaseUnusedVAAPIFrames() {
}
}
DMABufSurfaceWrapper*
DMABufSurfaceWrapper<LIBAV_VER>*
FFmpegVideoDecoder<LIBAV_VER>::GetUnusedDMABufSurfaceWrapper() {
int len = mDMABufSurfaces.Length();
for (int i = 0; i < len; i++) {
@ -771,7 +779,8 @@ MediaResult FFmpegVideoDecoder<LIBAV_VER>::CreateImageDMABuf(
RefPtr<DMABufSurfaceYUV> surface;
DMABufSurfaceWrapper* surfaceWrapper = GetUnusedDMABufSurfaceWrapper();
DMABufSurfaceWrapper<LIBAV_VER>* surfaceWrapper =
GetUnusedDMABufSurfaceWrapper();
if (!surfaceWrapper) {
if (mVAAPIDeviceContext) {
surface = DMABufSurfaceYUV::CreateYUVSurface(vaDesc);

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

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