格式调整

Signed-off-by: guoyao <guoyao18@huawei.com>
This commit is contained in:
guoyao 2023-04-27 10:20:03 +08:00
parent e26f7e8f2c
commit 462c16bd69
3 changed files with 70 additions and 35 deletions

View File

@ -43,19 +43,23 @@ namespace OHOS {
namespace Media {
static AVCodecClient avCodecClientInstance;
IAVCodecService &AVCodecServiceFactory::GetInstance() {
IAVCodecService &AVCodecServiceFactory::GetInstance()
{
return avCodecClientInstance;
}
AVCodecClient::AVCodecClient() noexcept {
AVCodecClient::AVCodecClient() noexcept
{
AVCODEC_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
}
AVCodecClient::~AVCodecClient() {
AVCodecClient::~AVCodecClient()
{
AVCODEC_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
}
bool AVCodecClient::IsAlived() {
bool AVCodecClient::IsAlived()
{
if (avCodecProxy_ == nullptr) {
avCodecProxy_ = GetAVCodecProxy();
}
@ -63,7 +67,8 @@ bool AVCodecClient::IsAlived() {
return avCodecProxy_ != nullptr;
}
#ifdef SUPPORT_CODEC
std::shared_ptr<ICodecService> AVCodecClient::CreateCodecService() {
std::shared_ptr<ICodecService> AVCodecClient::CreateCodecService()
{
std::lock_guard<std::mutex> lock(mutex_);
if (!IsAlived()) {
AVCODEC_LOGE("av_codec service does not exist.");
@ -84,7 +89,8 @@ std::shared_ptr<ICodecService> AVCodecClient::CreateCodecService() {
return codecClient;
}
int32_t AVCodecClient::DestroyCodecService(std::shared_ptr<ICodecService> codecClient) {
int32_t AVCodecClient::DestroyCodecService(std::shared_ptr<ICodecService> codecClient)
{
std::lock_guard<std::mutex> lock(mutex_);
CHECK_AND_RETURN_RET_LOG(codecClient != nullptr, AVCS_ERR_NO_MEMORY, "codec client is nullptr.");
codecClientList_.remove(codecClient);
@ -92,7 +98,8 @@ int32_t AVCodecClient::DestroyCodecService(std::shared_ptr<ICodecService> codecC
}
#endif
#ifdef SUPPORT_CODECLIST
std::shared_ptr<ICodecListService> AVCodecClient::CreateCodecListService() {
std::shared_ptr<ICodecListService> AVCodecClient::CreateCodecListService()
{
std::lock_guard<std::mutex> lock(mutex_);
if (!IsAlived()) {
AVCODEC_LOGE("av_codec service does not exist.");
@ -113,7 +120,8 @@ std::shared_ptr<ICodecListService> AVCodecClient::CreateCodecListService() {
return codecListClient;
}
int32_t AVCodecClient::DestroyCodecListService(std::shared_ptr<ICodecListService> codecListClient) {
int32_t AVCodecClient::DestroyCodecListService(std::shared_ptr<ICodecListService> codecListClient)
{
std::lock_guard<std::mutex> lock(mutex_);
CHECK_AND_RETURN_RET_LOG(codecListClient != nullptr, AVCS_ERR_NO_MEMORY, "codeclist client is nullptr.");
codecListClientList_.remove(codecListClient);
@ -122,7 +130,8 @@ int32_t AVCodecClient::DestroyCodecListService(std::shared_ptr<ICodecListService
#endif
#ifdef SUPPORT_DEMUXER
std::shared_ptr<IAVDemuxer> AVCodecClient::CreateDemuxerService() {
std::shared_ptr<IAVDemuxer> AVCodecClient::CreateDemuxerService()
{
std::lock_guard<std::mutex> lock(mutex_);
if (!IsAlived()) {
AVCODEC_LOGE("av_codec service does not exist.");
@ -143,7 +152,8 @@ std::shared_ptr<IAVDemuxer> AVCodecClient::CreateDemuxerService() {
return demuxerClient;
}
int32_t AVCodecClient::DestroyDemuxerService(std::shared_ptr<IAVDemuxer> demuxerClient) {
int32_t AVCodecClient::DestroyDemuxerService(std::shared_ptr<IAVDemuxer> demuxerClient)
{
std::lock_guard<std::mutex> lock(mutex_);
CHECK_AND_RETURN_RET_LOG(demuxerClient != nullptr, AVCS_ERR_NO_MEMORY, "demuxer client is nullptr.");
demuxerClientList_.remove(demuxerClient);
@ -152,7 +162,8 @@ int32_t AVCodecClient::DestroyDemuxerService(std::shared_ptr<IAVDemuxer> demuxer
#endif
#ifdef SUPPORT_MUXER
std::shared_ptr<IMuxerService> AVCodecClient::CreateMuxerService() {
std::shared_ptr<IMuxerService> AVCodecClient::CreateMuxerService()
{
std::lock_guard<std::mutex> lock(mutex_);
if (!IsAlived()) {
AVCODEC_LOGE("avcodec service does not exist.");
@ -173,7 +184,8 @@ std::shared_ptr<IMuxerService> AVCodecClient::CreateMuxerService() {
return muxer;
}
int32_t AVCodecClient::DestroyMuxerService(std::shared_ptr<IMuxerService> muxer) {
int32_t AVCodecClient::DestroyMuxerService(std::shared_ptr<IMuxerService> muxer)
{
std::lock_guard<std::mutex> lock(mutex_);
CHECK_AND_RETURN_RET_LOG(muxer != nullptr, AVCS_ERR_NO_MEMORY, "input muxer is nullptr.");
muxerClientList_.remove(muxer);
@ -182,7 +194,8 @@ int32_t AVCodecClient::DestroyMuxerService(std::shared_ptr<IMuxerService> muxer)
#endif
#ifdef SUPPORT_SOURCE
std::shared_ptr<IAVMuxer> AVCodecClient::CreateSourceService() {
std::shared_ptr<IAVMuxer> AVCodecClient::CreateSourceService()
{
std::lock_guard<std::mutex> lock(mutex_);
if (!IsAlived()) {
AVCODEC_LOGE("av_codec service does not exist.");
@ -203,7 +216,8 @@ std::shared_ptr<IAVMuxer> AVCodecClient::CreateSourceService() {
return source;
}
int32_t AVCodecClient::DestroySourceService(std::shared_ptr<ISourceService> sourceClient) {
int32_t AVCodecClient::DestroySourceService(std::shared_ptr<ISourceService> sourceClient)
{
std::lock_guard<std::mutex> lock(mutex_);
CHECK_AND_RETURN_RET_LOG(sourceClient != nullptr, AVCS_ERR_NO_MEMORY, "source client is nullptr.");
sourceClientList_.remove(sourceClient);
@ -211,7 +225,8 @@ int32_t AVCodecClient::DestroySourceService(std::shared_ptr<ISourceService> sour
}
#endif
sptr<IStandardAVCodecService> AVCodecClient::GetAVCodecProxy() {
sptr<IStandardAVCodecService> AVCodecClient::GetAVCodecProxy()
{
AVCODEC_LOGD("enter");
sptr<ISystemAbilityManager> samgr = nullptr;
COLLIE_LISTEN(samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(),
@ -242,12 +257,14 @@ sptr<IStandardAVCodecService> AVCodecClient::GetAVCodecProxy() {
return avCodecProxy_;
}
void AVCodecClient::AVCodecServerDied(pid_t pid) {
void AVCodecClient::AVCodecServerDied(pid_t pid)
{
AVCODEC_LOGE("av_codec server is died, pid:%{public}d!", pid);
avCodecClientInstance.DoAVCodecServerDied();
}
void AVCodecClient::DoAVCodecServerDied() {
void AVCodecClient::DoAVCodecServerDied()
{
std::lock_guard<std::mutex> lock(mutex_);
if (avCodecProxy_ != nullptr) {
(void)avCodecProxy_->AsObject()->RemoveDeathRecipient(deathRecipient_);

View File

@ -27,19 +27,23 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AVCodecSer
namespace OHOS {
namespace Media {
REGISTER_SYSTEM_ABILITY_BY_ID(AVCodecServer, AV_CODEC_SERVICE_ID, true)
AVCodecServer::AVCodecServer(int32_t systemAbilityId, bool runOnCreate) : SystemAbility(systemAbilityId, runOnCreate) {
AVCodecServer::AVCodecServer(int32_t systemAbilityId, bool runOnCreate) : SystemAbility(systemAbilityId, runOnCreate)
{
AVCODEC_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
}
AVCodecServer::~AVCodecServer() {
AVCodecServer::~AVCodecServer()
{
AVCODEC_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
}
void AVCodecServer::OnDump() {
void AVCodecServer::OnDump()
{
AVCODEC_LOGD("AVCodecServer OnDump");
}
void AVCodecServer::OnStart() {
void AVCodecServer::OnStart()
{
AVCODEC_LOGD("AVCodecServer OnStart");
bool res = Publish(this);
if (res) {
@ -47,12 +51,14 @@ void AVCodecServer::OnStart() {
}
}
void AVCodecServer::OnStop() {
void AVCodecServer::OnStop()
{
AVCODEC_LOGD("AVCodecServer OnStop");
}
sptr<IRemoteObject> AVCodecServer::GetSubSystemAbility(IStandardAVCodecService::AVCodecSystemAbility subSystemId,
const sptr<IRemoteObject> &listener) {
const sptr<IRemoteObject> &listener)
{
int32_t ret = AVCodecServiceStub::SetDeathListener(listener);
CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, nullptr, "failed set death listener");
@ -89,7 +95,8 @@ sptr<IRemoteObject> AVCodecServer::GetSubSystemAbility(IStandardAVCodecService::
}
}
int32_t AVCodecServer::Dump(int32_t fd, const std::vector<std::u16string> &args) {
int32_t AVCodecServer::Dump(int32_t fd, const std::vector<std::u16string> &args)
{
if (fd <= 0) {
AVCODEC_LOGW("Failed to check fd");
return OHOS::INVALID_OPERATION;

View File

@ -22,16 +22,19 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AvCodec-Ta
namespace OHOS {
namespace Media {
TaskThread::TaskThread(std::string_view name) : name_(name), runningState_(RunningState::STOPPED), loop_(nullptr) {
TaskThread::TaskThread(std::string_view name) : name_(name), runningState_(RunningState::STOPPED), loop_(nullptr)
{
AVCODEC_LOGD("task %{public}s ctor called", name_.data());
}
TaskThread::TaskThread(std::string_view name, std::function<void()> handler) : TaskThread(name) {
TaskThread::TaskThread(std::string_view name, std::function<void()> handler) : TaskThread(name)
{
handler_ = std::move(handler);
loop_ = std::make_unique<std::thread>(&TaskThread::Run, this);
}
TaskThread::~TaskThread() {
TaskThread::~TaskThread()
{
AVCODEC_LOGD("task %{public}s dtor called", name_.data());
runningState_ = RunningState::STOPPED;
syncCond_.notify_all();
@ -44,7 +47,8 @@ TaskThread::~TaskThread() {
}
}
void TaskThread::Start() {
void TaskThread::Start()
{
std::unique_lock lock(stateMutex_);
runningState_ = RunningState::STARTED;
@ -55,7 +59,8 @@ void TaskThread::Start() {
AVCODEC_LOGD("task %{public}s start called", name_.data());
}
void TaskThread::Stop() {
void TaskThread::Stop()
{
AVCODEC_LOGW("task %{public}s stop entered, current state: %{public}d", name_.data(), runningState_.load());
std::unique_lock lock(stateMutex_);
if (runningState_.load() != RunningState::STOPPED) {
@ -72,7 +77,8 @@ void TaskThread::Stop() {
AVCODEC_LOGW("task %{public}s stop exited", name_.data());
}
void TaskThread::StopAsync() {
void TaskThread::StopAsync()
{
AVCODEC_LOGD("task %{public}s StopAsync called", name_.data());
std::unique_lock lock(stateMutex_);
if (runningState_.load() != RunningState::STOPPED) {
@ -80,7 +86,8 @@ void TaskThread::StopAsync() {
}
}
void TaskThread::Pause() {
void TaskThread::Pause()
{
AVCODEC_LOGD("task %{public}s Pause called", name_.data());
std::unique_lock lock(stateMutex_);
switch (runningState_.load()) {
@ -105,7 +112,8 @@ void TaskThread::Pause() {
AVCODEC_LOGD("task %{public}s Pause done.", name_.data());
}
void TaskThread::PauseAsync() {
void TaskThread::PauseAsync()
{
AVCODEC_LOGD("task %{public}s PauseAsync called", name_.data());
std::unique_lock lock(stateMutex_);
if (runningState_.load() == RunningState::STARTED) {
@ -113,16 +121,19 @@ void TaskThread::PauseAsync() {
}
}
void TaskThread::RegisterHandler(std::function<void()> handler) {
void TaskThread::RegisterHandler(std::function<void()> handler)
{
AVCODEC_LOGI("task %{public}s RegisterHandler called", name_.data());
handler_ = std::move(handler);
}
void TaskThread::doTask() {
void TaskThread::doTask()
{
AVCODEC_LOGD("task %{public}s not override DoTask...", name_.data());
}
void TaskThread::Run() {
void TaskThread::Run()
{
for (;;) {
AVCODEC_LOGD("task %{public}s is running on state : %{public}d", name_.data(), runningState_.load());
if (runningState_.load() == RunningState::STARTED) {