/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim:set ts=2 sw=2 sts=2 et cindent: */ /* 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 WMFMediaDataEncoder_h_ #define WMFMediaDataEncoder_h_ #include "MFTEncoder.h" #include "PlatformEncoderModule.h" #include "WMFDataEncoderUtils.h" #include "WMFUtils.h" #include #include "mozilla/WindowsProcessMitigations.h" namespace mozilla { class WMFMediaDataEncoder final : public MediaDataEncoder { public: WMFMediaDataEncoder(const EncoderConfig& aConfig, const RefPtr& aTaskQueue); RefPtr Init() override; RefPtr Encode(const MediaData* aSample) override; RefPtr Drain() override; RefPtr Shutdown() override; RefPtr SetBitrate(uint32_t aBitsPerSec) override; RefPtr Reconfigure( const RefPtr& aConfigurationChanges) override; nsCString GetDescriptionName() const override; private: // Automatically lock/unlock IMFMediaBuffer. class LockBuffer final { public: explicit LockBuffer(RefPtr& aBuffer) : mBuffer(aBuffer) { mResult = mBuffer->Lock(&mBytes, &mCapacity, &mLength); } ~LockBuffer() { if (SUCCEEDED(mResult)) { mBuffer->Unlock(); } } BYTE* Data() { return mBytes; } DWORD Capacity() { return mCapacity; } DWORD Length() { return mLength; } HRESULT Result() { return mResult; } private: RefPtr mBuffer; BYTE* mBytes{}; DWORD mCapacity{}; DWORD mLength{}; HRESULT mResult{}; }; RefPtr ProcessInit(); HRESULT InitMFTEncoder(RefPtr& aEncoder); void FillConfigData(); RefPtr ProcessEncode(RefPtr&& aSample); already_AddRefed ConvertToNV12InputSample( RefPtr&& aData); RefPtr ProcessOutputSamples( nsTArray>& aSamples); already_AddRefed IMFSampleToMediaData( RefPtr& aSample); bool WriteFrameData(RefPtr& aDest, LockBuffer& aSrc, bool aIsKeyframe); void AssertOnTaskQueue() { MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn()); } EncoderConfig mConfig; const RefPtr mTaskQueue; const bool mHardwareNotAllowed; RefPtr mEncoder; // SPS/PPS NALUs for realtime usage, avcC otherwise. RefPtr mConfigData; }; } // namespace mozilla #endif