mirror of
https://gitee.com/openharmony/multimedia_av_codec
synced 2024-12-11 17:16:02 +00:00
Merge branch 'develop' into dev_lyd
This commit is contained in:
commit
7c67fadd97
@ -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;
|
||||
@ -61,7 +57,7 @@ int32_t AVCodecImpl::Init(AVCodecType type, bool isMimeType, const std::string &
|
||||
|
||||
AVCodecImpl::AVCodecImpl()
|
||||
{
|
||||
MEDIA_LOGD("AVCodecImpl:0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
|
||||
AVCODEC_LOGD("AVCodecImpl:0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
|
||||
}
|
||||
|
||||
AVCodecImpl::~AVCodecImpl()
|
||||
@ -70,7 +66,7 @@ AVCodecImpl::~AVCodecImpl()
|
||||
(void)MediaServiceFactory::GetInstance().DestroyAVCodecService(codecService_);
|
||||
codecService_ = nullptr;
|
||||
}
|
||||
MEDIA_LOGD("AVCodecImpl:0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
|
||||
AVCODEC_LOGD("AVCodecImpl:0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
|
||||
}
|
||||
|
||||
int32_t AVCodecImpl::Configure(const Format &format)
|
||||
@ -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
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
#include "avdemuxer_impl.h"
|
||||
#include "i_media_service.h"
|
||||
#include "media_error.h"
|
||||
#include "media_errors.h"
|
||||
#include "media_log.h"
|
||||
|
||||
namespace {
|
||||
@ -39,14 +39,13 @@ int32_t AVDemuxerImpl::Init(Source *source)
|
||||
{
|
||||
demuxerService_ = MediaServiceFactory::GetInstance().CreateAVDemuxerService();
|
||||
CHECK_AND_RETURN_RET_LOG(demuxerService_ != nullptr, MSERR_UNKNOWN, "failed to create avdemuxer service");
|
||||
|
||||
return demuxerService_->InitParameter(source);
|
||||
uint8_t sourceAttr = source->GetSourceAttr();
|
||||
return demuxerService_->Init(sourceAttr);
|
||||
}
|
||||
|
||||
|
||||
AVDemuxerImpl::AVDemuxerImpl()
|
||||
{
|
||||
MEDIA_LOGD("AVDemuxerImpl:0x%{public}06" PRIXPTR " Instances create". FAKE_POINTER(this));
|
||||
AVCODEC_LOGD("AVDemuxerImpl:0x%{public}06" PRIXPTR " Instances create". FAKE_POINTER(this));
|
||||
}
|
||||
|
||||
AVDemuxerImpl::~AVDemuxerImpl()
|
||||
@ -55,7 +54,7 @@ AVDemuxerImpl::~AVDemuxerImpl()
|
||||
(void)MediaServiceFactory::GetInstance().DestroyAVDemuxerService(demuxerService_);
|
||||
demuxerService_ = nullptr;
|
||||
}
|
||||
MEDIA_LOGD("AVDemuxerImpl:0x%{public}06" PRIXPTR " Instances destroy". FAKE_POINTER(this));
|
||||
AVCODEC_LOGD("AVDemuxerImpl:0x%{public}06" PRIXPTR " Instances destroy". FAKE_POINTER(this));
|
||||
}
|
||||
|
||||
int32_t AVDemuxerImpl::AddSourceTrackByID(uint32_t index)
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include "avdemuxer.h"
|
||||
#include "i_demuxer_service.h"
|
||||
#include "i_avdemuxer_service.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
|
100
frameworks/native/avmuxer/avmuxer_impl.cpp
Normal file
100
frameworks/native/avmuxer/avmuxer_impl.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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 "avmuxer_impl.h"
|
||||
#include <unistd.h>
|
||||
#include "av_log.h"
|
||||
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AVMuxerImpl"};
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
std::shared_ptr<AVMuxer> AVMuxerFactory::CreateAVMuxer(int32_t fd, OutputFormat format)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG((fcntl(fd, F_GETFL, 0) & O_RDWR) == O_RDWR, nullptr, "No permission to read and write fd");
|
||||
CHECK_AND_RETURN_RET_LOG(lseek(fd, 0, SEEK_CUR) != -1, nullptr, "The fd is not seekable");
|
||||
|
||||
std::shared_ptr<AVMuxerImpl> impl = std::make_shared<AVMuxerImpl>(fd, format);
|
||||
CHECK_AND_RETURN_RET_LOG(impl != nullptr, nullptr, "Failed to create avmuxer implementation");
|
||||
|
||||
int32_t ret = impl->Init();
|
||||
CHECK_AND_RETURN_RET_LOG(ret == Status::CSERR_OK, nullptr, "Failed to init avmuxer implementation");
|
||||
return impl;
|
||||
}
|
||||
|
||||
AVMuxerImpl::AVMuxerImpl(int32_t fd, OutputFormat format) : fd_(fd), format_(format)
|
||||
{
|
||||
AVCODEC_LOGD("AVMuxerImpl:0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
|
||||
}
|
||||
|
||||
AVMuxerImpl::~AVMuxerImpl()
|
||||
{
|
||||
AVCODEC_LOGD("AVMuxerImpl:0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
|
||||
}
|
||||
|
||||
int32_t AVMuxerImpl::Init()
|
||||
{
|
||||
muxerEngine_ = IMuxerEngineFactory::CreateMuxerEngine(-1, -1, fd_, format_);
|
||||
CHECK_AND_RETURN_RET_LOG(muxerEngine_ != nullptr, Status::CSERR_NO_MEMORY, "Failed to create avmuxer engine");
|
||||
return Status::CSERR_OK;
|
||||
}
|
||||
|
||||
int32_t AVMuxerImpl::SetLocation(float latitude, float longitude)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(muxerEngine_ != nullptr, Status::CSERR_INVALID_OPERATION, "AVMuxer Engine does not exist");
|
||||
return muxerEngine_->SetLocation(latitude, longitude);
|
||||
}
|
||||
|
||||
int32_t AVMuxerImpl::SetRotation(int32_t rotation)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(muxerEngine_ != nullptr, Status::CSERR_INVALID_OPERATION, "AVMuxer Engine does not exist");
|
||||
return muxerEngine_->SetRotation(rotation);
|
||||
}
|
||||
|
||||
int32_t AVMuxerImpl::SetParameter(const Format &generalFormat)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(muxerEngine_ != nullptr, Status::CSERR_INVALID_OPERATION, "AVMuxer Engine does not exist");
|
||||
return muxerEngine_->SetParameter(generalFormat);
|
||||
}
|
||||
|
||||
int32_t AVMuxerImpl::AddTrack(const Format &trackFormat)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(muxerEngine_ != nullptr, Status::CSERR_INVALID_OPERATION, "AVMuxer Engine does not exist");
|
||||
return muxerEngine_->AddTrack(trackFormat);
|
||||
}
|
||||
|
||||
int32_t AVMuxerImpl::Start()
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(muxerEngine_ != nullptr, Status::CSERR_INVALID_OPERATION, "AVMuxer Engine does not exist");
|
||||
return muxerEngine_->Start();
|
||||
}
|
||||
|
||||
int32_t AVMuxerImpl::WriteSampleBuffer(uint32_t trackIndex, uint8_t *sampleBuffer, AVCodecBufferInfo info)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(muxerEngine_ != nullptr, Status::CSERR_INVALID_OPERATION, "AVMuxer Engine does not exist");
|
||||
CHECK_AND_RETURN_RET_LOG(sampleBuffer != nullptr && info.size >= 0 && info.pts >= 0, Status::CSERR_NO_MEMORY, "Invalid memory");
|
||||
return muxerEngine_->WriteSampleBuffer(trackIndex, sampleBuffer, info);
|
||||
}
|
||||
|
||||
int32_t AVMuxerImpl::Stop()
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(muxerEngine_ != nullptr, Status::CSERR_INVALID_OPERATION, "AVMuxer Engine does not exist");
|
||||
return muxerEngine_->Stop();
|
||||
}
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
44
frameworks/native/avmuxer/avmuxer_impl.h
Normal file
44
frameworks/native/avmuxer/avmuxer_impl.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 AVMUXER_IMPL_H
|
||||
#define AVMUXER_IMPL_H
|
||||
|
||||
#include "avmuxer.h"
|
||||
#include "i_muxer_engine.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
class AVMuxerImpl : public AVMuxer, public NoCopyable {
|
||||
public:
|
||||
AVMuxerImpl(int32_t fd, OutputFormat format);
|
||||
~AVMuxerImpl() override;
|
||||
int32_t Init();
|
||||
int32_t SetLocation(float latitude, float longitude) override;
|
||||
int32_t SetRotation(int32_t rotation) override;
|
||||
int32_t SetParameter(const Format &generalFormat) override;
|
||||
int32_t AddTrack(const Format &trackFormat) override;
|
||||
int32_t Start() override;
|
||||
int32_t WriteSampleBuffer(uint32_t trackIndex, uint8_t *sampleBuffer, AVCodecBufferInfo info) override;
|
||||
int32_t Stop() override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<IMuxerEngine> muxerEngine_ = nullptr;
|
||||
int32_t fd_ = -1;
|
||||
OutputFormat format_ = AV_OUTPUT_FORMAT_UNKNOWN;
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
#endif // AVMUXER_IMPL_H
|
123
frameworks/native/avsource/avsource_impl.cpp
Normal file
123
frameworks/native/avsource/avsource_impl.cpp
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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 "avsource_impl.h"
|
||||
#include "i_media_service.h"
|
||||
#include "media_errors.h"
|
||||
#include "media_log.h"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AVSourceImpl"}
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec{
|
||||
std::shared_ptr<AVCodec> SourceFactory::CreateWithURI(const std::string &uri)
|
||||
{
|
||||
std::shared_ptr<AVSourceImpl> sourceImpl = std::make_shared<AVSourceImpl>();
|
||||
CHECK_AND_RETURN_RET_LOG(sourceImpl != nullptr, nullptr, "failed to new AVSourceImpl");
|
||||
|
||||
AVCodecType codeType = encoder ? AVCODEC_TYPE_ENCODER : AVCODEC_TYPE_DECODER;
|
||||
int32_t ret = sourceImpl->Init(uri);;
|
||||
CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, nullptr, "failed to init AVSourceImpl");
|
||||
|
||||
return impl;
|
||||
}
|
||||
|
||||
int32_t AVSourceImpl::Init(const std::string &uri)
|
||||
{
|
||||
sourceService_ = MediaServiceFactory::GetInstance().CreateAVSourceService();
|
||||
CHECK_AND_RETURN_RET_LOG(sourceService_ != nullptr, MSERR_UNKNOWN, "failed to create avsource service");
|
||||
return sourceService_->Init(uri);
|
||||
}
|
||||
|
||||
uint8_t GetSourceAttr()
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(sourceService_ != nullptr, MSERR_INVALID_OPERATION, "avdemuxer service died!");
|
||||
return sourceService_->GetSourceAttr();
|
||||
}
|
||||
|
||||
AVSourceImpl::AVSourceImpl()
|
||||
{
|
||||
MEDIA_LOGD("AVSourceImpl:0x%{public}06" PRIXPTR " Instances create". FAKE_POINTER(this));
|
||||
}
|
||||
|
||||
AVSourceImpl::~AVSourceImpl()
|
||||
{
|
||||
if (sourceService_ != nullptr) {
|
||||
(void)MediaServiceFactory::GetInstance().DestroyAVSourceService(sourceService_);
|
||||
sourceService_ = nullptr;
|
||||
}
|
||||
MEDIA_LOGD("AVSourceImpl:0x%{public}06" PRIXPTR " Instances destroy". FAKE_POINTER(this));
|
||||
}
|
||||
|
||||
uint32_t AVSourceImpl::GetTrackCount()
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(sourceService_ != nullptr, MSERR_INVALID_OPERATION, "avdemuxer service died!");
|
||||
return sourceService_->GetTrackCount();
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceTrack> AVSourceImpl::LoadSourceTrackByID(uint32_t trackId)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(sourceService_ != nullptr, MSERR_INVALID_OPERATION, "avdemuxer service died!");
|
||||
return AVSourceTrackImpl(trackId);
|
||||
}
|
||||
|
||||
int32_t Destroy()
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(sourceService_ != nullptr, MSERR_INVALID_OPERATION, "avdemuxer service died!");
|
||||
return sourceService_->Destroy();
|
||||
}
|
||||
|
||||
int32_t AVSourceImpl::SetParameter(const Format ¶m, uint32_t trackId)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(sourceService_ != nullptr, MSERR_INVALID_OPERATION, "avdemuxer service died!");
|
||||
return sourceService_->SetParameter(param, trackId);
|
||||
}
|
||||
|
||||
std::shared_ptr<Format> AVSourceImpl::GetTrackFormat(Format &format, uint32_t trackId)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(sourceService_ != nullptr, MSERR_INVALID_OPERATION, "avdemuxer service died!");
|
||||
return sourceService_->GetTrackFormat(format, trackId);
|
||||
}
|
||||
|
||||
AVSourceTrack::AVSourceTrackImpl(AVSource* source, uint32_t trackId)
|
||||
{
|
||||
trackId_ = trackId;
|
||||
sourceImpl_ = std::make_shared<AVSource>(source);
|
||||
MEDIA_LOGD("AVSourceTrackImpl:0x%{public}06" PRIXPTR " Instances create". FAKE_POINTER(this));
|
||||
}
|
||||
|
||||
AVSourceTrack::~AVSourceTrackImpl()
|
||||
{
|
||||
if (sourceImpl_ != nullptr) {
|
||||
delete sourceImpl_;
|
||||
}
|
||||
MEDIA_LOGD("AVSourceTrackImpl:0x%{public}06" PRIXPTR " Instances destroy". FAKE_POINTER(this));
|
||||
}
|
||||
|
||||
int32_t SetParameter(const Format ¶m)
|
||||
{
|
||||
return sourceImpl_->SetParameter(param, trackId_)
|
||||
}
|
||||
|
||||
std::shared_ptr<Format> GetTrackFormat()
|
||||
{
|
||||
Format format;
|
||||
return sourceImpl_->GetTrackFormat(format, trackId_)
|
||||
}
|
||||
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
56
frameworks/native/avsource/avsource_impl.h
Normal file
56
frameworks/native/avsource/avsource_impl.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 AVSOURCE_IMPL_H
|
||||
#define AVSOURCE_IMPL_H
|
||||
|
||||
#include <avsource>
|
||||
#include "nocopyable.h"
|
||||
#include "i_avsource_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec{
|
||||
class AVSourceImpl : public AVSource, public NoCopyable {
|
||||
public:
|
||||
AVSourceImpl();
|
||||
~AVSourceImpl();
|
||||
|
||||
uint32_t GetTrackCount() override;
|
||||
std::shared_ptr<SourceTrack> LoadSourceTrackByID(uint32_t trackId) override;
|
||||
int32_t Destroy() override;
|
||||
uint8_t GetSourceAttr() override;
|
||||
int32_t SetParameter(const Format ¶m, uint32_t trackId) override;
|
||||
std::shared_ptr<Format> GetTrackFormat(Format ¶m, uint32_t trackId) override;
|
||||
int32_t Init(const std::string &uri);
|
||||
|
||||
private:
|
||||
std::shared_ptr<IAVSourceService> sourceService_ = nullptr;
|
||||
};
|
||||
|
||||
class AVSourceTrackImpl : public AVSourceTrack, public NoCopyable {
|
||||
public:
|
||||
AVSourceTrackImpl(AVSource* source, uint32_t trackId);
|
||||
~AVSourceTrackImpl();
|
||||
|
||||
int32_t SetParameter(const Format ¶m) override;
|
||||
std::shared_ptr<Format> GetTrackFormat(Format ¶m) override;
|
||||
private:
|
||||
uint32_t trackId_;
|
||||
std::shared_ptr<AVSourceImpl> sourceImpl_;
|
||||
};
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
||||
#endif // AVSOURCE_IMPL_H
|
||||
|
@ -77,7 +77,7 @@ public:
|
||||
CHECK_AND_RETURN_LOG(codecObj->codec_ != nullptr, "codec_ is nullptr!");
|
||||
|
||||
if (codecObj->isFlushing_.load() || codecObj->isStop_.load() || codecObj->isEOS_.load()) {
|
||||
MEDIA_LOGD("At flush, eos or stop, no buffer available");
|
||||
AVCODEC_LOGD("At flush, eos or stop, no buffer available");
|
||||
return;
|
||||
}
|
||||
OH_AVBufferElement *data = GetInputData(codec_, index);
|
||||
@ -95,7 +95,7 @@ public:
|
||||
CHECK_AND_RETURN_LOG(codecObj->codec_ != nullptr, "codec_ is nullptr!");
|
||||
|
||||
if (codecObj->isFlushing_.load() || codecObj->isStop_.load()) {
|
||||
MEDIA_LOGD("At flush or stop, ignore");
|
||||
AVCODEC_LOGD("At flush or stop, ignore");
|
||||
return;
|
||||
}
|
||||
struct OH_AVCodecBufferAttr bufferAttr;
|
||||
@ -218,12 +218,12 @@ OH_AVErrCode OH_AVCodec_Destroy(struct OH_AVCodec *codec)
|
||||
codecObj->isStop_.store(false);
|
||||
int32_t ret = codecObj->codec_->Release();
|
||||
if (ret != MSERR_OK) {
|
||||
MEDIA_LOGE("codec Release failed!");
|
||||
AVCODEC_LOGE("codec Release failed!");
|
||||
delete codec;
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
}
|
||||
} else {
|
||||
MEDIA_LOGD("codec_ is nullptr!");
|
||||
AVCODEC_LOGD("codec_ is nullptr!");
|
||||
}
|
||||
|
||||
delete codec;
|
||||
@ -266,12 +266,12 @@ OH_AVErrCode OH_AVCodec_Stop(struct OH_AVCodec *codec)
|
||||
CHECK_AND_RETURN_RET_LOG(codecObj->codec_ != nullptr, AV_ERR_INVALID_VAL, "codec_ is nullptr!");
|
||||
|
||||
codecObj->isStop_.store(true);
|
||||
MEDIA_LOGD("Set stop status to true");
|
||||
AVCODEC_LOGD("Set stop status to true");
|
||||
|
||||
int32_t ret = codecObj->codec_->Stop();
|
||||
if (ret != MSERR_OK) {
|
||||
codecObj->isStop_.store(false);
|
||||
MEDIA_LOGE("codec Stop failed! Set stop status to false");
|
||||
AVCODEC_LOGE("codec Stop failed! Set stop status to false");
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
}
|
||||
codecObj->memoryObjList_.clear();
|
||||
@ -287,18 +287,18 @@ OH_AVErrCode OH_AVCodec_Flush(struct OH_AVCodec *codec)
|
||||
CHECK_AND_RETURN_RET_LOG(codecObj->codec_ != nullptr, AV_ERR_INVALID_VAL, "codec_ is nullptr!");
|
||||
|
||||
codecObj->isFlushing_.store(true);
|
||||
MEDIA_LOGD("Set flush status to true");
|
||||
AVCODEC_LOGD("Set flush status to true");
|
||||
|
||||
int32_t ret = codecObj->codec_->Flush();
|
||||
if (ret != MSERR_OK) {
|
||||
codecObj->isFlushing_.store(false);
|
||||
MEDIA_LOGD("codec Flush failed! Set flush status to false");
|
||||
AVCODEC_LOGD("codec Flush failed! Set flush status to false");
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
}
|
||||
|
||||
codecObj->memoryObjList_.clear();
|
||||
codecObj->isFlushing_.store(false);
|
||||
MEDIA_LOGD("Set flush status to false");
|
||||
AVCODEC_LOGD("Set flush status to false");
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
@ -309,11 +309,11 @@ OH_AVErrCode OH_AVCodec_Reset(struct OH_AVCodec *codec)
|
||||
struct CodecObject *codecObj = reinterpret_cast<CodecObject *>(codec);
|
||||
CHECK_AND_RETURN_RET_LOG(codecObj->codec_ != nullptr, AV_ERR_INVALID_VAL, "codec_ is nullptr!");
|
||||
codecObj->isStop_.store(false);
|
||||
MEDIA_LOGD("Set stop status to true");
|
||||
AVCODEC_LOGD("Set stop status to true");
|
||||
int32_t ret = codecObj->codec_->Reset();
|
||||
if (ret != MSERR_OK) {
|
||||
codecObj->isStop_.store(false);
|
||||
MEDIA_LOGE("codec Reset failed! Set stop status to false");
|
||||
AVCODEC_LOGE("codec Reset failed! Set stop status to false");
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
}
|
||||
|
||||
@ -338,7 +338,7 @@ OH_AVErrCode OH_AVCodec_VideoDecoderSetSurface(OH_AVCodec *codec, OHNativeWindow
|
||||
|
||||
OH_AVErrCode OH_AVCodec_QueueInputBuffer(struct OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr)
|
||||
{
|
||||
MEDIA_LOGD("In OH_AVCodec_QueueInputBuffer");
|
||||
AVCODEC_LOGD("In OH_AVCodec_QueueInputBuffer");
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "input codec is nullptr!");
|
||||
|
||||
struct CodecObject *codecObj = reinterpret_cast<CodecObject *>(codec);
|
||||
@ -378,7 +378,7 @@ OH_AVFormat *OH_AVCodec_GetOutputFormat(struct OH_AVCodec *codec)
|
||||
|
||||
OH_AVErrCode OH_AVCodec_VideoDecoderRenderFrame(struct OH_AVCodec *codec, uint32_t index)
|
||||
{
|
||||
MEDIA_LOGD("In OH_AVCodec_VideoDecoderRenderFrame");
|
||||
AVCODEC_LOGD("In OH_AVCodec_VideoDecoderRenderFrame");
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "input codec is nullptr!");
|
||||
|
||||
struct CodecObject *codecObj = reinterpret_cast<CodecObject *>(codec);
|
||||
@ -392,7 +392,7 @@ OH_AVErrCode OH_AVCodec_VideoDecoderRenderFrame(struct OH_AVCodec *codec, uint32
|
||||
|
||||
OH_AVErrCode OH_AVCodec_ReleaseOutputData(struct OH_AVCodec *codec, uint32_t index)
|
||||
{
|
||||
MEDIA_LOGD("In OH_AVCodec_ReleaseOutputData");
|
||||
AVCODEC_LOGD("In OH_AVCodec_ReleaseOutputData");
|
||||
CHECK_AND_RETURN_RET_LOG(codec != nullptr, AV_ERR_INVALID_VAL, "input codec is nullptr!");
|
||||
|
||||
struct CodecObject *codecObj = reinterpret_cast<CodecObject *>(codec);
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include "avdemuxer.h"
|
||||
#include "native_avcodec_demuxer.h"
|
||||
#include "native_avmagic.h"
|
||||
#include "media_error.h"
|
||||
#include "media_errors.h"
|
||||
#include "media_log.h"
|
||||
|
||||
namespace {
|
||||
@ -56,12 +56,12 @@ OH_AVErrCode OH_AVDemuxer_Destroy(OH_AVDemuxer *demuxer)
|
||||
if (demuxerObj != nullptr && demuxerObj->demuxer_ != nullptr) {
|
||||
int32_t ret = demuxerObj->demuxer_->Destroy();
|
||||
if (ret != MSERR_OK) {
|
||||
MEDIA_LOGE("demuxer Destroy failed!");
|
||||
AVCODEC_LOGE("demuxer Destroy failed!");
|
||||
delete demuxer;
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
}
|
||||
} else {
|
||||
MEDIA_LOGE("demuxer_ is nullptr!");
|
||||
AVCODEC_LOGE("demuxer_ is nullptr!");
|
||||
}
|
||||
|
||||
delete demuxer;
|
||||
|
150
frameworks/native/capi/avmuxer/native_avmuxer.cpp
Normal file
150
frameworks/native/capi/avmuxer/native_avmuxer.cpp
Normal file
@ -0,0 +1,150 @@
|
||||
/*
|
||||
* 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 "native_avmuxer.h"
|
||||
#include "native_avmagic.h"
|
||||
#include "avmuxer.h"
|
||||
#include "av_log.h"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "NativeAVMuxer"};
|
||||
}
|
||||
|
||||
using namespace OHOS::Media;
|
||||
|
||||
struct AVMuxerObject : public OH_AVMuxer {
|
||||
explicit AVMuxerObject(const std::shared_ptr<AVMuxer> &muxer)
|
||||
: OH_AVMuxer(AVMagic::AVCODEC_MAGIC_AVMUXER), muxer_(muxer) {}
|
||||
~AVMuxerObject() = default;
|
||||
|
||||
const std::shared_ptr<AVMuxer> muxer_;
|
||||
};
|
||||
|
||||
struct OH_AVMuxer *OH_AVMuxer_Create(int32_t fd, OH_AVOutputFormat format) {
|
||||
CHECK_AND_RETURN_RET_LOG(fd >= 0, nullptr, "fd %d is error!", fd);
|
||||
std::shared_ptr<AVMuxer> avmuxer = AVMuxerFactory::CreateAVMuxer(fd, format);
|
||||
CHECK_AND_RETURN_RET_LOG(avmuxer != nullptr, nullptr, "failed to AVMuxerFactory::CreateAVMuxer");
|
||||
struct AVMuxerObject *object = new(std::nothrow) AVMuxerObject(avmuxer);
|
||||
return object;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVMuxer_SetLocation(OH_AVMuxer *muxer, float latitude, float longitude) {
|
||||
CHECK_AND_RETURN_RET_LOG(muxer != nullptr, AV_ERR_INVALID_VAL, "input muxer is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(muxer->magic_ == AVMagic::AVCODEC_MAGIC_AVMUXER, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
struct AVMuxerObject *object = reinterpret_cast<AVMuxerObject *>(muxer);
|
||||
CHECK_AND_RETURN_RET_LOG(object->muxer_ != nullptr, AV_ERR_INVALID_VAL, "muxer_ is nullptr!");
|
||||
|
||||
int32_t ret = object->muxer_->SetLocation(latitude, longitude);
|
||||
CHECK_AND_RETURN_RET_LOG(ret == Status::CSERR_OK, AV_ERR_OPERATE_NOT_PERMIT, "muxer_ SetLocation failed!");
|
||||
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVMuxer_SetRotation(OH_AVMuxer *muxer, int32_t rotation) {
|
||||
CHECK_AND_RETURN_RET_LOG(muxer != nullptr, AV_ERR_INVALID_VAL, "input muxer is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(muxer->magic_ == AVMagic::AVCODEC_MAGIC_AVMUXER, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
struct AVMuxerObject *object = reinterpret_cast<AVMuxerObject *>(muxer);
|
||||
CHECK_AND_RETURN_RET_LOG(object->muxer_ != nullptr, AV_ERR_INVALID_VAL, "muxer_ is nullptr!");
|
||||
|
||||
if (rotation != V_ROTATION_0 && rotation != V_ROTATION_90 &&
|
||||
rotation != V_ROTATION_180 &&rotation != V_ROTATION_270) {
|
||||
CHECK_AND_RETURN_RET_LOG(false, AV_ERR_INVALID_VAL, "rotation is invalid value!");
|
||||
}
|
||||
|
||||
int32_t ret = object->muxer_->SetRotation(rotation);
|
||||
CHECK_AND_RETURN_RET_LOG(ret == Status::CSERR_OK, AV_ERR_OPERATE_NOT_PERMIT, "muxer_ SetRotation failed!");
|
||||
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVMuxer_SetParameter(OH_AVMuxer *muxer, OH_AVFormat *generalFormat) {
|
||||
CHECK_AND_RETURN_RET_LOG(muxer != nullptr, AV_ERR_INVALID_VAL, "input muxer is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(muxer->magic_ == AVMagic::AVCODEC_MAGIC_AVMUXER, AV_ERR_INVALID_VAL, "magic error!");
|
||||
CHECK_AND_RETURN_RET_LOG(generalFormat != nullptr, AV_ERR_INVALID_VAL, "input general format is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(generalFormat->magic_ == AVMagic::AVCODEC_MAGIC_FORMAT, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
struct AVMuxerObject *object = reinterpret_cast<AVMuxerObject *>(muxer);
|
||||
CHECK_AND_RETURN_RET_LOG(object->muxer_ != nullptr, AV_ERR_INVALID_VAL, "muxer_ is nullptr!");
|
||||
|
||||
int32_t ret = object->muxer_->SetParameter(generalFormat->format_);
|
||||
|
||||
CHECK_AND_RETURN_RET_LOG(ret == Status::CSERR_OK, AV_ERR_OPERATE_NOT_PERMIT, "muxer_ SetParameter failed!");
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
int32_t OH_AVMuxer_AddTrack(OH_AVMuxer *muxer, OH_AVFormat *trackFormat) {
|
||||
CHECK_AND_RETURN_RET_LOG(muxer != nullptr, AV_ERR_INVALID_VAL, "input muxer is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(muxer->magic_ == AVMagic::AVCODEC_MAGIC_AVMUXER, AV_ERR_INVALID_VAL, "magic error!");
|
||||
CHECK_AND_RETURN_RET_LOG(trackFormat != nullptr, AV_ERR_INVALID_VAL, "input track format is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(trackFormat->magic_ == AVMagic::AVCODEC_MAGIC_FORMAT, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
struct AVMuxerObject *object = reinterpret_cast<AVMuxerObject *>(muxer);
|
||||
CHECK_AND_RETURN_RET_LOG(object->muxer_ != nullptr, AV_ERR_INVALID_VAL, "muxer_ is nullptr!");
|
||||
|
||||
int32_t ret = object->muxer_->AddTrack(trackFormat->format_);
|
||||
CHECK_AND_RETURN_RET_LOG(ret >= Status::CSERR_OK, AV_ERR_OPERATE_NOT_PERMIT, "muxer_ AddTrack failed!");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVMuxer_Start(OH_AVMuxer *muxer) {
|
||||
CHECK_AND_RETURN_RET_LOG(muxer != nullptr, AV_ERR_INVALID_VAL, "input muxer is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(muxer->magic_ == AVMagic::AVCODEC_MAGIC_AVMUXER, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
struct AVMuxerObject *object = reinterpret_cast<AVMuxerObject *>(muxer);
|
||||
CHECK_AND_RETURN_RET_LOG(object->muxer_ != nullptr, AV_ERR_INVALID_VAL, "muxer_ is nullptr!");
|
||||
|
||||
int32_t ret = object->muxer_->Start();
|
||||
CHECK_AND_RETURN_RET_LOG(ret == Status::CSERR_OK, AV_ERR_OPERATE_NOT_PERMIT, "muxer_ Start failed!");
|
||||
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVMuxer_WriteSampleBuffer(OH_AVMuxer *muxer, uint32_t trackIndex, uint8_t *sampleBuffer, OH_AVCodecBufferInfo info) {
|
||||
CHECK_AND_RETURN_RET_LOG(muxer != nullptr, AV_ERR_INVALID_VAL, "input muxer is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(muxer->magic_ == AVMagic::AVCODEC_MAGIC_AVMUXER, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
struct AVMuxerObject *object = reinterpret_cast<AVMuxerObject *>(muxer);
|
||||
CHECK_AND_RETURN_RET_LOG(object->muxer_ != nullptr, AV_ERR_INVALID_VAL, "muxer_ is nullptr!");
|
||||
|
||||
int32_t ret = object->muxer_->WriteSampleBuffer(trackIndex, sampleBuffer, info);
|
||||
CHECK_AND_RETURN_RET_LOG(ret == Status::CSERR_OK, AV_ERR_OPERATE_NOT_PERMIT, "muxer_ WriteSampleBuffer failed!");
|
||||
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVMuxer_Stop(OH_AVMuxer *muxer) {
|
||||
CHECK_AND_RETURN_RET_LOG(muxer != nullptr, AV_ERR_INVALID_VAL, "input muxer is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(muxer->magic_ == AVMagic::AVCODEC_MAGIC_AVMUXER, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
struct AVMuxerObject *object = reinterpret_cast<AVMuxerObject *>(muxer);
|
||||
CHECK_AND_RETURN_RET_LOG(object->muxer_ != nullptr, AV_ERR_INVALID_VAL, "muxer_ is nullptr!");
|
||||
|
||||
int32_t ret = object->muxer_->Stop();
|
||||
CHECK_AND_RETURN_RET_LOG(ret == Status::CSERR_OK, AV_ERR_OPERATE_NOT_PERMIT, "muxer_ Stop failed!");
|
||||
|
||||
return AV_ERR_OK;
|
||||
}
|
||||
|
||||
OH_AVErrCode OH_AVMuxer_Destroy(OH_AVMuxer *muxer) {
|
||||
CHECK_AND_RETURN_RET_LOG(muxer != nullptr, AV_ERR_INVALID_VAL, "input muxer is nullptr!");
|
||||
CHECK_AND_RETURN_RET_LOG(muxer->magic_ == AVMagic::AVCODEC_MAGIC_AVMUXER, AV_ERR_INVALID_VAL, "magic error!");
|
||||
|
||||
delete muxer;
|
||||
|
||||
return AV_ERR_OK;
|
||||
}
|
@ -17,8 +17,7 @@
|
||||
|
||||
#include "securec.h"
|
||||
#include "native_avmagic.h"
|
||||
#include "media_log.h"
|
||||
#include "media_errors.h"
|
||||
#include "av_log.h"
|
||||
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "OH_AVFormat"};
|
||||
@ -177,7 +176,7 @@ bool OH_AVFormat_GetStringValue(struct OH_AVFormat *format, const char *key, con
|
||||
CHECK_AND_RETURN_RET_LOG(format->outString_ != nullptr, false, "malloc out string nullptr!");
|
||||
|
||||
if (strcpy_s(format->outString_, bufLength + 1, str.c_str()) != EOK) {
|
||||
MEDIA_LOGE("Failed to strcpy_s");
|
||||
AVCODEC_LOGE("Failed to strcpy_s");
|
||||
free(format->outString_);
|
||||
format->outString_ = nullptr;
|
||||
return false;
|
||||
@ -212,7 +211,7 @@ const char *OH_AVFormat_DumpInfo(struct OH_AVFormat *format)
|
||||
format->dumpInfo_ = static_cast<char *>(malloc((bufLength + 1) * sizeof(char)));
|
||||
CHECK_AND_RETURN_RET_LOG(format->dumpInfo_ != nullptr, nullptr, "malloc dump info nullptr!");
|
||||
if (strcpy_s(format->dumpInfo_, bufLength + 1, info.c_str()) != EOK) {
|
||||
MEDIA_LOGE("Failed to strcpy_s");
|
||||
AVCODEC_LOGE("Failed to strcpy_s");
|
||||
free(format->dumpInfo_);
|
||||
format->dumpInfo_ = nullptr;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022-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
|
||||
@ -20,6 +20,20 @@
|
||||
#include "format.h"
|
||||
#include "avsharedmemory.h"
|
||||
|
||||
|
||||
#define AV_MAGIC(a, b, c, d) (((a) << 24) + ((b) << 16) + ((c) << 8) + ((d) << 0))
|
||||
|
||||
enum AVMagic {
|
||||
AVCODEC_MAGIC_AVMUXER = AV_MAGIC('M', 'U', 'X', 'R'),
|
||||
AVCODEC_MAGIC_FORMAT = AV_MAGIC('F', 'R', 'M', 'T'),
|
||||
};
|
||||
|
||||
struct AVObjectMagic : public OHOS::RefBase {
|
||||
explicit AVObjectMagic(enum AVMagic m) : magic_(m) {}
|
||||
virtual ~AVObjectMagic() = default;
|
||||
enum AVMagic magic_;
|
||||
};
|
||||
|
||||
struct OH_AVFormat : public OHOS::RefBase {
|
||||
OH_AVFormat();
|
||||
explicit OH_AVFormat(const OHOS::AVCodec::Format &fmt);
|
||||
@ -47,4 +61,9 @@ struct OH_AVCodec : public OHOS::RefBase {
|
||||
explicit OH_AVCodec();
|
||||
virtual ~OH_AVCodec() = default;
|
||||
};
|
||||
|
||||
struct OH_AVMuxer : public AVObjectMagic {
|
||||
explicit OH_AVMuxer(enum AVMagic m) : AVObjectMagic(m) {}
|
||||
virtual ~OH_AVMuxer() = default;
|
||||
};
|
||||
#endif // NATIVE_AVMAGIC_H
|
@ -13,11 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include "avsource.h"
|
||||
#include "native_avmagic.h"
|
||||
#include "native_avsource.h"
|
||||
#include "media_error.h"
|
||||
#include "media_errors.h"
|
||||
#include "media_log.h"
|
||||
|
||||
namespace {
|
||||
@ -34,11 +33,11 @@ struct SourceObject : public OH_AVSource {
|
||||
const std::shared_ptr<OH_AVSource> source_;
|
||||
};
|
||||
|
||||
struct OH_AVSource *OH_AVSource_CreateWithURI(char *uri)
|
||||
struct OH_AVSource *OH_AVSource_CreateWithURI(const char *uri)
|
||||
{
|
||||
CHECK_AND_RETURN_RET_LOG(uri != nullptr, nullptr, "input uri is nullptr!");
|
||||
|
||||
std::shared_ptr<AVSource> source = std::make_shared_ptr<AVSource>(uri);
|
||||
std::shared_ptr<AVSource> source = SourceFactory::CreateWithURI(uri);
|
||||
CHECK_AND_RETURN_RET_LOG(source != nullptr, nullptr, "failed to new Source!");
|
||||
|
||||
struct SourceObject *object = new(std::nothrow) SourceObject(source);
|
||||
@ -56,7 +55,7 @@ struct OH_AVSource *OH_AVSource_CreateWithFd(int32_t fd, int64_t offset, int64_t
|
||||
std::String uri = std::format("fd://()?offset=()&size=()", fd, offset, size)
|
||||
CHECK_AND_RETURN_RET_LOG(uri != nullptr, nullptr, "Format uri is nullptr!");
|
||||
|
||||
std::shared_ptr<AVSource> source = std::make_shared_ptr<AVSource>(uri.c_str());
|
||||
std::shared_ptr<AVSource> source = SourceFactory::CreateWithURI(uri);
|
||||
CHECK_AND_RETURN_RET_LOG(source != nullptr, nullptr, "failed to new Source!");
|
||||
|
||||
struct SourceObject *object = new(std::nothrow) SourceObject(source);
|
||||
@ -74,12 +73,12 @@ OH_AVErrCode OH_AVSource_Destroy(OH_AVSource *source)
|
||||
if (sourceObj != nullptr && sourceObj->source_ != nullptr) {
|
||||
int32_t ret = sourceObj->source_->Destroy();
|
||||
if (ret != MSERR_OK) {
|
||||
MEDIA_LOGE("source Destroy failed!");
|
||||
AVCODEC_LOGE("source Destroy failed!");
|
||||
delete source;
|
||||
return AV_ERR_OPERATE_NOT_PERMIT;
|
||||
}
|
||||
} else {
|
||||
MEDIA_LOGE("source_ is nullptr!");
|
||||
AVCODEC_LOGE("source_ is nullptr!");
|
||||
}
|
||||
|
||||
delete source;
|
||||
@ -130,7 +129,7 @@ OH_AVErrCode OH_AVSourceTrack_SetParameter(OH_AVSourceTrack *sourceTrack, OH_AVF
|
||||
struct SourceTrackObject *sourceTrackObj = reinterpret_cast<SourceTrackObject *>(sourceTrack);
|
||||
CHECK_AND_RETURN_RET_LOG(sourceTrackObj->sourceTrack_ != nullptr, nullptr, "sourceTrack_ is nullptr!");
|
||||
|
||||
int32_t ret = sourceTrackObj->sourceTrack_->SetParameter(sourceTrack, param->format_);
|
||||
int32_t ret = sourceTrackObj->sourceTrack_->SetParameter(param->format_);
|
||||
CHECK_AND_RETURN_RET_LOG(ret != MSERR_OK, AV_ERR_OPERATE_NOT_PERMIT, "sourceTrack SetParameter failed!");
|
||||
|
||||
return AV_ERR_OK;
|
||||
|
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
|
29
hisysevent.yaml
Normal file
29
hisysevent.yaml
Normal file
@ -0,0 +1,29 @@
|
||||
# Copyright (c) 2022 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.
|
||||
|
||||
domain: AVCODEC
|
||||
|
||||
AVCODEC_ERR:
|
||||
__BASE: {type: FAULT, level: CRITICAL, desc: AVCodec error}
|
||||
PID: {type: INT32, desc: The pid of the AVCODEC_ERR event}
|
||||
UID: {type: INT32, desc: The uid of the AVCODEC_ERR event}
|
||||
MODULE: {type: STRING, desc: module name}
|
||||
ERRORCODE: {type: INT32, desc: error code}
|
||||
MSG: {type: STRING, desc: error description}
|
||||
|
||||
AVCODEC_STATE:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, desc: state change}
|
||||
PID: {type: INT32, desc: The pid of the AVCODEC_STATE event}
|
||||
UID: {type: INT32, desc: The uid of the AVCODEC_STATE event}
|
||||
MODULE: {type: STRING, desc: module name}
|
||||
STATE: {type: STRING, desc: current state}
|
110
interfaces/inner_api/native/BUILD.gn
Normal file
110
interfaces/inner_api/native/BUILD.gn
Normal file
@ -0,0 +1,110 @@
|
||||
# Copyright (C) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/multimedia/av_codec/config.gni")
|
||||
|
||||
AV_CODEC_ROOT_DIR = "//foundation/multimedia/av_codec"
|
||||
|
||||
config("av_codec_client_local_config") {
|
||||
include_dirs = [
|
||||
"$AV_CODEC_ROOT_DIR/services/services/factory",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/muxer",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/factory",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/muxer",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/plugin/common",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/plugin/core",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/plugin/interface",
|
||||
]
|
||||
}
|
||||
|
||||
config("av_codec_client_public_config") {
|
||||
include_dirs = [
|
||||
"$AV_CODEC_ROOT_DIR/frameworks/native/avmuxer",
|
||||
"$AV_CODEC_ROOT_DIR/interfaces/inner_api/native",
|
||||
"$AV_CODEC_ROOT_DIR/interfaces/kits/c",
|
||||
"$AV_CODEC_ROOT_DIR/services/utils",
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-fno-exceptions",
|
||||
"-Wall",
|
||||
"-fno-common",
|
||||
"-fstack-protector-strong",
|
||||
"-Wshadow",
|
||||
"-FPIC",
|
||||
"-FS",
|
||||
"-O2",
|
||||
"-D_FORTIFY_SOURCE=2",
|
||||
"-Wformat=2",
|
||||
"-Wdate-time",
|
||||
]
|
||||
|
||||
cflags_cc = [
|
||||
"-std=c++17",
|
||||
"-fno-rtti",
|
||||
]
|
||||
|
||||
if (target_cpu == "arm") {
|
||||
cflags += [ "-DBINDER_IPC_32BIT" ]
|
||||
}
|
||||
|
||||
defines = []
|
||||
defines += av_codec_defines
|
||||
|
||||
if (target_cpu == "arm64") {
|
||||
av_codec_plugin_path = "\"/system/lib64/media/av_codec_plugins\""
|
||||
} else {
|
||||
av_codec_plugin_path = "\"/system/lib/media/av_codec_plugins\""
|
||||
}
|
||||
|
||||
defines += [
|
||||
"AV_CODEC_PLUGIN_PATH=${av_codec_plugin_path}",
|
||||
"AV_CODEC_PLUGIN_FILE_TAIL=\".z.so\"",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("av_codec_client") {
|
||||
install_enable = true
|
||||
|
||||
sources = [
|
||||
"$AV_CODEC_ROOT_DIR/frameworks/native/avmuxer/avmuxer_impl.cpp",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/muxer/muxer_engine_impl.cpp",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/factory/muxer_factory.cpp",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/plugin/core/muxer.cpp",
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/plugin/core/plugin_loader.cpp",
|
||||
]
|
||||
|
||||
public_configs = [
|
||||
":av_codec_client_local_config",
|
||||
":av_codec_client_public_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"$AV_CODEC_ROOT_DIR/services/engine/plugin:av_codec_plugin",
|
||||
"$AV_CODEC_ROOT_DIR/services/utils:av_codec_format",
|
||||
"//third_party/bounds_checking_function:libsec_static",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
]
|
||||
|
||||
subsystem_name = "multimedia"
|
||||
part_name = "multimedia_av_codec"
|
||||
}
|
59
interfaces/inner_api/native/av_base.h
Normal file
59
interfaces/inner_api/native/av_base.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 AV_BASE_H
|
||||
#define AV_BASE_H
|
||||
|
||||
#include <memory>
|
||||
#include "native_avbase.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
using AudioSampleFormat = OH_AudioSampleFormat;
|
||||
using AudioChannelSet = OH_AudioChannelSet;
|
||||
using AudioChannelMask = OH_AudioChannelMask;
|
||||
using AudioAacProfile = OH_AudioAacProfile;
|
||||
using VideoPixelFormat = OH_VideoPixelFormat;
|
||||
using VideoH264Profile = OH_VideoH264Profile;
|
||||
using OutputFormat = OH_AVOutputFormat ;
|
||||
using AVCodecBufferInfo = OH_AVCodecBufferInfo;
|
||||
using AVCodecBufferFlags = OH_AVCodecBufferFlags;
|
||||
|
||||
enum Status : int32_t {
|
||||
CSERR_OK = 0, ///< The execution result is correct.
|
||||
CSERR_UNKNOWN = -1, ///< An unknown error occurred.
|
||||
CSERR_PLUGIN_ALREADY_EXISTS = -2, ///< The plugin already exists, usually occurs when in plugin registered.
|
||||
CSERR_INCOMPATIBLE_VERSION = -3, ///< Incompatible version, may occur during plugin registration or function calling.
|
||||
CSERR_NO_MEMORY = -4, ///< The system memory is insufficient.
|
||||
CSERR_WRONG_STATE = -5, ///< The function is called in an invalid state.
|
||||
CSERR_UNIMPLEMENTED = -6, ///< This method or interface is not implemented.
|
||||
CSERR_INVALID_PARAMETER = -7, ///< The plugin does not support this parameter.
|
||||
CSERR_INVALID_DATA = -8, ///< The value is not in the valid range.
|
||||
CSERR_MISMATCHED_TYPE = -9, ///< Mismatched data type
|
||||
CSERR_TIMED_OUT = -10, ///< Operation timeout.
|
||||
CSERR_UNSUPPORTED_FORMAT = -11, ///< The plugin not support this format/name.
|
||||
CSERR_NOT_ENOUGH_DATA = -12, ///< Not enough data when read from source.
|
||||
CSERR_NOT_EXISTED = -13, ///< Source is not existed.
|
||||
CSERR_AGAIN = -14, ///< Operation is not available right now, should try again later.
|
||||
CSERR_PERMISSION_DENIED = -15, ///< Permission denied.
|
||||
CSERR_NULL_POINTER = -16, ///< Null pointer.
|
||||
CSERR_INVALID_OPERATION = -17, ///< Invalid operation.
|
||||
CSERR_CLIENT = -18, ///< Http client error
|
||||
CSERR_SERVER = -19, ///< Http server error
|
||||
CSERR_DELAY_READY = -20, ///< Delay ready event
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
#endif // AV_BASE_H
|
@ -56,6 +56,8 @@ struct AVCodecBufferInfo {
|
||||
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 {
|
||||
|
101
interfaces/inner_api/native/avcodec_errors.h
Normal file
101
interfaces/inner_api/native/avcodec_errors.h
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
__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
|
@ -78,21 +78,20 @@ public:
|
||||
class __attribute__((visibility("default"))) DemuxerFactory {
|
||||
public:
|
||||
#ifdef UNSUPPORT_DEMUXER
|
||||
static std::shared_ptr<AVDemuxer> CreateWithSource(Source *source)
|
||||
static std::shared_ptr<AVDemuxer> CreateWithSource(uint8_t sourceAddr)
|
||||
{
|
||||
(void)source;
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
/**
|
||||
* @brief Instantiate the preferred demuxer of the given source instance.
|
||||
*
|
||||
* @param source The source model for demuxer.
|
||||
* @return Returns the designated demuxer.
|
||||
* @param sourceAddr The address for source instance.
|
||||
* @return Returns the preferred demuxer.
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
static std::shared_ptr<AVDemuxer> CreateWithSource(Source *source);
|
||||
static std::shared_ptr<AVDemuxer> CreateWithSource(uint8_t sourceAddr);
|
||||
#endif
|
||||
private:
|
||||
DemuxerFactory() = default;
|
||||
|
46
interfaces/inner_api/native/avmuxer.h
Normal file
46
interfaces/inner_api/native/avmuxer.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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 AVMUXER_H
|
||||
#define AVMUXER_H
|
||||
|
||||
#include "format.h"
|
||||
#include "av_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Media {
|
||||
class AVMuxer {
|
||||
public:
|
||||
virtual ~AVMuxer() = default;
|
||||
virtual int32_t SetLocation(float latitude, float longitude) = 0;
|
||||
virtual int32_t SetRotation(int32_t rotation) = 0;
|
||||
virtual int32_t SetParameter(const Format &generalFormat) = 0;
|
||||
virtual int32_t AddTrack(const Format &trackFormat) = 0;
|
||||
virtual int32_t Start() = 0;
|
||||
virtual int32_t WriteSampleBuffer(uint32_t trackIndex, uint8_t *sampleBuffer, AVCodecBufferInfo info) = 0;
|
||||
virtual int32_t Stop() = 0;
|
||||
};
|
||||
|
||||
class __attribute__((visibility("default"))) AVMuxerFactory {
|
||||
public:
|
||||
static std::shared_ptr<AVMuxer> CreateAVMuxer(int32_t fd, OutputFormat format);
|
||||
private:
|
||||
AVMuxerFactory() = default;
|
||||
~AVMuxerFactory() = default;
|
||||
};
|
||||
} // namespace Media
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // AVMUXER_H
|
@ -16,26 +16,18 @@
|
||||
#ifndef AVSOURCE_H
|
||||
#define AVSOURCE_H
|
||||
|
||||
#include <stdint>
|
||||
#include <memory>
|
||||
#include "native_avcodec_base.h"
|
||||
#include "libavformat/avformat.h"
|
||||
#include <stdint>
|
||||
#include <string>
|
||||
#include "avcodec_common.h"
|
||||
#include "format.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec{
|
||||
|
||||
class __attribute__((visibility("default"))) AVSource {
|
||||
class AVSource {
|
||||
public:
|
||||
/**
|
||||
* @brief Instantiate the source of the given uri.
|
||||
*
|
||||
* @param uri The source model for demuxer.
|
||||
* @return Returns the designated demuxer.
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
static Source(const std::string &uri);
|
||||
virtual ~Source() = default;
|
||||
virtual ~AVSource() = default;
|
||||
|
||||
/**
|
||||
* @brief Count number of the track in source.
|
||||
@ -55,24 +47,36 @@ public:
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual std::shared_ptr<SourceTrack> LoadSourceTrackByID(uint32_t trackId) = 0;
|
||||
|
||||
private:
|
||||
std::shared_ptr<AVFormatContext> formatContext_ = nullptr;
|
||||
|
||||
};
|
||||
|
||||
class __attribute__((visibility("default"))) AVSourceTrack {
|
||||
public:
|
||||
class __attribute__((visibility("default"))) SourceFactory {
|
||||
#ifdef UNSUPPORT_SOURCE
|
||||
static std::shared_ptr<AVSource> CreateWithURI(const std::string &uri)
|
||||
{
|
||||
(void)uri;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* @brief Instantiate the sourceTrack of the given trackId from formatContext.
|
||||
*
|
||||
* @param formatContext The ffmpeg source model.
|
||||
* @param trackId The index of the track.
|
||||
* @brief Instantiate the preferred source of the uri.
|
||||
*
|
||||
* @param uri The file's uri.
|
||||
* @return Returns the preferred source.
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
SourceTrack(const AVFormatContext &formatContext, uint32_t trackId);
|
||||
virtual ~SourceTrack() = default;
|
||||
static std::shared_ptr<AVSource> CreateWithURI(const std::string &uri);
|
||||
|
||||
#endif
|
||||
private:
|
||||
SourceFactory() = default;
|
||||
~SourceFactory() = default;
|
||||
};
|
||||
|
||||
class AVSourceTrack {
|
||||
public:
|
||||
virtual ~AVSourceTrack() = default;
|
||||
|
||||
/**
|
||||
* @brief Sets the parameters to the track.
|
||||
@ -82,7 +86,7 @@ public:
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual uint32_t SetParameter(const Format ¶m) = 0;
|
||||
virtual int32_t SetParameter(const Format ¶m) = 0;
|
||||
|
||||
/**
|
||||
* @brief Gets the parameters of the track.
|
||||
@ -91,12 +95,9 @@ public:
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
*/
|
||||
virtual std::shared_ptr<Format> GetTrackFormat() = 0;
|
||||
virtual std::shared_ptr<Format> GetTrackFormat(Format &format) = 0;
|
||||
private:
|
||||
uint32_t trackId_;
|
||||
OH_MediaType trackType_;
|
||||
std::unique_ptr<Format> trackFormat_;
|
||||
std::shared_ptr<AVStream> stream_;
|
||||
};
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
||||
|
@ -68,8 +68,8 @@ public:
|
||||
* @param key Indicates the metadata key.
|
||||
* @param value Indicates the metadata value, which is a 32-bit integer.
|
||||
* @return Returns <b>true</b> if the setting is successful; returns <b>false</b> otherwise.
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
bool PutIntValue(const std::string_view &key, int32_t value);
|
||||
|
||||
@ -79,8 +79,8 @@ public:
|
||||
* @param key Indicates the metadata key.
|
||||
* @param value Indicates the metadata value, which is a 64-bit integer.
|
||||
* @return Returns <b>true</b> if the setting is successful; returns <b>false</b> otherwise.
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
bool PutLongValue(const std::string_view &key, int64_t value);
|
||||
|
||||
@ -90,8 +90,8 @@ public:
|
||||
* @param key Indicates the metadata key.
|
||||
* @param value Indicates the metadata value, which is a single-precision floating-point number.
|
||||
* @return Returns <b>true</b> if the metadata is successfully set; returns <b>false</b> otherwise.
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
bool PutFloatValue(const std::string_view &key, float value);
|
||||
|
||||
@ -101,8 +101,8 @@ public:
|
||||
* @param key Indicates the metadata key.
|
||||
* @param value Indicates the metadata value, which is a double-precision floating-point number.
|
||||
* @return Returns <b>true</b> if the setting is successful; returns <b>false</b> otherwise.
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
bool PutDoubleValue(const std::string_view &key, double value);
|
||||
|
||||
@ -112,8 +112,8 @@ public:
|
||||
* @param key Indicates the metadata key.
|
||||
* @param value Indicates the metadata value, which is a string.
|
||||
* @return Returns <b>true</b> if the metadata is successfully set; returns <b>false</b> otherwise.
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
bool PutStringValue(const std::string_view &key, const std::string_view &value);
|
||||
|
||||
@ -124,8 +124,8 @@ public:
|
||||
* @param addr Indicates the metadata addr, which is a uint8_t *.
|
||||
* @param size Indicates the metadata addr size, which is a size_t.
|
||||
* @return Returns <b>true</b> if the metadata is successfully set; returns <b>false</b> otherwise.
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
bool PutBuffer(const std::string_view &key, const uint8_t *addr, size_t size);
|
||||
|
||||
@ -135,8 +135,8 @@ public:
|
||||
* @param key Indicates the metadata key.
|
||||
* @param value Indicates the metadata value to obtain, which is a 32-bit integer.
|
||||
* @return Returns <b>true</b> if the integer is successfully obtained; returns <b>false</b> otherwise.
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
bool GetIntValue(const std::string_view &key, int32_t &value) const;
|
||||
|
||||
@ -146,8 +146,8 @@ public:
|
||||
* @param key Indicates the metadata key.
|
||||
* @param value Indicates the metadata value to obtain, which is a 64-bit long integer.
|
||||
* @return Returns <b>true</b> if the integer is successfully obtained; returns <b>false</b> otherwise.
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
bool GetLongValue(const std::string_view &key, int64_t &value) const;
|
||||
|
||||
@ -158,8 +158,8 @@ public:
|
||||
* @param value Indicates the metadata value to obtain, which is a single-precision floating-point number.
|
||||
* @return Returns <b>true</b> if the single-precision number is successfully obtained; returns
|
||||
* <b>false</b> otherwise.
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
bool GetFloatValue(const std::string_view &key, float &value) const;
|
||||
|
||||
@ -170,8 +170,8 @@ public:
|
||||
* @param value Indicates the metadata value to obtain, which is a double-precision floating-point number.
|
||||
* @return Returns <b>true</b> if the double-precision number is successfully obtained; returns
|
||||
* <b>false</b> otherwise.
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
bool GetDoubleValue(const std::string_view &key, double &value) const;
|
||||
|
||||
@ -181,8 +181,8 @@ public:
|
||||
* @param key Indicates the metadata key.
|
||||
* @param value Indicates the metadata value to obtain, which is a string.
|
||||
* @return Returns <b>true</b> if the string is successfully obtained; returns <b>false</b> otherwise.
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
bool GetStringValue(const std::string_view &key, std::string &value) const;
|
||||
|
||||
@ -193,8 +193,8 @@ public:
|
||||
* @param addr Indicates the metadata addr to obtain, which is a uint8_t **.
|
||||
* @param size Indicates the metadata addr size to obtain, which is a size_t.
|
||||
* @return Returns <b>true</b> if the string is successfully obtained; returns <b>false</b> otherwise.
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
bool GetBuffer(const std::string_view &key, uint8_t **addr, size_t &size) const;
|
||||
|
||||
@ -233,8 +233,8 @@ public:
|
||||
* @brief Obtains the metadata map.
|
||||
*
|
||||
* @return Returns the map object.
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
const FormatDataMap &GetFormatMap() const;
|
||||
|
||||
@ -242,8 +242,8 @@ public:
|
||||
* @brief Convert the metadata map to string.
|
||||
*
|
||||
* @return Returns a converted string.
|
||||
* @since 4.0
|
||||
* @version 4.0
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
std::string Stringify() const;
|
||||
|
||||
|
@ -0,0 +1,78 @@
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/multimedia/av_codec/config.gni")
|
||||
|
||||
AV_CODEC_ROOT_DIR = "//foundation/multimedia/av_codec"
|
||||
|
||||
group("capi_packages") {
|
||||
deps = []
|
||||
if (multimedia_av_codec_support_capi) {
|
||||
deps += [
|
||||
"//foundation/multimedia/av_codec/interfaces/kits/c:native_av_codec_avmuxer",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
config("av_codec_capi_config") {
|
||||
include_dirs = [
|
||||
"$AV_CODEC_ROOT_DIR/interfaces/inner_api/native",
|
||||
"$AV_CODEC_ROOT_DIR/interfaces/kits/c",
|
||||
"$AV_CODEC_ROOT_DIR/frameworks/native/capi/avmuxer",
|
||||
"$AV_CODEC_ROOT_DIR/frameworks/native/capi/common",
|
||||
"$AV_CODEC_ROOT_DIR/services/utils",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-fno-exceptions",
|
||||
"-Wall",
|
||||
"-fno-common",
|
||||
"-fstack-protector-all",
|
||||
"-Wshadow",
|
||||
"-FPIC",
|
||||
"-FS",
|
||||
"-O2",
|
||||
"-D_FORTIFY_SOURCE=2",
|
||||
"-Wformat=2",
|
||||
"-Wdate-time",
|
||||
]
|
||||
|
||||
cflags_cc = [
|
||||
"-std=c++17",
|
||||
"-fno-rtti",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("native_av_codec_avmuxer") {
|
||||
install_enable = true
|
||||
sources = [
|
||||
"$AV_CODEC_ROOT_DIR/frameworks/native/capi/common/native_avformat.cpp",
|
||||
"$AV_CODEC_ROOT_DIR/frameworks/native/capi/avmuxer/native_avmuxer.cpp",
|
||||
]
|
||||
|
||||
public_configs = [ ":av_codec_capi_config" ]
|
||||
|
||||
deps = [
|
||||
"//foundation/multimedia/av_codec/interfaces/inner_api/native:av_codec_client",
|
||||
"//foundation/multimedia/av_codec/services/utils:av_codec_format",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
]
|
||||
output_extension = "so"
|
||||
subsystem_name = "multimedia"
|
||||
part_name = "multimedia_av_codec"
|
||||
}
|
40
interfaces/kits/c/avmuxer/BUILD.gn
Normal file
40
interfaces/kits/c/avmuxer/BUILD.gn
Normal file
@ -0,0 +1,40 @@
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//build/ohos/ndk/ndk.gni")
|
||||
|
||||
ohos_ndk_headers("native_av_codec_avmuxer_header") {
|
||||
dest_dir = "$ndk_headers_out_dir/multimedia/av_codec"
|
||||
sources = [
|
||||
"//foundation/multimedia/av_codec/interfaces/kits/c/native_avbase.h",
|
||||
"//foundation/multimedia/av_codec/interfaces/kits/c/native_averrors.h",
|
||||
"//foundation/multimedia/av_codec/interfaces/kits/c/native_avformat.h",
|
||||
"//foundation/multimedia/av_codec/interfaces/kits/c/native_avmuxer.h",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_ndk_library("libnative_av_codec_avmuxer") {
|
||||
ndk_description_file = "./libnative_av_codec_avmuxer.ndk.json"
|
||||
min_compact_version = "1"
|
||||
output_name = "native_av_codec_avmuxer"
|
||||
output_extension = "so"
|
||||
|
||||
system_capability = "SystemCapability.Multimedia.Media.AVMuxer"
|
||||
system_capability_headers = [
|
||||
"native_av_codec_avmuxer/native_avbase.h",
|
||||
"native_av_codec_avmuxer/native_averrors.h",
|
||||
"native_av_codec_avmuxer/native_avformat.h",
|
||||
"native_av_codec_avmuxer/native_avmuxer.h",
|
||||
]
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
[
|
||||
{ "name": "OH_AVFormat_Create" },
|
||||
{ "name": "OH_AVFormat_Destroy" },
|
||||
{ "name": "OH_AVFormat_Copy" },
|
||||
{ "name": "OH_AVFormat_SetIntValue" },
|
||||
{ "name": "OH_AVFormat_SetLongValue" },
|
||||
{ "name": "OH_AVFormat_SetFloatValue" },
|
||||
{ "name": "OH_AVFormat_SetDoubleValue" },
|
||||
{ "name": "OH_AVFormat_SetStringValue" },
|
||||
{ "name": "OH_AVFormat_SetBuffer" },
|
||||
{ "name": "OH_AVFormat_GetIntValue" },
|
||||
{ "name": "OH_AVFormat_GetLongValue" },
|
||||
{ "name": "OH_AVFormat_GetFloatValue" },
|
||||
{ "name": "OH_AVFormat_GetDoubleValue" },
|
||||
{ "name": "OH_AVFormat_GetStringValue" },
|
||||
{ "name": "OH_AVFormat_GetBuffer" },
|
||||
{ "name": "OH_AVFormat_DumpInfo" },
|
||||
{ "name": "OH_AVMuxer_Create" },
|
||||
{ "name": "OH_AVMuxer_SetLocation" },
|
||||
{ "name": "OH_AVMuxer_SetRotation" },
|
||||
{ "name": "OH_AVMuxer_SetParameter" },
|
||||
{ "name": "OH_AVMuxer_AddTrack" },
|
||||
{ "name": "OH_AVMuxer_Start" },
|
||||
{ "name": "OH_AVMuxer_WriteSampleBuffer" },
|
||||
{ "name": "OH_AVMuxer_Stop" },
|
||||
{ "name": "OH_AVMuxer_Destroy" }
|
||||
]
|
398
interfaces/kits/c/native_avbase.h
Normal file
398
interfaces/kits/c/native_avbase.h
Normal file
@ -0,0 +1,398 @@
|
||||
/*
|
||||
* 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 NATIVE_AVBASE_H
|
||||
#define NATIVE_AVBASE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* mime type */
|
||||
static const char *OH_AV_MIME_AUDIO_MPEG = "audio/mpeg";
|
||||
static const char *OH_AV_MIME_AUDIO_FLAC = "audio/flac";
|
||||
static const char *OH_AV_MIME_AUDIO_RAW = "audio/raw";
|
||||
static const char *OH_AV_MIME_AUDIO_APE = "audio/ape";
|
||||
static const char *OH_AV_MIME_AUDIO_WAV = "audio/wav";
|
||||
static const char *OH_AV_MIME_AUDIO_AAC = "audio/mp4a-latm";
|
||||
static const char *OH_AV_MIME_AUDIO_AAC_LATM = "audio/aac-latm";
|
||||
static const char *OH_AV_MIME_AUDIO_VORBIS = "audio/vorbis";
|
||||
static const char *OH_AV_MIME_AUDIO_OPUS = "audio/opus";
|
||||
static const char *OH_AV_MIME_AUDIO_AC3 = "audio/ac3";
|
||||
static const char *OH_AV_MIME_AUDIO_EAC3 = "audio/eac3";
|
||||
static const char *OH_AV_MIME_AUDIO_WMA = "audio/x-ms-wma";
|
||||
static const char *OH_AV_MIME_AUDIO_AMR_NB = "audio/3gpp";
|
||||
static const char *OH_AV_MIME_AUDIO_AMR_WB = "audio/amr-wb";
|
||||
|
||||
static const char *OH_AV_MIME_VIDEO_RAW = "video/raw";
|
||||
static const char *OH_AV_MIME_VIDEO_H264 = "video/avc";
|
||||
static const char *OH_AV_MIME_VIDEO_MPEG4 = "video/mp4v-es";
|
||||
|
||||
/* format keys */
|
||||
static const char *OH_AV_KEY_MIME = "mime"; ///< mime type
|
||||
static const char *OH_AV_KEY_BIT_RATE = "bitrate"; ///< int64_t
|
||||
static const char *OH_AV_KEY_CODEC_CONFIG = "codec-config"; ///< uint8_t* codec specific data buffer
|
||||
|
||||
/* audio format keys */
|
||||
static const char *OH_AV_KEY_AUDIO_SAMPLE_FORMAT = "audio-sample-format"; ///< @OH_AudioSampleFormat int32_t
|
||||
static const char *OH_AV_KEY_AUDIO_CHANNELS = "audio-channel-count"; ///< int32_t
|
||||
static const char *OH_AV_KEY_AUDIO_SAMPLE_RATE = "audio-sample-rate"; ///< int32_t
|
||||
static const char *OH_AV_KEY_AUDIO_CHANNEL_MASK = "audio-channel-mask"; ///< @OH_AudioChannelMask uint64_t
|
||||
static const char *OH_AV_KEY_AUDIO_SAMPLE_PER_FRAME = "audio-frame-size"; ///< int32_t
|
||||
static const char *OH_AV_KEY_AUDIO_AAC_PROFILE = "audio-aac-profile"; ///< int32_t
|
||||
|
||||
/* video format keys */
|
||||
static const char *OH_AV_KEY_VIDEO_PIXEL_FORMAT = "video-pixel-format"; ///< OH_VideoPixelFormat int32_t
|
||||
static const char *OH_AV_KEY_VIDEO_WIDTH = "video-width"; ///< int32_t
|
||||
static const char *OH_AV_KEY_VIDEO_HEIGHT = "video-height"; ///< int32_t
|
||||
static const char *OH_AV_KEY_VIDEO_FRAME_RATE = "video-frame-rate"; ///< int32_t
|
||||
static const char *OH_AV_KEY_VIDEO_H264_PROFILE = "video-h264-profile"; ///< int32_t
|
||||
static const char *OH_AV_KEY_VIDEO_H264_LEVEL = "video-h264-level"; ///< int32_t
|
||||
|
||||
/* metadata format keys */
|
||||
static const char *OH_AV_KEY_TITLE = "metadata-title"; ///< const char *
|
||||
static const char *OH_AV_KEY_ARTIST = "metadata-artist"; ///< const char *
|
||||
static const char *OH_AV_KEY_LYRICIST = "metadata-lyricist"; ///< const char *
|
||||
static const char *OH_AV_KEY_ALBUM = "metadata-album"; ///< const char *
|
||||
static const char *OH_AV_KEY_ALBUM_ARTIST = "metadata-album-artist"; ///< const char *
|
||||
static const char *OH_AV_KEY_DATE = "metadata-date"; ///< const char *
|
||||
static const char *OH_AV_KEY_COMMENT = "metadata-comment"; ///< const char *
|
||||
static const char *OH_AV_KEY_GENRE = "metadata-genre"; ///< const char *
|
||||
static const char *OH_AV_KEY_COPYRIGHT = "metadata-copyright"; ///< const char *
|
||||
static const char *OH_AV_KEY_LANGUAGE = "metadata-language"; ///< const char *
|
||||
static const char *OH_AV_KEY_DESCRIPTION = "metadata-description"; ///< const char *
|
||||
static const char *OH_AV_KEY_LYRICS = "metadata-lyrics"; ///< const char *
|
||||
static const char *OH_AV_KEY_AUTHOR = "metadata-author"; ///< const char *
|
||||
static const char *OH_AV_KEY_COMPOSER = "metadata-composer"; ///< const char *
|
||||
static const char *OH_AV_KEY_MAKE = "metadata-make"; ///< const char *
|
||||
static const char *OH_AV_KEY_MODEL = "metadata-model"; ///< const char *
|
||||
|
||||
|
||||
/**
|
||||
* @enum Audio sample formats
|
||||
*
|
||||
* 'S' is signed, 'U' is unsigned, and 'F' is a floating-point number.
|
||||
* 'P' is planes, default is interleaved.
|
||||
*
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef enum OH_AudioSampleFormat {
|
||||
A_SAMPLE_FMT_NONE = 0,
|
||||
A_SAMPLE_FMT_U8, ///< unsigned 8 bits
|
||||
A_SAMPLE_FMT_U8P, ///< unsigned 8 bits, planar
|
||||
A_SAMPLE_FMT_S16, ///< signed 16 bits
|
||||
A_SAMPLE_FMT_S16P, ///< signed 16 bits, planar
|
||||
A_SAMPLE_FMT_S32, ///< signed 32 bits
|
||||
A_SAMPLE_FMT_S32P, ///< signed 32 bits, planar
|
||||
A_SAMPLE_FMT_S64, ///< signed 64 bits
|
||||
A_SAMPLE_FMT_S64P, ///< signed 64 bits, planar
|
||||
A_SAMPLE_FMT_F32, ///< float
|
||||
A_SAMPLE_FMT_F32P, ///< signed 32 bits, planar
|
||||
A_SAMPLE_FMT_F64, ///< double
|
||||
A_SAMPLE_FMT_F64P, ///< signed 64 bits, planar
|
||||
} OH_AudioSampleFormat;
|
||||
|
||||
/**
|
||||
* @enum Audio Channel Set
|
||||
*
|
||||
* A 64-bit integer with bits set for each channel.
|
||||
*
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef enum OH_AudioChannelSet : uint64_t {
|
||||
A_CH_SET_FRONT_LEFT = 1ULL << 0U,
|
||||
A_CH_SET_FRONT_RIGHT = 1ULL << 1U,
|
||||
A_CH_SET_FRONT_CENTER = 1ULL << 2U,
|
||||
A_CH_SET_LOW_FREQUENCY = 1ULL << 3U,
|
||||
A_CH_SET_BACK_LEFT = 1ULL << 4U,
|
||||
A_CH_SET_BACK_RIGHT = 1ULL << 5U,
|
||||
A_CH_SET_FRONT_LEFT_OF_CENTER = 1ULL << 6U,
|
||||
A_CH_SET_FRONT_RIGHT_OF_CENTER = 1ULL << 7U,
|
||||
A_CH_SET_BACK_CENTER = 1ULL << 8U,
|
||||
A_CH_SET_SIDE_LEFT = 1ULL << 9U,
|
||||
A_CH_SET_SIDE_RIGHT = 1ULL << 10U,
|
||||
A_CH_SET_TOP_CENTER = 1ULL << 11U,
|
||||
A_CH_SET_TOP_FRONT_LEFT = 1ULL << 12U,
|
||||
A_CH_SET_TOP_FRONT_CENTER = 1ULL << 13U,
|
||||
A_CH_SET_TOP_FRONT_RIGHT = 1ULL << 14U,
|
||||
A_CH_SET_TOP_BACK_LEFT = 1ULL << 15U,
|
||||
A_CH_SET_TOP_BACK_CENTER = 1ULL << 16U,
|
||||
A_CH_SET_TOP_BACK_RIGHT = 1ULL << 17U,
|
||||
A_CH_SET_STEREO_LEFT = 1ULL << 29U,
|
||||
A_CH_SET_STEREO_RIGHT = 1ULL << 30U,
|
||||
A_CH_SET_WIDE_LEFT = 1ULL << 31U,
|
||||
A_CH_SET_WIDE_RIGHT = 1ULL << 32U,
|
||||
A_CH_SET_SURROUND_DIRECT_LEFT = 1ULL << 33U,
|
||||
A_CH_SET_SURROUND_DIRECT_RIGHT = 1ULL << 34U,
|
||||
A_CH_SET_LOW_FREQUENCY_2 = 1ULL << 35U,
|
||||
A_CH_SET_TOP_SIDE_LEFT = 1ULL << 36U,
|
||||
A_CH_SET_TOP_SIDE_RIGHT = 1ULL << 37U,
|
||||
A_CH_SET_BOTTOM_FRONT_CENTER = 1ULL << 38U,
|
||||
A_CH_SET_BOTTOM_FRONT_LEFT = 1ULL << 39U,
|
||||
A_CH_SET_BOTTOM_FRONT_RIGHT = 1ULL << 40U,
|
||||
|
||||
// Ambisonics ACN formats
|
||||
|
||||
// 0th and first order ambisonics ACN
|
||||
A_CH_SET_AMBISONICS_ACN0 = 1ULL << 41U, /** 0th ambisonics channel number 0. */
|
||||
A_CH_SET_AMBISONICS_ACN1 = 1ULL << 42U, /** first-order ambisonics channel number 1. */
|
||||
A_CH_SET_AMBISONICS_ACN2 = 1ULL << 43U, /** first-order ambisonics channel number 2. */
|
||||
A_CH_SET_AMBISONICS_ACN3 = 1ULL << 44U, /** first-order ambisonics channel number 3. */
|
||||
A_CH_SET_AMBISONICS_W = A_CH_SET_AMBISONICS_ACN0, /** same as 0th ambisonics channel number 0. */
|
||||
A_CH_SET_AMBISONICS_Y = A_CH_SET_AMBISONICS_ACN1, /** same as first-order ambisonics channel number 1. */
|
||||
A_CH_SET_AMBISONICS_Z = A_CH_SET_AMBISONICS_ACN2, /** same as first-order ambisonics channel number 2. */
|
||||
A_CH_SET_AMBISONICS_X = A_CH_SET_AMBISONICS_ACN3, /** same as first-order ambisonics channel number 3. */
|
||||
|
||||
// second order ambisonics ACN
|
||||
A_CH_SET_AMBISONICS_ACN4 = 1ULL << 45U, /** second-order ambisonics channel number 4. */
|
||||
A_CH_SET_AMBISONICS_ACN5 = 1ULL << 46U, /** second-order ambisonics channel number 5. */
|
||||
A_CH_SET_AMBISONICS_ACN6 = 1ULL << 47U, /** second-order ambisonics channel number 6. */
|
||||
A_CH_SET_AMBISONICS_ACN7 = 1ULL << 48U, /** second-order ambisonics channel number 7. */
|
||||
A_CH_SET_AMBISONICS_ACN8 = 1ULL << 49U, /** second-order ambisonics channel number 8. */
|
||||
|
||||
// third order ambisonics ACN
|
||||
A_CH_SET_AMBISONICS_ACN9 = 1ULL << 50U, /** third-order ambisonics channel number 9. */
|
||||
A_CH_SET_AMBISONICS_ACN10 = 1ULL << 51U, /** third-order ambisonics channel number 10. */
|
||||
A_CH_SET_AMBISONICS_ACN11 = 1ULL << 52U, /** third-order ambisonics channel number 11. */
|
||||
A_CH_SET_AMBISONICS_ACN12 = 1ULL << 53U, /** third-order ambisonics channel number 12. */
|
||||
A_CH_SET_AMBISONICS_ACN13 = 1ULL << 54U, /** third-order ambisonics channel number 13. */
|
||||
A_CH_SET_AMBISONICS_ACN14 = 1ULL << 55U, /** third-order ambisonics channel number 14. */
|
||||
A_CH_SET_AMBISONICS_ACN15 = 1ULL << 56U, /** third-order ambisonics channel number 15. */
|
||||
} OH_AudioChannelSet;
|
||||
|
||||
/**
|
||||
* @enum Audio AudioChannel Mask
|
||||
*
|
||||
* Indicates that the channel order in which the user requests decoder output
|
||||
* is the native codec channel order.
|
||||
*
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef enum OH_AudioChannelMask : uint64_t {
|
||||
A_CH_MASK_UNKNOWN = 0,
|
||||
A_CH_MASK_MONO = (A_CH_SET_FRONT_CENTER),
|
||||
A_CH_MASK_STEREO = (A_CH_SET_FRONT_LEFT | A_CH_SET_FRONT_RIGHT),
|
||||
A_CH_MASK_CH_2POINT1 = (A_CH_MASK_STEREO | A_CH_SET_LOW_FREQUENCY),
|
||||
A_CH_MASK_CH_2_1 = (A_CH_MASK_STEREO | A_CH_SET_BACK_CENTER),
|
||||
A_CH_MASK_SURROUND = (A_CH_MASK_STEREO | A_CH_SET_FRONT_CENTER),
|
||||
A_CH_MASK_CH_3POINT1 = (A_CH_MASK_SURROUND | A_CH_SET_LOW_FREQUENCY),
|
||||
A_CH_MASK_CH_4POINT0 = (A_CH_MASK_SURROUND | A_CH_SET_BACK_CENTER),
|
||||
A_CH_MASK_CH_4POINT1 = (A_CH_MASK_CH_4POINT0 | A_CH_SET_LOW_FREQUENCY),
|
||||
A_CH_MASK_CH_2_2 = (A_CH_MASK_STEREO | A_CH_SET_SIDE_LEFT | A_CH_SET_SIDE_RIGHT),
|
||||
A_CH_MASK_QUAD = (A_CH_MASK_STEREO | A_CH_SET_BACK_LEFT | A_CH_SET_BACK_RIGHT),
|
||||
A_CH_MASK_CH_5POINT0 = (A_CH_MASK_SURROUND | A_CH_SET_SIDE_LEFT | A_CH_SET_SIDE_RIGHT),
|
||||
A_CH_MASK_CH_5POINT1 = (A_CH_MASK_CH_5POINT0 | A_CH_SET_LOW_FREQUENCY),
|
||||
A_CH_MASK_CH_5POINT0_BACK = (A_CH_MASK_SURROUND | A_CH_SET_BACK_LEFT | A_CH_SET_BACK_RIGHT),
|
||||
A_CH_MASK_CH_5POINT1_BACK = (A_CH_MASK_CH_5POINT0_BACK | A_CH_SET_LOW_FREQUENCY),
|
||||
A_CH_MASK_CH_6POINT0 = (A_CH_MASK_CH_5POINT0 | A_CH_SET_BACK_CENTER),
|
||||
A_CH_MASK_CH_6POINT0_FRONT = (A_CH_MASK_CH_2_2 | A_CH_SET_FRONT_LEFT_OF_CENTER | A_CH_SET_FRONT_RIGHT_OF_CENTER),
|
||||
A_CH_MASK_HEXAGONAL = (A_CH_MASK_CH_5POINT0_BACK | A_CH_SET_BACK_CENTER),
|
||||
A_CH_MASK_CH_6POINT1 = (A_CH_MASK_CH_5POINT1 | A_CH_SET_BACK_CENTER),
|
||||
A_CH_MASK_CH_6POINT1_BACK = (A_CH_MASK_CH_5POINT1_BACK | A_CH_SET_BACK_CENTER),
|
||||
A_CH_MASK_CH_6POINT1_FRONT = (A_CH_MASK_CH_6POINT0_FRONT | A_CH_SET_LOW_FREQUENCY),
|
||||
A_CH_MASK_CH_7POINT0 = (A_CH_MASK_CH_5POINT0 | A_CH_SET_BACK_LEFT | A_CH_SET_BACK_RIGHT),
|
||||
A_CH_MASK_CH_7POINT0_FRONT = (A_CH_MASK_CH_5POINT0 | A_CH_SET_FRONT_LEFT_OF_CENTER | A_CH_SET_FRONT_RIGHT_OF_CENTER),
|
||||
A_CH_MASK_CH_7POINT1 = (A_CH_MASK_CH_5POINT1 | A_CH_SET_BACK_LEFT | A_CH_SET_BACK_RIGHT),
|
||||
A_CH_MASK_CH_7POINT1_WIDE = (A_CH_MASK_CH_5POINT1 | A_CH_SET_FRONT_LEFT_OF_CENTER | A_CH_SET_FRONT_RIGHT_OF_CENTER),
|
||||
A_CH_MASK_CH_7POINT1_WIDE_BACK = (A_CH_MASK_CH_5POINT1_BACK | A_CH_SET_FRONT_LEFT_OF_CENTER | A_CH_SET_FRONT_RIGHT_OF_CENTER),
|
||||
A_CH_MASK_CH_3POINT1POINT2 = (A_CH_MASK_CH_3POINT1 | A_CH_SET_TOP_FRONT_LEFT | A_CH_SET_TOP_FRONT_RIGHT),
|
||||
A_CH_MASK_CH_5POINT1POINT2 = (A_CH_MASK_CH_5POINT1 | A_CH_SET_TOP_SIDE_LEFT | A_CH_SET_TOP_SIDE_RIGHT),
|
||||
A_CH_MASK_CH_5POINT1POINT4 = (A_CH_MASK_CH_5POINT1 | A_CH_SET_TOP_FRONT_LEFT | A_CH_SET_TOP_FRONT_RIGHT |
|
||||
A_CH_SET_TOP_BACK_LEFT | A_CH_SET_TOP_BACK_RIGHT),
|
||||
A_CH_MASK_CH_7POINT1POINT2 = (A_CH_MASK_CH_7POINT1 | A_CH_SET_TOP_SIDE_LEFT | A_CH_SET_TOP_SIDE_RIGHT),
|
||||
A_CH_MASK_CH_7POINT1POINT4 = (A_CH_MASK_CH_7POINT1 | A_CH_SET_TOP_FRONT_LEFT | A_CH_SET_TOP_FRONT_RIGHT |
|
||||
A_CH_SET_TOP_BACK_LEFT | A_CH_SET_TOP_BACK_RIGHT),
|
||||
A_CH_MASK_CH_9POINT1POINT4 = (A_CH_MASK_CH_7POINT1POINT4 | A_CH_SET_WIDE_LEFT | A_CH_SET_WIDE_RIGHT),
|
||||
A_CH_MASK_CH_9POINT1POINT6 = (A_CH_MASK_CH_9POINT1POINT4 | A_CH_SET_TOP_SIDE_LEFT | A_CH_SET_TOP_SIDE_RIGHT),
|
||||
A_CH_MASK_CH_10POINT2 = (A_CH_SET_FRONT_LEFT | A_CH_SET_FRONT_RIGHT | A_CH_SET_FRONT_CENTER |
|
||||
A_CH_SET_TOP_FRONT_LEFT | A_CH_SET_TOP_FRONT_RIGHT | A_CH_SET_BACK_LEFT |
|
||||
A_CH_SET_BACK_RIGHT | A_CH_SET_BACK_CENTER | A_CH_SET_SIDE_LEFT |
|
||||
A_CH_SET_SIDE_RIGHT | A_CH_SET_WIDE_LEFT | A_CH_SET_WIDE_RIGHT),
|
||||
A_CH_MASK_CH_22POINT2 = (A_CH_MASK_CH_7POINT1POINT4 | A_CH_SET_FRONT_LEFT_OF_CENTER | A_CH_SET_FRONT_RIGHT_OF_CENTER |
|
||||
A_CH_SET_BACK_CENTER | A_CH_SET_TOP_CENTER | A_CH_SET_TOP_FRONT_CENTER |
|
||||
A_CH_SET_TOP_BACK_CENTER | A_CH_SET_TOP_SIDE_LEFT | A_CH_SET_TOP_SIDE_RIGHT |
|
||||
A_CH_SET_BOTTOM_FRONT_LEFT | A_CH_SET_BOTTOM_FRONT_RIGHT |
|
||||
A_CH_SET_BOTTOM_FRONT_CENTER | A_CH_SET_LOW_FREQUENCY_2),
|
||||
A_CH_MASK_OCTAGONAL = (A_CH_MASK_CH_5POINT0 | A_CH_SET_BACK_LEFT | A_CH_SET_BACK_CENTER | A_CH_SET_BACK_RIGHT),
|
||||
A_CH_MASK_HEXADECAGONAL = (A_CH_MASK_OCTAGONAL | A_CH_SET_WIDE_LEFT | A_CH_SET_WIDE_RIGHT | A_CH_SET_TOP_BACK_LEFT |
|
||||
A_CH_SET_TOP_BACK_RIGHT | A_CH_SET_TOP_BACK_CENTER | A_CH_SET_TOP_FRONT_CENTER |
|
||||
A_CH_SET_TOP_FRONT_LEFT | A_CH_SET_TOP_FRONT_RIGHT),
|
||||
A_CH_MASK_STEREO_DOWNMIX = (A_CH_SET_STEREO_LEFT | A_CH_SET_STEREO_RIGHT),
|
||||
A_CH_MASK_HOA_FIRST = A_CH_SET_AMBISONICS_ACN0 | A_CH_SET_AMBISONICS_ACN1 | A_CH_SET_AMBISONICS_ACN2 |
|
||||
A_CH_SET_AMBISONICS_ACN3,
|
||||
A_CH_MASK_HOA_SECOND = A_CH_MASK_HOA_FIRST | A_CH_SET_AMBISONICS_ACN4 | A_CH_SET_AMBISONICS_ACN5 |
|
||||
A_CH_SET_AMBISONICS_ACN6 | A_CH_SET_AMBISONICS_ACN7 | A_CH_SET_AMBISONICS_ACN8,
|
||||
A_CH_MASK_HOA_THIRD = A_CH_MASK_HOA_SECOND | A_CH_SET_AMBISONICS_ACN9 | A_CH_SET_AMBISONICS_ACN10 | A_CH_SET_AMBISONICS_ACN11 |
|
||||
A_CH_SET_AMBISONICS_ACN12 |A_CH_SET_AMBISONICS_ACN13 | A_CH_SET_AMBISONICS_ACN14 | A_CH_SET_AMBISONICS_ACN15,
|
||||
} OH_AudioChannelMask;
|
||||
|
||||
/**
|
||||
* @enum Audio AAC Profile。
|
||||
*
|
||||
* AAC mode type. Note that the term profile is used with the MPEG-2
|
||||
* standard and the term object type and profile is used with MPEG-4
|
||||
*
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef enum OH_AudioAacProfile {
|
||||
AAC_PROFILE_NONE = 0, ///< Null, not used
|
||||
AAC_PROFILE_MAIN = 1, ///< AAC Main object
|
||||
AAC_PROFILE_LC, ///< AAC Low Complexity object (AAC profile)
|
||||
AAC_PROFILE_SSR, ///< AAC Scalable Sample Rate object
|
||||
AAC_PROFILE_LTP, ///< AAC Long Term Prediction object
|
||||
AAC_PROFILE_HE, ///< AAC High Efficiency (object type SBR, HE-AAC profile)
|
||||
AAC_PROFILE_SCALABLE, ///< AAC Scalable object
|
||||
AAC_PROFILE_ERLC = 17, ///< ER AAC Low Complexity object (Error Resilient AAC-LC)
|
||||
AAC_PROFILE_ER_SCALABLE = 20, ///< ER AAC scalable object
|
||||
AAC_PROFILE_LD = 23, ///< AAC Low Delay object (Error Resilient)
|
||||
AAC_PROFILE_HE_PS = 29, ///< AAC High Efficiency with Parametric Stereo coding (HE-AAC v2, object type PS)
|
||||
AAC_PROFILE_ELD = 39, ///< AAC Enhanced Low Delay. NOTE: Pending Khronos standardization
|
||||
AAC_PROFILE_XHE = 42, ///< extended High Efficiency AAC. NOTE: Pending Khronos standardization
|
||||
} OH_AudioAacProfile;
|
||||
|
||||
/**
|
||||
* @enum Video Pixel Format.
|
||||
*
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef enum OH_VideoPixelFormat {
|
||||
V_PIX_FMT_UNKNOWN = 0,
|
||||
V_PIX_FMT_YUV410P, ///< planar YUV 4:1:0, 1 Cr & Cb sample per 4x4 Y samples
|
||||
V_PIX_FMT_YUV411P, ///< planar YUV 4:1:1, 1 Cr & Cb sample per 4x1 Y samples
|
||||
V_PIX_FMT_YUV420P, ///< planar YUV 4:2:0, 1 Cr & Cb sample per 2x2 Y samples
|
||||
V_PIX_FMT_NV12, ///< semi-planar YUV 4:2:0, UVUV...
|
||||
V_PIX_FMT_NV21, ///< semi-planar YUV 4:2:0, VUVU...
|
||||
V_PIX_FMT_YUYV422, ///< packed YUV 4:2:2, Y0 Cb Y1 Cr
|
||||
V_PIX_FMT_YUV422P, ///< planar YUV 4:2:2, 1 Cr & Cb sample per 2x1 Y samples
|
||||
V_PIX_FMT_YUV444P, ///< planar YUV 4:4:4, 1 Cr & Cb sample per 1x1 Y samples
|
||||
V_PIX_FMT_RGBA, ///< packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
|
||||
V_PIX_FMT_ARGB, ///< packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
|
||||
V_PIX_FMT_ABGR, ///< packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
|
||||
V_PIX_FMT_BGRA, ///< packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
|
||||
V_PIX_FMT_RGB24, ///< packed RGB 8:8:8, RGBRGB...
|
||||
V_PIX_FMT_BGR24, ///< packed RGB 8:8:8, BGRBGR...
|
||||
V_PIX_FMT_PAL8, ///< 8 bit with AV_PIX_FMT_RGB32 palette
|
||||
V_PIX_FMT_GRAY8, ///< Y
|
||||
V_PIX_FMT_MONOWHITE, ///< Y, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb
|
||||
V_PIX_FMT_MONOBLACK, ///< Y, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb
|
||||
V_PIX_FMT_YUVJ420P, ///< planar YUV 4:2:0, 12bpp, full scale (JPEG)
|
||||
V_PIX_FMT_YUVJ422P, ///< planar YUV 4:2:2, 16bpp, full scale (JPEG)
|
||||
V_PIX_FMT_YUVJ444P, ///< planar YUV 4:4:4, 24bpp, full scale (JPEG)
|
||||
} OH_VideoPixelFormat;
|
||||
|
||||
/**
|
||||
* @enum Video H264/AVC profile.
|
||||
*
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef enum OH_VideoH264Profile {
|
||||
H264_PROFILE_UNKNOWN = 0,
|
||||
H264_PROFILE_BASELINE, ///< Baseline profile
|
||||
H264_PROFILE_MAIN, ///< Main profile
|
||||
H264_PROFILE_EXTENDED, ///< Extended profile
|
||||
H264_PROFILE_HIGH, ///< High profile
|
||||
H264_PROFILE_HIGH10, ///< High 10 profile
|
||||
H264_PROFILE_HIGH422, ///< High 4:2:2 profile
|
||||
H264_PROFILE_HIGH444, ///< High 4:4:4 profile
|
||||
} OH_VideoH264Profile;
|
||||
|
||||
/**
|
||||
* @brief Enumerate the categories of OH_AVCodec's Buffer tags
|
||||
*
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef enum OH_AVCodecBufferFlags : uint32_t {
|
||||
AVCODEC_BUFFER_FLAGS_NONE = 0,
|
||||
/* Indicates that the Buffer is an End-of-Stream frame */
|
||||
AVCODEC_BUFFER_FLAGS_EOS = 1 << 0,
|
||||
/* Indicates that the Buffer contains keyframes */
|
||||
AVCODEC_BUFFER_FLAGS_SYNC_FRAME = 1 << 1,
|
||||
/* Indicates that the data contained in the Buffer is only part of a frame */
|
||||
AVCODEC_BUFFER_FLAGS_PARTIAL_FRAME = 1 << 2,
|
||||
} OH_AVCodecBufferFlags;
|
||||
|
||||
/**
|
||||
* @brief Define the Buffer description information of OH_AVCodec
|
||||
*
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef struct OH_AVCodecBufferInfo {
|
||||
/* Presentation timestamp of this Buffer in microseconds */
|
||||
int64_t pts;
|
||||
/* Decoding timestamp of this Buffer in microseconds */
|
||||
int64_t dts;
|
||||
/* Duration in time of this Buffer data in microseconds */
|
||||
int64_t duration;
|
||||
/* The size of the data contained in the Buffer in bytes */
|
||||
int32_t size;
|
||||
/* The starting offset of valid data in this Buffer */
|
||||
int32_t offset;
|
||||
/* The flags this Buffer has, which is also a combination of multiple {@link OH_AVCodecBufferFlags}. */
|
||||
uint32_t flags;
|
||||
} OH_AVCodecBufferInfo;
|
||||
|
||||
/**
|
||||
* @brief Enumerates the muxer ouputfile format
|
||||
*
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef enum OH_AVOutputFormat {
|
||||
AV_OUTPUT_FORMAT_UNKNOWN = 0,
|
||||
AV_OUTPUT_FORMAT_MPEG_4 = 1,
|
||||
AV_OUTPUT_FORMAT_M4A = 2,
|
||||
} OH_AVOutputFormat;
|
||||
|
||||
/**
|
||||
* @brief Enumerates the video rotation.
|
||||
*
|
||||
* @since 10
|
||||
* @version 3.2
|
||||
*/
|
||||
typedef enum OH_VideoRotation {
|
||||
/**
|
||||
* Video without rotation
|
||||
*/
|
||||
V_ROTATION_0 = 0,
|
||||
/**
|
||||
* Video rotated 90 degrees
|
||||
*/
|
||||
V_ROTATION_90 = 90,
|
||||
/**
|
||||
* Video rotated 180 degrees
|
||||
*/
|
||||
V_ROTATION_180 = 180,
|
||||
/**
|
||||
* Video rotated 270 degrees
|
||||
*/
|
||||
V_ROTATION_270 = 270,
|
||||
} OH_VideoRotation;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NATIVE_AVBASE_H
|
@ -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;
|
||||
|
||||
/**
|
||||
@ -222,9 +224,9 @@ extern const char *OH_MD_KEY_ROTATION;
|
||||
*/
|
||||
typedef enum OH_MediaType {
|
||||
/* track is audio. */
|
||||
MEDIA_TYPE_AUD = 0,
|
||||
AVCODEC_TYPE_AUD = 0,
|
||||
/* track is video. */
|
||||
MEDIA_TYPE_VID = 1,
|
||||
AVCODEC_TYPE_VID = 1,
|
||||
} OH_MediaType;
|
||||
|
||||
/**
|
||||
|
@ -82,8 +82,8 @@ OH_AVErrCode OH_AVCodec_Destroy(OH_AVCodec *codec);
|
||||
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
|
||||
@ -168,6 +168,30 @@ OH_AVFormat *OH_AVCodec_GetOutputFormat(OH_AVCodec *codec);
|
||||
*/
|
||||
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
|
||||
@ -187,18 +211,20 @@ OH_AVErrCode OH_AVCodec_SetParameter(OH_AVCodec *codec, OH_AVFormat *format);
|
||||
OH_AVErrCode OH_AVCodec_QueueInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr);
|
||||
|
||||
/**
|
||||
* @brief Get an input buffer.
|
||||
* @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 index The index value corresponding to the input Buffer
|
||||
* @return Returns a pointer to an BufferElement 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
|
||||
*/
|
||||
OH_AVBufferElement* OH_AVCodec_GetInputBuffer(OH_AVCodec *codec, size_t index);
|
||||
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
|
||||
@ -208,30 +234,6 @@ OH_AVBufferElement* OH_AVCodec_GetInputBuffer(OH_AVCodec *codec, size_t index);
|
||||
*/
|
||||
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 4.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,
|
||||
* otherwise returns negtive value for invalid buffer index
|
||||
* @since 10
|
||||
* @version 4.0
|
||||
*/
|
||||
int32_t OH_AVCodec_DequeueOutputBuffer(OH_AVCodec *codec, int64_t timeoutUs);
|
||||
|
||||
/**
|
||||
* @brief Return the processed output Buffer to the codec.
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.Codec
|
||||
|
@ -25,51 +25,51 @@ extern "C" {
|
||||
* @since 10
|
||||
* @version 4.0
|
||||
*/
|
||||
typedef enum OH_AVErrCode {
|
||||
typedef enum OH_AVCodecErrCode {
|
||||
/**
|
||||
* the operation completed successfully.
|
||||
*/
|
||||
AV_ERR_OK = 0,
|
||||
AVCODEC_ERR_OK = 0,
|
||||
/**
|
||||
* no memory.
|
||||
*/
|
||||
AV_ERR_NO_MEMORY = 1,
|
||||
AVCODEC_ERR_NO_MEMORY = 1,
|
||||
/**
|
||||
* opertation not be permitted.
|
||||
*/
|
||||
AV_ERR_OPERATE_NOT_PERMIT = 2,
|
||||
AVCODEC_ERR_OPERATE_NOT_PERMIT = 2,
|
||||
/**
|
||||
* invalid argument.
|
||||
*/
|
||||
AV_ERR_INVALID_VAL = 3,
|
||||
AVCODEC_ERR_INVALID_VAL = 3,
|
||||
/**
|
||||
* IO error.
|
||||
*/
|
||||
AV_ERR_IO = 4,
|
||||
AVCODEC_ERR_IO = 4,
|
||||
/**
|
||||
* network timeout.
|
||||
* avcodec service timeout.
|
||||
*/
|
||||
AV_ERR_TIMEOUT = 5,
|
||||
AVCODEC_ERR_TIMEOUT = 5,
|
||||
/**
|
||||
* unknown error.
|
||||
*/
|
||||
AV_ERR_UNKNOWN = 6,
|
||||
AVCODEC_ERR_UNKNOWN = 6,
|
||||
/**
|
||||
* media service died.
|
||||
* avcodec service died.
|
||||
*/
|
||||
AV_ERR_SERVICE_DIED = 7,
|
||||
AVCODEC_ERR_SERVICE_DIED = 7,
|
||||
/**
|
||||
* the state is not support this operation.
|
||||
*/
|
||||
AV_ERR_INVALID_STATE = 8,
|
||||
AVCODEC_ERR_INVALID_STATE = 8,
|
||||
/**
|
||||
* unsupport interface.
|
||||
*/
|
||||
AV_ERR_UNSUPPORT = 9,
|
||||
AVCODEC_ERR_UNSUPPORT = 9,
|
||||
/**
|
||||
* extend err start.
|
||||
*/
|
||||
AV_ERR_EXTEND_START = 100,
|
||||
AVCODEC_ERR_EXTEND_START = 100,
|
||||
} OH_AVErrCode;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -26,35 +26,6 @@ extern "C" {
|
||||
|
||||
typedef struct OH_AVFormat OH_AVFormat;
|
||||
|
||||
/**
|
||||
* @brief Enumerates AVPixel Format.
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.Core
|
||||
* @since 10
|
||||
* @version 4.0
|
||||
*/
|
||||
typedef enum OH_AVPixelFormat {
|
||||
/**
|
||||
* yuv 420 planar.
|
||||
*/
|
||||
AV_PIXEL_FORMAT_YUVI420 = 1,
|
||||
/**
|
||||
* NV12. yuv 420 semiplanar.
|
||||
*/
|
||||
AV_PIXEL_FORMAT_NV12 = 2,
|
||||
/**
|
||||
* NV21. yvu 420 semiplanar.
|
||||
*/
|
||||
AV_PIXEL_FORMAT_NV21 = 3,
|
||||
/**
|
||||
* format from surface.
|
||||
*/
|
||||
AV_PIXEL_FORMAT_SURFACE_FORMAT = 4,
|
||||
/**
|
||||
* RGBA8888
|
||||
*/
|
||||
AV_PIXEL_FORMAT_RGBA = 5,
|
||||
} OH_AVPixelFormat;
|
||||
|
||||
/**
|
||||
* @briefCreate an OH_AVFormat handle pointer to read and write data
|
||||
* @syscap SystemCapability.Multimedia.AVCodec.Core
|
||||
|
157
interfaces/kits/c/native_avmuxer.h
Normal file
157
interfaces/kits/c/native_avmuxer.h
Normal file
@ -0,0 +1,157 @@
|
||||
/*
|
||||
* 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 NATIVE_AVMUXER_H
|
||||
#define NATIVE_AVMUXER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "native_avbase.h"
|
||||
#include "native_averrors.h"
|
||||
#include "native_avformat.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct OH_AVMuxer OH_AVMuxer;
|
||||
|
||||
/**
|
||||
* @brief Create an OH_AVMuxer instance by output file handler and format.
|
||||
* @syscap SystemCapability.Multimedia.Media.AVMuxer
|
||||
* @return Returns a pointer to an OH_AVMuxer instance
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
OH_AVMuxer *OH_AVMuxer_Create(int32_t fd, OH_AVOutputFormat format);
|
||||
|
||||
/**
|
||||
* @brief Set and store the location to the output file.
|
||||
* Note: This interface can only be called before OH_AVMuxer_Start.
|
||||
* The location is stored in the output file if the output format is {@link OH_AVOutputFormat}
|
||||
* AV_OUTPUT_FORMAT_MPEG_4, and is ignored for other output formats.
|
||||
* @syscap SystemCapability.Multimedia.Media.AVMuxer
|
||||
* @param muxer Pointer to an OH_AVMuxer instance.
|
||||
* @param latitude must be in the range [-90, 90].
|
||||
* @param longitude must be in the range [-180, 180].
|
||||
* @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
|
||||
*/
|
||||
OH_AVErrCode OH_AVMuxer_SetLocation(OH_AVMuxer *muxer, float latitude, float longitude);
|
||||
|
||||
/**
|
||||
* @brief Set the rotation for output video playback.
|
||||
* Note: This interface can only be called before OH_AVMuxer_Start.
|
||||
* @syscap SystemCapability.Multimedia.Media.AVMuxer
|
||||
* @param muxer Pointer to an OH_AVMuxer instance.
|
||||
* @param rotation The supported angles are 0, 90, 180, and 270 degrees. {@link OH_VideoRotation}
|
||||
* @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
|
||||
*/
|
||||
OH_AVErrCode OH_AVMuxer_SetRotation(OH_AVMuxer *muxer, int32_t rotation);
|
||||
|
||||
/**
|
||||
* @brief Set parameters to the muxer.
|
||||
* Note: This interface can only be called before OH_AVMuxer_Start.
|
||||
* @syscap SystemCapability.Multimedia.Media.AVMuxer
|
||||
* @param muxer Pointer to an OH_AVMuxer instance
|
||||
* @param generalFormat OH_AVFormat handle pointer contain metadata
|
||||
* @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
|
||||
*/
|
||||
OH_AVErrCode OH_AVMuxer_SetParameter(OH_AVMuxer *muxer, OH_AVFormat *generalFormat);
|
||||
|
||||
/**
|
||||
* @brief Add track format to the muxer.
|
||||
* Note: This interface can only be called before OH_AVMuxer_Start.
|
||||
* @syscap SystemCapability.Multimedia.Media.AVMuxer
|
||||
* @param muxer Pointer to an OH_AVMuxer instance
|
||||
* @param trackFormat OH_AVFormat handle pointer contain track format
|
||||
* @return The track index for this newly added track, and it should be used in the OH_AVMuxer_WriteSampleBuffer.
|
||||
* The track index is greater than or equal to 0, otherwise returns a specific error code, refer to {@link OH_AVErrCode}.
|
||||
* @since 10
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OH_AVMuxer_AddTrack(OH_AVMuxer *muxer, OH_AVFormat *trackFormat);
|
||||
|
||||
/**
|
||||
* @brief Start the muxer.
|
||||
* Note: This interface is called after OH_AVMuxer_AddTrack and before OH_AVMuxer_WriteSampleBuffer.
|
||||
* @syscap SystemCapability.Multimedia.Media.AVMuxer
|
||||
* @param muxer Pointer to an OH_AVMuxer instance
|
||||
* @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
|
||||
*/
|
||||
OH_AVErrCode OH_AVMuxer_Start(OH_AVMuxer *muxer);
|
||||
|
||||
/**
|
||||
* @brief Write an encoded sample to the muxer.
|
||||
* Note: This interface can only be called after OH_AVMuxer_Start and before OH_AVMuxer_Stop. The application needs to
|
||||
* make sure that the samples are written to the right tacks. Also, it needs to make sure the samples for each track are
|
||||
* written in chronological order.
|
||||
* For MPEG4 mime type format, the duration of the last sample in a track can be set by passing an additional empty buffer
|
||||
* (info.size = 0) with flags (info.flags = AVCODEC_BUFFER_FLAGS_EOS) {@link OH_AVCodecBufferInfo and OH_AVCodecBufferFlags}
|
||||
* and a suitable presentation timestamp set in info parameter as the last sample of that track. This last sample's presentation
|
||||
* timestamp shall be a sum of the presentation timestamp and the duration preferred for the original last sample. If no explicit
|
||||
* AVCODEC_BUFFER_FLAGS_EOS sample was passed, then the duration of the last sample would be the same as that of the sample before that.
|
||||
* @syscap SystemCapability.Multimedia.Media.AVMuxer
|
||||
* @param muxer Pointer to an OH_AVMuxer instance
|
||||
* @param trackIndex The track index for this sample
|
||||
* @param sampleBuffer The encoded sample buffer
|
||||
* @param info The buffer information related to this sample {@link OH_AVCodecBufferInfo}
|
||||
* @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
|
||||
*/
|
||||
OH_AVErrCode OH_AVMuxer_WriteSampleBuffer(OH_AVMuxer *muxer, uint32_t trackIndex, uint8_t *sampleBuffer, OH_AVCodecBufferInfo info);
|
||||
|
||||
/**
|
||||
* @brief Stop the muxer.
|
||||
* Note: Once the muxer stops, it can not be restarted.
|
||||
* @syscap SystemCapability.Multimedia.Media.AVMuxer
|
||||
* @param muxer Pointer to an OH_AVMuxer instance
|
||||
* @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
|
||||
*/
|
||||
OH_AVErrCode OH_AVMuxer_Stop(OH_AVMuxer *muxer);
|
||||
|
||||
/**
|
||||
* @brief Clear the internal resources of the muxer and destroy the muxer instance
|
||||
* @syscap SystemCapability.Multimedia.Media.AVMuxer
|
||||
* @param codec Pointer to an OH_AVMuxer instance
|
||||
* @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
|
||||
*/
|
||||
OH_AVErrCode OH_AVMuxer_Destroy(OH_AVMuxer *muxer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NATIVE_AVMUXER_H
|
143
services/dfx/avcodec_dfx.cpp
Normal file
143
services/dfx/avcodec_dfx.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 <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::StatisticEventWrite(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 AVCodecEvent::BehaviorEventWrite(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,
|
||||
"STATE", msg_);
|
||||
}
|
||||
|
||||
void AVCodecEvent::FaultEventWrite(std::string eventName, int32_t errorCode, 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,
|
||||
"ERRORCODE", errorCode,
|
||||
"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.BehaviorEventWrite("AVCODEC_STATE", OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, moudle);
|
||||
} else {
|
||||
AVCODEC_LOGW("Failed to call CreateMsg");
|
||||
}
|
||||
}
|
||||
|
||||
void FaultEventWrite(int32_t errorCode, std::string msg, std::string moudle)
|
||||
{
|
||||
AVCodecEvent event;
|
||||
if (event.CreateMsg("%s", msg.c_str())) {
|
||||
event.FaultEventWrite("AVCODEC_ERR", errorCode, 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.StatisticEventWrite("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
|
59
services/dfx/include/avcodec_dfx.h
Normal file
59
services/dfx/include/avcodec_dfx.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 StatisticEventWrite(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
|
||||
std::string module);
|
||||
void BehaviorEventWrite(std::string eventName, OHOS::HiviewDFX::HiSysEvent::EventType type,
|
||||
std::string module);
|
||||
void FaultEventWrite(std::string eventName, int32_t errorCode, 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(int32_t errorCode, 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,66 @@
|
||||
/*
|
||||
* 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 {
|
||||
FFmpegDemuxerPlugin::FFmpegDemuxerPlugin(size_t sourceAttr)
|
||||
{
|
||||
formatContext_ = (AVFormatContext*)sourceAttr;
|
||||
}
|
||||
|
||||
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(size_t sourceAttr);
|
||||
~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
|
@ -13,8 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef I_MEDIA_SERVICE_H
|
||||
#define I_MEDIA_SERVICE_H
|
||||
#ifndef I_AVCODEC_SERVICE_H
|
||||
#define I_AVCODEC_SERVICE_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
@ -121,4 +121,4 @@ private:
|
||||
};
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
||||
#endif // I_MEDIA_SERVICE_H
|
||||
#endif // I_AVCODEC_SERVICE_H
|
||||
|
@ -12,8 +12,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef AVCODECBASE_H
|
||||
#define AVCODECBASE_H
|
||||
#ifndef CODECBASE_H
|
||||
#define CODECBASE_H
|
||||
|
||||
#include <string>
|
||||
#include "avcodec_common.h"
|
||||
@ -21,9 +21,10 @@
|
||||
|
||||
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);
|
||||
class CodecBase {
|
||||
virtual ~CodecBase() = default;
|
||||
static std::shared_ptr<CodecBase> Create(const std::string& name);
|
||||
static std::shared_ptr<CodecBase> 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;
|
||||
@ -48,4 +49,4 @@ class AVCodecBase {
|
||||
};
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
||||
#endif // AVCODECBASE_H
|
||||
#endif // CODECBASE_H
|
@ -20,9 +20,10 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec {
|
||||
class AVCodecListBase {
|
||||
class CodecListBase {
|
||||
virtual ~CodecListBase() = default;
|
||||
virtual int32_t GetCapabilityList(std::vector<CapabilityData>& caps) = 0;
|
||||
};
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
||||
#endif // AVCODECLISTBASE_H
|
||||
#endif // CODECLISTBASE_H
|
40
services/services/source/server/include/avsourcebase.h
Normal file
40
services/services/source/server/include/avsourcebase.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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 AVSOURCEBASE_H
|
||||
#define AVSOURCEBASE_H
|
||||
|
||||
#include <memory>
|
||||
#include <stdint>
|
||||
#include <string>
|
||||
#include "avcodec_common.h"
|
||||
#include "libavformat/avformat.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AVCodec {
|
||||
class AVSourceBase {
|
||||
public:
|
||||
static std::shared_ptr<AVSourceBase> Create(const std::string& uri);
|
||||
virtual int32_t GetTrackCount() = 0;
|
||||
virtual int32_t Destroy() = 0;
|
||||
virtual int32_t SetParameter(const Format ¶m, uint32_t trackId) = 0;
|
||||
virtual int32_t GetTrackFormat(Format &format, uint32_t trackId) = 0;
|
||||
virtual size_t GetSourceAttr() = 0;
|
||||
|
||||
private:
|
||||
std::shared_ptr<AVFormatContext> formatContext_;
|
||||
};
|
||||
} // namespace AVCodec
|
||||
} // namespace OHOS
|
||||
#endif // AVSOURCEBASE_H
|
98
services/utils/av_log.h
Normal file
98
services/utils/av_log.h
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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 AV_LOG_H
|
||||
#define AV_LOG_H
|
||||
|
||||
#include <hilog/log.h>
|
||||
#include <cinttypes>
|
||||
|
||||
namespace OHOS {
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN 0xD002B2B
|
||||
|
||||
#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
|
||||
|
||||
#define MEDIA_LOG(func, fmt, args...) \
|
||||
do { \
|
||||
(void)func(LABEL, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args); \
|
||||
} while (0)
|
||||
|
||||
#define MEDIA_LOGD(fmt, ...) MEDIA_LOG(::OHOS::HiviewDFX::HiLog::Debug, fmt, ##__VA_ARGS__)
|
||||
#define MEDIA_LOGI(fmt, ...) MEDIA_LOG(::OHOS::HiviewDFX::HiLog::Info, fmt, ##__VA_ARGS__)
|
||||
#define MEDIA_LOGW(fmt, ...) MEDIA_LOG(::OHOS::HiviewDFX::HiLog::Warn, fmt, ##__VA_ARGS__)
|
||||
#define MEDIA_LOGE(fmt, ...) MEDIA_LOG(::OHOS::HiviewDFX::HiLog::Error, fmt, ##__VA_ARGS__)
|
||||
#define MEDIA_LOGF(fmt, ...) MEDIA_LOG(::OHOS::HiviewDFX::HiLog::Fatal, fmt, ##__VA_ARGS__)
|
||||
|
||||
#define CHECK_AND_RETURN(cond) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
MEDIA_LOGE("%{public}s, check failed!", #cond); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_AND_RETURN_RET(cond, ret) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
MEDIA_LOGE("%{public}s, check failed! ret = %{public}s", #cond, #ret); \
|
||||
return ret; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
MEDIA_LOGE(fmt, ##__VA_ARGS__); \
|
||||
return ret; \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
#define CHECK_AND_RETURN_LOG(cond, fmt, ...) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
MEDIA_LOGE(fmt, ##__VA_ARGS__); \
|
||||
return; \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
#define CHECK_AND_BREAK_LOG(cond, fmt, ...) \
|
||||
if (1) { \
|
||||
if (!(cond)) { \
|
||||
MEDIA_LOGE(fmt, ##__VA_ARGS__); \
|
||||
break; \
|
||||
} \
|
||||
} else void (0)
|
||||
|
||||
#define CHECK_AND_BREAK(cond) \
|
||||
if (1) { \
|
||||
if (!(cond)) { \
|
||||
MEDIA_LOGE("%{public}s, check failed!", #cond); \
|
||||
break; \
|
||||
} \
|
||||
} else void (0)
|
||||
|
||||
#define CHECK_AND_CONTINUE(cond) \
|
||||
if (1) { \
|
||||
if (!(cond)) { \
|
||||
MEDIA_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 OHOS
|
||||
#endif // AV_LOG_H
|
@ -35,7 +35,7 @@ std::shared_ptr<AVSharedMemory> AVDataSrcMemory::CreateFromLocal(
|
||||
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);
|
||||
AVCODEC_LOGE("Create avsharedmemory failed, ret = %{public}d", ret);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ std::shared_ptr<AVSharedMemory> AVDataSrcMemory::CreateFromRemote(
|
||||
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);
|
||||
AVCODEC_LOGE("Create avsharedmemory failed, ret = %{public}d", ret);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ std::shared_ptr<AVSharedMemory> AVDataSrcMemory::CreateFromRemote(
|
||||
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",
|
||||
AVCODEC_LOGD("enter ctor, instance: 0x%{public}06" PRIXPTR ", name = %{public}s",
|
||||
FAKE_POINTER(this), name.c_str());
|
||||
offset_ = 0;
|
||||
}
|
||||
@ -66,14 +66,14 @@ AVDataSrcMemory::AVDataSrcMemory(int32_t size, uint32_t flags, const std::string
|
||||
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",
|
||||
AVCODEC_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",
|
||||
AVCODEC_LOGD("enter dtor, instance: 0x%{public}06" PRIXPTR ", name = %{public}s",
|
||||
FAKE_POINTER(this), GetName().c_str());
|
||||
}
|
||||
} // namespace AVCodec
|
||||
|
@ -39,7 +39,7 @@ std::shared_ptr<AVSharedMemory> AVSharedMemoryBase::CreateFromLocal(
|
||||
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);
|
||||
AVCODEC_LOGE("Create avsharedmemory failed, ret = %{public}d", ret);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ std::shared_ptr<AVSharedMemory> AVSharedMemoryBase::CreateFromRemote(
|
||||
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);
|
||||
AVCODEC_LOGE("Create avsharedmemory failed, ret = %{public}d", ret);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -62,20 +62,20 @@ std::shared_ptr<AVSharedMemory> AVSharedMemoryBase::CreateFromRemote(
|
||||
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",
|
||||
AVCODEC_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",
|
||||
AVCODEC_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",
|
||||
AVCODEC_LOGD("enter dtor, instance: 0x%{public}06" PRIXPTR ", name = %{public}s",
|
||||
FAKE_POINTER(this), name_.c_str());
|
||||
Close();
|
||||
}
|
||||
@ -83,7 +83,7 @@ AVSharedMemoryBase::~AVSharedMemoryBase()
|
||||
int32_t AVSharedMemoryBase::Init()
|
||||
{
|
||||
ON_SCOPE_EXIT(0) {
|
||||
MEDIA_LOGE("create avsharedmemory failed, name = %{public}s, size = %{public}d, "
|
||||
AVCODEC_LOGE("create avsharedmemory failed, name = %{public}s, size = %{public}d, "
|
||||
"flags = 0x%{public}x, fd = %{public}d",
|
||||
name_.c_str(), size_, flags_, fd_);
|
||||
Close();
|
||||
|
@ -27,12 +27,12 @@ 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());
|
||||
AVCODEC_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());
|
||||
AVCODEC_LOGD("enter dtor, 0x%{public}06" PRIXPTR ", name: %{public}s", FAKE_POINTER(this), name_.c_str());
|
||||
Reset();
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ int32_t AVSharedMemoryPool::Init(const InitializeOption &option)
|
||||
option_.preAllocMemCnt = option.maxMemCnt;
|
||||
}
|
||||
|
||||
MEDIA_LOGI("name: %{public}s, init option: preAllocMemCnt = %{public}u, memSize = %{public}d, "
|
||||
AVCODEC_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);
|
||||
@ -57,7 +57,7 @@ int32_t AVSharedMemoryPool::Init(const InitializeOption &option)
|
||||
for (uint32_t i = 0; i < option_.preAllocMemCnt; ++i) {
|
||||
auto memory = AllocMemory(option_.memSize);
|
||||
if (memory == nullptr) {
|
||||
MEDIA_LOGE("alloc memory failed");
|
||||
AVCODEC_LOGE("alloc memory failed");
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
@ -85,7 +85,7 @@ AVSharedMemory *AVSharedMemoryPool::AllocMemory(int32_t size)
|
||||
if (memory->Init() != MSERR_OK) {
|
||||
delete memory;
|
||||
memory = nullptr;
|
||||
MEDIA_LOGE("init avsharedmemorybase failed");
|
||||
AVCODEC_LOGE("init avsharedmemorybase failed");
|
||||
}
|
||||
|
||||
return memory;
|
||||
@ -104,7 +104,7 @@ void AVSharedMemoryPool::ReleaseMemory(AVSharedMemory *memory)
|
||||
busyList_.erase(iter);
|
||||
idleList_.push_back(memory);
|
||||
cond_.notify_all();
|
||||
MEDIA_LOGD("0x%{public}06" PRIXPTR " released back to pool %{public}s",
|
||||
AVCODEC_LOGD("0x%{public}06" PRIXPTR " released back to pool %{public}s",
|
||||
FAKE_POINTER(memory), name_.c_str());
|
||||
|
||||
lock.unlock();
|
||||
@ -114,13 +114,13 @@ void AVSharedMemoryPool::ReleaseMemory(AVSharedMemory *memory)
|
||||
return;
|
||||
}
|
||||
|
||||
MEDIA_LOGE("0x%{public}06" PRIXPTR " is no longer managed by this pool", FAKE_POINTER(memory));
|
||||
AVCODEC_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());
|
||||
AVCODEC_LOGD("busylist size %{public}zu, idlelist size %{public}zu", busyList_.size(), idleList_.size());
|
||||
|
||||
AVSharedMemory *result = nullptr;
|
||||
std::list<AVSharedMemory *>::iterator minSizeIdleMem = idleList_.end();
|
||||
@ -184,12 +184,12 @@ bool AVSharedMemoryPool::CheckSize(int32_t size)
|
||||
|
||||
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",
|
||||
AVCODEC_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);
|
||||
AVCODEC_LOGE("invalid size: %{public}d", size);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -211,7 +211,7 @@ std::shared_ptr<AVSharedMemory> AVSharedMemoryPool::AcquireMemory(int32_t size,
|
||||
} while (inited_ && !forceNonBlocking_);
|
||||
|
||||
if (memory == nullptr) {
|
||||
MEDIA_LOGD("acquire memory failed for size: %{public}d", size);
|
||||
AVCODEC_LOGD("acquire memory failed for size: %{public}d", size);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -222,19 +222,19 @@ std::shared_ptr<AVSharedMemory> AVSharedMemoryPool::AcquireMemory(int32_t size,
|
||||
if (pool != nullptr) {
|
||||
pool->ReleaseMemory(memory);
|
||||
} else {
|
||||
MEDIA_LOGI("release memory 0x%{public}06" PRIXPTR ", but the pool is destroyed", FAKE_POINTER(memory));
|
||||
AVCODEC_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));
|
||||
AVCODEC_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);
|
||||
AVCODEC_LOGD("SetNonBlocking: %{public}d", enable);
|
||||
forceNonBlocking_ = enable;
|
||||
if (forceNonBlocking_) {
|
||||
cond_.notify_all();
|
||||
@ -243,7 +243,7 @@ void AVSharedMemoryPool::SetNonBlocking(bool enable)
|
||||
|
||||
void AVSharedMemoryPool::Reset()
|
||||
{
|
||||
MEDIA_LOGD("Reset");
|
||||
AVCODEC_LOGD("Reset");
|
||||
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
for (auto &memory : idleList_) {
|
||||
|
@ -43,7 +43,7 @@ void CopyFormatDataMap(const Format::FormatDataMap &from, Format::FormatDataMap
|
||||
|
||||
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());
|
||||
AVCODEC_LOGE("malloc addr failed. Key: %{public}s", it->first.c_str());
|
||||
it = to.erase(it);
|
||||
continue;
|
||||
}
|
||||
@ -51,7 +51,7 @@ void CopyFormatDataMap(const Format::FormatDataMap &from, Format::FormatDataMap
|
||||
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());
|
||||
AVCODEC_LOGE("memcpy addr failed. Key: %{public}s", it->first.c_str());
|
||||
free(it->second.addr);
|
||||
it->second.addr = nullptr;
|
||||
it = to.erase(it);
|
||||
@ -159,7 +159,7 @@ bool Format::GetStringValue(const std::string_view &key, std::string &value) con
|
||||
{
|
||||
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());
|
||||
AVCODEC_LOGE("Format::GetFormat failed. Key: %{public}s", key.data());
|
||||
return false;
|
||||
}
|
||||
value = iter->second.stringVal;
|
||||
@ -170,7 +170,7 @@ 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());
|
||||
AVCODEC_LOGE("Format::GetFormat failed. Key: %{public}s", key.data());
|
||||
return false;
|
||||
}
|
||||
value = iter->second.val.int32Val;
|
||||
@ -181,7 +181,7 @@ 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());
|
||||
AVCODEC_LOGE("Format::GetFormat failed. Key: %{public}s", key.data());
|
||||
return false;
|
||||
}
|
||||
value = iter->second.val.int64Val;
|
||||
@ -192,7 +192,7 @@ 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());
|
||||
AVCODEC_LOGE("Format::GetFormat failed. Key: %{public}s", key.data());
|
||||
return false;
|
||||
}
|
||||
value = iter->second.val.floatVal;
|
||||
@ -203,7 +203,7 @@ 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());
|
||||
AVCODEC_LOGE("Format::GetFormat failed. Key: %{public}s", key.data());
|
||||
return false;
|
||||
}
|
||||
value = iter->second.val.doubleVal;
|
||||
@ -213,13 +213,13 @@ bool Format::GetDoubleValue(const std::string_view &key, double &value) const
|
||||
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");
|
||||
AVCODEC_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());
|
||||
AVCODEC_LOGE("PutBuffer input size failed. Key: %{public}s", key.data());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -227,13 +227,13 @@ bool Format::PutBuffer(const std::string_view &key, const uint8_t *addr, size_t
|
||||
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());
|
||||
AVCODEC_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());
|
||||
AVCODEC_LOGE("PutBuffer memcpy addr failed. Key: %{public}s", key.data());
|
||||
free(data.addr);
|
||||
return false;
|
||||
}
|
||||
@ -249,7 +249,7 @@ bool Format::GetBuffer(const std::string_view &key, uint8_t **addr, size_t &size
|
||||
{
|
||||
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());
|
||||
AVCODEC_LOGE("Format::GetBuffer failed. Key: %{public}s", key.data());
|
||||
return false;
|
||||
}
|
||||
*addr = iter->second.addr;
|
||||
@ -317,7 +317,7 @@ std::string Format::Stringify() const
|
||||
case FORMAT_TYPE_ADDR:
|
||||
break;
|
||||
default:
|
||||
MEDIA_LOGE("Format::Stringify failed. Key: %{public}s", iter->first.c_str());
|
||||
AVCODEC_LOGE("Format::Stringify failed. Key: %{public}s", iter->first.c_str());
|
||||
}
|
||||
}
|
||||
return outString;
|
||||
|
Loading…
Reference in New Issue
Block a user