From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- dom/media/platforms/apple/AppleVTEncoder.h | 85 ++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 dom/media/platforms/apple/AppleVTEncoder.h (limited to 'dom/media/platforms/apple/AppleVTEncoder.h') diff --git a/dom/media/platforms/apple/AppleVTEncoder.h b/dom/media/platforms/apple/AppleVTEncoder.h new file mode 100644 index 0000000000..7f12f7ebb5 --- /dev/null +++ b/dom/media/platforms/apple/AppleVTEncoder.h @@ -0,0 +1,85 @@ +/* -*- 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 mozilla_AppleVTEncoder_h_ +#define mozilla_AppleVTEncoder_h_ + +#include +#include + +#include "PlatformEncoderModule.h" +#include "TimeUnits.h" + +namespace mozilla { + +namespace layers { +class Image; +} + +class AppleVTEncoder final : public MediaDataEncoder { + public: + using Config = H264Config; + + AppleVTEncoder(const Config& aConfig, RefPtr aTaskQueue, + const bool aHwardwareNotAllowed) + : mConfig(aConfig), + mTaskQueue(aTaskQueue), + mHardwareNotAllowed(aHwardwareNotAllowed), + mFramesCompleted(false), + mError(NS_OK), + mSession(nullptr) { + MOZ_ASSERT(mConfig.mSize.width > 0 && mConfig.mSize.height > 0); + MOZ_ASSERT(mTaskQueue); + } + + RefPtr Init() override; + RefPtr Encode(const MediaData* aSample) override; + RefPtr Drain() override; + RefPtr Shutdown() override; + RefPtr SetBitrate(Rate aBitsPerSec) override; + + nsCString GetDescriptionName() const override { + MOZ_ASSERT(mSession); + return mIsHardwareAccelerated ? "apple hardware VT encoder"_ns + : "apple software VT encoder"_ns; + } + + void OutputFrame(CMSampleBufferRef aBuffer); + + private: + virtual ~AppleVTEncoder() { MOZ_ASSERT(!mSession); } + RefPtr ProcessEncode(RefPtr aSample); + void ProcessOutput(RefPtr&& aOutput); + void ResolvePromise(); + RefPtr ProcessDrain(); + RefPtr ProcessShutdown(); + + CFDictionaryRef BuildSourceImageBufferAttributes(); + CVPixelBufferRef CreateCVPixelBuffer(const layers::Image* aSource); + bool WriteExtraData(MediaRawData* aDst, CMSampleBufferRef aSrc, + const bool aAsAnnexB); + void AssertOnTaskQueue() { MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn()); } + + const Config mConfig; + const RefPtr mTaskQueue; + const bool mHardwareNotAllowed; + // Access only in mTaskQueue. + EncodedData mEncodedData; + bool mFramesCompleted; + RefPtr mAvcc; // Stores latest avcC data. + MediaResult mError; + + // Written by Init() but used only in task queue. + VTCompressionSessionRef mSession; + // Can be accessed on any thread, but only written on during init. + Atomic mIsHardwareAccelerated; + // Written during init and shutdown. + Atomic mInited; +}; + +} // namespace mozilla + +#endif // mozilla_AppleVTEncoder_h_ -- cgit v1.2.3