146f34cbfSopenharmony_ci/*
246f34cbfSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
346f34cbfSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
446f34cbfSopenharmony_ci * you may not use this file except in compliance with the License.
546f34cbfSopenharmony_ci * You may obtain a copy of the License at
646f34cbfSopenharmony_ci *
746f34cbfSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
846f34cbfSopenharmony_ci *
946f34cbfSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1046f34cbfSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1146f34cbfSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1246f34cbfSopenharmony_ci * See the License for the specific language governing permissions and
1346f34cbfSopenharmony_ci * limitations under the License.
1446f34cbfSopenharmony_ci */
1546f34cbfSopenharmony_ci#ifndef LOG_TAG
1646f34cbfSopenharmony_ci#define LOG_TAG "OHAudioRenderer"
1746f34cbfSopenharmony_ci#endif
1846f34cbfSopenharmony_ci
1946f34cbfSopenharmony_ci#include "OHAudioRenderer.h"
2046f34cbfSopenharmony_ci#include "audio_errors.h"
2146f34cbfSopenharmony_ci
2246f34cbfSopenharmony_ciusing OHOS::AudioStandard::Timestamp;
2346f34cbfSopenharmony_ci
2446f34cbfSopenharmony_cistatic const int64_t SECOND_TO_NANOSECOND = 1000000000;
2546f34cbfSopenharmony_ci
2646f34cbfSopenharmony_cistatic OHOS::AudioStandard::OHAudioRenderer *convertRenderer(OH_AudioRenderer *renderer)
2746f34cbfSopenharmony_ci{
2846f34cbfSopenharmony_ci    return (OHOS::AudioStandard::OHAudioRenderer*) renderer;
2946f34cbfSopenharmony_ci}
3046f34cbfSopenharmony_ci
3146f34cbfSopenharmony_cistatic OH_AudioStream_Result ConvertError(int32_t err)
3246f34cbfSopenharmony_ci{
3346f34cbfSopenharmony_ci    if (err == OHOS::AudioStandard::SUCCESS) {
3446f34cbfSopenharmony_ci        return AUDIOSTREAM_SUCCESS;
3546f34cbfSopenharmony_ci    } else if (err == OHOS::AudioStandard::ERR_INVALID_PARAM) {
3646f34cbfSopenharmony_ci        return AUDIOSTREAM_ERROR_INVALID_PARAM;
3746f34cbfSopenharmony_ci    } else if (err == OHOS::AudioStandard::ERR_ILLEGAL_STATE) {
3846f34cbfSopenharmony_ci        return AUDIOSTREAM_ERROR_ILLEGAL_STATE;
3946f34cbfSopenharmony_ci    }
4046f34cbfSopenharmony_ci    return AUDIOSTREAM_ERROR_SYSTEM;
4146f34cbfSopenharmony_ci}
4246f34cbfSopenharmony_ci
4346f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_Start(OH_AudioRenderer *renderer)
4446f34cbfSopenharmony_ci{
4546f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
4646f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
4746f34cbfSopenharmony_ci    if (audioRenderer->Start()) {
4846f34cbfSopenharmony_ci        return AUDIOSTREAM_SUCCESS;
4946f34cbfSopenharmony_ci    } else {
5046f34cbfSopenharmony_ci        return AUDIOSTREAM_ERROR_ILLEGAL_STATE;
5146f34cbfSopenharmony_ci    }
5246f34cbfSopenharmony_ci}
5346f34cbfSopenharmony_ci
5446f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_Pause(OH_AudioRenderer *renderer)
5546f34cbfSopenharmony_ci{
5646f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
5746f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
5846f34cbfSopenharmony_ci
5946f34cbfSopenharmony_ci    if (audioRenderer->Pause()) {
6046f34cbfSopenharmony_ci        return AUDIOSTREAM_SUCCESS;
6146f34cbfSopenharmony_ci    } else {
6246f34cbfSopenharmony_ci        return AUDIOSTREAM_ERROR_ILLEGAL_STATE;
6346f34cbfSopenharmony_ci    }
6446f34cbfSopenharmony_ci}
6546f34cbfSopenharmony_ci
6646f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_Stop(OH_AudioRenderer *renderer)
6746f34cbfSopenharmony_ci{
6846f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
6946f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
7046f34cbfSopenharmony_ci
7146f34cbfSopenharmony_ci    if (audioRenderer->Stop()) {
7246f34cbfSopenharmony_ci        return AUDIOSTREAM_SUCCESS;
7346f34cbfSopenharmony_ci    } else {
7446f34cbfSopenharmony_ci        return AUDIOSTREAM_ERROR_ILLEGAL_STATE;
7546f34cbfSopenharmony_ci    }
7646f34cbfSopenharmony_ci}
7746f34cbfSopenharmony_ci
7846f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_Flush(OH_AudioRenderer *renderer)
7946f34cbfSopenharmony_ci{
8046f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
8146f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
8246f34cbfSopenharmony_ci
8346f34cbfSopenharmony_ci    if (audioRenderer->Flush()) {
8446f34cbfSopenharmony_ci        return AUDIOSTREAM_SUCCESS;
8546f34cbfSopenharmony_ci    } else {
8646f34cbfSopenharmony_ci        return AUDIOSTREAM_ERROR_ILLEGAL_STATE;
8746f34cbfSopenharmony_ci    }
8846f34cbfSopenharmony_ci}
8946f34cbfSopenharmony_ci
9046f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_Release(OH_AudioRenderer *renderer)
9146f34cbfSopenharmony_ci{
9246f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
9346f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
9446f34cbfSopenharmony_ci
9546f34cbfSopenharmony_ci    if (audioRenderer->Release()) {
9646f34cbfSopenharmony_ci        delete audioRenderer;
9746f34cbfSopenharmony_ci        audioRenderer = nullptr;
9846f34cbfSopenharmony_ci        return AUDIOSTREAM_SUCCESS;
9946f34cbfSopenharmony_ci    } else {
10046f34cbfSopenharmony_ci        return AUDIOSTREAM_ERROR_ILLEGAL_STATE;
10146f34cbfSopenharmony_ci    }
10246f34cbfSopenharmony_ci}
10346f34cbfSopenharmony_ci
10446f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_GetCurrentState(OH_AudioRenderer *renderer, OH_AudioStream_State *state)
10546f34cbfSopenharmony_ci{
10646f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
10746f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
10846f34cbfSopenharmony_ci
10946f34cbfSopenharmony_ci    OHOS::AudioStandard::RendererState rendererState = audioRenderer->GetCurrentState();
11046f34cbfSopenharmony_ci    *state = (OH_AudioStream_State)rendererState;
11146f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
11246f34cbfSopenharmony_ci}
11346f34cbfSopenharmony_ci
11446f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_GetSamplingRate(OH_AudioRenderer *renderer, int32_t *rate)
11546f34cbfSopenharmony_ci{
11646f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
11746f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
11846f34cbfSopenharmony_ci
11946f34cbfSopenharmony_ci    *rate = audioRenderer->GetSamplingRate();
12046f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
12146f34cbfSopenharmony_ci}
12246f34cbfSopenharmony_ci
12346f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_GetStreamId(OH_AudioRenderer *renderer, uint32_t *streamId)
12446f34cbfSopenharmony_ci{
12546f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
12646f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
12746f34cbfSopenharmony_ci    audioRenderer->GetStreamId(*streamId);
12846f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
12946f34cbfSopenharmony_ci}
13046f34cbfSopenharmony_ci
13146f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_GetChannelCount(OH_AudioRenderer *renderer, int32_t *channelCount)
13246f34cbfSopenharmony_ci{
13346f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
13446f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
13546f34cbfSopenharmony_ci    *channelCount = audioRenderer->GetChannelCount();
13646f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
13746f34cbfSopenharmony_ci}
13846f34cbfSopenharmony_ci
13946f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_GetSampleFormat(OH_AudioRenderer *renderer,
14046f34cbfSopenharmony_ci    OH_AudioStream_SampleFormat *sampleFormat)
14146f34cbfSopenharmony_ci{
14246f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
14346f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
14446f34cbfSopenharmony_ci    *sampleFormat = (OH_AudioStream_SampleFormat)audioRenderer->GetSampleFormat();
14546f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
14646f34cbfSopenharmony_ci}
14746f34cbfSopenharmony_ci
14846f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_GetLatencyMode(OH_AudioRenderer *renderer,
14946f34cbfSopenharmony_ci    OH_AudioStream_LatencyMode *latencyMode)
15046f34cbfSopenharmony_ci{
15146f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
15246f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
15346f34cbfSopenharmony_ci    OHOS::AudioStandard::AudioRendererInfo rendererInfo;
15446f34cbfSopenharmony_ci    audioRenderer->GetRendererInfo(rendererInfo);
15546f34cbfSopenharmony_ci    *latencyMode = (OH_AudioStream_LatencyMode)rendererInfo.rendererFlags;
15646f34cbfSopenharmony_ci
15746f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
15846f34cbfSopenharmony_ci}
15946f34cbfSopenharmony_ci
16046f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_GetRendererInfo(OH_AudioRenderer *renderer,
16146f34cbfSopenharmony_ci    OH_AudioStream_Usage *usage)
16246f34cbfSopenharmony_ci{
16346f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
16446f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
16546f34cbfSopenharmony_ci
16646f34cbfSopenharmony_ci    OHOS::AudioStandard::AudioRendererInfo rendererInfo;
16746f34cbfSopenharmony_ci    audioRenderer->GetRendererInfo(rendererInfo);
16846f34cbfSopenharmony_ci    *usage = (OH_AudioStream_Usage)rendererInfo.streamUsage;
16946f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
17046f34cbfSopenharmony_ci}
17146f34cbfSopenharmony_ci
17246f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_GetRendererPrivacy(OH_AudioRenderer* renderer,
17346f34cbfSopenharmony_ci    OH_AudioStream_PrivacyType* privacy)
17446f34cbfSopenharmony_ci{
17546f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
17646f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
17746f34cbfSopenharmony_ci
17846f34cbfSopenharmony_ci    *privacy = (OH_AudioStream_PrivacyType)audioRenderer->GetRendererPrivacy();
17946f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
18046f34cbfSopenharmony_ci}
18146f34cbfSopenharmony_ci
18246f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_GetEncodingType(OH_AudioRenderer *renderer,
18346f34cbfSopenharmony_ci    OH_AudioStream_EncodingType *encodingType)
18446f34cbfSopenharmony_ci{
18546f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
18646f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
18746f34cbfSopenharmony_ci    *encodingType = (OH_AudioStream_EncodingType)audioRenderer->GetEncodingType();
18846f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
18946f34cbfSopenharmony_ci}
19046f34cbfSopenharmony_ci
19146f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_GetFramesWritten(OH_AudioRenderer *renderer, int64_t *frames)
19246f34cbfSopenharmony_ci{
19346f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
19446f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
19546f34cbfSopenharmony_ci    *frames = audioRenderer->GetFramesWritten();
19646f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
19746f34cbfSopenharmony_ci}
19846f34cbfSopenharmony_ci
19946f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_GetTimestamp(OH_AudioRenderer *renderer,
20046f34cbfSopenharmony_ci    clockid_t clockId, int64_t *framePosition, int64_t *timestamp)
20146f34cbfSopenharmony_ci{
20246f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
20346f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
20446f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(clockId == CLOCK_MONOTONIC, AUDIOSTREAM_ERROR_INVALID_PARAM, "error clockId value");
20546f34cbfSopenharmony_ci    Timestamp stamp;
20646f34cbfSopenharmony_ci    Timestamp::Timestampbase base = Timestamp::Timestampbase::MONOTONIC;
20746f34cbfSopenharmony_ci    bool ret = audioRenderer->GetAudioTime(stamp, base);
20846f34cbfSopenharmony_ci    if (!ret) {
20946f34cbfSopenharmony_ci        AUDIO_ERR_LOG("GetAudioTime error!");
21046f34cbfSopenharmony_ci        return AUDIOSTREAM_ERROR_ILLEGAL_STATE;
21146f34cbfSopenharmony_ci    }
21246f34cbfSopenharmony_ci    *framePosition = stamp.framePosition;
21346f34cbfSopenharmony_ci    *timestamp = stamp.time.tv_sec * SECOND_TO_NANOSECOND + stamp.time.tv_nsec;
21446f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
21546f34cbfSopenharmony_ci}
21646f34cbfSopenharmony_ci
21746f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_GetFrameSizeInCallback(OH_AudioRenderer *renderer, int32_t *frameSize)
21846f34cbfSopenharmony_ci{
21946f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
22046f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
22146f34cbfSopenharmony_ci    *frameSize = audioRenderer->GetFrameSizeInCallback();
22246f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
22346f34cbfSopenharmony_ci}
22446f34cbfSopenharmony_ci
22546f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_GetSpeed(OH_AudioRenderer *renderer, float *speed)
22646f34cbfSopenharmony_ci{
22746f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
22846f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
22946f34cbfSopenharmony_ci    *speed = audioRenderer->GetSpeed();
23046f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
23146f34cbfSopenharmony_ci}
23246f34cbfSopenharmony_ci
23346f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_SetSpeed(OH_AudioRenderer *renderer, float speed)
23446f34cbfSopenharmony_ci{
23546f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
23646f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
23746f34cbfSopenharmony_ci    audioRenderer->SetSpeed(speed);
23846f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
23946f34cbfSopenharmony_ci}
24046f34cbfSopenharmony_ci
24146f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_SetVolume(OH_AudioRenderer *renderer, float volume)
24246f34cbfSopenharmony_ci{
24346f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
24446f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
24546f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(((volume >= 0) && (volume <= 1)), AUDIOSTREAM_ERROR_INVALID_PARAM, "volume set invalid");
24646f34cbfSopenharmony_ci    int32_t err = audioRenderer->SetVolume(volume);
24746f34cbfSopenharmony_ci    return ConvertError(err);
24846f34cbfSopenharmony_ci}
24946f34cbfSopenharmony_ci
25046f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_SetVolumeWithRamp(OH_AudioRenderer *renderer, float volume, int32_t durationMs)
25146f34cbfSopenharmony_ci{
25246f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
25346f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
25446f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(((volume >= 0) && (volume <= 1)), AUDIOSTREAM_ERROR_INVALID_PARAM, "volume set invalid");
25546f34cbfSopenharmony_ci    int32_t err = audioRenderer->SetVolumeWithRamp(volume, durationMs);
25646f34cbfSopenharmony_ci    return ConvertError(err);
25746f34cbfSopenharmony_ci}
25846f34cbfSopenharmony_ci
25946f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_GetVolume(OH_AudioRenderer *renderer, float *volume)
26046f34cbfSopenharmony_ci{
26146f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
26246f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
26346f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(volume != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "volume is nullptr");
26446f34cbfSopenharmony_ci    *volume = audioRenderer->GetVolume();
26546f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
26646f34cbfSopenharmony_ci}
26746f34cbfSopenharmony_ci
26846f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_SetMarkPosition(OH_AudioRenderer *renderer, uint32_t samplePos,
26946f34cbfSopenharmony_ci    OH_AudioRenderer_OnMarkReachedCallback callback, void *userData)
27046f34cbfSopenharmony_ci{
27146f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
27246f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
27346f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(samplePos > 0, AUDIOSTREAM_ERROR_INVALID_PARAM, "framePos set invalid");
27446f34cbfSopenharmony_ci    int32_t err = audioRenderer->SetRendererPositionCallback(callback, samplePos, userData);
27546f34cbfSopenharmony_ci    return ConvertError(err);
27646f34cbfSopenharmony_ci}
27746f34cbfSopenharmony_ci
27846f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_CancelMark(OH_AudioRenderer *renderer)
27946f34cbfSopenharmony_ci{
28046f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
28146f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
28246f34cbfSopenharmony_ci    audioRenderer->UnsetRendererPositionCallback();
28346f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
28446f34cbfSopenharmony_ci}
28546f34cbfSopenharmony_ci
28646f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_GetChannelLayout(OH_AudioRenderer *renderer,
28746f34cbfSopenharmony_ci    OH_AudioChannelLayout *channelLayout)
28846f34cbfSopenharmony_ci{
28946f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
29046f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
29146f34cbfSopenharmony_ci    *channelLayout = (OH_AudioChannelLayout)audioRenderer->GetChannelLayout();
29246f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
29346f34cbfSopenharmony_ci}
29446f34cbfSopenharmony_ci
29546f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_GetEffectMode(OH_AudioRenderer *renderer,
29646f34cbfSopenharmony_ci    OH_AudioStream_AudioEffectMode *effectMode)
29746f34cbfSopenharmony_ci{
29846f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
29946f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
30046f34cbfSopenharmony_ci    *effectMode = (OH_AudioStream_AudioEffectMode)audioRenderer->GetEffectMode();
30146f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
30246f34cbfSopenharmony_ci}
30346f34cbfSopenharmony_ci
30446f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_SetEffectMode(OH_AudioRenderer *renderer,
30546f34cbfSopenharmony_ci    OH_AudioStream_AudioEffectMode effectMode)
30646f34cbfSopenharmony_ci{
30746f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
30846f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
30946f34cbfSopenharmony_ci    audioRenderer->SetEffectMode((OHOS::AudioStandard::AudioEffectMode)effectMode);
31046f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
31146f34cbfSopenharmony_ci}
31246f34cbfSopenharmony_ci
31346f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_GetUnderflowCount(OH_AudioRenderer* renderer, uint32_t* count)
31446f34cbfSopenharmony_ci{
31546f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
31646f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
31746f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(count != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "count is nullptr");
31846f34cbfSopenharmony_ci    *count = audioRenderer->GetUnderflowCount();
31946f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
32046f34cbfSopenharmony_ci}
32146f34cbfSopenharmony_ci
32246f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_SetSilentModeAndMixWithOthers(
32346f34cbfSopenharmony_ci    OH_AudioRenderer* renderer, bool on)
32446f34cbfSopenharmony_ci{
32546f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
32646f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
32746f34cbfSopenharmony_ci    audioRenderer->SetSilentModeAndMixWithOthers(on);
32846f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
32946f34cbfSopenharmony_ci}
33046f34cbfSopenharmony_ci
33146f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_GetSilentModeAndMixWithOthers(
33246f34cbfSopenharmony_ci    OH_AudioRenderer* renderer, bool* on)
33346f34cbfSopenharmony_ci{
33446f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
33546f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
33646f34cbfSopenharmony_ci    *on = audioRenderer->GetSilentModeAndMixWithOthers();
33746f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
33846f34cbfSopenharmony_ci}
33946f34cbfSopenharmony_ci
34046f34cbfSopenharmony_ciOH_AudioStream_Result OH_AudioRenderer_SetDefaultOutputDevice(
34146f34cbfSopenharmony_ci    OH_AudioRenderer* renderer, OH_AudioDevice_Type deviceType)
34246f34cbfSopenharmony_ci{
34346f34cbfSopenharmony_ci    OHOS::AudioStandard::OHAudioRenderer *audioRenderer = convertRenderer(renderer);
34446f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer != nullptr, AUDIOSTREAM_ERROR_INVALID_PARAM, "convert renderer failed");
34546f34cbfSopenharmony_ci    bool result = (deviceType == AUDIO_DEVICE_TYPE_EARPIECE || deviceType == AUDIO_DEVICE_TYPE_SPEAKER ||
34646f34cbfSopenharmony_ci        deviceType == AUDIO_DEVICE_TYPE_DEFAULT) ? true : false;
34746f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(result != false, AUDIOSTREAM_ERROR_INVALID_PARAM, "deviceType is not valid");
34846f34cbfSopenharmony_ci    int32_t ret = audioRenderer->SetDefaultOutputDevice((OHOS::AudioStandard::DeviceType)deviceType);
34946f34cbfSopenharmony_ci    if (ret == OHOS::AudioStandard::ERR_NOT_SUPPORTED) {
35046f34cbfSopenharmony_ci        AUDIO_ERR_LOG("This audiorenderer can not reset the output device");
35146f34cbfSopenharmony_ci        return AUDIOSTREAM_ERROR_ILLEGAL_STATE;
35246f34cbfSopenharmony_ci    } else if (ret != AUDIOSTREAM_SUCCESS) {
35346f34cbfSopenharmony_ci        AUDIO_ERR_LOG("system error when calling this function");
35446f34cbfSopenharmony_ci        return AUDIOSTREAM_ERROR_SYSTEM;
35546f34cbfSopenharmony_ci    }
35646f34cbfSopenharmony_ci    return AUDIOSTREAM_SUCCESS;
35746f34cbfSopenharmony_ci}
35846f34cbfSopenharmony_ci
35946f34cbfSopenharmony_cinamespace OHOS {
36046f34cbfSopenharmony_cinamespace AudioStandard {
36146f34cbfSopenharmony_ciOHAudioRenderer::OHAudioRenderer()
36246f34cbfSopenharmony_ci{
36346f34cbfSopenharmony_ci    AUDIO_INFO_LOG("OHAudioRenderer created!");
36446f34cbfSopenharmony_ci}
36546f34cbfSopenharmony_ci
36646f34cbfSopenharmony_ciOHAudioRenderer::~OHAudioRenderer()
36746f34cbfSopenharmony_ci{
36846f34cbfSopenharmony_ci    AUDIO_INFO_LOG("OHAudioRenderer destroyed!");
36946f34cbfSopenharmony_ci}
37046f34cbfSopenharmony_ci
37146f34cbfSopenharmony_cibool OHAudioRenderer::Initialize(AudioRendererOptions &rendererOptions)
37246f34cbfSopenharmony_ci{
37346f34cbfSopenharmony_ci    bool offloadAllowed = true;
37446f34cbfSopenharmony_ci
37546f34cbfSopenharmony_ci    // unknown stream use music policy as default
37646f34cbfSopenharmony_ci    if (rendererOptions.rendererInfo.streamUsage == STREAM_USAGE_UNKNOWN) {
37746f34cbfSopenharmony_ci        rendererOptions.rendererInfo.streamUsage = STREAM_USAGE_MUSIC;
37846f34cbfSopenharmony_ci        offloadAllowed = false;
37946f34cbfSopenharmony_ci    }
38046f34cbfSopenharmony_ci    std::string cacheDir = "/data/storage/el2/base/temp";
38146f34cbfSopenharmony_ci    audioRenderer_ = AudioRenderer::Create(cacheDir, rendererOptions);
38246f34cbfSopenharmony_ci
38346f34cbfSopenharmony_ci    // if caller do not set usage, do not allow to use offload output
38446f34cbfSopenharmony_ci    if (audioRenderer_ != nullptr) {
38546f34cbfSopenharmony_ci        audioRenderer_->SetOffloadAllowed(offloadAllowed);
38646f34cbfSopenharmony_ci    }
38746f34cbfSopenharmony_ci
38846f34cbfSopenharmony_ci    return audioRenderer_ != nullptr;
38946f34cbfSopenharmony_ci}
39046f34cbfSopenharmony_ci
39146f34cbfSopenharmony_cibool OHAudioRenderer::Start()
39246f34cbfSopenharmony_ci{
39346f34cbfSopenharmony_ci    if (audioRenderer_ == nullptr) {
39446f34cbfSopenharmony_ci        AUDIO_ERR_LOG("renderer client is nullptr");
39546f34cbfSopenharmony_ci        return false;
39646f34cbfSopenharmony_ci    }
39746f34cbfSopenharmony_ci    return audioRenderer_->Start();
39846f34cbfSopenharmony_ci}
39946f34cbfSopenharmony_ci
40046f34cbfSopenharmony_cibool OHAudioRenderer::Pause()
40146f34cbfSopenharmony_ci{
40246f34cbfSopenharmony_ci    if (audioRenderer_ == nullptr) {
40346f34cbfSopenharmony_ci        AUDIO_ERR_LOG("renderer client is nullptr");
40446f34cbfSopenharmony_ci        return false;
40546f34cbfSopenharmony_ci    }
40646f34cbfSopenharmony_ci    return audioRenderer_->Pause();
40746f34cbfSopenharmony_ci}
40846f34cbfSopenharmony_ci
40946f34cbfSopenharmony_cibool OHAudioRenderer::Stop()
41046f34cbfSopenharmony_ci{
41146f34cbfSopenharmony_ci    if (audioRenderer_ == nullptr) {
41246f34cbfSopenharmony_ci        AUDIO_ERR_LOG("renderer client is nullptr");
41346f34cbfSopenharmony_ci        return false;
41446f34cbfSopenharmony_ci    }
41546f34cbfSopenharmony_ci    return audioRenderer_->Stop();
41646f34cbfSopenharmony_ci}
41746f34cbfSopenharmony_ci
41846f34cbfSopenharmony_cibool OHAudioRenderer::Flush()
41946f34cbfSopenharmony_ci{
42046f34cbfSopenharmony_ci    if (audioRenderer_ == nullptr) {
42146f34cbfSopenharmony_ci        AUDIO_ERR_LOG("renderer client is nullptr");
42246f34cbfSopenharmony_ci        return false;
42346f34cbfSopenharmony_ci    }
42446f34cbfSopenharmony_ci    return audioRenderer_->Flush();
42546f34cbfSopenharmony_ci}
42646f34cbfSopenharmony_ci
42746f34cbfSopenharmony_cibool OHAudioRenderer::Release()
42846f34cbfSopenharmony_ci{
42946f34cbfSopenharmony_ci    if (audioRenderer_ == nullptr) {
43046f34cbfSopenharmony_ci        AUDIO_ERR_LOG("renderer client is nullptr");
43146f34cbfSopenharmony_ci        return false;
43246f34cbfSopenharmony_ci    }
43346f34cbfSopenharmony_ci
43446f34cbfSopenharmony_ci    if (!audioRenderer_->Release()) {
43546f34cbfSopenharmony_ci        return false;
43646f34cbfSopenharmony_ci    }
43746f34cbfSopenharmony_ci    audioRenderer_ = nullptr;
43846f34cbfSopenharmony_ci    audioRendererCallback_ = nullptr;
43946f34cbfSopenharmony_ci    return true;
44046f34cbfSopenharmony_ci}
44146f34cbfSopenharmony_ci
44246f34cbfSopenharmony_ciRendererState OHAudioRenderer::GetCurrentState()
44346f34cbfSopenharmony_ci{
44446f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, RENDERER_INVALID, "renderer client is nullptr");
44546f34cbfSopenharmony_ci    return audioRenderer_->GetStatus();
44646f34cbfSopenharmony_ci}
44746f34cbfSopenharmony_ci
44846f34cbfSopenharmony_civoid OHAudioRenderer::GetStreamId(uint32_t &streamId)
44946f34cbfSopenharmony_ci{
45046f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(audioRenderer_ != nullptr, "renderer client is nullptr");
45146f34cbfSopenharmony_ci    audioRenderer_->GetAudioStreamId(streamId);
45246f34cbfSopenharmony_ci}
45346f34cbfSopenharmony_ci
45446f34cbfSopenharmony_ciAudioChannel OHAudioRenderer::GetChannelCount()
45546f34cbfSopenharmony_ci{
45646f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, MONO, "renderer client is nullptr");
45746f34cbfSopenharmony_ci    AudioRendererParams params;
45846f34cbfSopenharmony_ci    audioRenderer_->GetParams(params);
45946f34cbfSopenharmony_ci    return params.channelCount;
46046f34cbfSopenharmony_ci}
46146f34cbfSopenharmony_ci
46246f34cbfSopenharmony_ciint32_t OHAudioRenderer::GetSamplingRate()
46346f34cbfSopenharmony_ci{
46446f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, MONO, "renderer client is nullptr");
46546f34cbfSopenharmony_ci    AudioRendererParams params;
46646f34cbfSopenharmony_ci    audioRenderer_->GetParams(params);
46746f34cbfSopenharmony_ci    return params.sampleRate;
46846f34cbfSopenharmony_ci}
46946f34cbfSopenharmony_ci
47046f34cbfSopenharmony_ciAudioSampleFormat OHAudioRenderer::GetSampleFormat()
47146f34cbfSopenharmony_ci{
47246f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, INVALID_WIDTH, "renderer client is nullptr");
47346f34cbfSopenharmony_ci    AudioRendererParams params;
47446f34cbfSopenharmony_ci    audioRenderer_->GetParams(params);
47546f34cbfSopenharmony_ci    return params.sampleFormat;
47646f34cbfSopenharmony_ci}
47746f34cbfSopenharmony_ci
47846f34cbfSopenharmony_civoid OHAudioRenderer::GetRendererInfo(AudioRendererInfo& rendererInfo)
47946f34cbfSopenharmony_ci{
48046f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(audioRenderer_ != nullptr, "renderer client is nullptr");
48146f34cbfSopenharmony_ci    audioRenderer_->GetRendererInfo(rendererInfo);
48246f34cbfSopenharmony_ci}
48346f34cbfSopenharmony_ci
48446f34cbfSopenharmony_ciAudioEncodingType OHAudioRenderer::GetEncodingType()
48546f34cbfSopenharmony_ci{
48646f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, ENCODING_INVALID, "renderer client is nullptr");
48746f34cbfSopenharmony_ci    AudioRendererParams params;
48846f34cbfSopenharmony_ci    audioRenderer_->GetParams(params);
48946f34cbfSopenharmony_ci    return params.encodingType;
49046f34cbfSopenharmony_ci}
49146f34cbfSopenharmony_ci
49246f34cbfSopenharmony_ciint64_t OHAudioRenderer::GetFramesWritten()
49346f34cbfSopenharmony_ci{
49446f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, ERROR, "renderer client is nullptr");
49546f34cbfSopenharmony_ci    return audioRenderer_->GetFramesWritten();
49646f34cbfSopenharmony_ci}
49746f34cbfSopenharmony_ci
49846f34cbfSopenharmony_cibool OHAudioRenderer::GetAudioTime(Timestamp &timestamp, Timestamp::Timestampbase base)
49946f34cbfSopenharmony_ci{
50046f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, false, "renderer client is nullptr");
50146f34cbfSopenharmony_ci    return audioRenderer_->GetAudioPosition(timestamp, base);
50246f34cbfSopenharmony_ci}
50346f34cbfSopenharmony_ci
50446f34cbfSopenharmony_ciint32_t OHAudioRenderer::GetFrameSizeInCallback()
50546f34cbfSopenharmony_ci{
50646f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, ERROR, "renderer client is nullptr");
50746f34cbfSopenharmony_ci    uint32_t frameSize;
50846f34cbfSopenharmony_ci    audioRenderer_->GetFrameCount(frameSize);
50946f34cbfSopenharmony_ci    return static_cast<int32_t>(frameSize);
51046f34cbfSopenharmony_ci}
51146f34cbfSopenharmony_ci
51246f34cbfSopenharmony_ciint32_t OHAudioRenderer::GetBufferDesc(BufferDesc &bufDesc) const
51346f34cbfSopenharmony_ci{
51446f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, ERROR, "renderer client is nullptr");
51546f34cbfSopenharmony_ci    return audioRenderer_->GetBufferDesc(bufDesc);
51646f34cbfSopenharmony_ci}
51746f34cbfSopenharmony_ci
51846f34cbfSopenharmony_ciint32_t OHAudioRenderer::Enqueue(const BufferDesc &bufDesc) const
51946f34cbfSopenharmony_ci{
52046f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, ERROR, "renderer client is nullptr");
52146f34cbfSopenharmony_ci    return audioRenderer_->Enqueue(bufDesc);
52246f34cbfSopenharmony_ci}
52346f34cbfSopenharmony_ci
52446f34cbfSopenharmony_ciint32_t OHAudioRenderer::SetSpeed(float speed)
52546f34cbfSopenharmony_ci{
52646f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, ERROR, "renderer client is nullptr");
52746f34cbfSopenharmony_ci    return audioRenderer_->SetSpeed(speed);
52846f34cbfSopenharmony_ci}
52946f34cbfSopenharmony_ci
53046f34cbfSopenharmony_cifloat OHAudioRenderer::GetSpeed()
53146f34cbfSopenharmony_ci{
53246f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, ERROR, "renderer client is nullptr");
53346f34cbfSopenharmony_ci    return audioRenderer_->GetSpeed();
53446f34cbfSopenharmony_ci}
53546f34cbfSopenharmony_ci
53646f34cbfSopenharmony_ciint32_t OHAudioRenderer::SetVolume(float volume) const
53746f34cbfSopenharmony_ci{
53846f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, ERROR, "renderer client is nullptr");
53946f34cbfSopenharmony_ci    return audioRenderer_->SetVolume(volume);
54046f34cbfSopenharmony_ci}
54146f34cbfSopenharmony_ci
54246f34cbfSopenharmony_cifloat OHAudioRenderer::GetVolume() const
54346f34cbfSopenharmony_ci{
54446f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, ERROR, "renderer client is nullptr");
54546f34cbfSopenharmony_ci    return audioRenderer_->GetVolume();
54646f34cbfSopenharmony_ci}
54746f34cbfSopenharmony_ci
54846f34cbfSopenharmony_ciint32_t OHAudioRenderer::SetVolumeWithRamp(float volume, int32_t duration)
54946f34cbfSopenharmony_ci{
55046f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, ERROR, "renderer client is nullptr");
55146f34cbfSopenharmony_ci    return audioRenderer_->SetVolumeWithRamp(volume, duration);
55246f34cbfSopenharmony_ci}
55346f34cbfSopenharmony_ci
55446f34cbfSopenharmony_ciint32_t OHAudioRenderer::SetRendererPositionCallback(OH_AudioRenderer_OnMarkReachedCallback callback,
55546f34cbfSopenharmony_ci    uint32_t markPosition, void *userData)
55646f34cbfSopenharmony_ci{
55746f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, ERROR, "renderer client is nullptr");
55846f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERROR, "callback is nullptr");
55946f34cbfSopenharmony_ci    rendererPositionCallback_ = std::make_shared<OHRendererPositionCallback>(callback,
56046f34cbfSopenharmony_ci        reinterpret_cast<OH_AudioRenderer*>(this), userData);
56146f34cbfSopenharmony_ci    return audioRenderer_->SetRendererPositionCallback(markPosition, rendererPositionCallback_);
56246f34cbfSopenharmony_ci}
56346f34cbfSopenharmony_ci
56446f34cbfSopenharmony_civoid OHAudioRenderer::UnsetRendererPositionCallback()
56546f34cbfSopenharmony_ci{
56646f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(audioRenderer_ != nullptr, "renderer client is nullptr");
56746f34cbfSopenharmony_ci    audioRenderer_->UnsetRendererPositionCallback();
56846f34cbfSopenharmony_ci}
56946f34cbfSopenharmony_ci
57046f34cbfSopenharmony_civoid OHRendererPositionCallback::OnMarkReached(const int64_t &framePosition)
57146f34cbfSopenharmony_ci{
57246f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(ohAudioRenderer_ != nullptr, "renderer client is nullptr");
57346f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(callback_ != nullptr, "pointer to the function is nullptr");
57446f34cbfSopenharmony_ci    callback_(ohAudioRenderer_, framePosition, userData_);
57546f34cbfSopenharmony_ci}
57646f34cbfSopenharmony_ci
57746f34cbfSopenharmony_ciAudioChannelLayout OHAudioRenderer::GetChannelLayout()
57846f34cbfSopenharmony_ci{
57946f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, CH_LAYOUT_UNKNOWN, "renderer client is nullptr");
58046f34cbfSopenharmony_ci    AudioRendererParams params;
58146f34cbfSopenharmony_ci    audioRenderer_->GetParams(params);
58246f34cbfSopenharmony_ci    return params.channelLayout;
58346f34cbfSopenharmony_ci}
58446f34cbfSopenharmony_ci
58546f34cbfSopenharmony_ciAudioPrivacyType OHAudioRenderer::GetRendererPrivacy()
58646f34cbfSopenharmony_ci{
58746f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, PRIVACY_TYPE_PUBLIC, "renderer client is nullptr for privacy");
58846f34cbfSopenharmony_ci    return audioRenderer_->GetAudioPrivacyType();
58946f34cbfSopenharmony_ci}
59046f34cbfSopenharmony_ci
59146f34cbfSopenharmony_ciAudioEffectMode OHAudioRenderer::GetEffectMode()
59246f34cbfSopenharmony_ci{
59346f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, EFFECT_NONE, "renderer client is nullptr");
59446f34cbfSopenharmony_ci    return audioRenderer_->GetAudioEffectMode();
59546f34cbfSopenharmony_ci}
59646f34cbfSopenharmony_ci
59746f34cbfSopenharmony_ciint32_t OHAudioRenderer::SetEffectMode(AudioEffectMode effectMode)
59846f34cbfSopenharmony_ci{
59946f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, ERROR, "renderer client is nullptr");
60046f34cbfSopenharmony_ci    return audioRenderer_->SetAudioEffectMode(effectMode);
60146f34cbfSopenharmony_ci}
60246f34cbfSopenharmony_ci
60346f34cbfSopenharmony_civoid OHAudioRenderer::SetWriteDataCallback(RendererCallback rendererCallbacks, void *userData,
60446f34cbfSopenharmony_ci    void *metadataUserData, AudioEncodingType encodingType)
60546f34cbfSopenharmony_ci{
60646f34cbfSopenharmony_ci    if (encodingType == ENCODING_AUDIOVIVID && rendererCallbacks.writeDataWithMetadataCallback != nullptr) {
60746f34cbfSopenharmony_ci        std::shared_ptr<AudioRendererWriteCallback> callback = std::make_shared<OHAudioRendererModeCallback>(
60846f34cbfSopenharmony_ci            rendererCallbacks.writeDataWithMetadataCallback, (OH_AudioRenderer*)this, metadataUserData, encodingType);
60946f34cbfSopenharmony_ci        audioRenderer_->SetRendererWriteCallback(callback);
61046f34cbfSopenharmony_ci        AUDIO_INFO_LOG("The write callback function is for AudioVivid type");
61146f34cbfSopenharmony_ci    } else if (encodingType == ENCODING_PCM) {
61246f34cbfSopenharmony_ci        if (writeDataCallbackType_ == WRITE_DATA_CALLBACK_WITH_RESULT &&
61346f34cbfSopenharmony_ci            rendererCallbacks.onWriteDataCallback != nullptr) {
61446f34cbfSopenharmony_ci            std::shared_ptr<AudioRendererWriteCallback> callback = std::make_shared<OHAudioRendererModeCallback>(
61546f34cbfSopenharmony_ci                rendererCallbacks.onWriteDataCallback, (OH_AudioRenderer*)this, userData, encodingType);
61646f34cbfSopenharmony_ci            audioRenderer_->SetRendererWriteCallback(callback);
61746f34cbfSopenharmony_ci            AUDIO_INFO_LOG("The write callback function is for PCM type with result");
61846f34cbfSopenharmony_ci        }
61946f34cbfSopenharmony_ci
62046f34cbfSopenharmony_ci        if (writeDataCallbackType_ == WRITE_DATA_CALLBACK_WITHOUT_RESULT &&
62146f34cbfSopenharmony_ci            rendererCallbacks.callbacks.OH_AudioRenderer_OnWriteData != nullptr) {
62246f34cbfSopenharmony_ci            std::shared_ptr<AudioRendererWriteCallback> callback = std::make_shared<OHAudioRendererModeCallback>(
62346f34cbfSopenharmony_ci                rendererCallbacks.callbacks, (OH_AudioRenderer*)this, userData, encodingType);
62446f34cbfSopenharmony_ci            audioRenderer_->SetRendererWriteCallback(callback);
62546f34cbfSopenharmony_ci            AUDIO_INFO_LOG("The write callback function is for PCM type without result");
62646f34cbfSopenharmony_ci        }
62746f34cbfSopenharmony_ci    } else {
62846f34cbfSopenharmony_ci        AUDIO_WARNING_LOG("The write callback function is not set");
62946f34cbfSopenharmony_ci    }
63046f34cbfSopenharmony_ci}
63146f34cbfSopenharmony_ci
63246f34cbfSopenharmony_civoid OHAudioRenderer::SetInterruptCallback(RendererCallback rendererCallbacks, void *userData)
63346f34cbfSopenharmony_ci{
63446f34cbfSopenharmony_ci    if (rendererCallbacks.callbacks.OH_AudioRenderer_OnInterruptEvent != nullptr) {
63546f34cbfSopenharmony_ci        audioRendererCallback_ = std::make_shared<OHAudioRendererCallback>(rendererCallbacks.callbacks,
63646f34cbfSopenharmony_ci            (OH_AudioRenderer*)this, userData);
63746f34cbfSopenharmony_ci        audioRenderer_->SetRendererCallback(audioRendererCallback_);
63846f34cbfSopenharmony_ci    } else {
63946f34cbfSopenharmony_ci        AUDIO_WARNING_LOG("The audio renderer interrupt callback function is not set");
64046f34cbfSopenharmony_ci    }
64146f34cbfSopenharmony_ci}
64246f34cbfSopenharmony_ci
64346f34cbfSopenharmony_civoid OHAudioRenderer::SetErrorCallback(RendererCallback rendererCallbacks, void *userData)
64446f34cbfSopenharmony_ci{
64546f34cbfSopenharmony_ci    if (rendererCallbacks.callbacks.OH_AudioRenderer_OnError != nullptr) {
64646f34cbfSopenharmony_ci        std::shared_ptr<AudioRendererPolicyServiceDiedCallback> callback =
64746f34cbfSopenharmony_ci            std::make_shared<OHServiceDiedCallback>(rendererCallbacks.callbacks, (OH_AudioRenderer*)this, userData);
64846f34cbfSopenharmony_ci        int32_t clientPid = getpid();
64946f34cbfSopenharmony_ci        audioRenderer_->RegisterAudioPolicyServerDiedCb(clientPid, callback);
65046f34cbfSopenharmony_ci
65146f34cbfSopenharmony_ci        std::shared_ptr<AudioRendererErrorCallback> errorCallback = std::make_shared<OHAudioRendererErrorCallback>(
65246f34cbfSopenharmony_ci            rendererCallbacks.callbacks, (OH_AudioRenderer*)this, userData);
65346f34cbfSopenharmony_ci        audioRenderer_->SetAudioRendererErrorCallback(errorCallback);
65446f34cbfSopenharmony_ci    } else {
65546f34cbfSopenharmony_ci        AUDIO_WARNING_LOG("The audio renderer error callback function is not set");
65646f34cbfSopenharmony_ci    }
65746f34cbfSopenharmony_ci}
65846f34cbfSopenharmony_ci
65946f34cbfSopenharmony_civoid OHAudioRenderer::SetRendererCallback(RendererCallback rendererCallbacks, void *userData, void *metadataUserData)
66046f34cbfSopenharmony_ci{
66146f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(audioRenderer_ != nullptr, "renderer client is nullptr");
66246f34cbfSopenharmony_ci    audioRenderer_->SetRenderMode(RENDER_MODE_CALLBACK);
66346f34cbfSopenharmony_ci
66446f34cbfSopenharmony_ci    AudioEncodingType encodingType = GetEncodingType();
66546f34cbfSopenharmony_ci    SetWriteDataCallback(rendererCallbacks, userData, metadataUserData, encodingType);
66646f34cbfSopenharmony_ci    SetInterruptCallback(rendererCallbacks, userData);
66746f34cbfSopenharmony_ci    SetErrorCallback(rendererCallbacks, userData);
66846f34cbfSopenharmony_ci}
66946f34cbfSopenharmony_ci
67046f34cbfSopenharmony_civoid OHAudioRenderer::SetRendererOutputDeviceChangeCallback(OH_AudioRenderer_OutputDeviceChangeCallback callback,
67146f34cbfSopenharmony_ci    void *userData)
67246f34cbfSopenharmony_ci{
67346f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(audioRenderer_ != nullptr, "renderer client is nullptr");
67446f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(callback != nullptr, "callback is nullptr");
67546f34cbfSopenharmony_ci    audioRendererDeviceChangeCallbackWithInfo_ =
67646f34cbfSopenharmony_ci        std::make_shared<OHAudioRendererDeviceChangeCallbackWithInfo> (callback,
67746f34cbfSopenharmony_ci        reinterpret_cast<OH_AudioRenderer*>(this), userData);
67846f34cbfSopenharmony_ci    audioRenderer_->RegisterOutputDeviceChangeWithInfoCallback(audioRendererDeviceChangeCallbackWithInfo_);
67946f34cbfSopenharmony_ci}
68046f34cbfSopenharmony_ci
68146f34cbfSopenharmony_civoid OHAudioRenderer::SetPreferredFrameSize(int32_t frameSize)
68246f34cbfSopenharmony_ci{
68346f34cbfSopenharmony_ci    audioRenderer_->SetPreferredFrameSize(frameSize);
68446f34cbfSopenharmony_ci}
68546f34cbfSopenharmony_ci
68646f34cbfSopenharmony_cibool OHAudioRenderer::IsFastRenderer()
68746f34cbfSopenharmony_ci{
68846f34cbfSopenharmony_ci    return audioRenderer_->IsFastRenderer();
68946f34cbfSopenharmony_ci}
69046f34cbfSopenharmony_ci
69146f34cbfSopenharmony_ciuint32_t OHAudioRenderer::GetUnderflowCount()
69246f34cbfSopenharmony_ci{
69346f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, ERROR, "renderer client is nullptr");
69446f34cbfSopenharmony_ci    return audioRenderer_->GetUnderflowCount();
69546f34cbfSopenharmony_ci}
69646f34cbfSopenharmony_ci
69746f34cbfSopenharmony_civoid OHAudioRendererModeCallback::OnWriteData(size_t length)
69846f34cbfSopenharmony_ci{
69946f34cbfSopenharmony_ci    OHAudioRenderer *audioRenderer = (OHAudioRenderer*)ohAudioRenderer_;
70046f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(audioRenderer != nullptr, "renderer client is nullptr");
70146f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(((encodingType_ == ENCODING_PCM) && (callbacks_.OH_AudioRenderer_OnWriteData != nullptr)) ||
70246f34cbfSopenharmony_ci        ((encodingType_ == ENCODING_PCM) && (onWriteDataCallback_ != nullptr)) ||
70346f34cbfSopenharmony_ci        ((encodingType_ == ENCODING_AUDIOVIVID) && (writeDataWithMetadataCallback_ != nullptr)),
70446f34cbfSopenharmony_ci        "pointer to the function is nullptr");
70546f34cbfSopenharmony_ci    BufferDesc bufDesc;
70646f34cbfSopenharmony_ci    audioRenderer->GetBufferDesc(bufDesc);
70746f34cbfSopenharmony_ci    if (encodingType_ == ENCODING_AUDIOVIVID && writeDataWithMetadataCallback_ != nullptr) {
70846f34cbfSopenharmony_ci        writeDataWithMetadataCallback_(ohAudioRenderer_, metadataUserData_, (void*)bufDesc.buffer, bufDesc.bufLength,
70946f34cbfSopenharmony_ci            (void*)bufDesc.metaBuffer, bufDesc.metaLength);
71046f34cbfSopenharmony_ci    } else {
71146f34cbfSopenharmony_ci        if (audioRenderer->GetRendererCallbackType() == WRITE_DATA_CALLBACK_WITHOUT_RESULT &&
71246f34cbfSopenharmony_ci            callbacks_.OH_AudioRenderer_OnWriteData != nullptr) {
71346f34cbfSopenharmony_ci            callbacks_.OH_AudioRenderer_OnWriteData(ohAudioRenderer_, userData_,
71446f34cbfSopenharmony_ci                (void*)bufDesc.buffer, bufDesc.bufLength);
71546f34cbfSopenharmony_ci        }
71646f34cbfSopenharmony_ci        if (audioRenderer->GetRendererCallbackType() == WRITE_DATA_CALLBACK_WITH_RESULT &&
71746f34cbfSopenharmony_ci            onWriteDataCallback_ != nullptr) {
71846f34cbfSopenharmony_ci            OH_AudioData_Callback_Result result = onWriteDataCallback_(ohAudioRenderer_, userData_,
71946f34cbfSopenharmony_ci                (void*)bufDesc.buffer, bufDesc.bufLength);
72046f34cbfSopenharmony_ci            if (result == AUDIO_DATA_CALLBACK_RESULT_INVALID) {
72146f34cbfSopenharmony_ci                AUDIO_DEBUG_LOG("Data callback returned invalid, data will not be used.");
72246f34cbfSopenharmony_ci                bufDesc.dataLength = 0; // Ensure that the invalid data is not used.
72346f34cbfSopenharmony_ci            }
72446f34cbfSopenharmony_ci        }
72546f34cbfSopenharmony_ci    }
72646f34cbfSopenharmony_ci    audioRenderer->Enqueue(bufDesc);
72746f34cbfSopenharmony_ci}
72846f34cbfSopenharmony_ci
72946f34cbfSopenharmony_civoid OHAudioRendererDeviceChangeCallback::OnOutputDeviceChange(const DeviceInfo &deviceInfo,
73046f34cbfSopenharmony_ci    const AudioStreamDeviceChangeReason reason)
73146f34cbfSopenharmony_ci{
73246f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(ohAudioRenderer_ != nullptr, "renderer client is nullptr");
73346f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(callbacks_.OH_AudioRenderer_OnStreamEvent != nullptr, "pointer to the function is nullptr");
73446f34cbfSopenharmony_ci
73546f34cbfSopenharmony_ci    OH_AudioStream_Event event =  AUDIOSTREAM_EVENT_ROUTING_CHANGED;
73646f34cbfSopenharmony_ci    callbacks_.OH_AudioRenderer_OnStreamEvent(ohAudioRenderer_, userData_, event);
73746f34cbfSopenharmony_ci}
73846f34cbfSopenharmony_ci
73946f34cbfSopenharmony_civoid OHAudioRendererCallback::OnInterrupt(const InterruptEvent &interruptEvent)
74046f34cbfSopenharmony_ci{
74146f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(ohAudioRenderer_ != nullptr, "renderer client is nullptr");
74246f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(callbacks_.OH_AudioRenderer_OnInterruptEvent != nullptr, "pointer to the function is nullptr");
74346f34cbfSopenharmony_ci    OH_AudioInterrupt_ForceType type = (OH_AudioInterrupt_ForceType)(interruptEvent.forceType);
74446f34cbfSopenharmony_ci    OH_AudioInterrupt_Hint hint = OH_AudioInterrupt_Hint(interruptEvent.hintType);
74546f34cbfSopenharmony_ci    callbacks_.OH_AudioRenderer_OnInterruptEvent(ohAudioRenderer_, userData_, type, hint);
74646f34cbfSopenharmony_ci}
74746f34cbfSopenharmony_ci
74846f34cbfSopenharmony_civoid OHServiceDiedCallback::OnAudioPolicyServiceDied()
74946f34cbfSopenharmony_ci{
75046f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(ohAudioRenderer_ != nullptr, "renderer client is nullptr");
75146f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(callbacks_.OH_AudioRenderer_OnError != nullptr, "pointer to the function is nullptr");
75246f34cbfSopenharmony_ci    OH_AudioStream_Result error = AUDIOSTREAM_ERROR_SYSTEM;
75346f34cbfSopenharmony_ci    callbacks_.OH_AudioRenderer_OnError(ohAudioRenderer_, userData_, error);
75446f34cbfSopenharmony_ci}
75546f34cbfSopenharmony_ci
75646f34cbfSopenharmony_ciOH_AudioStream_Result OHAudioRendererErrorCallback::GetErrorResult(AudioErrors errorCode) const
75746f34cbfSopenharmony_ci{
75846f34cbfSopenharmony_ci    switch (errorCode) {
75946f34cbfSopenharmony_ci        case ERROR_ILLEGAL_STATE:
76046f34cbfSopenharmony_ci            return AUDIOSTREAM_ERROR_ILLEGAL_STATE;
76146f34cbfSopenharmony_ci        case ERROR_INVALID_PARAM:
76246f34cbfSopenharmony_ci            return AUDIOSTREAM_ERROR_INVALID_PARAM;
76346f34cbfSopenharmony_ci        case ERROR_SYSTEM:
76446f34cbfSopenharmony_ci            return AUDIOSTREAM_ERROR_SYSTEM;
76546f34cbfSopenharmony_ci        default:
76646f34cbfSopenharmony_ci            return AUDIOSTREAM_ERROR_SYSTEM;
76746f34cbfSopenharmony_ci    }
76846f34cbfSopenharmony_ci}
76946f34cbfSopenharmony_ci
77046f34cbfSopenharmony_civoid OHAudioRendererErrorCallback::OnError(AudioErrors errorCode)
77146f34cbfSopenharmony_ci{
77246f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(ohAudioRenderer_ != nullptr && callbacks_.OH_AudioRenderer_OnError != nullptr,
77346f34cbfSopenharmony_ci        "renderer client or error callback funtion is nullptr");
77446f34cbfSopenharmony_ci    OH_AudioStream_Result error = GetErrorResult(errorCode);
77546f34cbfSopenharmony_ci    callbacks_.OH_AudioRenderer_OnError(ohAudioRenderer_, userData_, error);
77646f34cbfSopenharmony_ci}
77746f34cbfSopenharmony_ci
77846f34cbfSopenharmony_civoid OHAudioRendererDeviceChangeCallbackWithInfo::OnOutputDeviceChange(const DeviceInfo &deviceInfo,
77946f34cbfSopenharmony_ci    const AudioStreamDeviceChangeReason reason)
78046f34cbfSopenharmony_ci{
78146f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(ohAudioRenderer_ != nullptr, "renderer client is nullptr");
78246f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(callback_ != nullptr, "pointer to the function is nullptr");
78346f34cbfSopenharmony_ci
78446f34cbfSopenharmony_ci    callback_(ohAudioRenderer_, userData_, static_cast<OH_AudioStream_DeviceChangeReason>(reason));
78546f34cbfSopenharmony_ci}
78646f34cbfSopenharmony_ci
78746f34cbfSopenharmony_civoid OHAudioRenderer::SetInterruptMode(InterruptMode mode)
78846f34cbfSopenharmony_ci{
78946f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(audioRenderer_ != nullptr, "renderer client is nullptr");
79046f34cbfSopenharmony_ci    audioRenderer_->SetInterruptMode(mode);
79146f34cbfSopenharmony_ci}
79246f34cbfSopenharmony_ci
79346f34cbfSopenharmony_civoid OHAudioRenderer::SetSilentModeAndMixWithOthers(bool on)
79446f34cbfSopenharmony_ci{
79546f34cbfSopenharmony_ci    CHECK_AND_RETURN_LOG(audioRenderer_ != nullptr, "renderer client is nullptr");
79646f34cbfSopenharmony_ci    audioRenderer_->SetSilentModeAndMixWithOthers(on);
79746f34cbfSopenharmony_ci}
79846f34cbfSopenharmony_ci
79946f34cbfSopenharmony_cibool OHAudioRenderer::GetSilentModeAndMixWithOthers()
80046f34cbfSopenharmony_ci{
80146f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, false, "renderer client is nullptr");
80246f34cbfSopenharmony_ci    return audioRenderer_->GetSilentModeAndMixWithOthers();
80346f34cbfSopenharmony_ci}
80446f34cbfSopenharmony_ci
80546f34cbfSopenharmony_ciint32_t OHAudioRenderer::SetDefaultOutputDevice(DeviceType deviceType)
80646f34cbfSopenharmony_ci{
80746f34cbfSopenharmony_ci    CHECK_AND_RETURN_RET_LOG(audioRenderer_ != nullptr, ERROR, "renderer client is nullptr");
80846f34cbfSopenharmony_ci    return audioRenderer_->SetDefaultOutputDevice(deviceType);
80946f34cbfSopenharmony_ci}
81046f34cbfSopenharmony_ci
81146f34cbfSopenharmony_civoid OHAudioRenderer::SetRendererCallbackType(WriteDataCallbackType writeDataCallbackType)
81246f34cbfSopenharmony_ci{
81346f34cbfSopenharmony_ci    writeDataCallbackType_ = writeDataCallbackType;
81446f34cbfSopenharmony_ci}
81546f34cbfSopenharmony_ci
81646f34cbfSopenharmony_ciWriteDataCallbackType OHAudioRenderer::GetRendererCallbackType()
81746f34cbfSopenharmony_ci{
81846f34cbfSopenharmony_ci    return writeDataCallbackType_;
81946f34cbfSopenharmony_ci}
82046f34cbfSopenharmony_ci}  // namespace AudioStandard
82146f34cbfSopenharmony_ci}  // namespace OHOS
822