已合并
AudioCapturer增加public内录接口 #13096
yangjcc创建于 2025年12月22日
AudioCapturer增加public内录接口 #13096
已合并
共 30 个文件变更+463-17
| @@ -84,6 +84,8 @@ public: | |||
| 84 | int32_t RegisterAudioPolicyServerDiedCb(const int32_t clientPid, | 84 | int32_t RegisterAudioPolicyServerDiedCb(const int32_t clientPid, |
| 85 | const std::shared_ptr<AudioCapturerPolicyServiceDiedCallback> &callback) override; | 85 | const std::shared_ptr<AudioCapturerPolicyServiceDiedCallback> &callback) override; |
| 86 | void SetFastStatusChangeCallback(const std::shared_ptr<AudioCapturerFastStatusChangeCallback> &callback) override; | 86 | void SetFastStatusChangeCallback(const std::shared_ptr<AudioCapturerFastStatusChangeCallback> &callback) override; |
| 87 | + void SetPlaybackCaptureStartStateCallback( | ||
| 88 | + const std::shared_ptr<AudioCapturerOnPlaybackCaptureStartCallback> &callback) override; | ||
| 87 | 89 | ||
| 88 | int32_t GetAudioTimestampInfo(Timestamp ×tamp, Timestamp::Timestampbase base) const override; | 90 | int32_t GetAudioTimestampInfo(Timestamp ×tamp, Timestamp::Timestampbase base) const override; |
| 89 | bool GetTimeStampInfo(Timestamp ×tampNs, Timestamp::Timestampbase base) const override; | 91 | bool GetTimeStampInfo(Timestamp ×tampNs, Timestamp::Timestampbase base) const override; |
| @@ -107,6 +109,7 @@ public: | |||
| 107 | 109 | ||
| 108 | void RestoreAudioInLoop(bool &restoreResult, int32_t &tryCounter); | 110 | void RestoreAudioInLoop(bool &restoreResult, int32_t &tryCounter); |
| 109 | void HandleSetCapturerInfoByOptions(const AudioCapturerOptions &capturerOptions, const AppInfo &appInfo); | 111 | void HandleSetCapturerInfoByOptions(const AudioCapturerOptions &capturerOptions, const AppInfo &appInfo); |
| 112 | + int32_t StartPlaybackCapture() override; | ||
| 110 | 113 | ||
| 111 | std::shared_ptr<IAudioStream> audioStream_; | 114 | std::shared_ptr<IAudioStream> audioStream_; |
| 112 | AudioCapturerInfo capturerInfo_ = {}; | 115 | AudioCapturerInfo capturerInfo_ = {}; |
| @@ -29,6 +29,7 @@ | |||
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | + | ||
| 32 | 33 | ||
| 33 | 34 | ||
| 34 | 35 | ||
| @@ -648,6 +649,14 @@ void AudioCapturerPrivate::SetFastStatusChangeCallback( | |||
| 648 | fastStatusChangeCallback_ = callback; | 649 | fastStatusChangeCallback_ = callback; |
| 649 | } | 650 | } |
| 650 | 651 | ||
| 652 | +void AudioCapturerPrivate::SetPlaybackCaptureStartStateCallback( | ||
| 653 | + const std::shared_ptr<AudioCapturerOnPlaybackCaptureStartCallback> &callback) | ||
| 654 | +{ | ||
| 655 | + std::shared_ptr<IAudioStream> currentStream = GetInnerStream(); | ||
| 656 | + CHECK_AND_RETURN_LOG(currentStream != nullptr, "audioStream_ is nullptr"); | ||
| 657 | + currentStream->SetPlaybackCaptureStartStateCallback(callback); | ||
| 658 | +} | ||
| 659 | + | ||
| 651 | int32_t AudioCapturerPrivate::GetParams(AudioCapturerParams ¶ms) const | 660 | int32_t AudioCapturerPrivate::GetParams(AudioCapturerParams ¶ms) const |
| 652 | { | 661 | { |
| 653 | std::shared_ptr<IAudioStream> currentStream = GetInnerStream(); | 662 | std::shared_ptr<IAudioStream> currentStream = GetInnerStream(); |
| @@ -2104,5 +2113,12 @@ int32_t AudioCapturerPrivate::HandleCreateFastStreamError(AudioStreamParams &aud | |||
| 2104 | callbackLoopTid_ = audioStream_->GetCallbackLoopTid(); | 2113 | callbackLoopTid_ = audioStream_->GetCallbackLoopTid(); |
| 2105 | return ret; | 2114 | return ret; |
| 2106 | } | 2115 | } |
| 2116 | + | ||
| 2117 | +int32_t AudioCapturerPrivate::StartPlaybackCapture() | ||
| 2118 | +{ | ||
| 2119 | + std::shared_ptr<IAudioStream> currentStream = GetInnerStream(); | ||
| 2120 | + CHECK_AND_RETURN_RET_LOG(currentStream != nullptr, ERROR_ILLEGAL_STATE, "audioStream_ is nullptr"); | ||
| 2121 | + return currentStream->RequestUserPrivacyAuthority(sessionID_); | ||
| 2122 | +} | ||
| 2107 | } // namespace AudioStandard | 2123 | } // namespace AudioStandard |
| 2108 | } // namespace OHOS | 2124 | } // namespace OHOS |
| @@ -66,6 +66,9 @@ public: | |||
| 66 | virtual ~FastAudioStream(); | 66 | virtual ~FastAudioStream(); |
| 67 | 67 | ||
| 68 | void SetClientID(int32_t clientPid, int32_t clientUid, uint32_t appTokenId, uint64_t fullTokenId) override; | 68 | void SetClientID(int32_t clientPid, int32_t clientUid, uint32_t appTokenId, uint64_t fullTokenId) override; |
| 69 | + int32_t RequestUserPrivacyAuthority(uint32_t sessionId) override; | ||
| 70 | + void SetPlaybackCaptureStartStateCallback( | ||
| 71 | + const std::shared_ptr<AudioCapturerOnPlaybackCaptureStartCallback> &callback) override; | ||
| 69 | 72 | ||
| 70 | int32_t UpdatePlaybackCaptureConfig(const AudioPlaybackCaptureConfig &config) override; | 73 | int32_t UpdatePlaybackCaptureConfig(const AudioPlaybackCaptureConfig &config) override; |
| 71 | void SetRendererInfo(const AudioRendererInfo &rendererInfo) override; | 74 | void SetRendererInfo(const AudioRendererInfo &rendererInfo) override; |
| @@ -190,6 +190,9 @@ public: | |||
| 190 | virtual int32_t SetPitch(float pitch) = 0; | 190 | virtual int32_t SetPitch(float pitch) = 0; |
| 191 | virtual float GetSpeed() = 0; | 191 | virtual float GetSpeed() = 0; |
| 192 | virtual int32_t SetRebuildFlag() { return 0; } | 192 | virtual int32_t SetRebuildFlag() { return 0; } |
| 193 | + virtual int32_t RequestUserPrivacyAuthority(uint32_t sessionId) = 0; | ||
| 194 | + virtual void SetPlaybackCaptureStartStateCallback( | ||
| 195 | + const std::shared_ptr<AudioCapturerOnPlaybackCaptureStartCallback> &callback) = 0; | ||
| 193 | virtual int32_t SetRenderTarget(RenderTarget target) { return ERR_NOT_SUPPORTED; } | 196 | virtual int32_t SetRenderTarget(RenderTarget target) { return ERR_NOT_SUPPORTED; } |
| 194 | virtual RenderTarget GetRenderTarget() { return NORMAL_PLAYBACK; } | 197 | virtual RenderTarget GetRenderTarget() { return NORMAL_PLAYBACK; } |
| 195 | virtual int32_t GetKeepRunning(bool &keepRunning) const { return -1; } | 198 | virtual int32_t GetKeepRunning(bool &keepRunning) const { return -1; } |
| @@ -22,6 +22,7 @@ | |||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | +static const int32_t START_RESULT_SUCCESS = 0; | ||
| 25 | 26 | ||
| 26 | using OHOS::AudioStandard::Timestamp; | 27 | using OHOS::AudioStandard::Timestamp; |
| 27 | 28 | ||
| @@ -50,6 +51,8 @@ OH_AudioStream_Result OH_AudioCapturer_Start(OH_AudioCapturer* capturer) | |||
| 50 | AUDIO_INFO_LOG("in"); | 51 | AUDIO_INFO_LOG("in"); |
| 51 | OHOS::AudioStandard::OHAudioCapturer *audioCapturer = convertCapturer(capturer); | 52 | OHOS::AudioStandard::OHAudioCapturer *audioCapturer = convertCapturer(capturer); |
| 52 | CHECK_AND_RETURN_RET_LOG(audioCapturer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert capturer failed"); | 53 | CHECK_AND_RETURN_RET_LOG(audioCapturer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert capturer failed"); |
| 54 | + CHECK_AND_RETURN_RET_LOG(audioCapturer->IsModernInnerCapturer() != true, AUDIOSTREAM_ERROR_ILLEGAL_STATE, | ||
| 55 | + "Innercapturer can not use this interface"); | ||
| 53 | if (audioCapturer->Start()) { | 56 | if (audioCapturer->Start()) { |
| 54 | return AUDIOSTREAM_SUCCESS; | 57 | return AUDIOSTREAM_SUCCESS; |
| 55 | } else { | 58 | } else { |
| @@ -57,6 +60,19 @@ OH_AudioStream_Result OH_AudioCapturer_Start(OH_AudioCapturer* capturer) | |||
| 57 | } | 60 | } |
| 58 | } | 61 | } |
| 59 | 62 | ||
| 63 | +OH_AudioStream_Result OH_AudioCapturer_RequestPlaybackCaptureStart(OH_AudioCapturer* capturer, | ||
| 64 | + OH_AudioCapturer_OnPlaybackCaptureStartCallback callback, void* userData) | ||
| 65 | +{ | ||
| 66 | + OHOS::AudioStandard::OHAudioCapturer *audioCapturer = convertCapturer(capturer); | ||
| 67 | + CHECK_AND_RETURN_RET_LOG(audioCapturer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert capturer failed"); | ||
| 68 | + int32_t startResult = audioCapturer->StartPlaybackCapture(capturer, callback, userData); | ||
| 69 | + if (startResult == START_RESULT_SUCCESS) { | ||
| 70 | + return AUDIOSTREAM_SUCCESS; | ||
| 71 | + } else { | ||
| 72 | + return AUDIOSTREAM_ERROR_ILLEGAL_STATE; | ||
| 73 | + } | ||
| 74 | +} | ||
| 75 | + | ||
| 60 | OH_AudioStream_Result OH_AudioCapturer_Pause(OH_AudioCapturer* capturer) | 76 | OH_AudioStream_Result OH_AudioCapturer_Pause(OH_AudioCapturer* capturer) |
| 61 | { | 77 | { |
| 62 | AUDIO_INFO_LOG("in"); | 78 | AUDIO_INFO_LOG("in"); |
| @@ -264,6 +280,7 @@ OHAudioCapturer::~OHAudioCapturer() | |||
| 264 | bool OHAudioCapturer::Initialize(const AudioCapturerOptions& capturerOptions) | 280 | bool OHAudioCapturer::Initialize(const AudioCapturerOptions& capturerOptions) |
| 265 | { | 281 | { |
| 266 | audioCapturer_ = AudioCapturer::CreateCapturer(capturerOptions); | 282 | audioCapturer_ = AudioCapturer::CreateCapturer(capturerOptions); |
| 283 | + isModernInnerCapturer_ = capturerOptions.playbackCaptureConfig.isModernInnerCapturer; | ||
| 267 | return audioCapturer_ != nullptr; | 284 | return audioCapturer_ != nullptr; |
| 268 | } | 285 | } |
| 269 | 286 | ||
| @@ -565,6 +582,20 @@ void OHAudioCapturerFastStatusChangeCallback::OnFastStatusChange(FastStatus stat | |||
| 565 | callback_(ohAudioCapturer_, userData_, static_cast<OH_AudioStream_FastStatus>(status)); | 582 | callback_(ohAudioCapturer_, userData_, static_cast<OH_AudioStream_FastStatus>(status)); |
| 566 | } | 583 | } |
| 567 | 584 | ||
| 585 | +void OHAudioCapturerOnPlaybackCaptureStartCallback::OnPlaybackCaptureStartResult( | ||
| 586 | + PlaybackCaptureStartState state) | ||
| 587 | +{ | ||
| 588 | + CHECK_AND_RETURN_LOG(ohAudioCapturer_ != nullptr, "capturer client is nullptr"); | ||
| 589 | + CHECK_AND_RETURN_LOG(callback_ != nullptr, "pointer to the function is nullptr"); | ||
| 590 | + | ||
| 591 | + callback_(ohAudioCapturer_, userData_, static_cast<OH_AudioStream_PlaybackCaptureStartState>(state)); | ||
| 592 | + if (state == START_STATE_SUCCESS) { | ||
| 593 | + OHOS::AudioStandard::OHAudioCapturer *audioCapturer = convertCapturer(ohAudioCapturer_); | ||
| 594 | + CHECK_AND_RETURN_LOG(audioCapturer != nullptr, "convert capturer failed"); | ||
| 595 | + audioCapturer->Start(); | ||
| 596 | + } | ||
| 597 | +} | ||
| 598 | + | ||
| 568 | void OHAudioCapturer::SetReadDataCallback(CapturerCallback capturerCallbacks, void* userData) | 599 | void OHAudioCapturer::SetReadDataCallback(CapturerCallback capturerCallbacks, void* userData) |
| 569 | { | 600 | { |
| 570 | if (readDataCallbackType_ == READ_DATA_CALLBACK_WITH_RESULT && | 601 | if (readDataCallbackType_ == READ_DATA_CALLBACK_WITH_RESULT && |
| @@ -691,5 +722,26 @@ void OHAudioCapturer::SetCapturerFastStatusChangeCallback(OH_AudioCapturer_OnFas | |||
| 691 | reinterpret_cast<OH_AudioCapturer*>(this), userData); | 722 | reinterpret_cast<OH_AudioCapturer*>(this), userData); |
| 692 | audioCapturer_->SetFastStatusChangeCallback(audioCapturerFastStatusChangeCallback_); | 723 | audioCapturer_->SetFastStatusChangeCallback(audioCapturerFastStatusChangeCallback_); |
| 693 | } | 724 | } |
| 725 | + | ||
| 726 | +int32_t OHAudioCapturer::StartPlaybackCapture(OH_AudioCapturer* capturer, | ||
| 727 | + OH_AudioCapturer_OnPlaybackCaptureStartCallback callback, void* userData) | ||
| 728 | +{ | ||
| 729 | + CHECK_AND_RETURN_RET_LOG(audioCapturer_ != nullptr, ERROR, "capturer client is nullptr"); | ||
| 730 | + CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERROR, "callback is nullptr"); | ||
| 731 | + capturerOnPlaybackCaptureStartCallback_ = std::make_shared<OHAudioCapturerOnPlaybackCaptureStartCallback> (callback, | ||
| 732 | + reinterpret_cast<OH_AudioCapturer*>(this), userData); | ||
| 733 | + audioCapturer_->SetPlaybackCaptureStartStateCallback(capturerOnPlaybackCaptureStartCallback_); | ||
| 734 | + | ||
| 735 | + return audioCapturer_->StartPlaybackCapture(); | ||
| 736 | +} | ||
| 737 | + | ||
| 738 | +bool OHAudioCapturer::IsModernInnerCapturer() | ||
| 739 | +{ | ||
| 740 | + CHECK_AND_RETURN_RET_LOG(audioCapturer_ != nullptr, false, "capturer client is nullptr"); | ||
| 741 | + AudioCapturerInfo capturerInfo; | ||
| 742 | + CHECK_AND_RETURN_RET(audioCapturer_->GetCapturerInfo(capturerInfo) == SUCCESS, false); | ||
| 743 | + CHECK_AND_RETURN_RET(capturerInfo.sourceType == SOURCE_TYPE_PLAYBACK_CAPTURE && isModernInnerCapturer_, false); | ||
| 744 | + return true; | ||
| 745 | +} | ||
| 694 | } // namespace AudioStandard | 746 | } // namespace AudioStandard |
| 695 | } // namespace OHOS | 747 | } // namespace OHOS |
| @@ -154,6 +154,21 @@ struct CapturerCallback { | |||
| 154 | OH_AudioCapturer_OnErrorCallback onErrorCallback = {}; | 154 | OH_AudioCapturer_OnErrorCallback onErrorCallback = {}; |
| 155 | }; | 155 | }; |
| 156 | 156 | ||
| 157 | +class OHAudioCapturerOnPlaybackCaptureStartCallback : public AudioCapturerOnPlaybackCaptureStartCallback { | ||
| 158 | +public: | ||
| 159 | + OHAudioCapturerOnPlaybackCaptureStartCallback(OH_AudioCapturer_OnPlaybackCaptureStartCallback callback, | ||
| 160 | + OH_AudioCapturer *audioCapturer, void *userData) | ||
| 161 | + : callback_(callback), ohAudioCapturer_(audioCapturer), userData_(userData) | ||
| 162 | + { | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + void OnPlaybackCaptureStartResult(PlaybackCaptureStartState state) override; | ||
| 166 | +private: | ||
| 167 | + OH_AudioCapturer_OnPlaybackCaptureStartCallback callback_; | ||
| 168 | + OH_AudioCapturer *ohAudioCapturer_; | ||
| 169 | + void *userData_; | ||
| 170 | +}; | ||
| 171 | + | ||
| 157 | class OHAudioCapturer { | 172 | class OHAudioCapturer { |
| 158 | public: | 173 | public: |
| 159 | OHAudioCapturer(); | 174 | OHAudioCapturer(); |
| @@ -199,6 +214,9 @@ public: | |||
| 199 | void SetCapturerWillMuteWhenInterrupted(InterruptStrategy strategy); | 214 | void SetCapturerWillMuteWhenInterrupted(InterruptStrategy strategy); |
| 200 | ReadDataCallbackType GetCapturerReadDataCallbackType(); | 215 | ReadDataCallbackType GetCapturerReadDataCallbackType(); |
| 201 | StreamEventCallbackType GetCapturerStreamEventCallbackType(); | 216 | StreamEventCallbackType GetCapturerStreamEventCallbackType(); |
| 217 | + int32_t StartPlaybackCapture(OH_AudioCapturer* capturer, | ||
| 218 | + OH_AudioCapturer_OnPlaybackCaptureStartCallback callback, void* userData); | ||
| 219 | + bool IsModernInnerCapturer(); | ||
| 202 | 220 | ||
| 203 | private: | 221 | private: |
| 204 | std::shared_ptr<AudioCapturer> audioCapturer_; | 222 | std::shared_ptr<AudioCapturer> audioCapturer_; |
| @@ -208,6 +226,8 @@ private: | |||
| 208 | ErrorCallbackType errorCallbackType_ = ERROR_CALLBACK_COMBINED; | 226 | ErrorCallbackType errorCallbackType_ = ERROR_CALLBACK_COMBINED; |
| 209 | InterruptEventCallbackType interruptCallbackType_ = INTERRUPT_EVENT_CALLBACK_COMBINED; | 227 | InterruptEventCallbackType interruptCallbackType_ = INTERRUPT_EVENT_CALLBACK_COMBINED; |
| 210 | std::shared_ptr<OHAudioCapturerFastStatusChangeCallback> audioCapturerFastStatusChangeCallback_; | 228 | std::shared_ptr<OHAudioCapturerFastStatusChangeCallback> audioCapturerFastStatusChangeCallback_; |
| 229 | + std::shared_ptr<OHAudioCapturerOnPlaybackCaptureStartCallback> capturerOnPlaybackCaptureStartCallback_ = nullptr; | ||
| 230 | + bool isModernInnerCapturer_ = false; | ||
| 211 | }; | 231 | }; |
| 212 | } // namespace AudioStandard | 232 | } // namespace AudioStandard |
| 213 | } // namespace OHOS | 233 | } // namespace OHOS |
| @@ -86,6 +86,22 @@ OH_AudioStream_Result OH_AudioStreamBuilder_SetEncodingType(OH_AudioStreamBuilde | |||
| 86 | return audioStreamBuilder->SetEncodingType(type); | 86 | return audioStreamBuilder->SetEncodingType(type); |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | +OH_AudioStream_Result OH_AudioStreamBuilder_SetPlaybackCaptureMode(OH_AudioStreamBuilder *builder, | ||
| 90 | + uint32_t mode) | ||
| 91 | +{ | ||
| 92 | + OHAudioStreamBuilder *audioStreamBuilder = convertBuilder(builder); | ||
| 93 | + CHECK_AND_RETURN_RET_LOG(audioStreamBuilder != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert builder failed"); | ||
| 94 | + | ||
| 95 | + if (mode != AUDIOSTREAM_PLAYBACKCAPTURE_MODE_DEFAULT && mode != AUDIOSTREAM_PLAYBACKCAPTURE_MODE_MEDIA && | ||
| 96 | + mode != AUDIOSTREAM_PLAYBACKCAPTURE_MODE_EXCLUDING_SELF && | ||
| 97 | + mode != (AUDIOSTREAM_PLAYBACKCAPTURE_MODE_EXCLUDING_SELF | AUDIOSTREAM_PLAYBACKCAPTURE_MODE_MEDIA)) { | ||
| 98 | + AUDIO_WARNING_LOG("Invalid param: playbackCapture mode:%{public}d", mode); | ||
| 99 | + return AUDIOSTREAM_ERROR_INVALID_PARAM; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + return audioStreamBuilder->SetPlaybackCaptureMode(mode); | ||
| 103 | +} | ||
| 104 | + | ||
| 89 | OH_AudioStream_Result OH_AudioStreamBuilder_SetLatencyMode(OH_AudioStreamBuilder *builder, | 105 | OH_AudioStream_Result OH_AudioStreamBuilder_SetLatencyMode(OH_AudioStreamBuilder *builder, |
| 90 | OH_AudioStream_LatencyMode latencyMode) | 106 | OH_AudioStream_LatencyMode latencyMode) |
| 91 | { | 107 | { |
| @@ -441,6 +457,12 @@ OH_AudioStream_Result OHAudioStreamBuilder::SetEncodingType(AudioEncodingType en | |||
| 441 | return AUDIOSTREAM_SUCCESS; | 457 | return AUDIOSTREAM_SUCCESS; |
| 442 | } | 458 | } |
| 443 | 459 | ||
| 460 | +OH_AudioStream_Result OHAudioStreamBuilder::SetPlaybackCaptureMode(uint32_t mode) | ||
| 461 | +{ | ||
| 462 | + playbackCaptureMode_ = mode; | ||
| 463 | + return AUDIOSTREAM_SUCCESS; | ||
| 464 | +} | ||
| 465 | + | ||
| 444 | OH_AudioStream_Result OHAudioStreamBuilder::SetSourceType(SourceType type) | 466 | OH_AudioStream_Result OHAudioStreamBuilder::SetSourceType(SourceType type) |
| 445 | { | 467 | { |
| 446 | CHECK_AND_RETURN_RET_LOG(streamType_ != RENDERER_TYPE && type != SOURCE_TYPE_INVALID, | 468 | CHECK_AND_RETURN_RET_LOG(streamType_ != RENDERER_TYPE && type != SOURCE_TYPE_INVALID, |
| @@ -545,6 +567,40 @@ void OHAudioStreamBuilder::ConfigureCapturer(OHAudioCapturer *audioCapturer) | |||
| 545 | capturerFastStatusChangeCallback_, capturerFastStatusChangeUserData_); | 567 | capturerFastStatusChangeCallback_, capturerFastStatusChangeUserData_); |
| 546 | } | 568 | } |
| 547 | 569 | ||
| 570 | +void OHAudioStreamBuilder::InitPlaybackCaptureConfig(AudioPlaybackCaptureConfig &config, | ||
| 571 | + uint32_t mode) | ||
| 572 | +{ | ||
| 573 | + std::vector<StreamUsage> &usages = config.filterOptions.usages; | ||
| 574 | + if (mode & AUDIOSTREAM_PLAYBACKCAPTURE_MODE_MEDIA) { | ||
| 575 | + config.isModernInnerCapturer = true; | ||
| 576 | + usages.push_back(AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN); | ||
| 577 | + usages.push_back(AudioStandard::StreamUsage::STREAM_USAGE_MEDIA); | ||
| 578 | + usages.push_back(AudioStandard::StreamUsage::STREAM_USAGE_MUSIC); | ||
| 579 | + usages.push_back(AudioStandard::StreamUsage::STREAM_USAGE_MOVIE); | ||
| 580 | + usages.push_back(AudioStandard::StreamUsage::STREAM_USAGE_GAME); | ||
| 581 | + usages.push_back(AudioStandard::StreamUsage::STREAM_USAGE_AUDIOBOOK); | ||
| 582 | + usages.push_back(AudioStandard::StreamUsage::STREAM_USAGE_VOICE_MESSAGE); | ||
| 583 | + } else { | ||
| 584 | + config.isModernInnerCapturer = true; | ||
| 585 | + usages.push_back(AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN); | ||
| 586 | + usages.push_back(AudioStandard::StreamUsage::STREAM_USAGE_MEDIA); | ||
| 587 | + usages.push_back(AudioStandard::StreamUsage::STREAM_USAGE_MUSIC); | ||
| 588 | + usages.push_back(AudioStandard::StreamUsage::STREAM_USAGE_MOVIE); | ||
| 589 | + usages.push_back(AudioStandard::StreamUsage::STREAM_USAGE_GAME); | ||
| 590 | + usages.push_back(AudioStandard::StreamUsage::STREAM_USAGE_AUDIOBOOK); | ||
| 591 | + usages.push_back(AudioStandard::StreamUsage::STREAM_USAGE_VOICE_MESSAGE); | ||
| 592 | + usages.push_back(AudioStandard::StreamUsage::STREAM_USAGE_NAVIGATION); | ||
| 593 | + usages.push_back(AudioStandard::StreamUsage::STREAM_USAGE_ALARM); | ||
| 594 | + usages.push_back(AudioStandard::StreamUsage::STREAM_USAGE_NOTIFICATION); | ||
| 595 | + usages.push_back(AudioStandard::StreamUsage::STREAM_USAGE_VOICE_ASSISTANT); | ||
| 596 | + } | ||
| 597 | + | ||
| 598 | + if (mode & AUDIOSTREAM_PLAYBACKCAPTURE_MODE_EXCLUDING_SELF) { | ||
| 599 | + config.filterOptions.pids.push_back(getpid()); | ||
| 600 | + config.filterOptions.pidFilterMode = FilterMode::EXCLUDE; | ||
| 601 | + } | ||
| 602 | +} | ||
| 603 | + | ||
| 548 | OH_AudioStream_Result OHAudioStreamBuilder::Generate(OH_AudioCapturer **capturer) | 604 | OH_AudioStream_Result OHAudioStreamBuilder::Generate(OH_AudioCapturer **capturer) |
| 549 | { | 605 | { |
| 550 | AUDIO_INFO_LOG("Generate OHAudioCapturer"); | 606 | AUDIO_INFO_LOG("Generate OHAudioCapturer"); |
| @@ -568,6 +624,10 @@ OH_AudioStream_Result OHAudioStreamBuilder::Generate(OH_AudioCapturer **capturer | |||
| 568 | capturerInfo | 624 | capturerInfo |
| 569 | }; | 625 | }; |
| 570 | 626 | ||
| 627 | + if (sourceType_ == SOURCE_TYPE_PLAYBACK_CAPTURE) { | ||
| 628 | + InitPlaybackCaptureConfig(options.playbackCaptureConfig, playbackCaptureMode_); | ||
| 629 | + } | ||
| 630 | + | ||
| 571 | OHAudioCapturer *audioCapturer = new OHAudioCapturer(); | 631 | OHAudioCapturer *audioCapturer = new OHAudioCapturer(); |
| 572 | if (audioCapturer->Initialize(options)) { | 632 | if (audioCapturer->Initialize(options)) { |
| 573 | ConfigureCapturer(audioCapturer); | 633 | ConfigureCapturer(audioCapturer); |
| @@ -41,6 +41,8 @@ public: | |||
| 41 | OH_AudioStream_Result SetLatencyMode(int32_t latencyMode); | 41 | OH_AudioStream_Result SetLatencyMode(int32_t latencyMode); |
| 42 | OH_AudioStream_Result SetChannelLayout(AudioChannelLayout channelLayout); | 42 | OH_AudioStream_Result SetChannelLayout(AudioChannelLayout channelLayout); |
| 43 | OH_AudioStream_Result SetRendererKeepRunning(bool keepRunning); | 43 | OH_AudioStream_Result SetRendererKeepRunning(bool keepRunning); |
| 44 | + OH_AudioStream_Result SetPlaybackCaptureMode(uint32_t mode); | ||
| 45 | + OH_AudioStream_Result StartPlaybackCapture(OH_AudioStream_PlaybackCaptureStartState stateCode); | ||
| 44 | 46 | ||
| 45 | OH_AudioStream_Result SetRendererInfo(StreamUsage usage); | 47 | OH_AudioStream_Result SetRendererInfo(StreamUsage usage); |
| 46 | OH_AudioStream_Result SetAudioVolumeMode(AudioVolumeMode volumeMode); | 48 | OH_AudioStream_Result SetAudioVolumeMode(AudioVolumeMode volumeMode); |
| @@ -79,6 +81,7 @@ private: | |||
| 79 | int32_t streamType_; | 81 | int32_t streamType_; |
| 80 | int32_t latencyMode_ = 0; // default value is normal mode | 82 | int32_t latencyMode_ = 0; // default value is normal mode |
| 81 | int32_t preferredFrameSize_ = -1; // undefined clientBufferSizeInFrame | 83 | int32_t preferredFrameSize_ = -1; // undefined clientBufferSizeInFrame |
| 84 | + uint32_t playbackCaptureMode_ = AUDIOSTREAM_PLAYBACKCAPTURE_MODE_DEFAULT; | ||
| 82 | 85 | ||
| 83 | // stream params | 86 | // stream params |
| 84 | int32_t samplingRate_ = SAMPLE_RATE_48000; | 87 | int32_t samplingRate_ = SAMPLE_RATE_48000; |
| @@ -134,6 +137,7 @@ private: | |||
| 134 | 137 | ||
| 135 | void ConfigureRenderer(OHAudioRenderer *audioRenderer); | 138 | void ConfigureRenderer(OHAudioRenderer *audioRenderer); |
| 136 | void ConfigureCapturer(OHAudioCapturer *audioCapturer); | 139 | void ConfigureCapturer(OHAudioCapturer *audioCapturer); |
| 140 | + void InitPlaybackCaptureConfig(AudioPlaybackCaptureConfig &config, uint32_t mode); | ||
| 137 | }; | 141 | }; |
| 138 | } // namespace AudioStandard | 142 | } // namespace AudioStandard |
| 139 | } // namespace OHOS | 143 | } // namespace OHOS |
| @@ -172,6 +172,19 @@ public: | |||
| 172 | virtual void OnFastStatusChange(FastStatus status) = 0; | 172 | virtual void OnFastStatusChange(FastStatus status) = 0; |
| 173 | }; | 173 | }; |
| 174 | 174 | ||
| 175 | +class AudioCapturerOnPlaybackCaptureStartCallback { | ||
| 176 | +public: | ||
| 177 | + virtual ~AudioCapturerOnPlaybackCaptureStartCallback() = default; | ||
| 178 | + | ||
| 179 | + /** | ||
| 180 | + * Called to notify internal recording started result. | ||
| 181 | + * | ||
| 182 | + * @param state Internal recording started result. | ||
| 183 | + * since 23 | ||
| 184 | + */ | ||
| 185 | + virtual void OnPlaybackCaptureStartResult(PlaybackCaptureStartState state) = 0; | ||
| 186 | +}; | ||
| 187 | + | ||
| 175 | /** | 188 | /** |
| 176 | * @brief Provides functions for applications to implement audio capturing. | 189 | * @brief Provides functions for applications to implement audio capturing. |
| 177 | */ | 190 | */ |
| @@ -315,6 +328,18 @@ public: | |||
| 315 | virtual void SetFastStatusChangeCallback( | 328 | virtual void SetFastStatusChangeCallback( |
| 316 | const std::shared_ptr<AudioCapturerFastStatusChangeCallback> &callback) = 0; | 329 | const std::shared_ptr<AudioCapturerFastStatusChangeCallback> &callback) = 0; |
| 317 | 330 | ||
| 331 | + /** | ||
| 332 | + * @brief Set the audio capturer playback capture start state callback listener | ||
| 333 | + * | ||
| 334 | + * @since 23 | ||
| 335 | + */ | ||
| 336 | + virtual void SetPlaybackCaptureStartStateCallback( | ||
| 337 | + const std::shared_ptr<AudioCapturerOnPlaybackCaptureStartCallback> &callback) | ||
| 338 | + { | ||
| 339 | + (void) callback; | ||
| 340 | + return; | ||
| 341 | + } | ||
| 342 | + | ||
| 318 | /** | 343 | /** |
| 319 | * @brief Obtains audio capturer parameters. | 344 | * @brief Obtains audio capturer parameters. |
| 320 | * | 345 | * |
| @@ -766,6 +791,11 @@ public: | |||
| 766 | return; | 791 | return; |
| 767 | } | 792 | } |
| 768 | 793 | ||
| 794 | + virtual int32_t StartPlaybackCapture() | ||
| 795 | + { | ||
| 796 | + return 0; | ||
| 797 | + } | ||
| 798 | + | ||
| 769 | protected: | 799 | protected: |
| 770 | static AudioStreamType FindStreamTypeBySourceType(SourceType sourceType); | 800 | static AudioStreamType FindStreamTypeBySourceType(SourceType sourceType); |
| 771 | 801 | ||
| @@ -999,6 +999,7 @@ inline constexpr uint32_t MAX_VALID_PIDS_SIZE = 128; // 128 for pids | |||
| 999 | struct AudioPlaybackCaptureConfig : public Parcelable { | 999 | struct AudioPlaybackCaptureConfig : public Parcelable { |
| 1000 | CaptureFilterOptions filterOptions; | 1000 | CaptureFilterOptions filterOptions; |
| 1001 | bool silentCapture {false}; // To be deprecated since 12 | 1001 | bool silentCapture {false}; // To be deprecated since 12 |
| 1002 | + bool isModernInnerCapturer = false; | ||
| 1002 | 1003 | ||
| 1003 | AudioPlaybackCaptureConfig() = default; | 1004 | AudioPlaybackCaptureConfig() = default; |
| 1004 | AudioPlaybackCaptureConfig(const CaptureFilterOptions &filter, const bool silent) | 1005 | AudioPlaybackCaptureConfig(const CaptureFilterOptions &filter, const bool silent) |
| @@ -1037,6 +1038,7 @@ struct AudioPlaybackCaptureConfig : public Parcelable { | |||
| 1037 | 1038 | ||
| 1038 | // silentCapture | 1039 | // silentCapture |
| 1039 | parcel.WriteBool(silentCapture); | 1040 | parcel.WriteBool(silentCapture); |
| 1041 | + parcel.WriteBool(isModernInnerCapturer); | ||
| 1040 | return true; | 1042 | return true; |
| 1041 | } | 1043 | } |
| 1042 | 1044 | ||
| @@ -1098,6 +1100,8 @@ struct AudioPlaybackCaptureConfig : public Parcelable { | |||
| 1098 | // silentCapture | 1100 | // silentCapture |
| 1099 | config->silentCapture = parcel.ReadBool(); | 1101 | config->silentCapture = parcel.ReadBool(); |
| 1100 | 1102 | ||
| 1103 | + config->isModernInnerCapturer = parcel.ReadBool(); | ||
| 1104 | + | ||
| 1101 | return config; | 1105 | return config; |
| 1102 | } | 1106 | } |
| 1103 | }; | 1107 | }; |
| @@ -1265,6 +1269,15 @@ enum FastStatus { | |||
| 1265 | FASTSTATUS_FAST | 1269 | FASTSTATUS_FAST |
| 1266 | }; | 1270 | }; |
| 1267 | 1271 | ||
| 1272 | +enum PlaybackCaptureStartState { | ||
| 1273 | + /* Internal recording started successfully. */ | ||
| 1274 | + START_STATE_SUCCESS = 0, | ||
| 1275 | + /* Start playback capture failed */ | ||
| 1276 | + START_STATE_FAILED = 1, | ||
| 1277 | + /* Start playback capture but user not authorized state. */ | ||
| 1278 | + START_STATE_NOT_AUTHORIZED = 2 | ||
| 1279 | +}; | ||
| 1280 | + | ||
| 1268 | struct StreamSwitchingInfo { | 1281 | struct StreamSwitchingInfo { |
| 1269 | bool isSwitching_ = false; | 1282 | bool isSwitching_ = false; |
| 1270 | State state_ = INVALID; | 1283 | State state_ = INVALID; |
| @@ -66,6 +66,18 @@ OH_AudioStream_Result OH_AudioCapturer_Release(OH_AudioCapturer* capturer); | |||
| 66 | */ | 66 | */ |
| 67 | OH_AudioStream_Result OH_AudioCapturer_Start(OH_AudioCapturer* capturer); | 67 | OH_AudioStream_Result OH_AudioCapturer_Start(OH_AudioCapturer* capturer); |
| 68 | 68 | ||
| 69 | +/** | ||
| 70 | + * @brief Callback function to get playback capture start result. | ||
| 71 | + * | ||
| 72 | + * @param capturer Pointer to the AudioCapturer instance that triggers the callback. | ||
| 73 | + * @param userData Pointer to the user data passed when setting the callback via | ||
| 74 | + * {@link #OH_AudioCapturer_RequestPlaybackCaptureStart}. | ||
| 75 | + * @param state The final state to describe whether start request is successful. | ||
| 76 | + * @since 23 | ||
| 77 | + */ | ||
| 78 | +typedef void (*OH_AudioCapturer_OnPlaybackCaptureStartCallback)(OH_AudioCapturer* capturer, void* userData, | ||
| 79 | + OH_AudioStream_PlaybackCaptureStartState stateCode); | ||
| 80 | + | ||
| 69 | /* | 81 | /* |
| 70 | * Request to pause the capturer stream. | 82 | * Request to pause the capturer stream. |
| 71 | * | 83 | * |
| @@ -346,6 +358,24 @@ typedef void (*OH_AudioCapturer_OnFastStatusChange)( | |||
| 346 | OH_AudioStream_FastStatus status | 358 | OH_AudioStream_FastStatus status |
| 347 | ); | 359 | ); |
| 348 | 360 | ||
| 361 | +/** | ||
| 362 | + * Asynchronously request to start the playback capture stream. | ||
| 363 | + * This function is non-blocking, which means system will continue to process user authorization and | ||
| 364 | + * stream starting when receiving the start request. And the final result will be returned by callback. | ||
| 365 | + * @param capturer reference created by {@link #OH_AudioStreamBuilder_GenerateCapturer} | ||
| 366 | + * @param callback Callback function used to receive the final result of start request. | ||
| 367 | + * @param userData Pointer to an application data structure that will be passed to the callback functions. | ||
| 368 | + * @return Function result code: | ||
| 369 | + * {@link #AUDIOSTREAM_SUCCESS} If the execution is successful. | ||
| 370 | + * {@link #AUDIOSTREAM_ERROR_INVALID_PARAM} The param of capturer is nullptr or callback is invalid. | ||
| 371 | + * {@link #AUDIOSTREAM_ERROR_ILLEGAL_STATE} Running and released are illegal states. | ||
| 372 | + * {@link #AUDIOSTREAM_ERROR_SYSTEM} System internal error, like audio service error. | ||
| 373 | + * @since 23 | ||
| 374 | + */ | ||
| 375 | + | ||
| 376 | +OH_AudioStream_Result OH_AudioCapturer_RequestPlaybackCaptureStart(OH_AudioCapturer* capturer, | ||
| 377 | + OH_AudioCapturer_OnPlaybackCaptureStartCallback callback, void* userData); | ||
| 378 | + | ||
| 349 | 379 | ||
| 350 | } | 380 | } |
| 351 | 381 | ||
| @@ -957,6 +957,47 @@ typedef enum { | |||
| 957 | AUDIOSTREAM_LATENCY_TYPE_HARDWARE = 2 | 957 | AUDIOSTREAM_LATENCY_TYPE_HARDWARE = 2 |
| 958 | } OH_AudioStream_LatencyType; | 958 | } OH_AudioStream_LatencyType; |
| 959 | 959 | ||
| 960 | +typedef enum { | ||
| 961 | + /** | ||
| 962 | + * default mode". | ||
| 963 | + * | ||
| 964 | + * @since 23 | ||
| 965 | + */ | ||
| 966 | + AUDIOSTREAM_PLAYBACKCAPTURE_MODE_DEFAULT = 0x0, | ||
| 967 | + /** | ||
| 968 | + * media mode. | ||
| 969 | + * | ||
| 970 | + * @since 23 | ||
| 971 | + */ | ||
| 972 | + AUDIOSTREAM_PLAYBACKCAPTURE_MODE_MEDIA = 0x1, | ||
| 973 | + /** | ||
| 974 | + * Self-exclusion mode. | ||
| 975 | + * | ||
| 976 | + * @since 23 | ||
| 977 | + */ | ||
| 978 | + AUDIOSTREAM_PLAYBACKCAPTURE_MODE_EXCLUDING_SELF = 0x8000, | ||
| 979 | +} OH_AudioStream_PlaybackCaptureMode; | ||
| 980 | + | ||
| 981 | +typedef enum { | ||
| 982 | + /** | ||
| 983 | + * Internal recording started successfully. | ||
| 984 | + * | ||
| 985 | + * @since 23 | ||
| 986 | + */ | ||
| 987 | + AUDIOSTREAM_PLAYBACKCAPTURE_START_STATE_SUCCESS = 0, | ||
| 988 | +/** | ||
| 989 | + * Start playback capture failed state, because the request for interrupt is denied | ||
| 990 | + * or meet system internal error. | ||
| 991 | + * @since 23 | ||
| 992 | + */ | ||
| 993 | + AUDIOSTREAM_PLAYBACKCAPTURE_START_STATE_FAILED = 1, | ||
| 994 | +/** | ||
| 995 | + * Start playback capture but user not authorized state. | ||
| 996 | + * @since 23 | ||
| 997 | + */ | ||
| 998 | + AUDIOSTREAM_PLAYBACKCAPTURE_START_STATE_NOT_AUTHORIZED = 2, | ||
| 999 | +} OH_AudioStream_PlaybackCaptureStartState; | ||
| 1000 | + | ||
| 960 | 1001 | ||
| 961 | } | 1002 | } |
| 962 | 1003 | ||
| @@ -475,6 +475,27 @@ OH_AudioStream_Result OH_AudioStreamBuilder_SetCapturerFastStatusChangeCallback( | |||
| 475 | */ | 475 | */ |
| 476 | OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererKeepRunning(OH_AudioStreamBuilder* builder, bool keepRunning); | 476 | OH_AudioStream_Result OH_AudioStreamBuilder_SetRendererKeepRunning(OH_AudioStreamBuilder* builder, bool keepRunning); |
| 477 | 477 | ||
| 478 | +/** | ||
| 479 | + * Sets target mode when using playback capture. Mode will decide what kind of streams to capture. | ||
| 480 | + * This function is only available for {@link #AUDIOSTREAM_TYPE_CAPTURER} type. | ||
| 481 | + * After setting playback capture mode, the {@link #OH_AudioStream_SourceType} will be ignored, so | ||
| 482 | + * caller do not need to use {@link #OH_AudioStreamBuilder_SetCapturerInfo} if you only want to capture | ||
| 483 | + * playback streams. | ||
| 484 | + * Note that playback capture is only available for specific system applications currently, others do | ||
| 485 | + * not have authorization. | ||
| 486 | + * | ||
| 487 | + * @param builder Reference provided by OH_AudioStreamBuilder_Create(). | ||
| 488 | + * @param mode The playback capture mode to set. This can be a combination of the available | ||
| 489 | + * {@link #OH_AudioStream_PlaybackCaptureMode}. | ||
| 490 | + * @return Function result code: | ||
| 491 | + * {@link #AUDIOSTREAM_SUCCESS} If the execution is successful. | ||
| 492 | + * {@link #AUDIOSTREAM_ERROR_INVALID_PARAM} 1.The param of builder is nullptr; | ||
| 493 | + * 2.The param of mode is invalid. | ||
| 494 | + * @since 23 | ||
| 495 | + */ | ||
| 496 | +OH_AudioStream_Result OH_AudioStreamBuilder_SetPlaybackCaptureMode(OH_AudioStreamBuilder* builder, | ||
| 497 | + uint32_t mode); | ||
| 498 | + | ||
| 478 | 499 | ||
| 479 | } | 500 | } |
| 480 | 501 | ||
| @@ -219,6 +219,9 @@ public: | |||
| 219 | bool GetStopFlag() const override; | 219 | bool GetStopFlag() const override; |
| 220 | bool IsRestoreNeeded() override; | 220 | bool IsRestoreNeeded() override; |
| 221 | int32_t SetRebuildFlag() override; | 221 | int32_t SetRebuildFlag() override; |
| 222 | + int32_t RequestUserPrivacyAuthority(uint32_t sessionId) override; | ||
| 223 | + void SetPlaybackCaptureStartStateCallback( | ||
| 224 | + const std::shared_ptr<AudioCapturerOnPlaybackCaptureStartCallback> &callback) override; | ||
| 222 | 225 | ||
| 223 | int32_t SetLoopTimes(int64_t bufferLoopTimes) override; | 226 | int32_t SetLoopTimes(int64_t bufferLoopTimes) override; |
| 224 | void SetStaticBufferInfo(StaticBufferInfo staticBufferInfo) override; | 227 | void SetStaticBufferInfo(StaticBufferInfo staticBufferInfo) override; |
| @@ -355,6 +358,8 @@ private: | |||
| 355 | 358 | ||
| 356 | bool paramsIsSet_ = false; | 359 | bool paramsIsSet_ = false; |
| 357 | int32_t innerCapId_ = 0; | 360 | int32_t innerCapId_ = 0; |
| 361 | + std::mutex playbackCaptureStartCallbackMutex_; | ||
| 362 | + std::shared_ptr<AudioCapturerOnPlaybackCaptureStartCallback> playbackCaptureStartCallback_ = nullptr; | ||
| 358 | 363 | ||
| 359 | std::string bundleName = ""; | 364 | std::string bundleName = ""; |
| 360 | 365 | ||
| @@ -378,6 +383,12 @@ private: | |||
| 378 | HANDLER_PARAM_RUNNING_FROM_SYSTEM, | 383 | HANDLER_PARAM_RUNNING_FROM_SYSTEM, |
| 379 | HANDLER_PARAM_PAUSED_FROM_SYSTEM, | 384 | HANDLER_PARAM_PAUSED_FROM_SYSTEM, |
| 380 | }; | 385 | }; |
| 386 | + | ||
| 387 | + enum :int32_t { | ||
| 388 | + AUDIOSTREAM_PLAYBACKCAPTURE_START_STATE_SUCCESS = 0, | ||
| 389 | + AUDIOSTREAM_PLAYBACKCAPTURE_START_STATE_FAILED, | ||
| 390 | + AUDIOSTREAM_PLAYBACKCAPTURE_START_STATE_NOT_AUTHORIZED, | ||
| 391 | + }; | ||
| 381 | }; | 392 | }; |
| 382 | } // namespace AudioStandard | 393 | } // namespace AudioStandard |
| 383 | } // namespace OHOS | 394 | } // namespace OHOS |
| @@ -59,6 +59,9 @@ public: | |||
| 59 | void SetClientID(int32_t clientPid, int32_t clientUid, uint32_t appTokenId, uint64_t fullTokenId) override; | 59 | void SetClientID(int32_t clientPid, int32_t clientUid, uint32_t appTokenId, uint64_t fullTokenId) override; |
| 60 | 60 | ||
| 61 | int32_t UpdatePlaybackCaptureConfig(const AudioPlaybackCaptureConfig &config) override; | 61 | int32_t UpdatePlaybackCaptureConfig(const AudioPlaybackCaptureConfig &config) override; |
| 62 | + int32_t RequestUserPrivacyAuthority(uint32_t sessionId) override; | ||
| 63 | + void SetPlaybackCaptureStartStateCallback( | ||
| 64 | + const std::shared_ptr<AudioCapturerOnPlaybackCaptureStartCallback> &callback) override; | ||
| 62 | void SetRendererInfo(const AudioRendererInfo &rendererInfo) override; | 65 | void SetRendererInfo(const AudioRendererInfo &rendererInfo) override; |
| 63 | void GetRendererInfo(AudioRendererInfo &rendererInfo) override; | 66 | void GetRendererInfo(AudioRendererInfo &rendererInfo) override; |
| 64 | void SetCapturerInfo(const AudioCapturerInfo &capturerInfo) override; | 67 | void SetCapturerInfo(const AudioCapturerInfo &capturerInfo) override; |
| @@ -1161,6 +1161,45 @@ bool CapturerInClientInner::StartAudioStream(StateChangeCmdType cmdType, AudioSt | |||
| 1161 | return true; | 1161 | return true; |
| 1162 | } | 1162 | } |
| 1163 | 1163 | ||
| 1164 | +void CapturerInClientInner::SetPlaybackCaptureStartStateCallback( | ||
| 1165 | + const std::shared_ptr<AudioCapturerOnPlaybackCaptureStartCallback> &callback) | ||
| 1166 | +{ | ||
| 1167 | + std::lock_guard<std::mutex> lock(playbackCaptureStartCallbackMutex_); | ||
| 1168 | + playbackCaptureStartCallback_ = callback; | ||
| 1169 | +} | ||
| 1170 | + | ||
| 1171 | +int32_t CapturerInClientInner::RequestUserPrivacyAuthority(uint32_t sessionId) | ||
| 1172 | +{ | ||
| 1173 | + CHECK_AND_RETURN_RET(playbackCaptureStartCallback_ != nullptr, ERROR); | ||
| 1174 | + sptr<IStandardAudioService> gasp = CapturerInClientInner::GetAudioServerProxy(); | ||
| 1175 | + if (gasp == nullptr) { | ||
| 1176 | + AUDIO_ERR_LOG("LatencyMeas failed to get AudioServerProxy"); | ||
| 1177 | + return ERROR; | ||
| 1178 | + } | ||
| 1179 | + gasp->RequestUserPrivacyAuthority(sessionId); | ||
| 1180 | + | ||
| 1181 | + std::unique_lock<std::mutex> waitLock(callServerMutex_); | ||
| 1182 | + bool stopWaiting = callServerCV_.wait_for(waitLock, std::chrono::milliseconds(OPERATION_TIMEOUT_IN_MS), [this] { | ||
| 1183 | + return notifiedOperation_ == USER_PRIVACY_AUTHORITY; // will be false when got notified. | ||
| 1184 | + }); | ||
| 1185 | + Operation operation = notifiedOperation_; | ||
| 1186 | + int64_t result = notifiedResult_; | ||
| 1187 | + waitLock.unlock(); | ||
| 1188 | + | ||
| 1189 | + std::unique_lock<std::mutex> lock(playbackCaptureStartCallbackMutex_); | ||
| 1190 | + if (operation != USER_PRIVACY_AUTHORITY) { | ||
| 1191 | + AUDIO_ERR_LOG("authorization failed: %{public}s Operation:%{public}d result:%{public}" PRId64".", | ||
| 1192 | + (!stopWaiting ? "timeout" : "no timeout"), operation, result); | ||
| 1193 | + playbackCaptureStartCallback_->OnPlaybackCaptureStartResult(START_STATE_FAILED); | ||
| 1194 | + return ERROR; | ||
| 1195 | + } | ||
| 1196 | + playbackCaptureStartCallback_->OnPlaybackCaptureStartResult( | ||
| 1197 | + static_cast<PlaybackCaptureStartState>(notifiedResult_)); | ||
| 1198 | + lock.unlock(); | ||
| 1199 | + | ||
| 1200 | + return SUCCESS; | ||
| 1201 | +} | ||
| 1202 | + | ||
| 1164 | bool CapturerInClientInner::PauseAudioStream(StateChangeCmdType cmdType) | 1203 | bool CapturerInClientInner::PauseAudioStream(StateChangeCmdType cmdType) |
| 1165 | { | 1204 | { |
| 1166 | Trace trace("CapturerInClientInner::PauseAudioStream " + std::to_string(sessionId_)); | 1205 | Trace trace("CapturerInClientInner::PauseAudioStream " + std::to_string(sessionId_)); |
| @@ -66,6 +66,18 @@ int32_t FastAudioStream::UpdatePlaybackCaptureConfig(const AudioPlaybackCaptureC | |||
| 66 | return ERR_NOT_SUPPORTED; | 66 | return ERR_NOT_SUPPORTED; |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | +void FastAudioStream::SetPlaybackCaptureStartStateCallback( | ||
| 70 | + const std::shared_ptr<AudioCapturerOnPlaybackCaptureStartCallback> &callback) | ||
| 71 | +{ | ||
| 72 | + return; | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +int32_t FastAudioStream::RequestUserPrivacyAuthority(uint32_t sessionId) | ||
| 76 | +{ | ||
| 77 | + AUDIO_ERR_LOG("Unsupported operation: RequestUserPrivacyAuthority"); | ||
| 78 | + return ERR_NOT_SUPPORTED; | ||
| 79 | +} | ||
| 80 | + | ||
| 69 | void FastAudioStream::SetRendererInfo(const AudioRendererInfo &rendererInfo) | 81 | void FastAudioStream::SetRendererInfo(const AudioRendererInfo &rendererInfo) |
| 70 | { | 82 | { |
| 71 | rendererInfo_ = rendererInfo; | 83 | rendererInfo_ = rendererInfo; |
| @@ -173,6 +173,18 @@ int32_t RendererInClientInner::UpdatePlaybackCaptureConfig(const AudioPlaybackCa | |||
| 173 | return ERR_NOT_SUPPORTED; | 173 | return ERR_NOT_SUPPORTED; |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | +void RendererInClientInner::SetPlaybackCaptureStartStateCallback( | ||
| 177 | + const std::shared_ptr<AudioCapturerOnPlaybackCaptureStartCallback> &callback) | ||
| 178 | +{ | ||
| 179 | + return; | ||
| 180 | +} | ||
| 181 | + | ||
| 182 | +int32_t RendererInClientInner::RequestUserPrivacyAuthority(uint32_t sessionId) | ||
| 183 | +{ | ||
| 184 | + AUDIO_ERR_LOG("Unsupported operation!"); | ||
| 185 | + return ERR_NOT_SUPPORTED; | ||
| 186 | +} | ||
| 187 | + | ||
| 176 | void RendererInClientInner::SetRendererInfo(const AudioRendererInfo &rendererInfo) | 188 | void RendererInClientInner::SetRendererInfo(const AudioRendererInfo &rendererInfo) |
| 177 | { | 189 | { |
| 178 | rendererInfo_ = rendererInfo; | 190 | rendererInfo_ = rendererInfo; |
| @@ -33,6 +33,7 @@ enum Operation : int32_t { | |||
| 33 | DATA_LINK_CONNECTING, // a2dp offload connecting | 33 | DATA_LINK_CONNECTING, // a2dp offload connecting |
| 34 | DATA_LINK_CONNECTED, | 34 | DATA_LINK_CONNECTED, |
| 35 | RESTORE_SESSION, | 35 | RESTORE_SESSION, |
| 36 | + USER_PRIVACY_AUTHORITY, | ||
| 36 | MAX_OPERATION_CODE // in plan add underrun overflow | 37 | MAX_OPERATION_CODE // in plan add underrun overflow |
| 37 | }; | 38 | }; |
| 38 | class IStreamListener { | 39 | class IStreamListener { |
| @@ -158,4 +158,5 @@ interface IStandardAudioService { | |||
| 158 | void RegistAdapterManagerCallback([in] IRemoteObject object, [in] String networkId); | 158 | void RegistAdapterManagerCallback([in] IRemoteObject object, [in] String networkId); |
| 159 | void UnRegistAdapterManagerCallback([in] String networkId); | 159 | void UnRegistAdapterManagerCallback([in] String networkId); |
| 160 | void GetRemoteAudioParameter([in] String networkId, [in] int key, [in] String condition, [out] String value); | 160 | void GetRemoteAudioParameter([in] String networkId, [in] int key, [in] String condition, [out] String value); |
| 161 | + [oneway] void RequestUserPrivacyAuthority([in] unsigned int sessionId); | ||
| 161 | } | 162 | } |
| @@ -85,6 +85,7 @@ | |||
| 85 | *GetPrivacyType*; | 85 | *GetPrivacyType*; |
| 86 | *GetEndPointByType*; | 86 | *GetEndPointByType*; |
| 87 | *SetEndpointMuteForSwitchDevice*; | 87 | *SetEndpointMuteForSwitchDevice*; |
| 88 | + *RequestUserPrivacyAuthority*; | ||
| 88 | local: | 89 | local: |
| 89 | *; | 90 | *; |
| 90 | }; | 91 | }; |
| @@ -292,6 +292,7 @@ public: | |||
| 292 | std::vector<std::shared_ptr<AudioOutputPipeInfo>> &pipeChangeInfos) override; | 292 | std::vector<std::shared_ptr<AudioOutputPipeInfo>> &pipeChangeInfos) override; |
| 293 | int32_t GetCurrentInputPipeChangeInfos( | 293 | int32_t GetCurrentInputPipeChangeInfos( |
| 294 | std::vector<std::shared_ptr<AudioInputPipeInfo>> &pipeChangeInfos) override; | 294 | std::vector<std::shared_ptr<AudioInputPipeInfo>> &pipeChangeInfos) override; |
| 295 | + int32_t RequestUserPrivacyAuthority(uint32_t sessionId) override; | ||
| 295 | 296 | ||
| 296 | int32_t RegistAdapterManagerCallback(const sptr<IRemoteObject>& object, const std::string& networkId) override; | 297 | int32_t RegistAdapterManagerCallback(const sptr<IRemoteObject>& object, const std::string& networkId) override; |
| 297 | int32_t UnRegistAdapterManagerCallback(const std::string& networkId) override; | 298 | int32_t UnRegistAdapterManagerCallback(const std::string& networkId) override; |
| @@ -383,8 +384,10 @@ private: | |||
| 383 | bool CheckVoiceCallRecorderPermission(Security::AccessToken::AccessTokenID tokenId); | 384 | bool CheckVoiceCallRecorderPermission(Security::AccessToken::AccessTokenID tokenId); |
| 384 | void RegisterSinkLatencyFetcher(uint32_t renderId); | 385 | void RegisterSinkLatencyFetcher(uint32_t renderId); |
| 385 | 386 | ||
| 386 | - void ResetRecordConfig(AudioProcessConfig &config); | 387 | + void ResetRecordConfig(AudioProcessConfig &config, |
| 387 | - AudioProcessConfig ResetProcessConfig(const AudioProcessConfig &config); | 388 | + const AudioPlaybackCaptureConfig &filterConfig); |
| 389 | + AudioProcessConfig ResetProcessConfig(const AudioProcessConfig &config, | ||
| 390 | + const AudioPlaybackCaptureConfig &filterConfig); | ||
| 388 | bool CheckStreamInfoFormat(const AudioProcessConfig &config); | 391 | bool CheckStreamInfoFormat(const AudioProcessConfig &config); |
| 389 | bool CheckRendererFormat(const AudioProcessConfig &config); | 392 | bool CheckRendererFormat(const AudioProcessConfig &config); |
| 390 | bool CheckRecorderFormat(const AudioProcessConfig &config); | 393 | bool CheckRecorderFormat(const AudioProcessConfig &config); |
| @@ -148,6 +148,7 @@ public: | |||
| 148 | void RenderersCheckForAudioWorkgroup(int32_t pid); | 148 | void RenderersCheckForAudioWorkgroup(int32_t pid); |
| 149 | int32_t GetPrivacyType(const uint32_t sessionId, AudioPrivacyType &privacyType); | 149 | int32_t GetPrivacyType(const uint32_t sessionId, AudioPrivacyType &privacyType); |
| 150 | void NotifyVoIPStart(SourceType sourceType, int32_t uid); | 150 | void NotifyVoIPStart(SourceType sourceType, int32_t uid); |
| 151 | + int32_t RequestUserPrivacyAuthority(uint32_t sessionId); | ||
| 151 | private: | 152 | private: |
| 152 | AudioService(); | 153 | AudioService(); |
| 153 | void DelayCallReleaseEndpoint(std::string endpointName); | 154 | void DelayCallReleaseEndpoint(std::string endpointName); |
| @@ -49,6 +49,7 @@ public: | |||
| 49 | 49 | ||
| 50 | int32_t GetAudioTime(uint64_t &framePos, uint64_t ×tamp); | 50 | int32_t GetAudioTime(uint64_t &framePos, uint64_t ×tamp); |
| 51 | int32_t GetLatency(uint64_t &latency); | 51 | int32_t GetLatency(uint64_t &latency); |
| 52 | + int32_t RequestUserPrivacyAuthority(); | ||
| 52 | 53 | ||
| 53 | int32_t Init(); | 54 | int32_t Init(); |
| 54 | 55 | ||
| @@ -135,6 +136,7 @@ private: | |||
| 135 | std::atomic<IStatus> lastStatus_ = I_STATUS_IDLE; | 136 | std::atomic<IStatus> lastStatus_ = I_STATUS_IDLE; |
| 136 | std::atomic<bool> lastOverflowStatus_ = false; | 137 | std::atomic<bool> lastOverflowStatus_ = false; |
| 137 | std::shared_ptr<AudioStreamChecker> audioStreamChecker_ = nullptr; | 138 | std::shared_ptr<AudioStreamChecker> audioStreamChecker_ = nullptr; |
| 139 | + bool hasRequestUserPrivacyAuthority_ = false; | ||
| 138 | }; | 140 | }; |
| 139 | } // namespace AudioStandard | 141 | } // namespace AudioStandard |
| 140 | } // namespace OHOS | 142 | } // namespace OHOS |
| @@ -1779,7 +1779,8 @@ int32_t AudioServer::GetHapBuildApiVersion(int32_t callerUid) | |||
| 1779 | return hapApiVersion; | 1779 | return hapApiVersion; |
| 1780 | } | 1780 | } |
| 1781 | 1781 | ||
| 1782 | -void AudioServer::ResetRecordConfig(AudioProcessConfig &config) | 1782 | +void AudioServer::ResetRecordConfig(AudioProcessConfig &config, |
| 1783 | + const AudioPlaybackCaptureConfig &filterConfig) | ||
| 1783 | { | 1784 | { |
| 1784 | if (config.capturerInfo.sourceType == SOURCE_TYPE_PLAYBACK_CAPTURE) { | 1785 | if (config.capturerInfo.sourceType == SOURCE_TYPE_PLAYBACK_CAPTURE) { |
| 1785 | config.isInnerCapturer = true; | 1786 | config.isInnerCapturer = true; |
| @@ -1787,7 +1788,8 @@ void AudioServer::ResetRecordConfig(AudioProcessConfig &config) | |||
| 1787 | if (PermissionUtil::VerifyPermission(CAPTURE_PLAYBACK_PERMISSION, IPCSkeleton::GetCallingTokenID())) { | 1788 | if (PermissionUtil::VerifyPermission(CAPTURE_PLAYBACK_PERMISSION, IPCSkeleton::GetCallingTokenID())) { |
| 1788 | AUDIO_INFO_LOG("CAPTURE_PLAYBACK permission granted"); | 1789 | AUDIO_INFO_LOG("CAPTURE_PLAYBACK permission granted"); |
| 1789 | config.innerCapMode = MODERN_INNER_CAP; | 1790 | config.innerCapMode = MODERN_INNER_CAP; |
| 1790 | - } else if (config.callerUid == MEDIA_SERVICE_UID || config.callerUid == VASSISTANT_UID) { | 1791 | + } else if (config.callerUid == MEDIA_SERVICE_UID || config.callerUid == VASSISTANT_UID || |
【严重】【安全】filterConfig由客户端可任意构造的数据反序列而来,也就是任意应用可通过设置该参数绕过系统 内录权限校验,有安全风险 ![]() ![]() | |||
| 1792 | + filterConfig.isModernInnerCapturer) { | ||
| 1791 | config.innerCapMode = MODERN_INNER_CAP; | 1793 | config.innerCapMode = MODERN_INNER_CAP; |
| 1792 | } else if (GetHapBuildApiVersion(config.callerUid) >= MODERN_INNER_API_VERSION) { // check build api-version | 1794 | } else if (GetHapBuildApiVersion(config.callerUid) >= MODERN_INNER_API_VERSION) { // check build api-version |
| 1793 | config.innerCapMode = LEGACY_MUTE_CAP; | 1795 | config.innerCapMode = LEGACY_MUTE_CAP; |
| @@ -1808,7 +1810,8 @@ void AudioServer::ResetRecordConfig(AudioProcessConfig &config) | |||
| 1808 | } | 1810 | } |
| 1809 | } | 1811 | } |
| 1810 | 1812 | ||
| 1811 | -AudioProcessConfig AudioServer::ResetProcessConfig(const AudioProcessConfig &config) | 1813 | +AudioProcessConfig AudioServer::ResetProcessConfig(const AudioProcessConfig &config, |
| 1814 | + const AudioPlaybackCaptureConfig &filterConfig) | ||
| 1812 | { | 1815 | { |
| 1813 | AudioProcessConfig resetConfig(config); | 1816 | AudioProcessConfig resetConfig(config); |
| 1814 | 1817 | ||
| @@ -1833,7 +1836,7 @@ AudioProcessConfig AudioServer::ResetProcessConfig(const AudioProcessConfig &con | |||
| 1833 | } | 1836 | } |
| 1834 | 1837 | ||
| 1835 | if (resetConfig.audioMode == AUDIO_MODE_RECORD) { | 1838 | if (resetConfig.audioMode == AUDIO_MODE_RECORD) { |
| 1836 | - ResetRecordConfig(resetConfig); | 1839 | + ResetRecordConfig(resetConfig, filterConfig); |
| 1837 | } | 1840 | } |
| 1838 | return resetConfig; | 1841 | return resetConfig; |
| 1839 | } | 1842 | } |
| @@ -2091,7 +2094,7 @@ sptr<IRemoteObject> AudioServer::CreateAudioProcessInner(const AudioProcessConfi | |||
| 2091 | errorCode = CheckAndWaitAudioPolicyReady(); | 2094 | errorCode = CheckAndWaitAudioPolicyReady(); |
| 2092 | CHECK_AND_RETURN_RET(errorCode == SUCCESS, nullptr); | 2095 | CHECK_AND_RETURN_RET(errorCode == SUCCESS, nullptr); |
| 2093 | 2096 | ||
| 2094 | - AudioProcessConfig resetConfig = ResetProcessConfig(config); | 2097 | + AudioProcessConfig resetConfig = ResetProcessConfig(config, filterConfig); |
| 2095 | CHECK_AND_CALL_RET_FUNC(CheckConfigFormat(resetConfig), nullptr, | 2098 | CHECK_AND_CALL_RET_FUNC(CheckConfigFormat(resetConfig), nullptr, |
| 2096 | HILOG_COMM_ERROR("[CreateAudioProcessInner]AudioProcessConfig format is wrong, please check" | 2099 | HILOG_COMM_ERROR("[CreateAudioProcessInner]AudioProcessConfig format is wrong, please check" |
| 2097 | ":%{public}s", ProcessConfig::DumpProcessConfig(resetConfig).c_str())); | 2100 | ":%{public}s", ProcessConfig::DumpProcessConfig(resetConfig).c_str())); |
| @@ -3460,7 +3463,11 @@ int32_t AudioServer::GetRemoteAudioParameter(const std::string& networkId, int32 | |||
| 3460 | return SUCCESS; | 3463 | return SUCCESS; |
| 3461 | } | 3464 | } |
| 3462 | 3465 | ||
| 3463 | - | 3466 | +int32_t AudioServer::RequestUserPrivacyAuthority(uint32_t sessionId) |
| 3467 | +{ | ||
| 3468 | + CHECK_AND_RETURN_RET_LOG(AudioService::GetInstance() != nullptr, ERR_INVALID_OPERATION, "AudioService is nullptr"); | ||
| 3469 | + return AudioService::GetInstance()->RequestUserPrivacyAuthority(sessionId); | ||
| 3470 | +} | ||
| 3464 | // LCOV_EXCL_STOP | 3471 | // LCOV_EXCL_STOP |
| 3465 | } // namespace AudioStandard | 3472 | } // namespace AudioStandard |
| 3466 | } // namespace OHOS | 3473 | } // namespace OHOS |
| @@ -1911,5 +1911,18 @@ void AudioService::NotifyVoIPStart(SourceType sourceType, int32_t uid) | |||
| 1911 | } | 1911 | } |
| 1912 | 1912 | ||
| 1913 | } | 1913 | } |
| 1914 | + | ||
| 1915 | +int32_t AudioService::RequestUserPrivacyAuthority(uint32_t sessionId) | ||
| 1916 | +{ | ||
| 1917 | + std::shared_ptr<CapturerInServer> capturerInServer = nullptr; | ||
| 1918 | + std::unique_lock<std::mutex> lock(capturerMapMutex_); | ||
| 1919 | + if (allCapturerMap_.count(sessionId)) { | ||
【严重】【入参校验】sessionId 为ipc反序列化数据而来,有仿冒风险:比如A应用仿冒有权限的B应用的sessionID来调用,会影响B的功能 ![]() ![]() | |||
| 1920 | + capturerInServer = allCapturerMap_[sessionId].lock(); | ||
| 1921 | + } | ||
| 1922 | + lock.unlock(); | ||
| 1923 | + CHECK_AND_RETURN_RET_LOG(capturerInServer != nullptr, ERROR, "sessionid not in allCapturerMap"); | ||
| 1924 | + | ||
| 1925 | + return capturerInServer->RequestUserPrivacyAuthority(); | ||
| 1926 | +} | ||
| 1914 | } // namespace AudioStandard | 1927 | } // namespace AudioStandard |
| 1915 | } // namespace OHOS | 1928 | } // namespace OHOS |
| @@ -37,6 +37,7 @@ | |||
| 37 | 37 | ||
| 38 | namespace OHOS { | 38 | namespace OHOS { |
| 39 | namespace AudioStandard { | 39 | namespace AudioStandard { |
| 40 | +const char* CAPTURE_SERVER_PLAYBACK_PERMISSION = "ohos.permission.CAPTURE_PLAYBACK"; | ||
| 40 | namespace { | 41 | namespace { |
| 41 | static constexpr int32_t VOLUME_SHIFT_NUMBER = 16; // 1 >> 16 = 65536, max volume | 42 | static constexpr int32_t VOLUME_SHIFT_NUMBER = 16; // 1 >> 16 = 65536, max volume |
| 42 | static const size_t CAPTURER_BUFFER_DEFAULT_NUM = 4; | 43 | static const size_t CAPTURER_BUFFER_DEFAULT_NUM = 4; |
| @@ -533,6 +534,9 @@ bool CapturerInServer::TurnOffMicIndicator(CapturerState capturerState) | |||
| 533 | 534 | ||
| 534 | int32_t CapturerInServer::Start() | 535 | int32_t CapturerInServer::Start() |
| 535 | { | 536 | { |
| 537 | + CHECK_AND_RETURN_RET_LOG(processConfig_.capturerInfo.sourceType != SOURCE_TYPE_PLAYBACK_CAPTURE || | ||
| 538 | + filterConfig_.isModernInnerCapturer == false || hasRequestUserPrivacyAuthority_ == true, | ||
| 539 | + ERR_INVALID_OPERATION, "New Innercapturer mode and not requestUserPrivacyAuthority"); | ||
| 536 | AudioXCollie audioXCollie( | 540 | AudioXCollie audioXCollie( |
| 537 | "CapturerInServer::Start", RELEASE_TIMEOUT_IN_SEC, nullptr, nullptr, | 541 | "CapturerInServer::Start", RELEASE_TIMEOUT_IN_SEC, nullptr, nullptr, |
| 538 | AUDIO_XCOLLIE_FLAG_LOG | AUDIO_XCOLLIE_FLAG_RECOVERY); | 542 | AUDIO_XCOLLIE_FLAG_LOG | AUDIO_XCOLLIE_FLAG_RECOVERY); |
| @@ -865,6 +869,27 @@ int32_t CapturerInServer::GetLatency(uint64_t &latency) | |||
| 865 | return stream_->GetLatency(latency); | 869 | return stream_->GetLatency(latency); |
| 866 | } | 870 | } |
| 867 | 871 | ||
| 872 | +int32_t CapturerInServer::RequestUserPrivacyAuthority() | ||
| 873 | +{ | ||
| 874 | + std::shared_ptr<IStreamListener> stateListener = streamListener_.lock(); | ||
| 875 | + CHECK_AND_RETURN_RET_LOG(stateListener != nullptr, ERR_OPERATION_FAILED, "IStreamListener is nullptr"); | ||
| 876 | + if (status_ == I_STATUS_STARTING || status_ == I_STATUS_STARTED) { | ||
| 877 | + stateListener->OnOperationHandled(USER_PRIVACY_AUTHORITY, START_STATE_FAILED); | ||
| 878 | + AUDIO_ERR_LOG("Inner capturer already start"); | ||
| 879 | + return SUCCESS; | ||
| 880 | + } | ||
| 881 | + if (PermissionUtil::VerifyPermission(CAPTURE_SERVER_PLAYBACK_PERMISSION, IPCSkeleton::GetCallingTokenID())) { | ||
| 882 | + hasRequestUserPrivacyAuthority_ = true; | ||
| 883 | + stateListener->OnOperationHandled(USER_PRIVACY_AUTHORITY, START_STATE_SUCCESS); | ||
| 884 | + AUDIO_INFO_LOG("request user privacy authority success"); | ||
| 885 | + } else { | ||
| 886 | + hasRequestUserPrivacyAuthority_ = false; | ||
| 887 | + stateListener->OnOperationHandled(USER_PRIVACY_AUTHORITY, START_STATE_NOT_AUTHORIZED); | ||
| 888 | + AUDIO_ERR_LOG("request user privacy authority failed"); | ||
| 889 | + } | ||
| 890 | + return SUCCESS; | ||
【一般】【条件分支】权限校验失败仍返回SUCCESS,不合理 ![]() ![]() | |||
| 891 | +} | ||
| 892 | + | ||
| 868 | int32_t CapturerInServer::InitCacheBuffer(size_t targetSize) | 893 | int32_t CapturerInServer::InitCacheBuffer(size_t targetSize) |
| 869 | { | 894 | { |
| 870 | CHECK_AND_RETURN_RET_LOG(spanSizeInBytes_ != 0, ERR_OPERATION_FAILED, "spanSizeInByte_ invalid"); | 895 | CHECK_AND_RETURN_RET_LOG(spanSizeInBytes_ != 0, ERR_OPERATION_FAILED, "spanSizeInByte_ invalid"); |
| @@ -576,11 +576,12 @@ HWTEST_F(AudioServerUnitTest, AudioServerCheckStreamInfoFormat_001, TestSize.Lev | |||
| 576 | audioServer->NotifyDeviceInfo(LOCAL_NETWORK_ID, false); | 576 | audioServer->NotifyDeviceInfo(LOCAL_NETWORK_ID, false); |
| 577 | audioServer->NotifyDeviceInfo("", true); | 577 | audioServer->NotifyDeviceInfo("", true); |
| 578 | audioServer->NotifyDeviceInfo("", false); | 578 | audioServer->NotifyDeviceInfo("", false); |
| 579 | + AudioPlaybackCaptureConfig filterConfig; | ||
| 579 | 580 | ||
| 580 | AudioProcessConfig config = {}; | 581 | AudioProcessConfig config = {}; |
| 581 | config.callerUid = AudioServer::MEDIA_SERVICE_UID; | 582 | config.callerUid = AudioServer::MEDIA_SERVICE_UID; |
| 582 | config.capturerInfo.sourceType = SourceType::SOURCE_TYPE_WAKEUP; | 583 | config.capturerInfo.sourceType = SourceType::SOURCE_TYPE_WAKEUP; |
| 583 | - audioServer->ResetRecordConfig(config); | 584 | + audioServer->ResetRecordConfig(config, filterConfig); |
| 584 | 585 | ||
| 585 | config.audioMode = AUDIO_MODE_RECORD; | 586 | config.audioMode = AUDIO_MODE_RECORD; |
| 586 | config.streamInfo.channels = CHANNEL_11; | 587 | config.streamInfo.channels = CHANNEL_11; |
| @@ -973,10 +974,11 @@ HWTEST_F(AudioServerUnitTest, AudioServerResetRecordConfig_001, TestSize.Level1) | |||
| 973 | { | 974 | { |
| 974 | EXPECT_NE(nullptr, audioServer); | 975 | EXPECT_NE(nullptr, audioServer); |
| 975 | AudioProcessConfig config; | 976 | AudioProcessConfig config; |
| 977 | + AudioPlaybackCaptureConfig filterConfig; | ||
| 976 | config.capturerInfo.sourceType = SOURCE_TYPE_PLAYBACK_CAPTURE; | 978 | config.capturerInfo.sourceType = SOURCE_TYPE_PLAYBACK_CAPTURE; |
| 977 | - audioServer->ResetRecordConfig(config); | 979 | + audioServer->ResetRecordConfig(config, filterConfig); |
| 978 | config.capturerInfo.sourceType = SOURCE_TYPE_WAKEUP; | 980 | config.capturerInfo.sourceType = SOURCE_TYPE_WAKEUP; |
| 979 | - audioServer->ResetRecordConfig(config); | 981 | + audioServer->ResetRecordConfig(config, filterConfig); |
| 980 | } | 982 | } |
| 981 | 983 | ||
| 982 | /** | 984 | /** |
| @@ -1835,9 +1837,10 @@ HWTEST_F(AudioServerUnitTest, ResetRecordConfig_001, TestSize.Level1) | |||
| 1835 | EXPECT_NE(nullptr, audioServer); | 1837 | EXPECT_NE(nullptr, audioServer); |
| 1836 | 1838 | ||
| 1837 | AudioProcessConfig config; | 1839 | AudioProcessConfig config; |
| 1840 | + AudioPlaybackCaptureConfig filterConfig; | ||
| 1838 | config.capturerInfo.sourceType = SourceType::SOURCE_TYPE_LIVE; | 1841 | config.capturerInfo.sourceType = SourceType::SOURCE_TYPE_LIVE; |
| 1839 | 1842 | ||
| 1840 | - audioServer->ResetRecordConfig(config); | 1843 | + audioServer->ResetRecordConfig(config, filterConfig); |
| 1841 | EXPECT_EQ(config.capturerInfo.sourceType, SOURCE_TYPE_LIVE); | 1844 | EXPECT_EQ(config.capturerInfo.sourceType, SOURCE_TYPE_LIVE); |
| 1842 | } | 1845 | } |
| 1843 | 1846 | ||
| @@ -1852,8 +1855,9 @@ HWTEST_F(AudioServerUnitTest, ResetRecordConfig_002, TestSize.Level1) | |||
| 1852 | EXPECT_NE(nullptr, audioServer); | 1855 | EXPECT_NE(nullptr, audioServer); |
| 1853 | 1856 | ||
| 1854 | AudioProcessConfig config; | 1857 | AudioProcessConfig config; |
| 1858 | + AudioPlaybackCaptureConfig filterConfig; | ||
| 1855 | config.capturerInfo.sourceType = SOURCE_TYPE_PLAYBACK_CAPTURE; | 1859 | config.capturerInfo.sourceType = SOURCE_TYPE_PLAYBACK_CAPTURE; |
| 1856 | - audioServer->ResetRecordConfig(config); | 1860 | + audioServer->ResetRecordConfig(config, filterConfig); |
| 1857 | EXPECT_EQ(config.isInnerCapturer, true); | 1861 | EXPECT_EQ(config.isInnerCapturer, true); |
| 1858 | } | 1862 | } |
| 1859 | 1863 | ||
| @@ -1352,15 +1352,17 @@ void AudioServerGetHapBuildApiVersionFuzzTest() | |||
| 1352 | void AudioServerResetRecordConfigFuzzTest() | 1352 | void AudioServerResetRecordConfigFuzzTest() |
| 1353 | { | 1353 | { |
| 1354 | AudioProcessConfig config; | 1354 | AudioProcessConfig config; |
| 1355 | + AudioPlaybackCaptureConfig filterConfig; | ||
| 1355 | sptr<AudioServer> audioServerPtr = sptr<AudioServer>::MakeSptr(SYSTEM_ABILITY_ID, RUN_ON_CREATE); | 1356 | sptr<AudioServer> audioServerPtr = sptr<AudioServer>::MakeSptr(SYSTEM_ABILITY_ID, RUN_ON_CREATE); |
| 1356 | - audioServerPtr->ResetRecordConfig(config); | 1357 | + audioServerPtr->ResetRecordConfig(config, filterConfig); |
| 1357 | } | 1358 | } |
| 1358 | 1359 | ||
| 1359 | void AudioServerResetProcessConfigFuzzTest() | 1360 | void AudioServerResetProcessConfigFuzzTest() |
| 1360 | { | 1361 | { |
| 1361 | AudioProcessConfig config; | 1362 | AudioProcessConfig config; |
| 1363 | + AudioPlaybackCaptureConfig filterConfig; | ||
| 1362 | sptr<AudioServer> audioServerPtr = sptr<AudioServer>::MakeSptr(SYSTEM_ABILITY_ID, RUN_ON_CREATE); | 1364 | sptr<AudioServer> audioServerPtr = sptr<AudioServer>::MakeSptr(SYSTEM_ABILITY_ID, RUN_ON_CREATE); |
| 1363 | - audioServerPtr->ResetProcessConfig(config); | 1365 | + audioServerPtr->ResetProcessConfig(config, filterConfig); |
| 1364 | } | 1366 | } |
| 1365 | 1367 | ||
| 1366 | void AudioServerCheckStreamInfoFormatFuzzTest() | 1368 | void AudioServerCheckStreamInfoFormatFuzzTest() |
| @@ -1746,6 +1748,7 @@ void AudioServerSetActiveOutputDeviceFuzzTest() | |||
| 1746 | void AudioServerResetRecordConfigSourceTypeFuzzTest() | 1748 | void AudioServerResetRecordConfigSourceTypeFuzzTest() |
| 1747 | { | 1749 | { |
| 1748 | AudioProcessConfig config; | 1750 | AudioProcessConfig config; |
| 1751 | + AudioPlaybackCaptureConfig filterConfig; | ||
| 1749 | FuzzedDataProvider provider(RAW_DATA, g_dataSize); | 1752 | FuzzedDataProvider provider(RAW_DATA, g_dataSize); |
| 1750 | sptr<AudioServer> audioServerPtr = sptr<AudioServer>::MakeSptr(SYSTEM_ABILITY_ID, RUN_ON_CREATE); | 1753 | sptr<AudioServer> audioServerPtr = sptr<AudioServer>::MakeSptr(SYSTEM_ABILITY_ID, RUN_ON_CREATE); |
| 1751 | CHECK_AND_RETURN(audioServerPtr != nullptr); | 1754 | CHECK_AND_RETURN(audioServerPtr != nullptr); |
| @@ -1753,17 +1756,18 @@ void AudioServerResetRecordConfigSourceTypeFuzzTest() | |||
| 1753 | return; | 1756 | return; |
| 1754 | } | 1757 | } |
| 1755 | config.capturerInfo.sourceType = g_sourceTypes[provider.ConsumeIntegral<int32_t>() % g_sourceTypes.size()]; | 1758 | config.capturerInfo.sourceType = g_sourceTypes[provider.ConsumeIntegral<int32_t>() % g_sourceTypes.size()]; |
| 1756 | - audioServerPtr->ResetRecordConfig(config); | 1759 | + audioServerPtr->ResetRecordConfig(config, filterConfig); |
| 1757 | } | 1760 | } |
| 1758 | 1761 | ||
| 1759 | void AudioServerResetProcessConfigCallerUidFuzzTest() | 1762 | void AudioServerResetProcessConfigCallerUidFuzzTest() |
| 1760 | { | 1763 | { |
| 1761 | AudioProcessConfig config; | 1764 | AudioProcessConfig config; |
| 1765 | + AudioPlaybackCaptureConfig filterConfig; | ||
| 1762 | sptr<AudioServer> audioServerPtr = sptr<AudioServer>::MakeSptr(SYSTEM_ABILITY_ID, RUN_ON_CREATE); | 1766 | sptr<AudioServer> audioServerPtr = sptr<AudioServer>::MakeSptr(SYSTEM_ABILITY_ID, RUN_ON_CREATE); |
| 1763 | CHECK_AND_RETURN(audioServerPtr != nullptr); | 1767 | CHECK_AND_RETURN(audioServerPtr != nullptr); |
| 1764 | FuzzedDataProvider provider(RAW_DATA, g_dataSize); | 1768 | FuzzedDataProvider provider(RAW_DATA, g_dataSize); |
| 1765 | config.callerUid = provider.ConsumeIntegral<int32_t>(); | 1769 | config.callerUid = provider.ConsumeIntegral<int32_t>(); |
| 1766 | - audioServerPtr->ResetProcessConfig(config); | 1770 | + audioServerPtr->ResetProcessConfig(config, filterConfig); |
| 1767 | } | 1771 | } |
| 1768 | 1772 | ||
| 1769 | void AudioServerCheckStreamInfoFormatNotContainFuzzTest() | 1773 | void AudioServerCheckStreamInfoFormatNotContainFuzzTest() |


【一般】【维测日志】此处需添加 mode打印info日志,记录应用设置入口处所设类型