From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- dom/media/platforms/ffmpeg/FFmpegVideoEncoder.h | 110 ++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 dom/media/platforms/ffmpeg/FFmpegVideoEncoder.h (limited to 'dom/media/platforms/ffmpeg/FFmpegVideoEncoder.h') diff --git a/dom/media/platforms/ffmpeg/FFmpegVideoEncoder.h b/dom/media/platforms/ffmpeg/FFmpegVideoEncoder.h new file mode 100644 index 0000000000..1bcdd3eaf9 --- /dev/null +++ b/dom/media/platforms/ffmpeg/FFmpegVideoEncoder.h @@ -0,0 +1,110 @@ +/* -*- 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 DOM_MEDIA_PLATFORMS_FFMPEG_FFMPEGVIDEOENCODER_H_ +#define DOM_MEDIA_PLATFORMS_FFMPEG_FFMPEGVIDEOENCODER_H_ + +#include "FFmpegLibWrapper.h" +#include "PlatformEncoderModule.h" +#include "SimpleMap.h" +#include "mozilla/ThreadSafety.h" + +// This must be the last header included +#include "FFmpegLibs.h" + +namespace mozilla { + +template +AVCodecID GetFFmpegEncoderCodecId(CodecType aCodec); + +template <> +AVCodecID GetFFmpegEncoderCodecId(CodecType aCodec); + +template +class FFmpegVideoEncoder : public MediaDataEncoder {}; + +// TODO: Bug 1860925: FFmpegDataEncoder +template <> +class FFmpegVideoEncoder final : public MediaDataEncoder { + using DurationMap = SimpleMap; + + public: + FFmpegVideoEncoder(const FFmpegLibWrapper* aLib, AVCodecID aCodecID, + const RefPtr& aTaskQueue, + const EncoderConfig& aConfig); + + /* MediaDataEncoder Methods */ + // All methods run on the task queue, except for GetDescriptionName. + RefPtr Init() override; + RefPtr Encode(const MediaData* aSample) override; + RefPtr Reconfigure( + const RefPtr& aConfigurationChanges) + override; + RefPtr Drain() override; + RefPtr Shutdown() override; + RefPtr SetBitrate(uint32_t aBitRate) override; + nsCString GetDescriptionName() const override; + + private: + ~FFmpegVideoEncoder() = default; + + // Methods only called on mTaskQueue. + RefPtr ProcessInit(); + RefPtr ProcessEncode(RefPtr aSample); + RefPtr ProcessReconfigure( + const RefPtr aConfigurationChanges); + RefPtr ProcessDrain(); + RefPtr ProcessShutdown(); + MediaResult InitInternal(); + void ShutdownInternal(); + // TODO: Share these with FFmpegDataDecoder. + int OpenCodecContext(const AVCodec* aCodec, AVDictionary** aOptions) + MOZ_EXCLUDES(sMutex); + void CloseCodecContext() MOZ_EXCLUDES(sMutex); + bool PrepareFrame(); + void DestroyFrame(); + bool ScaleInputFrame(); +#if LIBAVCODEC_VERSION_MAJOR >= 58 + RefPtr EncodeWithModernAPIs(RefPtr aSample); + RefPtr DrainWithModernAPIs(); +#endif + RefPtr ToMediaRawData(AVPacket* aPacket); + Result, nsresult> GetExtraData( + AVPacket* aPacket); + void ForceEnablingFFmpegDebugLogs(); + + // This refers to a static FFmpegLibWrapper, so raw pointer is adequate. + const FFmpegLibWrapper* mLib; + const AVCodecID mCodecID; + const RefPtr mTaskQueue; + + // set in constructor, modified when parameters change + EncoderConfig mConfig; + + // mTaskQueue only. + nsCString mCodecName; + AVCodecContext* mCodecContext; + AVFrame* mFrame; + DurationMap mDurationMap; + + struct SVCInfo { + explicit SVCInfo(nsTArray&& aTemporalLayerIds) + : mTemporalLayerIds(std::move(aTemporalLayerIds)), mNextIndex(0) {} + const nsTArray mTemporalLayerIds; + size_t mNextIndex; + // Return the current temporal layer id and update the next. + uint8_t UpdateTemporalLayerId(); + }; + Maybe mSVCInfo; + + // Provide critical-section for open/close mCodecContext. + // TODO: Merge this with FFmpegDataDecoder's one. + static StaticMutex sMutex; +}; + +} // namespace mozilla + +#endif /* DOM_MEDIA_PLATFORMS_FFMPEG_FFMPEGVIDEOENCODER_H_ */ -- cgit v1.2.3