mirror of
https://gitee.com/openharmony/multimedia_av_codec
synced 2024-11-27 09:01:07 +00:00
清理代码告警,合入aenc功能等
Signed-off-by: zhanghongran <zhanghongran@huawei.com>
This commit is contained in:
parent
3eda247786
commit
83014dcc52
@ -32,7 +32,7 @@ std::shared_ptr<AVCodecVideoDecoder> VideoDecoderFactory::CreateByMime(const std
|
||||
std::shared_ptr<AVCodecVideoDecoderImpl> impl = std::make_shared<AVCodecVideoDecoderImpl>();
|
||||
|
||||
int32_t ret = impl->Init(AVCODEC_TYPE_VIDEO_DECODER, true, mime);
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK,
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK,
|
||||
nullptr, "AVCodec video decoder impl init failed");
|
||||
|
||||
return impl;
|
||||
@ -45,7 +45,7 @@ std::shared_ptr<AVCodecVideoDecoder> VideoDecoderFactory::CreateByName(const std
|
||||
std::shared_ptr<AVCodecVideoDecoderImpl> impl = std::make_shared<AVCodecVideoDecoderImpl>();
|
||||
|
||||
int32_t ret = impl->Init(AVCODEC_TYPE_VIDEO_DECODER, false, name);
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK,
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK,
|
||||
nullptr, "AVCodec video decoder impl init failed");
|
||||
|
||||
return impl;
|
||||
@ -55,7 +55,7 @@ int32_t AVCodecVideoDecoderImpl::Init(AVCodecType type, bool isMimeType, const s
|
||||
{
|
||||
AVCODEC_SYNC_TRACE;
|
||||
codecService_ = AVCodecServiceFactory::GetInstance().CreateCodecService();
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service create failed");
|
||||
|
||||
return codecService_->Init(type, isMimeType, name);
|
||||
@ -77,7 +77,7 @@ AVCodecVideoDecoderImpl::~AVCodecVideoDecoderImpl()
|
||||
|
||||
int32_t AVCodecVideoDecoderImpl::Configure(const Format &format)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -91,7 +91,7 @@ int32_t AVCodecVideoDecoderImpl::Prepare()
|
||||
|
||||
int32_t AVCodecVideoDecoderImpl::Start()
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -100,7 +100,7 @@ int32_t AVCodecVideoDecoderImpl::Start()
|
||||
|
||||
int32_t AVCodecVideoDecoderImpl::Stop()
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -109,7 +109,7 @@ int32_t AVCodecVideoDecoderImpl::Stop()
|
||||
|
||||
int32_t AVCodecVideoDecoderImpl::Flush()
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -118,7 +118,7 @@ int32_t AVCodecVideoDecoderImpl::Flush()
|
||||
|
||||
int32_t AVCodecVideoDecoderImpl::Reset()
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -127,7 +127,7 @@ int32_t AVCodecVideoDecoderImpl::Reset()
|
||||
|
||||
int32_t AVCodecVideoDecoderImpl::Release()
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -136,7 +136,7 @@ int32_t AVCodecVideoDecoderImpl::Release()
|
||||
|
||||
int32_t AVCodecVideoDecoderImpl::SetOutputSurface(sptr<Surface> surface)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -145,7 +145,7 @@ int32_t AVCodecVideoDecoderImpl::SetOutputSurface(sptr<Surface> surface)
|
||||
|
||||
std::shared_ptr<AVSharedMemory> AVCodecVideoDecoderImpl::GetInputBuffer(uint32_t index)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
nullptr, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -154,7 +154,7 @@ std::shared_ptr<AVSharedMemory> AVCodecVideoDecoderImpl::GetInputBuffer(uint32_t
|
||||
|
||||
int32_t AVCodecVideoDecoderImpl::QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -163,7 +163,7 @@ int32_t AVCodecVideoDecoderImpl::QueueInputBuffer(uint32_t index, AVCodecBufferI
|
||||
|
||||
std::shared_ptr<AVSharedMemory> AVCodecVideoDecoderImpl::GetOutputBuffer(uint32_t index)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
nullptr, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -172,7 +172,7 @@ std::shared_ptr<AVSharedMemory> AVCodecVideoDecoderImpl::GetOutputBuffer(uint32_
|
||||
|
||||
int32_t AVCodecVideoDecoderImpl::GetOutputFormat(Format &format)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -181,7 +181,7 @@ int32_t AVCodecVideoDecoderImpl::GetOutputFormat(Format &format)
|
||||
|
||||
int32_t AVCodecVideoDecoderImpl::ReleaseOutputBuffer(uint32_t index, bool render)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -190,7 +190,7 @@ int32_t AVCodecVideoDecoderImpl::ReleaseOutputBuffer(uint32_t index, bool render
|
||||
|
||||
int32_t AVCodecVideoDecoderImpl::SetParameter(const Format &format)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -199,9 +199,9 @@ int32_t AVCodecVideoDecoderImpl::SetParameter(const Format &format)
|
||||
|
||||
int32_t AVCodecVideoDecoderImpl::SetCallback(const std::shared_ptr<AVCodecCallback> &callback)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
CHECK_AND_RETURN_RET_LOG(callback != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(callback != nullptr,
|
||||
AVCS_ERR_INVALID_VAL, "Callback is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
|
@ -32,7 +32,7 @@ std::shared_ptr<AVCodecVideoEncoder> VideoEncoderFactory::CreateByMime(const std
|
||||
std::shared_ptr<AVCodecVideoEncoderImpl> impl = std::make_shared<AVCodecVideoEncoderImpl>();
|
||||
|
||||
int32_t ret = impl->Init(AVCODEC_TYPE_VIDEO_ENCODER, true, mime);
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, nullptr,
|
||||
"AVCodec video encoder impl init failed");
|
||||
|
||||
return impl;
|
||||
@ -45,7 +45,7 @@ std::shared_ptr<AVCodecVideoEncoder> VideoEncoderFactory::CreateByName(const std
|
||||
std::shared_ptr<AVCodecVideoEncoderImpl> impl = std::make_shared<AVCodecVideoEncoderImpl>();
|
||||
|
||||
int32_t ret = impl->Init(AVCODEC_TYPE_VIDEO_ENCODER, false, name);
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, nullptr,
|
||||
"AVCodec video encoder impl init failed");
|
||||
|
||||
return impl;
|
||||
@ -55,7 +55,7 @@ int32_t AVCodecVideoEncoderImpl::Init(AVCodecType type, bool isMimeType, const s
|
||||
{
|
||||
AVCODEC_SYNC_TRACE;
|
||||
codecService_ = AVCodecServiceFactory::GetInstance().CreateCodecService();
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_UNKNOWN, "Codec service create failed");
|
||||
|
||||
return codecService_->Init(type, isMimeType, name);
|
||||
@ -77,7 +77,7 @@ AVCodecVideoEncoderImpl::~AVCodecVideoEncoderImpl()
|
||||
|
||||
int32_t AVCodecVideoEncoderImpl::Configure(const Format &format)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -86,7 +86,7 @@ int32_t AVCodecVideoEncoderImpl::Configure(const Format &format)
|
||||
|
||||
int32_t AVCodecVideoEncoderImpl::Prepare()
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -95,7 +95,7 @@ int32_t AVCodecVideoEncoderImpl::Prepare()
|
||||
|
||||
int32_t AVCodecVideoEncoderImpl::Start()
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -104,7 +104,7 @@ int32_t AVCodecVideoEncoderImpl::Start()
|
||||
|
||||
int32_t AVCodecVideoEncoderImpl::Stop()
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -113,7 +113,7 @@ int32_t AVCodecVideoEncoderImpl::Stop()
|
||||
|
||||
int32_t AVCodecVideoEncoderImpl::Flush()
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -122,7 +122,7 @@ int32_t AVCodecVideoEncoderImpl::Flush()
|
||||
|
||||
int32_t AVCodecVideoEncoderImpl::NotifyEos()
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -131,7 +131,7 @@ int32_t AVCodecVideoEncoderImpl::NotifyEos()
|
||||
|
||||
int32_t AVCodecVideoEncoderImpl::Reset()
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -140,7 +140,7 @@ int32_t AVCodecVideoEncoderImpl::Reset()
|
||||
|
||||
int32_t AVCodecVideoEncoderImpl::Release()
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -149,7 +149,7 @@ int32_t AVCodecVideoEncoderImpl::Release()
|
||||
|
||||
sptr<Surface> AVCodecVideoEncoderImpl::CreateInputSurface()
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
nullptr, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -159,7 +159,7 @@ sptr<Surface> AVCodecVideoEncoderImpl::CreateInputSurface()
|
||||
|
||||
std::shared_ptr<AVSharedMemory> AVCodecVideoEncoderImpl::GetInputBuffer(uint32_t index)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
nullptr, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -168,7 +168,7 @@ std::shared_ptr<AVSharedMemory> AVCodecVideoEncoderImpl::GetInputBuffer(uint32_t
|
||||
|
||||
int32_t AVCodecVideoEncoderImpl::QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -177,7 +177,7 @@ int32_t AVCodecVideoEncoderImpl::QueueInputBuffer(uint32_t index, AVCodecBufferI
|
||||
|
||||
std::shared_ptr<AVSharedMemory> AVCodecVideoEncoderImpl::GetOutputBuffer(uint32_t index)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
nullptr, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -186,7 +186,7 @@ std::shared_ptr<AVSharedMemory> AVCodecVideoEncoderImpl::GetOutputBuffer(uint32_
|
||||
|
||||
int32_t AVCodecVideoEncoderImpl::GetOutputFormat(Format &format)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -195,7 +195,7 @@ int32_t AVCodecVideoEncoderImpl::GetOutputFormat(Format &format)
|
||||
|
||||
int32_t AVCodecVideoEncoderImpl::ReleaseOutputBuffer(uint32_t index)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -204,7 +204,7 @@ int32_t AVCodecVideoEncoderImpl::ReleaseOutputBuffer(uint32_t index)
|
||||
|
||||
int32_t AVCodecVideoEncoderImpl::SetParameter(const Format &format)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
@ -213,9 +213,9 @@ int32_t AVCodecVideoEncoderImpl::SetParameter(const Format &format)
|
||||
|
||||
int32_t AVCodecVideoEncoderImpl::SetCallback(const std::shared_ptr<AVCodecCallback> &callback)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr,
|
||||
AVCS_ERR_INVALID_OPERATION, "Codec service is nullptr");
|
||||
CHECK_AND_RETURN_RET_LOG(callback != nullptr,
|
||||
CHECK_AND_RETURN_RET_LOG(callback != nullptr,
|
||||
AVCS_ERR_INVALID_VAL, "Callback is nullptr");
|
||||
|
||||
AVCODEC_SYNC_TRACE;
|
||||
|
@ -68,6 +68,5 @@ CapabilityData AVCodecListImpl::CreateCapability(std::string codecName)
|
||||
{
|
||||
return codecListService_->CreateCapability(codecName);
|
||||
}
|
||||
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
@ -65,7 +65,7 @@ public:
|
||||
if (codec_ != nullptr && callback_.onStreamChanged != nullptr) {
|
||||
OHOS::sptr<OH_AVFormat> object = new(std::nothrow) OH_AVFormat(format);
|
||||
// The object lifecycle is controlled by the current function stack
|
||||
callback_.onStreamChanged(codec_, static_cast<OH_AVFormat *>(object.GetRefPtr()), userData_);
|
||||
callback_.onStreamChanged(codec_, reinterpret_cast<OH_AVFormat *>(object.GetRefPtr()), userData_);
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ public:
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
if (codec_ != nullptr && callback_.onNeedInputData != nullptr) {
|
||||
struct AudioDecoderObject *audioDecObj = static_cast<AudioDecoderObject *>(codec_);
|
||||
struct AudioDecoderObject *audioDecObj = reinterpret_cast<AudioDecoderObject *>(codec_);
|
||||
CHECK_AND_RETURN_LOG(audioDecObj->audioDecoder_ != nullptr, "audioDecoder_ is nullptr!");
|
||||
if (audioDecObj->isFlushing_.load() || audioDecObj->isStop_.load() || audioDecObj->isEOS_.load()) {
|
||||
AVCODEC_LOGD("At flush, eos or stop, no buffer available");
|
||||
@ -91,7 +91,7 @@ public:
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
if (codec_ != nullptr && callback_.onNeedOutputData != nullptr) {
|
||||
struct AudioDecoderObject *audioDecObj = static_cast<AudioDecoderObject *>(codec_);
|
||||
struct AudioDecoderObject *audioDecObj = reinterpret_cast<AudioDecoderObject *>(codec_);
|
||||
CHECK_AND_RETURN_LOG(audioDecObj->audioDecoder_ != nullptr, "audioDecoder_ is nullptr!");
|
||||
if (audioDecObj->isFlushing_.load() || audioDecObj->isStop_.load()) {
|
||||
AVCODEC_LOGD("At flush or stop, ignore");
|
||||
@ -121,7 +121,7 @@ private:
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, nullptr, "input codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_AUDIO_DECODER, nullptr, "magic error!");
|
||||
|
||||
struct AudioDecoderObject *audioDecObj = static_cast<AudioDecoderObject *>(codec);
|
||||
struct AudioDecoderObject *audioDecObj = reinterpret_cast<AudioDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(audioDecObj->audioDecoder_ != nullptr, nullptr, "audioDecoder_ is nullptr!");
|
||||
|
||||
std::shared_ptr<AVSharedMemory> memory = audioDecObj->audioDecoder_->GetInputBuffer(index);
|
||||
@ -129,7 +129,7 @@ private:
|
||||
|
||||
for (auto &memoryObj : audioDecObj->memoryObjList_) {
|
||||
if (memoryObj->IsEqualMemory(memory)) {
|
||||
return static_cast<OH_AVMemory *>(memoryObj.GetRefPtr());
|
||||
return reinterpret_cast<OH_AVMemory *>(memoryObj.GetRefPtr());
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,7 +137,7 @@ private:
|
||||
CHECK_AND_RETURN_RET_LOG(object != nullptr, nullptr, "failed to new OH_AVMemory");
|
||||
|
||||
audioDecObj->memoryObjList_.push_back(object);
|
||||
return static_cast<OH_AVMemory *>(object.GetRefPtr());
|
||||
return reinterpret_cast<OH_AVMemory *>(object.GetRefPtr());
|
||||
}
|
||||
|
||||
OH_AVMemory *GetOutputData(struct OH_AVCodec *codec, uint32_t index)
|
||||
@ -145,7 +145,7 @@ private:
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, nullptr, "input codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_AUDIO_DECODER, nullptr, "magic error!");
|
||||
|
||||
struct AudioDecoderObject *audioDecObj = static_cast<AudioDecoderObject *>(codec);
|
||||
struct AudioDecoderObject *audioDecObj = reinterpret_cast<AudioDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(audioDecObj->audioDecoder_ != nullptr, nullptr, "audioDecoder_ is nullptr!");
|
||||
|
||||
std::shared_ptr<AVSharedMemory> memory = audioDecObj->audioDecoder_->GetOutputBuffer(index);
|
||||
@ -153,7 +153,7 @@ private:
|
||||
|
||||
for (auto &memoryObj : audioDecObj->memoryObjList_) {
|
||||
if (memoryObj->IsEqualMemory(memory)) {
|
||||
return static_cast<OH_AVMemory *>(memoryObj.GetRefPtr());
|
||||
return reinterpret_cast<OH_AVMemory *>(memoryObj.GetRefPtr());
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,7 +161,7 @@ private:
|
||||
CHECK_AND_RETURN_RET_LOG(object != nullptr, nullptr, "failed to new OH_AVMemory");
|
||||
|
||||
audioDecObj->memoryObjList_.push_back(object);
|
||||
return static_cast<OH_AVMemory *>(object.GetRefPtr());
|
||||
return reinterpret_cast<OH_AVMemory *>(object.GetRefPtr());
|
||||
}
|
||||
|
||||
struct OH_AVCodec *codec_;
|
||||
@ -170,6 +170,12 @@ private:
|
||||
std::mutex mutex_;
|
||||
};
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct OH_AVCodec *OH_AudioDecoder_CreateByMime(const char *mime)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(mime != nullptr, nullptr, "input mime is nullptr!");
|
||||
@ -201,7 +207,7 @@ OH_AVErrCode OH_AudioDecoder_Destroy(struct OH_AVCodec *codec)
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "input codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_AUDIO_DECODER, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
struct AudioDecoderObject *audioDecObj = static_cast<AudioDecoderObject *>(codec);
|
||||
struct AudioDecoderObject *audioDecObj = reinterpret_cast<AudioDecoderObject *>(codec);
|
||||
|
||||
if (audioDecObj != nullptr && audioDecObj->audioDecoder_ != nullptr) {
|
||||
audioDecObj->callback_->StopCallback();
|
||||
@ -228,7 +234,7 @@ OH_AVErrCode OH_AudioDecoder_Configure(struct OH_AVCodec *codec, struct OH_AVFor
|
||||
CHECK_AND_RETURN_RET_LOG(format != nullptr, AV_ERR_INVALID_VAL, "input format is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(format->magic_ == AVMagic::AVCODEC_MAGIC_FORMAT, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
struct AudioDecoderObject *audioDecObj = static_cast<AudioDecoderObject *>(codec);
|
||||
struct AudioDecoderObject *audioDecObj = reinterpret_cast<AudioDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(audioDecObj->audioDecoder_ != nullptr, AV_ERR_INVALID_VAL, "audioDecoder is nullptr!");
|
||||
|
||||
int32_t ret = audioDecObj->audioDecoder_->Configure(format->format_);
|
||||
@ -242,7 +248,7 @@ OH_AVErrCode OH_AudioDecoder_Prepare(struct OH_AVCodec *codec)
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "input codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_AUDIO_DECODER, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
struct AudioDecoderObject *audioDecObj = static_cast<AudioDecoderObject *>(codec);
|
||||
struct AudioDecoderObject *audioDecObj = reinterpret_cast<AudioDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(audioDecObj->audioDecoder_ != nullptr, AV_ERR_INVALID_VAL, "audioDecoder_ is nullptr!");
|
||||
|
||||
int32_t ret = audioDecObj->audioDecoder_->Prepare();
|
||||
@ -255,7 +261,7 @@ OH_AVErrCode OH_AudioDecoder_Start(struct OH_AVCodec *codec)
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "input codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_AUDIO_DECODER, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
struct AudioDecoderObject *audioDecObj = static_cast<AudioDecoderObject *>(codec);
|
||||
struct AudioDecoderObject *audioDecObj = reinterpret_cast<AudioDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(audioDecObj->audioDecoder_ != nullptr, AV_ERR_INVALID_VAL, "audioDecoder_ is nullptr!");
|
||||
audioDecObj->isStop_.store(false);
|
||||
audioDecObj->isEOS_.store(false);
|
||||
@ -270,7 +276,7 @@ OH_AVErrCode OH_AudioDecoder_Stop(struct OH_AVCodec *codec)
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "input codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_AUDIO_DECODER, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
struct AudioDecoderObject *audioDecObj = static_cast<AudioDecoderObject *>(codec);
|
||||
struct AudioDecoderObject *audioDecObj = reinterpret_cast<AudioDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(audioDecObj->audioDecoder_ != nullptr, AV_ERR_INVALID_VAL, "audioDecoder_ is nullptr!");
|
||||
|
||||
audioDecObj->isStop_.store(true);
|
||||
@ -292,7 +298,7 @@ OH_AVErrCode OH_AudioDecoder_Flush(struct OH_AVCodec *codec)
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "input codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_AUDIO_DECODER, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
struct AudioDecoderObject *audioDecObj = static_cast<AudioDecoderObject *>(codec);
|
||||
struct AudioDecoderObject *audioDecObj = reinterpret_cast<AudioDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(audioDecObj->audioDecoder_ != nullptr, AV_ERR_INVALID_VAL, "audioDecoder_ is nullptr!");
|
||||
audioDecObj->isFlushing_.store(true);
|
||||
AVCODEC_LOGD("Set flush status to true");
|
||||
@ -314,7 +320,7 @@ OH_AVErrCode OH_AudioDecoder_Reset(struct OH_AVCodec *codec)
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "input codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_AUDIO_DECODER, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
struct AudioDecoderObject *audioDecObj = static_cast<AudioDecoderObject *>(codec);
|
||||
struct AudioDecoderObject *audioDecObj = reinterpret_cast<AudioDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(audioDecObj->audioDecoder_ != nullptr, AV_ERR_INVALID_VAL, "audioDecoder_ is nullptr!");
|
||||
audioDecObj->isStop_.store(true);
|
||||
AVCODEC_LOGD("Set stop status to true");
|
||||
@ -335,7 +341,7 @@ OH_AVErrCode OH_AudioDecoder_PushInputData(struct OH_AVCodec *codec, uint32_t in
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "input codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_AUDIO_DECODER, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
struct AudioDecoderObject *audioDecObj = static_cast<AudioDecoderObject *>(codec);
|
||||
struct AudioDecoderObject *audioDecObj = reinterpret_cast<AudioDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(audioDecObj->audioDecoder_ != nullptr, AV_ERR_INVALID_VAL, "audioDecoder_ is nullptr!");
|
||||
|
||||
struct AVCodecBufferInfo bufferInfo;
|
||||
@ -359,7 +365,7 @@ OH_AVFormat *OH_AudioDecoder_GetOutputDescription(struct OH_AVCodec *codec)
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, nullptr, "input codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_AUDIO_DECODER, nullptr, "magic error!");
|
||||
|
||||
struct AudioDecoderObject *audioDecObj = static_cast<AudioDecoderObject *>(codec);
|
||||
struct AudioDecoderObject *audioDecObj = reinterpret_cast<AudioDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(audioDecObj->audioDecoder_ != nullptr, nullptr, "audioDecoder_ is nullptr!");
|
||||
|
||||
Format format;
|
||||
@ -377,7 +383,7 @@ OH_AVErrCode OH_AudioDecoder_FreeOutputData(struct OH_AVCodec *codec, uint32_t i
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "input codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_AUDIO_DECODER, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
struct AudioDecoderObject *audioDecObj = static_cast<AudioDecoderObject *>(codec);
|
||||
struct AudioDecoderObject *audioDecObj = reinterpret_cast<AudioDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(audioDecObj->audioDecoder_ != nullptr, AV_ERR_INVALID_VAL, "audioDecoder_ is nullptr!");
|
||||
|
||||
int32_t ret = audioDecObj->audioDecoder_->ReleaseOutputBuffer(index);
|
||||
@ -393,7 +399,7 @@ OH_AVErrCode OH_AudioDecoder_SetParameter(struct OH_AVCodec *codec, struct OH_AV
|
||||
CHECK_AND_RETURN_RET_LOG(format != nullptr, AV_ERR_INVALID_VAL, "input format is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(format->magic_ == AVMagic::AVCODEC_MAGIC_FORMAT, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
struct AudioDecoderObject *audioDecObj = static_cast<AudioDecoderObject *>(codec);
|
||||
struct AudioDecoderObject *audioDecObj = reinterpret_cast<AudioDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(audioDecObj->audioDecoder_ != nullptr, AV_ERR_INVALID_VAL, "audioDecoder_ is nullptr!");
|
||||
|
||||
int32_t ret = audioDecObj->audioDecoder_->SetParameter(format->format_);
|
||||
@ -408,7 +414,7 @@ OH_AVErrCode OH_AudioDecoder_SetCallback(
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "input codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_AUDIO_DECODER, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
struct AudioDecoderObject *audioDecObj = static_cast<AudioDecoderObject *>(codec);
|
||||
struct AudioDecoderObject *audioDecObj = reinterpret_cast<AudioDecoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(audioDecObj->audioDecoder_ != nullptr, AV_ERR_INVALID_VAL, "audioDecoder_ is nullptr!");
|
||||
|
||||
audioDecObj->callback_ = std::make_shared<NativeAudioDecoder>(codec, callback, userData);
|
||||
@ -422,4 +428,10 @@ OH_AVErrCode OH_AudioDecoder_SetCallback(
|
||||
OH_AVErrCode OH_AudioDecoder_IsValid(OH_AVCodec *codec, bool *isVaild)
|
||||
{
|
||||
return AV_ERR_UNSUPPORT;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
} // namesapce Media
|
||||
} // OHOS
|
@ -169,6 +169,12 @@ private:
|
||||
std::mutex mutex_;
|
||||
};
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct OH_AVCodec *OH_AudioEncoder_CreateByMime(const char *mime)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(mime != nullptr, nullptr, "input mime is nullptr!");
|
||||
@ -339,7 +345,7 @@ OH_AVErrCode OH_AudioEncoder_PushInputData(struct OH_AVCodec *codec, uint32_t in
|
||||
bufferInfo.presentationTimeUs = attr.pts;
|
||||
bufferInfo.size = attr.size;
|
||||
bufferInfo.offset = attr.offset;
|
||||
enum AVCodecBufferFlag bufferFlag = static_cast<enum AVCodecBufferFlag>(attr.flags);
|
||||
AVCodecBufferFlag bufferFlag = static_cast<AVCodecBufferFlag>(attr.flags);
|
||||
|
||||
int32_t ret = audioEncObj->audioEncoder_->QueueInputBuffer(index, bufferInfo, bufferFlag);
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AV_ERR_OPERATE_NOT_PERMIT, "audioEncoder QueueInputBuffer failed!");
|
||||
@ -419,4 +425,10 @@ OH_AVErrCode OH_AudioEncoder_SetCallback(
|
||||
OH_AVErrCode OH_AudioEncoder_IsValid(OH_AVCodec *codec, bool *isVaild)
|
||||
{
|
||||
return AV_ERR_UNSUPPORT;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
} // namesapce Media
|
||||
} // OHOS
|
@ -24,7 +24,6 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "NativeCode
|
||||
}
|
||||
|
||||
using namespace OHOS::Media;
|
||||
|
||||
const char *OH_AVCodec_FindEncoder(const OH_AVFormat *format)
|
||||
{
|
||||
std::shared_ptr<AVCodecList> codeclist = AVCodecListFactory::CreateAVCodecList();
|
||||
|
@ -181,7 +181,7 @@ struct OH_AVCodec *OH_VideoEncoder_CreateByName(const char *name)
|
||||
OH_AVErrCode OH_VideoEncoder_Destroy(struct OH_AVCodec *codec)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "Codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER,
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER,
|
||||
AV_ERR_INVALID_VAL, "Codec magic error!");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
@ -207,9 +207,11 @@ OH_AVErrCode OH_VideoEncoder_Destroy(struct OH_AVCodec *codec)
|
||||
OH_AVErrCode OH_VideoEncoder_Configure(struct OH_AVCodec *codec, struct OH_AVFormat *format)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "Codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL, "Codec magic error!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL,
|
||||
"Codec magic error!");
|
||||
CHECK_AND_RETURN_RET_LOG(format != nullptr, AV_ERR_INVALID_VAL, "Format is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(format->magic_ == AVMagic::AVCODEC_MAGIC_FORMAT, AV_ERR_INVALID_VAL, "Format magic error!");
|
||||
CHECK_AND_RETURN_RET_LOG(format->magic_ == AVMagic::AVCODEC_MAGIC_FORMAT, AV_ERR_INVALID_VAL,
|
||||
"Format magic error!");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, AV_ERR_INVALID_VAL, "Video encoder is nullptr!");
|
||||
@ -223,7 +225,8 @@ OH_AVErrCode OH_VideoEncoder_Configure(struct OH_AVCodec *codec, struct OH_AVFor
|
||||
OH_AVErrCode OH_VideoEncoder_Prepare(struct OH_AVCodec *codec)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "Codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL, "Codec magic error!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL,
|
||||
"Codec magic error!");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, AV_ERR_INVALID_VAL, "Video encoder is nullptr!");
|
||||
@ -237,7 +240,8 @@ OH_AVErrCode OH_VideoEncoder_Prepare(struct OH_AVCodec *codec)
|
||||
OH_AVErrCode OH_VideoEncoder_Start(struct OH_AVCodec *codec)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "Codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL, "Codec magic error!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL,
|
||||
"Codec magic error!");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, AV_ERR_INVALID_VAL, "Video encoder is nullptr!");
|
||||
@ -253,7 +257,8 @@ OH_AVErrCode OH_VideoEncoder_Start(struct OH_AVCodec *codec)
|
||||
OH_AVErrCode OH_VideoEncoder_Stop(struct OH_AVCodec *codec)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "Codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL, "Codec magic error!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL,
|
||||
"Codec magic error!");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, AV_ERR_INVALID_VAL, "Video encoder is nullptr!");
|
||||
@ -273,7 +278,8 @@ OH_AVErrCode OH_VideoEncoder_Stop(struct OH_AVCodec *codec)
|
||||
OH_AVErrCode OH_VideoEncoder_Flush(struct OH_AVCodec *codec)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "Codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL, "Codec magic error!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL,
|
||||
"Codec magic error!");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, AV_ERR_INVALID_VAL, "Video encoder is nullptr!");
|
||||
@ -290,7 +296,8 @@ OH_AVErrCode OH_VideoEncoder_Flush(struct OH_AVCodec *codec)
|
||||
OH_AVErrCode OH_VideoEncoder_Reset(struct OH_AVCodec *codec)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "Codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL, "Codec magic error!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL,
|
||||
"Codec magic error!");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, AV_ERR_INVALID_VAL, "Video encoder is nullptr!");
|
||||
@ -310,7 +317,8 @@ OH_AVErrCode OH_VideoEncoder_Reset(struct OH_AVCodec *codec)
|
||||
OH_AVErrCode OH_VideoEncoder_GetSurface(OH_AVCodec *codec, OHNativeWindow **window)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr && window != nullptr, AV_ERR_INVALID_VAL, "Codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL, "Codec magic error!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL,
|
||||
"Codec magic error!");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, AV_ERR_INVALID_VAL, "Video encoder is nullptr!");
|
||||
@ -327,7 +335,8 @@ OH_AVErrCode OH_VideoEncoder_GetSurface(OH_AVCodec *codec, OHNativeWindow **wind
|
||||
OH_AVFormat *OH_VideoEncoder_GetOutputDescription(struct OH_AVCodec *codec)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, nullptr, "Codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, nullptr, "Codec magic error!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, nullptr,
|
||||
"Codec magic error!");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, nullptr, "Video encoder is nullptr!");
|
||||
@ -337,7 +346,8 @@ OH_AVFormat *OH_VideoEncoder_GetOutputDescription(struct OH_AVCodec *codec)
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, nullptr, "Video encoder get output description failed!");
|
||||
|
||||
videoEncObj->outputFormat_ = new(std::nothrow) OH_AVFormat(format);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->outputFormat_ != nullptr, nullptr, "Video encoder get output description failed!");
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->outputFormat_ != nullptr, nullptr,
|
||||
"Video encoder get output description failed!");
|
||||
|
||||
return reinterpret_cast<OH_AVFormat *>(videoEncObj->outputFormat_.GetRefPtr());
|
||||
}
|
||||
@ -345,7 +355,8 @@ OH_AVFormat *OH_VideoEncoder_GetOutputDescription(struct OH_AVCodec *codec)
|
||||
OH_AVErrCode OH_VideoEncoder_FreeOutputData(struct OH_AVCodec *codec, uint32_t index)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "Codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL, "Codec magic error!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL,
|
||||
"Codec magic error!");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, AV_ERR_INVALID_VAL, "Video encoder is nullptr!");
|
||||
@ -359,7 +370,8 @@ OH_AVErrCode OH_VideoEncoder_FreeOutputData(struct OH_AVCodec *codec, uint32_t i
|
||||
OH_AVErrCode OH_VideoEncoder_NotifyEndOfStream(OH_AVCodec *codec)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "Codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL, "Codec magic error!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL,
|
||||
"Codec magic error!");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, AV_ERR_INVALID_VAL, "Video encoder is nullptr!");
|
||||
@ -373,7 +385,8 @@ OH_AVErrCode OH_VideoEncoder_NotifyEndOfStream(OH_AVCodec *codec)
|
||||
OH_AVErrCode OH_VideoEncoder_SetParameter(struct OH_AVCodec *codec, struct OH_AVFormat *format)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "Codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL, "Codec magic error!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL,
|
||||
"Codec magic error!");
|
||||
CHECK_AND_RETURN_RET_LOG(format != nullptr, AV_ERR_INVALID_VAL, "Format is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(format->magic_ == AVMagic::AVCODEC_MAGIC_FORMAT, AV_ERR_INVALID_VAL, "Format magic error!");
|
||||
|
||||
@ -390,7 +403,8 @@ OH_AVErrCode OH_VideoEncoder_SetCallback(
|
||||
struct OH_AVCodec *codec, struct OH_AVCodecAsyncCallback callback, void *userData)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "Codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL, "Codec magic error!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL,
|
||||
"Codec magic error!");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, AV_ERR_INVALID_VAL, "Video encoder is nullptr!");
|
||||
@ -406,7 +420,8 @@ OH_AVErrCode OH_VideoEncoder_SetCallback(
|
||||
OH_AVErrCode OH_VideoEncoder_PushInputData(struct OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "Codec is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL, "Codec magic error!");
|
||||
CHECK_AND_RETURN_RET_LOG(codec->magic_ == AVMagic::AVCODEC_MAGIC_VIDEO_ENCODER, AV_ERR_INVALID_VAL,
|
||||
"Codec magic error!");
|
||||
|
||||
struct VideoEncoderObject *videoEncObj = reinterpret_cast<VideoEncoderObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(videoEncObj->videoEncoder_ != nullptr, AV_ERR_INVALID_VAL, "Video encoder is nullptr!");
|
||||
|
@ -93,7 +93,7 @@ OH_AVErrCode OH_AVDemuxer_UnselectSourceTrackByID(OH_AVDemuxer *demuxer, uint32_
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVDemuxer_CopyNextSample(OH_AVDemuxer *demuxer, uint32_t *trackIndex,
|
||||
uint8_t *buffer, OH_AVCodecBufferAttr *bufferInfo)
|
||||
uint8_t *buffer, OH_AVCodecBufferAttr *bufferInfo)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(demuxer != nullptr, AV_ERR_INVALID_VAL,
|
||||
"Copy sample failed because input demuxer is nullptr!");
|
||||
|
@ -52,7 +52,7 @@ struct OH_AVSource *OH_AVSource_CreateWithFD(int32_t fd, int64_t offset, int64_t
|
||||
{
|
||||
// 0-err, 1-in, 2-out
|
||||
CHECK_AND_RETURN_RET_LOG(fd > 2, nullptr,
|
||||
"Create source with uri failed because input fd is illegal, fd must be greater than 2!");
|
||||
"Create source with uri failed because input fd is illegal, fd must be greater than 2!");
|
||||
CHECK_AND_RETURN_RET_LOG(size >= 0, nullptr, "Create source with uri failed because input size is negative");
|
||||
|
||||
std::shared_ptr<AVSource> source = AVSourceFactory::CreateWithFD(fd, offset, size);
|
||||
@ -67,7 +67,7 @@ struct OH_AVSource *OH_AVSource_CreateWithFD(int32_t fd, int64_t offset, int64_t
|
||||
OH_AVErrCode OH_AVSource_Destroy(OH_AVSource *source)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(source != nullptr, AV_ERR_INVALID_VAL,
|
||||
"Destroy source failed because input source is nullptr!");
|
||||
"Destroy source failed because input source is nullptr!");
|
||||
|
||||
delete source;
|
||||
return AV_ERR_OK;
|
||||
@ -76,15 +76,15 @@ OH_AVErrCode OH_AVSource_Destroy(OH_AVSource *source)
|
||||
OH_AVErrCode OH_AVSource_GetTrackCount(OH_AVSource *source, uint32_t *trackCount)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(source != nullptr, AV_ERR_INVALID_VAL,
|
||||
"Get track count failed because input source is nullptr!");
|
||||
"Get track count failed because input source is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(source->magic_ == AVMagic::AVCODEC_MAGIC_AVSOURCE, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
CHECK_AND_RETURN_RET_LOG(trackCount != nullptr, AV_ERR_INVALID_VAL,
|
||||
"Get track count failed because input trackCount is nullptr!");
|
||||
"Get track count failed because input trackCount is nullptr!");
|
||||
|
||||
struct AVSourceObject *sourceObj = reinterpret_cast<AVSourceObject *>(source);
|
||||
CHECK_AND_RETURN_RET_LOG(sourceObj->source_ != nullptr, AV_ERR_INVALID_VAL,
|
||||
"New AVSourceObject failed when get track count!");
|
||||
"New AVSourceObject failed when get track count!");
|
||||
|
||||
int32_t ret = sourceObj->source_->GetTrackCount(*trackCount);
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AV_ERR_OPERATE_NOT_PERMIT, "source_ GetTrackCount failed!");
|
||||
@ -115,7 +115,7 @@ OH_AVFormat *OH_AVSource_GetSourceFormat(OH_AVSource *source)
|
||||
|
||||
struct AVSourceObject *sourceObj = reinterpret_cast<AVSourceObject *>(source);
|
||||
CHECK_AND_RETURN_RET_LOG(sourceObj->source_ != nullptr, nullptr,
|
||||
"New AVSourceObject failed when get source format!");
|
||||
"New AVSourceObject failed when get source format!");
|
||||
|
||||
Format format;
|
||||
int32_t ret = sourceObj->source_->GetSourceFormat(format);
|
||||
@ -131,16 +131,16 @@ OH_AVFormat *OH_AVSource_GetSourceFormat(OH_AVSource *source)
|
||||
OH_AVErrCode OH_AVSourceTrack_SetTrackFormat(OH_AVSourceTrack *sourceTrack, OH_AVFormat *format)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(sourceTrack != nullptr, AV_ERR_INVALID_VAL,
|
||||
"Set format failed because input sourceTrack is nullptr!");
|
||||
"Set format failed because input sourceTrack is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(sourceTrack->magic_ == AVMagic::AVCODEC_MAGIC_AVSOURCETRACK, AV_ERR_INVALID_VAL,
|
||||
"magic error!");
|
||||
"magic error!");
|
||||
|
||||
CHECK_AND_RETURN_RET_LOG(format != nullptr, AV_ERR_INVALID_VAL,
|
||||
"Set format failed because input param is nullptr!");
|
||||
"Set format failed because input param is nullptr!");
|
||||
|
||||
struct AVSourceTrackObject *sourceTrackObj = reinterpret_cast<AVSourceTrackObject *>(sourceTrack);
|
||||
CHECK_AND_RETURN_RET_LOG(sourceTrackObj->sourceTrack_ != nullptr, AV_ERR_INVALID_VAL,
|
||||
"New AVSourceObject failed when set track format!");
|
||||
"New AVSourceObject failed when set track format!");
|
||||
|
||||
int32_t ret = sourceTrackObj->sourceTrack_->SetTrackFormat(format->format_);
|
||||
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AV_ERR_OPERATE_NOT_PERMIT, "sourceTrack SetTrackFormat failed!");
|
||||
@ -151,12 +151,12 @@ OH_AVErrCode OH_AVSourceTrack_SetTrackFormat(OH_AVSourceTrack *sourceTrack, OH_A
|
||||
OH_AVFormat *OH_AVSourceTrack_GetTrackFormat(OH_AVSourceTrack *sourceTrack)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(sourceTrack != nullptr, nullptr,
|
||||
"Set format failed because input sourceTrack is nullptr!");
|
||||
"Set format failed because input sourceTrack is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(sourceTrack->magic_ == AVMagic::AVCODEC_MAGIC_AVSOURCETRACK, nullptr, "magic error!");
|
||||
|
||||
struct AVSourceTrackObject *sourceTrackObj = reinterpret_cast<AVSourceTrackObject *>(sourceTrack);
|
||||
CHECK_AND_RETURN_RET_LOG(sourceTrackObj->sourceTrack_ != nullptr, nullptr,
|
||||
"New AVSourceObject failed when get track format!");
|
||||
"New AVSourceObject failed when get track format!");
|
||||
|
||||
Format format;
|
||||
int32_t ret = sourceTrackObj->sourceTrack_->GetTrackFormat(format);
|
||||
|
@ -13,27 +13,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "native_avcapability.h"
|
||||
#include <algorithm>
|
||||
#include "native_avmagic.h"
|
||||
#include "avcodec_log.h"
|
||||
#include "avcodec_errors.h"
|
||||
|
||||
// namespace {
|
||||
// constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "OH_AVCapability"};
|
||||
// }
|
||||
#include "native_avcapability.h"
|
||||
|
||||
using namespace OHOS::Media;
|
||||
OH_AVCapability::OH_AVCapability(const CapabilityData &capabilityData) : capabilityData_(capabilityData) {}
|
||||
|
||||
OH_AVCapability::OH_AVCapability(const CapabilityData &capabilityData)
|
||||
: capabilityData_(capabilityData)
|
||||
{
|
||||
}
|
||||
|
||||
OH_AVCapability::~OH_AVCapability()
|
||||
{
|
||||
|
||||
}
|
||||
OH_AVCapability::~OH_AVCapability() {}
|
||||
|
||||
bool OH_AVCapability_IsHardware(OH_AVCapability *capability)
|
||||
{
|
||||
@ -50,7 +39,7 @@ const char *OH_AVCapability_GetMimeType(OH_AVCapability *capability)
|
||||
return empty.data();
|
||||
}
|
||||
|
||||
return capability->capabilityData_.mimeType.data(); //TODO: string data是否安全
|
||||
return capability->capabilityData_.mimeType.data();
|
||||
}
|
||||
|
||||
int32_t OH_AVCapability_GetMaxSupportedInstances(OH_AVCapability *capability)
|
||||
@ -62,8 +51,8 @@ int32_t OH_AVCapability_GetMaxSupportedInstances(OH_AVCapability *capability)
|
||||
return capability->capabilityData_.maxInstance;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVCapability_GetSupportedProfiles(OH_AVCapability *capability,
|
||||
const int32_t **profiles, uint32_t *profileNum)
|
||||
OH_AVErrCode OH_AVCapability_GetSupportedProfiles(OH_AVCapability *capability, const int32_t **profiles,
|
||||
uint32_t *profileNum)
|
||||
{
|
||||
if (capability == nullptr) {
|
||||
std::vector<int32_t> empty;
|
||||
@ -71,15 +60,15 @@ OH_AVErrCode OH_AVCapability_GetSupportedProfiles(OH_AVCapability *capability,
|
||||
*profileNum = empty.size();
|
||||
return AV_ERR_INVALID_VAL;
|
||||
}
|
||||
|
||||
|
||||
auto &vec = capability->capabilityData_.profiles;
|
||||
*profiles = vec.data();
|
||||
*profileNum = vec.size();
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVCapability_GetSupportedLevelsForProfile(OH_AVCapability *capability,
|
||||
int32_t profile, const int32_t **levels, uint32_t *levelNum)
|
||||
OH_AVErrCode OH_AVCapability_GetSupportedLevelsForProfile(OH_AVCapability *capability, int32_t profile,
|
||||
const int32_t **levels, uint32_t *levelNum)
|
||||
{
|
||||
std::vector<int32_t> empty;
|
||||
*levels = empty.data();
|
||||
@ -98,8 +87,7 @@ OH_AVErrCode OH_AVCapability_GetSupportedLevelsForProfile(OH_AVCapability *capab
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
bool OH_AVCapability_ValidateProfileAndLevel(OH_AVCapability *capability,
|
||||
int32_t profile, int32_t level)
|
||||
bool OH_AVCapability_ValidateProfileAndLevel(OH_AVCapability *capability, int32_t profile, int32_t level)
|
||||
{
|
||||
if (capability == nullptr) {
|
||||
return false;
|
||||
@ -109,12 +97,11 @@ bool OH_AVCapability_ValidateProfileAndLevel(OH_AVCapability *capability,
|
||||
if (levels == profileLevelsMap.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return find(levels->second.begin(), levels->second.end(), level) != levels->second.end();
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVCapability_GetEncoderBitrateRange(OH_AVCapability *capability,
|
||||
OH_AVRange *bitrateRange)
|
||||
OH_AVErrCode OH_AVCapability_GetEncoderBitrateRange(OH_AVCapability *capability, OH_AVRange *bitrateRange)
|
||||
{
|
||||
if (capability == nullptr) {
|
||||
bitrateRange->minVal = 0;
|
||||
@ -126,8 +113,7 @@ OH_AVErrCode OH_AVCapability_GetEncoderBitrateRange(OH_AVCapability *capability,
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVCapability_GetEncoderQualityRange(OH_AVCapability *capability,
|
||||
OH_AVRange *qualityRange)
|
||||
OH_AVErrCode OH_AVCapability_GetEncoderQualityRange(OH_AVCapability *capability, OH_AVRange *qualityRange)
|
||||
{
|
||||
if (capability == nullptr) {
|
||||
qualityRange->minVal = 0;
|
||||
@ -139,8 +125,7 @@ OH_AVErrCode OH_AVCapability_GetEncoderQualityRange(OH_AVCapability *capability,
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVCapability_GetEncoderComplexityRange(OH_AVCapability *capability,
|
||||
OH_AVRange *complexityRange)
|
||||
OH_AVErrCode OH_AVCapability_GetEncoderComplexityRange(OH_AVCapability *capability, OH_AVRange *complexityRange)
|
||||
{
|
||||
if (capability == nullptr) {
|
||||
complexityRange->minVal = 0;
|
||||
@ -152,8 +137,7 @@ OH_AVErrCode OH_AVCapability_GetEncoderComplexityRange(OH_AVCapability *capabili
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
bool OH_AVCapability_ValidateVideoEncoderBitrateMode(OH_AVCapability *capability,
|
||||
OH_BitrateMode bitrateMode)
|
||||
bool OH_AVCapability_ValidateVideoEncoderBitrateMode(OH_AVCapability *capability, OH_BitrateMode bitrateMode)
|
||||
{
|
||||
if (capability == nullptr) {
|
||||
return false;
|
||||
@ -162,8 +146,8 @@ bool OH_AVCapability_ValidateVideoEncoderBitrateMode(OH_AVCapability *capability
|
||||
return find(bitrateModeVec.begin(), bitrateModeVec.end(), bitrateMode) != bitrateModeVec.end();
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVCapability_GetAudioSupportedSampleRates(OH_AVCapability *capability,
|
||||
const int32_t **sampleRates, uint32_t *sampleRateNum)
|
||||
OH_AVErrCode OH_AVCapability_GetAudioSupportedSampleRates(OH_AVCapability *capability, const int32_t **sampleRates,
|
||||
uint32_t *sampleRateNum)
|
||||
{
|
||||
if (capability == nullptr) {
|
||||
std::vector<int32_t> empty;
|
||||
@ -171,15 +155,14 @@ OH_AVErrCode OH_AVCapability_GetAudioSupportedSampleRates(OH_AVCapability *capab
|
||||
*sampleRateNum = empty.size();
|
||||
return AV_ERR_INVALID_VAL;
|
||||
}
|
||||
|
||||
|
||||
auto &vec = capability->capabilityData_.sampleRate;
|
||||
*sampleRates = vec.data();
|
||||
*sampleRateNum = vec.size();
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
bool OH_AVCapability_ValidateAudioSampleRate(OH_AVCapability *capability,
|
||||
int32_t sampleRate)
|
||||
bool OH_AVCapability_ValidateAudioSampleRate(OH_AVCapability *capability, int32_t sampleRate)
|
||||
{
|
||||
if (capability == nullptr) {
|
||||
return false;
|
||||
@ -188,8 +171,7 @@ bool OH_AVCapability_ValidateAudioSampleRate(OH_AVCapability *capability,
|
||||
return find(sampeleRateVec.begin(), sampeleRateVec.end(), sampleRate) != sampeleRateVec.end();
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVCapability_GetAudioChannelsRange(OH_AVCapability *capability,
|
||||
OH_AVRange *channelsRange)
|
||||
OH_AVErrCode OH_AVCapability_GetAudioChannelsRange(OH_AVCapability *capability, OH_AVRange *channelsRange)
|
||||
{
|
||||
if (capability == nullptr) {
|
||||
channelsRange->minVal = 0;
|
||||
@ -201,8 +183,8 @@ OH_AVErrCode OH_AVCapability_GetAudioChannelsRange(OH_AVCapability *capability,
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVCapability_GetVideoSupportedPixFormats(OH_AVCapability *capability,
|
||||
const int32_t **pixFormats, uint32_t *pixFormatNum)
|
||||
OH_AVErrCode OH_AVCapability_GetVideoSupportedPixFormats(OH_AVCapability *capability, const int32_t **pixFormats,
|
||||
uint32_t *pixFormatNum)
|
||||
{
|
||||
if (capability == nullptr) {
|
||||
std::vector<int32_t> empty;
|
||||
@ -216,8 +198,7 @@ OH_AVErrCode OH_AVCapability_GetVideoSupportedPixFormats(OH_AVCapability *capabi
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVCapability_GetVideoWidthAlignment(OH_AVCapability *capability,
|
||||
int32_t *widthAlignment)
|
||||
OH_AVErrCode OH_AVCapability_GetVideoWidthAlignment(OH_AVCapability *capability, int32_t *widthAlignment)
|
||||
{
|
||||
if (capability == nullptr) {
|
||||
*widthAlignment = 0;
|
||||
@ -227,8 +208,7 @@ OH_AVErrCode OH_AVCapability_GetVideoWidthAlignment(OH_AVCapability *capability,
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVCapability_GetVideoHeightAlignment(OH_AVCapability *capability,
|
||||
int32_t *heightAlignment)
|
||||
OH_AVErrCode OH_AVCapability_GetVideoHeightAlignment(OH_AVCapability *capability, int32_t *heightAlignment)
|
||||
{
|
||||
if (capability == nullptr) {
|
||||
*heightAlignment = 0;
|
||||
@ -238,32 +218,29 @@ OH_AVErrCode OH_AVCapability_GetVideoHeightAlignment(OH_AVCapability *capability
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVCapability_GetVideoWidthRangeForHeight(OH_AVCapability *capability,
|
||||
int32_t height, OH_AVRange *widthRange)
|
||||
OH_AVErrCode OH_AVCapability_GetVideoWidthRangeForHeight(OH_AVCapability *capability, int32_t height,
|
||||
OH_AVRange *widthRange)
|
||||
{
|
||||
if (capability == nullptr) {
|
||||
widthRange->minVal = 0;
|
||||
widthRange->maxVal = 0;
|
||||
return AV_ERR_INVALID_VAL;
|
||||
}
|
||||
// TODO
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVCapability_GetVideoHeightRangeForWidth(OH_AVCapability *capability,
|
||||
int32_t width, OH_AVRange *heightRange)
|
||||
OH_AVErrCode OH_AVCapability_GetVideoHeightRangeForWidth(OH_AVCapability *capability, int32_t width,
|
||||
OH_AVRange *heightRange)
|
||||
{
|
||||
if (capability == nullptr) {
|
||||
heightRange->minVal = 0;
|
||||
heightRange->maxVal = 0;
|
||||
return AV_ERR_INVALID_VAL;
|
||||
}
|
||||
// TODO
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVCapability_GetVideoWidthRange(OH_AVCapability *capability,
|
||||
OH_AVRange *widthRange)
|
||||
OH_AVErrCode OH_AVCapability_GetVideoWidthRange(OH_AVCapability *capability, OH_AVRange *widthRange)
|
||||
{
|
||||
if (capability == nullptr) {
|
||||
widthRange->minVal = 0;
|
||||
@ -275,8 +252,7 @@ OH_AVErrCode OH_AVCapability_GetVideoWidthRange(OH_AVCapability *capability,
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVCapability_GetVideoHeightRange(OH_AVCapability *capability,
|
||||
OH_AVRange *heightRange)
|
||||
OH_AVErrCode OH_AVCapability_GetVideoHeightRange(OH_AVCapability *capability, OH_AVRange *heightRange)
|
||||
{
|
||||
if (capability == nullptr) {
|
||||
heightRange->minVal = 0;
|
||||
@ -288,24 +264,22 @@ OH_AVErrCode OH_AVCapability_GetVideoHeightRange(OH_AVCapability *capability,
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
bool OH_AVCapability_ValidateVideoSize(OH_AVCapability *capability,
|
||||
int32_t width, int32_t height)
|
||||
bool OH_AVCapability_ValidateVideoSize(OH_AVCapability *capability, int32_t width, int32_t height)
|
||||
{
|
||||
if (capability == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto &alignment = capability->capabilityData_.alignment;
|
||||
if (width == 0 || height == 0 ||
|
||||
alignment.width == 0 || alignment.height == 0 ||
|
||||
width % alignment.width != 0 || height % alignment.height != 0) {
|
||||
if (width == 0 || height == 0 || alignment.width == 0 || alignment.height == 0 || width % alignment.width != 0 ||
|
||||
height % alignment.height != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto &widthRange = capability->capabilityData_.width;
|
||||
auto &heightRange = capability->capabilityData_.height;
|
||||
if (width < widthRange.minVal || width > widthRange.maxVal ||
|
||||
height < heightRange.minVal || height > heightRange.maxVal) {
|
||||
if (width < widthRange.minVal || width > widthRange.maxVal || height < heightRange.minVal ||
|
||||
height > heightRange.maxVal) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -313,9 +287,9 @@ bool OH_AVCapability_ValidateVideoSize(OH_AVCapability *capability,
|
||||
if (blockSize.width == 0 || blockSize.height == 0) {
|
||||
return false;
|
||||
}
|
||||
int blockNum = ((width + blockSize.width - 1) / blockSize.width) *
|
||||
((height + blockSize.height - 1) / blockSize.height);
|
||||
|
||||
int blockNum =
|
||||
((width + blockSize.width - 1) / blockSize.width) * ((height + blockSize.height - 1) / blockSize.height);
|
||||
|
||||
auto &blockPerFrame = capability->capabilityData_.blockPerFrame;
|
||||
if (blockNum < blockPerFrame.minVal || blockNum > blockPerFrame.maxVal) {
|
||||
return false;
|
||||
@ -324,8 +298,7 @@ bool OH_AVCapability_ValidateVideoSize(OH_AVCapability *capability,
|
||||
return true;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVCapability_GetVideoFrameRateRange(OH_AVCapability *capability,
|
||||
OH_AVRange *frameRateRange)
|
||||
OH_AVErrCode OH_AVCapability_GetVideoFrameRateRange(OH_AVCapability *capability, OH_AVRange *frameRateRange)
|
||||
{
|
||||
if (capability == nullptr) {
|
||||
frameRateRange->minVal = 0;
|
||||
@ -337,8 +310,8 @@ OH_AVErrCode OH_AVCapability_GetVideoFrameRateRange(OH_AVCapability *capability,
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVCapability_GetVideoFrameRateRangeForSize(OH_AVCapability *capability,
|
||||
int32_t width, int32_t height, OH_AVRange *frameRateRange)
|
||||
OH_AVErrCode OH_AVCapability_GetVideoFrameRateRangeForSize(OH_AVCapability *capability, int32_t width, int32_t height,
|
||||
OH_AVRange *frameRateRange)
|
||||
{
|
||||
frameRateRange->minVal = 0;
|
||||
frameRateRange->maxVal = 0;
|
||||
@ -346,18 +319,17 @@ OH_AVErrCode OH_AVCapability_GetVideoFrameRateRangeForSize(OH_AVCapability *capa
|
||||
return AV_ERR_INVALID_VAL;
|
||||
}
|
||||
|
||||
if (OH_AVCapability_ValidateVideoSize(capability, width, height)!= AV_ERR_OK) {
|
||||
if (OH_AVCapability_ValidateVideoSize(capability, width, height) != AV_ERR_OK) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
}
|
||||
|
||||
auto &blockSize = capability->capabilityData_.blockSize;
|
||||
auto &blockPerSecond = capability->capabilityData_.blockPerSecond;
|
||||
if (blockSize.width == 0 || blockSize.height == 0 ||
|
||||
blockPerSecond.minVal <= 0 || blockPerSecond.maxVal <= 0) {
|
||||
if (blockSize.width == 0 || blockSize.height == 0 || blockPerSecond.minVal <= 0 || blockPerSecond.maxVal <= 0) {
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
int blockNum = ((width + blockSize.width - 1) / blockSize.width) *
|
||||
((height + blockSize.height - 1) / blockSize.height);
|
||||
int blockNum =
|
||||
((width + blockSize.width - 1) / blockSize.width) * ((height + blockSize.height - 1) / blockSize.height);
|
||||
|
||||
auto &fpsRange = capability->capabilityData_.frameRate;
|
||||
frameRateRange->minVal = std::max((blockPerSecond.minVal + blockNum - 1) / blockNum, fpsRange.minVal);
|
||||
@ -365,8 +337,8 @@ OH_AVErrCode OH_AVCapability_GetVideoFrameRateRangeForSize(OH_AVCapability *capa
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVCapability_GetVideoMeasuredFrameRateRangeForSize(OH_AVCapability *capability,
|
||||
int32_t width, int32_t height, OH_AVRange *frameRateRange)
|
||||
OH_AVErrCode OH_AVCapability_GetVideoMeasuredFrameRateRangeForSize(OH_AVCapability *capability, int32_t width,
|
||||
int32_t height, OH_AVRange *frameRateRange)
|
||||
{
|
||||
frameRateRange->minVal = 0;
|
||||
frameRateRange->maxVal = 0;
|
||||
@ -374,7 +346,7 @@ OH_AVErrCode OH_AVCapability_GetVideoMeasuredFrameRateRangeForSize(OH_AVCapabili
|
||||
return AV_ERR_INVALID_VAL;
|
||||
}
|
||||
|
||||
if (OH_AVCapability_ValidateVideoSize(capability, width, height)!= AV_ERR_OK) {
|
||||
if (OH_AVCapability_ValidateVideoSize(capability, width, height) != AV_ERR_OK) {
|
||||
return AV_ERR_INVALID_VAL;
|
||||
}
|
||||
|
||||
@ -382,8 +354,8 @@ OH_AVErrCode OH_AVCapability_GetVideoMeasuredFrameRateRangeForSize(OH_AVCapabili
|
||||
if (blockSize.width == 0 || blockSize.height == 0) {
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
int32_t blockNum = ((width + blockSize.width - 1) / blockSize.width) *
|
||||
((height + blockSize.height - 1) / blockSize.height);
|
||||
int32_t blockNum =
|
||||
((width + blockSize.width - 1) / blockSize.width) * ((height + blockSize.height - 1) / blockSize.height);
|
||||
|
||||
int32_t minDiff = INT32_MAX;
|
||||
Range fpsRange;
|
||||
@ -393,7 +365,7 @@ OH_AVErrCode OH_AVCapability_GetVideoMeasuredFrameRateRangeForSize(OH_AVCapabili
|
||||
auto iter = measureFps.begin();
|
||||
while (iter != measureFps.end()) {
|
||||
int32_t curBlockNum = (iter->first.width + blockSize.width - 1) / blockSize.width *
|
||||
((iter->first.height + blockSize.height - 1) / blockSize.height);
|
||||
((iter->first.height + blockSize.height - 1) / blockSize.height);
|
||||
int32_t curDiff = std::abs(curBlockNum - blockNum);
|
||||
if (curDiff < minDiff) {
|
||||
minDiff = curDiff;
|
||||
@ -408,26 +380,24 @@ OH_AVErrCode OH_AVCapability_GetVideoMeasuredFrameRateRangeForSize(OH_AVCapabili
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
bool OH_AVCapability_ValidateVideoSizeAndFrameRate(OH_AVCapability *capability,
|
||||
int32_t width, int32_t height, int32_t frameRate)
|
||||
bool OH_AVCapability_ValidateVideoSizeAndFrameRate(OH_AVCapability *capability, int32_t width, int32_t height,
|
||||
int32_t frameRate)
|
||||
{
|
||||
if (capability == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto &alignment = capability->capabilityData_.alignment;
|
||||
if (width == 0 || height == 0 ||
|
||||
alignment.width == 0 || alignment.height == 0 ||
|
||||
width % alignment.width != 0 || height % alignment.height != 0) {
|
||||
if (width == 0 || height == 0 || alignment.width == 0 || alignment.height == 0 || width % alignment.width != 0 ||
|
||||
height % alignment.height != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto &widthRange = capability->capabilityData_.width;
|
||||
auto &heightRange = capability->capabilityData_.height;
|
||||
auto &fpsRange = capability->capabilityData_.frameRate;
|
||||
if (width < widthRange.minVal || width > widthRange.maxVal ||
|
||||
height < heightRange.minVal || height > heightRange.maxVal ||
|
||||
frameRate < fpsRange.minVal || frameRate > fpsRange.maxVal) {
|
||||
if (width < widthRange.minVal || width > widthRange.maxVal || height < heightRange.minVal ||
|
||||
height > heightRange.maxVal || frameRate < fpsRange.minVal || frameRate > fpsRange.maxVal) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -435,15 +405,14 @@ bool OH_AVCapability_ValidateVideoSizeAndFrameRate(OH_AVCapability *capability,
|
||||
if (blockSize.width == 0 || blockSize.height == 0) {
|
||||
return false;
|
||||
}
|
||||
int blockNum = ((width + blockSize.width - 1) / blockSize.width) *
|
||||
((height + blockSize.height - 1) / blockSize.height);
|
||||
int blockNum =
|
||||
((width + blockSize.width - 1) / blockSize.width) * ((height + blockSize.height - 1) / blockSize.height);
|
||||
int blockOneSecond = blockNum * frameRate;
|
||||
auto &blockPerFrame = capability->capabilityData_.blockPerFrame;
|
||||
auto &blockPerSecond = capability->capabilityData_.blockPerSecond;
|
||||
if (blockNum < blockPerFrame.minVal || blockNum > blockPerFrame.maxVal ||
|
||||
blockOneSecond < blockPerSecond.minVal || blockOneSecond > blockPerSecond.maxVal ) {
|
||||
if (blockNum < blockPerFrame.minVal || blockNum > blockPerFrame.maxVal || blockOneSecond < blockPerSecond.minVal ||
|
||||
blockOneSecond > blockPerSecond.maxVal) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -193,8 +193,6 @@ public:
|
||||
* @version 3.1
|
||||
*/
|
||||
virtual int32_t SetCallback(const std::shared_ptr<AVCodecCallback> &callback) = 0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
class __attribute__((visibility("default"))) VideoDecoderFactory {
|
||||
|
@ -100,7 +100,6 @@ public:
|
||||
*/
|
||||
static constexpr std::string_view MD_KEY_ROTATION_ANGLE = "rotation_angle";
|
||||
|
||||
|
||||
/**
|
||||
* Key for video frame rate, value type is double.
|
||||
*/
|
||||
|
@ -20,11 +20,10 @@
|
||||
#include "native_averrors.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct OH_AVCapability OH_AVCapability;
|
||||
|
||||
/**
|
||||
* @brief The bitrate mode of video encoder.
|
||||
* @since 10
|
||||
@ -59,7 +58,7 @@ typedef struct OH_AVRange {
|
||||
* @return true indicate vendor codec, false indicate software codec
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
*/
|
||||
bool OH_AVCapability_IsHardwareAccelerated(OH_AVCapability *capability);
|
||||
|
||||
/**
|
||||
@ -68,7 +67,7 @@ bool OH_AVCapability_IsHardwareAccelerated(OH_AVCapability *capability);
|
||||
* @return mime type string
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
*/
|
||||
const char *OH_AVCapability_GetMimeType(OH_AVCapability *capability);
|
||||
|
||||
/**
|
||||
@ -77,7 +76,7 @@ const char *OH_AVCapability_GetMimeType(OH_AVCapability *capability);
|
||||
* @return instance count
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
*/
|
||||
int32_t OH_AVCapability_GetMaxSupportedInstances(OH_AVCapability *capability);
|
||||
|
||||
/**
|
||||
@ -89,9 +88,9 @@ int32_t OH_AVCapability_GetMaxSupportedInstances(OH_AVCapability *capability);
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetSupportedProfiles(OH_AVCapability *capability,
|
||||
const int32_t **profiles, uint32_t *profileNum);
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetSupportedProfiles(OH_AVCapability *capability, const int32_t **profiles,
|
||||
uint32_t *profileNum);
|
||||
|
||||
/**
|
||||
* @brief Get levels array for a specified profile.
|
||||
@ -103,9 +102,9 @@ OH_AVErrCode OH_AVCapability_GetSupportedProfiles(OH_AVCapability *capability,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetSupportedLevelsForProfile(OH_AVCapability *capability,
|
||||
int32_t profile, const int32_t **levels, uint32_t *levelNum);
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetSupportedLevelsForProfile(OH_AVCapability *capability, int32_t profile,
|
||||
const int32_t **levels, uint32_t *levelNum);
|
||||
|
||||
/**
|
||||
* @brief Check whether the profile and level is supported.
|
||||
@ -115,9 +114,8 @@ OH_AVErrCode OH_AVCapability_GetSupportedLevelsForProfile(OH_AVCapability *capab
|
||||
* @return true indicate supported, false indicate not supported
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
bool OH_AVCapability_ValidateProfileAndLevel(OH_AVCapability *capability,
|
||||
int32_t profile, int32_t level);
|
||||
*/
|
||||
bool OH_AVCapability_ValidateProfileAndLevel(OH_AVCapability *capability, int32_t profile, int32_t level);
|
||||
|
||||
/**
|
||||
* @brief Get encoder bitrate range
|
||||
@ -127,9 +125,8 @@ bool OH_AVCapability_ValidateProfileAndLevel(OH_AVCapability *capability,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetEncoderBitrateRange(OH_AVCapability *capability,
|
||||
OH_AVRange *bitrateRange);
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetEncoderBitrateRange(OH_AVCapability *capability, OH_AVRange *bitrateRange);
|
||||
|
||||
/**
|
||||
* @brief Get encoder quality range
|
||||
@ -139,9 +136,8 @@ OH_AVErrCode OH_AVCapability_GetEncoderBitrateRange(OH_AVCapability *capability,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetEncoderQualityRange(OH_AVCapability *capability,
|
||||
OH_AVRange *qualityRange);
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetEncoderQualityRange(OH_AVCapability *capability, OH_AVRange *qualityRange);
|
||||
|
||||
/**
|
||||
* @brief Get encoder complexity range
|
||||
@ -151,9 +147,8 @@ OH_AVErrCode OH_AVCapability_GetEncoderQualityRange(OH_AVCapability *capability,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetEncoderComplexityRange(OH_AVCapability *capability,
|
||||
OH_AVRange *complexityRange);
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetEncoderComplexityRange(OH_AVCapability *capability, OH_AVRange *complexityRange);
|
||||
|
||||
/**
|
||||
* @brief Check whether is this bitrate mode supported, only used for video encoder codecs.
|
||||
@ -162,9 +157,8 @@ OH_AVErrCode OH_AVCapability_GetEncoderComplexityRange(OH_AVCapability *capabili
|
||||
* @return true indicate supported, false indicate not supported
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
bool OH_AVCapability_ValidateVideoEncoderBitrateMode(OH_AVCapability *capability,
|
||||
OH_BitrateMode bitrateMode);
|
||||
*/
|
||||
bool OH_AVCapability_ValidateVideoEncoderBitrateMode(OH_AVCapability *capability, OH_BitrateMode bitrateMode);
|
||||
|
||||
/**
|
||||
* @brief Get sampleRate array, only used for audio codecs
|
||||
@ -175,9 +169,9 @@ bool OH_AVCapability_ValidateVideoEncoderBitrateMode(OH_AVCapability *capability
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetAudioSupportedSampleRates(OH_AVCapability *capability,
|
||||
const int32_t **sampleRates, uint32_t *sampleRateNum);
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetAudioSupportedSampleRates(OH_AVCapability *capability, const int32_t **sampleRates,
|
||||
uint32_t *sampleRateNum);
|
||||
|
||||
/**
|
||||
* @brief Check whether is this sampleRate supported, only used for audio codecs
|
||||
@ -186,9 +180,8 @@ OH_AVErrCode OH_AVCapability_GetAudioSupportedSampleRates(OH_AVCapability *capab
|
||||
* @return true indicate supported, false indicate not supported
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
bool OH_AVCapability_ValidateAudioSampleRate(OH_AVCapability *capability,
|
||||
int32_t sampleRate);
|
||||
*/
|
||||
bool OH_AVCapability_ValidateAudioSampleRate(OH_AVCapability *capability, int32_t sampleRate);
|
||||
|
||||
/**
|
||||
* @brief Get channels range, only used for audio codecs
|
||||
@ -198,10 +191,8 @@ bool OH_AVCapability_ValidateAudioSampleRate(OH_AVCapability *capability,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetAudioChannelsRange(OH_AVCapability *capability,
|
||||
OH_AVRange *channelsRange);
|
||||
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetAudioChannelsRange(OH_AVCapability *capability, OH_AVRange *channelsRange);
|
||||
|
||||
/**
|
||||
* @brief Get supported pixFormat array, only used for video codecs
|
||||
@ -212,9 +203,9 @@ OH_AVErrCode OH_AVCapability_GetAudioChannelsRange(OH_AVCapability *capability,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoSupportedPixFormats(OH_AVCapability *capability,
|
||||
const int32_t **pixFormats, uint32_t *pixFormatNum);
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoSupportedPixFormats(OH_AVCapability *capability, const int32_t **pixFormats,
|
||||
uint32_t *pixFormatNum);
|
||||
|
||||
/**
|
||||
* @brief Get width alignment, only used for video codecs
|
||||
@ -224,9 +215,8 @@ OH_AVErrCode OH_AVCapability_GetVideoSupportedPixFormats(OH_AVCapability *capabi
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoWidthAlignment(OH_AVCapability *capability,
|
||||
int32_t *widthAlignment);
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoWidthAlignment(OH_AVCapability *capability, int32_t *widthAlignment);
|
||||
|
||||
/**
|
||||
* @brief Get height alignment, only used for video codecs
|
||||
@ -236,9 +226,8 @@ OH_AVErrCode OH_AVCapability_GetVideoWidthAlignment(OH_AVCapability *capability,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoHeightAlignment(OH_AVCapability *capability,
|
||||
int32_t *heightAlignment);
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoHeightAlignment(OH_AVCapability *capability, int32_t *heightAlignment);
|
||||
|
||||
/**
|
||||
* @brief Get width range for a specified height, only used for video codecs
|
||||
@ -248,9 +237,9 @@ OH_AVErrCode OH_AVCapability_GetVideoHeightAlignment(OH_AVCapability *capability
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoWidthRangeForHeight(OH_AVCapability *capability,
|
||||
int32_t height, OH_AVRange *widthRange);
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoWidthRangeForHeight(OH_AVCapability *capability, int32_t height,
|
||||
OH_AVRange *widthRange);
|
||||
|
||||
/**
|
||||
* @brief Get height range for a specified width, only used for video codecs
|
||||
@ -260,9 +249,9 @@ OH_AVErrCode OH_AVCapability_GetVideoWidthRangeForHeight(OH_AVCapability *capabi
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoHeightRangeForWidth(OH_AVCapability *capability,
|
||||
int32_t width, OH_AVRange *heightRange);
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoHeightRangeForWidth(OH_AVCapability *capability, int32_t width,
|
||||
OH_AVRange *heightRange);
|
||||
|
||||
/**
|
||||
* @brief Get width range, only used for video codecs
|
||||
@ -272,9 +261,8 @@ OH_AVErrCode OH_AVCapability_GetVideoHeightRangeForWidth(OH_AVCapability *capabi
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoWidthRange(OH_AVCapability *capability,
|
||||
OH_AVRange *widthRange);
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoWidthRange(OH_AVCapability *capability, OH_AVRange *widthRange);
|
||||
|
||||
/**
|
||||
* @brief Get height range, only used for video codecs
|
||||
@ -284,9 +272,8 @@ OH_AVErrCode OH_AVCapability_GetVideoWidthRange(OH_AVCapability *capability,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoHeightRange(OH_AVCapability *capability,
|
||||
OH_AVRange *heightRange);
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoHeightRange(OH_AVCapability *capability, OH_AVRange *heightRange);
|
||||
|
||||
/**
|
||||
* @brief Check whether is this video size supported, only used for video codecs
|
||||
@ -296,9 +283,8 @@ OH_AVErrCode OH_AVCapability_GetVideoHeightRange(OH_AVCapability *capability,
|
||||
* @return true indicate supported, false indicate not supported
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
bool OH_AVCapability_ValidateVideoSize(OH_AVCapability *capability,
|
||||
int32_t width, int32_t height);
|
||||
*/
|
||||
bool OH_AVCapability_ValidateVideoSize(OH_AVCapability *capability, int32_t width, int32_t height);
|
||||
|
||||
/**
|
||||
* @brief Get frame rate range, only used for video codecs
|
||||
@ -308,9 +294,8 @@ bool OH_AVCapability_ValidateVideoSize(OH_AVCapability *capability,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoFrameRateRange(OH_AVCapability *capability,
|
||||
OH_AVRange *frameRateRange);
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoFrameRateRange(OH_AVCapability *capability, OH_AVRange *frameRateRange);
|
||||
|
||||
/**
|
||||
* @brief Get frame rate range for a specified video size, only used for video codecs
|
||||
@ -322,12 +307,12 @@ OH_AVErrCode OH_AVCapability_GetVideoFrameRateRange(OH_AVCapability *capability,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoFrameRateRangeForSize(OH_AVCapability *capability,
|
||||
int32_t width, int32_t height, OH_AVRange *frameRateRange);
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoFrameRateRangeForSize(OH_AVCapability *capability, int32_t width, int32_t height,
|
||||
OH_AVRange *frameRateRange);
|
||||
|
||||
/**
|
||||
* @brief Get measured frame rate range for a specified video size,
|
||||
* @brief Get measured frame rate range for a specified video size,
|
||||
* these frame rates is reachable, only used for video codecs
|
||||
* @param capability codec capability get from OH_AVCodec_GetCapability
|
||||
* @param width video width
|
||||
@ -337,9 +322,9 @@ OH_AVErrCode OH_AVCapability_GetVideoFrameRateRangeForSize(OH_AVCapability *capa
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoMeasuredFrameRateRangeForSize(OH_AVCapability *capability,
|
||||
int32_t width, int32_t height, OH_AVRange *frameRateRange);
|
||||
*/
|
||||
OH_AVErrCode OH_AVCapability_GetVideoMeasuredFrameRateRangeForSize(OH_AVCapability *capability, int32_t width,
|
||||
int32_t height, OH_AVRange *frameRateRange);
|
||||
|
||||
/**
|
||||
* @brief Check whether are this video size and fps supported.
|
||||
@ -350,12 +335,10 @@ OH_AVErrCode OH_AVCapability_GetVideoMeasuredFrameRateRangeForSize(OH_AVCapabili
|
||||
* @return true indicate supported, false indicate not supported
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
bool OH_AVCapability_ValidateVideoSizeAndFrameRate(OH_AVCapability *capability,
|
||||
int32_t width, int32_t height, int32_t frameRate);
|
||||
|
||||
*/
|
||||
bool OH_AVCapability_ValidateVideoSizeAndFrameRate(OH_AVCapability *capability, int32_t width, int32_t height,
|
||||
int32_t frameRate);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NATIVE_AVCAPABILITY_H
|
@ -23,6 +23,8 @@
|
||||
#include "native_avmemory.h"
|
||||
#include "native_avcodec_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -206,12 +208,12 @@ OH_AVErrCode OH_AudioDecoder_PushInputData(OH_AVCodec *codec, uint32_t index, OH
|
||||
OH_AVErrCode OH_AudioDecoder_FreeOutputData(OH_AVCodec *codec, uint32_t index);
|
||||
|
||||
/**
|
||||
* @brief Check whether the current codec instance is valid. It can be used fault recovery or app
|
||||
* @brief Check whether the current codec instance is valid. It can be used fault recovery or app
|
||||
* switchback from the background
|
||||
* @syscap SystemCapability.Multimedia.Media.AudioDecoder
|
||||
* @param codec Pointer to an OH_AVCodec instance
|
||||
* @param isVaild Pointer to an bool instance, true: the codec instance is vaild, false: the codec
|
||||
* instance is invalid
|
||||
* instance is invalid
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
@ -222,5 +224,6 @@ OH_AVErrCode OH_AudioDecoder_IsValid(OH_AVCodec *codec, bool *isVaild);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
#endif // NATIVE_AVCODEC_AUDIODECODER_H
|
@ -22,7 +22,8 @@
|
||||
#include "native_avformat.h"
|
||||
#include "native_avmemory.h"
|
||||
#include "native_avcodec_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -201,12 +202,12 @@ OH_AVErrCode OH_AudioEncoder_PushInputData(OH_AVCodec *codec, uint32_t index, OH
|
||||
OH_AVErrCode OH_AudioEncoder_FreeOutputData(OH_AVCodec *codec, uint32_t index);
|
||||
|
||||
/**
|
||||
* @brief Check whether the current codec instance is valid. It can be used fault recovery or app
|
||||
* @brief Check whether the current codec instance is valid. It can be used fault recovery or app
|
||||
* switchback from the background
|
||||
* @syscap SystemCapability.Multimedia.Media.AudioEncoder
|
||||
* @param codec Pointer to an OH_AVCodec instance
|
||||
* @param isVaild Pointer to an bool instance, true: the codec instance is vaild, false: the codec
|
||||
* instance is invalid
|
||||
* instance is invalid
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
@ -217,5 +218,6 @@ OH_AVErrCode OH_AudioEncoder_IsValid(OH_AVCodec *codec, bool *isVaild);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
#endif // NATIVE_AVCODEC_AUDIOENCODER_H
|
@ -230,12 +230,12 @@ OH_AVErrCode OH_VideoDecoder_RenderOutputData(OH_AVCodec *codec, uint32_t index)
|
||||
OH_AVErrCode OH_VideoDecoder_FreeOutputData(OH_AVCodec *codec, uint32_t index);
|
||||
|
||||
/**
|
||||
* @brief Check whether the current codec instance is valid. It can be used fault recovery or app
|
||||
* @brief Check whether the current codec instance is valid. It can be used fault recovery or app
|
||||
* switchback from the background
|
||||
* @syscap SystemCapability.Multimedia.Media.VideoDecoder
|
||||
* @param codec Pointer to an OH_AVCodec instance
|
||||
* @param isVaild Pointer to an bool instance, true: the codec instance is vaild, false: the codec
|
||||
* instance is invalid
|
||||
* instance is invalid
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
|
@ -208,7 +208,7 @@ OH_AVErrCode OH_VideoEncoder_FreeOutputData(OH_AVCodec *codec, uint32_t index);
|
||||
OH_AVErrCode OH_VideoEncoder_NotifyEndOfStream(OH_AVCodec *codec);
|
||||
|
||||
/**
|
||||
* @brief Submit the input buffer filled with data to the video encoder.
|
||||
* @brief Submit the input buffer filled with data to the video encoder.
|
||||
* @syscap SystemCapability.Multimedia.Media.VideoEncoder
|
||||
* @param codec Pointer to an OH_AVCodec instance
|
||||
* @param index Enter the index value corresponding to the Buffer
|
||||
@ -221,12 +221,12 @@ OH_AVErrCode OH_VideoEncoder_NotifyEndOfStream(OH_AVCodec *codec);
|
||||
OH_AVErrCode OH_VideoEncoder_PushInputData(OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr);
|
||||
|
||||
/**
|
||||
* @brief Check whether the current codec instance is valid. It can be used fault recovery or app
|
||||
* @brief Check whether the current codec instance is valid. It can be used fault recovery or app
|
||||
* switchback from the background
|
||||
* @syscap SystemCapability.Multimedia.Media.VideoEncoder
|
||||
* @param codec Pointer to an OH_AVCodec instance
|
||||
* @param isVaild Pointer to an bool instance, true: the codec instance is vaild, false: the codec
|
||||
* instance is invalid
|
||||
* instance is invalid
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
|
@ -42,7 +42,7 @@ __attribute__((visibility("default"))) void BehaviorEventWrite(std::string statu
|
||||
__attribute__((visibility("default"))) void FaultEventWrite(int32_t errorCode, std::string msg, std::string moudle);
|
||||
__attribute__((visibility("default"))) void StatisticEventWrite(std::string msg, std::string moudle);
|
||||
|
||||
#define AVCODEC_SYNC_TRACE AVCodecTrace trace(std::string(__FUNCTION__));
|
||||
#define AVCODEC_SYNC_TRACE AVCodecTrace trace(std::string(__FUNCTION__))
|
||||
|
||||
class __attribute__((visibility("default"))) AVCodecTrace : public NoCopyable {
|
||||
public:
|
||||
|
@ -22,7 +22,6 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "CodecBase"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
||||
int32_t CodecBase::NotifyEos()
|
||||
{
|
||||
AVCODEC_LOGW("NotifyEos is not supported");
|
||||
@ -54,6 +53,5 @@ int32_t CodecBase::SignalRequestIDRFrame()
|
||||
AVCODEC_LOGW("SignalRequestIDRFrame is not supported");
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
@ -15,10 +15,10 @@
|
||||
#ifndef CODECBASE_H
|
||||
#define CODECBASE_H
|
||||
|
||||
#include <string>
|
||||
#include "avcodec_common.h"
|
||||
#include "avsharedmemorybase.h"
|
||||
#include "surface.h"
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
@ -22,8 +22,8 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AvCodec-Au
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
constexpr short DEFALT_BUFFER_LENGTH{8};
|
||||
constexpr short DEFALT_SLEEP_TIME{500};
|
||||
constexpr short DEFALT_BUFFER_LENGTH = 8;
|
||||
constexpr short DEFALT_SLEEP_TIME = 500;
|
||||
|
||||
AudioBuffersManager::~AudioBuffersManager() {}
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "media_description.h"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AvCodec-AudioFFMpegDecoderAdapter"};
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AvCodec-AudioFFMpegAdapter"};
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
@ -206,7 +206,7 @@ int32_t AudioFFMpegAdapter::Release()
|
||||
}
|
||||
AVCODEC_LOGI("adapter Release, state from %{public}s to RRELEASING", stateToString(state_).data());
|
||||
state_ = CodecState::RRELEASING;
|
||||
auto ret = doRelease(); // todo:异步调用
|
||||
auto ret = doRelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -228,6 +228,9 @@ int32_t AudioFFMpegAdapter::GetOutputFormat(Format &format)
|
||||
{
|
||||
AVCODEC_SYNC_TRACE;
|
||||
format = audioCodec->GetFormat();
|
||||
if (!format.ContainKey(MediaDescriptionKey::MD_KEY_CODEC_NAME)) {
|
||||
format.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_NAME, name_);
|
||||
}
|
||||
return AVCodecServiceErrCode::AVCS_ERR_OK;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,6 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AvCodec-Au
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
||||
AudioFfmpegDecoderPlugin::AudioFfmpegDecoderPlugin()
|
||||
: hasExtra_(false),
|
||||
maxInputSize_(-1),
|
||||
@ -240,7 +239,6 @@ int32_t AudioFfmpegDecoderPlugin::AllocateContext(const std::string &name)
|
||||
AVCodecContext *context = nullptr;
|
||||
{
|
||||
std::unique_lock lock(avMutext_);
|
||||
// FALSE_RETURN_V(avCodec_ != nullptr, Status::ERROR_WRONG_STATE);
|
||||
context = avcodec_alloc_context3(avCodec_.get());
|
||||
|
||||
avCodecContext_ = std::shared_ptr<AVCodecContext>(context, [](AVCodecContext *ptr) {
|
||||
@ -318,6 +316,5 @@ int32_t AudioFfmpegDecoderPlugin::CloseCtxLocked()
|
||||
}
|
||||
return AVCodecServiceErrCode::AVCS_ERR_OK;
|
||||
}
|
||||
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
@ -18,19 +18,18 @@
|
||||
#include "media_description.h"
|
||||
|
||||
namespace {
|
||||
constexpr int getInputBufferSize_ = 65536;
|
||||
constexpr int getOutputBufferSize_ = 65536;
|
||||
constexpr int minChannels = 1;
|
||||
constexpr int maxChannels = 8;
|
||||
static const int flac_encoder_sample_rate_table[] = {
|
||||
0, 88200, 176400, 192000, 8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000,
|
||||
};
|
||||
static const int flac_encoder_bits_sample_table[] = {16, 24, 32};
|
||||
}
|
||||
constexpr int getInputBufferSize_ = 65536;
|
||||
constexpr int getOutputBufferSize_ = 65536;
|
||||
constexpr int minChannels = 1;
|
||||
constexpr int maxChannels = 8;
|
||||
static const int flac_encoder_sample_rate_table[] = {
|
||||
0, 88200, 176400, 192000, 8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000,
|
||||
};
|
||||
static const int flac_encoder_bits_sample_table[] = {16, 24, 32};
|
||||
} // namespace
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
||||
AudioFFMpegFlacDecoderPlugin::AudioFFMpegFlacDecoderPlugin() : basePlugin(std::make_unique<AudioFfmpegDecoderPlugin>())
|
||||
{
|
||||
}
|
||||
@ -138,6 +137,5 @@ Format AudioFFMpegFlacDecoderPlugin::GetFormat() const noexcept
|
||||
{
|
||||
return basePlugin->GetFormat();
|
||||
}
|
||||
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
@ -24,26 +24,14 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AvCodec-Au
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
static constexpr int32_t INPUT_BUFFER_SIZE_DEFAULT = 4 * 1024 * 8;
|
||||
static constexpr int32_t OUTPUT_BUFFER_SIZE_DEFAULT = 8192;
|
||||
static constexpr uint32_t ADTS_HEADER_SIZE = 7;
|
||||
constexpr int32_t INPUT_BUFFER_SIZE_DEFAULT = 4 * 1024 * 8;
|
||||
constexpr int32_t OUTPUT_BUFFER_SIZE_DEFAULT = 8192;
|
||||
constexpr uint32_t ADTS_HEADER_SIZE = 7;
|
||||
|
||||
static constexpr uint8_t SAMPLE_FREQUENCY_INDEX_DEFAULT = 4;
|
||||
static std::map<int32_t, uint8_t> sampleFreqMap = {
|
||||
{96000, 0},
|
||||
{88200, 1},
|
||||
{64000, 2},
|
||||
{48000, 3},
|
||||
{44100, 4},
|
||||
{32000, 5},
|
||||
{24000, 6},
|
||||
{22050, 7},
|
||||
{16000, 8},
|
||||
{12000, 9},
|
||||
{11025, 10},
|
||||
{8000, 11},
|
||||
{7350, 12}
|
||||
};
|
||||
constexpr uint8_t SAMPLE_FREQUENCY_INDEX_DEFAULT = 4;
|
||||
static std::map<int32_t, uint8_t> sampleFreqMap = {{96000, 0}, {88200, 1}, {64000, 2}, {48000, 3}, {44100, 4},
|
||||
{32000, 5}, {24000, 6}, {22050, 7}, {16000, 8}, {12000, 9},
|
||||
{11025, 10}, {8000, 11}, {7350, 12}};
|
||||
|
||||
AudioFFMpegAacEncoderPlugin::AudioFFMpegAacEncoderPlugin() : basePlugin(std::make_unique<AudioFfmpegEncoderPlugin>()) {}
|
||||
|
||||
@ -76,9 +64,9 @@ static int32_t GetAdtsHeader(std::string &adtsHeader, uint32_t &headerSize, std:
|
||||
return AVCodecServiceErrCode::AVCS_ERR_OK;
|
||||
}
|
||||
|
||||
static bool CheckSampleFormat(const std::shared_ptr<AVCodec> &codec, enum AVSampleFormat sample_fmt)
|
||||
static bool CheckSampleFormat(const std::shared_ptr<AVCodec> &codec, AVSampleFormat sample_fmt)
|
||||
{
|
||||
const enum AVSampleFormat* p = codec->sample_fmts;
|
||||
const enum AVSampleFormat *p = codec->sample_fmts;
|
||||
while (*p != AV_SAMPLE_FMT_NONE) { // 通过AV_SAMPLE_FMT_NONE作为结束符
|
||||
if (*p == sample_fmt) {
|
||||
return true;
|
||||
@ -90,7 +78,7 @@ static bool CheckSampleFormat(const std::shared_ptr<AVCodec> &codec, enum AVSamp
|
||||
|
||||
static bool CheckSampleRate(const std::shared_ptr<AVCodec> &codec, const int sample_rate)
|
||||
{
|
||||
const int* p = codec->supported_samplerates;
|
||||
const int *p = codec->supported_samplerates;
|
||||
while (*p != 0) { // 0作为退出条件,比如libfdk-aacenc.c的aac_sample_rates
|
||||
if (*p == sample_rate) {
|
||||
return true;
|
||||
@ -103,7 +91,7 @@ static bool CheckSampleRate(const std::shared_ptr<AVCodec> &codec, const int sam
|
||||
static bool CheckChannelLayout(const std::shared_ptr<AVCodec> &codec, const uint64_t channel_layout)
|
||||
{
|
||||
// 不是每个codec都给出支持的channel_layout
|
||||
const uint64_t* p = codec->channel_layouts;
|
||||
const uint64_t *p = codec->channel_layouts;
|
||||
if (!p) {
|
||||
AVCODEC_LOGI("The encoder %{public}s do not set channel_layouts", codec->name);
|
||||
return true;
|
||||
|
@ -21,8 +21,9 @@
|
||||
#include "securec.h"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AvCodec-AudioFFMpegEncoderPlugin"};
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AvCodec-AudioFFMpegEncoderPlugin"};
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
AudioFfmpegEncoderPlugin::AudioFfmpegEncoderPlugin() {}
|
||||
@ -61,13 +62,13 @@ int32_t AudioFfmpegEncoderPlugin::PcmFillFrame(const std::shared_ptr<AudioBuffer
|
||||
auto bytesPerSample = av_get_bytes_per_sample(avCodecContext_->sample_fmt);
|
||||
if (!av_sample_fmt_is_planar(avCodecContext_->sample_fmt)) {
|
||||
auto ret = av_samples_fill_arrays(cachedFrame_->data, cachedFrame_->linesize, ptr, cachedFrame_->channels,
|
||||
cachedFrame_->nb_samples, (AVSampleFormat)cachedFrame_->format, 0);
|
||||
cachedFrame_->nb_samples, (AVSampleFormat)cachedFrame_->format, 0);
|
||||
if (ret < 0) {
|
||||
AVCODEC_LOGE("Samples fill arrays failed: %{public}s", AVStrError(ret).c_str());
|
||||
return AVCodecServiceErrCode::AVCS_ERR_UNKNOWN;
|
||||
}
|
||||
return AVCodecServiceErrCode::AVCS_ERR_OK;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < cachedFrame_->nb_samples; i++) {
|
||||
for (int j = 0; j < cachedFrame_->channels; j++) {
|
||||
auto ret = memcpy_s((void *)(&cachedFrame_->data[j][i * bytesPerSample]), bytesPerSample,
|
||||
@ -165,21 +166,25 @@ int32_t AudioFfmpegEncoderPlugin::ReceivePacketSucc(std::shared_ptr<AudioBufferI
|
||||
AVCODEC_LOGE("Get header failed.");
|
||||
return AVCodecServiceErrCode::AVCS_ERR_UNKNOWN;
|
||||
}
|
||||
memcpy_s(memory->GetBase(), memory->GetSize(), header.c_str(), headerSize);
|
||||
auto len = memory->Write((uint8_t *)header.c_str(), headerSize);
|
||||
if (len < headerSize) {
|
||||
AVCODEC_LOGE("Write header failed, len = %{public}d", len);
|
||||
return AVCodecServiceErrCode::AVCS_ERR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t outputSize = avPacket_->size + headerSize;
|
||||
if (outBuffer->GetBuffer()->GetSize() < outputSize) {
|
||||
if (memory->GetSize() < outputSize) {
|
||||
AVCODEC_LOGW("Output buffer capacity is not enough");
|
||||
return AVCodecServiceErrCode::AVCS_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
auto ret = memcpy_s(memory->GetBase() + headerSize, memory->GetSize() - headerSize, avPacket_->data,
|
||||
avPacket_->size);
|
||||
if (ret != EOK) {
|
||||
AVCODEC_LOGE("Memory copy failed, errno = %{public}d", ret);
|
||||
auto len = memory->Write(avPacket_->data, avPacket_->size);
|
||||
if (len < avPacket_->size) {
|
||||
AVCODEC_LOGE("write packet data failed, len = %{public}d", len);
|
||||
return AVCodecServiceErrCode::AVCS_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
auto attr = outBuffer->GetBufferAttr();
|
||||
attr.size = avPacket_->size + headerSize;
|
||||
outBuffer->SetBufferAttr(attr);
|
||||
@ -244,10 +249,10 @@ int32_t AudioFfmpegEncoderPlugin::InitContext(const Format &format)
|
||||
|
||||
int64_t layout;
|
||||
format.GetLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_LAYOUT, layout);
|
||||
avCodecContext_->channel_layout = layout; // layout
|
||||
avCodecContext_->channel_layout = layout;
|
||||
|
||||
int32_t sampleFormat;
|
||||
format.GetIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_FORMAT, sampleFormat); // for aac is AV_SMAPLE_FORMAT_FLTP
|
||||
format.GetIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_FORMAT, sampleFormat);
|
||||
avCodecContext_->sample_fmt = (AVSampleFormat)sampleFormat;
|
||||
return AVCodecServiceErrCode::AVCS_ERR_OK;
|
||||
}
|
||||
@ -326,6 +331,5 @@ void AudioFfmpegEncoderPlugin::RegisterHeaderFunc(HeaderFunc headerFunc)
|
||||
GetHeaderFunc_ = headerFunc;
|
||||
headerFuncValid_ = true;
|
||||
}
|
||||
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "audio_ffmpeg_flac_encoder_plugin.h"
|
||||
#include "media_description.h"
|
||||
#include "avcodec_errors.h"
|
||||
#include "avcodec_dfx.h"
|
||||
#include "avcodec_log.h"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AvCodec-AudioFFMpegFlacEncoderPlugin"};
|
||||
}
|
||||
|
||||
namespace {
|
||||
constexpr int minChannel = 1;
|
||||
constexpr int maxChannel = 8;
|
||||
constexpr int getInputBufferSize_ = 65536;
|
||||
constexpr int getOutputBufferSize_ = 65536;
|
||||
static const int flac_encoder_sample_rate_table[] = {
|
||||
0, 88200, 176400, 192000, 8000, 16000, 22050, 24000, 32000, 44100, 48000, 96000,
|
||||
};
|
||||
static const int flac_encoder_bits_sample_table[] = {16, 24, 32};
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
AudioFFMpegFlacEncoderPlugin::AudioFFMpegFlacEncoderPlugin()
|
||||
: basePlugin(std::make_unique<AudioFfmpegEncoderPlugin>()) {}
|
||||
|
||||
AudioFFMpegFlacEncoderPlugin::~AudioFFMpegFlacEncoderPlugin() {
|
||||
basePlugin->Release();
|
||||
basePlugin.reset();
|
||||
basePlugin = nullptr;
|
||||
}
|
||||
|
||||
static bool isTrueSampleRate(int sample) {
|
||||
for (auto i : flac_encoder_sample_rate_table) {
|
||||
if (i == sample) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool isTrueBitsPerSample(int bits_per_coded_sample) {
|
||||
for (auto i : flac_encoder_bits_sample_table) {
|
||||
if (i == bits_per_coded_sample) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t AudioFFMpegFlacEncoderPlugin::init(const Format &format) {
|
||||
int32_t channels, sample_rate;
|
||||
int32_t bits_per_coded_sample;
|
||||
format.GetIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, channels);
|
||||
format.GetIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, sample_rate);
|
||||
format.GetIntValue(MediaDescriptionKey::MD_BITS_PER_CODED_SAMPLE_KEY, bits_per_coded_sample);
|
||||
if (!isTrueSampleRate(sample_rate)) {
|
||||
AVCODEC_LOGE("init failed, because sample rate=%{public}d not in table.", sample_rate);
|
||||
return AVCodecServiceErrCode::AVCS_ERR_MISMATCH_SAMPLE_RATE;
|
||||
} else if (channels < minChannel || channels > maxChannel) {
|
||||
AVCODEC_LOGE("init failed, because channels=%{public}d not support.", channels);
|
||||
return AVCodecServiceErrCode::AVCS_ERR_CONFIGURE_MISMATCH_CHANNEL_COUNT;
|
||||
} else if (!isTrueBitsPerSample(bits_per_coded_sample)) {
|
||||
AVCODEC_LOGE("init failed, because bits_per_coded_sample=%{public}d not support.", bits_per_coded_sample);
|
||||
return AVCodecServiceErrCode::AVCS_ERR_MISMATCH_BIT_RATE;
|
||||
}
|
||||
|
||||
int32_t ret = basePlugin->AllocateContext("flac");
|
||||
if (ret != AVCodecServiceErrCode::AVCS_ERR_OK) {
|
||||
AVCODEC_LOGE("init failed, because AllocateContext failed. ret=%{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = basePlugin->InitContext(format);
|
||||
if (ret != AVCodecServiceErrCode::AVCS_ERR_OK) {
|
||||
AVCODEC_LOGE("init failed, because InitContext failed. ret=%{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = basePlugin->OpenContext();
|
||||
if (ret != AVCodecServiceErrCode::AVCS_ERR_OK) {
|
||||
AVCODEC_LOGE("init failed, because OpenContext failed. ret=%{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = basePlugin->InitFrame();
|
||||
if (ret != AVCodecServiceErrCode::AVCS_ERR_OK) {
|
||||
AVCODEC_LOGE("init failed, because InitFrame failed. ret=%{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return AVCodecServiceErrCode::AVCS_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t AudioFFMpegFlacEncoderPlugin::processSendData(const std::shared_ptr<AudioBufferInfo> &inputBuffer) {
|
||||
return basePlugin->ProcessSendData(inputBuffer);
|
||||
}
|
||||
|
||||
int32_t AudioFFMpegFlacEncoderPlugin::processRecieveData(std::shared_ptr<AudioBufferInfo> &outBuffer) {
|
||||
return basePlugin->ProcessRecieveData(outBuffer);
|
||||
}
|
||||
|
||||
int32_t AudioFFMpegFlacEncoderPlugin::reset() {
|
||||
return basePlugin->Reset();
|
||||
}
|
||||
|
||||
int32_t AudioFFMpegFlacEncoderPlugin::release() {
|
||||
return basePlugin->Release();
|
||||
}
|
||||
|
||||
int32_t AudioFFMpegFlacEncoderPlugin::flush() {
|
||||
return basePlugin->Flush();
|
||||
}
|
||||
|
||||
uint32_t AudioFFMpegFlacEncoderPlugin::getInputBufferSize() const {
|
||||
int32_t maxSize = basePlugin->GetMaxInputSize();
|
||||
if (maxSize < 0 || maxSize > getInputBufferSize_) {
|
||||
maxSize = getInputBufferSize_;
|
||||
}
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
uint32_t AudioFFMpegFlacEncoderPlugin::getOutputBufferSize() const {
|
||||
return getOutputBufferSize_;
|
||||
}
|
||||
|
||||
Format AudioFFMpegFlacEncoderPlugin::GetFormat() const noexcept {
|
||||
return basePlugin->GetFormat();
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
@ -16,9 +16,9 @@
|
||||
#ifndef AUDIO_FFMPEG_DECODER_PLUGIN
|
||||
#define AUDIO_FFMPEG_DECODER_PLUGIN
|
||||
|
||||
#include <mutex>
|
||||
#include "audio_ffmpeg_base_codec.h"
|
||||
#include "nocopyable.h"
|
||||
#include <mutex>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -30,25 +30,7 @@ extern "C" {
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
||||
class AudioFfmpegDecoderPlugin : public NoCopyable {
|
||||
private:
|
||||
bool hasExtra_;
|
||||
int64_t maxInputSize_;
|
||||
int32_t bufferNum_;
|
||||
int32_t bufferIndex_;
|
||||
int64_t preBufferGroupPts_;
|
||||
int64_t curBufferGroupPts_;
|
||||
int64_t bufferGroupPtsDistance;
|
||||
|
||||
std::shared_ptr<AVCodec> avCodec_;
|
||||
std::shared_ptr<AVCodecContext> avCodecContext_;
|
||||
std::shared_ptr<AVFrame> cachedFrame_;
|
||||
std::shared_ptr<AVPacket> avPacket_;
|
||||
std::mutex avMutext_;
|
||||
std::mutex parameterMutex_;
|
||||
Format format_;
|
||||
|
||||
public:
|
||||
AudioFfmpegDecoderPlugin();
|
||||
|
||||
@ -84,12 +66,28 @@ public:
|
||||
|
||||
bool hasExtraData() const noexcept;
|
||||
|
||||
private:
|
||||
bool hasExtra_;
|
||||
int64_t maxInputSize_;
|
||||
int32_t bufferNum_;
|
||||
int32_t bufferIndex_;
|
||||
int64_t preBufferGroupPts_;
|
||||
int64_t curBufferGroupPts_;
|
||||
int64_t bufferGroupPtsDistance;
|
||||
|
||||
std::shared_ptr<AVCodec> avCodec_;
|
||||
std::shared_ptr<AVCodecContext> avCodecContext_;
|
||||
std::shared_ptr<AVFrame> cachedFrame_;
|
||||
std::shared_ptr<AVPacket> avPacket_;
|
||||
std::mutex avMutext_;
|
||||
std::mutex parameterMutex_;
|
||||
Format format_;
|
||||
|
||||
private:
|
||||
int32_t SendBuffer(const std::shared_ptr<AudioBufferInfo> &inputBuffer);
|
||||
int32_t ReceiveBuffer(std::shared_ptr<AudioBufferInfo> &outBuffer);
|
||||
int32_t ReceiveFrameSucc(std::shared_ptr<AudioBufferInfo> &outBuffer);
|
||||
};
|
||||
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
|
@ -22,7 +22,6 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
||||
class AudioFFMpegMp3DecoderPlugin : public AudioFFMpegBaseCodec::CodecRegister<AudioFFMpegMp3DecoderPlugin> {
|
||||
public:
|
||||
AudioFFMpegMp3DecoderPlugin();
|
||||
|
@ -16,15 +16,14 @@
|
||||
#ifndef AUDIO_FFMPEG_ENCODER_PLUGIN
|
||||
#define AUDIO_FFMPEG_ENCODER_PLUGIN
|
||||
|
||||
#include "audio_ffmpeg_base_codec.h"
|
||||
#include <mutex>
|
||||
#include <fstream>
|
||||
|
||||
#include "audio_ffmpeg_base_codec.h"
|
||||
#include "nocopyable.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "libavcodec/avcodec.h"
|
||||
#include "nocopyable.h"
|
||||
#include <libavutil/opt.h>
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
@ -33,15 +32,6 @@ extern "C" {
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
class AudioFfmpegEncoderPlugin : NoCopyable {
|
||||
private:
|
||||
int32_t maxInputSize_;
|
||||
std::shared_ptr<AVCodec> avCodec_{};
|
||||
std::shared_ptr<AVCodecContext> avCodecContext_{};
|
||||
std::shared_ptr<AVFrame> cachedFrame_{};
|
||||
std::shared_ptr<AVPacket> avPacket_{};
|
||||
mutable std::mutex avMutext_{};
|
||||
std::mutex parameterMutex_{};
|
||||
Format format_;
|
||||
using HeaderFunc = std::function<int32_t(std::string &header, uint32_t &headerSize, std::shared_ptr<AVCodecContext>,
|
||||
uint32_t dataLength)>;
|
||||
|
||||
@ -64,11 +54,20 @@ public:
|
||||
std::shared_ptr<AVPacket> GetCodecAVPacket() const;
|
||||
std::shared_ptr<AVFrame> GetCodecCacheFrame() const;
|
||||
std::shared_ptr<AVCodec> GetAVCodec() const;
|
||||
|
||||
void RegisterHeaderFunc(HeaderFunc headerFunc);
|
||||
int32_t CloseCtxLocked();
|
||||
int32_t GetMaxInputSize() const noexcept;
|
||||
|
||||
private:
|
||||
int32_t maxInputSize_;
|
||||
std::shared_ptr<AVCodec> avCodec_;
|
||||
std::shared_ptr<AVCodecContext> avCodecContext_;
|
||||
std::shared_ptr<AVFrame> cachedFrame_;
|
||||
std::shared_ptr<AVPacket> avPacket_;
|
||||
mutable std::mutex avMutext_;
|
||||
std::mutex parameterMutex_;
|
||||
Format format_;
|
||||
|
||||
private:
|
||||
int32_t sendBuffer(const std::shared_ptr<AudioBufferInfo> &inputBuffer);
|
||||
int32_t receiveBuffer(std::shared_ptr<AudioBufferInfo> &outBuffer);
|
||||
@ -76,9 +75,7 @@ private:
|
||||
int32_t PcmFillFrame(const std::shared_ptr<AudioBufferInfo> &inputBuffer);
|
||||
HeaderFunc GetHeaderFunc_;
|
||||
bool headerFuncValid_ = false;
|
||||
// std::unique_ptr<std::ofstream> outputFile_;
|
||||
};
|
||||
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef AUDIO_FFMPEG_FLAC_ENCODER_PLUGIN_H
|
||||
#define AUDIO_FFMPEG_FLAC_ENCODER_PLUGIN_H
|
||||
|
||||
#include "audio_ffmpeg_base_codec.h"
|
||||
#include "audio_ffmpeg_encoder_plugin.h"
|
||||
#include "avcodec_audio_codec_key.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
class AudioFFMpegFlacEncoderPlugin : public AudioFFMpegBaseCodec::CodecRegister<AudioFFMpegFlacEncoderPlugin> {
|
||||
public:
|
||||
AudioFFMpegFlacEncoderPlugin();
|
||||
~AudioFFMpegFlacEncoderPlugin() override;
|
||||
|
||||
int32_t init(const Format &format) override;
|
||||
int32_t processSendData(const std::shared_ptr<AudioBufferInfo> &inputBuffer) override;
|
||||
int32_t processRecieveData(std::shared_ptr<AudioBufferInfo> &outBuffer) override;
|
||||
int32_t reset() override;
|
||||
int32_t release() override;
|
||||
int32_t flush() override;
|
||||
uint32_t getInputBufferSize() const override;
|
||||
uint32_t getOutputBufferSize() const override;
|
||||
Format GetFormat() const noexcept override;
|
||||
|
||||
const static std::string identify()
|
||||
{
|
||||
return std::string(AVCodecAudioCodecKey::AUDIO_ENCODER_FLAC_NAME_KEY);
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<AudioFfmpegEncoderPlugin> basePlugin;
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -24,7 +24,6 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "CodecAbili
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
||||
CodecAbilitySingleton &CodecAbilitySingleton::GetInstance()
|
||||
{
|
||||
AVCODEC_LOGE("CodecAbilitySingleton entered: start getting ins");
|
||||
@ -86,6 +85,5 @@ std::vector<CapabilityData> CodecAbilitySingleton::GetCapabilityArray()
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return capabilityDataArray_;
|
||||
}
|
||||
// #endif
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
@ -33,7 +33,7 @@ private:
|
||||
bool ParseCodecXml();
|
||||
std::vector<CapabilityData> capabilityDataArray_;
|
||||
std::mutex mutex_;
|
||||
bool isParsered_{false};
|
||||
bool isParsered_ {false};
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
@ -21,19 +21,16 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
||||
class VideoCodecList : public CodecListBase {
|
||||
public:
|
||||
~VideoCodecList() override = default;
|
||||
int32_t GetCapabilityList(std::vector<CapabilityData> &caps) override;
|
||||
};
|
||||
|
||||
class AudioCodecList : public CodecListBase {
|
||||
public:
|
||||
~AudioCodecList() override = default;
|
||||
int32_t GetCapabilityList(std::vector<CapabilityData> &caps) override;
|
||||
};
|
||||
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
#endif // CODECLIST_BUILDER_H
|
||||
|
@ -88,27 +88,27 @@ bool CodecListCore::CheckVideoFrameRate(const Format &format, const CapabilityDa
|
||||
}
|
||||
|
||||
switch (format.GetValueType(std::string_view("frame_rate"))) {
|
||||
case FORMAT_TYPE_INT32: {
|
||||
int32_t targetFrameRateInt;
|
||||
(void)format.GetIntValue("frame_rate", targetFrameRateInt);
|
||||
if (data.frameRate.minVal > targetFrameRateInt || data.frameRate.maxVal < targetFrameRateInt) {
|
||||
return false;
|
||||
case FORMAT_TYPE_INT32: {
|
||||
int32_t targetFrameRateInt;
|
||||
(void)format.GetIntValue("frame_rate", targetFrameRateInt);
|
||||
if (data.frameRate.minVal > targetFrameRateInt || data.frameRate.maxVal < targetFrameRateInt) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FORMAT_TYPE_DOUBLE: {
|
||||
double targetFrameRateDouble;
|
||||
(void)format.GetDoubleValue("frame_rate", targetFrameRateDouble);
|
||||
double minValDouble{data.frameRate.minVal};
|
||||
double maxValDouble{data.frameRate.maxVal};
|
||||
if ((minValDouble > targetFrameRateDouble && fabs(minValDouble - targetFrameRateDouble) >= EPSINON) ||
|
||||
(maxValDouble < targetFrameRateDouble && fabs(maxValDouble - targetFrameRateDouble) >= EPSINON)) {
|
||||
return false;
|
||||
case FORMAT_TYPE_DOUBLE: {
|
||||
double targetFrameRateDouble;
|
||||
(void)format.GetDoubleValue("frame_rate", targetFrameRateDouble);
|
||||
double minValDouble {data.frameRate.minVal};
|
||||
double maxValDouble {data.frameRate.maxVal};
|
||||
if ((minValDouble > targetFrameRateDouble && fabs(minValDouble - targetFrameRateDouble) >= EPSINON) ||
|
||||
(maxValDouble < targetFrameRateDouble && fabs(maxValDouble - targetFrameRateDouble) >= EPSINON)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -186,7 +186,6 @@ std::string CodecListCore::FindCodec(const Format &format, bool isEncoder)
|
||||
++iter;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isVideo) {
|
||||
if (IsVideoCapSupport(format, *iter)) {
|
||||
return (*iter).codecName;
|
||||
@ -229,6 +228,5 @@ CapabilityData CodecListCore::CreateCapability(std::string codecName)
|
||||
}
|
||||
return capData;
|
||||
}
|
||||
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
@ -24,7 +24,6 @@ const std::string AVCODEC_CAPS_FILE = "/etc/codec/avcodec_caps.xml";
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
||||
const std::unordered_map<std::string, int> VIDEO_PROFILE_MAP = {
|
||||
// H263
|
||||
{"H263BackwardCompatible", H263_PROFILE_BACKWARD_COMPATIBLE},
|
||||
@ -227,16 +226,14 @@ bool CodeclistXmlParser::ParseInternal(xmlNode *node)
|
||||
for (; currNode != nullptr; currNode = currNode->next) {
|
||||
if (currNode->type == XML_ELEMENT_NODE) {
|
||||
switch (GetNodeNameAsInt(currNode)) {
|
||||
case AUDIO_DECODER:
|
||||
case AUDIO_ENCODER:
|
||||
case VIDEO_DECODER:
|
||||
case VIDEO_ENCODER: {
|
||||
ParseData(currNode);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ParseInternal(currNode->children);
|
||||
break;
|
||||
case AUDIO_DECODER:
|
||||
case AUDIO_ENCODER:
|
||||
case VIDEO_DECODER:
|
||||
case VIDEO_ENCODER: {
|
||||
ParseData(currNode);
|
||||
break;
|
||||
}
|
||||
default: ParseInternal(currNode->children); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -307,14 +304,13 @@ std::vector<int32_t> CodeclistXmlParser::TransStrAsIntegerArray(const std::vecto
|
||||
return array;
|
||||
}
|
||||
|
||||
std::vector<int32_t>
|
||||
CodeclistXmlParser::TransMapAsIntegerArray(const std::unordered_map<std::string, int> &capabilityMap,
|
||||
const std::vector<std::string> &spilt)
|
||||
std::vector<int32_t> CodeclistXmlParser::TransMapAsIntegerArray(const std::unordered_map<std::string, int> &capMap,
|
||||
const std::vector<std::string> &spilt)
|
||||
{
|
||||
std::vector<int32_t> res;
|
||||
for (auto iter = spilt.begin(); iter != spilt.end(); iter++) {
|
||||
if (capabilityMap.find(*iter) != capabilityMap.end()) {
|
||||
res.emplace_back(capabilityMap.at(*iter));
|
||||
if (capMap.find(*iter) != capMap.end()) {
|
||||
res.emplace_back(capMap.at(*iter));
|
||||
} else {
|
||||
AVCODEC_LOGD("can not find %{public}s in capabilityMap", iter->c_str());
|
||||
}
|
||||
@ -511,41 +507,23 @@ bool CodeclistXmlParser::SetCapabilityVectorData(std::unordered_map<std::string,
|
||||
bool CodeclistXmlParser::SetCapabilityData(CapabilityData &data, const std::string &capabilityKey,
|
||||
const std::string &capabilityValue) const
|
||||
{
|
||||
std::unordered_map<std::string, std::string &> capabilityStringMap = {{"codecName", data.codecName},
|
||||
{"mimeType", data.mimeType}};
|
||||
|
||||
std::unordered_map<std::string, int32_t &> capabilityIntMap = {{"codecType", data.codecType},
|
||||
{"maxInstance", data.maxInstance}};
|
||||
|
||||
std::unordered_map<std::string, std::string &> capabilityStringMap = {
|
||||
{"codecName", data.codecName}, {"mimeType", data.mimeType}};
|
||||
std::unordered_map<std::string, int32_t &> capabilityIntMap = {{"codecType", data.codecType}, {"maxInstance", data.maxInstance}};
|
||||
std::unordered_map<std::string, bool &> capabilityBoolMap = {
|
||||
{"isVendor", data.isVendor},
|
||||
{"supportSwapWidthHeight", data.supportSwapWidthHeight}};
|
||||
|
||||
std::unordered_map<std::string, ImgSize &> capabilitySizeMap = {{"blockSize", data.blockSize},
|
||||
{"alignment", data.alignment}};
|
||||
|
||||
{"isVendor", data.isVendor}, {"supportSwapWidthHeight", data.supportSwapWidthHeight}};
|
||||
std::unordered_map<std::string, ImgSize &> capabilitySizeMap = {{"blockSize", data.blockSize}, {"alignment", data.alignment}};
|
||||
std::unordered_map<std::string, std::map<ImgSize, Range> &> capabilityHashRangeMap = {
|
||||
{"measuredFrameRate", data.measuredFrameRate}};
|
||||
|
||||
std::unordered_map<std::string, Range &> capabilityRangeMap = {{"bitrate", data.bitrate},
|
||||
{"channels", data.channels},
|
||||
{"complexity", data.complexity},
|
||||
{"width", data.width},
|
||||
{"height", data.height},
|
||||
{"frameRate", data.frameRate},
|
||||
{"encodeQuality", data.encodeQuality},
|
||||
{"blockPerFrame", data.blockPerFrame},
|
||||
{"blockPerSecond", data.blockPerSecond}};
|
||||
|
||||
std::unordered_map<std::string, std::vector<int32_t> &> capabilityVectorMap = {{"sampleRate", data.sampleRate},
|
||||
{"pixFormat", data.pixFormat},
|
||||
{"bitDepth", data.bitDepth},
|
||||
{"profiles", data.profiles},
|
||||
{"bitrateMode", data.bitrateMode}};
|
||||
|
||||
std::unordered_map<std::string, Range &> capabilityRangeMap = {
|
||||
{"bitrate", data.bitrate}, {"complexity", data.complexity}, {"frameRate", data.frameRate},
|
||||
{"width", data.width}, {"height", data.height}, {"blockPerFrame", data.blockPerFrame},
|
||||
{"channels", data.channels}, {"encodeQuality", data.encodeQuality}, {"blockPerSecond", data.blockPerSecond}};
|
||||
std::unordered_map<std::string, std::vector<int32_t> &> capabilityVectorMap = {
|
||||
{"sampleRate", data.sampleRate}, {"pixFormat", data.pixFormat}, {"bitDepth", data.bitDepth},
|
||||
{"profiles", data.profiles}, {"bitrateMode", data.bitrateMode}};
|
||||
std::unordered_map<std::string, std::map<int32_t, std::vector<int32_t>> &> capabilityHashVectorMap = {
|
||||
{"profileLevelsMap", data.profileLevelsMap}};
|
||||
|
||||
bool ret = false;
|
||||
if (capabilityStringMap.find(capabilityKey) != capabilityStringMap.end()) {
|
||||
ret = SetCapabilityStringData(capabilityStringMap, capabilityKey, capabilityValue);
|
||||
|
@ -49,7 +49,7 @@ private:
|
||||
static bool IsNumberArray(const std::vector<std::string> &strArray);
|
||||
static bool TransStrAsRange(const std::string &str, Range &range);
|
||||
static bool TransStrAsSize(const std::string &str, ImgSize &size);
|
||||
static std::vector<int32_t> TransMapAsIntegerArray(const std::unordered_map<std::string, int> &capabilityMap,
|
||||
static std::vector<int32_t> TransMapAsIntegerArray(const std::unordered_map<std::string, int> &capMap,
|
||||
const std::vector<std::string> &spilt);
|
||||
static std::vector<int32_t> TransStrAsIntegerArray(const std::vector<std::string> &spilt);
|
||||
static bool SpiltKeyList(const std::string &str, const std::string &delim, std::vector<std::string> &spilt);
|
||||
|
@ -23,20 +23,8 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
||||
template <typename I, typename Identity, typename... Args>
|
||||
class AVCodecBaseFactory {
|
||||
private:
|
||||
friend I;
|
||||
AVCodecBaseFactory() = default;
|
||||
using builder = std::function<std::shared_ptr<I>(Args...)>;
|
||||
|
||||
static auto &builders()
|
||||
{
|
||||
static std::unordered_map<Identity, builder> container;
|
||||
return container;
|
||||
}
|
||||
|
||||
public:
|
||||
using self = AVCodecBaseFactory<I, Identity, Args...>;
|
||||
|
||||
@ -68,13 +56,23 @@ public:
|
||||
(void)registered;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
friend I;
|
||||
AVCodecBaseFactory() = default;
|
||||
using builder = std::function<std::shared_ptr<I>(Args...)>;
|
||||
|
||||
static auto &builders()
|
||||
{
|
||||
static std::unordered_map<Identity, builder> container;
|
||||
return container;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename I, typename Identify, typename... Args>
|
||||
template <typename T>
|
||||
bool AVCodecBaseFactory<I, Identify, Args...>::CodecRegister<T>::registered =
|
||||
AVCodecBaseFactory<I, Identify, Args...>::CodecRegister<T>::avRegister();
|
||||
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
|
@ -1,34 +1,34 @@
|
||||
# Copyright (C) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# Copyright (C) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/multimedia/av_codec/config.gni")
|
||||
|
||||
config("plugin_presets") {
|
||||
include_dirs = [
|
||||
"$av_codec_root_dir/interfaces/kits/c",
|
||||
"$av_codec_root_dir/interfaces/inner_api/native",
|
||||
"$av_codec_root_dir/services/dfx/include",
|
||||
"$av_codec_root_dir/services/utils/include",
|
||||
"$av_codec_root_dir/services/engine/plugin/core",
|
||||
"$av_codec_root_dir/services/engine/plugin/interface",
|
||||
"$av_codec_root_dir/services/engine/source/hst_releated",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
|
||||
]
|
||||
}
|
||||
|
||||
group("av_codec_plugin") {
|
||||
deps = [ "plugins:av_codec_plugin_store" ]
|
||||
}
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/multimedia/av_codec/config.gni")
|
||||
|
||||
config("plugin_presets") {
|
||||
include_dirs = [
|
||||
"$av_codec_root_dir/interfaces/kits/c",
|
||||
"$av_codec_root_dir/interfaces/inner_api/native",
|
||||
"$av_codec_root_dir/services/dfx/include",
|
||||
"$av_codec_root_dir/services/utils/include",
|
||||
"$av_codec_root_dir/services/engine/plugin/core",
|
||||
"$av_codec_root_dir/services/engine/plugin/interface",
|
||||
"$av_codec_root_dir/services/engine/source/hst_releated",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
|
||||
]
|
||||
}
|
||||
|
||||
group("av_codec_plugin") {
|
||||
deps = [ "plugins:av_codec_plugin_store" ]
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ int32_t DemuxerClient::UnselectSourceTrackByID(uint32_t index)
|
||||
return demuxerProxy_->UnselectSourceTrackByID(index);
|
||||
}
|
||||
int32_t DemuxerClient::CopyNextSample(uint32_t &trackIndex, uint8_t *buffer,
|
||||
AVCodecBufferInfo &bufferInfo, AVCodecBufferFlag &flag)
|
||||
AVCodecBufferInfo &bufferInfo, AVCodecBufferFlag &flag)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
CHECK_AND_RETURN_RET_LOG(demuxerProxy_ != nullptr, AVCS_ERR_NO_MEMORY, "demuxer service does not exist.");
|
||||
|
@ -71,7 +71,7 @@ int32_t DemuxerServiceProxy::SelectSourceTrackByID(uint32_t trackIndex)
|
||||
|
||||
int32_t error = Remote()->SendRequest(SELECT_SOURCE_TRACK_BY_ID, data, reply, option);
|
||||
CHECK_AND_RETURN_RET_LOG(error == AVCS_ERR_OK, error,
|
||||
"Failed to call SelectSourceTrackByID, error: %{public}d", error);
|
||||
"Failed to call SelectSourceTrackByID, error: %{public}d", error);
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
int32_t DemuxerServiceProxy::UnselectSourceTrackByID(uint32_t trackIndex)
|
||||
@ -83,8 +83,8 @@ int32_t DemuxerServiceProxy::UnselectSourceTrackByID(uint32_t trackIndex)
|
||||
CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Failed to write descriptor!");
|
||||
|
||||
int32_t error = Remote()->SendRequest(UNSELECT_SOURCE_TRACK_BY_ID, data, reply, option);
|
||||
CHECK_AND_RETURN_RET_LOG(error == AVCS_ERR_OK, error,
|
||||
"Failed to call UnselectSourceTrackByID, error: %{public}d", error);
|
||||
CHECK_AND_RETURN_RET_LOG(error == AVCS_ERR_OK, error,
|
||||
"Failed to call UnselectSourceTrackByID, error: %{public}d", error);
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
int32_t DemuxerServiceProxy::CopyNextSample(uint32_t &trackIndex, uint8_t *buffer,
|
||||
|
@ -113,7 +113,7 @@ int32_t DemuxerServiceStub::UnselectSourceTrackByID(uint32_t trackIndex)
|
||||
}
|
||||
|
||||
int32_t DemuxerServiceStub::CopyNextSample(uint32_t &trackIndex, uint8_t *buffer,
|
||||
AVCodecBufferInfo &bufferInfo, AVCodecBufferFlag &flag)
|
||||
AVCodecBufferInfo &bufferInfo, AVCodecBufferFlag &flag)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(demuxerServer_ != nullptr, AVCS_ERR_NO_MEMORY, "demuxer service is nullptr");
|
||||
return demuxerServer_->CopyNextSample(trackIndex, buffer, bufferInfo, flag);
|
||||
@ -140,7 +140,7 @@ int32_t DemuxerServiceStub::DumpInfo(int32_t fd)
|
||||
int32_t DemuxerServiceStub::Init(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
uint64_t sourceAddr = data.ReadUint64();
|
||||
CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(Init(sourceAddr)), AVCS_ERR_UNKNOWN, "Reply Init failed!");
|
||||
CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(Init(sourceAddr)), AVCS_ERR_UNKNOWN, "Reply Init failed!");
|
||||
return AVCS_ERR_OK;
|
||||
}
|
||||
|
||||
@ -149,7 +149,7 @@ int32_t DemuxerServiceStub::SelectSourceTrackByID(MessageParcel &data, MessagePa
|
||||
uint32_t trackIndex = data.ReadUint32();
|
||||
|
||||
CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(SelectSourceTrackByID(trackIndex)), AVCS_ERR_UNKNOWN,
|
||||
"Reply SelectSourceTrackByID failed!");
|
||||
"Reply SelectSourceTrackByID failed!");
|
||||
return AVCS_ERR_OK;
|
||||
}
|
||||
|
||||
@ -158,7 +158,7 @@ int32_t DemuxerServiceStub::UnselectSourceTrackByID(MessageParcel &data, Message
|
||||
uint32_t trackIndex = data.ReadUint32();
|
||||
|
||||
CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(UnselectSourceTrackByID(trackIndex)), AVCS_ERR_UNKNOWN,
|
||||
"Reply UnselectSourceTrackByID failed!");
|
||||
"Reply UnselectSourceTrackByID failed!");
|
||||
return AVCS_ERR_OK;
|
||||
}
|
||||
|
||||
@ -173,11 +173,12 @@ int32_t DemuxerServiceStub::CopyNextSample(MessageParcel &data, MessageParcel &r
|
||||
int32_t ret = CopyNextSample(trackIndex, buffer, info, flag);
|
||||
|
||||
CHECK_AND_RETURN_RET_LOG(reply.WriteUint32(trackIndex), AVCS_ERR_UNKNOWN, "Reply CopyNextSample failed!");
|
||||
CHECK_AND_RETURN_RET_LOG(reply.WriteUnpadBuffer(buffer, sizeof(buffer)), AVCS_ERR_UNKNOWN, "Reply CopyNextSample failed!");
|
||||
CHECK_AND_RETURN_RET_LOG(reply.WriteInt64(info.presentationTimeUs), AVCS_ERR_UNKNOWN, "Reply CopyNextSample failed!");
|
||||
CHECK_AND_RETURN_RET_LOG(reply.WriteInt64(info.presentationTimeUs), AVCS_ERR_UNKNOWN,
|
||||
"Reply CopyNextSample failed!");
|
||||
CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(info.size), AVCS_ERR_UNKNOWN, "Reply CopyNextSample failed!");
|
||||
CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(info.offset), AVCS_ERR_UNKNOWN, "Reply CopyNextSample failed!");
|
||||
CHECK_AND_RETURN_RET_LOG(reply.WriteUint32(static_cast<uint32_t>(flag)), AVCS_ERR_UNKNOWN, "Reply CopyNextSample failed!");
|
||||
CHECK_AND_RETURN_RET_LOG(reply.WriteUint32(static_cast<uint32_t>(flag)), AVCS_ERR_UNKNOWN,
|
||||
"Reply CopyNextSample failed!");
|
||||
CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), AVCS_ERR_UNKNOWN, "Reply CopyNextSample failed!");
|
||||
return AVCS_ERR_OK;
|
||||
}
|
||||
@ -188,7 +189,7 @@ int32_t DemuxerServiceStub::SeekToTime(MessageParcel &data, MessageParcel &reply
|
||||
AVSeekMode seekMode = static_cast<AVSeekMode>(data.ReadInt32());
|
||||
|
||||
CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(SeekToTime(mSeconds, seekMode)),
|
||||
AVCS_ERR_UNKNOWN, "Reply SeekToTime failed!");
|
||||
AVCS_ERR_UNKNOWN, "Reply SeekToTime failed!");
|
||||
return AVCS_ERR_OK;
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
int32_t Init(uint64_t sourceAddr) override;
|
||||
int32_t SelectSourceTrackByID(uint32_t trackIndex) override;
|
||||
int32_t UnselectSourceTrackByID(uint32_t trackIndex) override;
|
||||
int32_t CopyNextSample(uint32_t &trackIndex, uint8_t *buffer,
|
||||
int32_t CopyNextSample(uint32_t &trackIndex, uint8_t *buffer,
|
||||
AVCodecBufferInfo &bufferInfo, AVCodecBufferFlag &flag) override;
|
||||
int32_t SeekToTime(int64_t mSeconds, const AVSeekMode mode) override;
|
||||
|
||||
|
@ -69,7 +69,7 @@ int32_t DemuxerServer::UnselectSourceTrackByID(uint32_t trackIndex)
|
||||
}
|
||||
|
||||
int32_t DemuxerServer::CopyNextSample(uint32_t &trackIndex, uint8_t *buffer,
|
||||
AVCodecBufferInfo &bufferInfo, AVCodecBufferFlag &flag)
|
||||
AVCodecBufferInfo &bufferInfo, AVCodecBufferFlag &flag)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(demuxerEngine_ != nullptr, AVCS_ERR_INVALID_OPERATION, "Demuxer engine does not exist");
|
||||
int32_t ret = demuxerEngine_->CopyNextSample(trackIndex, buffer, bufferInfo, flag);
|
||||
|
@ -173,7 +173,7 @@ int32_t SourceServiceStub::SetTrackFormat(MessageParcel &data, MessageParcel &re
|
||||
(void)AVCodecParcel::Unmarshalling(data, param);
|
||||
uint32_t trackIndex = data.ReadUint32();
|
||||
CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(SetTrackFormat(param, trackIndex)), AVCS_ERR_UNKNOWN,
|
||||
"Reply SetTrackFormat failed");
|
||||
"Reply SetTrackFormat failed");
|
||||
return AVCS_ERR_OK;
|
||||
}
|
||||
|
||||
|
@ -85,8 +85,7 @@ int32_t AVSharedMemoryBase::Init()
|
||||
{
|
||||
ON_SCOPE_EXIT(0) {
|
||||
AVCODEC_LOGE("create avsharedmemory failed, name = %{public}s, size = %{public}d, "
|
||||
"flags = 0x%{public}x, fd = %{public}d",
|
||||
name_.c_str(), capacity_, flags_, fd_);
|
||||
"flags = 0x%{public}x, fd = %{public}d", name_.c_str(), capacity_, flags_, fd_);
|
||||
Close();
|
||||
};
|
||||
|
||||
@ -95,8 +94,8 @@ int32_t AVSharedMemoryBase::Init()
|
||||
bool isRemote = false;
|
||||
if (fd_ > 0) {
|
||||
int size = AshmemGetSize(fd_);
|
||||
CHECK_AND_RETURN_RET_LOG(size == capacity_, AVCS_ERR_INVALID_VAL, "size not equal capacity_, size = %{public}d, "
|
||||
"capacity_ = %{public}d", size, capacity_);
|
||||
CHECK_AND_RETURN_RET_LOG(size == capacity_, AVCS_ERR_INVALID_VAL,
|
||||
"size not equal capacity_, size = %{public}d, capacity_ = %{public}d", size, capacity_);
|
||||
isRemote = true;
|
||||
} else {
|
||||
fd_ = AshmemCreate(name_.c_str(), static_cast<size_t>(capacity_));
|
||||
@ -163,7 +162,8 @@ int32_t AVSharedMemoryBase::Write(const uint8_t *in, int32_t writeSize, int32_t
|
||||
CHECK_AND_RETURN_RET_LOG(dstPtr != nullptr, 0, "Inner dstPtr is nullptr");
|
||||
|
||||
auto error = memcpy_s(dstPtr, length, in, length);
|
||||
CHECK_AND_RETURN_RET_LOG(error == EOK, 0, "Inner memcpy_s failed,name:%{public}s, %{public}s", name_.c_str(), strerror(error));
|
||||
CHECK_AND_RETURN_RET_LOG(error == EOK, 0, "Inner memcpy_s failed,name:%{public}s, %{public}s",
|
||||
name_.c_str(), strerror(error));
|
||||
size_ = start + length;
|
||||
return length;
|
||||
}
|
||||
@ -184,7 +184,8 @@ int32_t AVSharedMemoryBase::Read(uint8_t *out, int32_t readSize, int32_t positio
|
||||
uint8_t *srcPtr = base_ + start;
|
||||
CHECK_AND_RETURN_RET_LOG(srcPtr != nullptr, 0, "Inner srcPtr is nullptr");
|
||||
auto error = memcpy_s(out, length, srcPtr, length);
|
||||
CHECK_AND_RETURN_RET_LOG(error == EOK, 0, "Inner memcpy_s failed,name:%{public}s, %{public}s", name_.c_str(), strerror(error));
|
||||
CHECK_AND_RETURN_RET_LOG(error == EOK, 0, "Inner memcpy_s failed,name:%{public}s, %{public}s",
|
||||
name_.c_str(), strerror(error));
|
||||
return length;
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,6 @@ public:
|
||||
|
||||
void ClearUsedSize();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the memory's virtual address
|
||||
* @return the memory's virtual address if the memory is valid, otherwise nullptr.
|
||||
|
@ -13,12 +13,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include <unistd.h>
|
||||
#include <memory>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
||||
inline void SleepFor(unsigned ms)
|
||||
{
|
||||
constexpr int factor = 1000;
|
||||
@ -41,6 +42,6 @@ inline std::shared_ptr<T> ReinterpretPointerCast(const std::shared_ptr<U>& ptr)
|
||||
{
|
||||
return std::shared_ptr<T>(ptr, reinterpret_cast<T*>(ptr.get()));
|
||||
}
|
||||
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -218,9 +218,7 @@ void ADecDemo::InputFunc()
|
||||
|
||||
uint32_t index = signal_->inQueue_.front();
|
||||
auto buffer = signal_->inBufferQueue_.front();
|
||||
|
||||
int32_t ret = av_read_frame(fmpt_ctx, &pkt);
|
||||
|
||||
if (ret < 0) {
|
||||
OH_AVCodecBufferAttr info;
|
||||
info.size = 0;
|
||||
|
@ -13,16 +13,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "avcodec_audio_encoder_demo.h"
|
||||
#include "securec.h"
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include "securec.h"
|
||||
#include "avcodec_common.h"
|
||||
#include "avcodec_errors.h"
|
||||
#include "media_description.h"
|
||||
#include "native_avformat.h"
|
||||
#include "demo_log.h"
|
||||
#include "native_avcodec_base.h"
|
||||
#include "avcodec_audio_encoder_demo.h"
|
||||
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::Media;
|
||||
@ -37,10 +37,9 @@ constexpr uint32_t FRAME_DURATION_US = 33000;
|
||||
constexpr uint32_t CHANNEL_LAYOUT = 3;
|
||||
constexpr int32_t SAMPLE_FORMAT = 1;
|
||||
|
||||
// constexpr uint32_t DEFAULT_FRAME_COUNT = 1;
|
||||
constexpr string_view inputFilePath = "/data/encoderTest.pcm";
|
||||
constexpr string_view outputFilePath = "/data/encoderTest.flac";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
static void OnError(OH_AVCodec *codec, int32_t errorCode, void *userData)
|
||||
{
|
||||
@ -79,11 +78,12 @@ static void OnOutputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemo
|
||||
signal_->outQueue_.push(index);
|
||||
signal_->outBufferQueue_.push(data);
|
||||
if (attr) {
|
||||
cout << "OnOutputBufferAvailable received, index:" << index << ", attr->size:" << attr->size <<", attr->flags:" << attr->flags<< endl;
|
||||
cout << "OnOutputBufferAvailable received, index:" << index << ", attr->size:" << attr->size
|
||||
<< ", attr->flags:" << attr->flags << endl;
|
||||
signal_->attrQueue_.push(*attr);
|
||||
} else {
|
||||
cout << "OnOutputBufferAvailable error, attr is nullptr!" << endl;
|
||||
}
|
||||
} else {
|
||||
cout << "OnOutputBufferAvailable error, attr is nullptr!" << endl;
|
||||
}
|
||||
signal_->outCond_.notify_all();
|
||||
}
|
||||
|
||||
@ -117,7 +117,6 @@ AEncDemo::AEncDemo()
|
||||
frameCount_ = 0;
|
||||
isRunning_ = false;
|
||||
inputFile_ = std::make_unique<std::ifstream>(inputFilePath, std::ios::binary);
|
||||
// outputFile_ = std::make_unique<std::ofstream>(outputFilePath, std::ios::binary);
|
||||
}
|
||||
|
||||
AEncDemo::~AEncDemo()
|
||||
@ -183,7 +182,8 @@ int32_t AEncDemo::Stop()
|
||||
return OH_AudioEncoder_Stop(audioEnc_);
|
||||
}
|
||||
|
||||
int32_t AEncDemo::Flush() {
|
||||
int32_t AEncDemo::Flush()
|
||||
{
|
||||
return OH_AudioEncoder_Flush(audioEnc_);
|
||||
}
|
||||
|
||||
@ -197,52 +197,51 @@ int32_t AEncDemo::Release()
|
||||
return OH_AudioEncoder_Destroy(audioEnc_);
|
||||
}
|
||||
|
||||
void AEncDemo::HandleEOS(const uint32_t &index)
|
||||
{
|
||||
OH_AVCodecBufferAttr info;
|
||||
info.size = 0;
|
||||
info.offset = 0;
|
||||
info.pts = 0;
|
||||
info.flags = AVCODEC_BUFFER_FLAGS_EOS;
|
||||
OH_AudioEncoder_PushInputData(audioEnc_, index, info);
|
||||
std::cout << "end buffer\n";
|
||||
signal_->inQueue_.pop();
|
||||
signal_->inBufferQueue_.pop();
|
||||
}
|
||||
|
||||
void AEncDemo::InputFunc()
|
||||
{
|
||||
DEMO_CHECK_AND_RETURN_LOG(inputFile_ != nullptr && inputFile_->is_open(), "Fatal: open file fail");
|
||||
inputFile_->seekg (0, ios::end);
|
||||
inputFile_->seekg(0, ios::end);
|
||||
int32_t fsize = inputFile_->tellg();
|
||||
inputFile_->seekg(0, ios::beg);
|
||||
|
||||
while (true) {
|
||||
if (!isRunning_.load()) {
|
||||
break;
|
||||
}
|
||||
|
||||
unique_lock<mutex> lock(signal_->inMutex_);
|
||||
signal_->inCond_.wait(lock, [this]() { return (signal_->inQueue_.size() > 0 || !isRunning_.load()); });
|
||||
|
||||
if (!isRunning_.load()) {
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t index = signal_->inQueue_.front();
|
||||
auto buffer = signal_->inBufferQueue_.front();
|
||||
DEMO_CHECK_AND_BREAK_LOG(buffer != nullptr, "Fatal: GetInputBuffer fail");
|
||||
|
||||
uint32_t bufferSize = fsize > OH_AVMemory_GetSize(buffer) ? OH_AVMemory_GetSize(buffer) : fsize;
|
||||
if(fsize > 0 || !inputFile_->eof() )
|
||||
{
|
||||
if (fsize > 0 || !inputFile_->eof()) {
|
||||
(void)inputFile_->read((char *)OH_AVMemory_GetAddr(buffer), bufferSize);
|
||||
fsize = fsize - bufferSize;
|
||||
std::cout << "fsize " << fsize << std::endl;
|
||||
} else {
|
||||
OH_AVCodecBufferAttr info;
|
||||
info.size = 0;
|
||||
info.offset = 0;
|
||||
info.pts = 0;
|
||||
info.flags = AVCODEC_BUFFER_FLAGS_EOS;
|
||||
OH_AudioEncoder_PushInputData(audioEnc_, index, info);
|
||||
std::cout << "end buffer\n";
|
||||
signal_->inQueue_.pop();
|
||||
signal_->inBufferQueue_.pop();
|
||||
HandleEOS(index);
|
||||
break;
|
||||
}
|
||||
DEMO_CHECK_AND_BREAK_LOG(buffer != nullptr, "Fatal: GetInputBuffer fail");
|
||||
OH_AVCodecBufferAttr info;
|
||||
info.size = bufferSize;
|
||||
info.offset = 0;
|
||||
// info.presentationTimeUs = timeStamp_;
|
||||
|
||||
int32_t ret = AVCS_ERR_OK;
|
||||
if (isFirstFrame_) {
|
||||
@ -253,12 +252,10 @@ void AEncDemo::InputFunc()
|
||||
info.flags = AVCODEC_BUFFER_FLAGS_NONE;
|
||||
ret = OH_AudioEncoder_PushInputData(audioEnc_, index, info);
|
||||
}
|
||||
|
||||
timeStamp_ += FRAME_DURATION_US;
|
||||
signal_->inQueue_.pop();
|
||||
signal_->inBufferQueue_.pop();
|
||||
frameCount_++;
|
||||
|
||||
if (ret != AVCS_ERR_OK) {
|
||||
cout << "Fatal error, exit" << endl;
|
||||
break;
|
||||
@ -267,11 +264,12 @@ void AEncDemo::InputFunc()
|
||||
inputFile_->close();
|
||||
}
|
||||
|
||||
void AEncDemo::OutputFunc() {
|
||||
void AEncDemo::OutputFunc()
|
||||
{
|
||||
std::ofstream outputFile;
|
||||
outputFile.open(outputFilePath.data(), std::ios::out | std::ios::binary);
|
||||
if (!outputFile.is_open()) {
|
||||
std::cout<<"open " << outputFilePath << " failed!"<<std::endl;
|
||||
std::cout << "open " << outputFilePath << " failed!" << std::endl;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
@ -295,7 +293,7 @@ void AEncDemo::OutputFunc() {
|
||||
OH_AVCodecBufferAttr attr = signal_->attrQueue_.front();
|
||||
OH_AVMemory *data = signal_->outBufferQueue_.front();
|
||||
if (data != nullptr) {
|
||||
cout << "OutputFunc write file,buffer index" << index << ", data size = :" << attr.size << endl;
|
||||
cout << "OutputFunc write file,buffer index" << index << ", data size = :" << attr.size << endl;
|
||||
outputFile.write(reinterpret_cast<char *>(OH_AVMemory_GetAddr(data)), attr.size);
|
||||
}
|
||||
cout << "attr.flags: " << attr.flags << endl;
|
||||
|
@ -16,7 +16,6 @@
|
||||
#ifndef AVCODEC_AUDIO_ENCODER_DEMO_H
|
||||
#define AVCODEC_AUDIO_ENCODER_DEMO_H
|
||||
|
||||
#include "native_avcodec_audioencoder.h"
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <fstream>
|
||||
@ -24,6 +23,7 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include "nocopyable.h"
|
||||
#include "native_avcodec_audioencoder.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
@ -57,6 +57,7 @@ private:
|
||||
int32_t Release();
|
||||
void InputFunc();
|
||||
void OutputFunc();
|
||||
void HandleEOS(const uint32_t &index);
|
||||
|
||||
std::atomic<bool> isRunning_;
|
||||
std::unique_ptr<std::ifstream> inputFile_;
|
||||
@ -69,7 +70,7 @@ private:
|
||||
int64_t timeStamp_ = 0;
|
||||
uint32_t frameCount_ = 0;
|
||||
};
|
||||
} // AudioDemo
|
||||
} // namespace AV_Codec
|
||||
} // namespace AudioDemo
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
#endif // AVCODEC_AUDIO_DECODER_DEMO_H
|
||||
|
@ -15,13 +15,14 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include "avcodec_audio_encoder_inner_demo.h"
|
||||
|
||||
#include "avcodec_audio_codec_key.h"
|
||||
#include "avcodec_common.h"
|
||||
#include "avcodec_errors.h"
|
||||
#include "demo_log.h"
|
||||
#include "media_description.h"
|
||||
#include "securec.h"
|
||||
#include "avcodec_audio_encoder_inner_demo.h"
|
||||
|
||||
extern "C" {
|
||||
#include "libavcodec/avcodec.h"
|
||||
@ -42,6 +43,7 @@ constexpr uint32_t BITS_RATE = 112000; // for aac encoding
|
||||
constexpr uint32_t BITS_PER_CODED_RATE = 4;
|
||||
constexpr uint32_t DEFAULT_SAMPLE_FORMATE_VALE = 8;
|
||||
constexpr uint32_t DEFAULT_CHANNEL_LAYOUT_COUNT = 3;
|
||||
constexpr uint32_t DEFAULT_SLEEP_TIME = 30;
|
||||
} // namespace
|
||||
|
||||
void AEnInnerDemo::RunCase()
|
||||
@ -58,7 +60,7 @@ void AEnInnerDemo::RunCase()
|
||||
DEMO_CHECK_AND_RETURN_LOG(Configure(format) == AVCS_ERR_OK, "Fatal: Configure fail");
|
||||
|
||||
DEMO_CHECK_AND_RETURN_LOG(Start() == AVCS_ERR_OK, "Fatal: Start fail");
|
||||
sleep(30);
|
||||
sleep(DEFAULT_SLEEP_TIME);
|
||||
DEMO_CHECK_AND_RETURN_LOG(Stop() == AVCS_ERR_OK, "Fatal: Stop fail");
|
||||
DEMO_CHECK_AND_RETURN_LOG(Release() == AVCS_ERR_OK, "Fatal: Release fail");
|
||||
}
|
||||
|
@ -46,6 +46,8 @@ int AVMuxerDemo::DoAddTrack(int32_t &trackIndex, MediaDescription &trackDesc)
|
||||
|
||||
void AVMuxerDemo::DoRunMuxer(const std::string &runMode)
|
||||
{
|
||||
constexpr float latitude = 50.5;
|
||||
constexpr float longitude = 60.6;
|
||||
std::string outFileName = "mux_" + runMode + "_" + audioType_ + "_" + videoType_ + "_" + coverType_ + "." + format_;
|
||||
outFd_ = open(outFileName.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
|
||||
if (outFd_ < 0) {
|
||||
@ -61,7 +63,7 @@ void AVMuxerDemo::DoRunMuxer(const std::string &runMode)
|
||||
}
|
||||
std::cout << "create muxer success " << avmuxer_ << std::endl;
|
||||
|
||||
if (avmuxer_->SetLocation(TEST_LATITUDE, TEST_LONGITUDE) != AVCS_ERR_OK
|
||||
if (avmuxer_->SetLocation(latitude, longitude) != AVCS_ERR_OK
|
||||
|| avmuxer_->SetRotation(0) != AVCS_ERR_OK) {
|
||||
std::cout<<"set failed!"<<std::endl;
|
||||
return;
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
class AVMuxerDemo /* : public NoCopyable */ : public AVMuxerDemoBase {
|
||||
class AVMuxerDemo : public AVMuxerDemoBase {
|
||||
public:
|
||||
AVMuxerDemo() = default;
|
||||
~AVMuxerDemo() = default;
|
||||
|
@ -309,7 +309,7 @@ void AVMuxerDemoBase::WriteSingleTrackSample(uint32_t trackId, std::shared_ptr<s
|
||||
int AVMuxerDemoBase::ReadSampleDataInfo(std::shared_ptr<std::ifstream> &curFile, unsigned char *&buffer,
|
||||
uint32_t &curSize, TrackSampleInfo &info)
|
||||
{
|
||||
int32_t dataSize = 0;
|
||||
uint32_t dataSize = 0;
|
||||
uint32_t flags = 0;
|
||||
if (audioPts_ > videoPts_) {
|
||||
curFile = videoFile_;
|
||||
@ -346,7 +346,7 @@ int AVMuxerDemoBase::ReadSampleDataInfo(std::shared_ptr<std::ifstream> &curFile,
|
||||
}
|
||||
|
||||
curFile->read((char *)buffer, dataSize);
|
||||
if(curFile->eof()) {
|
||||
if (curFile->eof()) {
|
||||
return -1;
|
||||
}
|
||||
info.size = dataSize;
|
||||
@ -358,7 +358,7 @@ void AVMuxerDemoBase::WriteAvTrackSample()
|
||||
if (audioFile_ == nullptr || videoFile_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
TrackSampleInfo info {0, 0, 0 ,0};
|
||||
TrackSampleInfo info {0, 0, 0, 0};
|
||||
std::shared_ptr<std::ifstream> curFile = nullptr;
|
||||
unsigned char *avMuxerDemoBuffer = nullptr;
|
||||
uint32_t avMuxerDemoBufferSize = 0;
|
||||
|
@ -21,10 +21,6 @@
|
||||
#include "avmuxer_demo_common.h"
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
||||
constexpr float TEST_LATITUDE = 50.5;
|
||||
constexpr float TEST_LONGITUDE = 60.6;
|
||||
|
||||
class AVMuxerDemoBase {
|
||||
public:
|
||||
AVMuxerDemoBase();
|
||||
|
@ -15,13 +15,6 @@
|
||||
|
||||
#include "avmuxer_demo_common.h"
|
||||
|
||||
enum ModeNum {
|
||||
MODE_ZERO = 0,
|
||||
MODE_ONE = 1,
|
||||
MODE_TWO = 2,
|
||||
MODE_THREE = 3
|
||||
};
|
||||
|
||||
struct AudioTrackParam g_audioMpegPar = {
|
||||
.fileName = "mpeg_44100_2.bin",
|
||||
.mimeType = "audio/mpeg",
|
||||
|
@ -30,11 +30,13 @@ constexpr int DEMO_THREAD_COUNT = 10;
|
||||
|
||||
static int RunLoopNativeMuxer(string out)
|
||||
{
|
||||
time_t startTime = time(nullptr);
|
||||
time_t curTime = time(nullptr);
|
||||
time_t startTime = 0;
|
||||
time_t curTime = 0;
|
||||
(void)time(&startTime);
|
||||
(void)time(&curTime);
|
||||
while (difftime(curTime, startTime) < RUN_TIME) {
|
||||
RunNativeMuxer(out.c_str());
|
||||
time(&curTime);
|
||||
(void)time(&curTime);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -90,8 +92,10 @@ static int RunEngineMuxer()
|
||||
|
||||
static int RunLoopEngineMuxer()
|
||||
{
|
||||
time_t startTime = time(nullptr);
|
||||
time_t curTime = time(nullptr);
|
||||
time_t startTime = 0;
|
||||
time_t curTime = 0;
|
||||
(void)time(&startTime);
|
||||
(void)time(&curTime);
|
||||
while (difftime(curTime, startTime) < RUN_TIME) {
|
||||
RunEngineMuxer();
|
||||
(void)time(&curTime);
|
||||
@ -99,7 +103,7 @@ static int RunLoopEngineMuxer()
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AvmuxerDemoCase()
|
||||
void AvmuxerDemoCase(void)
|
||||
{
|
||||
cout << "Please select a muxer demo(default native muxer demo): " << endl;
|
||||
cout << "0:native_muxer" << endl;
|
||||
|
@ -16,6 +16,6 @@
|
||||
#ifndef AVMUXER_DEMO_RUNNER_H
|
||||
#define AVMUXER_DEMO_RUNNER_H
|
||||
|
||||
void AvmuxerDemoCase();
|
||||
void AvmuxerDemoCase(void);
|
||||
|
||||
#endif // AVMUXER_DEMO_RUNNER_H
|
@ -60,6 +60,8 @@ int AVMuxerEngineDemo::DoAddTrack(int32_t &trackIndex, MediaDescription &trackDe
|
||||
|
||||
void AVMuxerEngineDemo::DoRunMuxer(const std::string &runMode)
|
||||
{
|
||||
constexpr float latitude = 50.5;
|
||||
constexpr float longitude = 60.6;
|
||||
std::string outFileName = "engine_mux_" + runMode + "_" + audioType_ + "_"
|
||||
+ videoType_ + "_" + coverType_ + "." + format_;
|
||||
outFd_ = open(outFileName.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
|
||||
@ -76,7 +78,7 @@ void AVMuxerEngineDemo::DoRunMuxer(const std::string &runMode)
|
||||
}
|
||||
std::cout << "create muxer success " << avmuxer_ << std::endl;
|
||||
|
||||
if (avmuxer_->SetLocation(TEST_LATITUDE, TEST_LONGITUDE) != AVCS_ERR_OK
|
||||
if (avmuxer_->SetLocation(latitude, longitude) != AVCS_ERR_OK
|
||||
|| avmuxer_->SetRotation(0) != AVCS_ERR_OK) {
|
||||
std::cout<<"set failed!"<<std::endl;
|
||||
return;
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
class AVMuxerEngineDemo /* : public NoCopyable */ : public AVMuxerDemoBase {
|
||||
class AVMuxerEngineDemo : public AVMuxerDemoBase {
|
||||
public:
|
||||
AVMuxerEngineDemo() = default;
|
||||
~AVMuxerEngineDemo() = default;
|
||||
|
@ -62,6 +62,8 @@ int AVMuxerFFmpegDemo::DoAddTrack(int32_t &trackIndex, MediaDescription ¶m)
|
||||
|
||||
void AVMuxerFFmpegDemo::DoRunMuxer()
|
||||
{
|
||||
constexpr float latitude = 50.5;
|
||||
constexpr float longitude = 60.6;
|
||||
GetFfmpegRegister();
|
||||
if (register_->plugins.size() <= 0) {
|
||||
std::cout<<"regist muxers failed!"<<std::endl;
|
||||
@ -99,7 +101,7 @@ void AVMuxerFFmpegDemo::DoRunMuxer()
|
||||
return;
|
||||
}
|
||||
|
||||
ffmpegMuxer_->SetLocation(TEST_LATITUDE, TEST_LONGITUDE);
|
||||
ffmpegMuxer_->SetLocation(latitude, longitude);
|
||||
ffmpegMuxer_->SetRotation(0);
|
||||
|
||||
AddAudioTrack(audioParams_);
|
||||
@ -118,7 +120,7 @@ void AVMuxerFFmpegDemo::DoRunMultiThreadCase()
|
||||
|
||||
int AVMuxerFFmpegDemo::DoWriteSampleBuffer(uint8_t *sampleBuffer, TrackSampleInfo &info)
|
||||
{
|
||||
if(ffmpegMuxer_ != nullptr &&
|
||||
if (ffmpegMuxer_ != nullptr &&
|
||||
ffmpegMuxer_->WriteSampleBuffer(sampleBuffer, info) == Status::NO_ERROR) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -25,14 +25,15 @@
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace Plugin {
|
||||
class AVMuxerFFmpegDemo /* : public NoCopyable */ : public AVMuxerDemoBase {
|
||||
class AVMuxerFFmpegDemo : public AVMuxerDemoBase {
|
||||
public:
|
||||
AVMuxerFFmpegDemo();
|
||||
~AVMuxerFFmpegDemo() = default;
|
||||
private:
|
||||
struct FfmpegRegister : PackageRegister {
|
||||
Status AddPlugin(const PluginDefBase& def) override;
|
||||
Status AddPackage(const PackageDef& def) override {
|
||||
Status AddPackage(const PackageDef& def) override
|
||||
{
|
||||
(void)def;
|
||||
return Status::NO_ERROR;
|
||||
}
|
||||
|
@ -30,6 +30,10 @@
|
||||
|
||||
#define NORMAL 0
|
||||
#define THREAD 1
|
||||
#define MODE_ZERO 0
|
||||
#define MODE_ONE 1
|
||||
#define MODE_TWO 2
|
||||
#define MODE_THREE 3
|
||||
#define TYPE_BUFFER_SIZE 20
|
||||
#define CONFIG_BUFFER_SIZE 100
|
||||
|
||||
@ -205,8 +209,6 @@ static int UpDateWriteBufferInfo(int fd, unsigned char **buffer, int *curSize, O
|
||||
return -1;
|
||||
}
|
||||
info->size = dataSize;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -358,12 +360,13 @@ int GetInputNum(int defaultNum)
|
||||
int num = defaultNum;
|
||||
num = getchar();
|
||||
if (num == '\n') { // default
|
||||
num = defaultNum;
|
||||
} else {
|
||||
ungetc(num, stdin);
|
||||
scanf_s("%d", &num, sizeof(num));
|
||||
fflush(stdin);
|
||||
return defaultNum;
|
||||
}
|
||||
ungetc(num, stdin);
|
||||
if (scanf_s("%d", &num) != EOK) {
|
||||
num = defaultNum;
|
||||
}
|
||||
fflush(stdin);
|
||||
return num;
|
||||
}
|
||||
|
||||
@ -375,11 +378,11 @@ void NativeSelectMuxerType(void)
|
||||
printf("\nplese select muxer type : 0.mp4 1.m4a\n");
|
||||
num = GetInputNum(0);
|
||||
switch (num) {
|
||||
case 0:
|
||||
case MODE_ZERO:
|
||||
g_muxerParam.outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
|
||||
(void)snprintf_s(g_muxerParam.outputFormatType, TYPE_BUFFER_SIZE, TYPE_BUFFER_SIZE - 1, "%s", "mp4");
|
||||
break;
|
||||
case 1:
|
||||
case MODE_ONE:
|
||||
g_muxerParam.outputFormat = AV_OUTPUT_FORMAT_M4A;
|
||||
(void)snprintf_s(g_muxerParam.outputFormatType, TYPE_BUFFER_SIZE, TYPE_BUFFER_SIZE - 1, "%s", "m4a");
|
||||
break;
|
||||
@ -400,11 +403,11 @@ void NativeSelectRunMode(void)
|
||||
printf("1. audio video write in different thread\n");
|
||||
num = GetInputNum(0);
|
||||
switch (num) {
|
||||
case 0:
|
||||
case MODE_ZERO:
|
||||
g_muxerParam.runMode = NORMAL;
|
||||
(void)snprintf_s(g_muxerParam.runModeType, TYPE_BUFFER_SIZE, TYPE_BUFFER_SIZE - 1, "%s", RUN_NORMAL);
|
||||
break;
|
||||
case 1:
|
||||
case MODE_ONE:
|
||||
g_muxerParam.runMode = THREAD;
|
||||
(void)snprintf_s(g_muxerParam.runModeType, TYPE_BUFFER_SIZE, TYPE_BUFFER_SIZE - 1, "%s", RUN_MUL_THREAD);
|
||||
break;
|
||||
@ -423,11 +426,11 @@ void NativeSelectAudio(void)
|
||||
printf("\nplese select audio mode: 0.noAudio 1.aac 2.mpeg\n");
|
||||
num = GetInputNum(1);
|
||||
switch (num) {
|
||||
case 1:
|
||||
case MODE_ONE:
|
||||
g_muxerParam.audioParams = &g_audioAacPar;
|
||||
(void)snprintf_s(g_muxerParam.audioType, TYPE_BUFFER_SIZE, TYPE_BUFFER_SIZE - 1, "%s", "aac");
|
||||
break;
|
||||
case 2:
|
||||
case MODE_TWO:
|
||||
g_muxerParam.audioParams = &g_audioMpegPar;
|
||||
(void)snprintf_s(g_muxerParam.audioType, TYPE_BUFFER_SIZE, TYPE_BUFFER_SIZE - 1, "%s", "mpeg");
|
||||
break;
|
||||
@ -446,11 +449,11 @@ void NativeSelectVideo(void)
|
||||
printf("\nplese select video mode: 0.noVideo 1.h264 2.mpeg4\n");
|
||||
num = GetInputNum(1);
|
||||
switch (num) {
|
||||
case 1:
|
||||
case MODE_ONE:
|
||||
g_muxerParam.videoParams = &g_videoH264Par;
|
||||
(void)snprintf_s(g_muxerParam.videoType, TYPE_BUFFER_SIZE, TYPE_BUFFER_SIZE - 1, "%s", "h264");
|
||||
break;
|
||||
case 2:
|
||||
case MODE_TWO:
|
||||
g_muxerParam.videoParams = &g_videoMpeg4Par;
|
||||
(void)snprintf_s(g_muxerParam.videoType, TYPE_BUFFER_SIZE, TYPE_BUFFER_SIZE - 1, "%s", "mpeg4");
|
||||
break;
|
||||
@ -469,15 +472,15 @@ void NativeSelectCover(void)
|
||||
printf("\nplese select cover mode: 0.noCover 1.jpg 2.png 3.bmp\n");
|
||||
num = GetInputNum(1);
|
||||
switch (num) {
|
||||
case 1:
|
||||
case MODE_ONE:
|
||||
g_muxerParam.coverParams = &g_jpegCoverPar;
|
||||
(void)snprintf_s(g_muxerParam.coverType, TYPE_BUFFER_SIZE, TYPE_BUFFER_SIZE - 1, "%s", "jpg");
|
||||
break;
|
||||
case 2:
|
||||
case MODE_TWO:
|
||||
g_muxerParam.coverParams = &g_pngCoverPar;
|
||||
(void)snprintf_s(g_muxerParam.coverType, TYPE_BUFFER_SIZE, TYPE_BUFFER_SIZE - 1, "%s", "png");
|
||||
break;
|
||||
case 3:
|
||||
case MODE_THREE:
|
||||
g_muxerParam.coverParams = &g_bmpCoverPar;
|
||||
(void)snprintf_s(g_muxerParam.coverType, TYPE_BUFFER_SIZE, TYPE_BUFFER_SIZE - 1, "%s", "bmp");
|
||||
break;
|
||||
@ -627,9 +630,14 @@ int RunNativeMuxer(const char *out)
|
||||
}
|
||||
|
||||
char outFileName[CONFIG_BUFFER_SIZE] = {0};
|
||||
(void)snprintf_s(outFileName, sizeof(outFileName), sizeof(outFileName) - 1, "%s_%s_%s_%s_%s.%s",
|
||||
errno_t err = EOK;
|
||||
err = snprintf_s(outFileName, sizeof(outFileName), sizeof(outFileName) - 1, "%s_%s_%s_%s_%s.%s",
|
||||
out, g_muxerParam.runModeType, g_muxerParam.audioType, g_muxerParam.videoType,
|
||||
g_muxerParam.coverType, g_muxerParam.outputFormatType);
|
||||
if (err != EOK) {
|
||||
CloseAllFd(&fdStr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fdStr.outputFd = open(outFileName, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
|
||||
if (fdStr.outputFd < 0) {
|
||||
|
@ -16,7 +16,7 @@
|
||||
#ifndef NATIVE_AVMUXER_DEMO_H
|
||||
#define NATIVE_AVMUXER_DEMO_H
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void NativeSelectMode(void);
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
||||
void CodecListDemo::RunCase()
|
||||
{
|
||||
std::cout << "===== ============== ======" << std::endl;
|
||||
|
@ -12,20 +12,18 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CODECLIST_DEMO_H
|
||||
#define CODECLIST_DEMO_H
|
||||
#include "native_avcodec_list.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
|
||||
class CodecListDemo {
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
CodecListDemo() = default;
|
||||
~CodecListDemo() = default;
|
||||
void RunCase();
|
||||
};
|
||||
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -44,7 +44,9 @@ constexpr uint32_t DEFAULT_AAC_TYPE = 1;
|
||||
constexpr uint32_t DEFAULT_AAC_LATM_TYPE = 2;
|
||||
} // namespace
|
||||
|
||||
static std::string codecName = CODEC_MP3_NAME;
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
std::string g_codecName = CODEC_MP3_NAME;
|
||||
|
||||
class ADecSignal {
|
||||
public:
|
||||
@ -134,7 +136,7 @@ void AudioCodeDecoderUnitTest::TearDownTestCase(void)
|
||||
void AudioCodeDecoderUnitTest::SetUp(void)
|
||||
{
|
||||
cout << "[SetUp]: SetUp!!!" << endl;
|
||||
adec_ = std::make_shared<OHOS::Media::AudioFFMpegAdapter>(codecName);
|
||||
adec_ = std::make_shared<OHOS::Media::AudioFFMpegAdapter>(g_codecName);
|
||||
ASSERT_NE(nullptr, adec_);
|
||||
|
||||
signal_ = new ADecSignal();
|
||||
@ -456,7 +458,7 @@ HWTEST_F(AudioCodeDecoderUnitTest, audioDecoder_Mp3_ReleaseOutputBuffer_01, Test
|
||||
|
||||
HWTEST_F(AudioCodeDecoderUnitTest, audioDecoder_SetCodecName_01, TestSize.Level1)
|
||||
{
|
||||
codecName = CODEC_FLAC_NAME;
|
||||
g_codecName = CODEC_FLAC_NAME;
|
||||
}
|
||||
|
||||
HWTEST_F(AudioCodeDecoderUnitTest, audioDecoder_Flac_Configure_01, TestSize.Level1)
|
||||
@ -726,7 +728,7 @@ HWTEST_F(AudioCodeDecoderUnitTest, audioDecoder_Flac_ReleaseOutputBuffer_01, Tes
|
||||
|
||||
HWTEST_F(AudioCodeDecoderUnitTest, audioDecoder_SetCodecName_02, TestSize.Level1)
|
||||
{
|
||||
codecName = CODEC_AAC_NAME;
|
||||
g_codecName = CODEC_AAC_NAME;
|
||||
}
|
||||
|
||||
HWTEST_F(AudioCodeDecoderUnitTest, audioDecoder_Aac_Configure_01, TestSize.Level1)
|
||||
@ -1042,4 +1044,6 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
@ -16,17 +16,17 @@
|
||||
#ifndef ACODEC_MOCK_H
|
||||
#define ACODEC_MOCK_H
|
||||
|
||||
#include <iostream>
|
||||
#include "avcodec_mock.h"
|
||||
#include "securec.h"
|
||||
#include "test_params_config.h"
|
||||
#include "unittest_log.h"
|
||||
#include <atomic>
|
||||
#include <fstream>
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include "avcodec_mock.h"
|
||||
#include "unittest_log.h"
|
||||
#include "test_params_config.h"
|
||||
#include "securec.h"
|
||||
#include <thread>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
@ -36,8 +36,8 @@ public:
|
||||
std::condition_variable inCondDec_;
|
||||
std::queue<uint32_t> inQueueDec_;
|
||||
std::queue<uint32_t> outQueueDec_;
|
||||
std::queue<uint32_t> sizeQueueDec_;
|
||||
std::queue<uint32_t> flagQueueDec_;
|
||||
std::queue<uint32_t> sizeQueueDec_;
|
||||
std::queue<uint32_t> flagQueueDec_;
|
||||
std::queue<std::shared_ptr<AVMemoryMock>> inBufferQueueDec_;
|
||||
std::queue<std::shared_ptr<AVMemoryMock>> outBufferQueueDec_;
|
||||
|
||||
@ -47,8 +47,8 @@ public:
|
||||
std::condition_variable outCondEnc_;
|
||||
std::queue<uint32_t> inQueueEnc_;
|
||||
std::queue<uint32_t> outQueueEnc_;
|
||||
std::queue<uint32_t> sizeQueueEnc_;
|
||||
std::queue<uint32_t> flagQueueEnc_;
|
||||
std::queue<uint32_t> sizeQueueEnc_;
|
||||
std::queue<uint32_t> flagQueueEnc_;
|
||||
std::queue<std::shared_ptr<AVMemoryMock>> inBufferQueueEnc_;
|
||||
std::queue<std::shared_ptr<AVMemoryMock>> outBufferQueueEnc_;
|
||||
int32_t errorNum_ = 0;
|
||||
@ -63,6 +63,7 @@ public:
|
||||
void OnStreamChanged(std::shared_ptr<FormatMock> format);
|
||||
void OnNeedInputData(uint32_t index, std::shared_ptr<AVMemoryMock> data);
|
||||
void OnNewOutputData(uint32_t index, std::shared_ptr<AVMemoryMock> data, AVCodecBufferAttrMock attr);
|
||||
|
||||
private:
|
||||
std::shared_ptr<ACodecSignal> acodecSignal_;
|
||||
};
|
||||
@ -75,13 +76,14 @@ public:
|
||||
void OnStreamChanged(std::shared_ptr<FormatMock> format);
|
||||
void OnNeedInputData(uint32_t index, std::shared_ptr<AVMemoryMock> data);
|
||||
void OnNewOutputData(uint32_t index, std::shared_ptr<AVMemoryMock> data, AVCodecBufferAttrMock attr);
|
||||
|
||||
private:
|
||||
std::shared_ptr<ACodecSignal> acodecSignal_;
|
||||
};
|
||||
|
||||
class ACodecMock : public NoCopyable {
|
||||
public:
|
||||
ACodecMock(std::shared_ptr<ACodecSignal> signal);
|
||||
explicit ACodecMock(std::shared_ptr<ACodecSignal> signal);
|
||||
~ACodecMock();
|
||||
|
||||
bool CreateAudioDecMockByMime(const std::string &mime);
|
||||
@ -117,8 +119,8 @@ public:
|
||||
void SetOutPath(const std::string &path);
|
||||
|
||||
private:
|
||||
void clearIntQueue (std::queue<uint32_t>& q);
|
||||
void clearBufferQueue (std::queue<std::shared_ptr<AVMemoryMock>>& q);
|
||||
void clearIntQueue(std::queue<uint32_t> &q);
|
||||
void clearBufferQueue(std::queue<std::shared_ptr<AVMemoryMock>> &q);
|
||||
std::shared_ptr<AudioDecMock> audioDec_;
|
||||
std::shared_ptr<ACodecSignal> acodecSignal_;
|
||||
void InputFuncDec();
|
||||
@ -148,6 +150,6 @@ private:
|
||||
int64_t timeStampEnc_ = 0;
|
||||
std::string outPath_ = "/data/test/media/out.es";
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
#endif // ACODEC_MOCK_H
|
||||
|
@ -13,9 +13,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "avcodec_errors.h"
|
||||
#include "acodec_unit_test.h"
|
||||
#include "avcodec_errors.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS;
|
||||
@ -42,9 +42,9 @@ void ACodecUnitTest::SetUp(void)
|
||||
|
||||
defaultFormat_ = AVCodecMockFactory::CreateFormat();
|
||||
ASSERT_NE(nullptr, defaultFormat_);
|
||||
(void)defaultFormat_->PutIntValue("channel_count", 2);
|
||||
(void)defaultFormat_->PutIntValue("sample_rate", 44100);
|
||||
(void)defaultFormat_->PutLongValue("bitrate", 97496);
|
||||
(void)defaultFormat_->PutIntValue("channel_count", 2); // max channel count of avdec_mp3
|
||||
(void)defaultFormat_->PutIntValue("sample_rate", 44100); // one of sample_rate that meets avdec_mp3
|
||||
(void)defaultFormat_->PutLongValue("bitrate", 97496); // one of bitrate that meets avdec_mp3
|
||||
(void)defaultFormat_->PutIntValue("aac-type", 1);
|
||||
|
||||
testInfo_ = ::testing::UnitTest::GetInstance()->current_test_info();
|
||||
|
@ -16,9 +16,10 @@
|
||||
#ifndef AVCODEC_MOCK_H
|
||||
#define AVCODEC_MOCK_H
|
||||
|
||||
#include <string>
|
||||
#include "enum_mock.h"
|
||||
#include "nocopyable.h"
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
@ -231,10 +232,11 @@ public:
|
||||
static std::shared_ptr<AVCodecListMock> CreateAVCodecList();
|
||||
static std::shared_ptr<VideoCapsMock> CreateVideoCaps();
|
||||
static std::shared_ptr<EnumMock> CreateEnum();
|
||||
|
||||
private:
|
||||
AVCodecMockFactory() = delete;
|
||||
~AVCodecMockFactory() = delete;
|
||||
};
|
||||
} // Media
|
||||
} // OHOS
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
#endif // AVCODEC_MOCK_H
|
@ -17,9 +17,9 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
OHNativeWindow* SurfaceCapiMock::GetSurface()
|
||||
OHNativeWindow *SurfaceCapiMock::GetSurface()
|
||||
{
|
||||
return nativeWindow_;
|
||||
}
|
||||
} // Media
|
||||
} // OHOS
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
@ -17,21 +17,22 @@
|
||||
#define SURFACE_CAPI_MOCK_H
|
||||
|
||||
#include "avcodec_mock.h"
|
||||
#include "window.h"
|
||||
#include "native_avcodec_base.h"
|
||||
#include "window.h"
|
||||
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
class SurfaceCapiMock : public SurfaceMock {
|
||||
public:
|
||||
explicit SurfaceCapiMock(OHNativeWindow* nativeWindow) : nativeWindow_(nativeWindow) {}
|
||||
explicit SurfaceCapiMock(OHNativeWindow *nativeWindow) : nativeWindow_(nativeWindow) {}
|
||||
SurfaceCapiMock() = default;
|
||||
~SurfaceCapiMock() = default;
|
||||
OHNativeWindow* GetSurface();
|
||||
OHNativeWindow *GetSurface();
|
||||
|
||||
private:
|
||||
OHNativeWindow* nativeWindow_ = nullptr;
|
||||
OHNativeWindow *nativeWindow_ = nullptr;
|
||||
};
|
||||
} // Media
|
||||
} // OHOS
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
#endif // SURFACE_CAPI_MOCK_H
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (C) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -14,13 +14,14 @@
|
||||
*/
|
||||
|
||||
#include "videodec_capi_mock.h"
|
||||
#include <iostream>
|
||||
#include "avcodec_video_decoder.h"
|
||||
#include "avformat_capi_mock.h"
|
||||
#include "avmemory_capi_mock.h"
|
||||
#include "surface_capi_mock.h"
|
||||
#include "native_avcodec_base.h"
|
||||
#include "surface_capi_mock.h"
|
||||
#include "window.h"
|
||||
#include "avcodec_video_decoder.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace OHOS {
|
||||
@ -56,8 +57,8 @@ void VideoDecCapiMock::OnNeedInputData(OH_AVCodec *codec, uint32_t index, OH_AVM
|
||||
}
|
||||
}
|
||||
|
||||
void VideoDecCapiMock::OnNewOutputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data,
|
||||
OH_AVCodecBufferAttr *attr, void *userData)
|
||||
void VideoDecCapiMock::OnNewOutputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, OH_AVCodecBufferAttr *attr,
|
||||
void *userData)
|
||||
{
|
||||
(void)data;
|
||||
(void)userData;
|
||||
@ -113,7 +114,7 @@ int32_t VideoDecCapiMock::SetOutputSurface(std::shared_ptr<SurfaceMock> surface)
|
||||
{
|
||||
if (codec_ != nullptr && surface != nullptr) {
|
||||
auto surfaceMock = std::static_pointer_cast<SurfaceCapiMock>(surface);
|
||||
OHNativeWindow *nativeWindow = surfaceMock->GetSurface();
|
||||
OHNativeWindow *nativeWindow = surfaceMock->GetSurface();
|
||||
if (nativeWindow != nullptr) {
|
||||
return OH_VideoDecoder_SetSurface(codec_, nativeWindow);
|
||||
}
|
||||
@ -228,5 +229,5 @@ int32_t VideoDecCapiMock::FreeOutputData(uint32_t index)
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
@ -17,10 +17,11 @@
|
||||
#ifndef VIDEODEC_CAPI_MOCK_H
|
||||
#define VIDEODEC_CAPI_MOCK_H
|
||||
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
#include "avcodec_mock.h"
|
||||
#include "native_avcodec_videodecoder.h"
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
@ -47,8 +48,8 @@ private:
|
||||
static void OnError(OH_AVCodec *codec, int32_t errorCode, void *userData);
|
||||
static void OnStreamChanged(OH_AVCodec *codec, OH_AVFormat *format, void *userData);
|
||||
static void OnNeedInputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, void *userData);
|
||||
static void OnNewOutputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data,
|
||||
OH_AVCodecBufferAttr *attr, void *userData);
|
||||
static void OnNewOutputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, OH_AVCodecBufferAttr *attr,
|
||||
void *userData);
|
||||
static void SetCallback(OH_AVCodec *codec, std::shared_ptr<AVCodecCallbackMock> cb);
|
||||
static void DelCallback(OH_AVCodec *codec);
|
||||
static std::shared_ptr<AVCodecCallbackMock> GetCallback(OH_AVCodec *codec);
|
||||
|
@ -14,15 +14,14 @@
|
||||
*/
|
||||
|
||||
#include "videoenc_capi_mock.h"
|
||||
#include <iostream>
|
||||
#include "avcodec_errors.h"
|
||||
#include "avcodec_video_encoder.h"
|
||||
#include "avformat_capi_mock.h"
|
||||
#include "avmemory_capi_mock.h"
|
||||
#include "surface_capi_mock.h"
|
||||
#include "avcodec_errors.h"
|
||||
#include "native_avcodec_base.h"
|
||||
#include "surface_capi_mock.h"
|
||||
#include "window.h"
|
||||
#include "avcodec_video_encoder.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -58,8 +57,8 @@ void VideoEncCapiMock::OnNeedInputData(OH_AVCodec *codec, uint32_t index, OH_AVM
|
||||
}
|
||||
}
|
||||
|
||||
void VideoEncCapiMock::OnNewOutputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data,
|
||||
OH_AVCodecBufferAttr *attr, void *userData)
|
||||
void VideoEncCapiMock::OnNewOutputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, OH_AVCodecBufferAttr *attr,
|
||||
void *userData)
|
||||
{
|
||||
(void)data;
|
||||
(void)userData;
|
||||
@ -219,5 +218,5 @@ int32_t VideoEncCapiMock::FreeOutputData(uint32_t index)
|
||||
}
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
@ -16,11 +16,10 @@
|
||||
#ifndef VIDEOENC_CAPI_MOCK_H
|
||||
#define VIDEOENC_CAPI_MOCK_H
|
||||
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
#include "avcodec_mock.h"
|
||||
#include "native_avcodec_videoencoder.h"
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
@ -45,8 +44,8 @@ private:
|
||||
static void OnError(OH_AVCodec *codec, int32_t errorCode, void *userData);
|
||||
static void OnStreamChanged(OH_AVCodec *codec, OH_AVFormat *format, void *userData);
|
||||
static void OnNeedInputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, void *userData);
|
||||
static void OnNewOutputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data,
|
||||
OH_AVCodecBufferAttr *attr, void *userData);
|
||||
static void OnNewOutputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, OH_AVCodecBufferAttr *attr,
|
||||
void *userData);
|
||||
static void SetCallback(OH_AVCodec *codec, std::shared_ptr<AVCodecCallbackMock> cb);
|
||||
static void DelCallback(OH_AVCodec *codec);
|
||||
static std::shared_ptr<AVCodecCallbackMock> GetCallback(OH_AVCodec *codec);
|
||||
|
@ -13,12 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#include "format_unit_test.h"
|
||||
#include <cmath>
|
||||
#include "gtest/gtest.h"
|
||||
#include "avcodec_errors.h"
|
||||
#include "securec.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS;
|
||||
@ -26,17 +25,17 @@ using namespace OHOS::Media;
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::Media::FormatTestParam;
|
||||
|
||||
void FormatUnitTest::SetUpTestCase(void) {}
|
||||
void AVFormatUnitTest::SetUpTestCase(void) {}
|
||||
|
||||
void FormatUnitTest::TearDownTestCase(void) {}
|
||||
void AVFormatUnitTest::TearDownTestCase(void) {}
|
||||
|
||||
void FormatUnitTest::SetUp(void)
|
||||
void AVFormatUnitTest::SetUp(void)
|
||||
{
|
||||
format_ = AVCodecMockFactory::CreateFormat();
|
||||
ASSERT_NE(nullptr, format_);
|
||||
}
|
||||
|
||||
void FormatUnitTest::TearDown(void)
|
||||
void AVFormatUnitTest::TearDown(void)
|
||||
{
|
||||
if (format_ != nullptr) {
|
||||
format_->Destroy();
|
||||
@ -49,7 +48,7 @@ void FormatUnitTest::TearDown(void)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5OWXY issueI5OXCD
|
||||
*/
|
||||
HWTEST_F(FormatUnitTest, format_value_0100, TestSize.Level0)
|
||||
HWTEST_F(AVFormatUnitTest, format_value_0100, TestSize.Level0)
|
||||
{
|
||||
const std::string_view intKey = "IntKey";
|
||||
const std::string_view longKey = "LongKey";
|
||||
@ -67,7 +66,7 @@ HWTEST_F(FormatUnitTest, format_value_0100, TestSize.Level0)
|
||||
float getFloatValue = 0.0;
|
||||
double getDoubleValue = 0.0;
|
||||
std::string getStringValue = "";
|
||||
|
||||
|
||||
ASSERT_TRUE(format_->PutIntValue(intKey, intValue));
|
||||
ASSERT_TRUE(format_->GetIntValue(intKey, getIntValue));
|
||||
ASSERT_TRUE(intValue == getIntValue);
|
||||
@ -95,7 +94,7 @@ HWTEST_F(FormatUnitTest, format_value_0100, TestSize.Level0)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5OWXY issueI5OXCD
|
||||
*/
|
||||
HWTEST_F(FormatUnitTest, format_buffer_0100, TestSize.Level0)
|
||||
HWTEST_F(AVFormatUnitTest, format_buffer_0100, TestSize.Level0)
|
||||
{
|
||||
constexpr int32_t num = 10;
|
||||
const std::string_view key = "BufferKey";
|
||||
@ -120,7 +119,7 @@ HWTEST_F(FormatUnitTest, format_buffer_0100, TestSize.Level0)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5OWXY issueI5OXCD
|
||||
*/
|
||||
HWTEST_F(FormatUnitTest, format_dump_info_0100, TestSize.Level0)
|
||||
HWTEST_F(AVFormatUnitTest, format_dump_info_0100, TestSize.Level0)
|
||||
{
|
||||
ASSERT_TRUE(format_->PutIntValue("width", 1));
|
||||
ASSERT_TRUE(format_->PutIntValue("height", 1));
|
||||
|
@ -16,12 +16,13 @@
|
||||
#ifndef FORMAT_UNIT_TEST_H
|
||||
#define FORMAT_UNIT_TEST_H
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "avcodec_mock.h"
|
||||
#include "test_params_config.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
class FormatUnitTest : public testing::Test {
|
||||
class AVFormatUnitTest : public testing::Test {
|
||||
public:
|
||||
// SetUpTestCase: Called before all test cases
|
||||
static void SetUpTestCase(void);
|
||||
|
@ -20,9 +20,9 @@
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace {
|
||||
constexpr uint32_t DEFAULT_WIDTH = 480;
|
||||
constexpr uint32_t DEFAULT_HEIGHT = 360;
|
||||
}
|
||||
constexpr uint32_t DEFAULT_WIDTH = 480;
|
||||
constexpr uint32_t DEFAULT_HEIGHT = 360;
|
||||
} // namespace
|
||||
SurfaceNativeMock::~SurfaceNativeMock()
|
||||
{
|
||||
if (window_ != nullptr) {
|
||||
@ -34,7 +34,7 @@ sptr<Surface> SurfaceNativeMock::GetSurface()
|
||||
{
|
||||
if (surface_ == nullptr) {
|
||||
sptr<Rosen::WindowOption> option = new Rosen::WindowOption();
|
||||
option->SetWindowRect({ 0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT });
|
||||
option->SetWindowRect( {0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT} );
|
||||
option->SetWindowType(Rosen::WindowType::WINDOW_TYPE_APP_LAUNCHING);
|
||||
option->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING);
|
||||
window_ = Rosen::Window::Create("avcodec_unittest", option);
|
||||
@ -46,5 +46,5 @@ sptr<Surface> SurfaceNativeMock::GetSurface()
|
||||
}
|
||||
return surface_;
|
||||
}
|
||||
} // Media
|
||||
} // OHOS
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
@ -43,7 +43,8 @@ int32_t AVMuxerCapiMock::AddTrack(int32_t &trackIndex, std::shared_ptr<FormatMoc
|
||||
return OH_AVMuxer_AddTrack(muxer_, &trackIndex, formatMock->GetFormat());
|
||||
}
|
||||
|
||||
int32_t AVMuxerCapiMock::WriteSampleBuffer(uint32_t trackIndex, uint8_t *sampleBuffer, const AVCodecBufferAttrMock &info)
|
||||
int32_t AVMuxerCapiMock::WriteSampleBuffer(uint32_t trackIndex,
|
||||
uint8_t *sampleBuffer, const AVCodecBufferAttrMock &info)
|
||||
{
|
||||
OH_AVCodecBufferAttr bufferAttr;
|
||||
bufferAttr.pts = info.pts;
|
||||
|
@ -51,7 +51,8 @@ int32_t AVMuxerInnerMock::AddTrack(int32_t &trackIndex, std::shared_ptr<FormatMo
|
||||
return AV_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
int32_t AVMuxerInnerMock::WriteSampleBuffer(uint32_t trackIndex, uint8_t *sampleBuffer, const AVCodecBufferAttrMock &info)
|
||||
int32_t AVMuxerInnerMock::WriteSampleBuffer(uint32_t trackIndex,
|
||||
uint8_t *sampleBuffer, const AVCodecBufferAttrMock &info)
|
||||
{
|
||||
if (muxer_ != nullptr) {
|
||||
TrackSampleInfo sampleInfo;
|
||||
|
@ -34,8 +34,7 @@ std::string CodecListCapiMock::FindEncoder(std::shared_ptr<FormatMock> &format)
|
||||
|
||||
CapabilityData CodecListCapiMock::CreateCapability(const std::string codecName)
|
||||
{
|
||||
// TODO: 接口还在评审
|
||||
// return *OH_AVCodec_CreateCapability(codecName.c_str());
|
||||
// 接口还在评审: *OH_AVCodec_CreateCapability(codecName.c_str());
|
||||
CapabilityData capability;
|
||||
return capability;
|
||||
}
|
||||
|
@ -13,7 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "codeclist_mock.h"
|
||||
#include "codeclist_capi_mock.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -26,5 +25,5 @@ std::shared_ptr<CodecListMock> CodecListMockFactory::CreateCodecList()
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
@ -13,18 +13,18 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "codeclist_unit_test.h"
|
||||
#include <fcntl.h>
|
||||
#include <fstream>
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fcntl.h>
|
||||
#include "codeclist_unit_test.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::Media;
|
||||
|
||||
template<typename TCodecMock>
|
||||
template <typename TCodecMock>
|
||||
void ReleaseCodec(vector<TCodecMock> &codecLst)
|
||||
{
|
||||
uint32_t ret;
|
||||
@ -86,7 +86,7 @@ HWTEST_F(CodecListUnitTest, CodecList_FindVideoDecoder_002, TestSize.Level0)
|
||||
(void)format->PutIntValue(bitrateKey_, MAX_VIDEO_BITRATE);
|
||||
(void)format->PutIntValue(widthKey_, DEFAULT_WIDTH);
|
||||
(void)format->PutIntValue(heightKey_, DEFAULT_HEIGHT);
|
||||
(void)format->PutIntValue(pixelFormatKey_, VideoPixelFormat::SURFACE_FORMAT);// Negative parameters
|
||||
(void)format->PutIntValue(pixelFormatKey_, VideoPixelFormat::SURFACE_FORMAT); // Negative parameters
|
||||
(void)format->PutIntValue(frameRateKey_, MAX_FRAME_RATE);
|
||||
codecName = codeclist_->FindDecoder(format);
|
||||
EXPECT_EQ("", codecName);
|
||||
@ -107,7 +107,7 @@ HWTEST_F(CodecListUnitTest, CodecList_FindVideoDecoder_003, TestSize.Level0)
|
||||
(void)format->PutIntValue(bitrateKey_, MAX_VIDEO_BITRATE);
|
||||
(void)format->PutIntValue(widthKey_, 15361);
|
||||
(void)format->PutIntValue(heightKey_, DEFAULT_HEIGHT);
|
||||
(void)format->PutIntValue(pixelFormatKey_, VideoPixelFormat::SURFACE_FORMAT);// Negative parameters
|
||||
(void)format->PutIntValue(pixelFormatKey_, VideoPixelFormat::SURFACE_FORMAT); // Negative parameters
|
||||
(void)format->PutIntValue(frameRateKey_, MAX_FRAME_RATE);
|
||||
codecName = codeclist_->FindDecoder(format);
|
||||
EXPECT_EQ("", codecName);
|
||||
@ -128,33 +128,12 @@ HWTEST_F(CodecListUnitTest, CodecList_FindVideoDecoder_004, TestSize.Level0)
|
||||
(void)format->PutIntValue(bitrateKey_, MAX_VIDEO_BITRATE);
|
||||
(void)format->PutIntValue(widthKey_, DEFAULT_WIDTH);
|
||||
(void)format->PutIntValue(heightKey_, 31);
|
||||
(void)format->PutIntValue(pixelFormatKey_, VideoPixelFormat::SURFACE_FORMAT);// Negative parameters
|
||||
(void)format->PutIntValue(pixelFormatKey_, VideoPixelFormat::SURFACE_FORMAT); // Negative parameters
|
||||
(void)format->PutIntValue(frameRateKey_, MAX_FRAME_RATE);
|
||||
codecName = codeclist_->FindDecoder(format);
|
||||
EXPECT_EQ("", codecName);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @tc.name: CodecList_FindVideoEncoder_001
|
||||
// * @tc.desc: CodecList FindVideoEncoder
|
||||
// * @tc.type: FUNC
|
||||
// * @tc.require:
|
||||
// */
|
||||
// HWTEST_F(CodecListUnitTest, CodecList_FindVideoEncoder_001, TestSize.Level0)
|
||||
// {
|
||||
// std::string codecName;
|
||||
// std::shared_ptr<FormatMock> format = FormatMockFactory::CreateFormat();
|
||||
// ASSERT_NE(nullptr, format);
|
||||
// (void)format->PutStringValue(codecMimeKey_, CodecMimeType::VIDEO_MPEG4);
|
||||
// (void)format->PutIntValue(bitrateKey_, MAX_VIDEO_BITRATE);
|
||||
// (void)format->PutIntValue(widthKey_, DEFAULT_WIDTH);
|
||||
// (void)format->PutIntValue(heightKey_, DEFAULT_HEIGHT);
|
||||
// (void)format->PutIntValue(pixelFormatKey_, VideoPixelFormat::NV21);
|
||||
// (void)format->PutIntValue(frameRateKey_, MAX_FRAME_RATE);
|
||||
// codecName = codeclist_->FindEncoder(format);
|
||||
// EXPECT_EQ("video/mp4v-es", codecName);
|
||||
// }
|
||||
|
||||
/**
|
||||
* @tc.name: CodecList_FindAudioDecoder_001
|
||||
* @tc.desc: CodecList FindAudioDecoder
|
||||
@ -257,7 +236,7 @@ HWTEST_F(CodecListUnitTest, CodecList_FindAudioDecoder_006, TestSize.Level0)
|
||||
std::shared_ptr<FormatMock> format = FormatMockFactory::CreateFormat();
|
||||
(void)format->PutStringValue(codecMimeKey_, CodecMimeType::AUDIO_OPUS);
|
||||
(void)format->PutIntValue(bitrateKey_, MAX_AUDIO_BITRATE);
|
||||
(void)format->PutIntValue(channelCountKey_, MAX_CHANNEL_COUNT + 1);// Negative parameters
|
||||
(void)format->PutIntValue(channelCountKey_, MAX_CHANNEL_COUNT + 1); // Negative parameters
|
||||
(void)format->PutIntValue(sampleRateKey_, DEFAULT_SAMPLE_RATE);
|
||||
codecName = codeclist_->FindDecoder(format);
|
||||
EXPECT_EQ("", codecName);
|
||||
@ -312,7 +291,7 @@ HWTEST_F(CodecListUnitTest, CodecList_FindAudioEncoder_003, TestSize.Level0)
|
||||
(void)format->PutStringValue(codecMimeKey_, CodecMimeType::AUDIO_OPUS);
|
||||
(void)format->PutIntValue(bitrateKey_, MAX_AUDIO_BITRATE);
|
||||
(void)format->PutIntValue(channelCountKey_, MAX_CHANNEL_COUNT);
|
||||
(void)format->PutIntValue(sampleRateKey_, DEFAULT_SAMPLE_RATE);// Negative parameters
|
||||
(void)format->PutIntValue(sampleRateKey_, DEFAULT_SAMPLE_RATE); // Negative parameters
|
||||
codecName = codeclist_->FindEncoder(format);
|
||||
EXPECT_EQ("", codecName);
|
||||
}
|
||||
|
@ -16,11 +16,11 @@
|
||||
#ifndef CODECLIST_UNIT_TEST_H
|
||||
#define CODECLIST_UNIT_TEST_H
|
||||
|
||||
#include <vector>
|
||||
#include "gtest/gtest.h"
|
||||
#include "avcodec_info.h"
|
||||
#include "media_description.h"
|
||||
#include "codeclist_mock.h"
|
||||
#include "media_description.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
@ -48,34 +48,17 @@ public:
|
||||
void TearDown(void);
|
||||
|
||||
protected:
|
||||
std::string codecMimeKey_ {MediaDescriptionKey::MD_KEY_CODEC_MIME};
|
||||
std::string bitrateKey_ {MediaDescriptionKey::MD_KEY_BITRATE};
|
||||
std::string widthKey_ {MediaDescriptionKey::MD_KEY_WIDTH};
|
||||
std::string heightKey_ {MediaDescriptionKey::MD_KEY_HEIGHT};
|
||||
std::string pixelFormatKey_ {MediaDescriptionKey::MD_KEY_PIXEL_FORMAT};
|
||||
std::string frameRateKey_ {MediaDescriptionKey::MD_KEY_FRAME_RATE};
|
||||
std::string channelCountKey_ {MediaDescriptionKey::MD_KEY_CHANNEL_COUNT};
|
||||
std::string sampleRateKey_ {"samplerate"};//{MediaDescriptionKey::MD_KEY_SAMPLE_RATE};
|
||||
std::string bitDepthKey_ {MediaDescriptionKey::MD_KEY_SAMPLE_RATE};
|
||||
std::string codecMimeKey_{MediaDescriptionKey::MD_KEY_CODEC_MIME};
|
||||
std::string bitrateKey_{MediaDescriptionKey::MD_KEY_BITRATE};
|
||||
std::string widthKey_{MediaDescriptionKey::MD_KEY_WIDTH};
|
||||
std::string heightKey_{MediaDescriptionKey::MD_KEY_HEIGHT};
|
||||
std::string pixelFormatKey_{MediaDescriptionKey::MD_KEY_PIXEL_FORMAT};
|
||||
std::string frameRateKey_{MediaDescriptionKey::MD_KEY_FRAME_RATE};
|
||||
std::string channelCountKey_{MediaDescriptionKey::MD_KEY_CHANNEL_COUNT};
|
||||
std::string sampleRateKey_{"samplerate"}; //{MediaDescriptionKey::MD_KEY_SAMPLE_RATE};
|
||||
std::string bitDepthKey_{MediaDescriptionKey::MD_KEY_SAMPLE_RATE};
|
||||
|
||||
std::shared_ptr<CodecListMock> codeclist_ {nullptr};
|
||||
|
||||
// void CheckAVDecH264(const std::shared_ptr<VideoCaps> &videoCaps) const;
|
||||
// void CheckAVDecH263(const std::shared_ptr<VideoCaps> &videoCaps) const;
|
||||
// void CheckAVDecMpeg2Video(const std::shared_ptr<VideoCaps> &videoCaps) const;
|
||||
// void CheckAVDecMpeg4(const std::shared_ptr<VideoCaps> &videoCaps) const;
|
||||
// void CheckAVEncMpeg4(const std::shared_ptr<VideoCaps> &videoCaps) const;
|
||||
// void CheckVideoCaps(const std::shared_ptr<VideoCaps> &videoCaps) const;
|
||||
// void CheckVideoCapsArray(const std::vector<std::shared_ptr<VideoCaps>> &videoCapsArray) const;
|
||||
// void CheckAVDecMP3(const std::shared_ptr<AudioCaps> &audioCaps) const;
|
||||
// void CheckAVDecAAC(const std::shared_ptr<AudioCaps> &audioCaps) const;
|
||||
// void CheckAVDecVorbis(const std::shared_ptr<AudioCaps> &audioCaps) const;
|
||||
// void CheckAVDecFlac(const std::shared_ptr<AudioCaps> &audioCaps) const;
|
||||
// void CheckAVDecOpus(const std::shared_ptr<AudioCaps> &audioCaps) const;
|
||||
// void CheckAVEncAAC(const std::shared_ptr<AudioCaps> &audioCaps) const;
|
||||
// void CheckAVEncOpus(const std::shared_ptr<AudioCaps> &audioCaps) const;
|
||||
// void CheckAudioCaps(const std::shared_ptr<AudioCaps> &audioCaps) const;
|
||||
// void CheckAudioCapsArray(const std::vector<std::shared_ptr<AudioCaps>> &audioCapsArray) const;
|
||||
std::shared_ptr<CodecListMock> codeclist_{nullptr};
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
@ -13,7 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "codeclist_mock.h"
|
||||
#include "codeclist_inner_mock.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -26,5 +25,5 @@ std::shared_ptr<CodecListMock> CodecListMockFactory::CreateCodecList()
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
@ -1,85 +1,85 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/test.gni")
|
||||
import("//foundation/multimedia/av_codec/config.gni")
|
||||
|
||||
module_output_path = "av_codec"
|
||||
|
||||
avcodec_unittest_cflags = [
|
||||
"-std=c++17",
|
||||
"-frtti",
|
||||
"-fexceptions",
|
||||
"-Wall",
|
||||
"-fno-common",
|
||||
"-fstack-protector-strong",
|
||||
"-Wshadow",
|
||||
"-FPIC",
|
||||
"-FS",
|
||||
"-O2",
|
||||
"-D_FORTIFY_SOURCE=2",
|
||||
"-fvisibility=hidden",
|
||||
"-Wformat=2",
|
||||
"-Wdate-time",
|
||||
"-Werror",
|
||||
"-Wextra",
|
||||
"-Wimplicit-fallthrough",
|
||||
"-Wsign-compare",
|
||||
"-Wunused-parameter",
|
||||
]
|
||||
|
||||
##################################################################################################################
|
||||
ohos_unittest("avformat_capi_unit_test") {
|
||||
module_out_path = module_output_path
|
||||
include_dirs = [
|
||||
"./",
|
||||
"./capi",
|
||||
"$av_codec_root_dir/interfaces/inner_api/native",
|
||||
"$av_codec_root_dir/interfaces/kits/c",
|
||||
]
|
||||
|
||||
cflags = avcodec_unittest_cflags
|
||||
|
||||
if (multimedia_av_codec_support_codec) {
|
||||
sources = [
|
||||
"./avformat_unit_test.cpp",
|
||||
"./capi/avformat_capi_mock.cpp",
|
||||
"./capi/avformat_capi_mock_factory.cpp",
|
||||
]
|
||||
}
|
||||
|
||||
deps = [ "$av_codec_root_dir/interfaces/kits/c:capi_packages" ]
|
||||
public_deps = [ "$av_codec_root_dir/services/utils:av_codec_format" ]
|
||||
resource_config_file =
|
||||
"$av_codec_root_dir/test/unittest/resources/ohos_test.xml"
|
||||
}
|
||||
|
||||
##################################################################################################################
|
||||
ohos_unittest("avformat_inner_unit_test") {
|
||||
module_out_path = module_output_path
|
||||
include_dirs = [
|
||||
"./",
|
||||
"./inner",
|
||||
"$av_codec_root_dir/interfaces/inner_api/native",
|
||||
"$av_codec_root_dir/interfaces/kits/c",
|
||||
]
|
||||
cflags = avcodec_unittest_cflags
|
||||
sources = [
|
||||
"./avformat_unit_test.cpp",
|
||||
"./inner/avformat_inner_mock.cpp",
|
||||
"./inner/avformat_inner_mock_factory.cpp",
|
||||
]
|
||||
public_deps = [ "$av_codec_root_dir/services/utils:av_codec_format" ]
|
||||
resource_config_file =
|
||||
"$av_codec_root_dir/test/unittest/resources/ohos_test.xml"
|
||||
}
|
||||
|
||||
import("//build/test.gni")
|
||||
import("//foundation/multimedia/av_codec/config.gni")
|
||||
|
||||
module_output_path = "av_codec"
|
||||
|
||||
avcodec_unittest_cflags = [
|
||||
"-std=c++17",
|
||||
"-frtti",
|
||||
"-fexceptions",
|
||||
"-Wall",
|
||||
"-fno-common",
|
||||
"-fstack-protector-strong",
|
||||
"-Wshadow",
|
||||
"-FPIC",
|
||||
"-FS",
|
||||
"-O2",
|
||||
"-D_FORTIFY_SOURCE=2",
|
||||
"-fvisibility=hidden",
|
||||
"-Wformat=2",
|
||||
"-Wdate-time",
|
||||
"-Werror",
|
||||
"-Wextra",
|
||||
"-Wimplicit-fallthrough",
|
||||
"-Wsign-compare",
|
||||
"-Wunused-parameter",
|
||||
]
|
||||
|
||||
##################################################################################################################
|
||||
ohos_unittest("avformat_capi_unit_test") {
|
||||
module_out_path = module_output_path
|
||||
include_dirs = [
|
||||
"./",
|
||||
"./capi",
|
||||
"$av_codec_root_dir/interfaces/inner_api/native",
|
||||
"$av_codec_root_dir/interfaces/kits/c",
|
||||
]
|
||||
|
||||
cflags = avcodec_unittest_cflags
|
||||
|
||||
if (multimedia_av_codec_support_codec) {
|
||||
sources = [
|
||||
"./avformat_unit_test.cpp",
|
||||
"./capi/avformat_capi_mock.cpp",
|
||||
"./capi/avformat_capi_mock_factory.cpp",
|
||||
]
|
||||
}
|
||||
|
||||
deps = [ "$av_codec_root_dir/interfaces/kits/c:capi_packages" ]
|
||||
public_deps = [ "$av_codec_root_dir/services/utils:av_codec_format" ]
|
||||
resource_config_file =
|
||||
"$av_codec_root_dir/test/unittest/resources/ohos_test.xml"
|
||||
}
|
||||
|
||||
##################################################################################################################
|
||||
ohos_unittest("avformat_inner_unit_test") {
|
||||
module_out_path = module_output_path
|
||||
include_dirs = [
|
||||
"./",
|
||||
"./inner",
|
||||
"$av_codec_root_dir/interfaces/inner_api/native",
|
||||
"$av_codec_root_dir/interfaces/kits/c",
|
||||
]
|
||||
cflags = avcodec_unittest_cflags
|
||||
sources = [
|
||||
"./avformat_unit_test.cpp",
|
||||
"./inner/avformat_inner_mock.cpp",
|
||||
"./inner/avformat_inner_mock_factory.cpp",
|
||||
]
|
||||
public_deps = [ "$av_codec_root_dir/services/utils:av_codec_format" ]
|
||||
resource_config_file =
|
||||
"$av_codec_root_dir/test/unittest/resources/ohos_test.xml"
|
||||
}
|
||||
|
@ -13,33 +13,32 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#include "avformat_unit_test.h"
|
||||
#include <cmath>
|
||||
#include "gtest/gtest.h"
|
||||
#include "avcodec_errors.h"
|
||||
#include "securec.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::Media;
|
||||
using namespace testing::ext;
|
||||
namespace {
|
||||
constexpr float EPSINON_FLOAT = 0.0001;
|
||||
constexpr double EPSINON_DOUBLE = 0.0001;
|
||||
} // namespace FormatTestParam
|
||||
constexpr float EPSINON_FLOAT = 0.0001;
|
||||
constexpr double EPSINON_DOUBLE = 0.0001;
|
||||
} // namespace
|
||||
|
||||
void FormatUnitTest::SetUpTestCase(void) {}
|
||||
void AVFormatUnitTest::SetUpTestCase(void) {}
|
||||
|
||||
void FormatUnitTest::TearDownTestCase(void) {}
|
||||
void AVFormatUnitTest::TearDownTestCase(void) {}
|
||||
|
||||
void FormatUnitTest::SetUp(void)
|
||||
void AVFormatUnitTest::SetUp(void)
|
||||
{
|
||||
format_ = FormatMockFactory::CreateFormat();
|
||||
ASSERT_NE(nullptr, format_);
|
||||
}
|
||||
|
||||
void FormatUnitTest::TearDown(void)
|
||||
void AVFormatUnitTest::TearDown(void)
|
||||
{
|
||||
if (format_ != nullptr) {
|
||||
format_->Destroy();
|
||||
@ -52,7 +51,7 @@ void FormatUnitTest::TearDown(void)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5OX06 issueI5P8N0
|
||||
*/
|
||||
HWTEST_F(FormatUnitTest, Format_Value_001, TestSize.Level0)
|
||||
HWTEST_F(AVFormatUnitTest, Format_Value_001, TestSize.Level0)
|
||||
{
|
||||
const std::string_view intKey = "IntKey";
|
||||
const std::string_view longKey = "LongKey";
|
||||
@ -71,7 +70,7 @@ HWTEST_F(FormatUnitTest, Format_Value_001, TestSize.Level0)
|
||||
float getFloatValue = 0.0;
|
||||
double getDoubleValue = 0.0;
|
||||
std::string getStringValue = "";
|
||||
|
||||
|
||||
EXPECT_TRUE(format_->PutIntValue(intKey, intValue));
|
||||
EXPECT_TRUE(format_->GetIntValue(intKey, getIntValue));
|
||||
EXPECT_TRUE(intValue == getIntValue);
|
||||
@ -103,7 +102,7 @@ HWTEST_F(FormatUnitTest, Format_Value_001, TestSize.Level0)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5OWXY issueI5OXCD
|
||||
*/
|
||||
HWTEST_F(FormatUnitTest, Format_Buffer_001, TestSize.Level0)
|
||||
HWTEST_F(AVFormatUnitTest, Format_Buffer_001, TestSize.Level0)
|
||||
{
|
||||
constexpr size_t size = 3;
|
||||
const std::string_view key = "BufferKey";
|
||||
|
@ -16,11 +16,12 @@
|
||||
#ifndef FORMAT_UNIT_TEST_H
|
||||
#define FORMAT_UNIT_TEST_H
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "avformat_mock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
class FormatUnitTest : public testing::Test {
|
||||
class AVFormatUnitTest : public testing::Test {
|
||||
public:
|
||||
// SetUpTestCase: Called before all test cases
|
||||
static void SetUpTestCase(void);
|
||||
|
@ -13,7 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "avformat_mock.h"
|
||||
#include "avformat_capi_mock.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -22,5 +21,5 @@ std::shared_ptr<FormatMock> FormatMockFactory::CreateFormat()
|
||||
{
|
||||
return std::make_shared<AVFormatCapiMock>();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
@ -13,7 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "avformat_mock.h"
|
||||
#include "avformat_inner_mock.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -22,5 +21,5 @@ std::shared_ptr<FormatMock> FormatMockFactory::CreateFormat()
|
||||
{
|
||||
return std::make_shared<AVFormatInnerMock>();
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
Loading…
Reference in New Issue
Block a user