mirror of
https://gitee.com/openharmony/multimedia_av_codec
synced 2024-12-11 17:16:02 +00:00
Merge branch 'dev_av_muxer' of gitee.com:zjskpajs/av_codec into dev_av_muxer
This commit is contained in:
commit
915a99ca8a
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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
|
||||
@ -29,12 +29,8 @@ std::shared_ptr<AVCodec> CodecFactory::CreateByMime(const std::string &mime, boo
|
||||
std::shared_ptr<AVCodecImpl> impl = std::make_shared<AVCodecImpl>();
|
||||
CHECK_AND_RETURN_RET_LOG(impl != nullptr, nullptr, "failed to new AVCodecImpl");
|
||||
|
||||
int32_t ret;
|
||||
if (encoder) {
|
||||
ret = impl->Init(AVCODEC_TYPE_ENCODER, true, mime);
|
||||
} else {
|
||||
ret = impl->Init(AVCODEC_TYPE_DECODER, true, mime);
|
||||
}
|
||||
AVCodecType codeType = encoder ? AVCODEC_TYPE_ENCODER : AVCODEC_TYPE_DECODER;
|
||||
int32_t ret = impl->Init(codeType, true, mime);;
|
||||
CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, nullptr, "failed to init AVCodecImpl");
|
||||
|
||||
return impl;
|
||||
@ -115,7 +111,7 @@ int32_t AVCodecImpl::SetOutputSurface(sptr<Surface> surface)
|
||||
return codecService_->SetOutputSurface(surface);
|
||||
}
|
||||
|
||||
std::shared_ptr<AVSharedMemory> AVCodecImpl::GetInputBuffer(uint32_t index)
|
||||
std::shared_ptr<AVBufferElement> AVCodecImpl::GetInputBuffer(uint32_t index)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr, nullptr, "service died");
|
||||
return codecService_->GetInputBuffer(index);
|
||||
@ -127,7 +123,7 @@ int32_t AVCodecImpl::QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AV
|
||||
return codecService_->QueueInputBuffer(index, info, flag);
|
||||
}
|
||||
|
||||
std::shared_ptr<AVSharedMemory> AVCodecImpl::GetOutputBuffer(uint32_t index)
|
||||
std::shared_ptr<AVBufferElement> AVCodecImpl::GetOutputBuffer(uint32_t index)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr, nullptr, "service died");
|
||||
return codecService_->GetOutputBuffer(index);
|
||||
@ -158,7 +154,7 @@ int32_t AVCodecImpl::SetCallback(const std::shared_ptr<AVCodecCallback> &callbac
|
||||
return codecService_->SetCallback(callback);
|
||||
}
|
||||
|
||||
sptr<Surface> AVCodecVideoEncoderImpl::CreateInputSurface()
|
||||
sptr<Surface> AVCodecImpl::CreateInputSurface()
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr, nullptr, "service died");
|
||||
surface_ = codecService_->CreateInputSurface();
|
||||
@ -183,5 +179,6 @@ int32_t AVCodecImpl::DequeueOutputBuffer(size_t *index, int64_t timetUs)
|
||||
return codecService_->DequeueOutputBuffer(surface);
|
||||
}
|
||||
|
||||
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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
|
||||
@ -35,9 +35,9 @@ public:
|
||||
int32_t NotifyEos() override;
|
||||
sptr<Surface> CreateInputSurface() override;
|
||||
int32_t SetOutputSurface(sptr<Surface> surface) override;
|
||||
std::shared_ptr<AVSharedMemory> GetInputBuffer(uint32_t index) override;
|
||||
std::shared_ptr<AVBufferElement> GetInputBuffer(uint32_t index) override;
|
||||
int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) override;
|
||||
std::shared_ptr<AVSharedMemory> GetOutputBuffer(uint32_t index) override;
|
||||
std::shared_ptr<AVBufferElement> GetOutputBuffer(uint32_t index) override;
|
||||
int32_t GetOutputFormat(Format &format) override;
|
||||
int32_t ReleaseOutputBuffer(uint32_t index, bool render) override;
|
||||
int32_t SetParameter(const Format &format) override;
|
||||
|
@ -70,7 +70,7 @@ int32_t AVDemuxerImpl::RemoveSourceTrackByID(uint32_t index)
|
||||
return demuxerService_->RemoveSourceTrackByID(index);
|
||||
}
|
||||
|
||||
int32_t AVDemuxerImpl::CopyCurrentSampleToBuf(AVCodecBufferElement *buffer, AVCodecBufferInfo *bufferInfo)
|
||||
int32_t AVDemuxerImpl::CopyCurrentSampleToBuf(AVBufferElement *buffer, AVCodecBufferInfo *bufferInfo)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(demuxerService_ != nullptr, MSERR_INVALID_OPERATION, "avdemuxer service died!");
|
||||
return demuxerService_->CopyCurrentSampleToBuf(buffer, bufferInfo);
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
|
||||
int32_t AddSourceTrackByID(uint32_t index) override;
|
||||
int32_t RemoveSourceTrackByID(uint32_t index) override;
|
||||
int32_t CopyCurrentSampleToBuf(AVCodecBufferElement *buffer, AVCodecBufferInfo *bufferInfo) override;
|
||||
int32_t CopyCurrentSampleToBuf(AVBufferElement *buffer, AVCodecBufferInfo *bufferInfo) override;
|
||||
int32_t SeekToTimeStamp(int64_t mSeconds, const SeekMode mode) override;
|
||||
int32_t Init(Source *source);
|
||||
|
||||
|
@ -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
|
||||
@ -36,7 +36,7 @@ struct CodecObject : public OH_AVCodec {
|
||||
~CodecObject() = default;
|
||||
|
||||
const std::shared_ptr<AVCodec> codec_;
|
||||
std::list<OHOS::sptr<OH_AVMemory>> memoryObjList_;
|
||||
std::list<OHOS::sptr<OH_AVBufferElement>> memoryObjList_;
|
||||
std::shared_ptr<NativeCodecCallback> callback_ = nullptr;
|
||||
std::atomic<bool> isFlushing_ = false;
|
||||
std::atomic<bool> isStop_ = false;
|
||||
@ -80,7 +80,7 @@ public:
|
||||
MEDIA_LOGD("At flush, eos or stop, no buffer available");
|
||||
return;
|
||||
}
|
||||
OH_AVMemory *data = GetInputData(codec_, index);
|
||||
OH_AVBufferElement *data = GetInputData(codec_, index);
|
||||
if (data != nullptr) {
|
||||
callback_.onInputDataReady(codec_, index, data, userData_);
|
||||
}
|
||||
@ -115,50 +115,50 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
OH_AVMemory *GetInputData(struct OH_AVCodec *codec, uint32_t index)
|
||||
OH_AVBufferElement *GetInputData(struct OH_AVCodec *codec, uint32_t index)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, nullptr, "input codec is nullptr!");
|
||||
|
||||
struct CodecObject *codecObj = reinterpret_cast<CodecObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(codecObj->codec_ != nullptr, nullptr, "codec_ is nullptr!");
|
||||
|
||||
std::shared_ptr<AVSharedMemory> memory = codecObj->codec_->GetInputBuffer(index);
|
||||
CHECK_AND_RETURN_RET_LOG(memory != nullptr, nullptr, "get input buffer is nullptr!");
|
||||
std::shared_ptr<AVBufferElement> bufferElement = codecObj->codec_->GetInputBuffer(index);
|
||||
CHECK_AND_RETURN_RET_LOG(bufferElement != nullptr, nullptr, "get input buffer is nullptr!");
|
||||
|
||||
for (auto &memoryObj : codecObj->memoryObjList_) {
|
||||
if (memoryObj->IsEqualMemory(memory)) {
|
||||
return reinterpret_cast<OH_AVMemory *>(memoryObj.GetRefPtr());
|
||||
if (memoryObj->IsEqualBufferElement(bufferElement)) {
|
||||
return reinterpret_cast<OH_AVBufferElement *>(memoryObj);
|
||||
}
|
||||
}
|
||||
|
||||
OHOS::sptr<OH_AVMemory> object = new(std::nothrow) OH_AVMemory(memory);
|
||||
CHECK_AND_RETURN_RET_LOG(object != nullptr, nullptr, "failed to new OH_AVMemory");
|
||||
OHOS::sptr<OH_AVBufferElement> object = new(std::nothrow) OH_AVBufferElement(bufferElement);
|
||||
CHECK_AND_RETURN_RET_LOG(object != nullptr, nullptr, "failed to new OH_AVBufferElement");
|
||||
|
||||
codecObj->memoryObjList_.push_back(object);
|
||||
return reinterpret_cast<OH_AVMemory *>(object.GetRefPtr());
|
||||
return reinterpret_cast<OH_AVBufferElement *>(object);
|
||||
}
|
||||
|
||||
OH_AVMemory *GetOutputData(struct OH_AVCodec *codec, uint32_t index)
|
||||
OH_AVBufferElement *GetOutputData(struct OH_AVCodec *codec, uint32_t index)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, nullptr, "input codec is nullptr!");
|
||||
|
||||
struct CodecObject *codecObj = reinterpret_cast<CodecObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(codecObj->codec_ != nullptr, nullptr, "codec_ is nullptr!");
|
||||
|
||||
std::shared_ptr<AVSharedMemory> memory = codecObj->codec_->GetOutputBuffer(index);
|
||||
CHECK_AND_RETURN_RET_LOG(memory != nullptr, nullptr, "get output buffer is nullptr!");
|
||||
std::shared_ptr<AVBufferElement> bufferElement = codecObj->codec_->GetOutputBuffer(index);
|
||||
CHECK_AND_RETURN_RET_LOG(bufferElement != nullptr, nullptr, "get output buffer is nullptr!");
|
||||
|
||||
for (auto &memoryObj : codecObj->memoryObjList_) {
|
||||
if (memoryObj->IsEqualMemory(memory)) {
|
||||
return reinterpret_cast<OH_AVMemory *>(memoryObj.GetRefPtr());
|
||||
if (memoryObj->IsEqualBufferElement(bufferElement)) {
|
||||
return reinterpret_cast<OH_AVBufferElement *>(memoryObj);
|
||||
}
|
||||
}
|
||||
|
||||
OHOS::sptr<OH_AVMemory> object = new(std::nothrow) OH_AVMemory(memory);
|
||||
CHECK_AND_RETURN_RET_LOG(object != nullptr, nullptr, "failed to new OH_AVMemory");
|
||||
OHOS::sptr<OH_AVBufferElement> object = new(std::nothrow) OH_AVBufferElement(bufferElement);
|
||||
CHECK_AND_RETURN_RET_LOG(object != nullptr, nullptr, "failed to new OH_AVBufferElement");
|
||||
|
||||
codecObj->memoryObjList_.push_back(object);
|
||||
return reinterpret_cast<OH_AVMemory *>(object.GetRefPtr());
|
||||
return reinterpret_cast<OH_AVBufferElement *>(object);
|
||||
}
|
||||
|
||||
struct OH_AVCodec *codec_;
|
||||
@ -442,14 +442,10 @@ OH_AVBufferElement* OH_AVCodec_GetInputBuffer(OH_AVCodec *codec, size_t index)
|
||||
struct CodecObject *codecObj = reinterpret_cast<CodecObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(codecObj->codec_ != nullptr, AV_ERR_INVALID_VAL, "codec_ is nullptr!");
|
||||
|
||||
std::shared_ptr<AVSharedMemory> memory = codecObj->codec_->GetInputBuffer(index);
|
||||
CHECK_AND_RETURN_RET_LOG(memory != nullptr, nullptr, "get input buffer is nullptr!");
|
||||
std::shared_ptr<AVBufferElement> bufferElement = codecObj->codec_->GetInputBuffer(index);
|
||||
CHECK_AND_RETURN_RET_LOG(bufferElement != nullptr, nullptr, "get input buffer is nullptr!")
|
||||
|
||||
OH_AVBufferElement bufferElement;
|
||||
bufferElement.buffer = memory.GetBase();
|
||||
bufferElement.size = memory.GetSize();
|
||||
|
||||
return &bufferElement;
|
||||
return bufferElement
|
||||
}
|
||||
|
||||
OH_AVBufferElement* OH_AVCodec_GetOutputBuffer(OH_AVCodec *codec, size_t index)
|
||||
@ -459,14 +455,10 @@ OH_AVBufferElement* OH_AVCodec_GetOutputBuffer(OH_AVCodec *codec, size_t index)
|
||||
struct CodecObject *codecObj = reinterpret_cast<CodecObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(codecObj->codec_ != nullptr, AV_ERR_INVALID_VAL, "codec_ is nullptr!");
|
||||
|
||||
std::shared_ptr<AVSharedMemory> memory = codecObj->codec_->GetOutputBuffer(index);
|
||||
CHECK_AND_RETURN_RET_LOG(memory != nullptr, nullptr, "get input buffer is nullptr!");
|
||||
std::shared_ptr<AVBufferElement> bufferElement = codecObj->codec_->GetOutputBuffer(index);
|
||||
CHECK_AND_RETURN_RET_LOG(bufferElement != nullptr, nullptr, "get input buffer is nullptr!");
|
||||
|
||||
OH_AVBufferElement bufferElement;
|
||||
bufferElement.buffer = memory.GetBase();
|
||||
bufferElement.size = memory.GetSize();
|
||||
|
||||
return &bufferElement;
|
||||
return bufferElement;
|
||||
}
|
||||
|
||||
int32_t OH_AVCodec_DequeueInputBuffer(OH_AVCodec *codec, int64_t timeoutUs)
|
||||
|
@ -24,7 +24,6 @@ namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "NativeAVDemuxer"}
|
||||
}
|
||||
|
||||
using namespase OHOS::Media;
|
||||
using namespase OHOS::AVCodec;
|
||||
|
||||
struct DemuxerObject : public OH_AVDemuxer {
|
||||
|
@ -36,20 +36,27 @@ struct AVObjectMagic : public OHOS::RefBase {
|
||||
|
||||
struct OH_AVFormat : public OHOS::RefBase {
|
||||
OH_AVFormat();
|
||||
explicit OH_AVFormat(const OHOS::Media::Format &fmt);
|
||||
explicit OH_AVFormat(const OHOS::AVCodec::Format &fmt);
|
||||
~OH_AVFormat() override;
|
||||
OHOS::Media::Format format_;
|
||||
OHOS::AVCodec::Format format_;
|
||||
char *outString_ = nullptr;
|
||||
char *dumpInfo_ = nullptr;
|
||||
};
|
||||
|
||||
struct OH_AVMemory : public OHOS::RefBase {
|
||||
explicit OH_AVMemory(const std::shared_ptr<OHOS::Media::AVSharedMemory> &mem);
|
||||
explicit OH_AVMemory(const std::shared_ptr<OHOS::AVCodec::AVSharedMemory> &mem);
|
||||
~OH_AVMemory() override;
|
||||
bool IsEqualMemory(const std::shared_ptr<OHOS::Media::AVSharedMemory> &mem);
|
||||
const std::shared_ptr<OHOS::Media::AVSharedMemory> memory_;
|
||||
bool IsEqualMemory(const std::shared_ptr<OHOS::AVCodec::AVSharedMemory> &mem);
|
||||
const std::shared_ptr<OHOS::AVCodec::AVSharedMemory> memory_;
|
||||
};
|
||||
|
||||
struct OH_AVBufferElement : public OHOS::RefBase {
|
||||
explicit OH_AVBufferElement(const std::shared_ptr<OHOS::AVCodec::AVBufferElement> &bufferElement);
|
||||
~OH_AVBufferElement() override;
|
||||
bool IsEqualBufferElement(const std::shared_ptr<OHOS::AVCodec::AVBufferElement> &bufferElement);
|
||||
const std::shared_ptr<OHOS::AVCodec::AVBufferElement> bufferElement_;
|
||||
}
|
||||
|
||||
struct OH_AVCodec : public OHOS::RefBase {
|
||||
explicit OH_AVCodec();
|
||||
virtual ~OH_AVCodec() = default;
|
||||
|
@ -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
|
||||
@ -24,7 +24,7 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "OH_AVMemor
|
||||
|
||||
using namespace OHOS::AVCodec;
|
||||
|
||||
OH_AVMemory::OH_AVMemory(const std::shared_ptr<OHOS::Media::AVSharedMemory> &mem)
|
||||
OH_AVMemory::OH_AVMemory(const std::shared_ptr<OHOS::AVCodec::AVSharedMemory> &mem)
|
||||
: memory_(mem)
|
||||
{
|
||||
}
|
||||
@ -33,7 +33,7 @@ OH_AVMemory::~OH_AVMemory()
|
||||
{
|
||||
}
|
||||
|
||||
bool OH_AVMemory::IsEqualMemory(const std::shared_ptr<OHOS::Media::AVSharedMemory> &mem)
|
||||
bool OH_AVMemory::IsEqualMemory(const std::shared_ptr<OHOS::AVCodec::AVSharedMemory> &mem)
|
||||
{
|
||||
return (mem == memory_) ? true : false;
|
||||
}
|
||||
@ -51,3 +51,18 @@ int32_t OH_AVMemory_GetSize(struct OH_AVMemory *mem)
|
||||
CHECK_AND_RETURN_RET_LOG(mem->memory_ != nullptr, -1, "memory is nullptr!");
|
||||
return mem->memory_->GetSize();
|
||||
}
|
||||
|
||||
|
||||
OH_AVBufferElement::OH_AVBufferElement(const std::shared_ptr<OHOS::AVCodec::AVBufferElement> &bufferElement)
|
||||
: bufferElement_(bufferElement)
|
||||
{
|
||||
}
|
||||
|
||||
OH_AVBufferElement::~OH_AVBufferElement()
|
||||
{
|
||||
}
|
||||
|
||||
bool OH_AVBufferElement::IsEqualBufferElement(const std::shared_ptr<OHOS::AVCodec::AVBufferElement> &bufferElement)
|
||||
{
|
||||
return (bufferElement == bufferElement_) ? true : false;
|
||||
}
|
@ -24,7 +24,6 @@ namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "NativeAVSource"}
|
||||
}
|
||||
|
||||
using namespase OHOS::Media;
|
||||
using namespase OHOS::AVCodec;
|
||||
|
||||
struct SourceObject : public OH_AVSource {
|
||||
|
243
frameworks/native/common/avcodec_errors.cpp
Normal file
243
frameworks/native/common/avcodec_errors.cpp
Normal file
@ -0,0 +1,243 @@
|
||||
/*
|
||||
* 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 "avcodec_errors.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec {
|
||||
using ErrorMessageFunc = std::function<std::string(const std::string& param1, const std::string& param2)>;
|
||||
const std::map<AVCodecServiceErrCode, std::string> AVCS_ERRCODE_INFOS = {
|
||||
{AVCSERR_OK, "success"},
|
||||
{AVCSERR_NO_MEMORY, "no memory"},
|
||||
{AVCSERR_INVALID_OPERATION, "operation not be permitted"},
|
||||
{AVCSERR_INVALID_VAL, "invalid argument"},
|
||||
{AVCSERR_UNKNOWN, "unkown error"},
|
||||
{AVCSERR_SERVICE_DIED, "avcodec service died"},
|
||||
{AVCSERR_CREATE_REC_ENGINE_FAILED, "create recorder engine failed"},
|
||||
{AVCSERR_CREATE_PLAYER_ENGINE_FAILED, "create player engine failed"},
|
||||
{AVCSERR_CREATE_AVMETADATAHELPER_ENGINE_FAILED, "create avmetadatahelper engine failed"},
|
||||
{AVCSERR_INVALID_STATE, "the state is not support this operation"},
|
||||
{AVCSERR_UNSUPPORT, "unsupport interface"},
|
||||
{AVCSERR_UNSUPPORT_AUD_SRC_TYPE, "unsupport audio source type"},
|
||||
{AVCSERR_UNSUPPORT_AUD_SAMPLE_RATE, "unsupport audio sample rate"},
|
||||
{AVCSERR_UNSUPPORT_AUD_CHANNEL_NUM, "unsupport audio channel"},
|
||||
{AVCSERR_UNSUPPORT_AUD_ENC_TYPE, "unsupport audio encoder type"},
|
||||
{AVCSERR_UNSUPPORT_AUD_PARAMS, "unsupport audio params(other params)"},
|
||||
{AVCSERR_UNSUPPORT_VID_SRC_TYPE, "unsupport video source type"},
|
||||
{AVCSERR_UNSUPPORT_VID_ENC_TYPE, "unsupport video encoder type"},
|
||||
{AVCSERR_UNSUPPORT_VID_PARAMS, "unsupport video params(other params)"},
|
||||
{AVCSERR_UNSUPPORT_CONTAINER_TYPE, "unsupport container format type"},
|
||||
{AVCSERR_UNSUPPORT_PROTOCOL_TYPE, "unsupport protocol type"},
|
||||
{AVCSERR_UNSUPPORT_VID_DEC_TYPE, "unsupport video decoder type"},
|
||||
{AVCSERR_UNSUPPORT_AUD_DEC_TYPE, "unsupport audio decoder type"},
|
||||
{AVCSERR_UNSUPPORT_STREAM, "internal data stream error"},
|
||||
{AVCSERR_UNSUPPORT_FILE, "this appears to be a text file"},
|
||||
{AVCSERR_UNSUPPORT_SOURCE, "unsupport source type"},
|
||||
{AVCSERR_AUD_ENC_FAILED, "audio encode failed"},
|
||||
{AVCSERR_AUD_RENDER_FAILED, "audio render failed"},
|
||||
{AVCSERR_VID_ENC_FAILED, "video encode failed"},
|
||||
{AVCSERR_AUD_DEC_FAILED, "audio decode failed"},
|
||||
{AVCSERR_VID_DEC_FAILED, "video decode failed"},
|
||||
{AVCSERR_MUXER_FAILED, "stream avmuxer failed"},
|
||||
{AVCSERR_DEMUXER_FAILED, "stream demuxer or parser failed"},
|
||||
{AVCSERR_OPEN_FILE_FAILED, "open file failed"},
|
||||
{AVCSERR_FILE_ACCESS_FAILED, "read or write file failed"},
|
||||
{AVCSERR_START_FAILED, "audio or video start failed"},
|
||||
{AVCSERR_PAUSE_FAILED, "audio or video pause failed"},
|
||||
{AVCSERR_STOP_FAILED, "audio or video stop failed"},
|
||||
{AVCSERR_SEEK_FAILED, "audio or video seek failed"},
|
||||
{AVCSERR_NETWORK_TIMEOUT, "network timeout"},
|
||||
{AVCSERR_NOT_FIND_CONTAINER, "not find a demuxer"},
|
||||
{AVCSERR_EXTEND_START, "extend start error code"},
|
||||
};
|
||||
|
||||
const std::map<AVCodecServiceErrCode, AVCodecServiceExtErrCode> AVCSERRCODE_TO_EXTERRORCODE = {
|
||||
{AVCSERR_OK, AVCSERR_EXT_OK},
|
||||
{AVCSERR_NO_MEMORY, AVCSERR_EXT_NO_MEMORY},
|
||||
{AVCSERR_INVALID_OPERATION, AVCSERR_EXT_OPERATE_NOT_PERMIT},
|
||||
{AVCSERR_INVALID_VAL, AVCSERR_EXT_INVALID_VAL},
|
||||
{AVCSERR_UNKNOWN, AVCSERR_EXT_UNKNOWN},
|
||||
{AVCSERR_SERVICE_DIED, AVCSERR_EXT_SERVICE_DIED},
|
||||
{AVCSERR_CREATE_REC_ENGINE_FAILED, AVCSERR_EXT_UNKNOWN},
|
||||
{AVCSERR_CREATE_PLAYER_ENGINE_FAILED, AVCSERR_EXT_UNKNOWN},
|
||||
{AVCSERR_INVALID_STATE, AVCSERR_EXT_INVALID_STATE},
|
||||
{AVCSERR_UNSUPPORT, AVCSERR_EXT_UNSUPPORT},
|
||||
{AVCSERR_UNSUPPORT_AUD_SRC_TYPE, AVCSERR_EXT_UNSUPPORT},
|
||||
{AVCSERR_UNSUPPORT_AUD_SAMPLE_RATE, AVCSERR_EXT_UNSUPPORT},
|
||||
{AVCSERR_UNSUPPORT_AUD_CHANNEL_NUM, AVCSERR_EXT_UNSUPPORT},
|
||||
{AVCSERR_UNSUPPORT_AUD_ENC_TYPE, AVCSERR_EXT_UNSUPPORT},
|
||||
{AVCSERR_UNSUPPORT_AUD_PARAMS, AVCSERR_EXT_UNSUPPORT},
|
||||
{AVCSERR_UNSUPPORT_VID_SRC_TYPE, AVCSERR_EXT_UNSUPPORT},
|
||||
{AVCSERR_UNSUPPORT_VID_ENC_TYPE, AVCSERR_EXT_UNSUPPORT},
|
||||
{AVCSERR_UNSUPPORT_VID_PARAMS, AVCSERR_EXT_UNSUPPORT},
|
||||
{AVCSERR_UNSUPPORT_CONTAINER_TYPE, AVCSERR_EXT_UNSUPPORT},
|
||||
{AVCSERR_UNSUPPORT_PROTOCOL_TYPE, AVCSERR_EXT_UNSUPPORT},
|
||||
{AVCSERR_UNSUPPORT_VID_DEC_TYPE, AVCSERR_EXT_UNSUPPORT},
|
||||
{AVCSERR_UNSUPPORT_AUD_DEC_TYPE, AVCSERR_EXT_UNSUPPORT},
|
||||
{AVCSERR_UNSUPPORT_STREAM, AVCSERR_EXT_UNSUPPORT},
|
||||
{AVCSERR_UNSUPPORT_FILE, AVCSERR_EXT_UNSUPPORT},
|
||||
{AVCSERR_UNSUPPORT_SOURCE, AVCSERR_EXT_UNSUPPORT},
|
||||
{AVCSERR_AUD_RENDER_FAILED, AVCSERR_EXT_UNSUPPORT},
|
||||
{AVCSERR_AUD_ENC_FAILED, AVCSERR_EXT_UNKNOWN},
|
||||
{AVCSERR_VID_ENC_FAILED, AVCSERR_EXT_UNKNOWN},
|
||||
{AVCSERR_AUD_DEC_FAILED, AVCSERR_EXT_UNKNOWN},
|
||||
{AVCSERR_VID_DEC_FAILED, AVCSERR_EXT_UNKNOWN},
|
||||
{AVCSERR_MUXER_FAILED, AVCSERR_EXT_UNKNOWN},
|
||||
{AVCSERR_DEMUXER_FAILED, AVCSERR_EXT_UNKNOWN},
|
||||
{AVCSERR_OPEN_FILE_FAILED, AVCSERR_EXT_UNKNOWN},
|
||||
{AVCSERR_FILE_ACCESS_FAILED, AVCSERR_EXT_UNKNOWN},
|
||||
{AVCSERR_START_FAILED, AVCSERR_EXT_UNKNOWN},
|
||||
{AVCSERR_PAUSE_FAILED, AVCSERR_EXT_UNKNOWN},
|
||||
{AVCSERR_STOP_FAILED, AVCSERR_EXT_UNKNOWN},
|
||||
{AVCSERR_SEEK_FAILED, AVCSERR_EXT_UNKNOWN},
|
||||
{AVCSERR_NETWORK_TIMEOUT, AVCSERR_EXT_TIMEOUT},
|
||||
{AVCSERR_NOT_FIND_CONTAINER, AVCSERR_EXT_UNSUPPORT},
|
||||
{AVCSERR_EXTEND_START, AVCSERR_EXT_EXTEND_START},
|
||||
};
|
||||
|
||||
const std::map<AVCodecServiceExtErrCode, std::string> AVCSEXTERRCODE_INFOS = {
|
||||
{AVCSERR_EXT_OK, "success"},
|
||||
{AVCSERR_EXT_NO_MEMORY, "no memory"},
|
||||
{AVCSERR_EXT_OPERATE_NOT_PERMIT, "operation not be permitted"},
|
||||
{AVCSERR_EXT_INVALID_VAL, "invalid argument"},
|
||||
{AVCSERR_EXT_IO, "IO error"},
|
||||
{AVCSERR_EXT_TIMEOUT, "network timeout"},
|
||||
{AVCSERR_EXT_UNKNOWN, "unkown error"},
|
||||
{AVCSERR_EXT_SERVICE_DIED, "avcodec service died"},
|
||||
{AVCSERR_EXT_INVALID_STATE, "the state is not support this operation"},
|
||||
{AVCSERR_EXT_UNSUPPORT, "unsupport interface"},
|
||||
{AVCSERR_EXT_EXTEND_START, "extend err start"},
|
||||
};
|
||||
|
||||
std::string ErrorMessageOk(const std::string& param1, const std::string& param2)
|
||||
{
|
||||
(void)param1;
|
||||
(void)param2;
|
||||
return "success";
|
||||
}
|
||||
|
||||
std::string ErrorMessageNoPermission(const std::string& param1, const std::string& param2)
|
||||
{
|
||||
std::string message = "Try to do " + param1 + " failed. User should request permission " + param2 +" first.";
|
||||
return message;
|
||||
}
|
||||
|
||||
std::string ErrorMessageInvalidParameter(const std::string& param1, const std::string& param2)
|
||||
{
|
||||
(void)param2;
|
||||
std::string message = "The Parameter " + param1 + " is invalid. Please check the type and range.";
|
||||
return message;
|
||||
}
|
||||
|
||||
std::string ErrorMessageUnsupportCapability(const std::string& param1, const std::string& param2)
|
||||
{
|
||||
(void)param2;
|
||||
std::string message = "Function " + param1 + " can not work correctly due to limited device capability.";
|
||||
return message;
|
||||
}
|
||||
|
||||
std::string ErrorMessageNoMemory(const std::string& param1, const std::string& param2)
|
||||
{
|
||||
(void)param2;
|
||||
std::string message = "Create " + param1 + " failed due to system memory.";
|
||||
return message;
|
||||
}
|
||||
|
||||
std::string ErrorMessageOperateNotPermit(const std::string& param1, const std::string& param2)
|
||||
{
|
||||
(void)param2;
|
||||
std::string message = "The operate " + param1 + " failed due to not permit in current state.";
|
||||
return message;
|
||||
}
|
||||
|
||||
std::string ErrorMessageIO(const std::string& param1, const std::string& param2)
|
||||
{
|
||||
(void)param2;
|
||||
std::string message = "IO error happened due to " + param1 + ".";
|
||||
return message;
|
||||
}
|
||||
|
||||
std::string ErrorMessageTimeout(const std::string& param1, const std::string& param2)
|
||||
{
|
||||
std::string message = "Timeout happend when " + param1 + " due to " + param2 + ".";
|
||||
return message;
|
||||
}
|
||||
|
||||
std::string ErrorMessageServiceDied(const std::string& param1, const std::string& param2)
|
||||
{
|
||||
(void)param1;
|
||||
(void)param2;
|
||||
std::string message = "AVCodec Serviced Died.";
|
||||
return message;
|
||||
}
|
||||
|
||||
std::string ErrorMessageUnsupportFormat(const std::string& param1, const std::string& param2)
|
||||
{
|
||||
(void)param2;
|
||||
std::string message = "The format " + param1 + " is not support.";
|
||||
return message;
|
||||
}
|
||||
|
||||
std::string AVCSErrorToString(AVCodecServiceErrCode code)
|
||||
{
|
||||
if (AVCS_ERRCODE_INFOS.count(code) != 0) {
|
||||
return AVCS_ERRCODE_INFOS.at(code);
|
||||
}
|
||||
|
||||
if (code > AVCSERR_EXTEND_START) {
|
||||
return "extend error:" + std::to_string(static_cast<int32_t>(code - AVCSERR_EXTEND_START));
|
||||
}
|
||||
|
||||
return "invalid error code:" + std::to_string(static_cast<int32_t>(code));
|
||||
}
|
||||
|
||||
std::string AVCSExtErrorToString(AVCodecServiceExtErrCode code)
|
||||
{
|
||||
if (AVCSEXTERRCODE_INFOS.count(code) != 0) {
|
||||
return AVCSEXTERRCODE_INFOS.at(code);
|
||||
}
|
||||
|
||||
if (code > AVCSERR_EXT_EXTEND_START) {
|
||||
return "extend error:" + std::to_string(static_cast<int32_t>(code - AVCSERR_EXTEND_START));
|
||||
}
|
||||
|
||||
return "invalid error code:" + std::to_string(static_cast<int32_t>(code));
|
||||
}
|
||||
|
||||
std::string AVCSErrorToExtErrorString(AVCodecServiceErrCode code)
|
||||
{
|
||||
if (AVCS_ERRCODE_INFOS.count(code) != 0 && AVCSERRCODE_TO_EXTERRORCODE.count(code) != 0) {
|
||||
AVCodecServiceExtErrCode extCode = AVCSERRCODE_TO_EXTERRORCODE.at(code);
|
||||
if (AVCSEXTERRCODE_INFOS.count(extCode) != 0) {
|
||||
return AVCSEXTERRCODE_INFOS.at(extCode);
|
||||
}
|
||||
}
|
||||
|
||||
return "unkown error";
|
||||
}
|
||||
|
||||
AVCodecServiceExtErrCode AVCSErrorToExtError(AVCodecServiceErrCode code)
|
||||
{
|
||||
if (AVCS_ERRCODE_INFOS.count(code) != 0 && AVCSERRCODE_TO_EXTERRORCODE.count(code) != 0) {
|
||||
return AVCSERRCODE_TO_EXTERRORCODE.at(code);
|
||||
}
|
||||
|
||||
return AVCSERR_EXT_UNKNOWN;
|
||||
}
|
||||
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
@ -33,8 +33,8 @@ public:
|
||||
*
|
||||
* @param format The format of the input data and the desired format of the output data.
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t Configure(const Format &format) = 0;
|
||||
|
||||
@ -42,8 +42,8 @@ public:
|
||||
* @brief Start codec.
|
||||
*
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t Start() = 0;
|
||||
|
||||
@ -53,8 +53,8 @@ public:
|
||||
* This function must be called during running
|
||||
*
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t Stop() = 0;
|
||||
|
||||
@ -62,8 +62,8 @@ public:
|
||||
* @brief Flush both input and output buffers of the codec.
|
||||
*
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t Flush() = 0;
|
||||
|
||||
@ -71,8 +71,8 @@ public:
|
||||
* @brief Notify eos of the encoder.
|
||||
*
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t NotifyEos() = 0;
|
||||
|
||||
@ -80,8 +80,8 @@ public:
|
||||
* @brief Restores the codec to the initial state.
|
||||
*
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t Reset() = 0;
|
||||
|
||||
@ -89,8 +89,8 @@ public:
|
||||
* @brief Releases codec resources. All methods are unavailable after calling this.
|
||||
*
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t Release() = 0;
|
||||
|
||||
@ -100,8 +100,8 @@ public:
|
||||
* This function can only be called after {@link Configure} and before {@link Start}
|
||||
*
|
||||
* @return Returns the pointer to the surface.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual sptr<Surface> CreateInputSurface() = 0;
|
||||
|
||||
@ -112,8 +112,8 @@ public:
|
||||
*
|
||||
* @param index The index of the output buffer.
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t SetInputSurface(sptr<PersistentSurface> surface) = 0;
|
||||
|
||||
@ -124,8 +124,8 @@ public:
|
||||
*
|
||||
* @param index The index of the output buffer.
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t SetOutputSurface(sptr<Surface> surface) = 0;
|
||||
|
||||
@ -136,8 +136,8 @@ public:
|
||||
*
|
||||
* @param index The index of the input buffer.
|
||||
* @return Returns {@link AVSharedMemory} if success; returns nullptr otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual std::shared_ptr<AVSharedMemory> GetInputBuffer(uint32_t index) = 0;
|
||||
|
||||
@ -150,8 +150,8 @@ public:
|
||||
* @param info The info of the input buffer. For details, see {@link AVCodecBufferInfo}
|
||||
* @param flag The flag of the input buffer. For details, see {@link AVCodecBufferFlag}
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) = 0;
|
||||
|
||||
@ -163,8 +163,8 @@ public:
|
||||
* @param index The index of the input buffer.
|
||||
* @param timeUs timeoutUs
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t DequeueInputBuffer(size_t *index, int64_t timetUs) = 0;
|
||||
|
||||
@ -176,8 +176,8 @@ public:
|
||||
* @param index The index of the output buffer.
|
||||
* @param timeUs timeoutUs
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t DequeueOutputBuffer(size_t *index, int64_t timetUs) = 0;
|
||||
|
||||
@ -188,8 +188,8 @@ public:
|
||||
*
|
||||
* @param index The index of the output buffer.
|
||||
* @return Returns {@link AVSharedMemory} if success; returns nullptr otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual std::shared_ptr<AVSharedMemory> GetOutputBuffer(uint32_t index) = 0;
|
||||
|
||||
@ -200,8 +200,8 @@ public:
|
||||
*
|
||||
* @param format
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t GetOutputFormat(Format &format) = 0;
|
||||
|
||||
@ -212,8 +212,8 @@ public:
|
||||
*
|
||||
* @param index The index of the output buffer.
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t ReleaseOutputBuffer(uint32_t index, bool render) = 0;
|
||||
|
||||
@ -224,8 +224,8 @@ public:
|
||||
*
|
||||
* @param format The parameters.
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t SetParameter(const Format &format) = 0;
|
||||
|
||||
@ -236,8 +236,8 @@ public:
|
||||
*
|
||||
* @param callback Indicates the codec listener to register. For details, see {@link AVCodecCallback}.
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t SetCallback(const std::shared_ptr<AVCodecCallback> &callback) = 0;
|
||||
|
||||
@ -264,8 +264,8 @@ public:
|
||||
* @param mime The mime type.
|
||||
* @param encoder true for encoder and false for decoder.
|
||||
* @return Returns the preferred codec.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
static std::shared_ptr<AVCodec> CreateByMime(const std::string &mime, bool encoder);
|
||||
|
||||
@ -274,8 +274,8 @@ public:
|
||||
*
|
||||
* @param name The codec's name.
|
||||
* @return Returns the designated codec.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
static std::shared_ptr<AVCodec> CreateByName(const std::string &name);
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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
|
||||
@ -24,8 +24,8 @@ namespace AVCodec {
|
||||
/**
|
||||
* @brief Error type of AVCodec
|
||||
*
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
enum AVCodecErrorType : int32_t {
|
||||
/* internal errors, error code passed by the errorCode, and definition see "MediaServiceErrCode" */
|
||||
@ -54,6 +54,15 @@ struct AVCodecBufferInfo {
|
||||
int32_t size = 0;
|
||||
/* The start-offset of the data in the buffer */
|
||||
int32_t offset = 0;
|
||||
/* The flag of the available buffer. For details, see {@link AVCodecBufferFlag} */
|
||||
uint32_t flags = 0;
|
||||
/* The index of the track which this Buffer belongs. */
|
||||
uint32_t trackId;
|
||||
};
|
||||
|
||||
struct AVBufferElement {
|
||||
std::shared_ptr<AVSharedMemory> buffer;
|
||||
std::shared_ptr<AVSharedMemory> metaData;
|
||||
};
|
||||
|
||||
class AVCodecCallback {
|
||||
@ -64,8 +73,8 @@ public:
|
||||
*
|
||||
* @param errorType Error type. For details, see {@link AVCodecErrorType}.
|
||||
* @param errorCode Error code.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual void OnError(AVCodecErrorType errorType, int32_t errorCode) = 0;
|
||||
|
||||
@ -73,8 +82,8 @@ public:
|
||||
* Called when the output format has changed.
|
||||
*
|
||||
* @param format The new output format.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual void OnOutputFormatChanged(const Format &format) = 0;
|
||||
|
||||
@ -82,8 +91,8 @@ public:
|
||||
* Called when an input buffer becomes available.
|
||||
*
|
||||
* @param index The index of the available input buffer.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual void OnInputBufferAvailable(uint32_t index) = 0;
|
||||
|
||||
@ -92,11 +101,10 @@ public:
|
||||
*
|
||||
* @param index The index of the available output buffer.
|
||||
* @param info The info of the available output buffer. For details, see {@link AVCodecBufferInfo}
|
||||
* @param flag The flag of the available output buffer. For details, see {@link AVCodecBufferFlag}
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) = 0;
|
||||
virtual void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info) = 0;
|
||||
};
|
||||
|
||||
class SurfaceBufferExtratDataKey {
|
||||
|
116
interfaces/inner_api/native/avcodec_errors.h
Normal file
116
interfaces/inner_api/native/avcodec_errors.h
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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 AVCODEC_ERRORS_H
|
||||
#define AVCODEC_ERRORS_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "errors.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec {
|
||||
using AVCSErrCode = ErrCode;
|
||||
|
||||
// bit 28~21 is subsys, bit 20~16 is Module. bit 15~0 is code
|
||||
// TODO: confirm module offset
|
||||
constexpr AVCSErrCode AVCS_MODULE = 0X01000;
|
||||
constexpr AVCSErrCode AVCS_ERR_OFFSET = ErrCodeOffset(SUBSYS_MULTIMEDIA, AVCS_MODULE);
|
||||
typedef enum AVCodecServiceErrCode : ErrCode {
|
||||
AVCS_ERR_OK = ERR_OK,
|
||||
AVCS_ERR_NO_MEMORY = AVCS_ERR_OFFSET + ENOMEM, // no memory
|
||||
AVCS_ERR_INVALID_OPERATION = AVCS_ERR_OFFSET + ENOSYS, // opertation not be permitted
|
||||
AVCS_ERR_INVALID_VAL = AVCS_ERR_OFFSET + EINVAL, // invalid argument
|
||||
AVCS_ERR_UNKNOWN = AVCS_ERR_OFFSET + 0x200, // unkown error.
|
||||
AVCS_ERR_SERVICE_DIED, // avcodec service died
|
||||
AVCS_ERR_CREATE_AVCODEC_SUB_SERVICE_FAILED, // create avcodec sub service failed.
|
||||
AVCS_ERR_CREATE_MUXER_SUB_SERVICE_FAILED, // create muxer sub service failed.
|
||||
AVCS_ERR_CREATE_DEMUXER_SUB_SERVICE_FAILED, // create demuxer sub service failed.
|
||||
AVCS_ERR_INVALID_STATE, // the state is not support this operation.
|
||||
AVCS_ERR_UNSUPPORT, // unsupport interface.
|
||||
AVCS_ERR_UNSUPPORT_AUD_SRC_TYPE, // unsupport audio source type.
|
||||
AVCS_ERR_UNSUPPORT_AUD_SAMPLE_RATE, // unsupport audio sample rate.
|
||||
AVCS_ERR_UNSUPPORT_AUD_CHANNEL_NUM, // unsupport audio channel.
|
||||
AVCS_ERR_UNSUPPORT_AUD_ENC_TYPE, // unsupport audio encoder type.
|
||||
AVCS_ERR_UNSUPPORT_AUD_PARAMS, // unsupport audio params(other params).
|
||||
AVCS_ERR_UNSUPPORT_VID_SRC_TYPE, // unsupport video source type.
|
||||
AVCS_ERR_UNSUPPORT_VID_ENC_TYPE, // unsupport video encoder type.
|
||||
AVCS_ERR_UNSUPPORT_VID_PARAMS, // unsupport video params(other params).
|
||||
AVCS_ERR_UNSUPPORT_CONTAINER_TYPE, // unsupport container format type.
|
||||
AVCS_ERR_UNSUPPORT_PROTOCOL_TYPE, // unsupport protocol type.
|
||||
AVCS_ERR_UNSUPPORT_VID_DEC_TYPE, // unsupport video decoder type.
|
||||
AVCS_ERR_UNSUPPORT_AUD_DEC_TYPE, // unsupport audio decoder type.
|
||||
AVCS_ERR_UNSUPPORT_STREAM, // internal data stream error.
|
||||
AVCS_ERR_UNSUPPORT_FILE, // this appears to be a text file.
|
||||
AVCS_ERR_UNSUPPORT_SOURCE, // unsupport source type.
|
||||
AVCS_ERR_AUD_RENDER_FAILED, // audio render failed.
|
||||
AVCS_ERR_AUD_ENC_FAILED, // audio encode failed.
|
||||
AVCS_ERR_VID_ENC_FAILED, // video encode failed.
|
||||
AVCS_ERR_AUD_DEC_FAILED, // audio decode failed.
|
||||
AVCS_ERR_VID_DEC_FAILED, // video decode failed.
|
||||
AVCS_ERR_MUXER_FAILED, // stream avmuxer failed.
|
||||
AVCS_ERR_DEMUXER_FAILED, // stream demuxer or parser failed.
|
||||
AVCS_ERR_OPEN_FILE_FAILED, // open file failed.
|
||||
AVCS_ERR_FILE_ACCESS_FAILED, // read or write file failed.
|
||||
AVCS_ERR_START_FAILED, // audio/video start failed.
|
||||
AVCS_ERR_PAUSE_FAILED, // audio/video pause failed.
|
||||
AVCS_ERR_STOP_FAILED, // audio/video stop failed.
|
||||
AVCS_ERR_SEEK_FAILED, // audio/video seek failed.
|
||||
AVCS_ERR_NETWORK_TIMEOUT, // network timeout.
|
||||
AVCS_ERR_NOT_FIND_CONTAINER, // not find a demuxer.
|
||||
AVCS_ERR_DATA_SOURCE_IO_ERROR, // avcodec data source IO failed.
|
||||
AVCS_ERR_DATA_SOURCE_OBTAIN_MEM_ERROR, // avcodec data source get mem failed.
|
||||
AVCS_ERR_DATA_SOURCE_ERROR_UNKNOWN, // avcodec data source error unknow.
|
||||
AVCS_ERR_EXTEND_START = AVCS_ERR_OFFSET + 0xF000, // extend err start.
|
||||
} AVCodecServiceErrCode;
|
||||
|
||||
// avcodec api error code
|
||||
typedef enum AVCodecServiceExtErrCode : ErrCode {
|
||||
AVCS_ERR_EXT_OK = 0,
|
||||
AVCS_ERR_EXT_NO_MEMORY = 1, // no memory.
|
||||
AVCS_ERR_EXT_OPERATE_NOT_PERMIT = 2, // opertation not be permitted.
|
||||
AVCS_ERR_EXT_INVALID_VAL = 3, // invalid argument.
|
||||
AVCS_ERR_EXT_IO = 4, // IO error.
|
||||
AVCS_ERR_EXT_TIMEOUT = 5, // network timeout.
|
||||
AVCS_ERR_EXT_UNKNOWN = 6, // unknown error.
|
||||
AVCS_ERR_EXT_SERVICE_DIED = 7, // avcodec service died.
|
||||
AVCS_ERR_EXT_INVALID_STATE = 8, // the state is not support this operation.
|
||||
AVCS_ERR_EXT_UNSUPPORT = 9, // unsupport interface.
|
||||
AVCS_ERR_EXT_EXTEND_START = 100, // extend err start.
|
||||
} AVCodecServiceExtErrCode;
|
||||
|
||||
// avcodec northbound interface error code
|
||||
typedef enum OH_AVCodecErrCode {
|
||||
AVC_ERR_OK = 0,
|
||||
AVC_ERR_NO_MEMORY = 1, // no memory.
|
||||
AVC_ERR_OPERATE_NOT_PERMIT = 2, // opertation not be permitted.
|
||||
AVC_ERR_INVALID_VAL = 3, // invalid argument.
|
||||
AVC_ERR_IO = 4, // IO error.
|
||||
AVC_ERR_TIMEOUT = 5, // network timeout.
|
||||
AVC_ERR_UNKNOWN = 6, // unknown error.
|
||||
AVC_ERR_SERVICE_DIED = 7, // avcodec service died.
|
||||
AVC_ERR_INVALID_STATE = 8, // the state is not support this operation.
|
||||
AVC_ERR_UNSUPPORT = 9, // unsupport interface.
|
||||
AVC_ERR_EXTEND_START = 100, // extend err start.
|
||||
} OH_AVCodecErrCode;
|
||||
|
||||
__attribute__((visibility("default"))) std::string AVCSErrorToString(AVCodecServiceErrCode code);
|
||||
__attribute__((visibility("default"))) std::string AVCSExtErrorToString(AVCodecServiceExtErrCode code);
|
||||
__attribute__((visibility("default"))) std::string AVCSErrorToExtErrorString(AVCodecServiceErrCode code);
|
||||
__attribute__((visibility("default"))) AVCodecServiceExtErrCode AVCSErrorToExtError(AVCodecServiceErrCode code);
|
||||
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
||||
#endif // AVCODEC_ERRORS_H
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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
|
||||
@ -27,8 +27,8 @@ namespace AVCodec {
|
||||
/**
|
||||
* @brief AVCodec Type
|
||||
*
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
enum AVCodecType : int32_t {
|
||||
AVCODEC_TYPE_NONE = -1,
|
||||
@ -39,8 +39,8 @@ enum AVCodecType : int32_t {
|
||||
/**
|
||||
* @brief Range contain min and max value
|
||||
*
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
struct Range {
|
||||
int32_t minVal;
|
||||
@ -80,8 +80,8 @@ struct Range {
|
||||
/**
|
||||
* @brief ImgSize contain width and height
|
||||
*
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
struct ImgSize {
|
||||
int32_t width;
|
||||
@ -104,8 +104,8 @@ struct ImgSize {
|
||||
/**
|
||||
* @brief Capability Data struct of Codec, parser from config file
|
||||
*
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
struct CapabilityData {
|
||||
std::string codecName = "";
|
||||
@ -164,48 +164,48 @@ public:
|
||||
/**
|
||||
* @brief Get name of this codec, used to create the codec instance.
|
||||
* @return Returns codec name.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
std::string GetName();
|
||||
|
||||
/**
|
||||
* @brief Get type of this codec
|
||||
* @return Returns codec type, see {@link AVCodecType}
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
AVCodecType GetType();
|
||||
|
||||
/**
|
||||
* @brief Get mime type of this codec
|
||||
* @return Returns codec mime type, see {@link CodecMimeType}
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
std::string GetMimeType();
|
||||
|
||||
/**
|
||||
* @brief Check whether the codec is accelerated by hardware.
|
||||
* @return Returns true if the codec is hardware accelerated; false otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
bool IsHardwareAccelerated();
|
||||
|
||||
/**
|
||||
* @brief Check whether the codec is software implemented only.
|
||||
* @return Returns true if the codec is software implemented only; false otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
bool IsSoftwareOnly();
|
||||
|
||||
/**
|
||||
* @brief Check whether the codec is provided by vendor.
|
||||
* @return Returns true if the codec is provided by vendor; false otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
bool IsVendor();
|
||||
|
||||
@ -223,56 +223,56 @@ public:
|
||||
* whether hardware acceleration is supported, whether only software is supported,
|
||||
* and whether the codec is provided by the vendor.
|
||||
* @return Returns the pointer of {@link AVCodecInfo}.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
std::shared_ptr<AVCodecInfo> GetCodecInfo();
|
||||
|
||||
/**
|
||||
* @brief Get supported bitrate range.
|
||||
* @return Returns the range of supported bitrates.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
Range GetSupportedBitrate();
|
||||
|
||||
/**
|
||||
* @brief Get supported video raw formats.
|
||||
* @return Returns an array of supported formats. For Details, see {@link VideoPixelFormat}.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
std::vector<int32_t> GetSupportedFormats();
|
||||
|
||||
/**
|
||||
* @brief Get supported alignment of video height, only used for video codecs.
|
||||
* @return Returns the supported alignment of video height (in pixels).
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
int32_t GetSupportedHeightAlignment();
|
||||
|
||||
/**
|
||||
* @brief Get supported alignment of video width, only used for video codecs.
|
||||
* @return Returns the supported alignment of video width (in pixels).
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
int32_t GetSupportedWidthAlignment();
|
||||
|
||||
/**
|
||||
* @brief Get supported width range of video.
|
||||
* @return Returns the supported width range of video.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
Range GetSupportedWidth();
|
||||
|
||||
/**
|
||||
* @brief Get supported height range of video.
|
||||
* @return Returns the supported height range of video.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
Range GetSupportedHeight();
|
||||
|
||||
@ -285,24 +285,24 @@ public:
|
||||
* returns {@link MPEG2Profile} array if codec is mpeg2,
|
||||
* returns {@link MPEG4Profile} array if codec is mpeg4,
|
||||
* returns {@link VP8Profile} array if codec is vp8.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
std::vector<int32_t> GetSupportedProfiles();
|
||||
|
||||
/**
|
||||
* @brief Get supported codec level array.
|
||||
* @return Returns an array of supported codec level number.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
std::vector<int32_t> GetSupportedLevels();
|
||||
|
||||
/**
|
||||
* @brief Get supported video encode quality Range.
|
||||
* @return Returns an array of supported video encode quality Range.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
Range GetSupportedEncodeQuality();
|
||||
|
||||
@ -311,16 +311,16 @@ public:
|
||||
* @param width Indicates the specified video width (in pixels).
|
||||
* @param height Indicates the specified video height (in pixels).
|
||||
* @return Returns true if the codec supports {@link width} * {@link height} size video, false otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
bool IsSizeSupported(int32_t width, int32_t height);
|
||||
|
||||
/**
|
||||
* @brief Get supported frameRate.
|
||||
* @return Returns the supported frameRate range of video.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
Range GetSupportedFrameRate();
|
||||
|
||||
@ -329,8 +329,8 @@ public:
|
||||
* @param width Indicates the specified video width (in pixels).
|
||||
* @param height Indicates the specified video height (in pixels).
|
||||
* @return Returns the supported frameRate range for the specified width and height.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
Range GetSupportedFrameRatesFor(int32_t width, int32_t height);
|
||||
|
||||
@ -340,8 +340,8 @@ public:
|
||||
* @param height Indicates the specified video height (in pixels).
|
||||
* @param frameRate Indicates the specified video frameRate.
|
||||
* @return Returns true if the codec supports the specified size and frameRate; false otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
bool IsSizeAndRateSupported(int32_t width, int32_t height, double frameRate);
|
||||
|
||||
@ -351,40 +351,40 @@ public:
|
||||
* @param width Indicates the specified video width (in pixels).
|
||||
* @param height Indicates the specified video height (in pixels).
|
||||
* @return Returns preferred frameRate range for the specified width and height.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
Range GetPreferredFrameRate(int32_t width, int32_t height);
|
||||
|
||||
/**
|
||||
* @brief Get supported encode bitrate mode.
|
||||
* @return Returns an array of supported encode bitrate mode. For details, see {@link VideoEncodeBitrateMode}.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
std::vector<int32_t> GetSupportedBitrateMode();
|
||||
|
||||
/**
|
||||
* @brief Get supported encode qualit range.
|
||||
* @return Returns supported encode qualit range.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
Range GetSupportedQuality();
|
||||
|
||||
/**
|
||||
* @brief Get supported encode complexity range.
|
||||
* @return Returns supported encode complexity range.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
Range GetSupportedComplexity();
|
||||
|
||||
/**
|
||||
* @brief Check video encoder wether support request key frame dynamicly.
|
||||
* @return Returns true if support, false not support.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
bool IsSupportDynamicIframe();
|
||||
|
||||
@ -422,64 +422,64 @@ public:
|
||||
* whether hardware acceleration is supported, whether only software is supported,
|
||||
* and whether the codec is provided by the vendor.
|
||||
* @return Returns the pointer of {@link AVCodecInfo}
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
std::shared_ptr<AVCodecInfo> GetCodecInfo();
|
||||
|
||||
/**
|
||||
* @brief Get supported bitrate range.
|
||||
* @return Returns the range of supported bitrates.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
Range GetSupportedBitrate();
|
||||
|
||||
/**
|
||||
* @brief Get supported channel range.
|
||||
* @return Returns the range of supported channel.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
Range GetSupportedChannel();
|
||||
|
||||
/**
|
||||
* @brief Get supported audio raw format range.
|
||||
* @return Returns the range of supported audio raw format. For details, see {@link AudioSampleFormat}.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
std::vector<int32_t> GetSupportedFormats();
|
||||
|
||||
/**
|
||||
* @brief Get supported audio samplerates.
|
||||
* @return Returns an array of supported samplerates.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
std::vector<int32_t> GetSupportedSampleRates();
|
||||
|
||||
/**
|
||||
* @brief Get supported codec profile number.
|
||||
* @return Returns an array of supported codec profile number. For details, see {@link AACProfile}.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
std::vector<int32_t> GetSupportedProfiles();
|
||||
|
||||
/**
|
||||
* @brief Get supported codec level array.
|
||||
* @return Returns an array of supported codec level number.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
std::vector<int32_t> GetSupportedLevels();
|
||||
|
||||
/**
|
||||
* @brief Get supported encode complexity range.
|
||||
* @return Returns supported encode complexity range.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
Range GetSupportedComplexity();
|
||||
|
||||
@ -512,8 +512,8 @@ public:
|
||||
/**
|
||||
* @brief AVC Profile
|
||||
*
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
enum AVCProfile : int32_t {
|
||||
AVC_PROFILE_BASELINE = 0,
|
||||
@ -530,8 +530,8 @@ enum AVCProfile : int32_t {
|
||||
/**
|
||||
* @brief HEVC Profile
|
||||
*
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
enum HEVCProfile : int32_t {
|
||||
HEVC_PROFILE_MAIN = 0,
|
||||
@ -544,8 +544,8 @@ enum HEVCProfile : int32_t {
|
||||
/**
|
||||
* @brief MPEG2 Profile
|
||||
*
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
enum MPEG2Profile : int32_t {
|
||||
MPEG2_PROFILE_422 = 0,
|
||||
@ -559,8 +559,8 @@ enum MPEG2Profile : int32_t {
|
||||
/**
|
||||
* @brief MPEG4 Profile
|
||||
*
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
enum MPEG4Profile : int32_t {
|
||||
MPEG4_PROFILE_ADVANCED_CODING = 0,
|
||||
@ -584,8 +584,8 @@ enum MPEG4Profile : int32_t {
|
||||
/**
|
||||
* @brief H263 Profile
|
||||
*
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
enum H263Profile : int32_t {
|
||||
H263_PROFILE_BACKWARD_COMPATIBLE = 0,
|
||||
@ -602,8 +602,8 @@ enum H263Profile : int32_t {
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
enum VP8Profile : int32_t {
|
||||
VP8_PROFILE_MAIN = 0,
|
||||
@ -612,8 +612,8 @@ enum VP8Profile : int32_t {
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
enum AACProfile : int32_t {
|
||||
AAC_PROFILE_LC = 0,
|
||||
@ -628,8 +628,8 @@ enum AACProfile : int32_t {
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
enum AVCLevel : int32_t {
|
||||
AVC_LEVEL_1 = 0,
|
||||
@ -653,8 +653,8 @@ enum AVCLevel : int32_t {
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
enum HEVCLevel : int32_t {
|
||||
HEVC_LEVEL_1 = 0,
|
||||
@ -675,8 +675,8 @@ enum HEVCLevel : int32_t {
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
enum MPEG2Level : int32_t {
|
||||
MPEG2_LEVEL_LL = 0,
|
||||
@ -688,8 +688,8 @@ enum MPEG2Level : int32_t {
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
enum MPEG4Level : int32_t {
|
||||
MPEG4_LEVEL_0 = 0,
|
||||
@ -705,8 +705,8 @@ enum MPEG4Level : int32_t {
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
enum VideoEncodeBitrateMode : int32_t {
|
||||
/**
|
||||
|
@ -35,8 +35,8 @@ public:
|
||||
*
|
||||
* @param index The index of the track to add.
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t AddSourceTrackByID(uint32_t index) = 0;
|
||||
|
||||
@ -47,8 +47,8 @@ public:
|
||||
*
|
||||
* @param index The index of the track to remove.
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t RemoveSourceTrackByID(uint32_t index) = 0;
|
||||
|
||||
@ -58,10 +58,10 @@ public:
|
||||
* @param buffer The BufferElement pointer to store data.
|
||||
* @param attr The CodecBufferAttr pointer to store data attribute.
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t CopyCurrentSampleToBuf(AVCodecBufferElement *buffer, AVCodecBufferInfo *bufferInfo) = 0;
|
||||
virtual int32_t CopyCurrentSampleToBuf(AVBufferElement *buffer, AVCodecBufferInfo *bufferInfo) = 0;
|
||||
|
||||
/**
|
||||
* @brief All selected tracks seek near to the requested time according to the seek mode.
|
||||
@ -69,8 +69,8 @@ public:
|
||||
* @param mSeconds The seconds for seeking.
|
||||
* @param mode The mode for seeking. Value. For details, see {@link SeekMode}.
|
||||
* @return Returns {@link MSERR_OK} if success; returns an error code otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t SeekToTimeStamp(int64_t mSeconds, SeekMode mode) = 0;
|
||||
};
|
||||
@ -89,8 +89,8 @@ public:
|
||||
*
|
||||
* @param source The source model for demuxer.
|
||||
* @return Returns the designated demuxer.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
static std::shared_ptr<AVDemuxer> CreateWithSource(Source *source);
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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
|
||||
|
@ -31,8 +31,8 @@ public:
|
||||
*
|
||||
* @param uri The source model for demuxer.
|
||||
* @return Returns the designated demuxer.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
static Source(const std::string &uri);
|
||||
virtual ~Source() = default;
|
||||
@ -41,8 +41,8 @@ public:
|
||||
* @brief Count number of the track in source.
|
||||
*
|
||||
* @return Returns the tracks's count.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual uint32_t GetTrackCount() = 0;
|
||||
|
||||
@ -51,8 +51,8 @@ public:
|
||||
*
|
||||
* @param trackId The index of the track.
|
||||
* @return Returns {@link AVSourceTrack} if success; returns nullptr otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual std::shared_ptr<SourceTrack> LoadSourceTrackByID(uint32_t trackId) = 0;
|
||||
|
||||
@ -68,8 +68,8 @@ public:
|
||||
*
|
||||
* @param formatContext The ffmpeg source model.
|
||||
* @param trackId The index of the track.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
SourceTrack(const AVFormatContext &formatContext, uint32_t trackId);
|
||||
virtual ~SourceTrack() = default;
|
||||
@ -79,8 +79,8 @@ public:
|
||||
*
|
||||
* @param format The parameters.
|
||||
* @return Returns {@link MSEER_OK} if success; returns nullptr otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual uint32_t SetParameter(const Format ¶m) = 0;
|
||||
|
||||
@ -88,8 +88,8 @@ public:
|
||||
* @brief Gets the parameters of the track.
|
||||
*
|
||||
* @return Returns {@link Format} if success; returns nullptr otherwise.
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual std::shared_ptr<Format> GetTrackFormat() = 0;
|
||||
private:
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
namespace AVCodec {
|
||||
enum FormatDataType : uint32_t {
|
||||
/* None */
|
||||
FORMAT_TYPE_NONE,
|
||||
@ -250,6 +250,6 @@ public:
|
||||
private:
|
||||
FormatDataMap formatMap_;
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
||||
#endif // FORMAT_H
|
||||
|
@ -36,13 +36,13 @@ typedef struct OH_AVSourceTrack OH_AVSourceTrack;
|
||||
* @brief Define the buffer struct when get input or output buffer
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.CodecBase
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
typedef struct OH_AVBufferElement {
|
||||
/* pointer to the buffer*/
|
||||
uint8_t *buffer,
|
||||
/* The size of the data contained in the Buffer in bytes */
|
||||
size_t size,
|
||||
OH_AVMemory *buffer,
|
||||
/* pointer to the metadata*/
|
||||
OH_AVMemory *metadata,
|
||||
} OH_AVBufferElement;
|
||||
|
||||
|
||||
@ -50,7 +50,7 @@ typedef struct OH_AVBufferElement {
|
||||
* @brief Enumerate the categories of OH_AVCodec's Buffer tags
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.CodecBase
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
typedef enum OH_AVCodecBufferFlags {
|
||||
AVCODEC_BUFFER_FLAGS_NONE = 0,
|
||||
@ -68,7 +68,7 @@ typedef enum OH_AVCodecBufferFlags {
|
||||
* @brief Define the Buffer description information of OH_AVCodec
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.CodecBase
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
typedef struct OH_AVCodecBufferAttr {
|
||||
/* Presentation timestamp of this Buffer in microseconds */
|
||||
@ -79,6 +79,8 @@ typedef struct OH_AVCodecBufferAttr {
|
||||
int32_t offset;
|
||||
/* The flags this Buffer has, which is also a combination of multiple {@link OH_AVCodecBufferFlags}. */
|
||||
uint32_t flags;
|
||||
/* The index of the track which this Buffer belongs. */
|
||||
uint32_t trackId;
|
||||
} OH_AVCodecBufferAttr;
|
||||
|
||||
/**
|
||||
@ -89,7 +91,7 @@ typedef struct OH_AVCodecBufferAttr {
|
||||
* @param errorCode specific error code
|
||||
* @param userData User specific data
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
typedef void (*OH_AVCodecOnError)(OH_AVCodec *codec, int32_t errorCode, void *userData);
|
||||
|
||||
@ -102,7 +104,7 @@ typedef void (*OH_AVCodecOnError)(OH_AVCodec *codec, int32_t errorCode, void *us
|
||||
* @param format New output stream description information
|
||||
* @param userData User specific data
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
typedef void (*OH_AVCodecOnFormatChanged)(OH_AVCodec *codec, OH_AVFormat *format, void *userData);
|
||||
|
||||
@ -115,9 +117,9 @@ typedef void (*OH_AVCodecOnFormatChanged)(OH_AVCodec *codec, OH_AVFormat *format
|
||||
* @param data New available input buffer.
|
||||
* @param userData User specific data
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
typedef void (*OH_AVCodecOnInputDataReady)(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, void *userData);
|
||||
typedef void (*OH_AVCodecOnInputDataReady)(OH_AVCodec *codec, uint32_t index, OH_AVBufferElement *data, void *userData);
|
||||
|
||||
/**
|
||||
* @brief When new output data is generated during the operation of OH_AVCodec, the function pointer will be
|
||||
@ -131,9 +133,9 @@ typedef void (*OH_AVCodecOnInputDataReady)(OH_AVCodec *codec, uint32_t index, OH
|
||||
* @param attr The description of the new output Buffer, please refer to {@link OH_AVCodecBufferAttr}
|
||||
* @param userData specified data
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
typedef void (*OH_AVCodecOnOutputDataReady)(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data,
|
||||
typedef void (*OH_AVCodecOnOutputDataReady)(OH_AVCodec *codec, uint32_t index, OH_AVBufferElement *data,
|
||||
OH_AVCodecBufferAttr *attr, void *userData);
|
||||
|
||||
/**
|
||||
@ -146,7 +148,7 @@ typedef void (*OH_AVCodecOnOutputDataReady)(OH_AVCodec *codec, uint32_t index, O
|
||||
* @param onInputDataReady Monitoring codec requires input data, refer to {@link OH_AVCodecOnInputDataReady}
|
||||
* @param onOutputDataReady Monitor codec to generate output data, refer to {@link OH_AVCodecOnOutputDataReady}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
typedef struct OH_AVCodecCallback {
|
||||
OH_AVCodecOnError onError;
|
||||
@ -159,7 +161,7 @@ typedef struct OH_AVCodecCallback {
|
||||
* @brief Enumerates the MIME types of audio and video codecs
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.CodecBase
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
extern const char *OH_AVCODEC_MIMETYPE_VIDEO_AVC;
|
||||
extern const char *OH_AVCODEC_MIMETYPE_AUDIO_AAC;
|
||||
@ -168,7 +170,7 @@ extern const char *OH_AVCODEC_MIMETYPE_AUDIO_AAC;
|
||||
* @brief The extra data's key of surface Buffer
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.CodecBase
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
/* Key for timeStamp in surface's extraData, value type is int64 */
|
||||
extern const char *OH_ED_KEY_TIME_STAMP;
|
||||
@ -179,7 +181,7 @@ extern const char *OH_ED_KEY_EOS;
|
||||
* @brief Provides the uniform container for storing the media description.
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.CodecBase
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
/* Key for track type, value type is uint8_t, see @OH_MediaType. */
|
||||
extern const char *OH_MD_KEY_TRACK_TYPE;
|
||||
@ -218,7 +220,7 @@ extern const char *OH_MD_KEY_ROTATION;
|
||||
* @brief Media type.
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.CodecBase
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
typedef enum OH_MediaType {
|
||||
/* track is audio. */
|
||||
@ -231,7 +233,7 @@ typedef enum OH_MediaType {
|
||||
* @brief AVC Profile
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.CodecBase
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
typedef enum OH_AVCProfile {
|
||||
AVC_PROFILE_BASELINE = 0,
|
||||
@ -243,7 +245,7 @@ typedef enum OH_AVCProfile {
|
||||
* @brief AAC Profile
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.CodecBase
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
typedef enum OH_AACProfile {
|
||||
AAC_PROFILE_LC = 0,
|
||||
@ -253,7 +255,7 @@ typedef enum OH_AACProfile {
|
||||
* @brief Seek Mode
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.CodecBase
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
typedef enum OH_AVSeekMode {
|
||||
SEEK_MODE_NEXT_SYNC = 0,
|
||||
|
@ -32,7 +32,7 @@ extern "C" {
|
||||
* @param mime mime type description string
|
||||
* @return Returns a Pointer to an OH_AVCodec instance
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVCodec *OH_AVCodec_CreateEncoderByMime(const char *mime);
|
||||
|
||||
@ -42,7 +42,7 @@ OH_AVCodec *OH_AVCodec_CreateEncoderByMime(const char *mime);
|
||||
* @param mime mime type description string
|
||||
* @return Returns a Pointer to an OH_AVCodec instance
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVCodec *OH_AVCodec_CreateDecoderByMime(const char *mime);
|
||||
|
||||
@ -52,7 +52,7 @@ OH_AVCodec *OH_AVCodec_CreateDecoderByMime(const char *mime);
|
||||
* @param name name description string
|
||||
* @return Returns a Pointer to an OH_AVCodec instance
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVCodec *OH_AVCodec_CreateByName(const char *name);
|
||||
|
||||
@ -63,7 +63,7 @@ OH_AVCodec *OH_AVCodec_CreateByName(const char *name);
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCodec_Destroy(OH_AVCodec *codec);
|
||||
|
||||
@ -77,20 +77,20 @@ OH_AVErrCode OH_AVCodec_Destroy(OH_AVCodec *codec);
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCodec_SetCallback(OH_AVCodec *codec, OH_AVCodecCallback callback, void *userData);
|
||||
|
||||
/**
|
||||
* @brief To configure the codec, typically, you need to configure the description information of the decoded
|
||||
* video track, which can be extracted from the container. This interface must be called before Start is called.
|
||||
* @brief To configure the codec, typically, you would get the fotmat from an extractor for decoding.
|
||||
* This interface must be called before Start is called.
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.Codec
|
||||
* @param codec Pointer to an OH_AVCodec instance
|
||||
* @param format A pointer to an OH_AVFormat to give the description of the video track to be decoded
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCodec_Configure(OH_AVCodec *codec, OH_AVFormat *format);
|
||||
|
||||
@ -102,7 +102,7 @@ OH_AVErrCode OH_AVCodec_Configure(OH_AVCodec *codec, OH_AVFormat *format);
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCodec_Start(OH_AVCodec *codec);
|
||||
|
||||
@ -114,7 +114,7 @@ OH_AVErrCode OH_AVCodec_Start(OH_AVCodec *codec);
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCodec_Stop(OH_AVCodec *codec);
|
||||
|
||||
@ -127,7 +127,7 @@ OH_AVErrCode OH_AVCodec_Stop(OH_AVCodec *codec);
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCodec_Flush(OH_AVCodec *codec);
|
||||
|
||||
@ -139,7 +139,7 @@ OH_AVErrCode OH_AVCodec_Flush(OH_AVCodec *codec);
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCodec_Reset(OH_AVCodec *codec);
|
||||
|
||||
@ -151,7 +151,7 @@ OH_AVErrCode OH_AVCodec_Reset(OH_AVCodec *codec);
|
||||
* @param codec Pointer to an OH_AVCodec instance
|
||||
* @return Returns a pointer to an OH_AVFormat instance
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVFormat *OH_AVCodec_GetOutputFormat(OH_AVCodec *codec);
|
||||
|
||||
@ -164,10 +164,34 @@ OH_AVFormat *OH_AVCodec_GetOutputFormat(OH_AVCodec *codec);
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCodec_SetParameter(OH_AVCodec *codec, OH_AVFormat *format);
|
||||
|
||||
/**
|
||||
* @brief Get the index of the next ready input buffer.
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.Codec
|
||||
* @param codec Pointer to an OH_AVCodec instance
|
||||
* @param timeoutUs timeoutUs
|
||||
* @return Returns non-negtive value of the buffer index,
|
||||
* otherwise returns negtive value for invalid buffer index
|
||||
* @since 10
|
||||
* @version 4.0
|
||||
*/
|
||||
int32_t OH_AVCodec_DequeueInputBuffer(OH_AVCodec *codec, int64_t timeoutUs);
|
||||
|
||||
/**
|
||||
* @brief Get an input buffer.
|
||||
* The buffer index must be odbtained from OH_AVCodec_DequeueInputBuffer, and not queued yet.
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.Codec
|
||||
* @param codec Pointer to an OH_AVCodec instance
|
||||
* @param index The index value corresponding to the input Buffer
|
||||
* @return Returns a pointer to an BufferElement instance
|
||||
* @since 10
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVBufferElement* OH_AVCodec_GetInputBuffer(OH_AVCodec *codec, size_t index);
|
||||
|
||||
/**
|
||||
* @brief Submit the input buffer filled with data to the codec. The {@link OH_AVCodecOnInputDataReady} callback
|
||||
* will report the available input buffer and the corresponding index value. Once the buffer with the specified index
|
||||
@ -182,56 +206,34 @@ OH_AVErrCode OH_AVCodec_SetParameter(OH_AVCodec *codec, OH_AVFormat *format);
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCodec_QueueInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr);
|
||||
|
||||
/**
|
||||
* @brief Get an input buffer.
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.Codec
|
||||
* @param codec Pointer to an OH_AVCodec instance
|
||||
* @param index The index value corresponding to the input Buffer
|
||||
* @return Returns a pointer to an BufferElement instance
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVBufferElement* OH_AVCodec_GetInputBuffer(OH_AVCodec *codec, size_t index);
|
||||
|
||||
/**
|
||||
* @brief Get an output buffer.
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.Codec
|
||||
* @param codec Pointer to an OH_AVCodec instance
|
||||
* @param index The index value corresponding to the output Buffer
|
||||
* @return Returns a pointer to an BufferElement instance
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVBufferElement* OH_AVCodec_GetOutputBuffer(OH_AVCodec *codec, size_t index);
|
||||
|
||||
/**
|
||||
* @brief Get the index of the next ready input buffer.
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.Codec
|
||||
* @param codec Pointer to an OH_AVCodec instance
|
||||
* @param timeoutUs timeoutUs
|
||||
* @return Returns 0 or positive of the buffer index,
|
||||
* otherwise returns negtive value for invalid buffer index
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OH_AVCodec_DequeueInputBuffer(OH_AVCodec *codec, int64_t timeoutUs);
|
||||
|
||||
/**
|
||||
* @brief Get the index of the next ready output buffer of processed data.
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.Codec
|
||||
* @param codec Pointer to an OH_AVCodec instance
|
||||
* @param timeoutUs timeoutUs
|
||||
* @return Returns 0 or positive of the buffer index,
|
||||
* @return Returns non-negtive value of the buffer index,
|
||||
* otherwise returns negtive value for invalid buffer index
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
int32_t OH_AVCodec_DequeueOutputBuffer(OH_AVCodec *codec, int64_t timeoutUs);
|
||||
|
||||
/**
|
||||
* @brief Get an output buffer.
|
||||
* The buffer index must be odbtained from OH_AVCodec_DequeueOutputBuffer.
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.Codec
|
||||
* @param codec Pointer to an OH_AVCodec instance
|
||||
* @param index The index value corresponding to the output Buffer
|
||||
* @return Returns a pointer to an BufferElement instance
|
||||
* @since 10
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVBufferElement* OH_AVCodec_GetOutputBuffer(OH_AVCodec *codec, size_t index);
|
||||
|
||||
/**
|
||||
* @brief Return the processed output Buffer to the codec.
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.Codec
|
||||
@ -240,7 +242,7 @@ int32_t OH_AVCodec_DequeueOutputBuffer(OH_AVCodec *codec, int64_t timeoutUs);
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCodec_ReleaseOutputData(OH_AVCodec *codec, uint32_t index);
|
||||
|
||||
@ -252,7 +254,7 @@ OH_AVErrCode OH_AVCodec_ReleaseOutputData(OH_AVCodec *codec, uint32_t index);
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCodec_VideoEncoderGetSurface(OH_AVCodec *codec, OHNativeWindow **window);
|
||||
|
||||
@ -265,7 +267,7 @@ OH_AVErrCode OH_AVCodec_VideoEncoderGetSurface(OH_AVCodec *codec, OHNativeWindow
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCodec_VideoEncoderGetPersistentSurface(OHNativeWindow **window);
|
||||
|
||||
@ -279,7 +281,7 @@ OH_AVErrCode OH_AVCodec_VideoEncoderGetPersistentSurface(OHNativeWindow **window
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCodec_VideoEncoderSetSurface(OH_AVCodec *codec, OHNativeWindow *window);
|
||||
|
||||
@ -292,7 +294,7 @@ OH_AVErrCode OH_AVCodec_VideoEncoderSetSurface(OH_AVCodec *codec, OHNativeWindow
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCodec_VideoDecoderSetSurface(OH_AVCodec *codec, OHNativeWindow *window);
|
||||
|
||||
@ -306,7 +308,7 @@ OH_AVErrCode OH_AVCodec_VideoDecoderSetSurface(OH_AVCodec *codec, OHNativeWindow
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCodec_VideoDecoderRenderFrame(OH_AVCodec *codec, uint32_t index);
|
||||
|
||||
@ -318,7 +320,7 @@ OH_AVErrCode OH_AVCodec_VideoDecoderRenderFrame(OH_AVCodec *codec, uint32_t inde
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specific error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVCodec_VideoEncoderNotifyEndOfStream(OH_AVCodec *codec);
|
||||
|
||||
|
@ -30,7 +30,7 @@ extern "C"{
|
||||
* @param source Pointer to an OH_AVSource instance.
|
||||
* @return Returns a pointer to an OH_AVDemuxer instance
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVDemuxer *OH_AVDemuxer_CreateWithSource(OH_AVSource *source);
|
||||
|
||||
@ -41,7 +41,7 @@ OH_AVDemuxer *OH_AVDemuxer_CreateWithSource(OH_AVSource *source);
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specifis error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVDemuxer_Destroy(OH_AVDemuxer *demuxer);
|
||||
|
||||
@ -56,7 +56,7 @@ OH_AVErrCode OH_AVDemuxer_Destroy(OH_AVDemuxer *demuxer);
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specifis error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVDemuxer_AddSourceTrackByID(OH_AVDemuxer *demuxer, uint32_t trackId);
|
||||
|
||||
@ -70,7 +70,7 @@ OH_AVErrCode OH_AVDemuxer_AddSourceTrackByID(OH_AVDemuxer *demuxer, uint32_t tra
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specifis error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVDemuxer_RemoveSourceTrackByID(OH_AVDemuxer *demuxer, uint32_t trackId);
|
||||
|
||||
@ -84,7 +84,7 @@ OH_AVErrCode OH_AVDemuxer_RemoveSourceTrackByID(OH_AVDemuxer *demuxer, uint32_t
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specifis error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVDemuxer_CopyCurrentSampleToBuf(OH_AVDemuxer *demuxer, OH_AVBufferElement *buffer, OH_AVCodecBufferAttr *bufferInfo);
|
||||
|
||||
@ -102,7 +102,7 @@ OH_AVErrCode OH_AVDemuxer_CopyCurrentSampleToBuf(OH_AVDemuxer *demuxer, OH_AVBuf
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specifis error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVDemuxer_SeekToTimeStamp(OH_AVDemuxer *demuxer, int64_t mSeconds, OH_AVSeekMode mode);
|
||||
|
||||
|
@ -23,7 +23,7 @@ extern "C" {
|
||||
* @brief AV error code
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.Core
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
typedef enum OH_AVErrCode {
|
||||
/**
|
||||
|
@ -31,7 +31,7 @@ typedef struct OH_AVFormat OH_AVFormat;
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.Core
|
||||
* @return Returns a pointer to an OH_AVFormat instance
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
struct OH_AVFormat *OH_AVFormat_Create(void);
|
||||
|
||||
@ -41,7 +41,7 @@ struct OH_AVFormat *OH_AVFormat_Create(void);
|
||||
* @param format pointer to an OH_AVFormat instance
|
||||
* @return void
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
void OH_AVFormat_Destroy(struct OH_AVFormat *format);
|
||||
|
||||
@ -52,7 +52,7 @@ void OH_AVFormat_Destroy(struct OH_AVFormat *format);
|
||||
* @param from pointer to the OH_AVFormat handle of the copied data
|
||||
* @return The return value is TRUE for success, FALSE for failure
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
bool OH_AVFormat_Copy(struct OH_AVFormat *to, struct OH_AVFormat *from);
|
||||
|
||||
@ -64,7 +64,7 @@ bool OH_AVFormat_Copy(struct OH_AVFormat *to, struct OH_AVFormat *from);
|
||||
* @param value written data
|
||||
* @return The return value is TRUE for success, FALSE for failure
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
bool OH_AVFormat_SetIntValue(struct OH_AVFormat *format, const char *key, int32_t value);
|
||||
|
||||
@ -76,7 +76,7 @@ bool OH_AVFormat_SetIntValue(struct OH_AVFormat *format, const char *key, int32_
|
||||
* @param value written data
|
||||
* @return The return value is TRUE for success, FALSE for failure
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
bool OH_AVFormat_SetLongValue(struct OH_AVFormat *format, const char *key, int64_t value);
|
||||
|
||||
@ -88,7 +88,7 @@ bool OH_AVFormat_SetLongValue(struct OH_AVFormat *format, const char *key, int64
|
||||
* @param value written data
|
||||
* @return The return value is TRUE for success, FALSE for failure
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
bool OH_AVFormat_SetFloatValue(struct OH_AVFormat *format, const char *key, float value);
|
||||
|
||||
@ -100,7 +100,7 @@ bool OH_AVFormat_SetFloatValue(struct OH_AVFormat *format, const char *key, floa
|
||||
* @param value written data
|
||||
* @return The return value is TRUE for success, FALSE for failure
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
bool OH_AVFormat_SetDoubleValue(struct OH_AVFormat *format, const char *key, double value);
|
||||
|
||||
@ -112,7 +112,7 @@ bool OH_AVFormat_SetDoubleValue(struct OH_AVFormat *format, const char *key, dou
|
||||
* @param value written data
|
||||
* @return The return value is TRUE for success, FALSE for failure
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
bool OH_AVFormat_SetStringValue(struct OH_AVFormat *format, const char *key, const char *value);
|
||||
|
||||
@ -125,7 +125,7 @@ bool OH_AVFormat_SetStringValue(struct OH_AVFormat *format, const char *key, con
|
||||
* @param size written data length
|
||||
* @return The return value is TRUE for success, FALSE for failure
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
bool OH_AVFormat_SetBuffer(struct OH_AVFormat *format, const char *key, const uint8_t *addr, size_t size);
|
||||
|
||||
@ -137,7 +137,7 @@ bool OH_AVFormat_SetBuffer(struct OH_AVFormat *format, const char *key, const ui
|
||||
* @param out read data
|
||||
* @return The return value is TRUE for success, FALSE for failure
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
bool OH_AVFormat_GetIntValue(struct OH_AVFormat *format, const char *key, int32_t *out);
|
||||
|
||||
@ -149,7 +149,7 @@ bool OH_AVFormat_GetIntValue(struct OH_AVFormat *format, const char *key, int32_
|
||||
* @param out read data
|
||||
* @return The return value is TRUE for success, FALSE for failure
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
bool OH_AVFormat_GetLongValue(struct OH_AVFormat *format, const char *key, int64_t *out);
|
||||
|
||||
@ -161,7 +161,7 @@ bool OH_AVFormat_GetLongValue(struct OH_AVFormat *format, const char *key, int64
|
||||
* @param out read data
|
||||
* @return The return value is TRUE for success, FALSE for failure
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
bool OH_AVFormat_GetFloatValue(struct OH_AVFormat *format, const char *key, float *out);
|
||||
|
||||
@ -173,7 +173,7 @@ bool OH_AVFormat_GetFloatValue(struct OH_AVFormat *format, const char *key, floa
|
||||
* @param out read data
|
||||
* @return The return value is TRUE for success, FALSE for failure
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
bool OH_AVFormat_GetDoubleValue(struct OH_AVFormat *format, const char *key, double *out);
|
||||
|
||||
@ -186,7 +186,7 @@ bool OH_AVFormat_GetDoubleValue(struct OH_AVFormat *format, const char *key, dou
|
||||
* and Format is destroyed. If the caller needs to hold it for a long time, it must copy the memory
|
||||
* @return The return value is TRUE for success, FALSE for failure
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
bool OH_AVFormat_GetStringValue(struct OH_AVFormat *format, const char *key, const char **out);
|
||||
|
||||
@ -200,7 +200,7 @@ bool OH_AVFormat_GetStringValue(struct OH_AVFormat *format, const char *key, con
|
||||
* @param size Length of read and write data
|
||||
* @return The return value is TRUE for success, FALSE for failure
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
bool OH_AVFormat_GetBuffer(struct OH_AVFormat *format, const char *key, uint8_t **addr, size_t *size);
|
||||
|
||||
@ -210,7 +210,7 @@ bool OH_AVFormat_GetBuffer(struct OH_AVFormat *format, const char *key, uint8_t
|
||||
* @param format pointer to an OH_AVFormat instance
|
||||
* @return Returns a string consisting of key and data
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
const char *OH_AVFormat_DumpInfo(struct OH_AVFormat *format);
|
||||
|
||||
|
@ -30,7 +30,7 @@ typedef struct OH_AVMemory OH_AVMemory;
|
||||
* @param mem Encapsulate OH_AVMemory structure instance pointer
|
||||
* @return the memory's virtual address if the memory is valid, otherwise nullptr.
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
uint8_t *OH_AVMemory_GetAddr(struct OH_AVMemory *mem);
|
||||
|
||||
@ -40,7 +40,7 @@ uint8_t *OH_AVMemory_GetAddr(struct OH_AVMemory *mem);
|
||||
* @param mem Encapsulate OH_AVMemory structure instance pointer
|
||||
* @return the memory's size if the memory is valid, otherwise -1.
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
int32_t OH_AVMemory_GetSize(struct OH_AVMemory *mem);
|
||||
|
||||
|
@ -32,7 +32,7 @@ extern "C"{
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specifis error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVSource *OH_AVSource_CreateWithURI(char *uri);
|
||||
|
||||
@ -45,7 +45,7 @@ OH_AVSource *OH_AVSource_CreateWithURI(char *uri);
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specifis error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVSource *OH_AVSource_CreateWithFd(int32_t fd, int64_t offset, int64_t size);
|
||||
|
||||
@ -56,7 +56,7 @@ OH_AVSource *OH_AVSource_CreateWithFd(int32_t fd, int64_t offset, int64_t size);
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specifis error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVSource_Destroy(OH_AVSource *source);
|
||||
|
||||
@ -66,7 +66,7 @@ OH_AVErrCode OH_AVSource_Destroy(OH_AVSource *source);
|
||||
* @param source Pointer to an OH_AVSource instance.
|
||||
* @return Returns the count of tracks in the source.
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
uint32_t OH_AVSource_GetTrackCount(OH_AVSource *source);
|
||||
|
||||
@ -77,7 +77,7 @@ uint32_t OH_AVSource_GetTrackCount(OH_AVSource *source);
|
||||
* @param trackId The identifier of the track to load.
|
||||
* @return Returns the track's format at the specified index.
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVSourceTrack *OH_AVSource_LoadSourceTrackByID(OH_AVSource *source, uint32_t trackId);
|
||||
|
||||
@ -89,7 +89,7 @@ OH_AVSourceTrack *OH_AVSource_LoadSourceTrackByID(OH_AVSource *source, uint32_t
|
||||
* @return Returns AV_ERR_OK if the execution is successful,
|
||||
* otherwise returns a specifis error code, refer to {@link OH_AVErrCode}
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVErrCode OH_AVSourceTrack_SetParameter(OH_AVSourceTrack *sourceTrack, OH_AVFormat *param);
|
||||
|
||||
@ -99,7 +99,7 @@ OH_AVErrCode OH_AVSourceTrack_SetParameter(OH_AVSourceTrack *sourceTrack, OH_AVF
|
||||
* @param sourceTrack Pointer to an AVSourceTrack instance.
|
||||
* @return Returns the track's format.
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
* @version 4.0
|
||||
*/
|
||||
OH_AVFormat *OH_AVSourceTrack_GetTrackFormat(OH_AVSourceTrack *sourceTrack);
|
||||
|
||||
|
118
services/dfx/avcodec_dfx.cpp
Normal file
118
services/dfx/avcodec_dfx.cpp
Normal file
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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 <avcodec_dfx.h>
|
||||
#include <unistd.h>
|
||||
#include "securec.h"
|
||||
#include "avcodec_log.h"
|
||||
#include "avcodec_errors.h"
|
||||
#include "hitrace_meter.h"
|
||||
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AVCodecDFX"};
|
||||
constexpr uint32_t MAX_STRING_SIZE = 256;
|
||||
constexpr char HISYSEVENT_DOMAIN_AVCODEC[] = "AVCODEC";
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec {
|
||||
bool AVCodecEvent::CreateMsg(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
char msg[MAX_STRING_SIZE] = {0};
|
||||
if (vsnprintf_s(msg, sizeof(msg), sizeof(msg) - 1, format, args) < 0) {
|
||||
AVCODEC_LOGE("failed to call vsnprintf_s");
|
||||
va_end(args);
|
||||
return false;
|
||||
}
|
||||
va_end(args);
|
||||
msg_ = msg;
|
||||
return true;
|
||||
}
|
||||
|
||||
void AVCodecEvent::EventWrite(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
|
||||
std::string module)
|
||||
{
|
||||
int32_t pid = getpid();
|
||||
uint32_t uid = getuid();
|
||||
HiSysEventWrite(HISYSEVENT_DOMAIN_AVCODEC, eventName, type,
|
||||
"PID", pid,
|
||||
"UID", uid,
|
||||
"MODULE", module,
|
||||
"MSG", msg_);
|
||||
}
|
||||
|
||||
void BehaviorEventWrite(std::string status, std::string moudle)
|
||||
{
|
||||
AVCodecEvent event;
|
||||
if (event.CreateMsg("%s, current state is: %s", "state change", status.c_str())) {
|
||||
event.EventWrite("AVCODEC_STATE", OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, moudle);
|
||||
} else {
|
||||
AVCODEC_LOGW("Failed to call CreateMsg");
|
||||
}
|
||||
}
|
||||
|
||||
void FaultEventWrite(std::string msg, std::string moudle)
|
||||
{
|
||||
AVCodecEvent event;
|
||||
if (event.CreateMsg("%s", msg.c_str())) {
|
||||
event.EventWrite("AVCODEC_ERR", OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, moudle);
|
||||
} else {
|
||||
AVCODEC_LOGW("Failed to call CreateMsg");
|
||||
}
|
||||
}
|
||||
|
||||
void StatisticEventWrite(std::string msg, std::string moudle)
|
||||
{
|
||||
AVCodecEvent event;
|
||||
if (event.CreateMsg("%s", msg.c_str())) {
|
||||
event.EventWrite("AVCODEC_STATISTIC", OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC, moudle);
|
||||
} else {
|
||||
AVCODEC_LOGW("Failed to call CreateMsg");
|
||||
}
|
||||
}
|
||||
|
||||
AVCodecTrace::AVCodecTrace(const std::string &funcName)
|
||||
{
|
||||
StartTrace(HITRACE_TAG_ZMEDIA, funcName);
|
||||
isSync_ = true;
|
||||
}
|
||||
|
||||
void AVCodecTrace::TraceBegin(const std::string &funcName, int32_t taskId)
|
||||
{
|
||||
StartAsyncTrace(HITRACE_TAG_ZMEDIA, funcName, taskId);
|
||||
}
|
||||
|
||||
void AVCodecTrace::TraceEnd(const std::string &funcName, int32_t taskId)
|
||||
{
|
||||
FinishAsyncTrace(HITRACE_TAG_ZMEDIA, funcName, taskId);
|
||||
}
|
||||
|
||||
void AVCodecTrace::CounterTrace(const std::string &varName, int32_t val)
|
||||
{
|
||||
CountTrace(HITRACE_TAG_ZMEDIA, varName, val);
|
||||
}
|
||||
|
||||
AVCodecTrace::~AVCodecTrace()
|
||||
{
|
||||
if (isSync_) {
|
||||
FinishTrace(HITRACE_TAG_ZMEDIA);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
55
services/dfx/include/avcodec_dfx.h
Normal file
55
services/dfx/include/avcodec_dfx.h
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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 AVCODEC_DFX_H
|
||||
#define AVCODEC_DFX_H
|
||||
|
||||
#include <string>
|
||||
#include <refbase.h>
|
||||
#include "nocopyable.h"
|
||||
#include "hisysevent.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec {
|
||||
|
||||
class __attribute__((visibility("default"))) AVCodecEvent : public NoCopyable {
|
||||
public:
|
||||
AVCodecEvent() = default;
|
||||
~AVCodecEvent() = default;
|
||||
bool CreateMsg(const char *format, ...) __attribute__((__format__(printf, 2, 3)));
|
||||
void EventWrite(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
|
||||
std::string module);
|
||||
private:
|
||||
std::string msg_;
|
||||
};
|
||||
|
||||
__attribute__((visibility("default"))) void BehaviorEventWrite(std::string status, std::string moudle);
|
||||
__attribute__((visibility("default"))) void FaultEventWrite(std::string msg, std::string moudle);
|
||||
__attribute__((visibility("default"))) void StatisticEventWrite(std::string msg, std::string moudle);
|
||||
|
||||
class __attribute__((visibility("default"))) AVCodecTrace : public NoCopyable {
|
||||
public:
|
||||
explicit AVCodecTrace(const std::string &funcName);
|
||||
static void TraceBegin(const std::string &funcName, int32_t taskId);
|
||||
static void TraceEnd(const std::string &funcName, int32_t taskId);
|
||||
static void CounterTrace(const std::string &varName, int32_t val);
|
||||
~AVCodecTrace();
|
||||
private:
|
||||
bool isSync_ = false;
|
||||
};
|
||||
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
||||
#endif // AVCODEC_DFX_H
|
102
services/dfx/include/avcodec_log.h
Normal file
102
services/dfx/include/avcodec_log.h
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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 <hilog/log.h>
|
||||
#include <cinttypes>
|
||||
|
||||
#ifndef AVCODEC_LOG_H
|
||||
#define AVCODEC_LOG_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec {
|
||||
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN 0xD002BAC
|
||||
|
||||
#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
|
||||
|
||||
#define AVCODEC_LOG(func, fmt, args...) \
|
||||
do { \
|
||||
(void)func(LABEL, fmt, ##args); \
|
||||
} while (0)
|
||||
|
||||
#define AVCODEC_LOGD(fmt, ...) AVCODEC_LOG(::OHOS::HiviewDFX::HiLog::Debug, fmt, ##__VA_ARGS__)
|
||||
#define AVCODEC_LOGI(fmt, ...) AVCODEC_LOG(::OHOS::HiviewDFX::HiLog::Info, fmt, ##__VA_ARGS__)
|
||||
#define AVCODEC_LOGW(fmt, ...) AVCODEC_LOG(::OHOS::HiviewDFX::HiLog::Warn, fmt, ##__VA_ARGS__)
|
||||
#define AVCODEC_LOGE(fmt, ...) AVCODEC_LOG(::OHOS::HiviewDFX::HiLog::Error, fmt, ##__VA_ARGS__)
|
||||
#define AVCODEC_LOGF(fmt, ...) AVCODEC_LOG(::OHOS::HiviewDFX::HiLog::Fatal, fmt, ##__VA_ARGS__)
|
||||
|
||||
#define CHECK_AND_RETURN(cond) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
AVCODEC_LOGE("%{public}s, check failed!", #cond); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_AND_RETURN_RET(cond, ret) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
AVCODEC_LOGE("%{public}s, check failed! ret = %{public}s", #cond, #ret); \
|
||||
return ret; \
|
||||
} \
|
||||
} while
|
||||
|
||||
#define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
AVCODEC_LOGE(fmt, ##__VA_ARGS__); \
|
||||
return ret; \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
#define CHECK_AND_RETURN_LOG(cond, fmt, ...) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
AVCODEC_LOGE(fmt, ##__VA_ARGS__); \
|
||||
return; \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
#define CHECK_AND_BREAK_LOG(cond, fmt, ...) \
|
||||
if (1) { \
|
||||
if (!(cond)) { \
|
||||
AVCODEC_LOGE(fmt, ##__VA_ARGS__); \
|
||||
break; \
|
||||
} \
|
||||
} else void (0)
|
||||
|
||||
#define CHECK_AND_BREAK(cond) \
|
||||
if (1) { \
|
||||
if (!(cond)) { \
|
||||
AVCODEC_LOGE("%{public}s, check failed!", #cond); \
|
||||
break; \
|
||||
} \
|
||||
} else void (0)
|
||||
|
||||
#define CHECK_AND_CONTINUE(cond) \
|
||||
if (1) { \
|
||||
if (!(cond)) { \
|
||||
AVCODEC_LOGE("%{public}s, check failed!", #cond); \
|
||||
continue; \
|
||||
} \
|
||||
} else void (0)
|
||||
|
||||
#define POINTER_MASK 0x00FFFFFF
|
||||
#define FAKE_POINTER(addr) (POINTER_MASK & reinterpret_cast<uintptr_t>(addr))
|
||||
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
||||
#endif // AVCODEC_LOG_H
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 "ffmpeg_demuxer_plugin.h"
|
||||
#include "avcodec_errors.h"
|
||||
#include "media_log.h"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "FFmpegDemuxerPlugin"};
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec{
|
||||
namespace Plugin {
|
||||
namespace Ffmpeg {
|
||||
Status FFmpegDemuxerPlugin::AddSourceTrackByID(uint32_t trackId)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(formatContext_ != nullptr,
|
||||
ErrCode::AVCSERR_DEMUXER_FAILED, "formatContext_ is empty!");
|
||||
CHECK_AND_RETURN_RET_LOG(trackId > 0 && trackId < static_cast<int32_t>(formatContext_->nb_streames),
|
||||
ErrCode::AVCSERR_INVALID_VAL, "trackId is invalid!");
|
||||
|
||||
OSAL::ScopedLock lock(mutex_);
|
||||
auto index = std::find_if(selectedTrackIds_.begin(), selectedTrackIds_.end(),
|
||||
[trackId](int32_t selectedId) {return trackId == selectedId; });
|
||||
if (index == selectedTrackIds_.end()) {
|
||||
selectedTrackIds_.push_back(trackId);
|
||||
}
|
||||
return ErrCode::AVCSERR_OK;
|
||||
}
|
||||
|
||||
Status FFmpegDemuxerPlugin::RemoveSourceTrackByID(uint32_t trackId)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(formatContext_ != nullptr, Status::ERROR_NULL_POINTER, "formatContext_ is empty");
|
||||
|
||||
OSAL::ScopedLock lock(mutex_);
|
||||
auto index = find_if(selectedTrackIds_.begin(), selectedTrackIds_.end(),
|
||||
[trackId](int32_t selectedId) {return trackId == selectedId; });
|
||||
if (index != selectedTrackIds_.end()) {
|
||||
selectedTrackIds_.erase(index);
|
||||
}
|
||||
|
||||
return ErrCode::AVCSERR_OK;
|
||||
}
|
||||
|
||||
} // Ffmpeg
|
||||
} // Plugin
|
||||
} // Media
|
||||
} // 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 FFMPEG_DEMUXER_PLUGIN_H
|
||||
#define FFMPEG_DEMUXER_PLUGIN_H
|
||||
|
||||
#include <memory>
|
||||
#include <stdint>
|
||||
#include <vector>
|
||||
#include "avcodec_common.h"
|
||||
#include "demuxer_plugin.h"
|
||||
#include "plugin/osal/thread/mutex.h"
|
||||
#include "source.h"
|
||||
#include "libavformat/avformat.h"
|
||||
|
||||
namespace OH{
|
||||
namespace AVCodec{
|
||||
namespace Plugin{
|
||||
namespace FFmpeg{
|
||||
class FFmpegDemuxerPlugin : public DemuxerPlugin{
|
||||
public:
|
||||
FFmpegDemuxerPlugin(Source source);
|
||||
~FFmpegDemuxerPlugin() override;
|
||||
|
||||
Status AddSourceTrackByID(uint32_t index) override;
|
||||
Status RemoveSourceTrackByID(uint32_t index) override;
|
||||
Status CopyCurrentSampleToBuf(AVCodecBufferElement *buffer, AVCodecBufferInfo *bufferInfo) override;
|
||||
Status SeekToTimeStamp(int64_t mSeconds, SeekMode mode) override;
|
||||
private:
|
||||
vector<int32_t> selectedTrackIds_;
|
||||
OSAL::Mutex mutex_ {};
|
||||
std::shared_ptr<AVFormatContext> formatContext_;
|
||||
};
|
||||
} // namespace FFmpeg
|
||||
} // namespace Plugin
|
||||
} // namespace AVCodec
|
||||
} // namespace OH
|
||||
#endif // FFMPEG_DEMUXER_PLUGIN_H
|
@ -36,8 +36,8 @@ public:
|
||||
* All player functions must be created and obtained first.
|
||||
*
|
||||
* @return Returns a valid pointer if the setting is successful;
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual std::shared_ptr<IAVCodecListService> CreateAVCodecListService() = 0;
|
||||
|
||||
@ -48,8 +48,8 @@ public:
|
||||
*
|
||||
* @param pointer to the codeclist service.
|
||||
* @return Returns a valid pointer if the setting is successful;
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t DestroyAVCodecListService(std::shared_ptr<IAVCodecListService> avCodecList) = 0;
|
||||
|
||||
@ -59,8 +59,8 @@ public:
|
||||
* All player functions must be created and obtained first.
|
||||
*
|
||||
* @return Returns a valid pointer if the setting is successful;
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual std::shared_ptr<IAVCodecService> CreateAVCodecService() = 0;
|
||||
|
||||
@ -71,8 +71,8 @@ public:
|
||||
*
|
||||
* @param pointer to the avcodec service.
|
||||
* @return Returns a valid pointer if the setting is successful;
|
||||
* @since 3.1
|
||||
* @version 3.1
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t DestroyAVCodecService(std::shared_ptr<IAVCodecService> avCodec) = 0;
|
||||
#endif
|
||||
@ -84,8 +84,8 @@ public:
|
||||
* All player functions must be created and obtained first.
|
||||
*
|
||||
* @return Returns a valid pointer if the setting is successful;
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual std::shared_ptr<IAVMetadataHelperService> CreateAVMetadataHelperService() = 0;
|
||||
|
||||
@ -96,8 +96,8 @@ public:
|
||||
*
|
||||
* @param pointer to the avmetadatahelper service.
|
||||
* @return Returns a valid pointer if the setting is successful;
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual int32_t DestroyAVMetadataHelperService(std::shared_ptr<IAVMetadataHelperService> avMetadataHelper) = 0;
|
||||
#endif
|
||||
@ -111,8 +111,8 @@ public:
|
||||
* Create Recorder Service and Player Service Through the Media Service.
|
||||
*
|
||||
* @return Returns IMediaService singleton;
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
static IMediaService &GetInstance();
|
||||
private:
|
||||
|
51
services/services/codec/server/include/avcodecbase.h
Normal file
51
services/services/codec/server/include/avcodecbase.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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 AVCODECBASE_H
|
||||
#define AVCODECBASE_H
|
||||
|
||||
#include <string>
|
||||
#include "avcodec_common.h"
|
||||
#include "surface.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec {
|
||||
class AVCodecBase {
|
||||
static std::shared_ptr<AVCodecBase> Create(const std::string& name);
|
||||
static std::shared_ptr<AVCodecBase> Create(bool isEncoder,const std::string& mime);
|
||||
virtual int32_t SetCallback(const std::shared_ptr<AVCodecCallBack>& callback) = 0;
|
||||
virtual int32_t Configure(const Format& format) = 0;
|
||||
virtual int32_t Start() = 0;
|
||||
virtual int32_t Pause() = 0;
|
||||
virtual int32_t Resume() = 0;
|
||||
virtual int32_t Stop() = 0;
|
||||
virtual int32_t Flush() = 0;
|
||||
virtual int32_t Reset() = 0;
|
||||
virtual int32_t Release() = 0;
|
||||
virtual int32_t NotifyEos() = 0;
|
||||
virtual int32_t SetParameter(const Format& format) = 0;
|
||||
virtual int32_t GetOutputFormat(Format& format) = 0;
|
||||
virtual sptr<Surface> CreateInputSurface() = 0;
|
||||
virtual int32_t SetInputSurface(sptr<Surface> surface) = 0;
|
||||
virtual int32_t SetOutputSurface(sptr<Surface> surface) = 0;
|
||||
virtual std::shared_ptr<AVBufferElement> GetInputBuffer(size_t index) = 0;
|
||||
virtual int32_t QueueInputBuffer(size_t index, const AVCodecBufferInfo& info) = 0;
|
||||
virtual std::shared_ptr<AVBufferElement> GetOutputBuffer(size_t index) = 0;
|
||||
virtual int32_t RenderOutputBuffer(size_t index) = 0;
|
||||
virtual int32_t ReleaseOutputBuffer(size_t index) = 0;
|
||||
virtual int32_t SignalRequestIDRFrame() = 0;
|
||||
};
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
||||
#endif // AVCODECBASE_H
|
28
services/services/codec/server/include/avcodeclistbase.h
Normal file
28
services/services/codec/server/include/avcodeclistbase.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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 AVCODECLISTBASE_H
|
||||
#define AVCODECLISTBASE_H
|
||||
|
||||
#include <string>
|
||||
#include "avcodec_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec {
|
||||
class AVCodecListBase {
|
||||
virtual int32_t GetCapabilityList(std::vector<CapabilityData>& caps) = 0;
|
||||
};
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
||||
#endif // AVCODECLISTBASE_H
|
80
services/utils/avdatasrcmemory.cpp
Normal file
80
services/utils/avdatasrcmemory.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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 "avdatasrcmemory.h"
|
||||
#include "media_errors.h"
|
||||
#include "media_log.h"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AVDataSrcMemory"};
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec {
|
||||
struct AVSharedMemoryBaseImpl : public AVDataSrcMemory {
|
||||
public:
|
||||
AVSharedMemoryBaseImpl(int32_t fd, int32_t size, uint32_t flags, const std::string &name)
|
||||
: AVDataSrcMemory(fd, size, flags, name) {}
|
||||
};
|
||||
|
||||
std::shared_ptr<AVSharedMemory> AVDataSrcMemory::CreateFromLocal(
|
||||
int32_t size, uint32_t flags, const std::string &name)
|
||||
{
|
||||
std::shared_ptr<AVDataSrcMemory> memory = std::make_shared<AVDataSrcMemory>(size, flags, name);
|
||||
int32_t ret = memory->Init();
|
||||
if (ret != MSERR_OK) {
|
||||
MEDIA_LOGE("Create avsharedmemory failed, ret = %{public}d", ret);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return memory;
|
||||
}
|
||||
|
||||
std::shared_ptr<AVSharedMemory> AVDataSrcMemory::CreateFromRemote(
|
||||
int32_t fd, int32_t size, uint32_t flags, const std::string &name)
|
||||
{
|
||||
std::shared_ptr<AVDataSrcMemory> memory = std::make_shared<AVSharedMemoryBaseImpl>(fd, size, flags, name);
|
||||
int32_t ret = memory->Init();
|
||||
if (ret != MSERR_OK) {
|
||||
MEDIA_LOGE("Create avsharedmemory failed, ret = %{public}d", ret);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return memory;
|
||||
}
|
||||
|
||||
AVDataSrcMemory::AVDataSrcMemory(int32_t size, uint32_t flags, const std::string &name)
|
||||
: AVSharedMemoryBase(size, flags, name)
|
||||
{
|
||||
MEDIA_LOGD("enter ctor, instance: 0x%{public}06" PRIXPTR ", name = %{public}s",
|
||||
FAKE_POINTER(this), name.c_str());
|
||||
offset_ = 0;
|
||||
}
|
||||
|
||||
AVDataSrcMemory::AVDataSrcMemory(int32_t fd, int32_t size, uint32_t flags, const std::string &name)
|
||||
: AVSharedMemoryBase(fd, size, flags, name)
|
||||
{
|
||||
MEDIA_LOGD("enter ctor, instance: 0x%{public}06" PRIXPTR ", name = %{public}s",
|
||||
FAKE_POINTER(this), name.c_str());
|
||||
offset_ = 0;
|
||||
}
|
||||
|
||||
AVDataSrcMemory::~AVDataSrcMemory()
|
||||
{
|
||||
MEDIA_LOGD("enter dtor, instance: 0x%{public}06" PRIXPTR ", name = %{public}s",
|
||||
FAKE_POINTER(this), GetName().c_str());
|
||||
}
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
143
services/utils/avsharedmemorybase.cpp
Normal file
143
services/utils/avsharedmemorybase.cpp
Normal file
@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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 "avsharedmemorybase.h"
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include "ashmem.h"
|
||||
#include "media_errors.h"
|
||||
#include "media_log.h"
|
||||
#include "scope_guard.h"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AVSharedMemoryBase"};
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec {
|
||||
struct AVSharedMemoryBaseImpl : public AVSharedMemoryBase {
|
||||
public:
|
||||
AVSharedMemoryBaseImpl(int32_t fd, int32_t size, uint32_t flags, const std::string &name)
|
||||
: AVSharedMemoryBase(fd, size, flags, name) {}
|
||||
};
|
||||
|
||||
std::shared_ptr<AVSharedMemory> AVSharedMemoryBase::CreateFromLocal(
|
||||
int32_t size, uint32_t flags, const std::string &name)
|
||||
{
|
||||
std::shared_ptr<AVSharedMemoryBase> memory = std::make_shared<AVSharedMemoryBase>(size, flags, name);
|
||||
int32_t ret = memory->Init();
|
||||
if (ret != MSERR_OK) {
|
||||
MEDIA_LOGE("Create avsharedmemory failed, ret = %{public}d", ret);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return memory;
|
||||
}
|
||||
|
||||
std::shared_ptr<AVSharedMemory> AVSharedMemoryBase::CreateFromRemote(
|
||||
int32_t fd, int32_t size, uint32_t flags, const std::string &name)
|
||||
{
|
||||
std::shared_ptr<AVSharedMemoryBase> memory = std::make_shared<AVSharedMemoryBaseImpl>(fd, size, flags, name);
|
||||
int32_t ret = memory->Init();
|
||||
if (ret != MSERR_OK) {
|
||||
MEDIA_LOGE("Create avsharedmemory failed, ret = %{public}d", ret);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return memory;
|
||||
}
|
||||
|
||||
AVSharedMemoryBase::AVSharedMemoryBase(int32_t size, uint32_t flags, const std::string &name)
|
||||
: base_(nullptr), size_(size), flags_(flags), name_(name), fd_(-1)
|
||||
{
|
||||
MEDIA_LOGD("enter ctor, instance: 0x%{public}06" PRIXPTR ", name = %{public}s",
|
||||
FAKE_POINTER(this), name_.c_str());
|
||||
}
|
||||
|
||||
AVSharedMemoryBase::AVSharedMemoryBase(int32_t fd, int32_t size, uint32_t flags, const std::string &name)
|
||||
: base_(nullptr), size_(size), flags_(flags), name_(name), fd_(dup(fd))
|
||||
{
|
||||
MEDIA_LOGD("enter ctor, instance: 0x%{public}06" PRIXPTR ", name = %{public}s",
|
||||
FAKE_POINTER(this), name_.c_str());
|
||||
}
|
||||
|
||||
AVSharedMemoryBase::~AVSharedMemoryBase()
|
||||
{
|
||||
MEDIA_LOGD("enter dtor, instance: 0x%{public}06" PRIXPTR ", name = %{public}s",
|
||||
FAKE_POINTER(this), name_.c_str());
|
||||
Close();
|
||||
}
|
||||
|
||||
int32_t AVSharedMemoryBase::Init()
|
||||
{
|
||||
ON_SCOPE_EXIT(0) {
|
||||
MEDIA_LOGE("create avsharedmemory failed, name = %{public}s, size = %{public}d, "
|
||||
"flags = 0x%{public}x, fd = %{public}d",
|
||||
name_.c_str(), size_, flags_, fd_);
|
||||
Close();
|
||||
};
|
||||
|
||||
CHECK_AND_RETURN_RET(size_ > 0, MSERR_INVALID_VAL);
|
||||
|
||||
bool isRemote = false;
|
||||
if (fd_ > 0) {
|
||||
int size = AshmemGetSize(fd_);
|
||||
CHECK_AND_RETURN_RET(size == size_, MSERR_INVALID_VAL);
|
||||
isRemote = true;
|
||||
} else {
|
||||
fd_ = AshmemCreate(name_.c_str(), static_cast<size_t>(size_));
|
||||
CHECK_AND_RETURN_RET(fd_ > 0, MSERR_INVALID_VAL);
|
||||
}
|
||||
|
||||
int32_t ret = MapMemory(isRemote);
|
||||
CHECK_AND_RETURN_RET(ret == MSERR_OK, MSERR_INVALID_VAL);
|
||||
|
||||
CANCEL_SCOPE_EXIT_GUARD(0);
|
||||
return MSERR_OK;
|
||||
}
|
||||
|
||||
int32_t AVSharedMemoryBase::MapMemory(bool isRemote)
|
||||
{
|
||||
unsigned int prot = PROT_READ | PROT_WRITE;
|
||||
if (isRemote && (flags_ & FLAGS_READ_ONLY)) {
|
||||
prot &= ~PROT_WRITE;
|
||||
}
|
||||
|
||||
int result = AshmemSetProt(fd_, static_cast<int>(prot));
|
||||
CHECK_AND_RETURN_RET(result >= 0, MSERR_INVALID_OPERATION);
|
||||
|
||||
void *addr = ::mmap(nullptr, static_cast<size_t>(size_), static_cast<int>(prot), MAP_SHARED, fd_, 0);
|
||||
CHECK_AND_RETURN_RET(addr != MAP_FAILED, MSERR_INVALID_OPERATION);
|
||||
|
||||
base_ = reinterpret_cast<uint8_t*>(addr);
|
||||
return MSERR_OK;
|
||||
}
|
||||
|
||||
void AVSharedMemoryBase::Close() noexcept
|
||||
{
|
||||
if (base_ != nullptr) {
|
||||
(void)::munmap(base_, static_cast<size_t>(size_));
|
||||
base_ = nullptr;
|
||||
size_ = 0;
|
||||
flags_ = 0;
|
||||
}
|
||||
|
||||
if (fd_ > 0) {
|
||||
(void)::close(fd_);
|
||||
fd_ = -1;
|
||||
}
|
||||
}
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
261
services/utils/avsharedmemorypool.cpp
Normal file
261
services/utils/avsharedmemorypool.cpp
Normal file
@ -0,0 +1,261 @@
|
||||
/*
|
||||
* 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 "avsharedmemorypool.h"
|
||||
#include "avsharedmemorybase.h"
|
||||
#include "media_log.h"
|
||||
#include "media_errors.h"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AVShMemPool"};
|
||||
constexpr int32_t MAX_MEM_SIZE = 100 * 1024 * 1024;
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec {
|
||||
AVSharedMemoryPool::AVSharedMemoryPool(const std::string &name) : name_(name)
|
||||
{
|
||||
MEDIA_LOGD("enter ctor, 0x%{public}06" PRIXPTR ", name: %{public}s", FAKE_POINTER(this), name_.c_str());
|
||||
}
|
||||
|
||||
AVSharedMemoryPool::~AVSharedMemoryPool()
|
||||
{
|
||||
MEDIA_LOGD("enter dtor, 0x%{public}06" PRIXPTR ", name: %{public}s", FAKE_POINTER(this), name_.c_str());
|
||||
Reset();
|
||||
}
|
||||
|
||||
int32_t AVSharedMemoryPool::Init(const InitializeOption &option)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
|
||||
CHECK_AND_RETURN_RET(!inited_, MSERR_INVALID_OPERATION);
|
||||
CHECK_AND_RETURN_RET(option.memSize < MAX_MEM_SIZE, MSERR_INVALID_VAL);
|
||||
CHECK_AND_RETURN_RET(option.maxMemCnt != 0, MSERR_INVALID_VAL);
|
||||
|
||||
option_ = option;
|
||||
if (option.preAllocMemCnt > option.maxMemCnt) {
|
||||
option_.preAllocMemCnt = option.maxMemCnt;
|
||||
}
|
||||
|
||||
MEDIA_LOGI("name: %{public}s, init option: preAllocMemCnt = %{public}u, memSize = %{public}d, "
|
||||
"maxMemCnt = %{public}u, enableFixedSize = %{public}d",
|
||||
name_.c_str(), option_.preAllocMemCnt, option_.memSize, option_.maxMemCnt,
|
||||
option_.enableFixedSize);
|
||||
bool ret = true;
|
||||
for (uint32_t i = 0; i < option_.preAllocMemCnt; ++i) {
|
||||
auto memory = AllocMemory(option_.memSize);
|
||||
if (memory == nullptr) {
|
||||
MEDIA_LOGE("alloc memory failed");
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
idleList_.push_back(memory);
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
for (auto iter = idleList_.begin(); iter != idleList_.end(); ++iter) {
|
||||
delete *iter;
|
||||
*iter = nullptr;
|
||||
}
|
||||
return MSERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
inited_ = true;
|
||||
notifier_ = option.notifier;
|
||||
return MSERR_OK;
|
||||
}
|
||||
|
||||
AVSharedMemory *AVSharedMemoryPool::AllocMemory(int32_t size)
|
||||
{
|
||||
AVSharedMemoryBase *memory = new (std::nothrow) AVSharedMemoryBase(size, option_.flags, name_);
|
||||
CHECK_AND_RETURN_RET_LOG(memory != nullptr, nullptr, "create object failed");
|
||||
|
||||
if (memory->Init() != MSERR_OK) {
|
||||
delete memory;
|
||||
memory = nullptr;
|
||||
MEDIA_LOGE("init avsharedmemorybase failed");
|
||||
}
|
||||
|
||||
return memory;
|
||||
}
|
||||
|
||||
void AVSharedMemoryPool::ReleaseMemory(AVSharedMemory *memory)
|
||||
{
|
||||
CHECK_AND_RETURN_LOG(memory != nullptr, "memory is nullptr");
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
|
||||
for (auto iter = busyList_.begin(); iter != busyList_.end(); ++iter) {
|
||||
if (*iter != memory) {
|
||||
continue;
|
||||
}
|
||||
|
||||
busyList_.erase(iter);
|
||||
idleList_.push_back(memory);
|
||||
cond_.notify_all();
|
||||
MEDIA_LOGD("0x%{public}06" PRIXPTR " released back to pool %{public}s",
|
||||
FAKE_POINTER(memory), name_.c_str());
|
||||
|
||||
lock.unlock();
|
||||
if (notifier_ != nullptr) {
|
||||
notifier_();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
MEDIA_LOGE("0x%{public}06" PRIXPTR " is no longer managed by this pool", FAKE_POINTER(memory));
|
||||
delete memory;
|
||||
}
|
||||
|
||||
bool AVSharedMemoryPool::DoAcquireMemory(int32_t size, AVSharedMemory **outMemory)
|
||||
{
|
||||
MEDIA_LOGD("busylist size %{public}zu, idlelist size %{public}zu", busyList_.size(), idleList_.size());
|
||||
|
||||
AVSharedMemory *result = nullptr;
|
||||
std::list<AVSharedMemory *>::iterator minSizeIdleMem = idleList_.end();
|
||||
int32_t minIdleSize = std::numeric_limits<int32_t>::max();
|
||||
|
||||
for (auto iter = idleList_.begin(); iter != idleList_.end(); ++iter) {
|
||||
if ((*iter)->GetSize() >= size) {
|
||||
result = *iter;
|
||||
idleList_.erase(iter);
|
||||
break;
|
||||
}
|
||||
|
||||
if ((*iter)->GetSize() < minIdleSize) {
|
||||
minIdleSize = (*iter)->GetSize();
|
||||
minSizeIdleMem = iter;
|
||||
}
|
||||
}
|
||||
|
||||
if (result == nullptr) {
|
||||
auto totalCnt = busyList_.size() + idleList_.size();
|
||||
if (totalCnt < option_.maxMemCnt) {
|
||||
result = AllocMemory(size);
|
||||
CHECK_AND_RETURN_RET(result != nullptr, false);
|
||||
}
|
||||
|
||||
if (!option_.enableFixedSize && minSizeIdleMem != idleList_.end()) {
|
||||
delete *minSizeIdleMem;
|
||||
*minSizeIdleMem = nullptr;
|
||||
idleList_.erase(minSizeIdleMem);
|
||||
result = AllocMemory(size);
|
||||
CHECK_AND_RETURN_RET(result != nullptr, false);
|
||||
}
|
||||
}
|
||||
|
||||
*outMemory = result;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AVSharedMemoryPool::CheckSize(int32_t size)
|
||||
{
|
||||
if (size <= 0 && size != -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!option_.enableFixedSize && size == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (option_.enableFixedSize) {
|
||||
if (size > option_.memSize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (size <= 0 && size != -1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<AVSharedMemory> AVSharedMemoryPool::AcquireMemory(int32_t size, bool blocking)
|
||||
{
|
||||
MEDIA_LOGD("acquire memory for size: %{public}d from pool %{public}s, blocking: %{public}d",
|
||||
size, name_.c_str(), blocking);
|
||||
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
if (!CheckSize(size)) {
|
||||
MEDIA_LOGE("invalid size: %{public}d", size);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (option_.enableFixedSize) {
|
||||
size = option_.memSize;
|
||||
}
|
||||
|
||||
AVSharedMemory *memory = nullptr;
|
||||
do {
|
||||
if (!DoAcquireMemory(size, &memory) || memory != nullptr) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!blocking || forceNonBlocking_) {
|
||||
break;
|
||||
}
|
||||
|
||||
cond_.wait(lock);
|
||||
} while (inited_ && !forceNonBlocking_);
|
||||
|
||||
if (memory == nullptr) {
|
||||
MEDIA_LOGD("acquire memory failed for size: %{public}d", size);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
busyList_.push_back(memory);
|
||||
|
||||
auto result = std::shared_ptr<AVSharedMemory>(memory, [weakPool = weak_from_this()](AVSharedMemory *memory) {
|
||||
std::shared_ptr<AVSharedMemoryPool> pool = weakPool.lock();
|
||||
if (pool != nullptr) {
|
||||
pool->ReleaseMemory(memory);
|
||||
} else {
|
||||
MEDIA_LOGI("release memory 0x%{public}06" PRIXPTR ", but the pool is destroyed", FAKE_POINTER(memory));
|
||||
delete memory;
|
||||
}
|
||||
});
|
||||
|
||||
MEDIA_LOGD("0x%{public}06" PRIXPTR " acquired from pool", FAKE_POINTER(memory));
|
||||
return result;
|
||||
}
|
||||
|
||||
void AVSharedMemoryPool::SetNonBlocking(bool enable)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
MEDIA_LOGD("SetNonBlocking: %{public}d", enable);
|
||||
forceNonBlocking_ = enable;
|
||||
if (forceNonBlocking_) {
|
||||
cond_.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
void AVSharedMemoryPool::Reset()
|
||||
{
|
||||
MEDIA_LOGD("Reset");
|
||||
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
for (auto &memory : idleList_) {
|
||||
delete memory;
|
||||
memory = nullptr;
|
||||
}
|
||||
idleList_.clear();
|
||||
inited_ = false;
|
||||
forceNonBlocking_ = false;
|
||||
notifier_ = nullptr;
|
||||
cond_.notify_all();
|
||||
// for busylist, the memory will be released when the refcount of shared_ptr is zero.
|
||||
}
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
326
services/utils/format.cpp
Normal file
326
services/utils/format.cpp
Normal file
@ -0,0 +1,326 @@
|
||||
/*
|
||||
* 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 "format.h"
|
||||
#include "securec.h"
|
||||
#include "media_log.h"
|
||||
#include "media_errors.h"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "Format"};
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec {
|
||||
void CopyFormatDataMap(const Format::FormatDataMap &from, Format::FormatDataMap &to)
|
||||
{
|
||||
for (auto it = to.begin(); it != to.end(); ++it) {
|
||||
if (it->second.type == FORMAT_TYPE_ADDR && it->second.addr != nullptr) {
|
||||
free(it->second.addr);
|
||||
it->second.addr = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
to = from;
|
||||
|
||||
for (auto it = to.begin(); it != to.end();) {
|
||||
if (it->second.type != FORMAT_TYPE_ADDR || it->second.addr == nullptr) {
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
|
||||
it->second.addr = reinterpret_cast<uint8_t *>(malloc(it->second.size));
|
||||
if (it->second.addr == nullptr) {
|
||||
MEDIA_LOGE("malloc addr failed. Key: %{public}s", it->first.c_str());
|
||||
it = to.erase(it);
|
||||
continue;
|
||||
}
|
||||
|
||||
errno_t err = memcpy_s(reinterpret_cast<void *>(it->second.addr),
|
||||
it->second.size, reinterpret_cast<const void *>(from.at(it->first).addr), it->second.size);
|
||||
if (err != EOK) {
|
||||
MEDIA_LOGE("memcpy addr failed. Key: %{public}s", it->first.c_str());
|
||||
free(it->second.addr);
|
||||
it->second.addr = nullptr;
|
||||
it = to.erase(it);
|
||||
continue;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
Format::~Format()
|
||||
{
|
||||
for (auto it = formatMap_.begin(); it != formatMap_.end(); ++it) {
|
||||
if (it->second.type == FORMAT_TYPE_ADDR && it->second.addr != nullptr) {
|
||||
free(it->second.addr);
|
||||
it->second.addr = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Format::Format(const Format &rhs)
|
||||
{
|
||||
if (&rhs == this) {
|
||||
return;
|
||||
}
|
||||
|
||||
CopyFormatDataMap(rhs.formatMap_, formatMap_);
|
||||
}
|
||||
|
||||
Format::Format(Format &&rhs) noexcept
|
||||
{
|
||||
std::swap(formatMap_, rhs.formatMap_);
|
||||
}
|
||||
|
||||
Format &Format::operator=(const Format &rhs)
|
||||
{
|
||||
if (&rhs == this) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
CopyFormatDataMap(rhs.formatMap_, this->formatMap_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Format &Format::operator=(Format &&rhs) noexcept
|
||||
{
|
||||
if (&rhs == this) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::swap(this->formatMap_, rhs.formatMap_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Format::PutIntValue(const std::string_view &key, int32_t value)
|
||||
{
|
||||
FormatData data;
|
||||
data.type = FORMAT_TYPE_INT32;
|
||||
data.val.int32Val = value;
|
||||
RemoveKey(key);
|
||||
auto ret = formatMap_.insert(std::make_pair(key, data));
|
||||
return ret.second;
|
||||
}
|
||||
|
||||
bool Format::PutLongValue(const std::string_view &key, int64_t value)
|
||||
{
|
||||
FormatData data;
|
||||
data.type = FORMAT_TYPE_INT64;
|
||||
data.val.int64Val = value;
|
||||
RemoveKey(key);
|
||||
auto ret = formatMap_.insert(std::make_pair(key, data));
|
||||
return ret.second;
|
||||
}
|
||||
|
||||
bool Format::PutFloatValue(const std::string_view &key, float value)
|
||||
{
|
||||
FormatData data;
|
||||
data.type = FORMAT_TYPE_FLOAT;
|
||||
data.val.floatVal = value;
|
||||
RemoveKey(key);
|
||||
auto ret = formatMap_.insert(std::make_pair(key, data));
|
||||
return ret.second;
|
||||
}
|
||||
|
||||
bool Format::PutDoubleValue(const std::string_view &key, double value)
|
||||
{
|
||||
FormatData data;
|
||||
data.type = FORMAT_TYPE_DOUBLE;
|
||||
data.val.doubleVal = value;
|
||||
RemoveKey(key);
|
||||
auto ret = formatMap_.insert(std::make_pair(key, data));
|
||||
return ret.second;
|
||||
}
|
||||
|
||||
bool Format::PutStringValue(const std::string_view &key, const std::string_view &value)
|
||||
{
|
||||
FormatData data;
|
||||
data.type = FORMAT_TYPE_STRING;
|
||||
data.stringVal = value;
|
||||
RemoveKey(key);
|
||||
auto ret = formatMap_.insert(std::make_pair(key, data));
|
||||
return ret.second;
|
||||
}
|
||||
|
||||
bool Format::GetStringValue(const std::string_view &key, std::string &value) const
|
||||
{
|
||||
auto iter = formatMap_.find(key);
|
||||
if (iter == formatMap_.end() || iter->second.type != FORMAT_TYPE_STRING) {
|
||||
MEDIA_LOGE("Format::GetFormat failed. Key: %{public}s", key.data());
|
||||
return false;
|
||||
}
|
||||
value = iter->second.stringVal;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Format::GetIntValue(const std::string_view &key, int32_t &value) const
|
||||
{
|
||||
auto iter = formatMap_.find(key);
|
||||
if (iter == formatMap_.end() || iter->second.type != FORMAT_TYPE_INT32) {
|
||||
MEDIA_LOGE("Format::GetFormat failed. Key: %{public}s", key.data());
|
||||
return false;
|
||||
}
|
||||
value = iter->second.val.int32Val;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Format::GetLongValue(const std::string_view &key, int64_t &value) const
|
||||
{
|
||||
auto iter = formatMap_.find(key);
|
||||
if (iter == formatMap_.end() || iter->second.type != FORMAT_TYPE_INT64) {
|
||||
MEDIA_LOGE("Format::GetFormat failed. Key: %{public}s", key.data());
|
||||
return false;
|
||||
}
|
||||
value = iter->second.val.int64Val;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Format::GetFloatValue(const std::string_view &key, float &value) const
|
||||
{
|
||||
auto iter = formatMap_.find(key);
|
||||
if (iter == formatMap_.end() || iter->second.type != FORMAT_TYPE_FLOAT) {
|
||||
MEDIA_LOGE("Format::GetFormat failed. Key: %{public}s", key.data());
|
||||
return false;
|
||||
}
|
||||
value = iter->second.val.floatVal;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Format::GetDoubleValue(const std::string_view &key, double &value) const
|
||||
{
|
||||
auto iter = formatMap_.find(key);
|
||||
if (iter == formatMap_.end() || iter->second.type != FORMAT_TYPE_DOUBLE) {
|
||||
MEDIA_LOGE("Format::GetFormat failed. Key: %{public}s", key.data());
|
||||
return false;
|
||||
}
|
||||
value = iter->second.val.doubleVal;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Format::PutBuffer(const std::string_view &key, const uint8_t *addr, size_t size)
|
||||
{
|
||||
if (addr == nullptr) {
|
||||
MEDIA_LOGE("put buffer error, addr is nullptr");
|
||||
return false;
|
||||
}
|
||||
|
||||
constexpr size_t sizeMax = 1 * 1024 * 1024;
|
||||
if (size > sizeMax) {
|
||||
MEDIA_LOGE("PutBuffer input size failed. Key: %{public}s", key.data());
|
||||
return false;
|
||||
}
|
||||
|
||||
FormatData data;
|
||||
data.type = FORMAT_TYPE_ADDR;
|
||||
data.addr = reinterpret_cast<uint8_t *>(malloc(size));
|
||||
if (data.addr == nullptr) {
|
||||
MEDIA_LOGE("malloc addr failed. Key: %{public}s", key.data());
|
||||
return false;
|
||||
}
|
||||
|
||||
errno_t err = memcpy_s(reinterpret_cast<void *>(data.addr), size, reinterpret_cast<const void *>(addr), size);
|
||||
if (err != EOK) {
|
||||
MEDIA_LOGE("PutBuffer memcpy addr failed. Key: %{public}s", key.data());
|
||||
free(data.addr);
|
||||
return false;
|
||||
}
|
||||
|
||||
RemoveKey(key);
|
||||
|
||||
data.size = size;
|
||||
auto ret = formatMap_.insert(std::make_pair(key, data));
|
||||
return ret.second;
|
||||
}
|
||||
|
||||
bool Format::GetBuffer(const std::string_view &key, uint8_t **addr, size_t &size) const
|
||||
{
|
||||
auto iter = formatMap_.find(key);
|
||||
if (iter == formatMap_.end() || iter->second.type != FORMAT_TYPE_ADDR) {
|
||||
MEDIA_LOGE("Format::GetBuffer failed. Key: %{public}s", key.data());
|
||||
return false;
|
||||
}
|
||||
*addr = iter->second.addr;
|
||||
size = iter->second.size;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Format::ContainKey(const std::string_view &key) const
|
||||
{
|
||||
auto iter = formatMap_.find(key);
|
||||
if (iter != formatMap_.end()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
FormatDataType Format::GetValueType(const std::string_view &key) const
|
||||
{
|
||||
auto iter = formatMap_.find(key);
|
||||
if (iter == formatMap_.end()) {
|
||||
return FORMAT_TYPE_NONE;
|
||||
}
|
||||
|
||||
return iter->second.type;
|
||||
}
|
||||
|
||||
void Format::RemoveKey(const std::string_view &key)
|
||||
{
|
||||
auto iter = formatMap_.find(key);
|
||||
if (iter != formatMap_.end()) {
|
||||
if (iter->second.type == FORMAT_TYPE_ADDR && iter->second.addr != nullptr) {
|
||||
free(iter->second.addr);
|
||||
iter->second.addr = nullptr;
|
||||
}
|
||||
formatMap_.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
const Format::FormatDataMap &Format::GetFormatMap() const
|
||||
{
|
||||
return formatMap_;
|
||||
}
|
||||
|
||||
std::string Format::Stringify() const
|
||||
{
|
||||
std::string outString;
|
||||
for (auto iter = formatMap_.begin(); iter != formatMap_.end(); iter++) {
|
||||
switch (GetValueType(iter->first)) {
|
||||
case FORMAT_TYPE_INT32:
|
||||
outString += iter->first + " = " + std::to_string(iter->second.val.int32Val) + " | ";
|
||||
break;
|
||||
case FORMAT_TYPE_INT64:
|
||||
outString += iter->first + " = " + std::to_string(iter->second.val.int64Val) + " | ";
|
||||
break;
|
||||
case FORMAT_TYPE_FLOAT:
|
||||
outString += iter->first + " = " + std::to_string(iter->second.val.floatVal) + " | ";
|
||||
break;
|
||||
case FORMAT_TYPE_DOUBLE:
|
||||
outString += iter->first + " = " + std::to_string(iter->second.val.doubleVal) + " | ";
|
||||
break;
|
||||
case FORMAT_TYPE_STRING:
|
||||
outString += iter->first + " = " + iter->second.stringVal + " | ";
|
||||
break;
|
||||
case FORMAT_TYPE_ADDR:
|
||||
break;
|
||||
default:
|
||||
MEDIA_LOGE("Format::Stringify failed. Key: %{public}s", iter->first.c_str());
|
||||
}
|
||||
}
|
||||
return outString;
|
||||
}
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
93
services/utils/include/avdatasrcmemory.h
Normal file
93
services/utils/include/avdatasrcmemory.h
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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 AVDATASRCMEMORY_H
|
||||
#define AVDATASRCMEMORY_H
|
||||
|
||||
#include <string>
|
||||
#include "nocopyable.h"
|
||||
#include "avsharedmemorybase.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec {
|
||||
class __attribute__((visibility("default"))) AVDataSrcMemory
|
||||
: public AVSharedMemoryBase {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new AVDataSrcMemory object. This function should only be used in the
|
||||
* local process.
|
||||
*
|
||||
* @param size the memory's size, bytes.
|
||||
* @param flags the memory's accessible flags, refer to {@AVSharedMemory::Flags}.
|
||||
* @param name the debug string
|
||||
*/
|
||||
static std::shared_ptr<AVSharedMemory> CreateFromLocal(
|
||||
int32_t size, uint32_t flags, const std::string &name);
|
||||
|
||||
/**
|
||||
* @brief Construct a new AVDataSrcMemory object. This function should only be used in the
|
||||
* remote process.
|
||||
*
|
||||
* @param fd the memory's fd
|
||||
* @param size the memory's size, bytes.
|
||||
* @param flags the memory's accessible flags, refer to {@AVSharedMemory::Flags}.
|
||||
* @param name the debug string
|
||||
*/
|
||||
static std::shared_ptr<AVSharedMemory> CreateFromRemote(
|
||||
int32_t fd, int32_t size, uint32_t flags, const std::string &name);
|
||||
|
||||
virtual ~AVDataSrcMemory();
|
||||
|
||||
/**
|
||||
* @brief Construct a new AVSharedMemoryBase object. This function should only be used in the
|
||||
* local process.
|
||||
*
|
||||
* @param size the memory's size, bytes.
|
||||
* @param flags the memory's accessible flags, refer to {@AVSharedMemory::Flags}.
|
||||
* @param name the debug string
|
||||
*/
|
||||
AVDataSrcMemory(int32_t size, uint32_t flags, const std::string &name);
|
||||
|
||||
/**
|
||||
* @brief Get the memory's virtual address
|
||||
* @return the memory's virtual address if the memory is valid, otherwise nullptr.
|
||||
*/
|
||||
virtual uint8_t *GetBase() const override
|
||||
{
|
||||
return AVSharedMemoryBase::GetBase() + offset_;
|
||||
}
|
||||
|
||||
uint8_t *GetInnerBase() const
|
||||
{
|
||||
return AVSharedMemoryBase::GetBase();
|
||||
}
|
||||
|
||||
void SetOffset(uint32_t offset)
|
||||
{
|
||||
offset_ = offset;
|
||||
}
|
||||
|
||||
uint32_t GetOffset() const
|
||||
{
|
||||
return offset_;
|
||||
}
|
||||
protected:
|
||||
AVDataSrcMemory(int32_t fd, int32_t size, uint32_t flags, const std::string &name);
|
||||
private:
|
||||
uint32_t offset_;
|
||||
};
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
||||
#endif
|
127
services/utils/include/avsharedmemorybase.h
Normal file
127
services/utils/include/avsharedmemorybase.h
Normal file
@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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 AVSHAREDMEMORYBASE_H
|
||||
#define AVSHAREDMEMORYBASE_H
|
||||
|
||||
#include <string>
|
||||
#include "nocopyable.h"
|
||||
#include "avsharedmemory.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec {
|
||||
class __attribute__((visibility("default"))) AVSharedMemoryBase
|
||||
: public AVSharedMemory, public NoCopyable {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new AVSharedMemoryBase object. This function should only be used in the
|
||||
* local process.
|
||||
*
|
||||
* @param size the memory's size, bytes.
|
||||
* @param flags the memory's accessible flags, refer to {@AVSharedMemory::Flags}.
|
||||
* @param name the debug string
|
||||
*/
|
||||
static std::shared_ptr<AVSharedMemory> CreateFromLocal(
|
||||
int32_t size, uint32_t flags, const std::string &name);
|
||||
|
||||
/**
|
||||
* @brief Construct a new AVSharedMemoryBase object. This function should only be used in the
|
||||
* remote process.
|
||||
*
|
||||
* @param fd the memory's fd
|
||||
* @param size the memory's size, bytes.
|
||||
* @param flags the memory's accessible flags, refer to {@AVSharedMemory::Flags}.
|
||||
* @param name the debug string
|
||||
*/
|
||||
static std::shared_ptr<AVSharedMemory> CreateFromRemote(
|
||||
int32_t fd, int32_t size, uint32_t flags, const std::string &name);
|
||||
|
||||
~AVSharedMemoryBase();
|
||||
|
||||
/**
|
||||
* @brief Construct a new AVSharedMemoryBase object. This function should only be used in the
|
||||
* local process.
|
||||
*
|
||||
* @param size the memory's size, bytes.
|
||||
* @param flags the memory's accessible flags, refer to {@AVSharedMemory::Flags}.
|
||||
* @param name the debug string
|
||||
*/
|
||||
AVSharedMemoryBase(int32_t size, uint32_t flags, const std::string &name);
|
||||
|
||||
/**
|
||||
* @brief Intialize the memory. Call this interface firstly before the other interface.
|
||||
* @return MSERR_OK if success, otherwise the errcode.
|
||||
*/
|
||||
int32_t Init();
|
||||
|
||||
/**
|
||||
* @brief Get the memory's fd, which only valid when the underlying memory
|
||||
* chunk is allocated through the ashmem.
|
||||
* @return the memory's fd if the memory is allocated through the ashmem, otherwise -1.
|
||||
*/
|
||||
int32_t GetFd() const
|
||||
{
|
||||
return fd_;
|
||||
}
|
||||
|
||||
std::string GetName() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the memory's virtual address
|
||||
* @return the memory's virtual address if the memory is valid, otherwise nullptr.
|
||||
*/
|
||||
virtual uint8_t *GetBase() const override
|
||||
{
|
||||
return base_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the memory's size
|
||||
* @return the memory's size if the memory is valid, otherwise -1.
|
||||
*/
|
||||
virtual int32_t GetSize() const override
|
||||
{
|
||||
return (base_ != nullptr) ? size_ : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the memory's flags set by the creator, refer to {@Flags}
|
||||
* @return the memory's flags if the memory is valid, otherwise 0.
|
||||
*/
|
||||
virtual uint32_t GetFlags() const final
|
||||
{
|
||||
return (base_ != nullptr) ? flags_ : 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
AVSharedMemoryBase(int32_t fd, int32_t size, uint32_t flags, const std::string &name);
|
||||
|
||||
private:
|
||||
int32_t MapMemory(bool isRemote);
|
||||
void Close() noexcept;
|
||||
|
||||
uint8_t *base_;
|
||||
int32_t size_;
|
||||
uint32_t flags_;
|
||||
std::string name_;
|
||||
int32_t fd_;
|
||||
};
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
||||
|
||||
#endif
|
111
services/utils/include/avsharedmemorypool.h
Normal file
111
services/utils/include/avsharedmemorypool.h
Normal file
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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 AVSHAREDMEMORYPOOL_H
|
||||
#define AVSHAREDMEMORYPOOL_H
|
||||
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include "nocopyable.h"
|
||||
#include "avsharedmemorybase.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec {
|
||||
/**
|
||||
* @brief A simple pool implementation for shared memory.
|
||||
*
|
||||
* This pool support multi configuration:
|
||||
* @preAllocMemCnt: The number of memory blocks allocated when the pool is initialized.
|
||||
* @memSize: the size of the preallocated memory blocks.
|
||||
* @maxMemCnt: the total number of memory blocks in the pool.
|
||||
* @flags: the shared memory access property, refer to {@AVSharedMemory::Flags}.
|
||||
* @enableFixedSize: if true, the pool will allocate all memory block using the memSize. If the acquired
|
||||
* size is larger than the memSize, the acquire will failed. If false, the pool will
|
||||
* free the smallest idle memory block when there is no idle memory block that can
|
||||
* satisfy the acqiured size and reallocate a new memory block with the acquired size.
|
||||
* @notifier: the callback will be called to notify there are any available memory. It will be useful for
|
||||
* non-blocking memory acquisition.
|
||||
*/
|
||||
class __attribute__((visibility("default"))) AVSharedMemoryPool
|
||||
: public std::enable_shared_from_this<AVSharedMemoryPool>, public NoCopyable {
|
||||
public:
|
||||
explicit AVSharedMemoryPool(const std::string &name);
|
||||
~AVSharedMemoryPool();
|
||||
|
||||
using MemoryAvailableNotifier = std::function<void(void)>;
|
||||
|
||||
struct InitializeOption {
|
||||
uint32_t preAllocMemCnt = 0;
|
||||
int32_t memSize = 0;
|
||||
uint32_t maxMemCnt = 0;
|
||||
uint32_t flags = AVSharedMemory::Flags::FLAGS_READ_WRITE;
|
||||
bool enableFixedSize = true;
|
||||
MemoryAvailableNotifier notifier;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Initialize the pool and preallocate some memory blocks.
|
||||
*/
|
||||
int32_t Init(const InitializeOption &option);
|
||||
|
||||
/**
|
||||
* @brief Get a memory from the pool and optional to wait for a memory to be release when there
|
||||
* are no memories available.
|
||||
*
|
||||
* @param size the expected memory size. if the enableFixedSize is configured, this param can be empty.
|
||||
* @return valid memory block if success, or nullptr.
|
||||
*/
|
||||
std::shared_ptr<AVSharedMemory> AcquireMemory(int32_t size = -1, bool blocking = true);
|
||||
|
||||
/**
|
||||
* @brief Set or Unset the pool to be non-blocking memory pool. If enable, the AcquireMemory will always
|
||||
* be non-blocking and the waiters will be returned with null memory.
|
||||
*/
|
||||
void SetNonBlocking(bool enable);
|
||||
|
||||
/**
|
||||
* @brief Free all memory blocks and reset the pool configuration. After reseted, all waiters of
|
||||
* the pool will be awaken up and returned with a nullptr.
|
||||
*/
|
||||
void Reset();
|
||||
|
||||
std::string GetName()
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
private:
|
||||
bool DoAcquireMemory(int32_t size, AVSharedMemory **outMemory);
|
||||
AVSharedMemory *AllocMemory(int32_t size);
|
||||
void ReleaseMemory(AVSharedMemory *memory);
|
||||
bool CheckSize(int32_t size);
|
||||
|
||||
InitializeOption option_ {};
|
||||
std::list<AVSharedMemory *> idleList_;
|
||||
std::list<AVSharedMemory *> busyList_;
|
||||
std::mutex mutex_;
|
||||
std::condition_variable cond_;
|
||||
bool inited_ = false;
|
||||
std::string name_;
|
||||
MemoryAvailableNotifier notifier_;
|
||||
bool forceNonBlocking_ = false;
|
||||
};
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user