diff --git a/audio_ohcore.gni b/audio_ohcore.gni deleted file mode 100644 index 917da899e6ca49770dfe7c7d13d63f42993556f1..0000000000000000000000000000000000000000 --- a/audio_ohcore.gni +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -audio_gateway_include_dirs = [] -audio_renderer_gateway_sources = [] -audio_renderer_gateway_deps = [] - -audio_capturer_gateway_sources = [] -audio_capturer_gateway_deps = [] diff --git a/bundle.json b/bundle.json index 17ae4f2221fff65c7d3b720fd682f2b49118afe2..7b7c631d06948f5bb64ea00f0f53429f05db0d72 100644 --- a/bundle.json +++ b/bundle.json @@ -85,8 +85,6 @@ "//foundation/multimedia/audio_framework/frameworks/js/napi:audio", "//foundation/multimedia/audio_framework/frameworks/native/ohaudio:ohaudio", "//foundation/multimedia/audio_framework/frameworks/native/opensles:opensles", - "//foundation/multimedia/audio_framework/frameworks/native/audiocompatibility:audio_renderer_gateway", - "//foundation/multimedia/audio_framework/frameworks/native/audiocompatibility:audio_capturer_gateway", "//foundation/multimedia/audio_framework/services/audio_service:audio_sasdk" ], "service_group": [ diff --git a/frameworks/native/audiocapturer/BUILD.gn b/frameworks/native/audiocapturer/BUILD.gn index a63bbad2e4aa9baaf4336524ddc83886b9808b7d..cec87a9baa675edee5159b08eb1a628f3d43c7fb 100644 --- a/frameworks/native/audiocapturer/BUILD.gn +++ b/frameworks/native/audiocapturer/BUILD.gn @@ -12,7 +12,6 @@ # limitations under the License. import("//build/ohos.gni") -import("../../../audio_ohcore.gni") import("../../../config.gni") pulseaudio_dir = "//third_party/pulseaudio" @@ -45,9 +44,7 @@ ohos_shared_library("audio_capturer") { configs = [ ":audio_capturer_config" ] - include_dirs = audio_gateway_include_dirs - - include_dirs += [ multimedia_audio_framework_pulse_audio ] + include_dirs = [ multimedia_audio_framework_pulse_audio ] sources = [ "src/audio_capturer.cpp", @@ -59,8 +56,6 @@ ohos_shared_library("audio_capturer") { "../../../services/audio_service:audio_client", ] - deps += audio_capturer_gateway_deps - public_configs = [ ":audio_external_library_config" ] external_deps = [ diff --git a/frameworks/native/audiocapturer/src/audio_capturer.cpp b/frameworks/native/audiocapturer/src/audio_capturer.cpp index 20e87f0d0b6a48ed3d0e1cd9655b8242afa08fe2..73b399eeb9e6b20cad35fff7c559b95b6fffa57e 100644 --- a/frameworks/native/audiocapturer/src/audio_capturer.cpp +++ b/frameworks/native/audiocapturer/src/audio_capturer.cpp @@ -19,9 +19,6 @@ #include "audio_capturer_private.h" #include "audio_errors.h" -#ifdef OHCORE -#include "audio_capturer_gateway.h" -#endif #include "audio_log.h" #include "audio_policy_manager.h" @@ -59,11 +56,7 @@ std::unique_ptr AudioCapturer::Create(AudioStreamType audioStream std::unique_ptr AudioCapturer::Create(AudioStreamType audioStreamType, const AppInfo &appInfo) { -#ifdef OHCORE - return std::make_unique(audioStreamType); -#else return std::make_unique(audioStreamType, appInfo, true); -#endif } std::unique_ptr AudioCapturer::Create(const AudioCapturerOptions &options) @@ -106,11 +99,8 @@ std::unique_ptr AudioCapturer::Create(const AudioCapturerOptions params.audioChannel = capturerOptions.streamInfo.channels; } params.audioEncoding = capturerOptions.streamInfo.encoding; -#ifdef OHCORE - auto capturer = std::make_unique(audioStreamType); -#else auto capturer = std::make_unique(audioStreamType, appInfo, false); -#endif + if (capturer == nullptr) { return capturer; } diff --git a/frameworks/native/audiocompatibility/BUILD.gn b/frameworks/native/audiocompatibility/BUILD.gn deleted file mode 100644 index baffbc6267fb35c17a91cba1b82e6d56a71c3ae8..0000000000000000000000000000000000000000 --- a/frameworks/native/audiocompatibility/BUILD.gn +++ /dev/null @@ -1,83 +0,0 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("../../../audio_ohcore.gni") -import("../../../config.gni") - -ohos_shared_library("audio_capturer_gateway") { - install_enable = true - - cflags = [ "-fPIC" ] - cflags += [ "-Wall" ] - cflags_cc = cflags - - include_dirs = [ - "../../../interfaces/inner_api/native/audiocommon/include", - "../../../interfaces/inner_api/native/audiocapturer/include", - ] - - include_dirs += audio_gateway_include_dirs - - sources = audio_capturer_gateway_sources - - deps = [ - "../../../services/audio_policy:audio_policy_client", - "../../../services/audio_service:audio_client", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] - - part_name = "audio_framework" - subsystem_name = "multimedia" -} - -ohos_shared_library("audio_renderer_gateway") { - install_enable = true - - cflags = [ "-fPIC" ] - cflags_cc = cflags - - include_dirs = [ - "../../../interfaces/inner_api/native/audiocommon/include", - "../../../interfaces/inner_api/native/audiorenderer/include", - ] - - include_dirs += audio_gateway_include_dirs - - sources = audio_renderer_gateway_sources - - deps = [ - "../../../services/audio_policy:audio_policy_client", - "../../../services/audio_service:audio_client", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] - - part_name = "audio_framework" - subsystem_name = "multimedia" -} diff --git a/frameworks/native/audiocompatibility/include/audio_capturer_gateway.h b/frameworks/native/audiocompatibility/include/audio_capturer_gateway.h deleted file mode 100644 index f826841167091b36a357d0f72482159dd7467dd9..0000000000000000000000000000000000000000 --- a/frameworks/native/audiocompatibility/include/audio_capturer_gateway.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef AUDIO_CAPTURER_GATEWAY_H -#define AUDIO_CAPTURER_GATEWAY_H - -#include "audio_stream.h" -#include "audio_container_stream_base.h" - -namespace OHOS { -namespace AudioStandard { -class AudioCapturerGateway : public AudioCapturer { -public: - - int32_t GetFrameCount(uint32_t &frameCount) const override; - int32_t SetParams(const AudioCapturerParams params) override; - int32_t SetCapturerCallback(const std::shared_ptr &callback) override; - int32_t GetParams(AudioCapturerParams ¶ms) const override; - int32_t GetCapturerInfo(AudioCapturerInfo &capturerInfo) const override; - int32_t GetStreamInfo(AudioStreamInfo &streamInfo) const override; - bool Start() const override; - int32_t Read(uint8_t &buffer, size_t userSize, bool isBlockingRead) const override; - CapturerState GetStatus() const override; - bool GetAudioTime(Timestamp ×tamp, Timestamp::Timestampbase base) const override; - bool Pause() const override; - bool Stop() const override; - bool Flush() const override; - bool Release() const override; - int32_t GetBufferSize(size_t &bufferSize) const override; - int32_t GetAudioStreamId(uint32_t &sessionID) const override; - int32_t SetCapturerPositionCallback(int64_t markPosition, - const std::shared_ptr &callback) override; - void UnsetCapturerPositionCallback() override; - int32_t SetCapturerPeriodPositionCallback(int64_t frameNumber, - const std::shared_ptr &callback) override; - void UnsetCapturerPeriodPositionCallback() override; - int32_t SetBufferDuration(uint64_t bufferDuration) const override; - int32_t SetCaptureMode(AudioCaptureMode capturerMode)const override; - AudioCaptureMode GetCaptureMode()const override; - int32_t SetCapturerReadCallback(const std::shared_ptr &callback) override; - int32_t GetBufferDesc(BufferDesc &bufDesc)const override; - int32_t Enqueue(const BufferDesc &bufDesc)const override; - int32_t Clear()const override; - int32_t GetBufQueueState(BufferQueueState &bufState)const override; - void SetApplicationCachePath(const std::string cachePath) override; - - AudioCapturerInfo capturerInfo_ = {}; - - explicit AudioCapturerGateway(AudioStreamType audioStreamType); - virtual ~AudioCapturerGateway(); - bool isChannelChange_ = false; - -private: - std::shared_ptr audioStream_; - std::shared_ptr audioStreamCallback_ = nullptr; -}; - -class AudioStreamCapturerCallback : public AudioStreamCallback { -public: - virtual ~AudioStreamCapturerCallback() = default; - - void OnStateChange(const State state, StateChangeCmdType cmdType = CMD_FROM_CLIENT) override; - void SaveCallback(const std::weak_ptr &callback); - -private: - std::weak_ptr callback_; -}; -} // namespace AudioStandard -} // namespace OHOS - -#endif // AUDIO_CAPTURER_GATEWAY_H \ No newline at end of file diff --git a/frameworks/native/audiocompatibility/include/audio_container_base.h b/frameworks/native/audiocompatibility/include/audio_container_base.h deleted file mode 100644 index 6a0376b7bb435ca594b892be1850d26325408c96..0000000000000000000000000000000000000000 --- a/frameworks/native/audiocompatibility/include/audio_container_base.h +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef AUDIO_CONTAINER_BASE_H -#define AUDIO_CONTAINER_BASE_H - -#include "audio_container_stream_callback.h" -#include "audio_stream_death_recipient.h" - -#include "audio_log.h" -#include "unistd.h" -#include "securec.h" - -namespace OHOS { -namespace AudioStandard { -class AudioContainerBase : public AudioTimer { -public: - /** - * Initializes audio service client for the required client type - * - * @param eClientType indicates the client type like playback, record or controller. - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t Initialize(ASClientType eClientType, int serviceId); - - // Stream handling APIs - - /** - * Creates & initializes resources based on the audioParams and audioType - * - * @param audioParams indicate format, sampling rate and number of channels - * @param audioType indicate the stream type like music, system, ringtone etc - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t CreateStream(AudioStreamParams audioParams, AudioStreamType audioType); - - /** - * @brief Obtains session ID . - * - * @return Returns unique session ID for the created session - */ - int32_t GetSessionID(uint32_t &sessionID, const int32_t &trackId) const; - - /** - * Starts the stream created using CreateStreamGa - * - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t StartStream(const int32_t &trackId); - - /** - * Stops the stream created using CreateStreamGa - * - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t StopStream(const int32_t &trackId); - - /** - * Flushes the stream created using CreateStreamGa. This is applicable for - * playback only - * - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t FlushStream(const int32_t &trackId); - - /** - * Drains the stream created using CreateStreamGa. This is applicable for - * playback only - * - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t DrainStream(const int32_t &trackId); - - /** - * Pauses the stream - * - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t PauseStream(const int32_t &trackId); - - /** - * Update the stream type - * - * @param audioStreamType Audio stream type - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t SetStreamType(AudioStreamType audioStreamType, const int32_t &trackId); - - /** - * Writes audio data of the stream created using CreateStreamGa to active sink device - * - * @param buffer contains audio data to write - * @param bufferSize indicates the size of audio data in bytes to write from the buffer - * @param pError indicates pointer to error which will be filled in case of internal errors - * @return returns size of audio data written in bytes. - */ - size_t WriteStream(const StreamBuffer &stream, int32_t &pError, const int32_t &trackId); - - /** - * Writes audio data of the stream created using CreateStreamGa to active sink device - Used when render mode is RENDER_MODE_CALLBACK - * - * @param buffer contains audio data to write - * @param bufferSize indicates the size of audio data in bytes to write from the buffer - * @param pError indicates pointer to error which will be filled in case of internal errors - * @return returns size of audio data written in bytes. - */ - size_t WriteStreamInCb(const StreamBuffer &stream, int32_t &pError, const int32_t &trackId); - - /** - * Reads audio data of the stream created using CreateStreamGa from active source device - * - * @param StreamBuffer including buffer to be filled with audio data - * and bufferSize indicating the size of audio data to read into buffer - * @param isBlocking indicates if the read is blocking or not - * @return Returns size read if success; returns {@code -1} failure. - */ - virtual int32_t ReadStream(StreamBuffer &stream, bool isBlocking, const int32_t &trackId); - - /** - * Release the resources allocated using CreateStreamGa - * - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t ReleaseStream(const int32_t &trackId); - - /** - * Provides the current timestamp for playback/record stream created using CreateStreamGa - * - * @param timestamp will be filled up with current timestamp - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t GetCurrentTimeStamp(uint64_t ×tamp, const int32_t &trackId); - - /** - * Provides the current latency for playback/record stream created using CreateStreamGa - * - * @param latency will be filled up with the current latency in microseconds - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t GetAudioLatency(uint64_t &latency, const int32_t &trackId) const; - - /** - * Provides the playback/record stream parameters created using CreateStreamGa - * - * @param audioParams will be filled up with stream audio parameters - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t GetAudioStreamParams(AudioStreamParams &audioParams, const int32_t &trackId); - - /** - * Provides the minimum buffer size required for this audio stream - * created using CreateStreamGa - * @param minBufferSize will be set to minimum buffer size in bytes - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t GetMinimumBufferSize(size_t &minBufferSize, const int32_t &trackId) const; - - /** - * Provides the minimum frame count required for this audio stream - * created using CreateStreamGa - * @param frameCount will be set to minimum number of frames - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t GetMinimumFrameCount(uint32_t &frameCount, const int32_t &trackId) const; - - /** - * @brief Set the track volume - * - * @param volume The volume to be set for the current track. - * @return Returns {@link SUCCESS} if volume is successfully set; returns an error code - * defined in {@link audio_errors.h} otherwise. - */ - int32_t SetStreamVolume(float volume, const int32_t &trackId); - - /** - * @brief Obtains the current track volume - * - * @return Returns current track volume - */ - float GetStreamVolume(); - - /** - * @brief Set the render rate - * - * @param renderRate The rate at which the stream needs to be rendered. - * @return Returns {@link SUCCESS} if render rate is successfully set; returns an error code - * defined in {@link audio_errors.h} otherwise. - */ - int32_t SetStreamRenderRate(AudioRendererRate renderRate, const int32_t &trackId); - - /** - * @brief Obtains the current render rate - * - * @return Returns current render rate - */ - AudioRendererRate GetStreamRenderRate(); - - /** - * @brief Saves StreamCallback - * - * @param callback callback reference to be saved. - * @return none. - */ - - void SaveStreamCallback(const std::weak_ptr &callback); - - /** - * @brief Sets the render mode. By default the mode is RENDER_MODE_NORMAL. - * This API is needs to be used only if RENDER_MODE_CALLBACK is required. - * - * * @param renderMode The mode of render. - * @return Returns {@link SUCCESS} if render mode is successfully set; returns an error code - * defined in {@link audio_errors.h} otherwise. - */ - int32_t SetAudioRenderMode(AudioRenderMode renderMode, const int32_t &trackId); - - /** - * @brief Obtains the render mode. - * - * @return Returns current render mode. - */ - AudioRenderMode GetAudioRenderMode(); - - /** - * @brief Set the buffer duration in msec - * - * @param bufferSizeInMsec buffer size in duration. - * @return Returns {@link SUCCESS} defined in {@link audio_errors.h} otherwise. - */ - int32_t SetBufferSizeInMsec(int32_t bufferSizeInMsec); - - /** - * Set the renderer frame position callback - * - * @param callback indicates pointer for registered callbacks - * @return none - */ - void SetRendererPositionCallback(int64_t markPosition, const std::shared_ptr &callback); - - /** - * Unset the renderer frame position callback - * - * @return none - */ - void UnsetRendererPositionCallback(); - - /** - * Set the renderer frame period position callback - * - * @param callback indicates pointer for registered callbacks - * @return none - */ - void SetRendererPeriodPositionCallback(int64_t markPosition, - const std::shared_ptr &callback); - - /** - * Unset the renderer frame period position callback - * - * @return none - */ - void UnsetRendererPeriodPositionCallback(); - - /** - * Set the capturer frame position callback - * - * @param callback indicates pointer for registered callbacks - * @return none - */ - void SetCapturerPositionCallback(int64_t markPosition, const std::shared_ptr &callback); - - /** - * Unset the capturer frame position callback - * - * @return none - */ - void UnsetCapturerPositionCallback(); - - /** - * Set the capturer frame period position callback - * - * @param callback indicates pointer for registered callbacks - * @return none - */ - void SetCapturerPeriodPositionCallback(int64_t markPosition, - const std::shared_ptr &callback); - - /** - * Unset the capturer frame period position callback - * - * @return none - */ - void UnsetCapturerPeriodPositionCallback(); - - // Audio timer callback - virtual void OnTimeOut(); - - int32_t SetAudioCaptureMode(AudioCaptureMode captureMode); - - int32_t SaveReadCallback(const std::weak_ptr &callback); - /** - * @brief Set the applicationcache path to access the application resources - * - * @return none - */ - void SetAppCachePath(const std::string cachePath); - - AudioCaptureMode GetAudioCaptureMode(); - - void InitAudioStreamManagerGa(int serviceId); - - /** - * @brief Registers the renderer write callback listener. - * This API should only be used if RENDER_MODE_CALLBACK is needed. - * - * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code - * defined in {@link audio_errors.h} otherwise. - */ - virtual int32_t SaveWriteCallback(const std::weak_ptr &callback, - const int32_t &trackId = 0); - - static void RegisterAudioStreamDeathRecipient(sptr &object); - -private: - static void AudioStreamDied(pid_t pid); -}; -} // namespace AudioStandard -} // namespace OHOS -#endif // AUDIO_CONTAINER_BASE_H \ No newline at end of file diff --git a/frameworks/native/audiocompatibility/include/audio_container_client_base.h b/frameworks/native/audiocompatibility/include/audio_container_client_base.h deleted file mode 100644 index 76f7a7e38b1e357dbe497ed92edd69afb010f951..0000000000000000000000000000000000000000 --- a/frameworks/native/audiocompatibility/include/audio_container_client_base.h +++ /dev/null @@ -1,461 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef AUDIO_STREAM_SERVICE_CLIENT_H -#define AUDIO_STREAM_SERVICE_CLIENT_H - -#include "audio_container_stream_callback.h" - -namespace OHOS { -namespace AudioStandard { -class AudioContainerClientBase : public IRemoteProxy { -public: - explicit AudioContainerClientBase(const sptr &impl); - virtual ~AudioContainerClientBase(); - - /** - * Initializes audio service client for the required client type - * - * @param eClientType indicates the client type like playback, record or controller. - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t InitializeGa(ASClientType eClientType) override; - - // Stream handling APIs - - /** - * Creates & initializes resources based on the audioParams and audioType - * - * @param audioParams indicate format, sampling rate and number of channels - * @param audioType indicate the stream type like music, system, ringtone etc - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t CreateStreamGa(AudioStreamParams audioParams, AudioStreamType audioType) override; - - /** - * @brief Obtains session ID . - * - * @return Returns unique session ID for the created session - */ - int32_t GetSessionIDGa(uint32_t &sessionID, const int32_t &trackId) override; - - /** - * Starts the stream created using CreateStreamGa - * - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t StartStreamGa(const int32_t &trackId) override; - - /** - * Stops the stream created using CreateStreamGa - * - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t StopStreamGa(const int32_t &trackId) override; - - /** - * Flushes the stream created using CreateStreamGa. This is applicable for - * playback only - * - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t FlushStreamGa(const int32_t &trackId) override; - - /** - * Drains the stream created using CreateStreamGa. This is applicable for - * playback only - * - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t DrainStreamGa(const int32_t &trackId) override; - - /** - * Pauses the stream - * - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t PauseStreamGa(const int32_t &trackId) override; - - /** - * Update the stream type - * - * @param audioStreamType Audio stream type - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t SetStreamTypeGa(AudioStreamType audioStreamType, const int32_t &trackId) override; - - /** - * Sets the volume of the stream associated with session ID - * - * @param sessionID indicates the ID for the active stream to be controlled - * @param volume indicates volume level between 0 to 65536 - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t SetStreamVolumeGa(uint32_t sessionID, uint32_t volume) override; - - /** - * Get the volume of the stream associated with session ID - * - * @param sessionID indicates the ID for the active stream to be controlled - * @return returns volume level between 0 to 65536 - */ - uint32_t GetStreamVolumeGa(uint32_t sessionID) override; - - /** - * Writes audio data of the stream created using CreateStreamGa to active sink device - * - * @param buffer contains audio data to write - * @param bufferSize indicates the size of audio data in bytes to write from the buffer - * @param pError indicates pointer to error which will be filled in case of internal errors - * @return returns size of audio data written in bytes. - */ - size_t WriteStreamGa(const StreamBuffer &stream, int32_t &pError, const int32_t &trackId) override; - - /** - * Writes audio data of the stream created using CreateStreamGa - * - * @param buffer contains audio data to write - * @param bufferSize indicates the size of audio data in bytes to write from the buffer - * @param pError indicates pointer to error which will be filled in case of internal errors - * @return returns size of audio data written in bytes. - */ - size_t WriteStreamInCbGa(const StreamBuffer &stream, int32_t &pError, const int32_t &trackId) override; - - /** - * Reads audio data of the stream created using CreateStreamGa from active source device - * - * @param StreamBuffer including buffer to be filled with audio data - * and bufferSize indicating the size of audio data to read into buffer - * @param isBlocking indicates if the read is blocking or not - * @return Returns size read if success; returns {@code -1} failure. - */ - int32_t ReadStreamGa(StreamBuffer &stream, bool isBlocking, const int32_t &trackId) override; - - /** - * Release the resources allocated using CreateStreamGa - * - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t ReleaseStreamGa(const int32_t &trackId) override; - - /** - * Provides the current timestamp for playback/record stream created using CreateStreamGa - * - * @param timestamp will be filled up with current timestamp - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t GetCurrentTimeStampGa(uint64_t ×tamp, const int32_t &trackId) override; - - /** - * Provides the current latency for playback/record stream created using CreateStreamGa - * - * @param latency will be filled up with the current latency in microseconds - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t GetAudioLatencyGa(uint64_t &latency, const int32_t &trackId) override; - - /** - * Provides the playback/record stream parameters created using CreateStreamGa - * - * @param audioParams will be filled up with stream audio parameters - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t GetAudioStreamParamsGa(AudioStreamParams &audioParams, const int32_t &trackId) override; - - /** - * Provides the minimum buffer size required for this audio stream - * created using CreateStreamGa - * @param minBufferSize will be set to minimum buffer size in bytes - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t GetMinimumBufferSizeGa(size_t &minBufferSize, const int32_t &trackId) override; - - /** - * Provides the minimum frame count required for this audio stream - * created using CreateStreamGa - * @param frameCount will be set to minimum number of frames - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - int32_t GetMinimumFrameCountGa(uint32_t &frameCount, const int32_t &trackId) override; - - /** - * @brief Set the buffer duration in msec - * - * @param bufferSizeInMsec buffer size in duration. - * @return Returns {@link SUCCESS} defined in {@link audio_errors.h} otherwise. - */ - int32_t SetBufferSizeInMsecGa(int32_t bufferSizeInMsec) override; - - /** - * Provides the sampling rate for the active audio stream - * created using CreateStreamGa - * - * @return Returns sampling rate in Hz - */ - uint32_t GetSamplingRateGa() const override; - - /** - * Provides the channel count for the active audio stream - * created using CreateStreamGa - * - * @return Returns number of channels - */ - uint8_t GetChannelCountGa() const override; - - /** - * Provides the sample size for the active audio stream - * created using CreateStreamGa - * - * @return Returns sample size in number of bits - */ - uint8_t GetSampleSizeGa() const override; - - // Device volume & route handling APIs - - // Audio stream callbacks - - /** - * Register for callbacks associated with the playback stream created using CreateStreamGa - * - * @param cb indicates pointer for registered callbacks - * @return none - */ - void RegisterAudioRendererCallbackGa(const AudioRendererCallback &cb) override; - - /** - * Register for callbacks associated with the record stream created using CreateStreamGa - * - * @param cb indicates pointer for registered callbacks - * @return none - */ - void RegisterAudioCapturerCallbackGa(const AudioCapturerCallback &cb) override; - - /** - * Set the renderer frame position callback - * - * @param callback indicates pointer for registered callbacks - * @return none - */ - void SetRendererPositionCallbackGa(int64_t markPosition, - const std::shared_ptr &callback) override; - - /** - * Unset the renderer frame position callback - * - * @return none - */ - void UnsetRendererPositionCallbackGa() override; - - /** - * Set the renderer frame period position callback - * - * @param callback indicates pointer for registered callbacks - * @return none - */ - void SetRendererPeriodPositionCallbackGa(int64_t markPosition, - const std::shared_ptr &callback) override; - - /** - * Unset the renderer frame period position callback - * - * @return none - */ - void UnsetRendererPeriodPositionCallbackGa() override; - - /** - * Set the capturer frame position callback - * - * @param callback indicates pointer for registered callbacks - * @return none - */ - void SetCapturerPositionCallbackGa(int64_t markPosition, - const std::shared_ptr &callback) override; - - /** - * Unset the capturer frame position callback - * - * @return none - */ - void UnsetCapturerPositionCallbackGa() override; - - /** - * Set the capturer frame period position callback - * - * @param callback indicates pointer for registered callbacks - * @return none - */ - void SetCapturerPeriodPositionCallbackGa(int64_t markPosition, - const std::shared_ptr &callback) override; - - /** - * Unset the capturer frame period position callback - * - * @return none - */ - void UnsetCapturerPeriodPositionCallbackGa() override; - - /** - * @brief Set the track volume - * - * @param volume The volume to be set for the current track. - * @return Returns {@link SUCCESS} if volume is successfully set; returns an error code - * defined in {@link audio_errors.h} otherwise. - */ - int32_t SetStreamVolumeGa(float volume, const int32_t &trackId) override; - - /** - * @brief Obtains the current track volume - * - * @return Returns current track volume - */ - float GetStreamVolumeGa() override; - - /** - * @brief Set the render rate - * - * @param renderRate The rate at which the stream needs to be rendered. - * @return Returns {@link SUCCESS} if render rate is successfully set; returns an error code - * defined in {@link audio_errors.h} otherwise. - */ - int32_t SetStreamRenderRateGa(AudioRendererRate renderRate, const int32_t &trackId) override; - - /** - * @brief Obtains the current render rate - * - * @return Returns current render rate - */ - AudioRendererRate GetStreamRenderRateGa() override; - - /** - * @brief Saves StreamCallback - * - * @param callback callback reference to be saved. - * @return none. - */ - - void SaveStreamCallbackGa(const std::weak_ptr &callback) override; - - /** - * @brief Sets the render mode. By default the mode is RENDER_MODE_NORMAL. - * This API is needs to be used only if RENDER_MODE_CALLBACK is required. - * - * * @param renderMode The mode of render. - * @return Returns {@link SUCCESS} if render mode is successfully set; returns an error code - * defined in {@link audio_errors.h} otherwise. - */ - int32_t SetAudioRenderModeGa(AudioRenderMode renderMode, const int32_t &trackId) override; - - /** - * @brief Obtains the render mode. - * - * @return Returns current render mode. - */ - AudioRenderMode GetAudioRenderModeGa() override; - - /** - * @brief Registers the renderer write callback listener. - * This API should only be used if RENDER_MODE_CALLBACK is needed. - * - * @return Returns {@link SUCCESS} if callback registration is successful; returns an error code - * defined in {@link audio_errors.h} otherwise. - */ - int32_t SaveWriteCallbackGa(const std::weak_ptr &callback, - const int32_t &trackId = 0) override; - - int32_t SetAudioCaptureMode(AudioCaptureMode captureMode) override; - - int32_t SaveReadCallback(const std::weak_ptr &callback) override; - /** - * @brief Set the applicationcache path to access the application resources - * - * @return none - */ - void SetAppCachePath(const std::string cachePath) override; - - AudioCaptureMode GetAudioCaptureMode() override; - - std::mutex dataMutex_; - std::mutex ctrlMutex_; - - int32_t audioTrackId = 0; - - const void *internalReadBuffer_; - size_t internalRdBufLen_; - size_t internalRdBufIndex_; - - float mVolumeFactor; - AudioStreamType mStreamType; - AudioSystemManager *mAudioSystemMgr; - - AudioRendererRate renderRate; - AudioRenderMode renderMode_; - std::weak_ptr writeCallback_; - - uint32_t mFrameSize = 0; - bool mMarkReached = false; - uint64_t mFrameMarkPosition = 0; - uint64_t mFramePeriodNumber = 0; - - uint64_t mTotalBytesWritten = 0; - uint64_t mFramePeriodWritten = 0; - std::shared_ptr mRenderPositionCb; - std::shared_ptr mRenderPeriodPositionCb; - - uint64_t mTotalBytesRead = 0; - uint64_t mFramePeriodRead = 0; - std::shared_ptr mCapturePositionCb; - std::shared_ptr mCapturePeriodPositionCb; - - std::vector> mPositionCBThreads; - std::vector> mPeriodPositionCBThreads; - - std::weak_ptr streamCallback_; - State state_; - - // To be set while using audio stream - // functionality for callbacks - AudioRendererCallback *mAudioRendererCallbacks; - AudioCapturerCallback *mAudioCapturerCallbacks; - - ASClientType eAudioClientType; - - // These APIs are applicable only for playback scenarios - void InitializeClientGa(); - int32_t InitializeAudioCacheGa(); - - int32_t UpdateReadBufferGa(uint8_t *buffer, size_t &length, size_t &readSize); - int32_t WriteStreamInnerGa(const uint8_t *buffer, size_t &length, const int32_t &trackId); - void HandleRenderPositionCallbacksGa(size_t bytesWritten); - void HandleCapturePositionCallbacksGa(size_t bytesRead); - - // Default values - static const uint32_t MINIMUM_BUFFER_SIZE = 1024; - static const uint32_t DEFAULT_SAMPLING_RATE = 44100; - static const uint8_t DEFAULT_CHANNEL_COUNT = 2; - static const uint8_t DEFAULT_SAMPLE_SIZE = 2; - static const uint32_t DEFAULT_STREAM_VOLUME = 65536; - static const std::string GetStreamNameGa(AudioStreamType audioType); - - static constexpr float MAX_STREAM_VOLUME_LEVEL = 1.0f; - static constexpr float MIN_STREAM_VOLUME_LEVEL = 0.0f; - - // Resets PA audio client and free up resources if any with this API - void ResetPAAudioClientGa(); - - static inline BrokerDelegator delegator_; -}; -} // namespace AudioStandard -} // namespace OHOS -#endif // AUDIO_STREAM_SERVICE_CLIENT_H \ No newline at end of file diff --git a/frameworks/native/audiocompatibility/include/audio_container_stream_base.h b/frameworks/native/audiocompatibility/include/audio_container_stream_base.h deleted file mode 100644 index c390858e416d063f2df06b7a12dcf1a40c737be3..0000000000000000000000000000000000000000 --- a/frameworks/native/audiocompatibility/include/audio_container_stream_base.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef AUDIO_CONTAINER_STREAM_BASE_H -#define AUDIO_CONTAINER_STREAM_BASE_H - -#include "audio_container_base.h" -#include "audio_renderer.h" -#include "timestamp.h" - -namespace OHOS { -namespace AudioStandard { -static constexpr int32_t MAX_LEN_BUFFERS = 3; - -class AudioContainerStreamBase : public AudioContainerBase { -public: - AudioContainerStreamBase(AudioStreamType eStreamType, AudioMode eMode); - virtual ~AudioContainerStreamBase(); - - int32_t SetAudioStreamInfo(const AudioStreamParams info); - int32_t GetAudioStreamInfo(AudioStreamParams &info); - bool VerifyClientPermission(const std::string &permissionName, uint32_t appTokenId, int32_t appUid, - AudioPermissionState state); - - int32_t GetAudioSessionID(uint32_t &sessionID) const; - State GetState(); - bool GetAudioTime(Timestamp ×tamp, Timestamp::Timestampbase base); - int32_t GetBufferSize(size_t &bufferSize) const; - int32_t GetFrameCount(uint32_t &frameCount) const; - int32_t GetLatency(uint64_t &latency) const; - static AudioStreamType GetStreamType(ContentType contentType, StreamUsage streamUsage); - int32_t SetAudioStreamType(AudioStreamType audioStreamType); - int32_t SetVolume(float volume); - float GetVolume(); - int32_t SetRenderRate(AudioRendererRate renderRate); - AudioRendererRate GetRenderRate(); - int32_t SetStreamCallback(const std::shared_ptr &callback); - int32_t SetRenderMode(AudioRenderMode renderMode); - AudioRenderMode GetRenderMode(); - int32_t SetRendererWriteCallback(const std::shared_ptr &callback); - int32_t SetCaptureMode(AudioCaptureMode captureMode); - AudioCaptureMode GetCaptureMode(); - int32_t SetCapturerReadCallback(const std::shared_ptr &callback); - virtual int32_t GetBufferDesc(BufferDesc &bufDesc); - virtual int32_t GetBufQueueState(BufferQueueState &bufState); - virtual int32_t Enqueue(const BufferDesc &bufDesc); - virtual int32_t Clear(); - - std::vector GetSupportedFormats() const; - std::vector GetSupportedEncodingTypes() const; - std::vector GetSupportedSamplingRates() const; - - // Common APIs - virtual bool StartAudioStream(); - bool PauseAudioStream(); - virtual bool StopAudioStream(); - bool ReleaseAudioStream(); - bool FlushAudioStream(); - - // Playback related APIs - bool DrainAudioStream(); - int32_t Write(uint8_t *buffer, size_t buffer_size); - - // Recording related APIs - int32_t Read(uint8_t &buffer, size_t userSize, bool isBlockingRead); - - void SetApplicationCachePath(const std::string cachePath); - - int32_t trackId_ = 0; - AudioStreamType eStreamType_; - AudioMode eMode_; - State state_; - std::atomic isReadInProgress_; - std::atomic isWriteInProgress_; - bool resetTime_; - uint64_t resetTimestamp_; - struct timespec baseTimestamp_ = {0, 0}; - AudioRenderMode renderMode_; - AudioCaptureMode captureMode_; - std::queue freeBufferQ_; - std::queue filledBufferQ_; - std::array, MAX_LEN_BUFFERS> bufferPool_ = {}; - std::unique_ptr writeThread_ = nullptr; - std::unique_ptr readThread_ = nullptr; - bool isReadyToWrite_; - bool isReadyToRead_; - void WriteBuffers(); - void ReadBuffers(); - - static const std::map, AudioStreamType> streamTypeMap_; - static std::map, AudioStreamType> CreateStreamMap(); - bool isFirstRead_; - int32_t sample_rate_ = 0; - int32_t format_ = 0; - int32_t channelCount_ = 0; - std::shared_ptr callback_; - pthread_cond_t writeCondition_ = PTHREAD_MUTEX_INITIALIZER; - pthread_mutex_t writeLock_ = PTHREAD_COND_INITIALIZER; - std::mutex mBufferQueueLock; - AudioRendererRate renderRate_ = RENDER_RATE_NORMAL; -}; - -class AudioContainerCaptureStream : public AudioContainerStreamBase { -public: - AudioContainerCaptureStream(AudioStreamType eStreamType, AudioMode eMode); - virtual ~AudioContainerCaptureStream(); - bool StartAudioStream() override; - bool StopAudioStream() override; - int32_t GetBufferDesc(BufferDesc &bufDesc) override; - int32_t GetBufQueueState(BufferQueueState &bufState) override; - int32_t Enqueue(const BufferDesc &bufDesc) override; - int32_t Clear() override; -}; - -class AudioContainerRenderStream : public AudioContainerStreamBase { -public: - AudioContainerRenderStream(AudioStreamType eStreamType, AudioMode eMode); - virtual ~AudioContainerRenderStream(); - bool StartAudioStream() override; - bool StopAudioStream() override; - int32_t GetBufferDesc(BufferDesc &bufDesc) override; - int32_t GetBufQueueState(BufferQueueState &bufState) override; - int32_t Enqueue(const BufferDesc &bufDesc) override; - int32_t Clear() override; -}; - -} // namespace AudioStandard -} // namespace OHOS -#endif // AUDIO_CONTAINER_STREAM_BASE_H \ No newline at end of file diff --git a/frameworks/native/audiocompatibility/include/audio_container_stream_callback.h b/frameworks/native/audiocompatibility/include/audio_container_stream_callback.h deleted file mode 100644 index a8cc81827261cddd1a00f6c1433168c70fc043b8..0000000000000000000000000000000000000000 --- a/frameworks/native/audiocompatibility/include/audio_container_stream_callback.h +++ /dev/null @@ -1,529 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef AUDIO_SERVICE_CLIENT_H -#define AUDIO_SERVICE_CLIENT_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "audio_capturer.h" -#include "audio_renderer.h" -#include "audio_system_manager.h" - -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" -#include "iservice_registry.h" - -namespace OHOS { -namespace AudioStandard { -enum ASClientType { - AUDIO_SERVICE_CLIENT_PLAYBACK, - AUDIO_SERVICE_CLIENT_RECORD, - AUDIO_SERVICE_CLIENT_CONTROLLER -}; - -struct StreamBuffer { - uint8_t *buffer; // the virtual address of stream - uint32_t bufferLen; // stream length in bytes -}; - -struct AudioCache { - std::unique_ptr buffer; - uint32_t readIndex; - uint32_t writeIndex; - uint32_t totalCacheSize; - bool isFull; -}; - -/** - * @brief Enumerates the stream states of the current device. - * - * @since 1.0 - * @version 1.0 - */ -enum State { - /** INVALID */ - INVALID = -1, - /** New */ - NEW, - /** Prepared */ - PREPARED, - /** Running */ - RUNNING, - /** Stopped */ - STOPPED, - /** Released */ - RELEASED, - /** Paused */ - PAUSED -}; - -/** - * @brief Enumerates the stream states of the current device. - * - * @since 1.0 - * @version 1.0 - */ -enum CMD_SEND { - CMD_CREATE_AUDIOSTREAM = 1, - CMD_START_AUDIOSTREAM = 2, - CMD_PAUSE_AUDIOSTREAM = 3, - CMD_STOP_AUDIOSTREAM = 4, - CMD_FLUSH_AUDIOSTREAM = 5, - CMD_DRAIN_AUDIOSTREAM = 6, - CMD_GET_AUDIO_SESSIONID = 7, - CMD_SET_AUDIORENDERER_MODE = 8, - CMD_WRITE_AUDIOSTREAM = 10, - CMD_RELEASE_AUDIOSTREAM = 11, - CMD_GET_MINIMUM_BUFFERSIZE = 12, - CMD_GET_MINIMUM_FRAMECOUNT = 13, - CMD_SET_STREAM_VOLUME = 15, - CMD_GET_AUDIO_LATENCY = 16, - CMD_SET_STREAM_TYPE = 17, - CMD_SET_STREAM_RENDER_RATE = 19, - CMD_GET_CURRENT_TIMESTAMP = 21, - CMD_GET_AUDIOSTREAM_PARAMS = 29, - CMD_WRITE_RENDERER_CALLBACK = 30, - CMD_READ_STREAM = 39, -}; - -enum AUDIO_STREAM_ERR { - // Error code used - AUDIO_CLIENT_SUCCESS = 0, - AUDIO_CLIENT_ERR = -1, - AUDIO_CLIENT_INVALID_PARAMS_ERR = -2, - AUDIO_CLIENT_INIT_ERR = -3, - AUDIO_CLIENT_CREATE_STREAM_ERR = -4, - AUDIO_CLIENT_START_STREAM_ERR = -5, - AUDIO_CLIENT_READ_STREAM_ERR = -6, - AUDIO_CLIENT_WRITE_STREAM_ERR = -7, - AUDIO_CLIENT_PA_ERR = -8, -}; - - -class AudioStreamCallback { -public: - virtual ~AudioStreamCallback() = default; - /** - * Called when stream state is updated. - * - * @param state Indicates the InterruptEvent information needed by client. - * For details, refer InterruptEvent struct in audio_info.h - */ - virtual void OnStateChange(const State state, StateChangeCmdType cmdType = CMD_FROM_CLIENT) = 0; -}; - -class AudioContainerStreamCallback { - // Need to check required state changes to update applications - virtual void OnStreamStateChangeCb() const = 0; - virtual void OnStreamBufferUnderFlowCb() const = 0; - virtual void OnStreamBufferOverFlowCb() const = 0; - virtual void OnErrorCb(AudioServiceErrorCodes error) const = 0; - virtual void OnEventCb(AudioServiceEventTypes error) const = 0; -}; - -class AudioRendererCallbacks : public AudioContainerStreamCallback { -public: - virtual ~AudioRendererCallbacks(); - virtual void OnSinkDeviceUpdatedCb() const = 0; -}; - -class AudioCapturerCallbacks : public AudioContainerStreamCallback { -public: - virtual ~AudioCapturerCallbacks(); - virtual void OnSourceDeviceUpdatedCb() const = 0; -}; - -class IAudioContainerService : public IRemoteBroker { -public: - /** - * Initializes audio service client for the required client type - * - * @param eClientType indicates the client type like playback, record or controller. - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - virtual int32_t InitializeGa(ASClientType eClientType) = 0; - - // Stream handling APIs - - /** - * Creates & initializes resources based on the audioParams and audioType - * - * @param audioParams indicate format, sampling rate and number of channels - * @param audioType indicate the stream type like music, system, ringtone etc - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - virtual int32_t CreateStreamGa(AudioStreamParams audioParams, AudioStreamType audioType) = 0; - - /** - * @brief Obtains session ID - * - * @return Returns unique session ID for the created session. - */ - virtual int32_t GetSessionIDGa(uint32_t &sessionID, const int32_t &trackId) = 0; - - /** - * Starts the stream created using CreateStreamGa - * - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - virtual int32_t StartStreamGa(const int32_t &trackId) = 0; - - /** - * Stops the stream created using CreateStreamGa - * - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - virtual int32_t StopStreamGa(const int32_t &trackId) = 0; - - /** - * Flushes the stream created using CreateStreamGa. This is applicable for - * playback only - * - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - virtual int32_t FlushStreamGa(const int32_t &trackId) = 0; - - /** - * Drains the stream created using CreateStreamGa. This is applicable for - * playback only - * - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - virtual int32_t DrainStreamGa(const int32_t &trackId) = 0; - - /** - * Pauses the stream - * - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - virtual int32_t PauseStreamGa(const int32_t &trackId) = 0; - - /** - * Update the stream type - * - * @param audioStreamType Audio stream type - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - virtual int32_t SetStreamTypeGa(AudioStreamType audioStreamType, const int32_t &trackId) = 0; - - /** - * Sets the volume of the stream associated with session ID - * - * @param sessionID indicates the ID for the active stream to be controlled - * @param volume indicates volume level between 0 to 65536 - * @return returns {@code 0} if success; returns {@code -1} otherwise. - */ - virtual int32_t SetStreamVolumeGa(uint32_t sessionID, uint32_t volume) = 0; - - /** - * Get the volume of the stream associated with session ID - * - * @param sessionID indicates the ID for the active stream to be controlled - * @return Returns volume level between 0 to 65536 - */ - virtual uint32_t GetStreamVolumeGa(uint32_t sessionID) = 0; - - /** - * Writes audio data of the stream created using CreateStreamGa to active sink device - * - * @param buffer contains audio data to write - * @param bufferSize indicates the size of audio data in bytes to write from the buffer - * @param pError indicates pointer to error which will be filled in case of internal errors - * @return Returns size of audio data written in bytes. - */ - virtual size_t WriteStreamGa(const StreamBuffer &stream, int32_t &pError, const int32_t &trackId) = 0; - - /** - * Writes audio data of the stream created using CreateStreamGa - * - * @param buffer contains audio data to write - * @param bufferSize indicates the size of audio data in bytes to write from the buffer - * @param pError indicates pointer to error which will be filled in case of internal errors - * @return Returns size of audio data written in bytes. - */ - virtual size_t WriteStreamInCbGa(const StreamBuffer &stream, int32_t &pError, const int32_t &trackId) = 0; - - /** - * Reads audio data of the stream created using CreateStreamGa from active source device - * - * @param StreamBuffer including buffer to be filled with audio data - * andbufferSize indicating the size of audio data to read into buffer - * @param isBlocking indicates if the read is blocking or not - * @return Returns size read if success; returns {@code -1} failure. - */ - virtual int32_t ReadStreamGa(StreamBuffer &stream, bool isBlocking, const int32_t &trackId) = 0; - - /** - * Release the resources allocated using CreateStreamGa - * - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - virtual int32_t ReleaseStreamGa(const int32_t &trackId) = 0; - - /** - * Provides the current timestamp for playback/record stream created using CreateStreamGa - * - * @param timestamp will be filled up with the current timestamp - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - virtual int32_t GetCurrentTimeStampGa(uint64_t ×tamp, const int32_t &trackId) = 0; - - /** - * Provides the current latency for playback/record stream created using CreateStreamGa - * - * @param latency will be filled up with current latency in microseconds - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - virtual int32_t GetAudioLatencyGa(uint64_t &latency, const int32_t &trackId) = 0; - - /** - * Provides the playback/record stream parameters created using CreateStreamGa - * - * @param audioParams will be filled up with stream audio parameters - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - virtual int32_t GetAudioStreamParamsGa(AudioStreamParams &audioParams, const int32_t &trackId) = 0; - - /** - * Provides the minimum buffer size required for this audio stream - * created using CreateStreamGa - * @param minBufferSize will be set to minimum buffer size in bytes - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - virtual int32_t GetMinimumBufferSizeGa(size_t &minBufferSize, const int32_t &trackId) = 0; - - /** - * Provides the minimum frame count required for this audio stream - * created using CreateStreamGa - * @param frameCount will be set to minimum number of frames - * @return Returns {@code 0} if success; returns {@code -1} otherwise. - */ - virtual int32_t GetMinimumFrameCountGa(uint32_t &frameCount, const int32_t &trackId) = 0; - - /** - * @brief Set the buffer duration in msec - * - * @param bufferSizeInMsec buffer size in duration. - * @return Returns {@link SUCCESS} defined in {@link audio_errors.h} otherwise. - */ - virtual int32_t SetBufferSizeInMsecGa(int32_t bufferSizeInMsec) = 0; - - /** - * Provides the sampling rate for the active audio stream - * created using CreateStreamGa - * - * @return Returns sampling rate in Hz - */ - virtual uint32_t GetSamplingRateGa() const = 0; - - /** - * Provides the channel count for the active audio stream - * created using CreateStreamGa - * - * @return Returns number of channels - */ - virtual uint8_t GetChannelCountGa() const = 0; - - /** - * Provides the sample size for the active audio stream - * created using CreateStreamGa - * - * @return Returns sample size in number of bits - */ - virtual uint8_t GetSampleSizeGa() const = 0; - - // Device volume & route handling APIS - - // Audio stream callbacks - - /** - * Register for callbacks associated with the playback stream created using CreateStreamGa - * - * @param cb indicates pointer for registered callbacks - * @return none - */ - virtual void RegisterAudioRendererCallbackGa(const AudioRendererCallback &cb) = 0; - - /** - * Register for callbacks associated with the record stream created using CreateStream - * - * @param cb indicates pointer for registered callbacks - * @return none - */ - virtual void RegisterAudioCapturerCallbackGa(const AudioCapturerCallback &cb) = 0; - - /** - * Set the renderer frame position callback - * - * @param callback indicates pointer for registered callbacks - * @return none - */ - virtual void SetRendererPositionCallbackGa(int64_t markPosition, - const std::shared_ptr &callback) = 0; - - /** - * Unset the renderer frame position callback - * - * @return none - */ - virtual void UnsetRendererPositionCallbackGa() = 0; - - /** - * Set the renderer frame period position callback - * - * @param callback indicates pointer for registered callbacks - * @return none - */ - virtual void SetRendererPeriodPositionCallbackGa(int64_t markPosition, - const std::shared_ptr &callback) = 0; - - /** - * Unset the renderer frame period position callback - * - * @return none - */ - virtual void UnsetRendererPeriodPositionCallbackGa() = 0; - - /** - * Set the capturer frame position callback - * - * @param callback indicates pointer for registered callbacks - * @return none - */ - virtual void SetCapturerPositionCallbackGa(int64_t markPosition, - const std::shared_ptr &callback) = 0; - - /** - * Unset the capturer frame position callback - * - * @return none - */ - virtual void UnsetCapturerPositionCallbackGa() = 0; - - /** - * Set the capturer frame period position callback - * - * @param callback indicates pointer for registered callbacks - * @return none - */ - virtual void SetCapturerPeriodPositionCallbackGa(int64_t markPosition, - const std::shared_ptr &callback) = 0; - - /** - * Unset the capturer frame period position callback - * - * @return none - */ - virtual void UnsetCapturerPeriodPositionCallbackGa() = 0; - - /** - * @brief Set the track volume - * - * @param volume The volume to be set for the current track. - * @return Returns {@link SUCCESS} if volume is successfully set; returns an error code - * defined in {@link audio_errors.h} otherwise. - */ - virtual int32_t SetStreamVolumeGa(float volume, const int32_t &trackId) = 0; - - /** - * @brief Obtains the current track volume - * - * @return Returns current track volume - */ - virtual float GetStreamVolumeGa() = 0; - - /** - * @brief Set the render rate - * - * @param renderRate The rate at which the stream needs to be rendered. - * @return Returns {@link SUCCESS} if render rate is successfully set; returns an error code - * defined in {@link audio_errors.h} otherwise. - */ - virtual int32_t SetStreamRenderRateGa(AudioRendererRate renderRate, const int32_t &trackId) = 0; - - /** - * @brief Obtains the current render rate - * - * @return Returns current render rate - */ - virtual AudioRendererRate GetStreamRenderRateGa() = 0; - - /** - * @brief Saves StreamCallback - * - * @param callback callback reference to be saved. - * @return none. - */ - virtual void SaveStreamCallbackGa(const std::weak_ptr &callback) = 0; - - /** - * @brief Sets the render mode. By default the mode is RENDER_MODE_NORMAL. - * This API is needs to be used only if RENDER_MODE_CALLBACK is required. - * - * @param renderMode The mode of render. - * @return Returns {@link SUCCESS} if render mode is successfully set; returns an error code - * defined in {@link audio_errors.h} otherwise. - */ - virtual int32_t SetAudioRenderModeGa(AudioRenderMode renderMode, const int32_t &trackId) = 0; - - /** - * @brief Obtains the render mode. - * - * @return Returns current render mode. - */ - virtual AudioRenderMode GetAudioRenderModeGa() = 0; - - /** - * @brief Registers the renderer write callback listener. - * This API should only be used if RENDER_MODE_CALLBACK is needed. - * - * @return Returns {@link SUCCESS} if callback registreation is successful; returns an error code - * defined in {@link audio_errors.h} otherwise. - */ - virtual int32_t SaveWriteCallbackGa(const std::weak_ptr &callback, - const int32_t &trackId = 0) = 0; - - virtual int32_t SetAudioCaptureMode(AudioCaptureMode captureMode) = 0; - - virtual int32_t SaveReadCallback(const std::weak_ptr &callback) = 0; - /** - * @brief Set the applicationcache path to access the application resources - * - * @return none - */ - virtual void SetAppCachePath(const std::string cachePath) = 0; - - virtual AudioCaptureMode GetAudioCaptureMode() = 0; -public: - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.sysability.samgr.IAudioStreamServiceGateway"); -}; -} // namespace AudioStandard -} // namespace OHOS -#endif // AUDIO_SERVICE_CLIENT_H diff --git a/frameworks/native/audiocompatibility/include/audio_renderer_gateway.h b/frameworks/native/audiocompatibility/include/audio_renderer_gateway.h deleted file mode 100644 index d3d14f9cf28d029876e8ef357244fa5e65cdfab6..0000000000000000000000000000000000000000 --- a/frameworks/native/audiocompatibility/include/audio_renderer_gateway.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef AUDIO_RENDERER_GATEWAY_H -#define AUDIO_RENDERER_GATEWAY_H - -#include "audio_interrupt_callback.h" -#include "audio_container_stream_base.h" - -namespace OHOS { -namespace AudioStandard { -constexpr uint32_t INVALID_SESSION = static_cast(-1); - -class AudioRendererGateway : public AudioRenderer { -public: - explicit AudioRendererGateway(AudioStreamType audioStreamType); - ~AudioRendererGateway(); - int32_t GetFrameCount(uint32_t &frameCount) const override; - int32_t GetLatency(uint64_t &latency) const override; - int32_t SetParams(const AudioRendererParams params) override; - int32_t GetParams(AudioRendererParams ¶ms) const override; - int32_t GetRendererInfo(AudioRendererInfo &rendererInfo) const override; - int32_t GetStreamInfo(AudioStreamInfo &streamInfo) const override; - bool Start(StateChangeCmdType cmdType = CMD_FROM_CLIENT) const override; - int32_t Write(uint8_t *buffer, size_t bufferSize) override; - int32_t Write(uint8_t *pcmBuffer, size_t pcmSize, uint8_t *metaBuffer, size_t metaSize) override; - RendererState GetStatus() const override; - bool GetAudioTime(Timestamp ×tamp, Timestamp::Timestampbase base) const override; - bool Drain() const override; - bool Pause(StateChangeCmdType cmdType = CMD_FROM_CLIENT) const override; - bool Stop() const override; - bool Flush() const override; - bool Release() const override; - int32_t GetBufferSize(size_t &bufferSize) const override; - int32_t GetAudioStreamId(uint32_t &sessionID) const override; - int32_t SetAudioRendererDesc(AudioRendererDesc audioRendererDesc) const override; - int32_t SetStreamType(AudioStreamType audioStreamType) const override; - int32_t SetVolume(float volume) const override; - float GetVolume() const override; - int32_t SetRenderRate(AudioRendererRate renderRate) const override; - AudioRendererRate GetRenderRate() const override; - int32_t SetRendererCallback(const std::shared_ptr &callback) override; - int32_t SetRendererPositionCallback(int64_t markPosition, - const std::shared_ptr &callback) override; - void UnsetRendererPositionCallback() override; - int32_t SetRendererPeriodPositionCallback(int64_t frameNumber, - const std::shared_ptr &callback) override; - void UnsetRendererPeriodPositionCallback() override; - int32_t SetBufferDuration(uint64_t bufferDuration) const override; - int32_t SetRenderMode(AudioRenderMode renderMode) const override; - AudioRenderMode GetRenderMode() const override; - int32_t SetRendererWriteCallback(const std::shared_ptr &callback) override; - void SetPreferredFrameSize(int32_t frameSize) override; - int32_t GetBufferDesc(BufferDesc &bufDesc) const override; - int32_t Enqueue(const BufferDesc &bufDesc) const override; - int32_t Clear() const override; - int32_t GetBufQueueState(BufferQueueState &bufState) const override; - void SetApplicationCachePath(const std::string cachePath) override; - void SetInterruptMode(InterruptMode mode) override; - int32_t SetLowPowerVolume(float volume) const override; - float GetLowPowerVolume() const override; - float GetSingleStreamVolume() const override; - bool IsFastRenderer() override; - AudioRendererInfo rendererInfo_ = {}; - -private: - static std::map> sharedInterrupts_; - std::shared_ptr audioStream_; - std::shared_ptr audioInterruptCallback_ = nullptr; - std::shared_ptr audioStreamCallback_ = nullptr; - AudioInterrupt audioInterrupt_ = { - STREAM_USAGE_UNKNOWN, CONTENT_TYPE_UNKNOWN, AudioStreamType::STREAM_DEFAULT, 0, false}; - AudioInterrupt sharedInterrupt_ = { - STREAM_USAGE_UNKNOWN, CONTENT_TYPE_UNKNOWN, AudioStreamType::STREAM_DEFAULT, 0, false}; - uint32_t sessionID_ = INVALID_SESSION; - AudioStandard::InterruptMode mode_ = AudioStandard::InterruptMode::SHARE_MODE; -}; - -class AudioInterruptCallbackGateway : public AudioInterruptCallback { -public: - explicit AudioInterruptCallbackGateway(const std::shared_ptr &audioStream, - const AudioInterrupt &audioInterrupt); - virtual ~AudioInterruptCallbackGateway(); - - void OnInterrupt(const InterruptEventInternal &interruptEvent) override; - void SaveCallback(const std::weak_ptr &callback); -private: - void NotifyEvent(const InterruptEvent &interruptEvent); - void HandleAndNotifyForcedEvent(const InterruptEventInternal &interruptEvent); - void NotifyForcePausedToResume(const InterruptEventInternal &interruptEvent); - bool HandleForceDucking(const InterruptEventInternal &interruptEvent); - std::shared_ptr audioStream_; - std::weak_ptr callback_; - std::shared_ptr cb_; - AudioInterrupt audioInterrupt_ {}; - bool isForcePaused_ = false; - bool isForceDucked_ = false; - float instanceVolBeforeDucking_ = 0.2f; -}; - -class AudioStreamRenderCallback : public AudioStreamCallback { -public: - virtual ~AudioStreamRenderCallback() = default; - - void OnStateChange(const State state, StateChangeCmdType cmdType = CMD_FROM_CLIENT) override; - void SaveCallback(const std::weak_ptr &callback); -private: - std::weak_ptr callback_; -}; - -} // namespace AudioStandard -} // namespace OHOS -#endif // AUDIO_RENDERER_GATEWAY_H diff --git a/frameworks/native/audiocompatibility/include/audio_renderer_write_callback_stub.h b/frameworks/native/audiocompatibility/include/audio_renderer_write_callback_stub.h deleted file mode 100644 index 637251a37c83958075a9ee63a1431b64d7876ad6..0000000000000000000000000000000000000000 --- a/frameworks/native/audiocompatibility/include/audio_renderer_write_callback_stub.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef AUDIO_RENDERER_WRITE_CALLBACK_STUB_H -#define AUDIO_RENDERER_WRITE_CALLBACK_STUB_H - -#include "audio_container_stream_callback.h" -#include "i_audio_renderer_write_callback.h" - -namespace OHOS { -namespace AudioStandard { -class AudioRendererWriteCallbackStub : public IRemoteStub { -public: - AudioRendererWriteCallbackStub(); - virtual ~AudioRendererWriteCallbackStub(); - virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption &option) override; - void OnWriteData(size_t length) override; - void SetOnRendererWriteCallback(const std::weak_ptr &callback); - -private: - std::weak_ptr callback_; -}; -} // namespace AudioStandard -} // namespace OHOS -#endif // AUDIO_RENDERER_WRITE_CALLBACK_STUB_H diff --git a/frameworks/native/audiocompatibility/include/audio_stream_death_recipient.h b/frameworks/native/audiocompatibility/include/audio_stream_death_recipient.h deleted file mode 100644 index 1c38f13d9e1402f2b36a2b122b999d725fb45551..0000000000000000000000000000000000000000 --- a/frameworks/native/audiocompatibility/include/audio_stream_death_recipient.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file audio_renderer_death_recipient.h - * - * @brief audio renderer death recipient. - */ - -#ifndef AUDIO_STREAM_DEATH_RECIPIENT_H -#define AUDIO_STREAM_DEATH_RECIPIENT_H - -#include "iremote_object.h" -#include "nocopyable.h" - -namespace OHOS { -namespace AudioStandard { -class AudioStreamDeathRecipient : public IRemoteObject::DeathRecipient { -public: - explicit AudioStreamDeathRecipient(pid_t pid) : m_pid(pid) {}; - - ~AudioStreamDeathRecipient() override = default; - DISALLOW_COPY_AND_MOVE(AudioStreamDeathRecipient); - - void OnRemoteDied(const wptr &remote) override - { - (void) remote; - if (m_callback != nullptr) { - m_callback(m_pid); - } - } - - using ServerDiedCallback = std::function; - - void SetServerDiedCallback(ServerDiedCallback callback) - { - m_callback = callback; - } - -private: - pid_t m_pid = 0; - ServerDiedCallback m_callback = nullptr; -}; -} -} - -#endif // AUDIO_STREAM_DEATH_RECIPIENT_H diff --git a/frameworks/native/audiocompatibility/include/i_audio_renderer_write_callback.h b/frameworks/native/audiocompatibility/include/i_audio_renderer_write_callback.h deleted file mode 100644 index b70580ffa984ec8d59bedcc36455d8bbc3d5fe0a..0000000000000000000000000000000000000000 --- a/frameworks/native/audiocompatibility/include/i_audio_renderer_write_callback.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef I_AUDIO_RENDERER_WRITE_CALLBACK_H -#define I_AUDIO_RENDERER_WRITE_CALLBACK_H - -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" -#include "audio_info.h" - -namespace OHOS { -namespace AudioStandard { -class IAudioRendererWriteCallback : public IRemoteBroker { -public: - virtual void OnWriteData(size_t length) = 0; - enum { - ON_WRITE_DATA = 0, - }; -public: - DECLARE_INTERFACE_DESCRIPTOR(u"IRemoteAudioRendererWriteCallback"); -}; -} // namespace AudioStandard -} // namespace OHOS -#endif // I_AUDIO_RENDERER_WRITE_CALLBACK_H diff --git a/frameworks/native/audiocompatibility/src/audio_capturer_gateway.cpp b/frameworks/native/audiocompatibility/src/audio_capturer_gateway.cpp deleted file mode 100644 index b1166bc1deccbf0ce5476dfbec887b2abf770a7f..0000000000000000000000000000000000000000 --- a/frameworks/native/audiocompatibility/src/audio_capturer_gateway.cpp +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#undef LOG_TAG -#define LOG_TAG "AudioCapturerGateway" - -#include "audio_errors.h" -#include "audio_policy_manager.h" -#include "audio_capturer_gateway.h" -#include "audio_container_stream_base.h" -#include "audio_log.h" -#include "audio_capturer.h" - -namespace OHOS { -namespace AudioStandard { -AudioCapturer::~AudioCapturer() = default; - -AudioCapturerGateway::~AudioCapturerGateway() -{ - CapturerState state = GetStatus(); - if (state != CAPTURER_RELEASED && state != CAPTURER_NEW) { - Release(); - } -} - -AudioCapturerGateway::AudioCapturerGateway(AudioStreamType audioStreamType) -{ - audioStream_ = std::make_shared(audioStreamType, AUDIO_MODE_RECORD); - if (audioStream_) { - AUDIO_DEBUG_LOG("Audio stream created"); - } -} - -int32_t AudioCapturerGateway::GetFrameCount(uint32_t &frameCount) const -{ - return audioStream_->GetFrameCount(frameCount); -} - -int32_t AudioCapturerGateway::SetParams(const AudioCapturerParams params) -{ - AudioStreamParams audioStreamParams; - audioStreamParams.format = params.audioSampleFormat; - audioStreamParams.samplingRate = params.samplingRate; - audioStreamParams.channels = params.audioChannel; - audioStreamParams.encoding = params.audioEncoding; - AUDIO_INFO_LOG("SetAudioStreamInfo"); - return audioStream_->SetAudioStreamInfo(audioStreamParams); -} - -int32_t AudioCapturerGateway::SetCapturerCallback(const std::shared_ptr &callback) -{ - // If the client is using the deprecated SetParams API. SetCapturerCallback must be invoked, after SetParams. - // In general, callbacks can only be set after the capturer state is PREPARED. - CapturerState state = GetStatus(); - CHECK_AND_RETURN_RET_LOG(state != CAPTURER_NEW && state != CAPTURER_RELEASED, ERR_ILLEGAL_STATE, - "ncorrect state:%{public}d to register cb", state); - CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERR_INVALID_PARAM, - "callback param is null"); - - // Save and Set reference for stream callback. Order is important here. - if (audioStreamCallback_ == nullptr) { - audioStreamCallback_ = std::make_shared(); - CHECK_AND_RETURN_RET_LOG(audioStreamCallback_ != nullptr, ERROR, - "Failed to allocate memory for audioStreamCallback_"); - } - AUDIO_DEBUG_LOG("SetCapturerCallback"); - std::shared_ptr cbStream = - std::static_pointer_cast(audioStreamCallback_); - cbStream->SaveCallback(callback); - (void)audioStream_->SetStreamCallback(audioStreamCallback_); - - return SUCCESS; -} - -int32_t AudioCapturerGateway::GetParams(AudioCapturerParams ¶ms) const -{ - AudioStreamParams audioStreamParams; - int32_t result = audioStream_->GetAudioStreamInfo(audioStreamParams); - if (SUCCESS == result) { - params.audioSampleFormat = static_cast(audioStreamParams.format); - params.samplingRate = static_cast(audioStreamParams.samplingRate); - params.audioChannel = static_cast(audioStreamParams.channels); - params.audioEncoding = static_cast(audioStreamParams.encoding); - } - - return result; -} - -int32_t AudioCapturerGateway::GetCapturerInfo(AudioCapturerInfo &capturerInfo) const -{ - capturerInfo = capturerInfo_; - - return SUCCESS; -} - -int32_t AudioCapturerGateway::GetStreamInfo(AudioStreamInfo &streamInfo) const -{ - AudioStreamParams audioStreamParams; - int32_t result = audioStream_->GetAudioStreamInfo(audioStreamParams); - if (SUCCESS == result) { - streamInfo.format = static_cast(audioStreamParams.format); - streamInfo.samplingRate = static_cast(audioStreamParams.samplingRate); - streamInfo.channels = static_cast(audioStreamParams.channels); - streamInfo.encoding = static_cast(audioStreamParams.encoding); - } - - return result; -} - - -int32_t AudioCapturerGateway::SetCapturerPositionCallback(int64_t markPosition, - const std::shared_ptr &callback) -{ - CHECK_AND_RETURN_RET_LOG((callback != nullptr) && (markPosition > 0), - ERR_INVALID_PARAM, "input param is invalid"); - - audioStream_->SetCapturerPositionCallback(markPosition, callback); - - return SUCCESS; -} - -void AudioCapturerGateway::UnsetCapturerPositionCallback() -{ - audioStream_->UnsetCapturerPositionCallback(); -} - -int32_t AudioCapturerGateway::SetCapturerPeriodPositionCallback(int64_t frameNumber, - const std::shared_ptr &callback) -{ - CHECK_AND_RETURN_RET_LOG((callback != nullptr) && (frameNumber > 0), ERR_INVALID_PARAM, - "input param is invalid"); - - audioStream_->SetCapturerPeriodPositionCallback(frameNumber, callback); - - return SUCCESS; -} - -void AudioCapturerGateway::UnsetCapturerPeriodPositionCallback() -{ - audioStream_->UnsetCapturerPeriodPositionCallback(); -} - -bool AudioCapturerGateway::Start() const -{ - return audioStream_->StartAudioStream(); -} - -int32_t AudioCapturerGateway::Read(uint8_t &buffer, size_t userSize, bool isBlockingRead) const -{ - return audioStream_->Read(buffer, userSize, isBlockingRead); -} - -CapturerState AudioCapturerGateway::GetStatus() const -{ - return (CapturerState)audioStream_->GetState(); -} - -bool AudioCapturerGateway::GetAudioTime(Timestamp ×tamp, Timestamp::Timestampbase base) const -{ - return audioStream_->GetAudioTime(timestamp, base); -} - -bool AudioCapturerGateway::Pause() const -{ - return audioStream_->PauseAudioStream(); -} - -bool AudioCapturerGateway::Stop() const -{ - return audioStream_->StopAudioStream(); -} - -bool AudioCapturerGateway::Flush() const -{ - return audioStream_->FlushAudioStream(); -} - -bool AudioCapturerGateway::Release() const -{ - return audioStream_->ReleaseAudioStream(); -} - -int32_t AudioCapturerGateway::GetBufferSize(size_t &bufferSize) const -{ - return audioStream_->GetBufferSize(bufferSize); -} - -int32_t AudioCapturerGateway::GetAudioStreamId(uint32_t &sessionID) const -{ - return audioStream_->GetAudioSessionID(sessionID); -} - -int32_t AudioCapturerGateway::SetBufferDuration(uint64_t bufferDuration) const -{ - CHECK_AND_RETURN_RET_LOG(bufferDuration >= MINIMUM_BUFFER_SIZE_MSEC && bufferDuration <= MAXIMUM_BUFFER_SIZE_MSEC, - ERR_INVALID_PARAM, "Error: Please set the buffer duration between 5ms ~ 20ms"); - return audioStream_->SetBufferSizeInMsec(bufferDuration); -} - -void AudioCapturerGateway::SetApplicationCachePath(const std::string cachePath) -{ - audioStream_->SetApplicationCachePath(cachePath); -} - -void AudioStreamCapturerCallback::SaveCallback(const std::weak_ptr &callback) -{ - std::shared_ptr cb = callback.lock(); - AUDIO_DEBUG_LOG("SaveCallback cb"); - callback_ = callback; -} - -void AudioStreamCapturerCallback::OnStateChange(const State state, StateChangeCmdType cmdType) -{ - std::shared_ptr cb = callback_.lock(); - CHECK_AND_RETURN_RET_LOG(cb != nullptr, "cb == nullptr."); - AUDIO_DEBUG_LOG("OnStateChange cb"); - cb->OnStateChange(static_cast(state)); -} - -int32_t AudioCapturerGateway::SetCaptureMode(AudioCaptureMode captureMode) const -{ - return audioStream_->SetCaptureMode(captureMode); -} - -AudioCaptureMode AudioCapturerGateway::GetCaptureMode() const -{ - return audioStream_->GetCaptureMode(); -} - -int32_t AudioCapturerGateway::SetCapturerReadCallback(const std::shared_ptr &callback) -{ - return audioStream_->SetCapturerReadCallback(callback); -} - -int32_t AudioCapturerGateway::GetBufferDesc(BufferDesc &bufDesc) const -{ - return audioStream_->GetBufferDesc(bufDesc); -} - -int32_t AudioCapturerGateway::Enqueue(const BufferDesc &bufDesc) const -{ - return audioStream_->Enqueue(bufDesc); -} - -int32_t AudioCapturerGateway::Clear() const -{ - return audioStream_->Clear(); -} - -int32_t AudioCapturerGateway::GetBufQueueState(BufferQueueState &bufState) const -{ - return audioStream_->GetBufQueueState(bufState); -} - -} // namespace AudioStandard -} // namespace OHOS diff --git a/frameworks/native/audiocompatibility/src/audio_container_base.cpp b/frameworks/native/audiocompatibility/src/audio_container_base.cpp deleted file mode 100644 index 5f7431001a956c42e34302bc33befa24c355fc6d..0000000000000000000000000000000000000000 --- a/frameworks/native/audiocompatibility/src/audio_container_base.cpp +++ /dev/null @@ -1,278 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#undef LOG_TAG -#define LOG_TAG "AudioContainerBase" - -#include "audio_container_base.h" -#include "audio_stream_death_recipient.h" -#include "audio_log.h" -#include "unistd.h" -#include "securec.h" -#include "system_ability_definition.h" - -using namespace std; - -namespace OHOS { -namespace AudioStandard { - -static bool g_isConnected = false; -static sptr g_sProxy = nullptr; - -void AudioContainerBase::InitAudioStreamManagerGa(int serviceId) -{ - AUDIO_INFO_LOG("serviceId %d", serviceId); - auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - CHECK_AND_RETURN_LOG(samgr != nullptr, "init failed"); - - sptr object = samgr->GetSystemAbility(serviceId); - CHECK_AND_RETURN_LOG(object != nullptr, "object is NULL"); - - g_sProxy = iface_cast(object); - CHECK_AND_RETURN_LOG(g_sProxy != nullptr, "init g_sProxy is NULL"); - g_isConnected = true; - RegisterAudioStreamDeathRecipient(object); - AUDIO_DEBUG_LOG("init g_sProxy is assigned."); -} - -void AudioContainerBase::RegisterAudioStreamDeathRecipient(sptr &object) -{ - AUDIO_INFO_LOG("Register audio renderer death recipient"); - pid_t pid = 0; - sptr recipient = new(std::nothrow) AudioStreamDeathRecipient(pid); - if (recipient != nullptr) { - recipient->SetServerDiedCallback([](auto &&PH1) { - AudioStreamDeathRecipient(std::forward(PH1)); - }); - bool result = object->AddDeathRecipient(recipient); - if (!result) { - AUDIO_ERR_LOG("failed to add recipient"); - } - } -} - -void AudioContainerBase::AudioStreamDied(pid_t pid) -{ - AUDIO_INFO_LOG("Audio renderer died, reestablish connection"); - g_isConnected = false; -} - -int32_t AudioContainerBase::Initialize(ASClientType eClientType, int serviceId) -{ - InitAudioStreamManagerGa(serviceId); - return g_sProxy->InitializeGa(eClientType); -} - -int32_t AudioContainerBase::CreateStream(AudioStreamParams audioParams, AudioStreamType audioType) -{ - return g_sProxy->CreateStreamGa(audioParams, audioType); -} - -int32_t AudioContainerBase::GetSessionID(uint32_t &sessionID, const int32_t &trackId) const -{ - return g_sProxy->GetSessionIDGa(sessionID, trackId); -} - -int32_t AudioContainerBase::StartStream(const int32_t &trackId) -{ - return g_sProxy->StartStreamGa(trackId); -} - -int32_t AudioContainerBase::PauseStream(const int32_t &trackId) -{ - return g_sProxy->PauseStreamGa(trackId); -} - -int32_t AudioContainerBase::StopStream(const int32_t &trackId) -{ - return g_sProxy->StopStreamGa(trackId); -} - -int32_t AudioContainerBase::FlushStream(const int32_t &trackId) -{ - return g_sProxy->FlushStreamGa(trackId); -} - -int32_t AudioContainerBase::DrainStream(const int32_t &trackId) -{ - return g_sProxy->DrainStreamGa(trackId); -} - -int32_t AudioContainerBase::SetAudioRenderMode(AudioRenderMode renderMode, const int32_t &trackId) -{ - return g_sProxy->SetAudioRenderModeGa(renderMode, trackId); -} - -AudioRenderMode AudioContainerBase::GetAudioRenderMode() -{ - return g_sProxy->GetAudioRenderModeGa(); -} - -size_t AudioContainerBase::WriteStreamInCb(const StreamBuffer &stream, int32_t &pError, const int32_t &trackId) -{ - return g_sProxy->WriteStreamInCbGa(stream, pError, trackId); -} - -size_t AudioContainerBase::WriteStream(const StreamBuffer &stream, int32_t &pError, const int32_t &trackId) -{ - return g_sProxy->WriteStreamGa(stream, pError, trackId); -} - -int32_t AudioContainerBase::ReadStream(StreamBuffer &stream, bool isBlocking, const int32_t &trackId) -{ - return g_sProxy->ReadStreamGa(stream, isBlocking, trackId); -} - -int32_t AudioContainerBase::ReleaseStream(const int32_t &trackId) -{ - return g_sProxy->ReleaseStreamGa(trackId); -} - -int32_t AudioContainerBase::GetMinimumBufferSize(size_t &minBufferSize, const int32_t &trackId) const -{ - return g_sProxy->GetMinimumBufferSizeGa(minBufferSize, trackId); -} - -int32_t AudioContainerBase::GetMinimumFrameCount(uint32_t &frameCount, const int32_t &trackId) const -{ - return g_sProxy->GetMinimumFrameCountGa(frameCount, trackId); -} - -int32_t AudioContainerBase::GetAudioStreamParams(AudioStreamParams& audioParams, const int32_t &trackId) -{ - return g_sProxy->GetAudioStreamParamsGa(audioParams, trackId); -} - -int32_t AudioContainerBase::GetCurrentTimeStamp(uint64_t ×tamp, const int32_t &trackId) -{ - return g_sProxy->GetCurrentTimeStampGa(timestamp, trackId); -} - -int32_t AudioContainerBase::GetAudioLatency(uint64_t &latency, const int32_t &trackId) const -{ - return g_sProxy->GetAudioLatencyGa(latency, trackId); -} - -int32_t AudioContainerBase::SetStreamType(AudioStreamType audioStreamType, const int32_t &trackId) -{ - return g_sProxy->SetStreamTypeGa(audioStreamType, trackId); -} - -int32_t AudioContainerBase::SetStreamVolume(float volume, const int32_t &trackId) -{ - return g_sProxy->SetStreamVolumeGa(volume, trackId); -} - -float AudioContainerBase::GetStreamVolume() -{ - return g_sProxy->GetStreamVolumeGa(); -} - -int32_t AudioContainerBase::SetStreamRenderRate(AudioRendererRate audioRendererRate, const int32_t &trackId) -{ - return g_sProxy->SetStreamRenderRateGa(audioRendererRate, trackId); -} - -AudioRendererRate AudioContainerBase::GetStreamRenderRate() -{ - return g_sProxy->GetStreamRenderRateGa(); -} - -void AudioContainerBase::SaveStreamCallback(const std::weak_ptr &callback) -{ - return g_sProxy->SaveStreamCallbackGa(callback); -} - -int32_t AudioContainerBase::SetBufferSizeInMsec(int32_t bufferSizeInMsec) -{ - return g_sProxy->SetBufferSizeInMsecGa(bufferSizeInMsec); -} - -void AudioContainerBase::SetRendererPositionCallback(int64_t markPosition, - const std::shared_ptr &callback) -{ - return g_sProxy->SetRendererPositionCallbackGa(markPosition, callback); -} - -void AudioContainerBase::UnsetRendererPositionCallback() -{ - return g_sProxy->UnsetRendererPositionCallbackGa(); -} - -void AudioContainerBase::SetRendererPeriodPositionCallback(int64_t periodPosition, - const std::shared_ptr &callback) -{ - return g_sProxy->SetRendererPeriodPositionCallbackGa(periodPosition, callback); -} - -void AudioContainerBase::UnsetRendererPeriodPositionCallback() -{ - return g_sProxy->UnsetRendererPeriodPositionCallbackGa(); -} - -void AudioContainerBase::SetCapturerPositionCallback(int64_t markPosition, - const std::shared_ptr &callback) -{ - return g_sProxy->SetCapturerPositionCallbackGa(markPosition, callback); -} - -void AudioContainerBase::UnsetCapturerPositionCallback() -{ - return g_sProxy->UnsetCapturerPositionCallbackGa(); -} - -void AudioContainerBase::SetCapturerPeriodPositionCallback(int64_t periodPosition, - const std::shared_ptr &callback) -{ - return g_sProxy->SetCapturerPeriodPositionCallbackGa(periodPosition, callback); -} - -void AudioContainerBase::UnsetCapturerPeriodPositionCallback() -{ - return g_sProxy->UnsetCapturerPeriodPositionCallbackGa(); -} - -void AudioContainerBase::OnTimeOut() -{ - AUDIO_WARNING_LOG("Inside read timeout callback"); -} - -int32_t AudioContainerBase::SetAudioCaptureMode(AudioCaptureMode captureMode) -{ - return g_sProxy->SetAudioCaptureMode(captureMode); -} - -int32_t AudioContainerBase::SaveReadCallback(const std::weak_ptr &callback) -{ - return g_sProxy->SaveReadCallback(callback); -} - -AudioCaptureMode AudioContainerBase::GetAudioCaptureMode() -{ - return g_sProxy->GetAudioCaptureMode(); -} - -void AudioContainerBase::SetAppCachePath(const std::string cachePath) -{ - AUDIO_INFO_LOG("cachePath %{public}s", cachePath.c_str()); -} - -int32_t AudioContainerBase::SaveWriteCallback(const std::weak_ptr &callback, - const int32_t &trackId) -{ - AUDIO_INFO_LOG("SaveWriteCallback"); - return g_sProxy->SaveWriteCallbackGa(callback, trackId); -} -} // namespace AudioStandard -} // namespace OHOS diff --git a/frameworks/native/audiocompatibility/src/audio_container_client_base.cpp b/frameworks/native/audiocompatibility/src/audio_container_client_base.cpp deleted file mode 100644 index 56f954727388304c9ab9a80c0c320fd200c91ce4..0000000000000000000000000000000000000000 --- a/frameworks/native/audiocompatibility/src/audio_container_client_base.cpp +++ /dev/null @@ -1,807 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#undef LOG_TAG -#define LOG_TAG "AudioContainerClientBase" - -#include "audio_container_client_base.h" -#include "audio_renderer_write_callback_stub.h" -#include -#include "audio_log.h" -#include "securec.h" -#include "unistd.h" -#include "system_ability_definition.h" - -using namespace std; - -namespace OHOS { -namespace AudioStandard { - -static const int32_t MAX_VOLUME_LEVEL = 15; -static const int32_t CONST_FACTOR = 100; - -static float VolumeToDb(int32_t volumeLevel) -{ - float value = static_cast(volumeLevel) / MAX_VOLUME_LEVEL; - float roundValue = static_cast(value * CONST_FACTOR); - - return static_cast(roundValue) / CONST_FACTOR; -} - -void AudioContainerClientBase::InitializeClientGa() -{ - mVolumeFactor = 1.0f; - mStreamType = STREAM_MUSIC; - mAudioSystemMgr = nullptr; - renderRate = RENDER_RATE_NORMAL; - renderMode_ = RENDER_MODE_NORMAL; - eAudioClientType = AUDIO_SERVICE_CLIENT_PLAYBACK; - mFrameSize = 0; - mFrameMarkPosition = 0; - mMarkReached = false; - mFramePeriodNumber = 0; - mTotalBytesWritten = 0; - mFramePeriodWritten = 0; - mTotalBytesRead = 0; - mFramePeriodRead = 0; - - mRenderPositionCb = nullptr; - mRenderPeriodPositionCb = nullptr; - mAudioRendererCallbacks = nullptr; - mAudioCapturerCallbacks = nullptr; - internalReadBuffer_ = nullptr; - - internalRdBufIndex_ = 0; - internalRdBufLen_ = 0; -} - -void AudioContainerClientBase::ResetPAAudioClientGa() -{ - lock_guard lock(ctrlMutex_); - mAudioRendererCallbacks = nullptr; - mAudioCapturerCallbacks = nullptr; - internalReadBuffer_ = nullptr; - - internalRdBufIndex_ = 0; - internalRdBufLen_ = 0; -} - -AudioContainerClientBase::AudioContainerClientBase(const sptr &impl) - :IRemoteProxy(impl) -{ -} - -AudioContainerClientBase::~AudioContainerClientBase() -{ - ResetPAAudioClientGa(); -} - -int32_t AudioContainerClientBase::InitializeGa(ASClientType eClientType) -{ - AUDIO_DEBUG_LOG("AudioContainerClientBase::InitializeGa"); - InitializeClientGa(); - eAudioClientType = eClientType; - - mMarkReached = false; - mTotalBytesWritten = 0; - mFramePeriodWritten = 0; - mTotalBytesRead = 0; - mFramePeriodRead = 0; - - mAudioSystemMgr = AudioSystemManager::GetInstance(); - - return AUDIO_CLIENT_SUCCESS; -} - -const std::string AudioContainerClientBase::GetStreamNameGa(AudioStreamType audioType) -{ - std::string name; - switch (audioType) { - case STREAM_VOICE_ASSISTANT: - name = "voice_assistant"; - break; - case STREAM_VOICE_CALL: - name = "voice_call"; - break; - case STREAM_SYSTEM: - name = "system"; - break; - case STREAM_RING: - name = "ring"; - break; - case STREAM_MUSIC: - name = "music"; - break; - case STREAM_ALARM: - name = "alarm"; - break; - case STREAM_NOTIFICATION: - name = "notification"; - break; - case STREAM_BLUETOOTH_SCO: - name = "bluetooth_sco"; - break; - case STREAM_DTMF: - name = "dtmf"; - break; - case STREAM_TTS: - name = "tts"; - break; - case STREAM_ACCESSIBILITY: - name = "accessibility"; - break; - case STREAM_WAKEUP: - name = "wakeup"; - break; - default: - name = "unknown"; - } - - const std::string streamName = name; - return streamName; -} - -int32_t AudioContainerClientBase::InitializeAudioCacheGa() -{ - return AUDIO_CLIENT_SUCCESS; -} - -int32_t AudioContainerClientBase::CreateStreamGa(AudioStreamParams audioParams, AudioStreamType audioType) -{ - int32_t error; - - if (eAudioClientType == AUDIO_SERVICE_CLIENT_CONTROLLER) { - return AUDIO_CLIENT_INVALID_PARAMS_ERR; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool tmp = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(tmp, AUDIO_CLIENT_ERR, - "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(audioParams.samplingRate)); - data.WriteInt32(static_cast(audioParams.encoding)); - data.WriteInt32(static_cast(audioParams.format)); - data.WriteInt32(static_cast(audioParams.channels)); - data.WriteInt32(static_cast(audioType)); - - error = Remote()->SendRequest(CMD_CREATE_AUDIOSTREAM, data, reply, option); - - mFrameSize = (static_cast(audioParams.channels)) * (static_cast(audioParams.format)); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_CLIENT_CREATE_STREAM_ERR, - "CreateRemoteAudioRenderer() failed, error: %{public}d", error); - - audioTrackId = reply.ReadInt32(); - CHECK_AND_RETURN_RET_LOG(audioTrackId >= 0, AUDIO_CLIENT_CREATE_STREAM_ERR, - "CreateRemoteAudioRenderer() remote failed"); - state_ = PREPARED; - std::shared_ptr streamCb = streamCallback_.lock(); - if (streamCb != nullptr) { - streamCb->OnStateChange(state_); - } - - AUDIO_INFO_LOG("Created Stream SUCCESS TrackId %{public}d", audioTrackId); - return audioTrackId; -} - -int32_t AudioContainerClientBase::StartStreamGa(const int32_t &trackId) -{ - lock_guard lock(ctrlMutex_); - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool tmp = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(tmp, AUDIO_CLIENT_ERR, "WriteInterfaceToken failed"); - data.WriteInt32(trackId); - int32_t error = Remote()->SendRequest(CMD_START_AUDIOSTREAM, data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_CLIENT_START_STREAM_ERR, - "StartStreamGa() failed, error: %{public}d", error); - AUDIO_INFO_LOG("Start Stream SUCCESS"); - return AUDIO_CLIENT_SUCCESS; -} - -int32_t AudioContainerClientBase::PauseStreamGa(const int32_t &trackId) -{ - lock_guard lock(ctrlMutex_); - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool tmp = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(tmp, AUDIO_CLIENT_ERR, "WriteInterfaceToken failed"); - data.WriteInt32(trackId); - int32_t error = Remote()->SendRequest(CMD_PAUSE_AUDIOSTREAM, data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_CLIENT_ERR, - "PauseStreamGa() failed, error: %{public}d", error); - - return AUDIO_CLIENT_SUCCESS; -} - -int32_t AudioContainerClientBase::StopStreamGa(const int32_t &trackId) -{ - lock_guard lock(ctrlMutex_); - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool tmp = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(tmp, AUDIO_CLIENT_ERR, "WriteInterfaceToken failed"); - data.WriteInt32(trackId); - int32_t error = Remote()->SendRequest(CMD_STOP_AUDIOSTREAM, data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_CLIENT_ERR, - "StopStreamGa() failed, error: %{public}d", error); - - return AUDIO_CLIENT_SUCCESS; -} - -int32_t AudioContainerClientBase::FlushStreamGa(const int32_t &trackId) -{ - lock_guard lock(dataMutex_); - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool tmp = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(tmp, AUDIO_CLIENT_ERR, "WriteInterfaceToken failed"); - data.WriteInt32(trackId); - int32_t error = Remote()->SendRequest(CMD_FLUSH_AUDIOSTREAM, data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_CLIENT_ERR, - "FlushStreamGa() failed, error: %{public}d", error); - - return AUDIO_CLIENT_SUCCESS; -} - -int32_t AudioContainerClientBase::DrainStreamGa(const int32_t &trackId) -{ - return AUDIO_CLIENT_SUCCESS; -} - -int32_t AudioContainerClientBase::GetSessionIDGa(uint32_t &sessionID, const int32_t &trackId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool tmp = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(tmp, AUDIO_CLIENT_ERR, "WriteInterfaceToken failed"); - data.WriteInt32(trackId); - int32_t error = Remote()->SendRequest(CMD_GET_AUDIO_SESSIONID, data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_CLIENT_ERR, - "GetSessinIDGa() failed, error: %{public}d", error); - sessionID = reply.ReadInt32(); - return AUDIO_CLIENT_SUCCESS; -} - -int32_t AudioContainerClientBase::SetAudioRenderModeGa(AudioRenderMode renderMode, const int32_t &trackId) -{ - renderMode_ = renderMode; - CHECK_AND_RETURN_RET(renderMode_ == RENDER_MODE_CALLBACK, AUDIO_CLIENT_SUCCESS); - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool tmp = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(tmp, AUDIO_CLIENT_ERR, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(renderMode)); - data.WriteInt32(trackId); - int32_t error = Remote()->SendRequest(CMD_SET_AUDIORENDERER_MODE, data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_CLIENT_ERR, - "SetAudioRenderModeGa() failed, error: %{public}d", error); - - return AUDIO_CLIENT_SUCCESS; -} - -AudioRenderMode AudioContainerClientBase::GetAudioRenderModeGa() -{ - return renderMode_; -} - -int32_t AudioContainerClientBase::SaveWriteCallbackGa(const std::weak_ptr &callback, - const int32_t &trackId) -{ - lock_guard lock(dataMutex_); - MessageParcel data; - MessageParcel reply; - MessageOption option; - CHECK_AND_RETURN_RET_LOG(callback.lock() != nullptr, AUDIO_CLIENT_INIT_ERR, - "callback.lock() == nullpt"); - writeCallback_ = callback; - // construct writecallback stub for remote - sptr writeCallbackStub = new(std::nothrow) AudioRendererWriteCallbackStub(); - CHECK_AND_RETURN_RET_LOG(writeCallbackStub != nullptr, AUDIO_CLIENT_ERR, - "writeCallbackStub == nullpt"); - writeCallbackStub->SetOnRendererWriteCallback(callback); - sptr object = writeCallbackStub->AsObject(); - CHECK_AND_RETURN_RET_LOG(object != nullptr, AUDIO_CLIENT_ERR, - "writeCallbackStub->AsObject is nullpt"); - - bool tmp = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(tmp, AUDIO_CLIENT_ERR, "WriteInterfaceToken failed"); - - data.WriteRemoteObject(object); - data.WriteInt32(trackId); - int32_t error = Remote()->SendRequest(CMD_WRITE_RENDERER_CALLBACK, data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_CLIENT_ERR, - "SaveWriteCallbackGa() failed, error: %{public}d", error); - - return AUDIO_CLIENT_SUCCESS; -} - -int32_t AudioContainerClientBase::SetStreamVolumeGa(uint32_t sessionID, uint32_t volume) -{ - return AUDIO_CLIENT_SUCCESS; -} - -int32_t AudioContainerClientBase::WriteStreamInnerGa(const uint8_t *buffer, size_t &length, const int32_t &trackId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool tmp = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(tmp, AUDIO_CLIENT_ERR, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(length)); - data.WriteBuffer(static_cast(buffer), length); - data.WriteInt32(trackId); - int32_t error = Remote()->SendRequest(CMD_WRITE_AUDIOSTREAM, data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_CLIENT_ERR, - "WriteStreamInnerGa() failed, error: %{public}d", error); - HandleRenderPositionCallbacksGa(length); - return AUDIO_CLIENT_SUCCESS; -} - -void AudioContainerClientBase::HandleRenderPositionCallbacksGa(size_t bytesWritten) -{ - mTotalBytesWritten += bytesWritten; - if (mFrameSize == 0) { - return; - } - - uint64_t writtenFrameNumber = mTotalBytesWritten / mFrameSize; - if (!mMarkReached && mRenderPositionCb) { - if (writtenFrameNumber >= mFrameMarkPosition) { - mRenderPositionCb->OnMarkReached(mFrameMarkPosition); - mPositionCBThreads.emplace_back(std::make_unique(&RendererPositionCallback::OnMarkReached, - mRenderPositionCb, mFrameMarkPosition)); - mMarkReached = true; - } - } - - if (mRenderPeriodPositionCb) { - mFramePeriodWritten += (bytesWritten / mFrameSize); - if (mFramePeriodWritten >= mFramePeriodNumber) { - mRenderPeriodPositionCb->OnPeriodReached(mFramePeriodNumber); - mFramePeriodWritten %= mFramePeriodNumber; - mPeriodPositionCBThreads.emplace_back(std::make_unique( - &RendererPeriodPositionCallback::OnPeriodReached, mRenderPeriodPositionCb, mFramePeriodNumber)); - } - } -} - -size_t AudioContainerClientBase::WriteStreamInCbGa(const StreamBuffer &stream, int32_t &pError, const int32_t &trackId) -{ - lock_guard lock(dataMutex_); - - const uint8_t *buffer = stream.buffer; - size_t length = stream.bufferLen; - pError = WriteStreamInnerGa(buffer, length, trackId); - - return (stream.bufferLen - length); -} - -size_t AudioContainerClientBase::WriteStreamGa(const StreamBuffer &stream, int32_t &pError, const int32_t &trackId) -{ - lock_guard lock(dataMutex_); - int error = 0; - const uint8_t *inputBuffer = stream.buffer; - size_t inputLength = stream.bufferLen; - CHECK_AND_RETURN_RET_LOG(inputBuffer != nullptr, 0, "WriteStreamGa inputBuffer is null"); - error = WriteStreamInnerGa(inputBuffer, inputLength, trackId); - - pError = error; - return inputLength; -} - -int32_t AudioContainerClientBase::UpdateReadBufferGa(uint8_t *buffer, size_t &length, size_t &readSize) -{ - size_t l = (internalRdBufLen_ < length) ? internalRdBufLen_ : length; - errno_t err = memcpy_s(buffer, length, static_cast(internalReadBuffer_) + internalRdBufIndex_, l); - CHECK_AND_RETURN_RET(err == 0, AUDIO_CLIENT_READ_STREAM_ERR); - - length -= l; - internalRdBufIndex_ += l; - internalRdBufLen_ -= l; - readSize += l; - - if (!internalRdBufLen_) { - internalReadBuffer_ = nullptr; - internalRdBufLen_ = 0; - internalRdBufIndex_ = 0; - } - - return AUDIO_CLIENT_SUCCESS; -} - -void AudioContainerClientBase::HandleCapturePositionCallbacksGa(size_t bytesRead) -{ - mTotalBytesRead += bytesRead; - CHECK_AND_RETURN_LOG(mFrameSize != 0, "capturerPeriodPositionCb not set"); - - uint64_t readFrameNumber = mTotalBytesRead / mFrameSize; - if (!mMarkReached && mCapturePositionCb) { - if (readFrameNumber >= mFrameMarkPosition) { - mCapturePositionCb->OnMarkReached(mFrameMarkPosition); - mPositionCBThreads.emplace_back(std::make_unique(&CapturerPositionCallback::OnMarkReached, - mCapturePositionCb, mFrameMarkPosition)); - mMarkReached = true; - } - } - - if (mCapturePeriodPositionCb) { - mFramePeriodRead += (bytesRead / mFrameSize); - if (mFramePeriodRead >= mFramePeriodNumber) { - mCapturePeriodPositionCb->OnPeriodReached(mFramePeriodNumber); - mFramePeriodRead %= mFramePeriodNumber; - mPeriodPositionCBThreads.emplace_back(std::make_unique( - &CapturerPeriodPositionCallback::OnPeriodReached, mCapturePeriodPositionCb, mFramePeriodNumber)); - } - } -} - -int32_t AudioContainerClientBase::ReadStreamGa(StreamBuffer &stream, bool isBlocking, const int32_t &trackId) -{ - lock_guard lock(dataMutex_); - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool tmp = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(tmp, AUDIO_CLIENT_ERR, "WriteInterfaceToken failed"); - data.WriteInt32(static_cast(stream.bufferLen)); - data.WriteInt32(trackId); - int32_t error = Remote()->SendRequest(CMD_READ_STREAM, data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_CLIENT_ERR, - "ReadStreamGa() failed, error: %{public}d", error); - reply.ReadUint32(stream.bufferLen); - size_t readSize = static_cast(stream.bufferLen); - - const uint8_t *buffer = reply.ReadBuffer(readSize); - memcpy_s(stream.buffer, readSize, buffer, readSize); - return readSize; -} - -int32_t AudioContainerClientBase::ReleaseStreamGa(const int32_t &trackId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool tmp = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(tmp, AUDIO_CLIENT_ERR, "WriteInterfaceToken failed"); - - data.WriteInt32(trackId); - int32_t error = Remote()->SendRequest(CMD_RELEASE_AUDIOSTREAM, data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_CLIENT_ERR, - "ReleaseStreamGa() failed, error: %{public}d", error); - - ResetPAAudioClientGa(); - state_ = RELEASED; - - std::shared_ptr streamCb = streamCallback_.lock(); - if (streamCb != nullptr) { - streamCb->OnStateChange(state_); - } - - return AUDIO_CLIENT_SUCCESS; -} - -int32_t AudioContainerClientBase::GetMinimumBufferSizeGa(size_t &minBufferSize, const int32_t &trackId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool tmp = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(tmp, AUDIO_CLIENT_ERR, "WriteInterfaceToken failed"); - data.WriteInt32(trackId); - int32_t error = Remote()->SendRequest(CMD_GET_MINIMUM_BUFFERSIZE, data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_CLIENT_ERR, - "GetMinimumBufferSizeGa() failed, error: %{public}d", error); - - minBufferSize = static_cast(reply.ReadInt64()); - - return AUDIO_CLIENT_SUCCESS; -} - -int32_t AudioContainerClientBase::GetMinimumFrameCountGa(uint32_t &frameCount, const int32_t &trackId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool tmp = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(tmp, AUDIO_CLIENT_ERR, "WriteInterfaceToken failed"); - data.WriteInt32(trackId); - int32_t error = Remote()->SendRequest(CMD_GET_MINIMUM_FRAMECOUNT, data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_CLIENT_ERR, - "GetMinimumFrameCountGa() failed, error: %{public}d", error); - - reply.ReadUint32(frameCount); - - return AUDIO_CLIENT_SUCCESS; -} - -int32_t AudioContainerClientBase::SetBufferSizeInMsecGa(int32_t bufferSizeInMsec) -{ - return AUDIO_CLIENT_SUCCESS; -} - -uint32_t AudioContainerClientBase::GetSamplingRateGa() const -{ - return DEFAULT_SAMPLING_RATE; -} - -uint8_t AudioContainerClientBase::GetChannelCountGa() const -{ - return DEFAULT_CHANNEL_COUNT; -} - -uint8_t AudioContainerClientBase::GetSampleSizeGa() const -{ - return DEFAULT_SAMPLE_SIZE; -} - -int32_t AudioContainerClientBase::GetAudioStreamParamsGa(AudioStreamParams &audioParams, const int32_t &trackId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool tmp = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(tmp, AUDIO_CLIENT_ERR, "WriteInterfaceToken failed"); - data.WriteInt32(trackId); - int32_t error = Remote()->SendRequest(CMD_GET_AUDIOSTREAM_PARAMS, data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_CLIENT_ERR, - "GetAudioStreamParamsGa() failed, error: %{public}d", error); - - reply.ReadUint32(audioParams.samplingRate); - reply.ReadUint8(audioParams.encoding); - reply.ReadUint8(audioParams.format); - reply.ReadUint8(audioParams.channels); - return AUDIO_CLIENT_SUCCESS; -} - -float AudioContainerClientBase::GetStreamVolumeGa() -{ - return mVolumeFactor; -} - -uint32_t AudioContainerClientBase::GetStreamVolumeGa(uint32_t sessionID) -{ - return DEFAULT_STREAM_VOLUME; -} - -int32_t AudioContainerClientBase::SetStreamVolumeGa(float volume, const int32_t &trackId) -{ - lock_guard lock(ctrlMutex_); - CHECK_AND_RETURN_RET((volume >= MIN_STREAM_VOLUME_LEVEL) && (volume <= MAX_STREAM_VOLUME_LEVEL), - AUDIO_CLIENT_INVALID_PARAMS_ERR); - mVolumeFactor = volume; - int32_t systemVolumeLevel = mAudioSystemMgr->GetVolume(static_cast(mStreamType)); - float systemVolumeDb = VolumeToDb(systemVolumeLevel); - float vol = systemVolumeDb * mVolumeFactor; - - AudioRingerMode ringerMode = mAudioSystemMgr->GetRingerMode(); - if ((mStreamType == STREAM_RING) && (ringerMode != RINGER_MODE_NORMAL)) { - vol = MIN_STREAM_VOLUME_LEVEL; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool tmp = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(tmp, AUDIO_CLIENT_ERR, "WriteInterfaceToken failed"); - data.WriteFloat(vol); - data.WriteInt32(trackId); - int32_t error = Remote()->SendRequest(CMD_SET_STREAM_VOLUME, data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_CLIENT_ERR, - "SetStreamVolumeGa() failed, error: %{public}d", error); - - return AUDIO_CLIENT_SUCCESS; -} - -int32_t AudioContainerClientBase::GetCurrentTimeStampGa(uint64_t ×tamp, const int32_t &trackId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool tmp = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(tmp, AUDIO_CLIENT_ERR, "WriteInterfaceToken failed"); - data.WriteInt32(trackId); - int32_t error = Remote()->SendRequest(CMD_GET_CURRENT_TIMESTAMP, data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_CLIENT_ERR, - "GetCurrentTimeStampGa() failed, error: %{public}d", error); - - reply.ReadUint64(timestamp); - - return AUDIO_CLIENT_SUCCESS; -} - -int32_t AudioContainerClientBase::GetAudioLatencyGa(uint64_t &latency, const int32_t &trackId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool tmp = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(tmp, AUDIO_CLIENT_ERR, "WriteInterfaceToken failed"); - data.WriteInt32(trackId); - int32_t error = Remote()->SendRequest(CMD_GET_AUDIO_LATENCY, data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, AUDIO_CLIENT_ERR, - "GetAudioLatencyGa() failed, error: %{public}d", error); - - reply.ReadUint64(latency); - - return AUDIO_CLIENT_SUCCESS; -} - -void AudioContainerClientBase::RegisterAudioRendererCallbackGa(const AudioRendererCallback &cb) -{ - AUDIO_DEBUG_LOG("Registering audio render callbacks"); - mAudioRendererCallbacks = (AudioRendererCallback *)&cb; -} - -void AudioContainerClientBase::RegisterAudioCapturerCallbackGa(const AudioCapturerCallback &cb) -{ - AUDIO_DEBUG_LOG("Registering audio recorder callbacks"); - mAudioCapturerCallbacks = (AudioCapturerCallback *)&cb; -} - -void AudioContainerClientBase::SetRendererPositionCallbackGa(int64_t markPosition, - const std::shared_ptr &callback) -{ - mFrameMarkPosition = markPosition; - mRenderPositionCb = callback; -} - -void AudioContainerClientBase::UnsetRendererPositionCallbackGa() -{ - mRenderPositionCb = nullptr; - mMarkReached = false; - mFrameMarkPosition = 0; -} - -void AudioContainerClientBase::SetRendererPeriodPositionCallbackGa(int64_t periodPosition, - const std::shared_ptr &callback) -{ - mFramePeriodNumber = periodPosition; - if (mFrameSize != 0 && mFramePeriodNumber != 0) { - mFramePeriodWritten = (mTotalBytesWritten / mFrameSize) % mFramePeriodNumber; - } else { - return; - } - - mRenderPeriodPositionCb = callback; -} - -void AudioContainerClientBase::UnsetRendererPeriodPositionCallbackGa() -{ - mRenderPeriodPositionCb = nullptr; - mFramePeriodWritten = 0; - mFramePeriodNumber = 0; -} - -void AudioContainerClientBase::SetCapturerPositionCallbackGa(int64_t markPosition, - const std::shared_ptr &callback) -{ - mFrameMarkPosition = markPosition; - mCapturePositionCb = callback; -} - -void AudioContainerClientBase::UnsetCapturerPositionCallbackGa() -{ - mCapturePositionCb = nullptr; - mMarkReached = false; - mFrameMarkPosition = 0; -} - -void AudioContainerClientBase::SetCapturerPeriodPositionCallbackGa(int64_t periodPosition, - const std::shared_ptr &callback) -{ - mFramePeriodNumber = periodPosition; - if (mFrameSize != 0 && mFramePeriodNumber != 0) { - mFramePeriodRead = (mTotalBytesRead / mFrameSize) % mFramePeriodNumber; - } else { - return; - } - - mCapturePeriodPositionCb = callback; -} - -void AudioContainerClientBase::UnsetCapturerPeriodPositionCallbackGa() -{ - mCapturePeriodPositionCb = nullptr; - mFramePeriodRead = 0; - mFramePeriodNumber = 0; -} - -int32_t AudioContainerClientBase::SetStreamTypeGa(AudioStreamType audioStreamType, const int32_t &trackId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool tmp = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(tmp, AUDIO_CLIENT_ERR, "WriteInterfaceToken failed"); - - data.WriteInt32(static_cast(audioStreamType)); - data.WriteInt32(trackId); - int32_t error = Remote()->SendRequest(CMD_SET_STREAM_TYPE, data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, - "SetStreamTypeGa() failed, error: %{public}d", error); - - return AUDIO_CLIENT_SUCCESS; -} - -int32_t AudioContainerClientBase::SetStreamRenderRateGa(AudioRendererRate audioRendererRate, const int32_t &trackId) -{ - renderRate = audioRendererRate; - uint32_t rate = renderRate; - - MessageParcel data; - MessageParcel reply; - MessageOption option; - bool tmp = data.WriteInterfaceToken(GetDescriptor()); - CHECK_AND_RETURN_RET_LOG(tmp, AUDIO_CLIENT_ERR, "WriteInterfaceToken failed"); - - data.WriteUint32(rate); - data.WriteInt32(trackId); - int32_t error = Remote()->SendRequest(CMD_SET_STREAM_RENDER_RATE, data, reply, option); - CHECK_AND_RETURN_RET_LOG(error == ERR_NONE, - "SetStreamRenderRateGa() failed, error: %{public}d", error); - - return AUDIO_CLIENT_SUCCESS; -} - -AudioRendererRate AudioContainerClientBase::GetStreamRenderRateGa() -{ - return renderRate; -} - -void AudioContainerClientBase::SaveStreamCallbackGa(const std::weak_ptr &callback) -{ - streamCallback_ = callback; - - if (state_ != PREPARED) { - return; - } - - std::shared_ptr streamCb = streamCallback_.lock(); - if (streamCb != nullptr) { - streamCb->OnStateChange(state_); - } -} - -int32_t AudioContainerClientBase::SetAudioCaptureMode(AudioCaptureMode captureMode) -{ - return AUDIO_CLIENT_SUCCESS; -} - -int32_t AudioContainerClientBase::SaveReadCallback(const std::weak_ptr &callback) -{ - return AUDIO_CLIENT_SUCCESS; -} - -AudioCaptureMode AudioContainerClientBase::GetAudioCaptureMode() -{ - return AudioCaptureMode::CAPTURE_MODE_NORMAL; -} - -void AudioContainerClientBase::SetAppCachePath(const std::string cachePath) -{ - AUDIO_INFO_LOG("cachePath %{public}s", cachePath.c_str()); -} -} // namespace AudioStandard -} // namespace OHOS - diff --git a/frameworks/native/audiocompatibility/src/audio_container_stream_base.cpp b/frameworks/native/audiocompatibility/src/audio_container_stream_base.cpp deleted file mode 100644 index 1e4aef2dfaa4ffcd8dba8d51a619c3e28970e797..0000000000000000000000000000000000000000 --- a/frameworks/native/audiocompatibility/src/audio_container_stream_base.cpp +++ /dev/null @@ -1,1154 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#undef LOG_TAG -#define LOG_TAG "AudioContainerStreamBase" - -#include -#include -#include - -#include "audio_errors.h" -#include "audio_info.h" -#include "audio_log.h" -#include "audio_container_stream_base.h" -#include "audio_policy_manager.h" -#include "audio_container_client_base.h" - -using namespace std; - -namespace OHOS { -namespace AudioStandard { -const unsigned long long TIME_CONVERSION_US_S = 1000000ULL; /* us to s */ -const unsigned long long TIME_CONVERSION_NS_US = 1000ULL; /* ns to us */ -const unsigned long long TIME_CONVERSION_NS_S = 1000000000ULL; /* ns to s */ -constexpr int32_t WRITE_RETRY_DELAY_IN_US = 500; -constexpr int32_t READ_WRITE_WAIT_TIME_IN_US = 500; -constexpr int32_t CB_WRITE_BUFFERS_WAIT_IN_US = 500; -constexpr int32_t CB_READ_BUFFERS_WAIT_IN_US = 500; -constexpr int32_t AUDIO_RENDERER_SERVICE_GATEWAY_ID = 13011; -constexpr int32_t AUDIO_CAPTURER_SERVICE_GATEWAY_ID = 13013; - - -const map, AudioStreamType> AudioContainerStreamBase::streamTypeMap_ = - AudioContainerStreamBase::CreateStreamMap(); - -map, AudioStreamType> AudioContainerStreamBase::CreateStreamMap() -{ - map, AudioStreamType> streamMap; - - streamMap[make_pair(CONTENT_TYPE_UNKNOWN, STREAM_USAGE_UNKNOWN)] = STREAM_MUSIC; - streamMap[make_pair(CONTENT_TYPE_UNKNOWN, STREAM_USAGE_MEDIA)] = STREAM_MUSIC; - streamMap[make_pair(CONTENT_TYPE_UNKNOWN, STREAM_USAGE_VOICE_COMMUNICATION)] = STREAM_MUSIC; - streamMap[make_pair(CONTENT_TYPE_UNKNOWN, STREAM_USAGE_VIDEO_COMMUNICATION)] = STREAM_VOICE_CALL; - streamMap[make_pair(CONTENT_TYPE_UNKNOWN, STREAM_USAGE_VOICE_ASSISTANT)] = STREAM_MUSIC; - streamMap[make_pair(CONTENT_TYPE_UNKNOWN, STREAM_USAGE_NOTIFICATION_RINGTONE)] = STREAM_MUSIC; - - streamMap[make_pair(CONTENT_TYPE_SPEECH, STREAM_USAGE_UNKNOWN)] = STREAM_MUSIC; - streamMap[make_pair(CONTENT_TYPE_SPEECH, STREAM_USAGE_MEDIA)] = STREAM_VOICE_ASSISTANT; - streamMap[make_pair(CONTENT_TYPE_SPEECH, STREAM_USAGE_VOICE_COMMUNICATION)] = STREAM_VOICE_CALL; - streamMap[make_pair(CONTENT_TYPE_SPEECH, STREAM_USAGE_VIDEO_COMMUNICATION)] = STREAM_VOICE_CALL; - streamMap[make_pair(CONTENT_TYPE_SPEECH, STREAM_USAGE_VOICE_ASSISTANT)] = STREAM_VOICE_ASSISTANT; - streamMap[make_pair(CONTENT_TYPE_SPEECH, STREAM_USAGE_NOTIFICATION_RINGTONE)] = STREAM_MUSIC; - - streamMap[make_pair(CONTENT_TYPE_MUSIC, STREAM_USAGE_UNKNOWN)] = STREAM_MUSIC; - streamMap[make_pair(CONTENT_TYPE_MUSIC, STREAM_USAGE_MEDIA)] = STREAM_MUSIC; - streamMap[make_pair(CONTENT_TYPE_MUSIC, STREAM_USAGE_VOICE_COMMUNICATION)] = STREAM_MUSIC; - streamMap[make_pair(CONTENT_TYPE_MUSIC, STREAM_USAGE_VOICE_ASSISTANT)] = STREAM_VOICE_ASSISTANT; - streamMap[make_pair(CONTENT_TYPE_MUSIC, STREAM_USAGE_NOTIFICATION_RINGTONE)] = STREAM_RING; - - streamMap[make_pair(CONTENT_TYPE_MOVIE, STREAM_USAGE_UNKNOWN)] = STREAM_MEDIA; - streamMap[make_pair(CONTENT_TYPE_MOVIE, STREAM_USAGE_MEDIA)] = STREAM_MEDIA; - streamMap[make_pair(CONTENT_TYPE_MOVIE, STREAM_USAGE_VOICE_COMMUNICATION)] = STREAM_MUSIC; - streamMap[make_pair(CONTENT_TYPE_MOVIE, STREAM_USAGE_VOICE_ASSISTANT)] = STREAM_MUSIC; - streamMap[make_pair(CONTENT_TYPE_MOVIE, STREAM_USAGE_NOTIFICATION_RINGTONE)] = STREAM_MUSIC; - - streamMap[make_pair(CONTENT_TYPE_SONIFICATION, STREAM_USAGE_UNKNOWN)] = STREAM_NOTIFICATION; - streamMap[make_pair(CONTENT_TYPE_SONIFICATION, STREAM_USAGE_MEDIA)] = STREAM_NOTIFICATION; - streamMap[make_pair(CONTENT_TYPE_SONIFICATION, STREAM_USAGE_VOICE_COMMUNICATION)] = STREAM_MUSIC; - streamMap[make_pair(CONTENT_TYPE_SONIFICATION, STREAM_USAGE_VOICE_ASSISTANT)] = STREAM_MUSIC; - streamMap[make_pair(CONTENT_TYPE_SONIFICATION, STREAM_USAGE_NOTIFICATION_RINGTONE)] = STREAM_MUSIC; - - streamMap[make_pair(CONTENT_TYPE_RINGTONE, STREAM_USAGE_UNKNOWN)] = STREAM_RING; - streamMap[make_pair(CONTENT_TYPE_RINGTONE, STREAM_USAGE_MEDIA)] = STREAM_RING; - streamMap[make_pair(CONTENT_TYPE_RINGTONE, STREAM_USAGE_VOICE_COMMUNICATION)] = STREAM_MUSIC; - streamMap[make_pair(CONTENT_TYPE_RINGTONE, STREAM_USAGE_VOICE_ASSISTANT)] = STREAM_MUSIC; - streamMap[make_pair(CONTENT_TYPE_RINGTONE, STREAM_USAGE_NOTIFICATION_RINGTONE)] = STREAM_RING; - - return streamMap; -} - -AudioContainerStreamBase::AudioContainerStreamBase(AudioStreamType eStreamType, AudioMode eMode) - : eStreamType_(eStreamType), - eMode_(eMode), - state_(NEW), - isReadInProgress_(false), - isWriteInProgress_(false), - resetTime_(false), - resetTimestamp_(0), - renderMode_(RENDER_MODE_NORMAL), - captureMode_(CAPTURE_MODE_NORMAL), - isReadyToWrite_(false), - isReadyToRead_(false), - isFirstRead_(false) -{ - AUDIO_DEBUG_LOG("AudioContainerStreamBase::AudioContainerStreamBase"); -} - -AudioContainerStreamBase::~AudioContainerStreamBase() -{ - isReadyToWrite_ = false; - isReadyToRead_ = false; - - if (writeThread_ && writeThread_->joinable()) { - writeThread_->join(); - } - - if (readThread_ && readThread_->joinable()) { - readThread_->join(); - } - - if (state_ != RELEASED && state_ != NEW) { - ReleaseAudioStream(); - } -} - -State AudioContainerStreamBase::GetState() -{ - return state_; -} - -int32_t AudioContainerStreamBase::GetAudioSessionID(uint32_t &sessionID) const -{ - CHECK_AND_RETURN_RET((state_ != RELEASED) && (state_ != NEW), ERR_ILLEGAL_STATE); - int32_t sessionID = GetSessionID(sessionID, trackId_); - CHECK_AND_RETURN_RET(sessionID == 0, ERR_INVALID_INDEX); - - return SUCCESS; -} - -bool AudioContainerStreamBase::GetAudioTime(Timestamp ×tamp, Timestamp::Timestampbase base) -{ - uint64_t paTimeStamp = 0; - if (GetCurrentTimeStamp(paTimeStamp, trackId_) == SUCCESS) { - if (resetTime_) { - AUDIO_INFO_LOG("resetTime_ %{public}d", resetTime_); - resetTime_ = false; - resetTimestamp_ = paTimeStamp; - } - - timestamp.time.tv_sec = static_cast((paTimeStamp - resetTimestamp_) / TIME_CONVERSION_US_S); - timestamp.time.tv_nsec = static_cast(((paTimeStamp - resetTimestamp_) - - (timestamp.time.tv_sec * TIME_CONVERSION_US_S)) * TIME_CONVERSION_NS_US); - timestamp.time.tv_sec += baseTimestamp_.tv_sec; - timestamp.time.tv_nsec += baseTimestamp_.tv_nsec; - timestamp.time.tv_sec += (timestamp.time.tv_nsec / TIME_CONVERSION_NS_S); - timestamp.time.tv_nsec = (timestamp.time.tv_nsec % TIME_CONVERSION_NS_S); - - return true; - } - return false; -} - -int32_t AudioContainerStreamBase::GetBufferSize(size_t &bufferSize) const -{ - if (GetMinimumBufferSize(bufferSize, trackId_) != 0) { - return ERR_OPERATION_FAILED; - } - int rate = 1; - if (renderRate_ == RENDER_RATE_DOUBLE) { - rate = 1; - } - bufferSize = bufferSize * rate; - return SUCCESS; -} - -int32_t AudioContainerStreamBase::GetFrameCount(uint32_t &frameCount) const -{ - AUDIO_INFO_LOG("Get frame count"); - if (GetMinimumFrameCount(frameCount, trackId_) != 0) { - return ERR_OPERATION_FAILED; - } - - return SUCCESS; -} - -int32_t AudioContainerStreamBase::GetLatency(uint64_t &latency) const -{ - if (GetAudioLatency(latency, trackId_) != SUCCESS) { - return ERR_OPERATION_FAILED; - } else { - return SUCCESS; - } -} - -vector AudioContainerStreamBase::GetSupportedFormats() const -{ - return AUDIO_SUPPORTED_FORMATS; -} - -vector AudioContainerStreamBase::GetSupportedEncodingTypes() const -{ - return AUDIO_SUPPORTED_ENCODING_TYPES; -} - -vector AudioContainerStreamBase::GetSupportedSamplingRates() const -{ - return AUDIO_SUPPORTED_SAMPLING_RATES; -} - -bool IsFormatValid(uint8_t format) -{ - bool isValidFormat = (find(AUDIO_SUPPORTED_FORMATS.begin(), AUDIO_SUPPORTED_FORMATS.end(), format) - != AUDIO_SUPPORTED_FORMATS.end()); - AUDIO_DEBUG_LOG("IsFormatValid: %{public}s", isValidFormat ? "true" : "false"); - return isValidFormat; -} - -bool IsRendererChannelValid(uint8_t channel) -{ - bool isValidChannel = (find(RENDERER_SUPPORTED_CHANNELS.begin(), RENDERER_SUPPORTED_CHANNELS.end(), channel) - != RENDERER_SUPPORTED_CHANNELS.end()); - AUDIO_DEBUG_LOG("IsChannelValid: %{public}s", isValidChannel ? "true" : "false"); - return isValidChannel; -} - -bool IsCapturerChannelValid(uint8_t channel) -{ - bool isValidChannel = (find(CAPTURER_SUPPORTED_CHANNELS.begin(), CAPTURER_SUPPORTED_CHANNELS.end(), channel) - != CAPTURER_SUPPORTED_CHANNELS.end()); - AUDIO_DEBUG_LOG("IsChannelValid: %{public}s", isValidChannel ? "true" : "false"); - return isValidChannel; -} - -bool IsEncodingTypeValid(uint8_t encodingType) -{ - bool isValidEncodingType = (find(AUDIO_SUPPORTED_ENCODING_TYPES.begin(), AUDIO_SUPPORTED_ENCODING_TYPES.end(), - encodingType) != AUDIO_SUPPORTED_ENCODING_TYPES.end()); - AUDIO_DEBUG_LOG("IsEncodingTypeValid: %{public}s", - isValidEncodingType ? "true" : "false"); - return isValidEncodingType; -} - -bool IsSamplingRateValid(uint32_t samplingRate) -{ - bool isValidSamplingRate = (find(AUDIO_SUPPORTED_SAMPLING_RATES.begin(), AUDIO_SUPPORTED_SAMPLING_RATES.end(), - samplingRate) != AUDIO_SUPPORTED_SAMPLING_RATES.end()); - AUDIO_DEBUG_LOG("IsSamplingRateValid: %{public}s", - isValidSamplingRate ? "true" : "false"); - return isValidSamplingRate; -} - -int32_t AudioContainerStreamBase::GetAudioStreamInfo(AudioStreamParams &audioStreamInfo) -{ - bool tmp = GetAudioStreamParams(audioStreamInfo, trackId_); - CHECK_AND_RETURN_RET(tmp == 0, ERR_OPERATION_FAILED); - - return SUCCESS; -} - -bool AudioContainerStreamBase::VerifyClientPermission(const std::string &permissionName, uint32_t appTokenId, - int32_t appUid, AudioPermissionState state) -{ - bool tmp = AudioPolicyManager::GetInstance().VerifyClientPermission(permissionName, appTokenId, appUid, state); - CHECK_AND_RETURN_RET_LOG(tmp, false, "Client doesn't have MICROPHONE permission"); - return true; -} - -int32_t AudioContainerStreamBase::SetAudioStreamInfo(const AudioStreamParams info) -{ - CHECK_AND_RETURN_RET_LOG(IsFormatValid(info.format) && IsSamplingRateValid(info.samplingRate) && - IsEncodingTypeValid(info.encoding), ERR_NOT_SUPPORTED, "Unsupported audio parameter"); - sample_rate_ = info.samplingRate; - format_ = info.format; - channelCount_ = info.channels; - if (state_ != NEW) { - AUDIO_DEBUG_LOG("State is not new, release existing stream"); - StopAudioStream(); - ReleaseAudioStream(); - } - - int32_t ret = 0; - switch (eMode_) { - case AUDIO_MODE_PLAYBACK: - AUDIO_ERR_LOG("Initialize playback"); - CHECK_AND_RETURN_RET_LOG(IsRendererChannelValid(info.channels), ERR_NOT_SUPPORTED, - "Invalid sink channel %{public}d", info.channels); - ret = Initialize(AUDIO_SERVICE_CLIENT_PLAYBACK, AUDIO_RENDERER_SERVICE_GATEWAY_ID); - break; - case AUDIO_MODE_RECORD: - AUDIO_ERR_LOG("Initialize recording"); - CHECK_AND_RETURN_RET_LOG(IsCapturerChannelValid(info.channels), ERR_NOT_SUPPORTED, - "Invalid source channel %{public}d", info.channels); - ret = Initialize(AUDIO_SERVICE_CLIENT_RECORD, AUDIO_CAPTURER_SERVICE_GATEWAY_ID); - break; - default: - return ERR_INVALID_OPERATION; - } - - CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ret, "Error initializing!"); - trackId_ = CreateStream(info, eStreamType_); - CHECK_AND_RETURN_RET_LOG(trackId_ >= 0, ERROR, "Create stream failed"); - - state_ = PREPARED; - AUDIO_INFO_LOG("CreateStream trackId_ %{public}d", trackId_); - return SUCCESS; -} - -bool AudioContainerStreamBase::StartAudioStream() -{ - CHECK_AND_RETURN_RET_LOG((state_ == PREPARED) || (state_ == STOPPED) || (state_ == PAUSED), - false, "Illegal state:%{public}u", state_); - - int32_t ret = StartStream(trackId_); - CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, false, "Start failed:%{public}d", ret); - - resetTime_ = true; - int32_t retCode = clock_gettime(CLOCK_MONOTONIC, &baseTimestamp_); - if (retCode != 0) { - AUDIO_WARNING_LOG("get system elapsed time failed: %d", retCode); - } - - if (renderMode_ == RENDER_MODE_CALLBACK) { - isReadyToWrite_ = true; - if (writeThread_ == nullptr) { - writeThread_ = std::make_unique(&AudioContainerStreamBase::WriteBuffers, this); - } - } else if (captureMode_ == CAPTURE_MODE_CALLBACK) { - isReadyToRead_ = true; - readThread_ = std::make_unique(&AudioContainerStreamBase::ReadBuffers, this); - } - - isFirstRead_ = true; - state_ = RUNNING; - pthread_cond_signal(&writeCondition_); - AUDIO_INFO_LOG("SUCCESS trackId_ %{public}d", trackId_); - return true; -} - -int32_t AudioContainerStreamBase::Read(uint8_t &buffer, size_t userSize, bool isBlockingRead) -{ - CHECK_AND_RETURN_RET_LOG(userSize > 0, ERR_INVALID_PARAM, - "Invalid userSize:%{public}zu", userSize); - - CHECK_AND_RETURN_RET_LOG(state_ == RUNNING, ERR_ILLEGAL_STATE, - "State is not RUNNNIG. Illegal state:%{public}u", state_); - - if (isFirstRead_) { - FlushAudioStream(); - isFirstRead_ = false; - } - - StreamBuffer stream; - stream.buffer = &buffer; - stream.bufferLen = userSize; - isReadInProgress_ = true; - int32_t readLen = ReadStream(stream, isBlockingRead, trackId_); - isReadInProgress_ = false; - CHECK_AND_RETURN_RET_LOG(readLen >= 0, ERR_INVALID_READ, - "ReadStream fail,ret:%{public}d", readLen); - - return readLen; -} - -int32_t AudioContainerStreamBase::Write(uint8_t *buffer, size_t buffer_size) -{ - CHECK_AND_RETURN_RET_LOG(renderMode_ != RENDER_MODE_CALLBACK, ERR_INCORRECT_MODE, - "Write not supported. RenderMode is callback"); - - CHECK_AND_RETURN_RET_LOG((buffer != nullptr) && (buffer_size > 0), ERR_INVALID_PARAM, - "Invalid buffer size:%{public}zu", buffer_size); - - if (state_ != RUNNING) { - // To allow context switch for APIs running in different thread contexts - std::this_thread::sleep_for(std::chrono::microseconds(WRITE_RETRY_DELAY_IN_US)); - return ERR_ILLEGAL_STATE; - } - - int32_t writeError; - StreamBuffer stream; - stream.buffer = buffer; - stream.bufferLen = buffer_size; - isWriteInProgress_ = true; - size_t bytesWritten = WriteStream(stream, writeError, trackId_); - isWriteInProgress_ = false; - CHECK_AND_RETURN_RET_LOG(writeError == 0, ERR_WRITE_FAILED, - "WriteStream fail,writeError:%{public}d", writeError); - return bytesWritten; -} - -bool AudioContainerStreamBase::PauseAudioStream() -{ - CHECK_AND_RETURN_RET_LOG(state_ == RUNNING, false, - "State is not RUNNING. Illegal state:%{public}u", state_); - State oldState = state_; - state_ = PAUSED; // Set it before stopping as Read/Write and Stop can be called from different threads - if (captureMode_ == CAPTURE_MODE_CALLBACK) { - isReadyToRead_ = false; - if (readThread_ && readThread_->joinable()) { - readThread_->join(); - } - } - while (isReadInProgress_ || isWriteInProgress_) { - std::this_thread::sleep_for(std::chrono::microseconds(READ_WRITE_WAIT_TIME_IN_US)); - } - - int32_t ret = PauseStream(trackId_); - if (ret != SUCCESS) { - AUDIO_ERR_LOG("StreamPause fail, ret:%{public}d", ret); - state_ = oldState; - return false; - } - - // Ends the WriteBuffers thread - if (renderMode_ == RENDER_MODE_CALLBACK) { - isReadyToWrite_ = false; - } - - AUDIO_DEBUG_LOG("PauseAudioStream SUCCESS"); - - return true; -} - -bool AudioContainerStreamBase::StopAudioStream() -{ - if (state_ == PAUSED) { - state_ = STOPPED; - AUDIO_INFO_LOG("StopAudioStream SUCCESS"); - return true; - } - - CHECK_AND_RETURN_RET_LOG(state_ == RUNNING, false, - "State is not RUNNING. Illegal state:%{public}u", state_); - State oldState = state_; - state_ = STOPPED; // Set it before stopping as Read/Write and Stop can be called from different threads - if (captureMode_ == CAPTURE_MODE_CALLBACK) { - isReadyToRead_ = false; - if (readThread_ && readThread_->joinable()) { - readThread_->join(); - } - } - while (isReadInProgress_ || isWriteInProgress_) { - std::this_thread::sleep_for(std::chrono::microseconds(READ_WRITE_WAIT_TIME_IN_US)); - } - - int32_t ret = StopStream(trackId_); - if (ret != SUCCESS) { - AUDIO_ERR_LOG("StreamStop fail, ret:%{public}d", ret); - state_ = oldState; - return false; - } - - // Ends the WriteBuffers thread - if (renderMode_ == RENDER_MODE_CALLBACK) { - isReadyToWrite_ = false; - pthread_cond_signal(&writeCondition_); - } - - AUDIO_DEBUG_LOG("StopAudioStream SUCCESS"); - - return true; -} - -bool AudioContainerStreamBase::FlushAudioStream() -{ - CHECK_AND_RETURN_RET_LOG((state_ == RUNNING) || (state_ == PAUSED) || (state_ == STOPPED), - false, "State is not RUNNING. Illegal state:%{public}u", state_); - - int32_t ret = FlushStream(trackId_); - CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, false, - "Flush stream fail,ret:%{public}d", ret); - - AUDIO_DEBUG_LOG("Flush stream SUCCESS"); - return true; -} - -bool AudioContainerStreamBase::DrainAudioStream() -{ - CHECK_AND_RETURN_RET_LOG(state_ == RUNNING, false, - "State is not RUNNING. Illegal state:%{public}u", state_); - - int32_t ret = DrainStream(trackId_); - - CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, false, - "Drain stream fail,ret:%{public}d", ret); - - AUDIO_DEBUG_LOG("Drain stream SUCCESS"); - return true; -} - -bool AudioContainerStreamBase::ReleaseAudioStream() -{ - CHECK_AND_RETURN_RET_LOG(state_ != RELEASED && state_ != NEW, false, - "Illegal state: state = %{public}u", state_); - // If state_ is RUNNING try to Stop it first and Release - if (state_ == RUNNING) { - StopAudioStream(); - } - - ReleaseStream(trackId_); - state_ = RELEASED; - AUDIO_DEBUG_LOG("ReleaseAudiostream SUCCESS"); - pthread_cond_signal(&writeCondition_); - - return true; -} - -AudioStreamType AudioContainerStreamBase::GetStreamType(ContentType contentType, StreamUsage streamUsage) -{ - AudioStreamType streamType = STREAM_MUSIC; - auto pos = streamTypeMap_.find(make_pair(contentType, streamUsage)); - if (pos != streamTypeMap_.end()) { - streamType = pos->second; - } - - if (streamType == STREAM_MEDIA) { - streamType = STREAM_MUSIC; - } - - return streamType; -} - -int32_t AudioContainerStreamBase::SetAudioStreamType(AudioStreamType audioStreamType) -{ - return SetStreamType(audioStreamType, trackId_); -} - -int32_t AudioContainerStreamBase::SetVolume(float volume) -{ - return SetStreamVolume(volume, trackId_); -} - -float AudioContainerStreamBase::GetVolume() -{ - return GetStreamVolume(); -} - -int32_t AudioContainerStreamBase::SetRenderRate(AudioRendererRate renderRate) -{ - switch (renderRate) { - case RENDER_RATE_NORMAL: - case RENDER_RATE_DOUBLE: - case RENDER_RATE_HALF: - break; - default: - return AUDIO_CLIENT_INVALID_PARAMS_ERR; - } - renderRate_ = renderRate; - return SetStreamRenderRate(renderRate, trackId_); -} - -AudioRendererRate AudioContainerStreamBase::GetRenderRate() -{ - return GetStreamRenderRate(); -} - -int32_t AudioContainerStreamBase::SetStreamCallback(const std::shared_ptr &callback) -{ - CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERR_INVALID_PARAM, - "setStreamCallback failed. callback == nullptr"); - - SaveStreamCallback(callback); - - return SUCCESS; -} - -int32_t AudioContainerStreamBase::SetRenderMode(AudioRenderMode renderMode) -{ - int32_t ret = SetAudioRenderMode(renderMode, trackId_); - CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ERR_OPERATION_FAILED, - "renderMode: %{public}d failed", renderMode); - renderMode_ = renderMode; - - for (int32_t i = 0; i < MAX_LEN_BUFFERS; ++i) { - size_t length; - GetMinimumBufferSize(length, trackId_); - AUDIO_DEBUG_LOG("GetMinimumBufferSize: %{public}zu", length); - - bufferPool_[i] = std::make_unique(length); - CHECK_AND_RETURN_RET_LOG(bufferPool_[i] != nullptr, ERR_OPERATION_FAILED, - "GetBufferDescriptor bufferPool_[i]==nullptr. Allocate memory failed."); - - BufferDesc bufDesc {}; - bufDesc.buffer = bufferPool_[i].get(); - bufDesc.bufLength = length; - freeBufferQ_.emplace(bufDesc); - } - - return SUCCESS; -} - -AudioRenderMode AudioContainerStreamBase::GetRenderMode() -{ - return GetAudioRenderMode(); -} - -int32_t AudioContainerStreamBase::SetCaptureMode(AudioCaptureMode captureMode) -{ - int32_t ret = SetAudioCaptureMode(captureMode); - CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ERR_OPERATION_FAILED, - "captureMode: %{public}d failed", captureMode); - captureMode_ = captureMode; - - for (int32_t i = 0; i < MAX_LEN_BUFFERS; ++i) { - size_t length; - GetMinimumBufferSize(length, trackId_); - AUDIO_DEBUG_LOG("length %{public}zu", length); - - bufferPool_[i] = std::make_unique(length); - CHECK_AND_RETURN_RET_LOG(bufferPool_[i] != nullptr, ERR_OPERATION_FAILED, - "bufferPool_[i]==nullptr. Allocate memory failed."); - - BufferDesc bufDesc {}; - bufDesc.buffer = bufferPool_[i].get(); - bufDesc.bufLength = length; - freeBufferQ_.emplace(bufDesc); - } - - return SUCCESS; -} - -AudioCaptureMode AudioContainerStreamBase::GetCaptureMode() -{ - return GetAudioCaptureMode(); -} - -int32_t AudioContainerStreamBase::SetRendererWriteCallback(const std::shared_ptr &callback) -{ - CHECK_AND_RETURN_RET_LOG(renderMode_ == RENDER_MODE_CALLBACK, ERR_INCORRECT_MODE, - "SetRendererWriteCallback not supported. Render mode is not callback."); - - callback_ = callback; - return SUCCESS; -} - -int32_t AudioContainerStreamBase::SetCapturerReadCallback(const std::shared_ptr &callback) -{ - CHECK_AND_RETURN_RET_LOG(captureMode_ == CAPTURE_MODE_CALLBACK, ERR_INCORRECT_MODE, - "SetCapturerReadCallback not supported. Capture mode is not callback."); - - int32_t ret = SaveReadCallback(callback); - CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ERR_INVALID_PARAM, - "SetCapturerReadCallback: failed."); - - return SUCCESS; -} - -int32_t AudioContainerStreamBase::GetBufferDesc(BufferDesc &bufDesc) -{ - CHECK_AND_RETURN_RET_LOG((renderMode_ == RENDER_MODE_CALLBACK) || (captureMode_ == CAPTURE_MODE_CALLBACK), - ERR_INCORRECT_MODE, "GetBufferDesc not supported. Render or Capture mode is not callback."); - - AUDIO_INFO_LOG("filledBufferQ_ count %{public}zu, freeBufferQ_ count %{public}zu", - filledBufferQ_.size(), freeBufferQ_.size()); - - lock_guard lock(mBufferQueueLock); - if (renderMode_ == RENDER_MODE_CALLBACK) { - if (!freeBufferQ_.empty()) { - bufDesc.buffer = freeBufferQ_.front().buffer; - bufDesc.bufLength = freeBufferQ_.front().bufLength; - freeBufferQ_.pop(); - } else { - bufDesc.buffer = nullptr; - AUDIO_ERR_LOG("GetBufferDesc freeBufferQ_.empty()"); - return ERR_OPERATION_FAILED; - } - } - - if (captureMode_ == CAPTURE_MODE_CALLBACK) { - if (!filledBufferQ_.empty()) { - bufDesc.buffer = filledBufferQ_.front().buffer; - bufDesc.bufLength = filledBufferQ_.front().bufLength; - bufDesc.dataLength = filledBufferQ_.front().dataLength; - filledBufferQ_.pop(); - } else { - bufDesc.buffer = nullptr; - AUDIO_ERR_LOG("GetBufferDesc filledBufferQ_.empty()"); - return ERR_OPERATION_FAILED; - } - } - return SUCCESS; -} - -int32_t AudioContainerStreamBase::GetBufQueueState(BufferQueueState &bufState) -{ - CHECK_AND_RETURN_RET_LOG((renderMode_ == RENDER_MODE_CALLBACK) || (captureMode_ == CAPTURE_MODE_CALLBACK), - ERR_INCORRECT_MODE, "GetBufQueueState not supported. Render or Capture mode is not callback."); - - lock_guard lock(mBufferQueueLock); - if (renderMode_ == RENDER_MODE_CALLBACK) { - AUDIO_DEBUG_LOG("bufferlength: %{public}zu.", filledBufferQ_.size()); - bufState.numBuffers = filledBufferQ_.size(); - } - - if (captureMode_ == CAPTURE_MODE_CALLBACK) { - bufState.numBuffers = freeBufferQ_.size(); - } - - return SUCCESS; -} - -int32_t AudioContainerStreamBase::Enqueue(const BufferDesc &bufDesc) -{ - AUDIO_DEBUG_LOG("AudioContainerStreamBase::Enqueue"); - CHECK_AND_RETURN_RET_LOG((renderMode_ == RENDER_MODE_CALLBACK) || (captureMode_ == CAPTURE_MODE_CALLBACK), - ERR_INCORRECT_MODE, "not supported. Render or capture mode is not callback."); - - CHECK_AND_RETURN_RET_LOG(bufDesc.buffer != nullptr, ERR_INVALID_PARAM, - "failed. bufDesc.buffer == nullptr."); - - lock_guard lock(mBufferQueueLock); - if (renderMode_ == RENDER_MODE_CALLBACK) { - AUDIO_INFO_LOG("filledBuffer length: %{public}zu.", bufDesc.bufLength); - filledBufferQ_.emplace(bufDesc); - } - - if (captureMode_ == CAPTURE_MODE_CALLBACK) { - AUDIO_INFO_LOG("freeBuffer length: %{public}zu.", bufDesc.bufLength); - freeBufferQ_.emplace(bufDesc); - } - - return SUCCESS; -} - -int32_t AudioContainerStreamBase::Clear() -{ - CHECK_AND_RETURN_RET_LOG((renderMode_ == RENDER_MODE_CALLBACK) || (captureMode_ == CAPTURE_MODE_CALLBACK), - ERR_INCORRECT_MODE, "Clear not supported. Render or capture mode is not callback."); - - lock_guard lock(mBufferQueueLock); - while (!filledBufferQ_.empty()) { - freeBufferQ_.emplace(filledBufferQ_.front()); - filledBufferQ_.pop(); - } - - return SUCCESS; -} - -void AudioContainerStreamBase::WriteBuffers() -{ - StreamBuffer stream; - size_t bytesWritten; - int32_t writeError; - int rate = 1; - while (isReadyToWrite_) { - while (!filledBufferQ_.empty()) { - if (state_ != RUNNING) { - AUDIO_ERR_LOG("Write: Illegal state:%{public}u", state_); - isReadyToWrite_ = false; - return; - } - stream.buffer = filledBufferQ_.front().buffer; - stream.bufferLen = filledBufferQ_.front().dataLength * rate; - CHECK_AND_RETURN_RET_LOG(stream.buffer != nullptr, "stream.buffer == nullptr return"); - bytesWritten = WriteStreamInCb(stream, writeError, trackId_); - if (writeError != 0) { - AUDIO_ERR_LOG("WriteStreamInCb fail, writeError:%{public}d", writeError); - } else { - AUDIO_INFO_LOG("WriteStream, bytesWritten:%{public}zu", bytesWritten); - freeBufferQ_.emplace(filledBufferQ_.front()); - filledBufferQ_.pop(); - } - if ((state_ != STOPPED) && (state_ != PAUSED)) { - size_t callback_size = 60 * format_ * channelCount_ / 1000; - callback_->OnWriteData(callback_size); - } else { - pthread_cond_wait(&writeCondition_, &writeLock_); - } - } - std::this_thread::sleep_for(std::chrono::microseconds(CB_WRITE_BUFFERS_WAIT_IN_US)); - } -} - -void AudioContainerStreamBase::ReadBuffers() -{ - AUDIO_INFO_LOG("ReadBuffers thread start"); - StreamBuffer stream; - int32_t readLen; - bool isBlockingRead = true; - - while (isReadyToRead_) { - while (!freeBufferQ_.empty()) { - if (state_ != RUNNING) { - AUDIO_ERR_LOG("Read: Illegal state:%{public}u", state_); - isReadyToRead_ = false; - return; - } - AUDIO_DEBUG_LOG("!freeBufferQ_.empty()"); - stream.buffer = freeBufferQ_.front().buffer; - stream.bufferLen = freeBufferQ_.front().bufLength; - AUDIO_DEBUG_LOG("requested stream.bufferLen:%{public}d", stream.bufferLen); - CHECK_AND_RETURN_RET_LOG(stream.buffer != nullptr, "stream.buffer == nullptr return"); - readLen = ReadStream(stream, isBlockingRead, trackId_); - if (readLen < 0) { - AUDIO_ERR_LOG("ReadStream fail, ret: %{public}d", readLen); - } else { - AUDIO_DEBUG_LOG("ReadStream, bytesRead:%{public}d", readLen); - freeBufferQ_.front().dataLength = readLen; - filledBufferQ_.emplace(freeBufferQ_.front()); - freeBufferQ_.pop(); - } - } - std::this_thread::sleep_for(std::chrono::microseconds(CB_READ_BUFFERS_WAIT_IN_US)); - } - - AUDIO_DEBUG_LOG("ReadBuffers thread end"); -} - -void AudioContainerStreamBase::SetApplicationCachePath(const std::string cachePath) -{ - SetAppCachePath(cachePath); -} - -AudioContainerCaptureStream::AudioContainerCaptureStream(AudioStreamType eStreamType, AudioMode eMode) - : AudioContainerStreamBase(eStreamType, eMode) -{ - AUDIO_INFO_LOG("AudioContainerCaptureStream::AudioContainerCaptureStream"); -} - -AudioContainerCaptureStream::~AudioContainerCaptureStream() -{ -} - -bool AudioContainerCaptureStream::StartAudioStream() -{ - CHECK_AND_RETURN_RET_LOG((state_ == PREPARED) || (state_ == STOPPED) || (state_ == PAUSED), - false, "AudioContainerCaptureStream::StartAudioStream Illegal state:%{public}u", state_); - - pthread_cond_signal(&writeCondition_); - int32_t ret = StartStream(trackId_); - CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, false, "Start failed:%{public}d", ret); - - resetTime_ = true; - int32_t retCode = clock_gettime(CLOCK_MONOTONIC, &baseTimestamp_); - if (retCode != 0) { - AUDIO_ERR_LOG("AudioContainerCaptureStream::StartAudioStream get system elapsed time failed: %d", retCode); - } - - if (renderMode_ == RENDER_MODE_CALLBACK) { - isReadyToWrite_ = true; - if (writeThread_ == nullptr) { - writeThread_ = std::make_unique(&AudioContainerStreamBase::WriteBuffers, this); - } - } else if (captureMode_ == CAPTURE_MODE_CALLBACK) { - isReadyToRead_ = true; - readThread_ = std::make_unique(&AudioContainerStreamBase::ReadBuffers, this); - } - - isFirstRead_ = true; - state_ = RUNNING; - AUDIO_INFO_LOG("AudioContainerCaptureStream::StartAudioStream SUCCESS trackId_ %{public}d", trackId_); - return true; -} - -bool AudioContainerCaptureStream::StopAudioStream() -{ - if (state_ == PAUSED) { - state_ = STOPPED; - AUDIO_INFO_LOG("StopAudioStream SUCCESS"); - return true; - } - - CHECK_AND_RETURN_RET_LOG(state_ == RUNNING, false, - "AudioContainerCaptureStream::StopAudioStream: State is not RUNNING. Illegal state:%{public}u", state_); - State oldState = state_; - state_ = STOPPED; // Set it before stopping as Read/Write and Stop can be called from different threads - if (captureMode_ == CAPTURE_MODE_CALLBACK) { - isReadyToRead_ = false; - if (readThread_ && readThread_->joinable()) { - readThread_->join(); - } - } - while (isReadInProgress_ || isWriteInProgress_) { - std::this_thread::sleep_for(std::chrono::microseconds(READ_WRITE_WAIT_TIME_IN_US)); - } - - int32_t ret = StopStream(trackId_); - if (ret != SUCCESS) { - AUDIO_ERR_LOG("AudioContainerCaptureStream::StreamStop fail, ret:%{public}d", ret); - state_ = oldState; - return false; - } - - // Ends the WriteBuffers thread - if (renderMode_ == RENDER_MODE_CALLBACK) { - isReadyToWrite_ = false; - } - - AUDIO_DEBUG_LOG("AudioContainerCaptureStream::StopAudioStream SUCCESS"); - - return true; -} - -int32_t AudioContainerCaptureStream::GetBufferDesc(BufferDesc & bufDesc) -{ - CHECK_AND_RETURN_RET_LOG((renderMode_ == RENDER_MODE_CALLBACK) || (captureMode_ == CAPTURE_MODE_CALLBACK), - ERR_INCORRECT_MODE, "GetBufferDesc not supported. Render or Capture mode is not callback."); - - AUDIO_DEBUG_LOG("AudioContainerStreamBase::freeBufferQ_ count %{public}zu", freeBufferQ_.size()); - AUDIO_DEBUG_LOG("AudioContainerStreamBase::filledBufferQ_ count %{public}zu", filledBufferQ_.size()); - - if (renderMode_ == RENDER_MODE_CALLBACK) { - if (!freeBufferQ_.empty()) { - bufDesc.buffer = freeBufferQ_.front().buffer; - bufDesc.bufLength = freeBufferQ_.front().bufLength; - freeBufferQ_.pop(); - } else { - bufDesc.buffer = nullptr; - AUDIO_ERR_LOG("AudioContainerCaptureStream::GetBufferDesc freeBufferQ_.empty()"); - return ERR_OPERATION_FAILED; - } - } - - if (captureMode_ == CAPTURE_MODE_CALLBACK) { - if (!filledBufferQ_.empty()) { - bufDesc.buffer = filledBufferQ_.front().buffer; - bufDesc.bufLength = filledBufferQ_.front().bufLength; - bufDesc.dataLength = filledBufferQ_.front().dataLength; - filledBufferQ_.pop(); - } else { - bufDesc.buffer = nullptr; - AUDIO_ERR_LOG("AudioContainerCaptureStream::GetBufferDesc filledBufferQ_.empty()"); - return ERR_OPERATION_FAILED; - } - } - return SUCCESS; -} - -int32_t AudioContainerCaptureStream::GetBufQueueState(BufferQueueState &bufState) -{ - CHECK_AND_RETURN_RET_LOG((renderMode_ == RENDER_MODE_CALLBACK) || (captureMode_ == CAPTURE_MODE_CALLBACK), - ERR_INCORRECT_MODE, "GetBufQueueState not supported. Render or Capture mode is not callback."); - - if (renderMode_ == RENDER_MODE_CALLBACK) { - bufState.numBuffers = filledBufferQ_.size(); - } - - if (captureMode_ == CAPTURE_MODE_CALLBACK) { - bufState.numBuffers = freeBufferQ_.size(); - } - - return SUCCESS; -} - -int32_t AudioContainerCaptureStream::Enqueue(const BufferDesc &bufDesc) -{ - AUDIO_INFO_LOG("AudioContainerCaptureStream::Enqueue"); - CHECK_AND_RETURN_RET_LOG((renderMode_ == RENDER_MODE_CALLBACK) || (captureMode_ == CAPTURE_MODE_CALLBACK), - ERR_INCORRECT_MODE, "Enqueue not supported. Render or capture mode is not callback."); - - CHECK_AND_RETURN_RET_LOG(bufDesc.buffer != nullptr, ERR_INVALID_PARAM, - "AudioContainerCaptureStream::Enqueue: failed. bufDesc.buffer == nullptr."); - - if (renderMode_ == RENDER_MODE_CALLBACK) { - AUDIO_DEBUG_LOG("AudioContainerCaptureStream::Enqueue: filledBuffer length: %{public}zu.", bufDesc.bufLength); - filledBufferQ_.emplace(bufDesc); - } - - if (captureMode_ == CAPTURE_MODE_CALLBACK) { - AUDIO_DEBUG_LOG("AudioContainerCaptureStream::Enqueue: freeBuffer length: %{public}zu.", bufDesc.bufLength); - freeBufferQ_.emplace(bufDesc); - } - - return SUCCESS; -} - -int32_t AudioContainerCaptureStream::Clear() -{ - CHECK_AND_RETURN_RET_LOG((renderMode_ == RENDER_MODE_CALLBACK) || (captureMode_ == CAPTURE_MODE_CALLBACK), - ERR_INCORRECT_MODE, "Clear not supported. Render or capture mode is not callback."); - - while (!filledBufferQ_.empty()) { - freeBufferQ_.emplace(filledBufferQ_.front()); - filledBufferQ_.pop(); - } - - return SUCCESS; -} - -AudioContainerRenderStream::AudioContainerRenderStream(AudioStreamType eStreamType, AudioMode eMode) - : AudioContainerStreamBase(eStreamType, eMode) -{ - AUDIO_INFO_LOG("AudioContainerRenderStream::AudioContainerRenderStream"); -} - -AudioContainerRenderStream::~AudioContainerRenderStream() -{ -} - -bool AudioContainerRenderStream::StartAudioStream() -{ - AUDIO_INFO_LOG("AudioContainerRenderStream::StartAudioStream"); - CHECK_AND_RETURN_RET_LOG((state_ == PREPARED) || (state_ == STOPPED) || (state_ == PAUSED), - false, "StartAudioStream Illegal state:%{public}u", state_); - - int32_t ret = StartStream(trackId_); - CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, false, - "StartStream Start failed:%{public}d", ret); - - resetTime_ = true; - int32_t retCode = clock_gettime(CLOCK_MONOTONIC, &baseTimestamp_); - if (retCode != 0) { - AUDIO_ERR_LOG("StartAudioStream get system elapsed time failed: %d", retCode); - } - - if (renderMode_ == RENDER_MODE_CALLBACK) { - isReadyToWrite_ = true; - if (writeThread_ == nullptr) { - writeThread_ = std::make_unique(&AudioContainerStreamBase::WriteBuffers, this); - } - } else if (captureMode_ == CAPTURE_MODE_CALLBACK) { - isReadyToRead_ = true; - readThread_ = std::make_unique(&AudioContainerStreamBase::ReadBuffers, this); - } - - isFirstRead_ = true; - state_ = RUNNING; - pthread_cond_signal(&writeCondition_); - AUDIO_INFO_LOG("AudioContainerRenderStream::StartAudioStream SUCCESS trackId_ %{public}d", trackId_); - return true; -} - -bool AudioContainerRenderStream::StopAudioStream() -{ - if (state_ == PAUSED) { - state_ = STOPPED; - AUDIO_INFO_LOG("AudioContainerRenderStream::StopAudioStream SUCCESS"); - return true; - } - - CHECK_AND_RETURN_RET_LOG(state_ == RUNNING, false, - "AudioContainerRenderStream::StopAudioStream: State is not RUNNING. Illegal state:%{public}u", state_); - State oldState = state_; - state_ = STOPPED; // Set it before stopping as Read/Write and Stop can be called from different threads - if (captureMode_ == CAPTURE_MODE_CALLBACK) { - isReadyToRead_ = false; - if (readThread_ && readThread_->joinable()) { - readThread_->join(); - } - } - while (isReadInProgress_ || isWriteInProgress_) { - std::this_thread::sleep_for(std::chrono::microseconds(READ_WRITE_WAIT_TIME_IN_US)); - } - - int32_t ret = StopStream(trackId_); - if (ret != SUCCESS) { - AUDIO_ERR_LOG("AudioContainerRenderStream::StreamStop fail, ret:%{public}d", ret); - state_ = oldState; - return false; - } - - // Ends the WriteBuffers thread - if (renderMode_ == RENDER_MODE_CALLBACK) { - isReadyToWrite_ = false; - pthread_cond_signal(&writeCondition_); - } - - AUDIO_DEBUG_LOG("AudioContainerRenderStream::StopAudioStream SUCCESS"); - - return true; -} - -int32_t AudioContainerRenderStream::GetBufferDesc(BufferDesc &bufDesc) -{ - CHECK_AND_RETURN_RET_LOG((renderMode_ == RENDER_MODE_CALLBACK) || (captureMode_ == CAPTURE_MODE_CALLBACK), - ERR_INCORRECT_MODE, "GetBufferDesc not supported. Render or Capture mode is not callback."); - - AUDIO_DEBUG_LOG("AudioContainerStreamBase::freeBufferQ_ count %{public}zu, filledBufferQ_ count %{public}zu", - freeBufferQ_.size(), filledBufferQ_.size()); - - lock_guard lock(mBufferQueueLock); - if (renderMode_ == RENDER_MODE_CALLBACK) { - if (!freeBufferQ_.empty()) { - bufDesc.buffer = freeBufferQ_.front().buffer; - bufDesc.bufLength = freeBufferQ_.front().bufLength; - freeBufferQ_.pop(); - } else { - bufDesc.buffer = nullptr; - AUDIO_ERR_LOG("AudioContainerRenderStream::GetBufferDesc freeBufferQ_.empty()"); - return ERR_OPERATION_FAILED; - } - } - - if (captureMode_ == CAPTURE_MODE_CALLBACK) { - if (!filledBufferQ_.empty()) { - bufDesc.buffer = filledBufferQ_.front().buffer; - bufDesc.bufLength = filledBufferQ_.front().bufLength; - bufDesc.dataLength = filledBufferQ_.front().dataLength; - filledBufferQ_.pop(); - } else { - bufDesc.buffer = nullptr; - AUDIO_ERR_LOG("AudioContainerRenderStream::GetBufferDesc filledBufferQ_.empty()"); - return ERR_OPERATION_FAILED; - } - } - return SUCCESS; -} - -int32_t AudioContainerRenderStream::GetBufQueueState(BufferQueueState &bufState) -{ - CHECK_AND_RETURN_RET_LOG((renderMode_ == RENDER_MODE_CALLBACK) || (captureMode_ == CAPTURE_MODE_CALLBACK), - ERR_INCORRECT_MODE, "GetBufQueueState not supported. Render or Capture mode is not callback."); - - lock_guard lock(mBufferQueueLock); - if (renderMode_ == RENDER_MODE_CALLBACK) { - AUDIO_DEBUG_LOG("bufferlength: %{public}zu.", filledBufferQ_.size()); - bufState.numBuffers = filledBufferQ_.size(); - } - - if (captureMode_ == CAPTURE_MODE_CALLBACK) { - bufState.numBuffers = freeBufferQ_.size(); - } - - return SUCCESS; -} - -int32_t AudioContainerRenderStream::Enqueue(const BufferDesc &bufDesc) -{ - AUDIO_INFO_LOG("AudioContainerRenderStream::Enqueue"); - CHECK_AND_RETURN_RET_LOG((renderMode_ == RENDER_MODE_CALLBACK) || (captureMode_ == CAPTURE_MODE_CALLBACK), - ERR_INCORRECT_MODE, "Enqueue not supported. Render or capture mode is not callback."); - - CHECK_AND_RETURN_RET_LOG(bufDesc.buffer != nullptr, ERR_INVALID_PARAM, - "AudioContainerRenderStream::Enqueue: failed. bufDesc.buffer == nullptr."); - - lock_guard lock(mBufferQueueLock); - if (renderMode_ == RENDER_MODE_CALLBACK) { - AUDIO_INFO_LOG("AudioContainerRenderStream::Enqueue: filledBuffer length: %{public}zu.", bufDesc.bufLength); - filledBufferQ_.emplace(bufDesc); - } - - if (captureMode_ == CAPTURE_MODE_CALLBACK) { - AUDIO_INFO_LOG("AudioContainerRenderStream::Enqueue: freeBuffer length: %{public}zu.", bufDesc.bufLength); - freeBufferQ_.emplace(bufDesc); - } - - return SUCCESS; -} - -int32_t AudioContainerRenderStream::Clear() -{ - CHECK_AND_RETURN_RET_LOG((renderMode_ == RENDER_MODE_CALLBACK) || (captureMode_ == CAPTURE_MODE_CALLBACK), - ERR_INCORRECT_MODE, "Clear not supported. Render or capture mode is not callback."); - - lock_guard lock(mBufferQueueLock); - while (!filledBufferQ_.empty()) { - freeBufferQ_.emplace(filledBufferQ_.front()); - filledBufferQ_.pop(); - } - - return SUCCESS; -} -} // namespace AudioStandard -} // namespace OHOS diff --git a/frameworks/native/audiocompatibility/src/audio_renderer_gateway.cpp b/frameworks/native/audiocompatibility/src/audio_renderer_gateway.cpp deleted file mode 100644 index 623e2c01778b27f949cb771bbd91d4b47010d652..0000000000000000000000000000000000000000 --- a/frameworks/native/audiocompatibility/src/audio_renderer_gateway.cpp +++ /dev/null @@ -1,565 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#undef LOG_TAG -#define LOG_TAG "AudioRendererGateway" - -#include "audio_errors.h" -#include "audio_policy_manager.h" -#include "audio_renderer_gateway.h" -#include "audio_container_stream_base.h" -#include "audio_log.h" -#include "audio_renderer.h" - -namespace OHOS { -namespace AudioStandard { - -static const int32_t MAX_VOLUME_LEVEL = 15; -static const int32_t CONST_FACTOR = 100; - -static float VolumeToDb(int32_t volumeLevel) -{ - float value = static_cast(volumeLevel) / MAX_VOLUME_LEVEL; - float roundValue = static_cast(value * CONST_FACTOR); - - return static_cast(roundValue) / CONST_FACTOR; -} - -std::map> AudioRendererGateway::sharedInterrupts_; - -AudioRenderer::~AudioRenderer() = default; -AudioRendererGateway::~AudioRendererGateway() -{ - RendererState state = GetStatus(); - if (state != RENDERER_RELEASED && state != RENDERER_NEW) { - Release(); - } -} - -AudioRendererGateway::AudioRendererGateway(AudioStreamType audioStreamType) -{ - audioStream_ = std::make_shared(audioStreamType, AUDIO_MODE_PLAYBACK); - audioInterrupt_.streamType = audioStreamType; -} - -int32_t AudioRendererGateway::GetFrameCount(uint32_t &frameCount) const -{ - return audioStream_->GetFrameCount(frameCount); -} - -int32_t AudioRendererGateway::GetLatency(uint64_t &latency) const -{ - return audioStream_->GetLatency(latency); -} - -int32_t AudioRendererGateway::SetParams(const AudioRendererParams params) -{ - AudioStreamParams audioStreamParams; - audioStreamParams.format = params.sampleFormat; - audioStreamParams.samplingRate = params.sampleRate; - audioStreamParams.channels = params.channelCount; - audioStreamParams.encoding = params.encodingType; - - int32_t ret = audioStream_->SetAudioStreamInfo(audioStreamParams); - - CHECK_AND_RETURN_RET_LOG(!ret, ret, "SetAudioStreamInfo Failed"); - - int32_t audioSessionID = audioStream_->GetAudioSessionID(sessionID_); - CHECK_AND_RETURN_RET_LOG(audioSessionID == 0, ERR_INVALID_INDEX, "GetAudioSessionID Failed"); - audioInterrupt_.sessionId = sessionID_; - - if (audioInterruptCallback_ == nullptr) { - audioInterruptCallback_ = std::make_shared(audioStream_, audioInterrupt_); - CHECK_AND_RETURN_RET_LOG(audioInterruptCallback_ != nullptr, ERROR, - "Failed to allocate memory for audioInterruptCallback_"); - } - - return AudioPolicyManager::GetInstance().SetAudioInterruptCallback(sessionID_, audioInterruptCallback_); -} - -int32_t AudioRendererGateway::GetParams(AudioRendererParams ¶ms) const -{ - AudioStreamParams audioStreamParams; - int32_t result = audioStream_->GetAudioStreamInfo(audioStreamParams); - if (!result) { - params.sampleFormat = static_cast(audioStreamParams.format); - params.sampleRate = static_cast(audioStreamParams.samplingRate); - params.channelCount = static_cast(audioStreamParams.channels); - params.encodingType = static_cast(audioStreamParams.encoding); - } - - return result; -} - -int32_t AudioRendererGateway::GetRendererInfo(AudioRendererInfo &rendererInfo) const -{ - rendererInfo = rendererInfo_; - - return SUCCESS; -} - -int32_t AudioRendererGateway::GetStreamInfo(AudioStreamInfo &streamInfo) const -{ - AudioStreamParams audioStreamParams; - int32_t result = audioStream_->GetAudioStreamInfo(audioStreamParams); - if (!result) { - streamInfo.format = static_cast(audioStreamParams.format); - streamInfo.samplingRate = static_cast(audioStreamParams.samplingRate); - streamInfo.channels = static_cast(audioStreamParams.channels); - streamInfo.encoding = static_cast(audioStreamParams.encoding); - } - - return result; -} - -int32_t AudioRendererGateway::SetRendererCallback(const std::shared_ptr &callback) -{ - // If the client is using the deprecated SetParams API. SetRendererCallback must be invoked, after SetParams. - // In general, callbacks can only be set after the renderer state is PREPARED. - RendererState state = GetStatus(); - CHECK_AND_RETURN_RET_LOG(state != RENDERER_NEW && state != RENDERER_RELEASED, ERR_ILLEGAL_STATE, - "incorrect state:%{public}d to register cb", state); - CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERR_INVALID_PARAM, "callback param is null"); - - // Save reference for interrupt callback - CHECK_AND_RETURN_RET_LOG(audioInterruptCallback_ != nullptr, ERROR, "audioInterruptCallback_ == nullptr"); - std::shared_ptr cbInterrupt = - std::static_pointer_cast(audioInterruptCallback_); - cbInterrupt->SaveCallback(callback); - - // Save and Set reference for stream callback. Order is important here. - if (audioStreamCallback_ == nullptr) { - audioStreamCallback_ = std::make_shared(); - CHECK_AND_RETURN_RET_LOG(audioStreamCallback_ != nullptr, ERROR, - "Failed to allocate memory for audioStreamCallback_"); - } - - std::shared_ptr cbStream = - std::static_pointer_cast(audioStreamCallback_); - cbStream->SaveCallback(callback); - AUDIO_INFO_LOG("callback audioStreamCallback_"); - (void)audioStream_->SetStreamCallback(audioStreamCallback_); - - return SUCCESS; -} - -int32_t AudioRendererGateway::SetRendererPositionCallback(int64_t markPosition, - const std::shared_ptr &callback) -{ - CHECK_AND_RETURN_RET_LOG((callback != nullptr) && (markPosition > 0), ERR_INVALID_PARAM, "input param is invalid"); - - audioStream_->SetRendererPositionCallback(markPosition, callback); - - return SUCCESS; -} - -void AudioRendererGateway::UnsetRendererPositionCallback() -{ - audioStream_->UnsetRendererPositionCallback(); -} - -int32_t AudioRendererGateway::SetRendererPeriodPositionCallback(int64_t frameNumber, - const std::shared_ptr &callback) -{ - CHECK_AND_RETURN_RET_LOG((callback != nullptr) && (frameNumber > 0), ERR_INVALID_PARAM, "input param is invalid"); - - audioStream_->SetRendererPeriodPositionCallback(frameNumber, callback); - - return SUCCESS; -} - -void AudioRendererGateway::UnsetRendererPeriodPositionCallback() -{ - audioStream_->UnsetRendererPeriodPositionCallback(); -} - -bool AudioRendererGateway::Start(StateChangeCmdType cmdType) const -{ - AUDIO_INFO_LOG("AudioRendererGateway::Start()"); - RendererState state = GetStatus(); - CHECK_AND_RETURN_RET_LOG((state == RENDERER_PREPARED) || (state == RENDERER_STOPPED) || (state == RENDERER_PAUSED), - false, "Illegal state:%{public}u, Start failed", state); - AudioInterrupt audioInterrupt; - switch (mode_) { - case InterruptMode::SHARE_MODE: - audioInterrupt = sharedInterrupt_; - break; - case InterruptMode::INDEPENDENT_MODE: - audioInterrupt = audioInterrupt_; - break; - default: - break; - } - - if (audioInterrupt_.streamType == STREAM_DEFAULT || audioInterrupt_.sessionId == INVALID_SESSION) { - return false; - } - - int32_t ret = AudioPolicyManager::GetInstance().ActivateAudioInterrupt(audioInterrupt); - CHECK_AND_RETURN_RET_LOG(ret == 0, false, "ActivateAudioInterrupt Failed"); - - return audioStream_->StartAudioStream(); -} - -int32_t AudioRendererGateway::Write(uint8_t *buffer, size_t bufferSize) -{ - return audioStream_->Write(buffer, bufferSize); -} - -int32_t AudioRendererGateway::Write(uint8_t *pcmBuffer, size_t pcmSize, uint8_t *metaBuffer, size_t metaSize) -{ - AUDIO_ERR_LOG("AudioRendererGateway::Write with meta do not supported"); - return ERR_INVALID_OPERATION; -} - -RendererState AudioRendererGateway::GetStatus() const -{ - return static_cast(audioStream_->GetState()); -} - -bool AudioRendererGateway::GetAudioTime(Timestamp ×tamp, Timestamp::Timestampbase base) const -{ - return audioStream_->GetAudioTime(timestamp, base); -} - -bool AudioRendererGateway::Drain() const -{ - return audioStream_->DrainAudioStream(); -} - -bool AudioRendererGateway::Flush() const -{ - return audioStream_->FlushAudioStream(); -} - -bool AudioRendererGateway::Pause(StateChangeCmdType cmdType) const -{ - bool result = audioStream_->PauseAudioStream(); - AudioInterrupt audioInterrupt; - switch (mode_) { - case InterruptMode::SHARE_MODE: - audioInterrupt = sharedInterrupt_; - break; - case InterruptMode::INDEPENDENT_MODE: - audioInterrupt = audioInterrupt_; - break; - default: - break; - } - // When user is intentionally pausing , Deactivate to remove from active/pending owners list - int32_t ret = AudioPolicyManager::GetInstance().DeactivateAudioInterrupt(audioInterrupt); - if (ret != 0) { - AUDIO_ERR_LOG("DeactivateAudioInterrupt Failed"); - } - - return result; -} - -bool AudioRendererGateway::Stop() const -{ - bool result = audioStream_->StopAudioStream(); - AudioInterrupt audioInterrupt; - switch (mode_) { - case InterruptMode::SHARE_MODE: - audioInterrupt = sharedInterrupt_; - break; - case InterruptMode::INDEPENDENT_MODE: - audioInterrupt = audioInterrupt_; - break; - default: - break; - } - int32_t ret = AudioPolicyManager::GetInstance().DeactivateAudioInterrupt(audioInterrupt); - if (ret != 0) { - AUDIO_ERR_LOG("DeactivateAudioInterrupt Failed"); - } - - return result; -} - -bool AudioRendererGateway::Release() const -{ - // If Stop call was skipped, Release to take care of Deactivation - (void)AudioPolicyManager::GetInstance().DeactivateAudioInterrupt(audioInterrupt_); - - // Unregister the callaback in policy server - (void)AudioPolicyManager::GetInstance().UnsetAudioInterruptCallback(sessionID_); - - return audioStream_->ReleaseAudioStream(); -} - -int32_t AudioRendererGateway::GetBufferSize(size_t &bufferSize) const -{ - return audioStream_->GetBufferSize(bufferSize); -} - -int32_t AudioRendererGateway::GetAudioStreamId(uint32_t &sessionID) const -{ - return audioStream_->GetAudioSessionID(sessionID); -} - -int32_t AudioRendererGateway::SetAudioRendererDesc(AudioRendererDesc audioRendererDesc) const -{ - ContentType contentType = audioRendererDesc.contentType; - StreamUsage streamUsage = audioRendererDesc.streamUsage; - AudioStreamType audioStreamType = audioStream_->GetStreamType(contentType, streamUsage); - return audioStream_->SetAudioStreamType(audioStreamType); -} - -int32_t AudioRendererGateway::SetStreamType(AudioStreamType audioStreamType) const -{ - return audioStream_->SetAudioStreamType(audioStreamType); -} - -int32_t AudioRendererGateway::SetVolume(float volume) const -{ - return audioStream_->SetVolume(volume); -} - -float AudioRendererGateway::GetVolume() const -{ - return audioStream_->GetVolume(); -} - -int32_t AudioRendererGateway::SetRenderRate(AudioRendererRate renderRate) const -{ - return audioStream_->SetRenderRate(renderRate); -} - -AudioRendererRate AudioRendererGateway::GetRenderRate() const -{ - return audioStream_->GetRenderRate(); -} - -int32_t AudioRendererGateway::SetBufferDuration(uint64_t bufferDuration) const -{ - CHECK_AND_RETURN_RET_LOG(bufferDuration >= MINIMUM_BUFFER_SIZE_MSEC && bufferDuration <= MAXIMUM_BUFFER_SIZE_MSEC, - ERR_INVALID_PARAM, "Error: Please set the buffer duration between 5ms ~ 20ms"); - - return audioStream_->SetBufferSizeInMsec(bufferDuration); -} - -AudioInterruptCallbackGateway::AudioInterruptCallbackGateway( - const std::shared_ptr &audioStream, const AudioInterrupt &audioInterrupt) - : audioStream_(audioStream), audioInterrupt_(audioInterrupt) -{ - AUDIO_INFO_LOG("AudioInterruptCallbackGateway constructor"); -} - -AudioInterruptCallbackGateway::~AudioInterruptCallbackGateway() -{ - AUDIO_DEBUG_LOG("AudioInterruptCallbackGateway: instance destroy"); -} - -void AudioInterruptCallbackGateway::SaveCallback(const std::weak_ptr &callback) -{ - callback_ = callback; -} - -void AudioInterruptCallbackGateway::NotifyEvent(const InterruptEvent &interruptEvent) -{ - AUDIO_DEBUG_LOG("NotifyEvent: Hint: %{public}d, eventType: %{public}d", - interruptEvent.hintType, interruptEvent.eventType); - - if (cb_ != nullptr) { - cb_->OnInterrupt(interruptEvent); - AUDIO_DEBUG_LOG("OnInterrupt : NotifyEvent to app complete"); - } else { - AUDIO_DEBUG_LOG("cb_ == nullptr cannont NotifyEvent to app"); - } -} - -bool AudioInterruptCallbackGateway::HandleForceDucking(const InterruptEventInternal &interruptEvent) -{ - int32_t systemVolumeLevel = AudioPolicyManager::GetInstance().GetSystemVolumeLevel(audioInterrupt_.streamType); - float systemVolumeDb = VolumeToDb(systemVolumeLevel); - float duckVolumeDb = interruptEvent.duckVolume; - int32_t ret = 0; - - if (systemVolumeDb <= duckVolumeDb || FLOAT_COMPARE_EQ(systemVolumeDb, 0.0f)) { - AUDIO_DEBUG_LOG("systemVolumeDb: %{public}f <= duckVolumeDb: %{public}f", - systemVolumeDb, duckVolumeDb); - AUDIO_DEBUG_LOG("No need to duck further return"); - return false; - } - - instanceVolBeforeDucking_ = audioStream_->GetVolume(); - float duckInstanceVolume = duckVolumeDb / systemVolumeDb; - CHECK_AND_RETURN_RET_LOG(!FLOAT_COMPARE_EQ(instanceVolBeforeDucking_, 0.0f) && - instanceVolBeforeDucking_ >= duckInstanceVolume, false, "No need to duck further return"); - - ret = audioStream_->SetVolume(duckInstanceVolume); - CHECK_AND_RETURN_RET_LOG(!ret, false, "set duckVolumeDb(instance) %{pubic}f failed", duckInstanceVolume); - - AUDIO_INFO_LOG("set duckVolumeDb(instance) %{pubic}f succeeded", duckInstanceVolume); - return true; -} - -void AudioInterruptCallbackGateway::NotifyForcePausedToResume(const InterruptEventInternal &interruptEvent) -{ - // Change InterruptForceType to Share, Since app will take care of resuming - InterruptEvent interruptEventResume {interruptEvent.eventType, INTERRUPT_SHARE, - interruptEvent.hintType}; - NotifyEvent(interruptEventResume); -} - -void AudioInterruptCallbackGateway::HandleAndNotifyForcedEvent(const InterruptEventInternal &interruptEvent) -{ - InterruptHint hintType = interruptEvent.hintType; - AUDIO_DEBUG_LOG("ForceType: INTERRUPT_FORCE, Force handle the event and notify the app"); - AUDIO_DEBUG_LOG("Hint: %{public}d eventType: %{public}d", - interruptEvent.hintType, interruptEvent.eventType); - - switch (hintType) { - case INTERRUPT_HINT_PAUSE: - State state = audioStream_->GetState(); - CHECK_AND_RETURN_LOG(state == RUNNING, "OnInterrupt state is not running no need to pause"); - (void)audioStream_->PauseAudioStream(); // Just Pause, do not deactivate here - isForcePaused_ = true; - break; - case INTERRUPT_HINT_RESUME: - State state_ = audioStream_->GetState(); - CHECK_AND_RETURN_LOG(state_ == PAUSED && isForcePaused_, - "OnInterrupt state is not paused or not forced paused"); - isForcePaused_ = false; - NotifyForcePausedToResume(interruptEvent); - return; // return, sending callback is taken care in NotifyForcePausedToResume - case INTERRUPT_HINT_STOP: - (void)audioStream_->StopAudioStream(); - break; - case INTERRUPT_HINT_DUCK: - bool forceDucking = HandleForceDucking(interruptEvent); - CHECK_AND_RETURN_LOG(forceDucking, "It is not forced ducked, no need notify app, return"); - isForceDucked_ = true; - break; - case INTERRUPT_HINT_UNDUCK: - CHECK_AND_RETURN_LOG(isForceDucked_, "It is not forced ducked, no need to unduck or notify app"); - (void)audioStream_->SetVolume(instanceVolBeforeDucking_); - AUDIO_DEBUG_LOG("unduck Volume(instance) complete: %{public}f", - instanceVolBeforeDucking_); - isForceDucked_ = false; - break; - default: - break; - } - // Notify valid forced event callbacks to app - InterruptEvent interruptEventForced {interruptEvent.eventType, interruptEvent.forceType, interruptEvent.hintType}; - NotifyEvent(interruptEventForced); -} - -void AudioInterruptCallbackGateway::OnInterrupt(const InterruptEventInternal &interruptEvent) -{ - cb_ = callback_.lock(); - InterruptForceType forceType = interruptEvent.forceType; - AUDIO_DEBUG_LOG("OnInterrupt InterruptForceType: %{public}d", forceType); - - if (forceType != INTERRUPT_FORCE) { // INTERRUPT_SHARE - AUDIO_DEBUG_LOG("ForceType: INTERRUPT_SHARE. Let app handle the event"); - InterruptEvent interruptEventShared {interruptEvent.eventType, interruptEvent.forceType, - interruptEvent.hintType}; - NotifyEvent(interruptEventShared); - return; - } - - CHECK_AND_RETURN_LOG(audioStream_ != nullptr, "stream is null. No need to take forced action"); - - HandleAndNotifyForcedEvent(interruptEvent); -} - -void AudioStreamRenderCallback::SaveCallback(const std::weak_ptr &callback) -{ - std::shared_ptr cb = callback.lock(); - AUDIO_ERR_LOG("AudioStreamRenderCallback::SaveCallback cb"); - callback_ = callback; -} - -void AudioStreamRenderCallback::OnStateChange(const State state, StateChangeCmdType cmdType) -{ - std::shared_ptr cb = callback_.lock(); - CHECK_AND_RETURN_LOG(cb != nullptr, "cb == nullptr."); - AUDIO_ERR_LOG("OnStateChange cb"); - cb->OnStateChange(static_cast(state)); -} - -int32_t AudioRendererGateway::SetRenderMode(AudioRenderMode renderMode) const -{ - return audioStream_->SetRenderMode(renderMode); -} - -AudioRenderMode AudioRendererGateway::GetRenderMode() const -{ - return audioStream_->GetRenderMode(); -} - -int32_t AudioRendererGateway::GetBufferDesc(BufferDesc &bufDesc) const -{ - return audioStream_->GetBufferDesc(bufDesc); -} - -int32_t AudioRendererGateway::Enqueue(const BufferDesc &bufDesc) const -{ - return audioStream_->Enqueue(bufDesc); -} - -int32_t AudioRendererGateway::Clear() const -{ - return audioStream_->Clear(); -} - -int32_t AudioRendererGateway::GetBufQueueState(BufferQueueState &bufState) const -{ - return audioStream_->GetBufQueueState(bufState); -} - -void AudioRendererGateway::SetApplicationCachePath(const std::string cachePath) -{ - audioStream_->SetApplicationCachePath(cachePath); -} - -int32_t AudioRendererGateway::SetRendererWriteCallback(const std::shared_ptr &callback) -{ - return audioStream_->SetRendererWriteCallback(callback); -} - -void AudioRendererGateway::SetInterruptMode(InterruptMode mode) -{ - AUDIO_INFO_LOG("InterruptMode %{pubilc}d", mode); - mode_ = mode; -} - -int32_t AudioRendererGateway::SetLowPowerVolume(float volume) const -{ - return 0; -} - -float AudioRendererGateway::GetLowPowerVolume() const -{ - return 0; -} - -float AudioRendererGateway::GetSingleStreamVolume() const -{ - return 0; -} - -void AudioRendererGateway::SetPreferredFrameSize(int32_t frameSize) -{ -} - -bool AudioRendererGateway::IsFastRenderer() -{ - return false; -} -} // namespace AudioStandard -} // namespace OHOS diff --git a/frameworks/native/audiocompatibility/src/audio_renderer_write_callback_stub.cpp b/frameworks/native/audiocompatibility/src/audio_renderer_write_callback_stub.cpp deleted file mode 100644 index 7a6c716a87714c1953ec8be27479411af5b08979..0000000000000000000000000000000000000000 --- a/frameworks/native/audiocompatibility/src/audio_renderer_write_callback_stub.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#undef LOG_TAG -#define LOG_TAG "AudioRendererWriteCallbackStub" - -#include "audio_renderer_write_callback_stub.h" -#include "audio_log.h" - -namespace OHOS { -namespace AudioStandard { -AudioRendererWriteCallbackStub::AudioRendererWriteCallbackStub() -{ -} - -AudioRendererWriteCallbackStub::~AudioRendererWriteCallbackStub() -{ -} - -int AudioRendererWriteCallbackStub::OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - CHECK_AND_RETURN_RET_LOG(data.ReadInterfaceToken() == GetDescriptor(), -1, "ReadInterfaceToken failed"); - switch (code) { - case ON_WRITE_DATA: { - size_t length = static_cast(data.ReadInt64()); - OnWriteData(length); - reply.WriteInt32(AUDIO_OK); - break; - } - default: { - reply.WriteInt32(AUDIO_INVALID_PARAM); - break; - } - } - return AUDIO_OK; -} - -void AudioRendererWriteCallbackStub::OnWriteData(size_t length) -{ - std::shared_ptr cb = callback_.lock(); - if (cb != nullptr) { - cb->OnWriteData(length); - } -} - -void AudioRendererWriteCallbackStub::SetOnRendererWriteCallback( - const std::weak_ptr &callback) -{ - callback_ = callback; -} -} // namespace AudioStandard -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/audioeffect/BUILD.gn b/frameworks/native/audioeffect/BUILD.gn index b88eb3c54f854eff1171b23bf3bd6cf80f82c295..791fff3bd2a239ef19abb0e731ff88d40ababc9d 100644 --- a/frameworks/native/audioeffect/BUILD.gn +++ b/frameworks/native/audioeffect/BUILD.gn @@ -12,7 +12,6 @@ # limitations under the License. import("//build/ohos.gni") -import("../../../audio_ohcore.gni") import("../../../config.gni") import("../../../sensor.gni") import("../../../window_manager.gni") diff --git a/frameworks/native/audiorenderer/BUILD.gn b/frameworks/native/audiorenderer/BUILD.gn index cf6182e13e21407a204e9e9112477e1e225ccad5..b3d2b7002f6ba76a75f8b6ccc77420874e902ef2 100644 --- a/frameworks/native/audiorenderer/BUILD.gn +++ b/frameworks/native/audiorenderer/BUILD.gn @@ -12,7 +12,6 @@ # limitations under the License. import("//build/ohos.gni") -import("../../../audio_ohcore.gni") import("../../../config.gni") pulseaudio_build_path = "//third_party/pulseaudio/ohosbuild" @@ -55,9 +54,7 @@ ohos_shared_library("audio_renderer") { configs = [ ":audio_renderer_config" ] - include_dirs = audio_gateway_include_dirs - - include_dirs += [ multimedia_audio_framework_pulse_audio ] + include_dirs = [ multimedia_audio_framework_pulse_audio ] sources = [ "src/audio_renderer.cpp", @@ -70,8 +67,6 @@ ohos_shared_library("audio_renderer") { "../audioutils:audio_utils", ] - deps += audio_renderer_gateway_deps - if (sonic_enable == true) { deps += [ "$pulseaudio_dir/sonic:sonic" ] } diff --git a/frameworks/native/audiorenderer/src/audio_renderer.cpp b/frameworks/native/audiorenderer/src/audio_renderer.cpp index a730830183accd63f5baf23d0b0f9b2dd981430c..de982e73e8c41e26b11f66c3912ece944731f0c6 100644 --- a/frameworks/native/audiorenderer/src/audio_renderer.cpp +++ b/frameworks/native/audiorenderer/src/audio_renderer.cpp @@ -24,9 +24,6 @@ #include "audio_errors.h" #include "audio_policy_manager.h" #include "audio_utils.h" -#ifdef OHCORE -#include "audio_renderer_gateway.h" -#endif namespace OHOS { namespace AudioStandard { @@ -156,11 +153,8 @@ std::unique_ptr AudioRenderer::Create(AudioStreamType audioStream if (audioStreamType == STREAM_MEDIA) { audioStreamType = STREAM_MUSIC; } -#ifdef OHCORE - return std::make_unique(audioStreamType); -#else + return std::make_unique(audioStreamType, appInfo, true); -#endif } std::unique_ptr AudioRenderer::Create(const AudioRendererOptions &rendererOptions) @@ -208,11 +202,8 @@ std::unique_ptr AudioRenderer::Create(const std::string cachePath CHECK_AND_RETURN_RET_LOG((audioStreamType != STREAM_ULTRASONIC || getuid() == UID_MSDP_SA), nullptr, "ULTRASONIC can only create by MSDP"); -#ifdef OHCORE - auto audioRenderer = std::make_unique(audioStreamType); -#else auto audioRenderer = std::make_unique(audioStreamType, appInfo, false); -#endif + CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, nullptr, "Failed to create renderer object"); if (!cachePath.empty()) { AUDIO_DEBUG_LOG("Set application cache path"); diff --git a/frameworks/native/examples/BUILD.gn b/frameworks/native/examples/BUILD.gn index 0e5781ea26dd5b43396c072971f6c59a412eb3b4..0d5528a7ad3d95cdbf53b1e4d7d4e48478782672 100644 --- a/frameworks/native/examples/BUILD.gn +++ b/frameworks/native/examples/BUILD.gn @@ -12,7 +12,6 @@ # limitations under the License. import("//build/ohos.gni") -import("../../../audio_ohcore.gni") import("../../../config.gni") ohos_executable("pa_stream_test") { diff --git a/frameworks/native/playbackcapturer/BUILD.gn b/frameworks/native/playbackcapturer/BUILD.gn index 4a49b591892b7c49338b23fdbec5fe46fe9499b3..8086288fd439bcaed04af9cf6e1eba655e7cd45e 100644 --- a/frameworks/native/playbackcapturer/BUILD.gn +++ b/frameworks/native/playbackcapturer/BUILD.gn @@ -12,7 +12,6 @@ # limitations under the License. import("//build/ohos.gni") -import("../../../audio_ohcore.gni") import("../../../config.gni") pulseaudio_dir = "//third_party/pulseaudio"