Bug 1425277 - p7: add apple encoder module and factory. r=jya

Differential Revision: https://phabricator.services.mozilla.com/D7563

--HG--
extra : moz-landing-system : lando
This commit is contained in:
John Lin 2018-11-26 18:29:08 +00:00
Родитель c81fdae426
Коммит bfb5ef4f39
5 изменённых файлов: 163 добавлений и 0 удалений

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

@ -0,0 +1,55 @@
/* -*- 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/. */
#include "PEMFactory.h"
#ifdef MOZ_APPLEMEDIA
#include "AppleEncoderModule.h"
#endif
namespace mozilla {
PEMFactory::PEMFactory() {
#ifdef MOZ_APPLEMEDIA
RefPtr<PlatformEncoderModule> m(new AppleEncoderModule());
mModules.AppendElement(m);
#endif
}
bool PEMFactory::SupportsMimeType(const nsACString& aMimeType) const {
for (auto m : mModules) {
if (m->SupportsMimeType(aMimeType)) {
return true;
}
}
return false;
}
already_AddRefed<MediaDataEncoder> PEMFactory::CreateEncoder(
const CreateEncoderParams& aParams) {
const TrackInfo& info = aParams.mConfig;
RefPtr<PlatformEncoderModule> m = FindPEM(info);
if (!m) {
return nullptr;
}
return info.IsVideo() ? m->CreateVideoEncoder(aParams) : nullptr;
}
already_AddRefed<PlatformEncoderModule> PEMFactory::FindPEM(
const TrackInfo& aTrackInfo) const {
RefPtr<PlatformEncoderModule> found;
for (auto m : mModules) {
if (m->SupportsMimeType(aTrackInfo.mMimeType)) {
found = m;
break;
}
}
return found.forget();
}
} // namespace mozilla

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

@ -0,0 +1,40 @@
/* -*- 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/. */
#if !defined(PEMFactory_h_)
#define PEMFactory_h_
#include "PlatformEncoderModule.h"
namespace mozilla {
class PEMFactory final {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(PEMFactory)
PEMFactory();
// Factory method that creates the appropriate PlatformEncoderModule for
// the platform we're running on. Caller is responsible for deleting this
// instance. It's expected that there will be multiple
// PlatformEncoderModules alive at the same time.
already_AddRefed<MediaDataEncoder> CreateEncoder(
const CreateEncoderParams& aParams);
bool SupportsMimeType(const nsACString& aMimeType) const;
private:
virtual ~PEMFactory() {}
// Returns the first PEM in our list supporting the mimetype.
already_AddRefed<PlatformEncoderModule> FindPEM(
const TrackInfo& aTrackInfo) const;
nsTArray<RefPtr<PlatformEncoderModule>> mModules;
};
} // namespace mozilla
#endif /* PEMFactory_h_ */

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

@ -0,0 +1,38 @@
/* -*- 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/. */
#include "AppleEncoderModule.h"
#include "nsMimeTypes.h"
#include "AppleVTEncoder.h"
namespace mozilla {
bool AppleEncoderModule::SupportsMimeType(const nsACString& aMimeType) const {
return aMimeType.EqualsLiteral(VIDEO_MP4) ||
aMimeType.EqualsLiteral("video/avc");
}
already_AddRefed<MediaDataEncoder> AppleEncoderModule::CreateVideoEncoder(
const CreateEncoderParams& aParams) const {
const VideoInfo* info = aParams.mConfig.GetAsVideoInfo();
MOZ_ASSERT(info);
using Config = AppleVTEncoder::Config;
Config config =
Config(MediaDataEncoder::CodecType::H264, aParams.mUsage, info->mImage,
aParams.mPixelFormat, aParams.mFramerate, aParams.mBitrate);
if (aParams.mCodecSpecific) {
config.SetCodecSpecific(aParams.mCodecSpecific.ref().mH264);
}
RefPtr<MediaDataEncoder> encoder(
new AppleVTEncoder(std::forward<Config>(config), aParams.mTaskQueue));
return encoder.forget();
}
} // namespace mozilla

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

@ -0,0 +1,26 @@
/* -*- 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 AppleEncoderModule_h_
#define AppleEncoderModule_h_
#include "PlatformEncoderModule.h"
namespace mozilla {
class AppleEncoderModule final : public PlatformEncoderModule {
public:
AppleEncoderModule() {}
virtual ~AppleEncoderModule() {}
bool SupportsMimeType(const nsACString& aMimeType) const override;
already_AddRefed<MediaDataEncoder> CreateVideoEncoder(
const CreateEncoderParams& aParams) const override;
};
} // namespace mozilla
#endif /* AppleEncoderModule_h_ */

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

@ -14,6 +14,7 @@ EXPORTS += [
'AllocationPolicy.h',
'MediaTelemetryConstants.h',
'PDMFactory.h',
'PEMFactory.h',
'PlatformDecoderModule.h',
'PlatformEncoderModule.h',
'ReorderQueue.h',
@ -34,6 +35,7 @@ UNIFIED_SOURCES += [
'agnostic/WAVDecoder.cpp',
'AllocationPolicy.cpp',
'PDMFactory.cpp',
'PEMFactory.cpp',
'wrappers/MediaChangeMonitor.cpp',
'wrappers/MediaDataDecoderProxy.cpp'
]
@ -86,10 +88,12 @@ if CONFIG['MOZ_OMX']:
if CONFIG['MOZ_APPLEMEDIA']:
EXPORTS += [
'apple/AppleDecoderModule.h',
'apple/AppleEncoderModule.h',
]
UNIFIED_SOURCES += [
'apple/AppleATDecoder.cpp',
'apple/AppleDecoderModule.cpp',
'apple/AppleEncoderModule.cpp',
'apple/AppleVTDecoder.cpp',
'apple/AppleVTEncoder.cpp',
]