mirror of
https://gitee.com/openharmony/multimedia_av_codec
synced 2024-11-27 00:50:36 +00:00
!3886 add vendor aac encoder, support HE-AAC mux
Merge pull request !3886 from SuRuoyan/master
This commit is contained in:
commit
3121363ede
@ -101,13 +101,16 @@ config("av_codec_client_public_config") {
|
||||
|
||||
if (target_cpu == "arm64" || is_emulator) {
|
||||
av_codec_plugin_path = "\"/system/lib64/media/av_codec_plugins\""
|
||||
av_codec_path = "\"/system/lib64\""
|
||||
} else {
|
||||
av_codec_plugin_path = "\"/system/lib/media/av_codec_plugins\""
|
||||
av_codec_path = "\"/system/lib\""
|
||||
}
|
||||
|
||||
defines += [
|
||||
"AV_CODEC_PLUGIN_PATH=${av_codec_plugin_path}",
|
||||
"AV_CODEC_PLUGIN_FILE_TAIL=\".z.so\"",
|
||||
"AV_CODEC_PATH=${av_codec_path}",
|
||||
]
|
||||
|
||||
if (av_codec_client_support_codec) {
|
||||
|
@ -38,6 +38,7 @@ public:
|
||||
static constexpr std::string_view AUDIO_ENCODER_OPUS_NAME = "OH.Media.Codec.Encoder.Audio.Opus";
|
||||
static constexpr std::string_view AUDIO_ENCODER_G711MU_NAME = "OH.Media.Codec.Encoder.Audio.G711mu";
|
||||
static constexpr std::string_view AUDIO_ENCODER_AAC_NAME = "OH.Media.Codec.Encoder.Audio.AAC";
|
||||
static constexpr std::string_view AUDIO_ENCODER_VENDOR_AAC_NAME = "OH.Media.Codec.Encoder.Audio.Vendor.AAC";
|
||||
static constexpr std::string_view AUDIO_ENCODER_LBVC_NAME = "OH.Media.Codec.Encoder.Audio.LBVC";
|
||||
static constexpr std::string_view AUDIO_ENCODER_AMRNB_NAME = "OH.Media.Codec.Encoder.Audio.Amrnb";
|
||||
static constexpr std::string_view AUDIO_ENCODER_AMRWB_NAME = "OH.Media.Codec.Encoder.Audio.Amrwb";
|
||||
|
@ -681,6 +681,8 @@ typedef enum OH_MediaType {
|
||||
*/
|
||||
typedef enum OH_AACProfile {
|
||||
AAC_PROFILE_LC = 0,
|
||||
AAC_PROFILE_HE = 3,
|
||||
AAC_PROFILE_HE_V2 = 4,
|
||||
} OH_AACProfile;
|
||||
|
||||
/**
|
||||
|
@ -35,6 +35,12 @@ ohos_static_library("av_codec_engine_codeclist") {
|
||||
if (av_codec_enable_special_codec) {
|
||||
defines += [ "AV_CODEC_AUDIO_VIVID_CAPACITY" ]
|
||||
}
|
||||
if (target_cpu == "arm64") {
|
||||
av_codec_path = "\"/system/lib64\""
|
||||
} else {
|
||||
av_codec_path = "\"/system/lib\""
|
||||
}
|
||||
defines += [ "AV_CODEC_PATH=${av_codec_path}" ]
|
||||
|
||||
sources = [
|
||||
"$av_codec_root_dir/services/media_engine/plugins/ffmpeg_adapter/common/hdi_codec.cpp",
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "avcodec_mime_type.h"
|
||||
#include "avcodec_codec_name.h"
|
||||
#include "hdi_codec.h"
|
||||
#include <fstream>
|
||||
|
||||
namespace OHOS {
|
||||
namespace MediaAVCodec {
|
||||
@ -67,6 +68,8 @@ constexpr int MAX_CHANNEL_COUNT_VIVID = 16;
|
||||
constexpr int MAX_BIT_RATE_G711MU_DECODER = 64000;
|
||||
constexpr int MAX_BIT_RATE_G711MU_ENCODER = 64000;
|
||||
|
||||
const std::string VENDOR_AAC_LIB_PATH = std::string(AV_CODEC_PATH) + "/libaac_enc.z.so";
|
||||
|
||||
CapabilityData AudioCodeclistInfo::GetMP3DecoderCapability()
|
||||
{
|
||||
CapabilityData audioMp3Capability;
|
||||
@ -283,6 +286,34 @@ CapabilityData AudioCodeclistInfo::GetLbvcEncoderCapability()
|
||||
audioLbvcCapability.isVendor = true;
|
||||
return audioLbvcCapability;
|
||||
}
|
||||
|
||||
CapabilityData AudioCodeclistInfo::GetVendorAacEncoderCapability()
|
||||
{
|
||||
std::unique_ptr<std::ifstream> libFile = std::make_unique<std::ifstream>(VENDOR_AAC_LIB_PATH, std::ios::binary);
|
||||
CapabilityData audioAacCapability;
|
||||
if (!libFile->is_open()) {
|
||||
audioAacCapability.codecName = "";
|
||||
audioAacCapability.mimeType = "";
|
||||
audioAacCapability.maxInstance = 0;
|
||||
audioAacCapability.codecType = AVCODEC_TYPE_NONE;
|
||||
audioAacCapability.isVendor = false;
|
||||
audioAacCapability.bitrate = Range(0, 0);
|
||||
audioAacCapability.channels = Range(0, 0);
|
||||
audioAacCapability.sampleRate = {0};
|
||||
return audioAacCapability;
|
||||
}
|
||||
libFile->close();
|
||||
audioAacCapability.codecName = AVCodecCodecName::AUDIO_ENCODER_VENDOR_AAC_NAME;
|
||||
audioAacCapability.codecType = AVCODEC_TYPE_AUDIO_ENCODER;
|
||||
audioAacCapability.mimeType = AVCodecMimeType::MEDIA_MIMETYPE_AUDIO_AAC;
|
||||
audioAacCapability.isVendor = false;
|
||||
audioAacCapability.bitrate = Range(MIN_BIT_RATE_AAC_ENCODER, MAX_BIT_RATE_AAC_ENCODER);
|
||||
audioAacCapability.channels = Range(1, MAX_AUDIO_CHANNEL_COUNT);
|
||||
audioAacCapability.sampleRate = AUDIO_SAMPLE_RATE;
|
||||
audioAacCapability.maxInstance = MAX_SUPPORT_AUDIO_INSTANCE;
|
||||
audioAacCapability.profiles = { AAC_PROFILE_LC, AAC_PROFILE_HE, AAC_PROFILE_HE_V2 };
|
||||
return audioAacCapability;
|
||||
}
|
||||
#endif
|
||||
|
||||
CapabilityData AudioCodeclistInfo::GetAacEncoderCapability()
|
||||
@ -365,7 +396,7 @@ AudioCodeclistInfo::AudioCodeclistInfo()
|
||||
GetAPEDecoderCapability(), GetMP3EncoderCapability(),
|
||||
#ifdef AV_CODEC_AUDIO_VIVID_CAPACITY
|
||||
GetVividDecoderCapability(), GetAmrnbEncoderCapability(), GetAmrwbEncoderCapability(),
|
||||
GetLbvcDecoderCapability(), GetLbvcEncoderCapability(),
|
||||
GetLbvcDecoderCapability(), GetLbvcEncoderCapability(), GetVendorAacEncoderCapability(),
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ public:
|
||||
CapabilityData GetMP3EncoderCapability();
|
||||
CapabilityData GetLbvcDecoderCapability();
|
||||
CapabilityData GetLbvcEncoderCapability();
|
||||
CapabilityData GetVendorAacEncoderCapability();
|
||||
#ifdef AV_CODEC_AUDIO_VIVID_CAPACITY
|
||||
CapabilityData GetVividDecoderCapability();
|
||||
CapabilityData GetAmrnbEncoderCapability();
|
||||
|
@ -284,7 +284,11 @@ std::vector<std::string> CodecListCore::FindCodecNameArray(const std::string &mi
|
||||
|
||||
for (auto index : iter->second) {
|
||||
if (capabilityArray[index].codecType == codecType) {
|
||||
nameArray.push_back(capabilityArray[index].codecName);
|
||||
if (capabilityArray[index].codecName == std::string("OH.Media.Codec.Encoder.Audio.Vendor.AAC")) {
|
||||
nameArray.insert(nameArray.begin(), capabilityArray[index].codecName);
|
||||
} else {
|
||||
nameArray.push_back(capabilityArray[index].codecName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return nameArray;
|
||||
|
@ -806,4 +806,31 @@ Status FFmpegAACEncoderPlugin::CloseCtxLocked()
|
||||
} // namespace Ffmpeg
|
||||
} // namespace Plugins
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
} // namespace OHOS
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
||||
#define FFMPEG_AAC_ENCODER_EXPORT extern "C" __declspec(dllexport)
|
||||
#else
|
||||
#if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
|
||||
#define FFMPEG_AAC_ENCODER_EXPORT extern "C" __attribute__((visibility("default")))
|
||||
#else
|
||||
#define FFMPEG_AAC_ENCODER_EXPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
using namespace Ffmpeg;
|
||||
FFMPEG_AAC_ENCODER_EXPORT CodecPlugin *CreateFFmpegAacEncoderPluginObject()
|
||||
{
|
||||
const std::string name = std::string(OHOS::MediaAVCodec::AVCodecCodecName::AUDIO_ENCODER_AAC_NAME);
|
||||
CodecPlugin *obj = new FFmpegAACEncoderPlugin(name);
|
||||
return obj;
|
||||
}
|
||||
|
||||
FFMPEG_AAC_ENCODER_EXPORT void DestroyFFmpegAacEncoderPluginObject(CodecPlugin *obj)
|
||||
{
|
||||
if (obj != nullptr) {
|
||||
delete obj;
|
||||
}
|
||||
}
|
||||
}
|
@ -339,13 +339,30 @@ std::vector<uint8_t> GenerateAACCodecConfig(int32_t profile, int32_t sampleRate,
|
||||
profileVal = it1->second;
|
||||
}
|
||||
int32_t sampleRateIndex = 0x10;
|
||||
int32_t baseIndex = 0xF;
|
||||
auto it2 = sampleRates.find(sampleRate);
|
||||
if (it2 != sampleRates.end()) {
|
||||
sampleRateIndex = it2->second;
|
||||
}
|
||||
std::vector<uint8_t> codecConfig = {0, 0, 0x56, 0xE5, 0};
|
||||
codecConfig[0] = ((profileVal + 1) << 0x03) | ((sampleRateIndex & 0x0F) >> 0x01);
|
||||
codecConfig[1] = ((sampleRateIndex & 0x01) << 0x07) | ((channels & 0x0F) << 0x03);
|
||||
it2 = sampleRates.find(sampleRate / 2); // 2: HE-AAC require divide base sample rate
|
||||
if (it2 != sampleRates.end()) {
|
||||
baseIndex = it2->second;
|
||||
}
|
||||
std::vector<uint8_t> codecConfig;
|
||||
if (profile == AAC_PROFILE_HE || profile == AAC_PROFILE_HE_V2) {
|
||||
codecConfig = {0, 0, 0, 0, 0};
|
||||
// 5 bit AOT(0x03:left 3 bits for sample rate) + 4 bit sample rate idx(0x01: 4 - 0x03)
|
||||
codecConfig[0] = ((profileVal + 1) << 0x03) | ((baseIndex & 0x0F) >> 0x01);
|
||||
// 0x07: left 7bits for other, 4 bit channel cfg,0x03:left for other
|
||||
codecConfig[1] = ((baseIndex & 0x01) << 0x07) | ((channels & 0x0F) << 0x03) | ((sampleRateIndex & 0x0F) >> 1) ;
|
||||
// 4 bit ext sample rate idx(0x07: left 7 bits for other) + 4 bit aot(2: LC-AAC, 0x02: left for other)
|
||||
codecConfig[2] = ((sampleRateIndex & 0x01) << 0x07) | (2 << 0x02);
|
||||
} else {
|
||||
codecConfig = {0, 0, 0x56, 0xE5, 0};
|
||||
codecConfig[0] = ((profileVal + 1) << 0x03) | ((sampleRateIndex & 0x0F) >> 0x01);
|
||||
codecConfig[1] = ((sampleRateIndex & 0x01) << 0x07) | ((channels & 0x0F) << 0x03);
|
||||
}
|
||||
|
||||
return codecConfig;
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@ constexpr float LATITUDE_MIN = -90.0f;
|
||||
constexpr float LATITUDE_MAX = 90.0f;
|
||||
constexpr float LONGITUDE_MIN = -180.0f;
|
||||
constexpr float LONGITUDE_MAX = 180.0f;
|
||||
constexpr int32_t MIN_HE_AAC_SAMPLE_RATE = 16000;
|
||||
const std::string TIMED_METADATA_HANDLER_NAME = "timed_metadata";
|
||||
|
||||
bool IsMuxerSupported(const char *name)
|
||||
@ -424,6 +425,11 @@ Status FFmpegMuxerPlugin::SetCodecParameterOfTrack(AVStream *stream, const std::
|
||||
int32_t channels;
|
||||
trackDesc->Get<Tag::MEDIA_PROFILE>(profile);
|
||||
trackDesc->Get<Tag::AUDIO_SAMPLE_RATE>(sampleRate);
|
||||
if ((profile == AAC_PROFILE_HE || profile == AAC_PROFILE_HE_V2) &&
|
||||
sampleRate < MIN_HE_AAC_SAMPLE_RATE) {
|
||||
MEDIA_LOG_E("HE-AAC only support sample rate >= 16k, input rate:%{public}d", sampleRate);
|
||||
return Status::ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
trackDesc->Get<Tag::AUDIO_CHANNEL_COUNT>(channels);
|
||||
codecConfig = GenerateAACCodecConfig(profile, sampleRate, channels);
|
||||
return SetCodecParameterExtra(stream, codecConfig.data(), codecConfig.size());
|
||||
|
@ -150,6 +150,12 @@ ohos_static_library("av_codec_engine_codeclist_mock") {
|
||||
if (av_codec_enable_special_codec) {
|
||||
defines += [ "AV_CODEC_AUDIO_VIVID_CAPACITY" ]
|
||||
}
|
||||
if (target_cpu == "arm64") {
|
||||
av_codec_path = "\"/system/lib64\""
|
||||
} else {
|
||||
av_codec_path = "\"/system/lib\""
|
||||
}
|
||||
defines += [ "AV_CODEC_PATH=${av_codec_path}" ]
|
||||
sanitize = av_codec_sanitize
|
||||
include_dirs = codeclist_coverage_include_dirs
|
||||
|
||||
|
@ -142,6 +142,12 @@ ohos_static_library("av_codec_engine_codeclist_mock") {
|
||||
if (av_codec_enable_special_codec) {
|
||||
defines += [ "AV_CODEC_AUDIO_VIVID_CAPACITY" ]
|
||||
}
|
||||
if (target_cpu == "arm64") {
|
||||
av_codec_path = "\"/system/lib64\""
|
||||
} else {
|
||||
av_codec_path = "\"/system/lib\""
|
||||
}
|
||||
defines += [ "AV_CODEC_PATH=${av_codec_path}" ]
|
||||
sanitize = av_codec_sanitize
|
||||
include_dirs = codec_server_coverage_include_dirs
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user