diff --git a/frameworks/native/capi/screencapture/native_avscreen_capture.cpp b/frameworks/native/capi/screencapture/native_avscreen_capture.cpp index eaf888bd0f8761731bf002888cf5bc1392f7bc7d..6ac21bb3dbd5ba5ae2bc91f04a8edfcfbbc04a68 100644 --- a/frameworks/native/capi/screencapture/native_avscreen_capture.cpp +++ b/frameworks/native/capi/screencapture/native_avscreen_capture.cpp @@ -240,7 +240,7 @@ public: void OnStateChange(AVScreenCaptureStateCode stateCode) override { - MEDIA_LOGI("OnError() is called, stateCode %{public}d", stateCode); + MEDIA_LOGI("OnStateChange() is called, stateCode %{public}d", stateCode); std::shared_lock lock(mutex_); CHECK_AND_RETURN(capture_ != nullptr); diff --git a/services/services/screen_capture/server/audio_capturer_wrapper.cpp b/services/services/screen_capture/server/audio_capturer_wrapper.cpp index 9afc416732960c732eded10c28829aa8075a5726..4bf7b9cc767170812e8f5677c41df54ff8a7c9aa 100644 --- a/services/services/screen_capture/server/audio_capturer_wrapper.cpp +++ b/services/services/screen_capture/server/audio_capturer_wrapper.cpp @@ -105,17 +105,33 @@ void AudioCapturerWrapper::SetIsMuted(bool isMuted) isMuted_.store(isMuted); } -std::shared_ptr AudioCapturerWrapper::CreateAudioCapturer(const OHOS::AudioStandard::AppInfo &appInfo) +void AudioCapturerWrapper::SetInnerAudioStreamUsage(std::vector &usages) +{ + // If do not call this function, the audio framework use MUSIC/MOVIE/GAME/AUDIOBOOK + usages.push_back(OHOS::AudioStandard::StreamUsage::STREAM_USAGE_MUSIC); + usages.push_back(OHOS::AudioStandard::StreamUsage::STREAM_USAGE_ALARM); + usages.push_back(OHOS::AudioStandard::StreamUsage::STREAM_USAGE_NOTIFICATION); + usages.push_back(OHOS::AudioStandard::StreamUsage::STREAM_USAGE_MOVIE); + usages.push_back(OHOS::AudioStandard::StreamUsage::STREAM_USAGE_GAME); + usages.push_back(OHOS::AudioStandard::StreamUsage::STREAM_USAGE_AUDIOBOOK); + usages.push_back(OHOS::AudioStandard::StreamUsage::STREAM_USAGE_NAVIGATION); +} + +std::shared_ptr AudioCapturerWrapper::CreateAudioCapturer( + const OHOS::AudioStandard::AppInfo &appInfo) { AudioCapturerOptions capturerOptions; capturerOptions.streamInfo.samplingRate = static_cast(audioInfo_.audioSampleRate); capturerOptions.streamInfo.channels = static_cast(audioInfo_.audioChannels); capturerOptions.streamInfo.encoding = AudioEncodingType::ENCODING_PCM; capturerOptions.streamInfo.format = AudioSampleFormat::SAMPLE_S16LE; - if (audioInfo_.audioSource == AudioCaptureSourceType::MIC) { - capturerOptions.capturerInfo.sourceType = static_cast(0); // Audio Source Type Mic is 0 - } else { - capturerOptions.capturerInfo.sourceType = static_cast(audioInfo_.audioSource); + if (audioInfo_.audioSource == AudioCaptureSourceType::SOURCE_DEFAULT || + audioInfo_.audioSource == AudioCaptureSourceType::MIC) { + capturerOptions.capturerInfo.sourceType = SourceType::SOURCE_TYPE_MIC; // Audio Source Type Mic is 0 + } else if (audioInfo_.audioSource == AudioCaptureSourceType::ALL_PLAYBACK || + audioInfo_.audioSource == AudioCaptureSourceType::APP_PLAYBACK) { + capturerOptions.capturerInfo.sourceType = SourceType::SOURCE_TYPE_PLAYBACK_CAPTURE; + SetInnerAudioStreamUsage(capturerOptions.playbackCaptureConfig.filterOptions.usages); } capturerOptions.capturerInfo.capturerFlags = 0; std::shared_ptr audioCapturer = AudioCapturer::Create(capturerOptions, appInfo); diff --git a/services/services/screen_capture/server/audio_capturer_wrapper.h b/services/services/screen_capture/server/audio_capturer_wrapper.h index a4d3269851a1b684d6720a5e61b5cf9ff5b9e706..54c10719e477ae5612507b9a630a2cea56d1ceac 100644 --- a/services/services/screen_capture/server/audio_capturer_wrapper.h +++ b/services/services/screen_capture/server/audio_capturer_wrapper.h @@ -54,7 +54,9 @@ protected: virtual void OnStartFailed(ScreenCaptureErrorType errorType, int32_t errorCode); private: - std::shared_ptr CreateAudioCapturer(const OHOS::AudioStandard::AppInfo &appInfo); + std::shared_ptr CreateAudioCapturer( + const OHOS::AudioStandard::AppInfo &appInfo); + void SetInnerAudioStreamUsage(std::vector &usages); protected: std::shared_ptr screenCaptureCb_; @@ -66,8 +68,8 @@ private: AudioCaptureInfo audioInfo_; std::string threadName_; std::unique_ptr readAudioLoop_ = nullptr; - std::shared_ptr audioCapturer_ = nullptr; - std::shared_ptr audioCaptureCallback_ = nullptr; + std::shared_ptr audioCapturer_ = nullptr; + std::shared_ptr audioCaptureCallback_ = nullptr; std::mutex bufferMutex_; std::condition_variable bufferCond_; diff --git a/services/services/screen_capture/server/screen_capture_server.cpp b/services/services/screen_capture/server/screen_capture_server.cpp index 62b36f4dfe12a3525a354a7948409865792f7c5f..4b85649199f75f0f6ead50e1dbbedc3f10cdd079 100644 --- a/services/services/screen_capture/server/screen_capture_server.cpp +++ b/services/services/screen_capture/server/screen_capture_server.cpp @@ -1546,16 +1546,16 @@ void ScreenCaptureServer::Release() int32_t sessionId; { std::lock_guard lock(mutex_); + StopScreenCaptureInner(AVScreenCaptureStateCode::SCREEN_CAPTURE_STATE_INVLID); sessionId = sessionId_; sessionId_ = SESSION_ID_INVALID; + MEDIA_LOGI("0x%{public}06" PRIXPTR " Instances Release Stop done sessionId:%{public}d", sessionId, + FAKE_POINTER(this)); } { std::lock_guard lock(mutexGlobal); serverMap.erase(sessionId); } - - std::lock_guard lock(mutex_); - StopScreenCaptureInner(AVScreenCaptureStateCode::SCREEN_CAPTURE_STATE_INVLID); MEDIA_LOGI("0x%{public}06" PRIXPTR " Instances Release E", FAKE_POINTER(this)); }