diff --git a/frameworks/native/soundpool/BUILD.gn b/frameworks/native/soundpool/BUILD.gn index 25fe4f06955be3c0fc62d5462bbf8c4b72d7a70c..17f38e3b409178f8d709282f17776e77b5fc0003 100644 --- a/frameworks/native/soundpool/BUILD.gn +++ b/frameworks/native/soundpool/BUILD.gn @@ -28,12 +28,11 @@ ohos_shared_library("soundpool_client") { include_dirs = [ "${multimedia_player_framework_path}/interfaces/inner_api/native/soundpool/include", + "${multimedia_player_framework_path}/services/utils/include", "${av_codec_root_path}/interfaces/inner_api/native", "${multimedia_audio_framework_path}/services/audio_service/client/include", "${multimedia_audio_framework_path}/interfaces/inner_api/native/audiocommon/include", "${multimedia_audio_framework_path}/interfaces/inner_api/native/audiomanager/include", - "${multimedia_media_library_path}/interfaces/inner_api/media_library_helper/include", - "${multimedia_media_library_path}/frameworks/utils/include", "${av_codec_root_path}/services/utils/include", ] diff --git a/frameworks/native/soundpool/cache_buffer.cpp b/frameworks/native/soundpool/cache_buffer.cpp index 0cd6af658fdf5d5c370d7f27d1e058e7355a2bf2..29493ccc6fdfb1bbdecb026a9c1816b8039b9ee8 100644 --- a/frameworks/native/soundpool/cache_buffer.cpp +++ b/frameworks/native/soundpool/cache_buffer.cpp @@ -19,6 +19,10 @@ #include "media_errors.h" #include "securec.h" +namespace { + constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "SoundPool"}; +} + namespace OHOS { namespace Media { CacheBuffer::CacheBuffer(const Format &trackFormat, @@ -28,12 +32,12 @@ CacheBuffer::CacheBuffer(const Format &trackFormat, cacheDataFrameNum_(0), havePlayedCount_(0) { - MEDIA_INFO_LOG("Construction CacheBuffer"); + MEDIA_LOGI("Construction CacheBuffer"); } CacheBuffer::~CacheBuffer() { - MEDIA_INFO_LOG("Destruction CacheBuffer dec"); + MEDIA_LOGI("Destruction CacheBuffer dec"); Release(); } @@ -73,7 +77,7 @@ std::unique_ptr CacheBuffer::CreateAudioRenderer(c AudioStandard::AudioRenderer::Create(cacheDir, rendererOptions); if (audioRenderer == nullptr) { - MEDIA_ERR_LOG("create audiorenderer failed, try again."); + MEDIA_LOGE("create audiorenderer failed, try again."); rendererFlags_ = NORMAL_PLAY_RENDERER_FLAGS; rendererOptions.rendererInfo.rendererFlags = rendererFlags_; audioRenderer = AudioStandard::AudioRenderer::Create(cacheDir, rendererOptions); @@ -83,11 +87,11 @@ std::unique_ptr CacheBuffer::CreateAudioRenderer(c audioRenderer->SetRenderMode(AudioStandard::AudioRenderMode::RENDER_MODE_CALLBACK); int32_t ret = audioRenderer->SetRendererWriteCallback(shared_from_this()); if (ret != MSERR_OK) { - MEDIA_ERR_LOG("audio renderer write callback fail, ret %{public}d.", ret); + MEDIA_LOGE("audio renderer write callback fail, ret %{public}d.", ret); } ret = audioRenderer->SetRendererFirstFrameWritingCallback(shared_from_this()); if (ret != MSERR_OK) { - MEDIA_ERR_LOG("audio renderer first frame write callback fail, ret %{public}d.", ret); + MEDIA_LOGE("audio renderer first frame write callback fail, ret %{public}d.", ret); } return audioRenderer; } @@ -100,7 +104,7 @@ int32_t CacheBuffer::PreparePlay(const int32_t streamID, const AudioStandard::Au audioRenderer_ = CreateAudioRenderer(streamID, audioRendererInfo, playParams); ReCombineCacheData(); } else { - MEDIA_INFO_LOG("audio render inited."); + MEDIA_LOGI("audio render inited."); } // deal play params DealPlayParamsBeforePlay(streamID, playParams); @@ -116,14 +120,14 @@ int32_t CacheBuffer::DoPlay(const int32_t streamID) cacheDataFrameNum_ = 0; havePlayedCount_ = 0; if (!audioRenderer_->Start()) { - MEDIA_ERR_LOG("audioRenderer Start failed"); + MEDIA_LOGE("audioRenderer Start failed"); if (callback_ != nullptr) callback_->OnError(MSERR_INVALID_VAL); if (cacheBufferCallback_ != nullptr) cacheBufferCallback_->OnError(MSERR_INVALID_VAL); return MSERR_INVALID_VAL; } return MSERR_OK; } - MEDIA_ERR_LOG("Invalid audioRenderer."); + MEDIA_LOGE("Invalid audioRenderer."); return MSERR_INVALID_VAL; } @@ -141,12 +145,12 @@ int32_t CacheBuffer::ReCombineCacheData() for (size_t reCombineCacheDataNum = 0; reCombineCacheDataNum < reCombineCacheDataSize; reCombineCacheDataNum++) { uint8_t *reCombineBuf = new(std::nothrow) uint8_t[bufferSize]; if (reCombineBuf == nullptr) { - MEDIA_ERR_LOG("Invalid recombine buffer."); + MEDIA_LOGE("Invalid recombine buffer."); continue; } for (size_t bufferNum = 0; bufferNum < bufferSize; bufferNum++) { if (preAudioBuffer == nullptr) { - MEDIA_ERR_LOG("Invalid pre audio buffer."); + MEDIA_LOGE("Invalid pre audio buffer."); continue; } if (cacheData_.size() > 1 && (preAudioBufferIndex == static_cast(preAudioBuffer->size))) { @@ -210,16 +214,16 @@ void CacheBuffer::OnWriteData(size_t length) { AudioStandard::BufferDesc bufDesc; if (audioRenderer_ == nullptr) { - MEDIA_ERR_LOG("audioRenderer is nullptr."); + MEDIA_LOGE("audioRenderer is nullptr."); return; } if (!isRunning_.load()) { - MEDIA_ERR_LOG("audioRenderer is stop."); + MEDIA_LOGE("audioRenderer is stop."); return; } if (cacheDataFrameNum_ == reCombineCacheData_.size()) { if (havePlayedCount_ == loop_) { - MEDIA_INFO_LOG("CacheBuffer stream write finish, cacheDataFrameNum_:%{public}zu," + MEDIA_LOGI("CacheBuffer stream write finish, cacheDataFrameNum_:%{public}zu," " havePlayedCount_:%{public}d, loop:%{public}d, try to stop.", cacheDataFrameNum_, havePlayedCount_, loop_); Stop(streamID_); @@ -318,7 +322,7 @@ int32_t CacheBuffer::SetParallelPlayFlag(const int32_t streamID, const bool para { std::lock_guard lock(cacheBufferLock_); if (streamID == streamID_) { - MEDIA_INFO_LOG("CacheBuffer parallelPlayFlag:%{public}d.", parallelPlayFlag); + MEDIA_LOGI("CacheBuffer parallelPlayFlag:%{public}d.", parallelPlayFlag); if (audioRenderer_ != nullptr) { audioRenderer_->SetParallelPlayFlag(parallelPlayFlag); } @@ -329,7 +333,7 @@ int32_t CacheBuffer::SetParallelPlayFlag(const int32_t streamID, const bool para int32_t CacheBuffer::Release() { std::lock_guard lock(cacheBufferLock_); - MEDIA_INFO_LOG("CacheBuffer release, streamID:%{public}d", streamID_); + MEDIA_LOGI("CacheBuffer release, streamID:%{public}d", streamID_); isRunning_.store(false); if (audioRenderer_ != nullptr) { audioRenderer_->Stop(); diff --git a/frameworks/native/soundpool/sound_id_manager.cpp b/frameworks/native/soundpool/sound_id_manager.cpp index 326fd0fdbaef4b3bb75ae336f2fe9b01eef167e2..ac551e0a267f5a74b9828ea8107778fa8e0135b2 100644 --- a/frameworks/native/soundpool/sound_id_manager.cpp +++ b/frameworks/native/soundpool/sound_id_manager.cpp @@ -27,13 +27,13 @@ namespace OHOS { namespace Media { SoundIDManager::SoundIDManager() : isParsingThreadPoolStarted_(false), quitQueue_(false) { - MEDIA_INFO_LOG("Construction SoundIDManager"); + MEDIA_LOGI("Construction SoundIDManager"); InitThreadPool(); } SoundIDManager::~SoundIDManager() { - MEDIA_INFO_LOG("Destruction SoundIDManager"); + MEDIA_LOGI("Destruction SoundIDManager"); { std::lock_guard lock(soundManagerLock_); quitQueue_ = true; @@ -78,7 +78,7 @@ int32_t SoundIDManager::Load(std::string url) { std::lock_guard lock(soundManagerLock_); if (soundParsers_.size() >= MAX_LOAD_NUM) { - MEDIA_INFO_LOG("SoundPool MAX_LOAD_NUM:%{public}zu.", MAX_LOAD_NUM); + MEDIA_LOGI("SoundPool MAX_LOAD_NUM:%{public}zu.", MAX_LOAD_NUM); return invalidSoundIDFlag; } const std::string fdHead = "fd://"; @@ -107,9 +107,9 @@ int32_t SoundIDManager::Load(int32_t fd, int64_t offset, int64_t length) int32_t soundID; { std::lock_guard lock(soundManagerLock_); - MEDIA_INFO_LOG("SoundIDManager startLoad"); + MEDIA_LOGI("SoundIDManager startLoad"); if (soundParsers_.size() >= MAX_LOAD_NUM) { - MEDIA_INFO_LOG("SoundPool MAX_LOAD_NUM:%{public}zu.", MAX_LOAD_NUM); + MEDIA_LOGI("SoundPool MAX_LOAD_NUM:%{public}zu.", MAX_LOAD_NUM); return invalidSoundIDFlag; } do { @@ -126,7 +126,7 @@ int32_t SoundIDManager::Load(int32_t fd, int64_t offset, int64_t length) int32_t SoundIDManager::DoLoad(int32_t soundID) { - MEDIA_INFO_LOG("SoundIDManager soundID:%{public}d", soundID); + MEDIA_LOGI("SoundIDManager soundID:%{public}d", soundID); if (!isParsingThreadPoolStarted_) { InitThreadPool(); } @@ -177,7 +177,7 @@ int32_t SoundIDManager::DoParser() std::shared_ptr SoundIDManager::FindSoundParser(int32_t soundID) const { - MEDIA_INFO_LOG("SoundIDManager soundID:%{public}d", soundID); + MEDIA_LOGI("SoundIDManager soundID:%{public}d", soundID); if (soundParsers_.empty()) { return nullptr; } @@ -189,7 +189,7 @@ std::shared_ptr SoundIDManager::FindSoundParser(int32_t soundID) co int32_t SoundIDManager::Unload(int32_t soundID) { - MEDIA_INFO_LOG("SoundIDManager soundID:%{public}d", soundID); + MEDIA_LOGI("SoundIDManager soundID:%{public}d", soundID); CHECK_AND_RETURN_RET_LOG(!soundParsers_.empty(), MSERR_NO_MEMORY, "No sound in the soundParsers_"); auto it = soundParsers_.find(soundID); if (it != soundParsers_.end()) { @@ -198,7 +198,7 @@ int32_t SoundIDManager::Unload(int32_t soundID) } soundParsers_.erase(it); } else { - MEDIA_INFO_LOG("Invalid soundID, unload failed"); + MEDIA_LOGI("Invalid soundID, unload failed"); return MSERR_INVALID_VAL; } return MSERR_OK; diff --git a/frameworks/native/soundpool/sound_parser.cpp b/frameworks/native/soundpool/sound_parser.cpp index f755ea0ec62438cc3cebb538baac92baef6c50ba..8133690d282205b261085d03ef1d9681e1107524 100644 --- a/frameworks/native/soundpool/sound_parser.cpp +++ b/frameworks/native/soundpool/sound_parser.cpp @@ -54,13 +54,13 @@ SoundParser::SoundParser(int32_t soundID, int32_t fd, int64_t offset, int64_t le SoundParser::~SoundParser() { - MEDIA_INFO_LOG("SoundParser Destruction."); + MEDIA_LOGI("SoundParser Destruction."); Release(); } int32_t SoundParser::DoParser() { - MEDIA_ERR_LOG("SoundParser do parser."); + MEDIA_LOGE("SoundParser do parser."); std::unique_lock lock(soundParserLock_); DoDemuxer(&trackFormat_); DoDecode(trackFormat_); @@ -77,22 +77,22 @@ int32_t SoundParser::DoDemuxer(MediaAVCodec::Format *trackFormat) CHECK_AND_RETURN_RET_LOG(trackFormat != nullptr, MSERR_INVALID_VAL, "Invalid trackFormat."); int32_t ret = source_->GetSourceFormat(sourceFormat); if (ret != 0) { - MEDIA_ERR_LOG("Get source format failed:%{public}d", ret); + MEDIA_LOGE("Get source format failed:%{public}d", ret); } sourceFormat.GetIntValue(MediaAVCodec::MediaDescriptionKey::MD_KEY_TRACK_COUNT, sourceTrackCountInfo); sourceFormat.GetLongValue(MediaAVCodec::MediaDescriptionKey::MD_KEY_DURATION, sourceDurationInfo); - MEDIA_INFO_LOG("SoundParser sourceTrackCountInfo:%{public}d", sourceTrackCountInfo); + MEDIA_LOGI("SoundParser sourceTrackCountInfo:%{public}d", sourceTrackCountInfo); for (int32_t sourceTrackIndex = 0; sourceTrackIndex < sourceTrackCountInfo; sourceTrackIndex++) { int32_t trackType = 0; ret = source_->GetTrackFormat(*trackFormat, sourceTrackIndex); if (ret != 0) { - MEDIA_ERR_LOG("Get track format failed:%{public}d", ret); + MEDIA_LOGE("Get track format failed:%{public}d", ret); } trackFormat->GetIntValue(MediaDescriptionKey::MD_KEY_TRACK_TYPE, trackType); - MEDIA_INFO_LOG("SoundParser trackType:%{public}d", trackType); + MEDIA_LOGI("SoundParser trackType:%{public}d", trackType); if (trackType == MEDIA_TYPE_AUD) { - MEDIA_INFO_LOG("SoundParser trackType:%{public}d", trackType); + MEDIA_LOGI("SoundParser trackType:%{public}d", trackType); demuxer_->SelectTrackByID(sourceTrackIndex); int32_t trackBitRateInfo; std::string trackMimeTypeInfo; @@ -121,7 +121,7 @@ int32_t SoundParser::DoDecode(MediaAVCodec::Format trackFormat) if (trackTypeInfo == MEDIA_TYPE_AUD) { std::string trackMimeTypeInfo; trackFormat.GetStringValue(MediaAVCodec::MediaDescriptionKey::MD_KEY_CODEC_MIME, trackMimeTypeInfo); - MEDIA_INFO_LOG("SoundParser mime type:%{public}s", trackMimeTypeInfo.c_str()); + MEDIA_LOGI("SoundParser mime type:%{public}s", trackMimeTypeInfo.c_str()); audioDec_ = MediaAVCodec::AudioDecoderFactory::CreateByMime(trackMimeTypeInfo); CHECK_AND_RETURN_RET_LOG(audioDec_ != nullptr, MSERR_INVALID_VAL, "Failed to obtain audioDecorder."); int32_t ret = audioDec_->Configure(trackFormat); @@ -166,7 +166,7 @@ int32_t SoundParser::SetCallback(const std::shared_ptr &call int32_t SoundParser::Release() { - MEDIA_INFO_LOG("SoundParser Release."); + MEDIA_LOGI("SoundParser Release."); int32_t ret = MSERR_OK; if (soundParserListener_ != nullptr) soundParserListener_.reset(); if (audioDecCb_ != nullptr) { @@ -190,18 +190,18 @@ SoundDecoderCallback::SoundDecoderCallback(const int32_t soundID, demuxer_(demuxer), isRawFile_(isRawFile), eosFlag_(false), decodeShouldCompleted_(false), currentSoundBufferSize_(0) { - MEDIA_INFO_LOG("Construction SoundDecoderCallback"); + MEDIA_LOGI("Construction SoundDecoderCallback"); } SoundDecoderCallback::~SoundDecoderCallback() { - MEDIA_INFO_LOG("Destruction SoundDecoderCallback"); + MEDIA_LOGI("Destruction SoundDecoderCallback"); Release(); } void SoundDecoderCallback::OnError(AVCodecErrorType errorType, int32_t errorCode) { if (isRawFile_) { - MEDIA_INFO_LOG("Recive error, errorType:%{public}d,errorCode:%{public}d", errorType, errorCode); + MEDIA_LOGI("Recive error, errorType:%{public}d,errorCode:%{public}d", errorType, errorCode); } } @@ -220,7 +220,7 @@ void SoundDecoderCallback::OnInputBufferAvailable(uint32_t index, std::shared_pt if (buffer != nullptr && isRawFile_ && !decodeShouldCompleted_) { if (demuxer_->ReadSample(0, buffer, sampleInfo, bufferFlag) != AVCS_ERR_OK) { - MEDIA_ERR_LOG("SoundDecoderCallback demuxer error."); + MEDIA_LOGE("SoundDecoderCallback demuxer error."); return; } if (!decodeShouldCompleted_ && (currentSoundBufferSize_ > MAX_SOUND_BUFFER_SIZE || @@ -237,7 +237,7 @@ void SoundDecoderCallback::OnInputBufferAvailable(uint32_t index, std::shared_pt uint8_t *buf = new(std::nothrow) uint8_t[size]; if (buf != nullptr) { if (memcpy_s(buf, size, buffer->GetBase(), size) != EOK) { - MEDIA_INFO_LOG("audio buffer copy failed:%{public}s", strerror(errno)); + MEDIA_LOGI("audio buffer copy failed:%{public}s", strerror(errno)); } else { availableAudioBuffers_.push_back(std::make_shared(buf, size)); bufferCond_.notify_all(); @@ -250,7 +250,7 @@ void SoundDecoderCallback::OnInputBufferAvailable(uint32_t index, std::shared_pt if (buffer != nullptr && !eosFlag_ && !decodeShouldCompleted_) { if (demuxer_->ReadSample(0, buffer, sampleInfo, bufferFlag) != AVCS_ERR_OK) { - MEDIA_ERR_LOG("SoundDecoderCallback demuxer error."); + MEDIA_LOGE("SoundDecoderCallback demuxer error."); return; } if (bufferFlag == AVCODEC_BUFFER_FLAG_EOS) { @@ -265,7 +265,7 @@ void SoundDecoderCallback::OnOutputBufferAvailable(uint32_t index, AVCodecBuffer { std::unique_lock lock(amutex_); if (isRawFile_) { - MEDIA_INFO_LOG("audio raw data, return."); + MEDIA_LOGI("audio raw data, return."); CHECK_AND_RETURN_LOG(audioDec_ != nullptr, "Failed to obtain audio decode."); audioDec_->ReleaseOutputBuffer(index); return; @@ -284,7 +284,7 @@ void SoundDecoderCallback::OnOutputBufferAvailable(uint32_t index, AVCodecBuffer uint8_t *buf = new(std::nothrow) uint8_t[size]; if (buf != nullptr) { if (memcpy_s(buf, size, buffer->GetBase(), info.size) != EOK) { - MEDIA_INFO_LOG("audio buffer copy failed:%{public}s", strerror(errno)); + MEDIA_LOGI("audio buffer copy failed:%{public}s", strerror(errno)); } else { availableAudioBuffers_.push_back(std::make_shared(buf, size)); bufferCond_.notify_all(); @@ -298,7 +298,7 @@ void SoundDecoderCallback::OnOutputBufferAvailable(uint32_t index, AVCodecBuffer int32_t SoundDecoderCallback::SetCallback(const std::shared_ptr &callback) { - MEDIA_INFO_LOG("SoundDecoderCallback::SetCallback"); + MEDIA_LOGI("SoundDecoderCallback::SetCallback"); callback_ = callback; return MSERR_OK; } @@ -306,7 +306,7 @@ int32_t SoundDecoderCallback::SetCallback(const std::shared_ptrRelease(); audioDec_.reset(); diff --git a/frameworks/native/soundpool/sound_parser.h b/frameworks/native/soundpool/sound_parser.h index 31f483d2e00a24351c249a744e8fe08f4596ec38..60fda165bf89dc4fa2354d8a01bd41b9316339fc 100644 --- a/frameworks/native/soundpool/sound_parser.h +++ b/frameworks/native/soundpool/sound_parser.h @@ -38,17 +38,21 @@ namespace OHOS { namespace Media { using namespace MediaAVCodec; +namespace { + constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "SoundPool"}; +} + class SoundDecoderCallback : public AVCodecCallback, public NoCopyable { public: class SoundDecodeListener { public: SoundDecodeListener() { - MEDIA_INFO_LOG("Construction SoundDecodeListener"); + MEDIA_LOGI("Construction SoundDecodeListener"); } virtual ~SoundDecodeListener() { - MEDIA_INFO_LOG("Destruction SoundDecodeListener"); + MEDIA_LOGI("Destruction SoundDecodeListener"); } virtual void OnSoundDecodeCompleted(const std::deque> &availableAudioBuffers) = 0; @@ -60,7 +64,7 @@ public: ~SoundDecoderCallback(); int32_t SetDecodeCallback(const std::shared_ptr &listener) { - MEDIA_INFO_LOG("%{public}s:%{public}d", __func__, __LINE__); + MEDIA_LOGI("%{public}s:%{public}d", __func__, __LINE__); CHECK_AND_RETURN_RET_LOG(listener != nullptr, MSERR_INVALID_VAL, "Invalid listener."); listener_ = listener; return MSERR_OK; diff --git a/frameworks/native/soundpool/soundpool.cpp b/frameworks/native/soundpool/soundpool.cpp index f330ba243df0d3579a4238c895c3a84899ba26c7..2a999b79a8f0af582d6f28953f4fa899881c3533 100644 --- a/frameworks/native/soundpool/soundpool.cpp +++ b/frameworks/native/soundpool/soundpool.cpp @@ -40,12 +40,12 @@ std::shared_ptr SoundPoolFactory::CreateSoundPool(int maxStreams, SoundPool::SoundPool() { - MEDIA_INFO_LOG("Construction SoundPool."); + MEDIA_LOGI("Construction SoundPool."); } SoundPool::~SoundPool() { - MEDIA_INFO_LOG("Destruction SoundPool."); + MEDIA_LOGI("Destruction SoundPool."); ReleaseInner(); } @@ -98,7 +98,7 @@ int32_t SoundPool::Play(int32_t soundID, PlayParams playParameters) CHECK_AND_RETURN_RET_LOG(soundParser != nullptr, -1, "Invalid sound."); if (!soundParser->IsSoundParserCompleted()) { - MEDIA_ERR_LOG("sound load no completed. "); + MEDIA_LOGE("sound load no completed. "); return -1; } const int32_t streamID = streamIdManager_->Play(soundParser, playParameters); @@ -131,7 +131,7 @@ int32_t SoundPool::SetPriority(int32_t streamID, int32_t priority) CHECK_AND_RETURN_RET_LOG(streamIdManager_ != nullptr, MSERR_INVALID_VAL, "sound pool have released."); if (std::shared_ptr cacheBuffer = streamIdManager_->FindCacheBuffer(streamID)) { if (priority < MIN_STREAM_PRIORITY) { - MEDIA_INFO_LOG("Invalid priority, align priority to min."); + MEDIA_LOGI("Invalid priority, align priority to min."); priority = MIN_STREAM_PRIORITY; } return cacheBuffer->SetPriority(streamID, priority); @@ -183,7 +183,7 @@ int32_t SoundPool::Release() int32_t SoundPool::ReleaseInner() { std::lock_guard lock(soundPoolLock_); - MEDIA_INFO_LOG("Release SoundPool."); + MEDIA_LOGI("Release SoundPool."); if (streamIdManager_ != nullptr) { streamIdManager_.reset(); } @@ -202,7 +202,7 @@ int32_t SoundPool::ReleaseInner() int32_t SoundPool::SetSoundPoolCallback(const std::shared_ptr &soundPoolCallback) { - MEDIA_INFO_LOG("SoundPool::%{public}s", __func__); + MEDIA_LOGI("SoundPool::%{public}s", __func__); if (soundIDManager_ != nullptr) soundIDManager_->SetCallback(soundPoolCallback); if (streamIdManager_ != nullptr) streamIdManager_->SetCallback(soundPoolCallback); callback_ = soundPoolCallback; @@ -212,7 +212,7 @@ int32_t SoundPool::SetSoundPoolCallback(const std::shared_ptr &frameWriteCallback) { - MEDIA_INFO_LOG("SoundPool::%{public}s", __func__); + MEDIA_LOGI("SoundPool::%{public}s", __func__); if (streamIdManager_ != nullptr) streamIdManager_->SetFrameWriteCallback(frameWriteCallback); frameWriteCallback_ = frameWriteCallback; return MSERR_OK; @@ -222,11 +222,11 @@ bool SoundPool::CheckVolumeVaild(float *leftVol, float *rightVol) { if (*leftVol != std::clamp(*leftVol, 0.f, 1.f) || *rightVol != std::clamp(*rightVol, 0.f, 1.f)) { - MEDIA_INFO_LOG("volume l=%{public}f r=%{public}f out of (0.f, 1.f) bounds, using 1.f", *leftVol, *rightVol); + MEDIA_LOGI("volume l=%{public}f r=%{public}f out of (0.f, 1.f) bounds, using 1.f", *leftVol, *rightVol); *leftVol = *rightVol = 1.f; } if (*leftVol != *rightVol) { - MEDIA_INFO_LOG("left volume %{public}f set not eq the right volume %{public}f ,use the left volume", + MEDIA_LOGI("left volume %{public}f set not eq the right volume %{public}f ,use the left volume", *leftVol, *rightVol); *rightVol = *leftVol; } diff --git a/frameworks/native/soundpool/soundpool_manager.cpp b/frameworks/native/soundpool/soundpool_manager.cpp index 4606e46e501c1670cc81c58c91d262a149e1615a..a2765b54d005048a3137147c8ed2d1b524bc745d 100644 --- a/frameworks/native/soundpool/soundpool_manager.cpp +++ b/frameworks/native/soundpool/soundpool_manager.cpp @@ -20,7 +20,7 @@ namespace OHOS { namespace Media { SoundPoolManager::~SoundPoolManager() { - MEDIA_INFO_LOG("Destruction SoundPoolManager."); + MEDIA_LOGI("Destruction SoundPoolManager."); std::lock_guard lock(mutex_); soundPools_.clear(); }; @@ -39,7 +39,7 @@ int32_t SoundPoolManager::SetSoundPool(const pid_t pid, std::shared_ptr lock(mutex_); auto it = soundPools_.find(pid); if (it != soundPools_.end()) { - MEDIA_INFO_LOG("SoundPool have setted, use old object."); + MEDIA_LOGI("SoundPool have setted, use old object."); return MSERR_OK; } soundPool = std::make_shared(); @@ -53,7 +53,7 @@ int32_t SoundPoolManager::Release(const pid_t pid) std::lock_guard lock(mutex_); auto it = soundPools_.find(pid); if (it != soundPools_.end()) { - MEDIA_INFO_LOG("Release soundpool, pid:%{pulibc}d.", pid); + MEDIA_LOGI("Release soundpool, pid:%{pulibc}d.", pid); soundPools_.erase(it); return MSERR_OK; } diff --git a/frameworks/native/soundpool/stream_id_manager.cpp b/frameworks/native/soundpool/stream_id_manager.cpp index 9c353819b8586fd946bc34f24ed12f0deef5709c..11837ac7a658bc88a44ed8a00a90631c1eb99b39 100644 --- a/frameworks/native/soundpool/stream_id_manager.cpp +++ b/frameworks/native/soundpool/stream_id_manager.cpp @@ -30,20 +30,20 @@ namespace Media { StreamIDManager::StreamIDManager(int32_t maxStreams, AudioStandard::AudioRendererInfo audioRenderInfo) : audioRendererInfo_(audioRenderInfo), maxStreams_(maxStreams) { - MEDIA_INFO_LOG("Construction StreamIDManager."); + MEDIA_LOGI("Construction StreamIDManager."); #ifdef SOUNDPOOL_SUPPORT_LOW_LATENCY char hardwareName[10] = {0}; GetParameter("ohos.boot.hardware", "rk3568", hardwareName, sizeof(hardwareName)); if (strcmp(hardwareName, "baltimore") != 0) { - MEDIA_INFO_LOG("Device unsupport low-latency, force set to normal play."); + MEDIA_LOGI("Device unsupport low-latency, force set to normal play."); audioRendererInfo_.rendererFlags = 0; } else { - MEDIA_INFO_LOG("Device support low-latency, set renderer by user."); + MEDIA_LOGI("Device support low-latency, set renderer by user."); } #else // Force all play to normal. audioRendererInfo_.rendererFlags = 0; - MEDIA_INFO_LOG("SoundPool unsupport low-latency."); + MEDIA_LOGI("SoundPool unsupport low-latency."); #endif InitThreadPool(); @@ -51,7 +51,7 @@ StreamIDManager::StreamIDManager(int32_t maxStreams, StreamIDManager::~StreamIDManager() { - MEDIA_INFO_LOG("Destruction StreamIDManager"); + MEDIA_LOGI("Destruction StreamIDManager"); if (callback_ != nullptr) { callback_.reset(); } @@ -82,13 +82,13 @@ int32_t StreamIDManager::InitThreadPool() "Failed to obtain playing ThreadPool"); if (maxStreams_ > MAX_PLAY_STREAMS_NUMBER) { maxStreams_ = MAX_PLAY_STREAMS_NUMBER; - MEDIA_INFO_LOG("more than max play stream number, align to max play strem number."); + MEDIA_LOGI("more than max play stream number, align to max play strem number."); } if (maxStreams_ < MIN_PLAY_STREAMS_NUMBER) { maxStreams_ = MIN_PLAY_STREAMS_NUMBER; - MEDIA_INFO_LOG("less than min play stream number, align to min play strem number."); + MEDIA_LOGI("less than min play stream number, align to min play strem number."); } - MEDIA_INFO_LOG("stream playing thread pool maxStreams_:%{public}d", maxStreams_); + MEDIA_LOGI("stream playing thread pool maxStreams_:%{public}d", maxStreams_); // For stream priority logic, thread num need align to task num. streamPlayingThreadPool_->Start(maxStreams_); streamPlayingThreadPool_->SetMaxTaskNum(maxStreams_); @@ -140,7 +140,7 @@ int32_t StreamIDManager::SetPlay(const int32_t soundID, const int32_t streamID, CHECK_AND_RETURN_RET_LOG(streamPlayingThreadPool_ != nullptr, MSERR_INVALID_VAL, "Failed to obtain stream play threadpool."); - MEDIA_INFO_LOG("StreamIDManager cur task num:%{public}zu, maxStreams_:%{public}d", + MEDIA_LOGI("StreamIDManager cur task num:%{public}zu, maxStreams_:%{public}d", currentTaskNum_, maxStreams_); // CacheBuffer must prepare before play. std::shared_ptr freshCacheBuffer = FindCacheBuffer(streamID); @@ -153,17 +153,17 @@ int32_t StreamIDManager::SetPlay(const int32_t soundID, const int32_t streamID, int32_t playingStreamID = playingStreamIDs_.back(); std::shared_ptr playingCacheBuffer = FindCacheBuffer(playingStreamID); CHECK_AND_RETURN_RET_LOG(freshCacheBuffer != nullptr, -1, "Invalid fresh cache buffer"); - MEDIA_INFO_LOG("StreamIDManager fresh sound priority:%{public}d, playing stream priority:%{public}d", + MEDIA_LOGI("StreamIDManager fresh sound priority:%{public}d, playing stream priority:%{public}d", freshCacheBuffer->GetPriority(), playingCacheBuffer->GetPriority()); if (freshCacheBuffer->GetPriority() >= playingCacheBuffer->GetPriority()) { - MEDIA_INFO_LOG("StreamIDManager stop playing low priority sound:%{public}d", playingStreamID); + MEDIA_LOGI("StreamIDManager stop playing low priority sound:%{public}d", playingStreamID); playingCacheBuffer->Stop(playingStreamID); playingStreamIDs_.pop_back(); - MEDIA_INFO_LOG("StreamIDManager to playing fresh sound:%{public}d.", streamID); + MEDIA_LOGI("StreamIDManager to playing fresh sound:%{public}d.", streamID); AddPlayTask(streamID, playParameters); } else { std::lock_guard lock(streamIDManagerLock_); - MEDIA_INFO_LOG("StreamIDManager queue will play streams, streamID:%{public}d.", streamID); + MEDIA_LOGI("StreamIDManager queue will play streams, streamID:%{public}d.", streamID); StreamIDAndPlayParamsInfo freshStreamIDAndPlayParamsInfo; freshStreamIDAndPlayParamsInfo.streamID = streamID; freshStreamIDAndPlayParamsInfo.playParameters = playParameters; @@ -257,7 +257,7 @@ int32_t StreamIDManager::AddPlayTask(const int32_t streamID, const PlayParams pl int32_t StreamIDManager::DoPlay(const int32_t streamID) { - MEDIA_INFO_LOG("StreamIDManager streamID:%{public}d", streamID); + MEDIA_LOGI("StreamIDManager streamID:%{public}d", streamID); std::shared_ptr cacheBuffer = FindCacheBuffer(streamID); CHECK_AND_RETURN_RET_LOG(cacheBuffer.get() != nullptr, MSERR_INVALID_VAL, "cachebuffer invalid."); if (cacheBuffer->DoPlay(streamID) == MSERR_OK) { @@ -269,7 +269,7 @@ int32_t StreamIDManager::DoPlay(const int32_t streamID) std::shared_ptr StreamIDManager::FindCacheBuffer(const int32_t streamID) { if (cacheBuffers_.empty()) { - MEDIA_INFO_LOG("StreamIDManager cacheBuffers_ empty"); + MEDIA_LOGI("StreamIDManager cacheBuffers_ empty"); return nullptr; } if (cacheBuffers_.find(streamID) != cacheBuffers_.end()) { @@ -288,17 +288,17 @@ int32_t StreamIDManager::GetFreshStreamID(const int32_t soundID, PlayParams play { int32_t streamID = 0; if (cacheBuffers_.empty()) { - MEDIA_INFO_LOG("StreamIDManager cacheBuffers_ empty"); + MEDIA_LOGI("StreamIDManager cacheBuffers_ empty"); return streamID; } for (auto cacheBuffer : cacheBuffers_) { if (cacheBuffer.second == nullptr) { - MEDIA_ERR_LOG("Invalid cacheBuffer, soundID:%{public}d", soundID); + MEDIA_LOGE("Invalid cacheBuffer, soundID:%{public}d", soundID); continue; } if (soundID == cacheBuffer.second->GetSoundID()) { streamID = cacheBuffer.second->GetStreamID(); - MEDIA_INFO_LOG("Have cache soundID:%{public}d, streamID:%{public}d", soundID, streamID); + MEDIA_LOGI("Have cache soundID:%{public}d, streamID:%{public}d", soundID, streamID); break; } } @@ -309,7 +309,7 @@ void StreamIDManager::OnPlayFinished() { currentTaskNum_--; if (!willPlayStreamInfos_.empty()) { - MEDIA_INFO_LOG("StreamIDManager OnPlayFinished will play streams non empty, get the front."); + MEDIA_LOGI("StreamIDManager OnPlayFinished will play streams non empty, get the front."); StreamIDAndPlayParamsInfo willPlayStreamInfo = willPlayStreamInfos_.front(); AddPlayTask(willPlayStreamInfo.streamID, willPlayStreamInfo.playParameters); std::lock_guard lock(streamIDManagerLock_); diff --git a/frameworks/native/soundpool/stream_id_manager.h b/frameworks/native/soundpool/stream_id_manager.h index 004e3a8342e23402eb13de309964d3bb71b4a24d..ca174fd2456e312ff4ad4880d15f413ce2895b28 100644 --- a/frameworks/native/soundpool/stream_id_manager.h +++ b/frameworks/native/soundpool/stream_id_manager.h @@ -23,6 +23,10 @@ #include "sound_parser.h" #include "thread_pool.h" +namespace { + constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "SoundPool"}; +} + namespace OHOS { namespace Media { class StreamIDManager : public std::enable_shared_from_this { @@ -46,12 +50,12 @@ private: explicit CacheBufferCallBack(const std::weak_ptr streamIDManager) : streamIDManagerInner_(streamIDManager) { - MEDIA_INFO_LOG("Construction StreamIDManager::SoundPoolCallBack"); + MEDIA_LOGI("Construction StreamIDManager::SoundPoolCallBack"); } virtual ~CacheBufferCallBack() = default; void OnLoadCompleted(int32_t soundID) { - MEDIA_INFO_LOG("StreamIDManager::SoundPoolCallBack OnLoadCompleted"); + MEDIA_LOGI("StreamIDManager::SoundPoolCallBack OnLoadCompleted"); } void OnPlayFinished() { @@ -61,7 +65,7 @@ private: } void OnError(int32_t errorCode) { - MEDIA_INFO_LOG("StreamIDManager::SoundPoolCallBack OnError"); + MEDIA_LOGI("StreamIDManager::SoundPoolCallBack OnError"); } private: