mirror of
https://gitee.com/openharmony/multimedia_av_codec
synced 2024-11-27 00:50:36 +00:00
!3996 add HE-AAC vendor plugin with the same AAC mime type
Merge pull request !3996 from SuRuoyan/master
This commit is contained in:
commit
bd86b7c888
@ -169,6 +169,7 @@ struct CapabilityData {
|
||||
std::map<ImgSize, Range> measuredFrameRate;
|
||||
bool supportSwapWidthHeight = false;
|
||||
std::map<int32_t, Format> featuresMap;
|
||||
int32_t rank = 0;
|
||||
};
|
||||
|
||||
struct LevelParams {
|
||||
|
@ -312,6 +312,7 @@ CapabilityData AudioCodeclistInfo::GetVendorAacEncoderCapability()
|
||||
audioAacCapability.sampleRate = AUDIO_SAMPLE_RATE;
|
||||
audioAacCapability.maxInstance = MAX_SUPPORT_AUDIO_INSTANCE;
|
||||
audioAacCapability.profiles = { AAC_PROFILE_LC, AAC_PROFILE_HE, AAC_PROFILE_HE_V2 };
|
||||
audioAacCapability.rank = 1; // larger than default rank 0
|
||||
return audioAacCapability;
|
||||
}
|
||||
#endif
|
||||
|
@ -64,6 +64,21 @@ CodecAbilitySingleton::CodecAbilitySingleton()
|
||||
RegisterCapabilityArray(capaArray, codecType);
|
||||
}
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::sort(capabilityDataArray_.begin(), capabilityDataArray_.end(),
|
||||
[](CapabilityData a, CapabilityData b) {
|
||||
return a.rank > b.rank;
|
||||
});
|
||||
size_t idx = 0;
|
||||
for (auto iter = capabilityDataArray_.begin(); iter != capabilityDataArray_.end(); iter++) {
|
||||
std::string mimeType = (*iter).mimeType;
|
||||
if (mimeCapIdxMap_.find(mimeType) == mimeCapIdxMap_.end()) {
|
||||
std::vector<size_t> idxVec;
|
||||
mimeCapIdxMap_.insert(std::make_pair(mimeType, idxVec));
|
||||
}
|
||||
mimeCapIdxMap_.at(mimeType).emplace_back(idx);
|
||||
idx++;
|
||||
}
|
||||
AVCODEC_LOGI("Succeed");
|
||||
}
|
||||
|
||||
@ -75,13 +90,7 @@ CodecAbilitySingleton::~CodecAbilitySingleton()
|
||||
void CodecAbilitySingleton::RegisterCapabilityArray(std::vector<CapabilityData> &capaArray, CodecType codecType)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
size_t beginIdx = capabilityDataArray_.size();
|
||||
for (auto iter = capaArray.begin(); iter != capaArray.end(); iter++) {
|
||||
std::string mimeType = (*iter).mimeType;
|
||||
std::vector<size_t> idxVec;
|
||||
if (mimeCapIdxMap_.find(mimeType) == mimeCapIdxMap_.end()) {
|
||||
mimeCapIdxMap_.insert(std::make_pair(mimeType, idxVec));
|
||||
}
|
||||
if ((*iter).profileLevelsMap.size() > MAX_MAP_SIZE) {
|
||||
while ((*iter).profileLevelsMap.size() > MAX_MAP_SIZE) {
|
||||
auto rIter = (*iter).profileLevelsMap.end();
|
||||
@ -100,9 +109,7 @@ void CodecAbilitySingleton::RegisterCapabilityArray(std::vector<CapabilityData>
|
||||
(*iter).measuredFrameRate.erase(--rIter);
|
||||
}
|
||||
capabilityDataArray_.emplace_back(*iter);
|
||||
mimeCapIdxMap_.at(mimeType).emplace_back(beginIdx);
|
||||
nameCodecTypeMap_.insert(std::make_pair((*iter).codecName, codecType));
|
||||
beginIdx++;
|
||||
}
|
||||
AVCODEC_LOGD("Register capability successful");
|
||||
}
|
||||
|
@ -284,11 +284,7 @@ std::vector<std::string> CodecListCore::FindCodecNameArray(const std::string &mi
|
||||
|
||||
for (auto index : iter->second) {
|
||||
if (capabilityArray[index].codecType == codecType) {
|
||||
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);
|
||||
}
|
||||
nameArray.push_back(capabilityArray[index].codecName);
|
||||
}
|
||||
}
|
||||
return nameArray;
|
||||
|
@ -554,7 +554,15 @@ bool FFmpegAACEncoderPlugin::CheckResample() const
|
||||
Status FFmpegAACEncoderPlugin::GetMetaData(const std::shared_ptr<Meta> &meta)
|
||||
{
|
||||
int32_t type;
|
||||
int32_t aacProfile;
|
||||
MEDIA_LOG_I("GetMetaData enter");
|
||||
if (meta->Get<Tag::MEDIA_PROFILE>(aacProfile)) {
|
||||
if (aacProfile != AAC_PROFILE_LC) {
|
||||
MEDIA_LOG_E("this plugin only support LC-AAC, input profile:%{public}d", aacProfile);
|
||||
return Status::ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
|
||||
if (meta->Get<Tag::AUDIO_AAC_IS_ADTS>(type)) {
|
||||
aacName_ = (type == 1 ? "aac" : "aac_latm");
|
||||
}
|
||||
|
@ -62,6 +62,7 @@ bool CodecListParcel::Marshalling(MessageParcel &parcel, CapabilityData &capabil
|
||||
(void)Marshalling(parcel, capabilityData.profileLevelsMap);
|
||||
(void)parcel.WriteBool(capabilityData.supportSwapWidthHeight);
|
||||
(void)Marshalling(parcel, capabilityData.featuresMap);
|
||||
(void)parcel.WriteInt32(capabilityData.rank);
|
||||
AVCODEC_LOGD("success to Marshalling capabilityDataArray");
|
||||
|
||||
return true;
|
||||
@ -141,6 +142,7 @@ bool CodecListParcel::Unmarshalling(MessageParcel &parcel, CapabilityData &capab
|
||||
capabilityData.supportSwapWidthHeight = parcel.ReadBool();
|
||||
CHECK_AND_RETURN_RET_LOG(Unmarshalling(parcel, capabilityData.featuresMap), false,
|
||||
"failed to Unmarshalling features map");
|
||||
capabilityData.rank = parcel.ReadInt32();
|
||||
AVCODEC_LOGD("success to Unmarshalling capabilityDataArray");
|
||||
return true;
|
||||
}
|
||||
|
@ -30,6 +30,9 @@
|
||||
#include "native_avformat.h"
|
||||
#include "avcodec_errors.h"
|
||||
#include "native_avcodec_audioencoder.h"
|
||||
#include "native_avcodec_audiocodec.h"
|
||||
#include "native_avcodec_base.h"
|
||||
#include "native_avcapability.h"
|
||||
#include "securec.h"
|
||||
#include "ffmpeg_converter.h"
|
||||
|
||||
@ -100,6 +103,20 @@ public:
|
||||
std::queue<OH_AVCodecBufferAttr> attrQueue_;
|
||||
};
|
||||
|
||||
class AEncSignalAv {
|
||||
public:
|
||||
std::mutex inMutex_;
|
||||
std::mutex outMutex_;
|
||||
std::mutex startMutex_;
|
||||
std::condition_variable inCond_;
|
||||
std::condition_variable outCond_;
|
||||
std::condition_variable startCond_;
|
||||
std::queue<uint32_t> inQueue_;
|
||||
std::queue<uint32_t> outQueue_;
|
||||
std::queue<OH_AVBuffer*> inBufferQueue_;
|
||||
std::queue<OH_AVBuffer*> outBufferQueue_;
|
||||
};
|
||||
|
||||
static void OnError(OH_AVCodec *codec, int32_t errorCode, void *userData)
|
||||
{
|
||||
(void)codec;
|
||||
@ -142,6 +159,30 @@ static void OnOutputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemo
|
||||
signal->outCond_.notify_all();
|
||||
}
|
||||
|
||||
static void OnInputBufferAvailableAv(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *data, void *userData)
|
||||
{
|
||||
(void)codec;
|
||||
AEncSignalAv *signal = static_cast<AEncSignalAv *>(userData);
|
||||
unique_lock<mutex> lock(signal->inMutex_);
|
||||
signal->inQueue_.push(index);
|
||||
signal->inBufferQueue_.push(data);
|
||||
signal->inCond_.notify_all();
|
||||
}
|
||||
|
||||
static void OnOutputBufferAvailableAv(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *data, void *userData)
|
||||
{
|
||||
(void)codec;
|
||||
AEncSignalAv *signal = static_cast<AEncSignalAv *>(userData);
|
||||
unique_lock<mutex> lock(signal->outMutex_);
|
||||
signal->outQueue_.push(index);
|
||||
signal->outBufferQueue_.push(data);
|
||||
if (data) {
|
||||
} else {
|
||||
cout << "OnOutputBufferAvailable error, attr is nullptr!" << endl;
|
||||
}
|
||||
signal->outCond_.notify_all();
|
||||
}
|
||||
|
||||
class AudioCodeCapiEncoderUnitTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
@ -149,9 +190,13 @@ public:
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
int32_t ProceFunc(const std::string codecName = CODEC_FLAC_NAME);
|
||||
int32_t ProceByMimeFunc(const std::string mime, bool isEncoder);
|
||||
int32_t ProceByCapabilityFunc(const std::string mime, bool isEncoder);
|
||||
int32_t CheckSoFunc();
|
||||
void InputFunc();
|
||||
void OutputFunc();
|
||||
void InputFuncAv();
|
||||
void OutputFuncAv();
|
||||
|
||||
protected:
|
||||
std::atomic<bool> isRunning_ = false;
|
||||
@ -165,7 +210,9 @@ protected:
|
||||
std::string outputFilePath_ = FLAC_OUTPUT_FILE_PATH.data();
|
||||
|
||||
struct OH_AVCodecAsyncCallback cb_;
|
||||
AEncSignal *signal_;
|
||||
struct OH_AVCodecCallback avcb_;
|
||||
AEncSignal *signal_ = nullptr;
|
||||
AEncSignalAv *signalAv_ = nullptr;
|
||||
OH_AVCodec *audioEnc_;
|
||||
OH_AVFormat *format;
|
||||
bool isFirstFrame_ = true;
|
||||
@ -189,6 +236,14 @@ void AudioCodeCapiEncoderUnitTest::SetUp(void)
|
||||
|
||||
void AudioCodeCapiEncoderUnitTest::TearDown(void)
|
||||
{
|
||||
if (signal_ != nullptr) {
|
||||
delete signal_;
|
||||
signal_ = nullptr;
|
||||
}
|
||||
if (signalAv_ != nullptr) {
|
||||
delete signalAv_;
|
||||
signalAv_ = nullptr;
|
||||
}
|
||||
cout << "[TearDown]: over!!!" << endl;
|
||||
}
|
||||
|
||||
@ -294,6 +349,125 @@ int32_t AudioCodeCapiEncoderUnitTest::ProceFunc(const std::string codecName)
|
||||
return AVCS_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t AudioCodeCapiEncoderUnitTest::ProceByMimeFunc(const std::string mime, bool isEncoder)
|
||||
{
|
||||
audioEnc_ = OH_AudioCodec_CreateByMime(mime.c_str(), isEncoder);
|
||||
EXPECT_NE((OH_AVCodec *)nullptr, audioEnc_);
|
||||
|
||||
signalAv_ = new AEncSignalAv();
|
||||
EXPECT_NE(nullptr, signal);
|
||||
|
||||
avcb_ = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailableAv, &OnOutputBufferAvailableAv};
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_RegisterCallback(audioEnc_, avcb_, signalAv_));
|
||||
|
||||
format = OH_AVFormat_Create();
|
||||
return AVCS_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t AudioCodeCapiEncoderUnitTest::ProceByCapabilityFunc(const std::string mime, bool isEncoder)
|
||||
{
|
||||
OH_AVCapability *cap = OH_AVCodec_GetCapability(mime.c_str(), isEncoder);
|
||||
const char *name = OH_AVCapability_GetName(cap);
|
||||
audioEnc_ = OH_AudioCodec_CreateByName(name);
|
||||
EXPECT_NE((OH_AVCodec *)nullptr, audioEnc_);
|
||||
|
||||
signalAv_ = new AEncSignalAv();
|
||||
EXPECT_NE(nullptr, signal);
|
||||
|
||||
avcb_ = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailableAv, &OnOutputBufferAvailableAv};
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_RegisterCallback(audioEnc_, avcb_, signalAv_));
|
||||
|
||||
format = OH_AVFormat_Create();
|
||||
return AVCS_ERR_OK;
|
||||
}
|
||||
|
||||
void AudioCodeCapiEncoderUnitTest::InputFuncAv()
|
||||
{
|
||||
OH_AVCodecBufferAttr info = {};
|
||||
bool isEos = false;
|
||||
inputFile_ = std::make_unique<std::ifstream>(inputFilePath_, std::ios::binary);
|
||||
if (!inputFile_->is_open()) {
|
||||
std::cout << "open file failed, path: " << inputFilePath_ << std::endl;
|
||||
return;
|
||||
}
|
||||
while (isRunning_.load()) {
|
||||
unique_lock<mutex> lock(signalAv_->inMutex_);
|
||||
signalAv_->inCond_.wait(lock, [this]() { return (signalAv_->inQueue_.size() > 0 || !isRunning_.load()); });
|
||||
if (!isRunning_.load()) {
|
||||
break;
|
||||
}
|
||||
uint32_t index = signalAv_->inQueue_.front();
|
||||
auto buffer = signalAv_->inBufferQueue_.front();
|
||||
isEos = !inputFile_->eof();
|
||||
if (!isEos) {
|
||||
inputFile_->read((char *)OH_AVBuffer_GetAddr(buffer), frameBytes_);
|
||||
}
|
||||
info.size = frameBytes_;
|
||||
info.flags = AVCODEC_BUFFER_FLAGS_NONE;
|
||||
if (isEos) {
|
||||
info.size = 0;
|
||||
info.flags = AVCODEC_BUFFER_FLAGS_EOS;
|
||||
} else if (isFirstFrame_) {
|
||||
info.flags = AVCODEC_BUFFER_FLAGS_CODEC_DATA;
|
||||
isFirstFrame_ = false;
|
||||
}
|
||||
info.offset = 0;
|
||||
OH_AVBuffer_SetBufferAttr(buffer, &info);
|
||||
int32_t ret = OH_AudioCodec_PushInputBuffer(audioEnc_, index);
|
||||
signalAv_->inQueue_.pop();
|
||||
signalAv_->inBufferQueue_.pop();
|
||||
if (ret != AVCS_ERR_OK) {
|
||||
isRunning_ = false;
|
||||
break;
|
||||
}
|
||||
if (isEos) {
|
||||
break;
|
||||
}
|
||||
timeStamp_ += FRAME_DURATION_US;
|
||||
}
|
||||
inputFile_->close();
|
||||
}
|
||||
|
||||
void AudioCodeCapiEncoderUnitTest::OutputFuncAv()
|
||||
{
|
||||
std::ofstream outputFile;
|
||||
outputFile.open(outputFilePath_, std::ios::out | std::ios::binary);
|
||||
if (!outputFile.is_open()) {
|
||||
std::cout << "open file failed, path: " << outputFilePath_ << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
while (isRunning_.load()) {
|
||||
unique_lock<mutex> lock(signalAv_->outMutex_);
|
||||
signalAv_->outCond_.wait(lock, [this]() { return (signalAv_->outQueue_.size() > 0 || !isRunning_.load()); });
|
||||
|
||||
if (!isRunning_.load()) {
|
||||
cout << "wait to stop, exit" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t index = signalAv_->outQueue_.front();
|
||||
auto *data = signalAv_->outBufferQueue_.front();
|
||||
OH_AVCodecBufferAttr attr;
|
||||
OH_AVBuffer_GetBufferAttr(data, &attr);
|
||||
if (data != nullptr) {
|
||||
outputFile.write(reinterpret_cast<char *>(OH_AVBuffer_GetAddr(data)), attr.size);
|
||||
}
|
||||
if (data != nullptr && (attr.flags == AVCODEC_BUFFER_FLAGS_EOS || attr.size == 0)) {
|
||||
cout << "encode eos" << endl;
|
||||
isRunning_.store(false);
|
||||
signalAv_->startCond_.notify_all();
|
||||
}
|
||||
signalAv_->outBufferQueue_.pop();
|
||||
signalAv_->outQueue_.pop();
|
||||
if (OH_AudioCodec_FreeOutputBuffer(audioEnc_, index) != AV_ERR_OK) {
|
||||
cout << "Fatal: FreeOutputData fail" << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
outputFile.close();
|
||||
}
|
||||
|
||||
int32_t AudioCodeCapiEncoderUnitTest::CheckSoFunc()
|
||||
{
|
||||
soFile_ = std::make_unique<std::ifstream>(OPUS_SO_FILE_PATH, std::ios::binary);
|
||||
@ -1441,5 +1615,211 @@ HWTEST_F(AudioCodeCapiEncoderUnitTest, g711muNormal, TestSize.Level1)
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioEncoder_Flush(audioEnc_));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioEncoder_Destroy(audioEnc_));
|
||||
}
|
||||
|
||||
HWTEST_F(AudioCodeCapiEncoderUnitTest, EncoderConfigureLCAAC, TestSize.Level1)
|
||||
{
|
||||
inputFilePath_ = AAC_INPUT_FILE_PATH;
|
||||
outputFilePath_ = AAC_OUTPUT_FILE_PATH;
|
||||
frameBytes_ = AAC_DEFAULT_FRAME_BYTES;
|
||||
ProceByMimeFunc(OH_AVCODEC_MIMETYPE_AUDIO_AAC, true);
|
||||
OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, CHANNEL_COUNT);
|
||||
OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_S16LE);
|
||||
OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, BITS_RATE);
|
||||
OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, SAMPLE_RATE);
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format));
|
||||
isRunning_.store(true);
|
||||
|
||||
inputLoop_ = make_unique<thread>(&AudioCodeCapiEncoderUnitTest::InputFuncAv, this);
|
||||
EXPECT_NE(nullptr, inputLoop_);
|
||||
outputLoop_ = make_unique<thread>(&AudioCodeCapiEncoderUnitTest::OutputFuncAv, this);
|
||||
EXPECT_NE(nullptr, outputLoop_);
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioEnc_));
|
||||
while (isRunning_.load()) {
|
||||
sleep(1); // sleep 1s
|
||||
}
|
||||
|
||||
isRunning_.store(false);
|
||||
if (inputLoop_ != nullptr && inputLoop_->joinable()) {
|
||||
{
|
||||
unique_lock<mutex> lock(signalAv_->inMutex_);
|
||||
signalAv_->inCond_.notify_all();
|
||||
}
|
||||
inputLoop_->join();
|
||||
}
|
||||
|
||||
if (outputLoop_ != nullptr && outputLoop_->joinable()) {
|
||||
{
|
||||
unique_lock<mutex> lock(signalAv_->outMutex_);
|
||||
signalAv_->outCond_.notify_all();
|
||||
}
|
||||
outputLoop_->join();
|
||||
}
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioEnc_));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioEnc_));
|
||||
}
|
||||
|
||||
HWTEST_F(AudioCodeCapiEncoderUnitTest, EncoderConfigureHEAAC, TestSize.Level1)
|
||||
{
|
||||
inputFilePath_ = AAC_INPUT_FILE_PATH;
|
||||
outputFilePath_ = AAC_OUTPUT_FILE_PATH;
|
||||
frameBytes_ = AAC_DEFAULT_FRAME_BYTES;
|
||||
OH_AVCodec *tmpCodec = OH_AudioCodec_CreateByName("OH.Media.Codec.Encoder.Audio.Vendor.AAC");
|
||||
bool vendorExist = (tmpCodec != nullptr);
|
||||
if (vendorExist) {
|
||||
OH_AudioCodec_Destroy(tmpCodec);
|
||||
tmpCodec = nullptr;
|
||||
}
|
||||
|
||||
ProceByMimeFunc(OH_AVCODEC_MIMETYPE_AUDIO_AAC, true);
|
||||
OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, CHANNEL_COUNT);
|
||||
OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_S16LE);
|
||||
OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, BITS_RATE);
|
||||
OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, SAMPLE_RATE);
|
||||
OH_AVFormat_SetIntValue(format, OH_MD_KEY_PROFILE, AAC_PROFILE_HE);
|
||||
if (vendorExist) {
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format));
|
||||
} else {
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioEnc_));
|
||||
return;
|
||||
}
|
||||
|
||||
isRunning_.store(true);
|
||||
|
||||
inputLoop_ = make_unique<thread>(&AudioCodeCapiEncoderUnitTest::InputFuncAv, this);
|
||||
EXPECT_NE(nullptr, inputLoop_);
|
||||
outputLoop_ = make_unique<thread>(&AudioCodeCapiEncoderUnitTest::OutputFuncAv, this);
|
||||
EXPECT_NE(nullptr, outputLoop_);
|
||||
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioEnc_));
|
||||
while (isRunning_.load()) {
|
||||
sleep(1); // sleep 1s
|
||||
}
|
||||
|
||||
isRunning_.store(false);
|
||||
if (inputLoop_ != nullptr && inputLoop_->joinable()) {
|
||||
{
|
||||
unique_lock<mutex> lock(signalAv_->inMutex_);
|
||||
signalAv_->inCond_.notify_all();
|
||||
}
|
||||
inputLoop_->join();
|
||||
}
|
||||
|
||||
if (outputLoop_ != nullptr && outputLoop_->joinable()) {
|
||||
{
|
||||
unique_lock<mutex> lock(signalAv_->outMutex_);
|
||||
signalAv_->outCond_.notify_all();
|
||||
}
|
||||
outputLoop_->join();
|
||||
}
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioEnc_));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioEnc_));
|
||||
}
|
||||
|
||||
HWTEST_F(AudioCodeCapiEncoderUnitTest, EncoderConfigureHEAACv2, TestSize.Level1)
|
||||
{
|
||||
inputFilePath_ = AAC_INPUT_FILE_PATH;
|
||||
outputFilePath_ = AAC_OUTPUT_FILE_PATH;
|
||||
frameBytes_ = AAC_DEFAULT_FRAME_BYTES;
|
||||
OH_AVCodec *tmpCodec = OH_AudioCodec_CreateByName("OH.Media.Codec.Encoder.Audio.Vendor.AAC");
|
||||
bool vendorExist = (tmpCodec != nullptr);
|
||||
if (vendorExist) {
|
||||
OH_AudioCodec_Destroy(tmpCodec);
|
||||
tmpCodec = nullptr;
|
||||
}
|
||||
ProceByMimeFunc(OH_AVCODEC_MIMETYPE_AUDIO_AAC, true);
|
||||
OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, CHANNEL_COUNT);
|
||||
OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_S16LE);
|
||||
OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, BITS_RATE);
|
||||
OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, SAMPLE_RATE);
|
||||
OH_AVFormat_SetIntValue(format, OH_MD_KEY_PROFILE, AAC_PROFILE_HE_V2);
|
||||
if (vendorExist) {
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format));
|
||||
} else {
|
||||
EXPECT_NE(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioEnc_));
|
||||
return;
|
||||
}
|
||||
isRunning_.store(true);
|
||||
|
||||
inputLoop_ = make_unique<thread>(&AudioCodeCapiEncoderUnitTest::InputFuncAv, this);
|
||||
EXPECT_NE(nullptr, inputLoop_);
|
||||
outputLoop_ = make_unique<thread>(&AudioCodeCapiEncoderUnitTest::OutputFuncAv, this);
|
||||
EXPECT_NE(nullptr, outputLoop_);
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioEnc_));
|
||||
while (isRunning_.load()) {
|
||||
sleep(1); // sleep 1s
|
||||
}
|
||||
|
||||
isRunning_.store(false);
|
||||
if (inputLoop_ != nullptr && inputLoop_->joinable()) {
|
||||
{
|
||||
unique_lock<mutex> lock(signalAv_->inMutex_);
|
||||
signalAv_->inCond_.notify_all();
|
||||
}
|
||||
inputLoop_->join();
|
||||
}
|
||||
|
||||
if (outputLoop_ != nullptr && outputLoop_->joinable()) {
|
||||
{
|
||||
unique_lock<mutex> lock(signalAv_->outMutex_);
|
||||
signalAv_->outCond_.notify_all();
|
||||
}
|
||||
outputLoop_->join();
|
||||
}
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioEnc_));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioEnc_));
|
||||
}
|
||||
|
||||
HWTEST_F(AudioCodeCapiEncoderUnitTest, EncoderConfigureByCap, TestSize.Level1)
|
||||
{
|
||||
inputFilePath_ = AAC_INPUT_FILE_PATH;
|
||||
outputFilePath_ = AAC_OUTPUT_FILE_PATH;
|
||||
frameBytes_ = AAC_DEFAULT_FRAME_BYTES;
|
||||
OH_AVCodec *tmpCodec = OH_AudioCodec_CreateByName("OH.Media.Codec.Encoder.Audio.Vendor.AAC");
|
||||
bool vendorExist = (tmpCodec != nullptr);
|
||||
ProceByCapabilityFunc(OH_AVCODEC_MIMETYPE_AUDIO_AAC, true);
|
||||
OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, CHANNEL_COUNT);
|
||||
OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AudioSampleFormat::SAMPLE_S16LE);
|
||||
OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, BITS_RATE);
|
||||
OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, SAMPLE_RATE);
|
||||
if (vendorExist) {
|
||||
OH_AudioCodec_Destroy(tmpCodec);
|
||||
tmpCodec = nullptr;
|
||||
OH_AVFormat_SetIntValue(format, OH_MD_KEY_PROFILE, AAC_PROFILE_HE);
|
||||
}
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Configure(audioEnc_, format));
|
||||
isRunning_.store(true);
|
||||
|
||||
inputLoop_ = make_unique<thread>(&AudioCodeCapiEncoderUnitTest::InputFuncAv, this);
|
||||
EXPECT_NE(nullptr, inputLoop_);
|
||||
outputLoop_ = make_unique<thread>(&AudioCodeCapiEncoderUnitTest::OutputFuncAv, this);
|
||||
EXPECT_NE(nullptr, outputLoop_);
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Start(audioEnc_));
|
||||
while (isRunning_.load()) {
|
||||
sleep(1); // sleep 1s
|
||||
}
|
||||
|
||||
isRunning_.store(false);
|
||||
if (inputLoop_ != nullptr && inputLoop_->joinable()) {
|
||||
{
|
||||
unique_lock<mutex> lock(signalAv_->inMutex_);
|
||||
signalAv_->inCond_.notify_all();
|
||||
}
|
||||
inputLoop_->join();
|
||||
}
|
||||
|
||||
if (outputLoop_ != nullptr && outputLoop_->joinable()) {
|
||||
{
|
||||
unique_lock<mutex> lock(signalAv_->outMutex_);
|
||||
signalAv_->outCond_.notify_all();
|
||||
}
|
||||
outputLoop_->join();
|
||||
}
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Flush(audioEnc_));
|
||||
EXPECT_EQ(OH_AVErrCode::AV_ERR_OK, OH_AudioCodec_Destroy(audioEnc_));
|
||||
}
|
||||
|
||||
} // namespace MediaAVCodec
|
||||
} // namespace OHOS
|
||||
} // namespace OHOS
|
||||
|
@ -875,5 +875,41 @@ HWTEST_F(AudioMediaCodecUnitTest, FFmpegBaseDecoderPlugin_03, TestSize.Level1)
|
||||
EXPECT_EQ(Status::OK, plugin->SetParameter(meta));
|
||||
}
|
||||
|
||||
HWTEST_F(AudioMediaCodecUnitTest, EncoderConfigureLCAAC, TestSize.Level1)
|
||||
{
|
||||
auto mediaCodec = std::make_shared<MediaCodec>();
|
||||
EXPECT_EQ(0, mediaCodec->Init(AAC_MIME_TYPE, true));
|
||||
auto meta = std::make_shared<Meta>();
|
||||
meta->Set<Tag::AUDIO_CHANNEL_COUNT>(1);
|
||||
meta->Set<Tag::AUDIO_SAMPLE_FORMAT>(Plugins::AudioSampleFormat::SAMPLE_F32LE);
|
||||
meta->Set<Tag::AUDIO_SAMPLE_RATE>(SAMPLE_RATE_48k);
|
||||
meta->Set<Tag::MEDIA_BITRATE>(64000); // 64000: valid param
|
||||
EXPECT_EQ(0, mediaCodec->Configure(meta));
|
||||
EXPECT_EQ(0, mediaCodec->Release());
|
||||
}
|
||||
|
||||
HWTEST_F(AudioMediaCodecUnitTest, EncoderConfigureHEAAC, TestSize.Level1)
|
||||
{
|
||||
auto detect = std::make_shared<MediaCodec>();
|
||||
bool vendorExist = (detect->Init("OH.Media.Codec.Encoder.Audio.Vendor.AAC") == 0);
|
||||
auto mediaCodec = std::make_shared<MediaCodec>();
|
||||
EXPECT_EQ(0, mediaCodec->Init(AAC_MIME_TYPE, true));
|
||||
auto meta = std::make_shared<Meta>();
|
||||
meta->Set<Tag::AUDIO_CHANNEL_COUNT>(CHANNEL_COUNT_STEREO);
|
||||
meta->Set<Tag::AUDIO_SAMPLE_FORMAT>(Plugins::AudioSampleFormat::SAMPLE_F32LE);
|
||||
meta->Set<Tag::AUDIO_SAMPLE_RATE>(SAMPLE_RATE_48k);
|
||||
meta->Set<Tag::MEDIA_BITRATE>(64000); // 64000: valid param
|
||||
meta->Set<Tag::MEDIA_PROFILE>(Media::Plugins::AAC_PROFILE_HE);
|
||||
if (vendorExist) {
|
||||
EXPECT_EQ(0, mediaCodec->Configure(meta));
|
||||
mediaCodec->Reset();
|
||||
meta->Set<Tag::MEDIA_PROFILE>(Media::Plugins::AAC_PROFILE_HE_V2);
|
||||
EXPECT_EQ(0, mediaCodec->Configure(meta));
|
||||
} else {
|
||||
EXPECT_NE(0, mediaCodec->Configure(meta));
|
||||
}
|
||||
EXPECT_EQ(0, mediaCodec->Release());
|
||||
}
|
||||
|
||||
} // namespace MediaAVCodec
|
||||
} // namespace OHOS
|
@ -165,7 +165,13 @@ HWTEST_F(CodecListUnitTest, CodecList_GetName_001, TestSize.Level1)
|
||||
capability_ = CodecListMockFactory::GetCapabilityByCategory(mime, true, category);
|
||||
ASSERT_NE(nullptr, capability_) << mime << " can not found!" << std::endl;
|
||||
std::string codecName = capability_->GetName();
|
||||
EXPECT_EQ(nameOfMime, codecName) << mime << " get error name: " << codecName << std::endl;
|
||||
if (mime == std::string(CodecMimeType::AUDIO_AAC)) {
|
||||
bool check = (codecName == nameOfMime ||
|
||||
codecName == std::string(AVCodecCodecName::AUDIO_ENCODER_AAC_NAME));
|
||||
EXPECT_EQ(true, check) << mime << " get error name: " << codecName << std::endl;
|
||||
} else {
|
||||
EXPECT_EQ(nameOfMime, codecName) << mime << " get error name: " << codecName << std::endl;
|
||||
}
|
||||
}
|
||||
if (isHardIncluded_) {
|
||||
for (auto it = CAPABILITY_DECODER_HARD_NAME.begin(); it != CAPABILITY_DECODER_HARD_NAME.end(); ++it) {
|
||||
|
Loading…
Reference in New Issue
Block a user