180922886Sopenharmony_ci/*
280922886Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
380922886Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
480922886Sopenharmony_ci * you may not use this file except in compliance with the License.
580922886Sopenharmony_ci * You may obtain a copy of the License at
680922886Sopenharmony_ci *
780922886Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
880922886Sopenharmony_ci *
980922886Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1080922886Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1180922886Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1280922886Sopenharmony_ci * See the License for the specific language governing permissions and
1380922886Sopenharmony_ci * limitations under the License.
1480922886Sopenharmony_ci */
1580922886Sopenharmony_ci
1680922886Sopenharmony_ci#include "OHAVSession.h"
1780922886Sopenharmony_ci#include "avmeta_data.h"
1880922886Sopenharmony_ci#include "avsession_manager.h"
1980922886Sopenharmony_ci
2080922886Sopenharmony_cinamespace OHOS::AVSession {
2180922886Sopenharmony_ciOHAVSession::~OHAVSession()
2280922886Sopenharmony_ci{
2380922886Sopenharmony_ci}
2480922886Sopenharmony_ci
2580922886Sopenharmony_ciOHAVSession::OHAVSession()
2680922886Sopenharmony_ci{
2780922886Sopenharmony_ci}
2880922886Sopenharmony_ci
2980922886Sopenharmony_ciOHAVSession::OHAVSession(AVSession_Type sessionType, const char* sessionTag,
3080922886Sopenharmony_ci    const char* bundleName, const char* abilityName)
3180922886Sopenharmony_ci{
3280922886Sopenharmony_ci    AppExecFwk::ElementName elementName;
3380922886Sopenharmony_ci    elementName.SetBundleName(bundleName);
3480922886Sopenharmony_ci    elementName.SetAbilityName(abilityName);
3580922886Sopenharmony_ci    avSession_ = AVSessionManager::GetInstance().CreateSession(sessionTag, sessionType, elementName);
3680922886Sopenharmony_ci}
3780922886Sopenharmony_ci
3880922886Sopenharmony_cibool OHAVSession::IsAVSessionNull()
3980922886Sopenharmony_ci{
4080922886Sopenharmony_ci    return avSession_ == nullptr;
4180922886Sopenharmony_ci}
4280922886Sopenharmony_ci
4380922886Sopenharmony_ciAVSession_ErrCode OHAVSession::GetEncodeErrcode(int32_t ret)
4480922886Sopenharmony_ci{
4580922886Sopenharmony_ci    auto it = errcodes.find(ret);
4680922886Sopenharmony_ci    if (it != errcodes.end()) {
4780922886Sopenharmony_ci        return it->second;
4880922886Sopenharmony_ci    }
4980922886Sopenharmony_ci    return AV_SESSION_ERR_SERVICE_EXCEPTION;
5080922886Sopenharmony_ci}
5180922886Sopenharmony_ci
5280922886Sopenharmony_ciAVSession_ErrCode OHAVSession::Activate()
5380922886Sopenharmony_ci{
5480922886Sopenharmony_ci    int32_t ret = avSession_->Activate();
5580922886Sopenharmony_ci    return GetEncodeErrcode(ret);
5680922886Sopenharmony_ci}
5780922886Sopenharmony_ci
5880922886Sopenharmony_ci
5980922886Sopenharmony_ciAVSession_ErrCode OHAVSession::Deactivate()
6080922886Sopenharmony_ci{
6180922886Sopenharmony_ci    int32_t ret = avSession_->Deactivate();
6280922886Sopenharmony_ci    return GetEncodeErrcode(ret);
6380922886Sopenharmony_ci}
6480922886Sopenharmony_ci
6580922886Sopenharmony_cistd::string OHAVSession::GetSessionType()
6680922886Sopenharmony_ci{
6780922886Sopenharmony_ci    std::string sessionType = avSession_->GetSessionType();
6880922886Sopenharmony_ci    return sessionType;
6980922886Sopenharmony_ci}
7080922886Sopenharmony_ci
7180922886Sopenharmony_ciconst std::string& OHAVSession::GetSessionId()
7280922886Sopenharmony_ci{
7380922886Sopenharmony_ci    if (sessionId_.empty()) {
7480922886Sopenharmony_ci        sessionId_ = avSession_->GetSessionId();
7580922886Sopenharmony_ci    }
7680922886Sopenharmony_ci    return sessionId_;
7780922886Sopenharmony_ci}
7880922886Sopenharmony_ci
7980922886Sopenharmony_ciAVSession_ErrCode OHAVSession::SetAVMetaData(OH_AVMetadata* metadata)
8080922886Sopenharmony_ci{
8180922886Sopenharmony_ci    AVMetaData* avMetaData = reinterpret_cast<AVMetaData*>(metadata);
8280922886Sopenharmony_ci    int32_t ret = avSession_->SetAVMetaData(*avMetaData);
8380922886Sopenharmony_ci    return GetEncodeErrcode(ret);
8480922886Sopenharmony_ci}
8580922886Sopenharmony_ci
8680922886Sopenharmony_ciAVSession_ErrCode OHAVSession::SetPlaybackState(AVSession_PlaybackState playbackState)
8780922886Sopenharmony_ci{
8880922886Sopenharmony_ci    AVPlaybackState avPlaybackState;
8980922886Sopenharmony_ci    avPlaybackState.SetState(playbackState);
9080922886Sopenharmony_ci    int32_t ret = avSession_->SetAVPlaybackState(avPlaybackState);
9180922886Sopenharmony_ci    return GetEncodeErrcode(ret);
9280922886Sopenharmony_ci}
9380922886Sopenharmony_ci
9480922886Sopenharmony_ciAVSession_ErrCode OHAVSession::SetPlaybackPosition(AVSession_PlaybackPosition* playbackPosition)
9580922886Sopenharmony_ci{
9680922886Sopenharmony_ci    AVPlaybackState avPlaybackState;
9780922886Sopenharmony_ci    AVPlaybackState::Position pos = {playbackPosition->elapsedTime, playbackPosition->updateTime};
9880922886Sopenharmony_ci    avPlaybackState.SetPosition(pos);
9980922886Sopenharmony_ci    int32_t ret = avSession_->SetAVPlaybackState(avPlaybackState);
10080922886Sopenharmony_ci    return GetEncodeErrcode(ret);
10180922886Sopenharmony_ci}
10280922886Sopenharmony_ci
10380922886Sopenharmony_ciAVSession_ErrCode OHAVSession::SetFavorite(bool favorite)
10480922886Sopenharmony_ci{
10580922886Sopenharmony_ci    AVPlaybackState avPlaybackState;
10680922886Sopenharmony_ci    avPlaybackState.SetFavorite(favorite);
10780922886Sopenharmony_ci    int32_t ret = avSession_->SetAVPlaybackState(avPlaybackState);
10880922886Sopenharmony_ci    return GetEncodeErrcode(ret);
10980922886Sopenharmony_ci}
11080922886Sopenharmony_ci
11180922886Sopenharmony_ciAVSession_ErrCode OHAVSession::SetLoopMode(AVSession_LoopMode loopMode)
11280922886Sopenharmony_ci{
11380922886Sopenharmony_ci    AVPlaybackState avPlaybackState;
11480922886Sopenharmony_ci    avPlaybackState.SetLoopMode(loopMode);
11580922886Sopenharmony_ci    int32_t ret = avSession_->SetAVPlaybackState(avPlaybackState);
11680922886Sopenharmony_ci    return GetEncodeErrcode(ret);
11780922886Sopenharmony_ci}
11880922886Sopenharmony_ci
11980922886Sopenharmony_ciAVSession_ErrCode OHAVSession::RegisterCommandCallback(AVSession_ControlCommand command,
12080922886Sopenharmony_ci    OH_AVSessionCallback_OnCommand callback, void* userData)
12180922886Sopenharmony_ci{
12280922886Sopenharmony_ci    int32_t ret = 0;
12380922886Sopenharmony_ci    std::lock_guard<std::mutex> lockGuard(lock_);
12480922886Sopenharmony_ci    if (ohAVSessionCallbackImpl_ == nullptr) {
12580922886Sopenharmony_ci        ohAVSessionCallbackImpl_ = std::make_shared<OHAVSessionCallbackImpl>();
12680922886Sopenharmony_ci        ret = avSession_->RegisterCallback(ohAVSessionCallbackImpl_);
12780922886Sopenharmony_ci    }
12880922886Sopenharmony_ci    ret = avSession_->AddSupportCommand(static_cast<int32_t>(command));
12980922886Sopenharmony_ci    if (static_cast<AVSession_ErrCode>(ret) != AV_SESSION_ERR_SUCCESS) {
13080922886Sopenharmony_ci        return GetEncodeErrcode(ret);
13180922886Sopenharmony_ci    }
13280922886Sopenharmony_ci    switch (command) {
13380922886Sopenharmony_ci        case CONTROL_CMD_PLAY:
13480922886Sopenharmony_ci            ohAVSessionCallbackImpl_->SetPlayCallback((OH_AVSession*)this, command, callback, userData);
13580922886Sopenharmony_ci            break;
13680922886Sopenharmony_ci        case CONTROL_CMD_PAUSE:
13780922886Sopenharmony_ci            ohAVSessionCallbackImpl_->SetPauseCallback((OH_AVSession*)this, command, callback, userData);
13880922886Sopenharmony_ci            break;
13980922886Sopenharmony_ci        case CONTROL_CMD_STOP:
14080922886Sopenharmony_ci            ohAVSessionCallbackImpl_->SetStopCallback((OH_AVSession*)this, command, callback, userData);
14180922886Sopenharmony_ci            break;
14280922886Sopenharmony_ci        case CONTROL_CMD_PLAY_NEXT:
14380922886Sopenharmony_ci            ohAVSessionCallbackImpl_->SetPlayNextCallback((OH_AVSession*)this, command, callback, userData);
14480922886Sopenharmony_ci            break;
14580922886Sopenharmony_ci        case CONTROL_CMD_PLAY_PREVIOUS:
14680922886Sopenharmony_ci            ohAVSessionCallbackImpl_->SetPlayPreviousCallback((OH_AVSession*)this, command, callback, userData);
14780922886Sopenharmony_ci            break;
14880922886Sopenharmony_ci        default:
14980922886Sopenharmony_ci            break;
15080922886Sopenharmony_ci    }
15180922886Sopenharmony_ci    return GetEncodeErrcode(ret);
15280922886Sopenharmony_ci}
15380922886Sopenharmony_ci
15480922886Sopenharmony_ciAVSession_ErrCode OHAVSession::UnregisterCommandCallback(AVSession_ControlCommand command,
15580922886Sopenharmony_ci    OH_AVSessionCallback_OnCommand callback)
15680922886Sopenharmony_ci{
15780922886Sopenharmony_ci    if (ohAVSessionCallbackImpl_ == nullptr) {
15880922886Sopenharmony_ci        return AV_SESSION_ERR_SUCCESS;
15980922886Sopenharmony_ci    }
16080922886Sopenharmony_ci    std::lock_guard<std::mutex> lockGuard(lock_);
16180922886Sopenharmony_ci    int32_t ret = avSession_->DeleteSupportCommand(static_cast<int32_t>(command));
16280922886Sopenharmony_ci    if (static_cast<AVSession_ErrCode>(ret) != AV_SESSION_ERR_SUCCESS) {
16380922886Sopenharmony_ci        return GetEncodeErrcode(ret);
16480922886Sopenharmony_ci    }
16580922886Sopenharmony_ci    switch (command) {
16680922886Sopenharmony_ci        case CONTROL_CMD_PLAY:
16780922886Sopenharmony_ci            ohAVSessionCallbackImpl_->UnSetPlayCallback((OH_AVSession*)this, command, callback);
16880922886Sopenharmony_ci            break;
16980922886Sopenharmony_ci        case CONTROL_CMD_PAUSE:
17080922886Sopenharmony_ci            ohAVSessionCallbackImpl_->UnSetPauseCallback((OH_AVSession*)this, command, callback);
17180922886Sopenharmony_ci            break;
17280922886Sopenharmony_ci        case CONTROL_CMD_STOP:
17380922886Sopenharmony_ci            ohAVSessionCallbackImpl_->UnSetStopCallback((OH_AVSession*)this, command, callback);
17480922886Sopenharmony_ci            break;
17580922886Sopenharmony_ci        case CONTROL_CMD_PLAY_NEXT:
17680922886Sopenharmony_ci            ohAVSessionCallbackImpl_->UnSetPlayNextCallback((OH_AVSession*)this, command, callback);
17780922886Sopenharmony_ci            break;
17880922886Sopenharmony_ci        case CONTROL_CMD_PLAY_PREVIOUS:
17980922886Sopenharmony_ci            ohAVSessionCallbackImpl_->UnSetPlayPreviousCallback((OH_AVSession*)this, command, callback);
18080922886Sopenharmony_ci            break;
18180922886Sopenharmony_ci        default:
18280922886Sopenharmony_ci            break;
18380922886Sopenharmony_ci    }
18480922886Sopenharmony_ci    return AV_SESSION_ERR_SUCCESS;
18580922886Sopenharmony_ci}
18680922886Sopenharmony_ci
18780922886Sopenharmony_ciAVSession_ErrCode OHAVSession::CheckAndRegister()
18880922886Sopenharmony_ci{
18980922886Sopenharmony_ci    if (ohAVSessionCallbackImpl_ == nullptr) {
19080922886Sopenharmony_ci        ohAVSessionCallbackImpl_ = std::make_shared<OHAVSessionCallbackImpl>();
19180922886Sopenharmony_ci        AVSession_ErrCode ret =  static_cast<AVSession_ErrCode>(
19280922886Sopenharmony_ci            avSession_->RegisterCallback(ohAVSessionCallbackImpl_));
19380922886Sopenharmony_ci        CHECK_AND_RETURN_RET_LOG(ret == AV_SESSION_ERR_SUCCESS, AV_SESSION_ERR_SERVICE_EXCEPTION,
19480922886Sopenharmony_ci            "RegisterCallback failed");
19580922886Sopenharmony_ci    }
19680922886Sopenharmony_ci    return AV_SESSION_ERR_SUCCESS;
19780922886Sopenharmony_ci}
19880922886Sopenharmony_ci
19980922886Sopenharmony_ciAVSession_ErrCode OHAVSession::RegisterForwardCallback(OH_AVSessionCallback_OnFastForward callback, void* userData)
20080922886Sopenharmony_ci{
20180922886Sopenharmony_ci    std::lock_guard<std::mutex> lockGuard(lock_);
20280922886Sopenharmony_ci    CheckAndRegister();
20380922886Sopenharmony_ci    int32_t ret = avSession_->AddSupportCommand(static_cast<int32_t>(AVControlCommand::SESSION_CMD_FAST_FORWARD));
20480922886Sopenharmony_ci    if (static_cast<AVSession_ErrCode>(ret) != AV_SESSION_ERR_SUCCESS) {
20580922886Sopenharmony_ci        return GetEncodeErrcode(ret);
20680922886Sopenharmony_ci    }
20780922886Sopenharmony_ci    ohAVSessionCallbackImpl_->RegisterForwardCallback((OH_AVSession*)this, callback, userData);
20880922886Sopenharmony_ci    return AV_SESSION_ERR_SUCCESS;
20980922886Sopenharmony_ci}
21080922886Sopenharmony_ci
21180922886Sopenharmony_ciAVSession_ErrCode OHAVSession::UnregisterForwardCallback(OH_AVSessionCallback_OnFastForward callback)
21280922886Sopenharmony_ci{
21380922886Sopenharmony_ci    if (ohAVSessionCallbackImpl_ == nullptr) {
21480922886Sopenharmony_ci        return AV_SESSION_ERR_SUCCESS;
21580922886Sopenharmony_ci    }
21680922886Sopenharmony_ci    std::lock_guard<std::mutex> lockGuard(lock_);
21780922886Sopenharmony_ci    int32_t ret = avSession_->DeleteSupportCommand(static_cast<int32_t>(AVControlCommand::SESSION_CMD_FAST_FORWARD));
21880922886Sopenharmony_ci    if (static_cast<AVSession_ErrCode>(ret) != AV_SESSION_ERR_SUCCESS) {
21980922886Sopenharmony_ci        return GetEncodeErrcode(ret);
22080922886Sopenharmony_ci    }
22180922886Sopenharmony_ci    ohAVSessionCallbackImpl_->UnregisterForwardCallback((OH_AVSession*)this, callback);
22280922886Sopenharmony_ci    return AV_SESSION_ERR_SUCCESS;
22380922886Sopenharmony_ci}
22480922886Sopenharmony_ci
22580922886Sopenharmony_ciAVSession_ErrCode OHAVSession::RegisterRewindCallback(OH_AVSessionCallback_OnRewind callback, void* userData)
22680922886Sopenharmony_ci{
22780922886Sopenharmony_ci    std::lock_guard<std::mutex> lockGuard(lock_);
22880922886Sopenharmony_ci    CheckAndRegister();
22980922886Sopenharmony_ci    int32_t ret = avSession_->AddSupportCommand(static_cast<int32_t>(AVControlCommand::SESSION_CMD_REWIND));
23080922886Sopenharmony_ci    if (static_cast<AVSession_ErrCode>(ret) != AV_SESSION_ERR_SUCCESS) {
23180922886Sopenharmony_ci        return GetEncodeErrcode(ret);
23280922886Sopenharmony_ci    }
23380922886Sopenharmony_ci    ohAVSessionCallbackImpl_->RegisterRewindCallback((OH_AVSession*)this, callback, userData);
23480922886Sopenharmony_ci    return AV_SESSION_ERR_SUCCESS;
23580922886Sopenharmony_ci}
23680922886Sopenharmony_ci
23780922886Sopenharmony_ciAVSession_ErrCode OHAVSession::UnregisterRewindCallback(OH_AVSessionCallback_OnRewind callback)
23880922886Sopenharmony_ci{
23980922886Sopenharmony_ci    if (ohAVSessionCallbackImpl_ == nullptr) {
24080922886Sopenharmony_ci        return AV_SESSION_ERR_SUCCESS;
24180922886Sopenharmony_ci    }
24280922886Sopenharmony_ci    std::lock_guard<std::mutex> lockGuard(lock_);
24380922886Sopenharmony_ci    int32_t ret = avSession_->DeleteSupportCommand(static_cast<int32_t>(AVControlCommand::SESSION_CMD_REWIND));
24480922886Sopenharmony_ci    if (static_cast<AVSession_ErrCode>(ret) != AV_SESSION_ERR_SUCCESS) {
24580922886Sopenharmony_ci        return GetEncodeErrcode(ret);
24680922886Sopenharmony_ci    }
24780922886Sopenharmony_ci    ohAVSessionCallbackImpl_->UnregisterRewindCallback((OH_AVSession*)this, callback);
24880922886Sopenharmony_ci    return AV_SESSION_ERR_SUCCESS;
24980922886Sopenharmony_ci}
25080922886Sopenharmony_ci
25180922886Sopenharmony_ciAVSession_ErrCode OHAVSession::RegisterSeekCallback(OH_AVSessionCallback_OnSeek callback, void* userData)
25280922886Sopenharmony_ci{
25380922886Sopenharmony_ci    std::lock_guard<std::mutex> lockGuard(lock_);
25480922886Sopenharmony_ci    CheckAndRegister();
25580922886Sopenharmony_ci    int32_t ret = avSession_->AddSupportCommand(static_cast<int32_t>(AVControlCommand::SESSION_CMD_SEEK));
25680922886Sopenharmony_ci    if (static_cast<AVSession_ErrCode>(ret) != AV_SESSION_ERR_SUCCESS) {
25780922886Sopenharmony_ci        return GetEncodeErrcode(ret);
25880922886Sopenharmony_ci    }
25980922886Sopenharmony_ci    ohAVSessionCallbackImpl_->RegisterSeekCallback((OH_AVSession*)this, callback, userData);
26080922886Sopenharmony_ci    return AV_SESSION_ERR_SUCCESS;
26180922886Sopenharmony_ci}
26280922886Sopenharmony_ci
26380922886Sopenharmony_ciAVSession_ErrCode OHAVSession::UnregisterSeekCallback(OH_AVSessionCallback_OnSeek callback)
26480922886Sopenharmony_ci{
26580922886Sopenharmony_ci    if (ohAVSessionCallbackImpl_ == nullptr) {
26680922886Sopenharmony_ci        return AV_SESSION_ERR_SUCCESS;
26780922886Sopenharmony_ci    }
26880922886Sopenharmony_ci    std::lock_guard<std::mutex> lockGuard(lock_);
26980922886Sopenharmony_ci    int32_t ret = avSession_->DeleteSupportCommand(static_cast<int32_t>(AVControlCommand::SESSION_CMD_SEEK));
27080922886Sopenharmony_ci    if (static_cast<AVSession_ErrCode>(ret) != AV_SESSION_ERR_SUCCESS) {
27180922886Sopenharmony_ci        return GetEncodeErrcode(ret);
27280922886Sopenharmony_ci    }
27380922886Sopenharmony_ci    ohAVSessionCallbackImpl_->UnregisterSeekCallback((OH_AVSession*)this, callback);
27480922886Sopenharmony_ci    return AV_SESSION_ERR_SUCCESS;
27580922886Sopenharmony_ci}
27680922886Sopenharmony_ci
27780922886Sopenharmony_ciAVSession_ErrCode OHAVSession::RegisterSetLoopModeCallback(OH_AVSessionCallback_OnSetLoopMode callback, void* userData)
27880922886Sopenharmony_ci{
27980922886Sopenharmony_ci    std::lock_guard<std::mutex> lockGuard(lock_);
28080922886Sopenharmony_ci    CheckAndRegister();
28180922886Sopenharmony_ci    int32_t ret = avSession_->AddSupportCommand(static_cast<int32_t>(AVControlCommand::SESSION_CMD_SET_LOOP_MODE));
28280922886Sopenharmony_ci    if (static_cast<AVSession_ErrCode>(ret) != AV_SESSION_ERR_SUCCESS) {
28380922886Sopenharmony_ci        return GetEncodeErrcode(ret);
28480922886Sopenharmony_ci    }
28580922886Sopenharmony_ci    ohAVSessionCallbackImpl_->RegisterSetLoopModeCallback((OH_AVSession*)this, callback, userData);
28680922886Sopenharmony_ci    return AV_SESSION_ERR_SUCCESS;
28780922886Sopenharmony_ci}
28880922886Sopenharmony_ci
28980922886Sopenharmony_ciAVSession_ErrCode OHAVSession::UnregisterSetLoopModeCallback(OH_AVSessionCallback_OnSetLoopMode callback)
29080922886Sopenharmony_ci{
29180922886Sopenharmony_ci    if (ohAVSessionCallbackImpl_ == nullptr) {
29280922886Sopenharmony_ci        return AV_SESSION_ERR_SUCCESS;
29380922886Sopenharmony_ci    }
29480922886Sopenharmony_ci    std::lock_guard<std::mutex> lockGuard(lock_);
29580922886Sopenharmony_ci    int32_t ret = avSession_->DeleteSupportCommand(static_cast<int32_t>(AVControlCommand::SESSION_CMD_SET_LOOP_MODE));
29680922886Sopenharmony_ci    if (static_cast<AVSession_ErrCode>(ret) != AV_SESSION_ERR_SUCCESS) {
29780922886Sopenharmony_ci        return GetEncodeErrcode(ret);
29880922886Sopenharmony_ci    }
29980922886Sopenharmony_ci    ohAVSessionCallbackImpl_->UnregisterSetLoopModeCallback((OH_AVSession*)this, callback);
30080922886Sopenharmony_ci    return AV_SESSION_ERR_SUCCESS;
30180922886Sopenharmony_ci}
30280922886Sopenharmony_ci
30380922886Sopenharmony_ciAVSession_ErrCode OHAVSession::RegisterToggleFavoriteCallback(OH_AVSessionCallback_OnToggleFavorite callback,
30480922886Sopenharmony_ci    void* userData)
30580922886Sopenharmony_ci{
30680922886Sopenharmony_ci    std::lock_guard<std::mutex> lockGuard(lock_);
30780922886Sopenharmony_ci    CheckAndRegister();
30880922886Sopenharmony_ci    int32_t ret = avSession_->AddSupportCommand(static_cast<int32_t>(AVControlCommand::SESSION_CMD_TOGGLE_FAVORITE));
30980922886Sopenharmony_ci    if (static_cast<AVSession_ErrCode>(ret) != AV_SESSION_ERR_SUCCESS) {
31080922886Sopenharmony_ci        return GetEncodeErrcode(ret);
31180922886Sopenharmony_ci    }
31280922886Sopenharmony_ci    ohAVSessionCallbackImpl_->RegisterToggleFavoriteCallback((OH_AVSession*)this, callback, userData);
31380922886Sopenharmony_ci    return AV_SESSION_ERR_SUCCESS;
31480922886Sopenharmony_ci}
31580922886Sopenharmony_ci
31680922886Sopenharmony_ciAVSession_ErrCode OHAVSession::UnregisterToggleFavoriteCallback(OH_AVSessionCallback_OnToggleFavorite callback)
31780922886Sopenharmony_ci{
31880922886Sopenharmony_ci    if (ohAVSessionCallbackImpl_ == nullptr) {
31980922886Sopenharmony_ci        return AV_SESSION_ERR_SUCCESS;
32080922886Sopenharmony_ci    }
32180922886Sopenharmony_ci    std::lock_guard<std::mutex> lockGuard(lock_);
32280922886Sopenharmony_ci    int32_t ret = avSession_->DeleteSupportCommand(static_cast<int32_t>(AVControlCommand::SESSION_CMD_TOGGLE_FAVORITE));
32380922886Sopenharmony_ci    if (static_cast<AVSession_ErrCode>(ret) != AV_SESSION_ERR_SUCCESS) {
32480922886Sopenharmony_ci        return GetEncodeErrcode(ret);
32580922886Sopenharmony_ci    }
32680922886Sopenharmony_ci    ohAVSessionCallbackImpl_->UnregisterToggleFavoriteCallback((OH_AVSession*)this, callback);
32780922886Sopenharmony_ci    return AV_SESSION_ERR_SUCCESS;
32880922886Sopenharmony_ci}
32980922886Sopenharmony_ci
33080922886Sopenharmony_ciAVSession_ErrCode OHAVSession::Destroy()
33180922886Sopenharmony_ci{
33280922886Sopenharmony_ci    avSession_->Destroy();
33380922886Sopenharmony_ci    return AV_SESSION_ERR_SUCCESS;
33480922886Sopenharmony_ci}
33580922886Sopenharmony_ci}
33680922886Sopenharmony_ci
33780922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_Create(AVSession_Type sessionType, const char* sessionTag,
33880922886Sopenharmony_ci    const char* bundleName, const char* abilityName, OH_AVSession** avsession)
33980922886Sopenharmony_ci{
34080922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(sessionTag != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "sessionTag is null");
34180922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(bundleName != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "bundleName is null");
34280922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(abilityName != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "abilityName is null");
34380922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "avsession is null");
34480922886Sopenharmony_ci
34580922886Sopenharmony_ci    switch (sessionType) {
34680922886Sopenharmony_ci        case SESSION_TYPE_AUDIO:
34780922886Sopenharmony_ci        case SESSION_TYPE_VIDEO:
34880922886Sopenharmony_ci        case SESSION_TYPE_VOICE_CALL:
34980922886Sopenharmony_ci        case SESSION_TYPE_VIDEO_CALL:
35080922886Sopenharmony_ci            break;
35180922886Sopenharmony_ci        default:
35280922886Sopenharmony_ci            SLOGE("Invalid session type: %{public}d", sessionType);
35380922886Sopenharmony_ci            return AV_SESSION_ERR_INVALID_PARAMETER;
35480922886Sopenharmony_ci    }
35580922886Sopenharmony_ci
35680922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = new OHOS::AVSession::OHAVSession(sessionType, sessionTag,
35780922886Sopenharmony_ci        bundleName, abilityName);
35880922886Sopenharmony_ci    if (oh_avsession->IsAVSessionNull()) {
35980922886Sopenharmony_ci        delete oh_avsession;
36080922886Sopenharmony_ci        oh_avsession = nullptr;
36180922886Sopenharmony_ci        return AV_SESSION_ERR_SERVICE_EXCEPTION;
36280922886Sopenharmony_ci    }
36380922886Sopenharmony_ci    *avsession = (OH_AVSession*)oh_avsession;
36480922886Sopenharmony_ci    return AV_SESSION_ERR_SUCCESS;
36580922886Sopenharmony_ci}
36680922886Sopenharmony_ci
36780922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_Destroy(OH_AVSession* avsession)
36880922886Sopenharmony_ci{
36980922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
37080922886Sopenharmony_ci
37180922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
37280922886Sopenharmony_ci    oh_avsession->Destroy();
37380922886Sopenharmony_ci    if (oh_avsession != nullptr) {
37480922886Sopenharmony_ci        delete oh_avsession;
37580922886Sopenharmony_ci        oh_avsession = nullptr;
37680922886Sopenharmony_ci    }
37780922886Sopenharmony_ci    return AV_SESSION_ERR_SUCCESS;
37880922886Sopenharmony_ci}
37980922886Sopenharmony_ci
38080922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_Activate(OH_AVSession* avsession)
38180922886Sopenharmony_ci{
38280922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
38380922886Sopenharmony_ci
38480922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
38580922886Sopenharmony_ci    return oh_avsession->Activate();
38680922886Sopenharmony_ci}
38780922886Sopenharmony_ci
38880922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_Deactivate(OH_AVSession* avsession)
38980922886Sopenharmony_ci{
39080922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
39180922886Sopenharmony_ci
39280922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
39380922886Sopenharmony_ci    return oh_avsession->Deactivate();
39480922886Sopenharmony_ci}
39580922886Sopenharmony_ci
39680922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_GetSessionType(OH_AVSession* avsession, AVSession_Type* sessionType)
39780922886Sopenharmony_ci{
39880922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
39980922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(sessionType != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "sessionType is null");
40080922886Sopenharmony_ci
40180922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
40280922886Sopenharmony_ci    std::string str = oh_avsession->GetSessionType();
40380922886Sopenharmony_ci    auto it = oh_avsession->avsessionTypes.find(str);
40480922886Sopenharmony_ci    if (it == oh_avsession->avsessionTypes.end()) {
40580922886Sopenharmony_ci        return AV_SESSION_ERR_SERVICE_EXCEPTION;
40680922886Sopenharmony_ci    }
40780922886Sopenharmony_ci    *sessionType = it->second;
40880922886Sopenharmony_ci    return AV_SESSION_ERR_SUCCESS;
40980922886Sopenharmony_ci}
41080922886Sopenharmony_ci
41180922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_GetSessionId(OH_AVSession* avsession, const char** sessionId)
41280922886Sopenharmony_ci{
41380922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
41480922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(sessionId != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "sessionId is null");
41580922886Sopenharmony_ci
41680922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
41780922886Sopenharmony_ci    *sessionId = oh_avsession->GetSessionId().c_str();
41880922886Sopenharmony_ci    return AV_SESSION_ERR_SUCCESS;
41980922886Sopenharmony_ci}
42080922886Sopenharmony_ci
42180922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_SetAVMetadata(OH_AVSession* avsession, OH_AVMetadata* metadata)
42280922886Sopenharmony_ci{
42380922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
42480922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(metadata != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVMetadata is null");
42580922886Sopenharmony_ci
42680922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
42780922886Sopenharmony_ci    return oh_avsession->SetAVMetaData(metadata);
42880922886Sopenharmony_ci}
42980922886Sopenharmony_ci
43080922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_SetPlaybackState(OH_AVSession* avsession, AVSession_PlaybackState playbackState)
43180922886Sopenharmony_ci{
43280922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
43380922886Sopenharmony_ci
43480922886Sopenharmony_ci    switch (playbackState) {
43580922886Sopenharmony_ci        case PLAYBACK_STATE_INITIAL:
43680922886Sopenharmony_ci        case PLAYBACK_STATE_PREPARING:
43780922886Sopenharmony_ci        case PLAYBACK_STATE_PLAYING:
43880922886Sopenharmony_ci        case PLAYBACK_STATE_PAUSED:
43980922886Sopenharmony_ci        case PLAYBACK_STATE_FAST_FORWARDING:
44080922886Sopenharmony_ci        case PLAYBACK_STATE_REWINDED:
44180922886Sopenharmony_ci        case PLAYBACK_STATE_STOPPED:
44280922886Sopenharmony_ci        case PLAYBACK_STATE_COMPLETED:
44380922886Sopenharmony_ci        case PLAYBACK_STATE_RELEASED:
44480922886Sopenharmony_ci        case PLAYBACK_STATE_ERROR:
44580922886Sopenharmony_ci        case PLAYBACK_STATE_IDLE:
44680922886Sopenharmony_ci        case PLAYBACK_STATE_BUFFERING:
44780922886Sopenharmony_ci            break;
44880922886Sopenharmony_ci        default:
44980922886Sopenharmony_ci            SLOGE("Invalid playback state: %{public}d", playbackState);
45080922886Sopenharmony_ci            return AV_SESSION_ERR_INVALID_PARAMETER;
45180922886Sopenharmony_ci    }
45280922886Sopenharmony_ci
45380922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
45480922886Sopenharmony_ci    return oh_avsession->SetPlaybackState(playbackState);
45580922886Sopenharmony_ci}
45680922886Sopenharmony_ci
45780922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_SetPlaybackPosition(OH_AVSession* avsession,
45880922886Sopenharmony_ci    AVSession_PlaybackPosition* playbackPosition)
45980922886Sopenharmony_ci{
46080922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
46180922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(playbackPosition != nullptr, AV_SESSION_ERR_INVALID_PARAMETER,
46280922886Sopenharmony_ci        "playbackPosition is null");
46380922886Sopenharmony_ci
46480922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
46580922886Sopenharmony_ci    return oh_avsession->SetPlaybackPosition(playbackPosition);
46680922886Sopenharmony_ci}
46780922886Sopenharmony_ci
46880922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_SetFavorite(OH_AVSession* avsession, bool favorite)
46980922886Sopenharmony_ci{
47080922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
47180922886Sopenharmony_ci
47280922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
47380922886Sopenharmony_ci    return oh_avsession->SetFavorite(favorite);
47480922886Sopenharmony_ci}
47580922886Sopenharmony_ci
47680922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_SetLoopMode(OH_AVSession* avsession, AVSession_LoopMode loopMode)
47780922886Sopenharmony_ci{
47880922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
47980922886Sopenharmony_ci
48080922886Sopenharmony_ci    switch (loopMode) {
48180922886Sopenharmony_ci        case LOOP_MODE_SEQUENCE:
48280922886Sopenharmony_ci        case LOOP_MODE_SINGLE:
48380922886Sopenharmony_ci        case LOOP_MODE_LIST:
48480922886Sopenharmony_ci        case LOOP_MODE_SHUFFLE:
48580922886Sopenharmony_ci        case LOOP_MODE_CUSTOM:
48680922886Sopenharmony_ci            break;
48780922886Sopenharmony_ci        default:
48880922886Sopenharmony_ci            SLOGE("Invalid loop mode: %{public}d", loopMode);
48980922886Sopenharmony_ci            return AV_SESSION_ERR_INVALID_PARAMETER;
49080922886Sopenharmony_ci    }
49180922886Sopenharmony_ci
49280922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
49380922886Sopenharmony_ci    return oh_avsession->SetLoopMode(loopMode);
49480922886Sopenharmony_ci}
49580922886Sopenharmony_ci
49680922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_RegisterCommandCallback(OH_AVSession* avsession,
49780922886Sopenharmony_ci    AVSession_ControlCommand command, OH_AVSessionCallback_OnCommand callback, void* userData)
49880922886Sopenharmony_ci{
49980922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
50080922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(callback != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "callback is null");
50180922886Sopenharmony_ci
50280922886Sopenharmony_ci    switch (command) {
50380922886Sopenharmony_ci        case CONTROL_CMD_PLAY:
50480922886Sopenharmony_ci        case CONTROL_CMD_PAUSE:
50580922886Sopenharmony_ci        case CONTROL_CMD_STOP:
50680922886Sopenharmony_ci        case CONTROL_CMD_PLAY_NEXT:
50780922886Sopenharmony_ci        case CONTROL_CMD_PLAY_PREVIOUS:
50880922886Sopenharmony_ci            break;
50980922886Sopenharmony_ci        default:
51080922886Sopenharmony_ci            SLOGE("Invalid command: %{public}d", command);
51180922886Sopenharmony_ci            return AV_SESSION_ERR_CODE_COMMAND_INVALID;
51280922886Sopenharmony_ci    }
51380922886Sopenharmony_ci
51480922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
51580922886Sopenharmony_ci    return  oh_avsession->RegisterCommandCallback(command, callback, userData);
51680922886Sopenharmony_ci}
51780922886Sopenharmony_ci
51880922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_UnregisterCommandCallback(OH_AVSession* avsession,
51980922886Sopenharmony_ci    AVSession_ControlCommand command, OH_AVSessionCallback_OnCommand callback)
52080922886Sopenharmony_ci{
52180922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
52280922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(callback != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "callback is null");
52380922886Sopenharmony_ci
52480922886Sopenharmony_ci    switch (command) {
52580922886Sopenharmony_ci        case CONTROL_CMD_PLAY:
52680922886Sopenharmony_ci        case CONTROL_CMD_PAUSE:
52780922886Sopenharmony_ci        case CONTROL_CMD_STOP:
52880922886Sopenharmony_ci        case CONTROL_CMD_PLAY_NEXT:
52980922886Sopenharmony_ci        case CONTROL_CMD_PLAY_PREVIOUS:
53080922886Sopenharmony_ci            break;
53180922886Sopenharmony_ci        default:
53280922886Sopenharmony_ci            SLOGE("Invalid command: %{public}d", command);
53380922886Sopenharmony_ci            return AV_SESSION_ERR_CODE_COMMAND_INVALID;
53480922886Sopenharmony_ci    }
53580922886Sopenharmony_ci
53680922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
53780922886Sopenharmony_ci    return oh_avsession->UnregisterCommandCallback(command, callback);
53880922886Sopenharmony_ci}
53980922886Sopenharmony_ci
54080922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_RegisterForwardCallback(OH_AVSession* avsession,
54180922886Sopenharmony_ci    OH_AVSessionCallback_OnFastForward callback, void* userData)
54280922886Sopenharmony_ci{
54380922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
54480922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(callback != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "callback is null");
54580922886Sopenharmony_ci
54680922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
54780922886Sopenharmony_ci    return oh_avsession->RegisterForwardCallback(callback, userData);
54880922886Sopenharmony_ci}
54980922886Sopenharmony_ci
55080922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_UnregisterForwardCallback(OH_AVSession* avsession,
55180922886Sopenharmony_ci    OH_AVSessionCallback_OnFastForward callback)
55280922886Sopenharmony_ci{
55380922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
55480922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(callback != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "callback is null");
55580922886Sopenharmony_ci
55680922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
55780922886Sopenharmony_ci    return oh_avsession->UnregisterForwardCallback(callback);
55880922886Sopenharmony_ci}
55980922886Sopenharmony_ci
56080922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_RegisterRewindCallback(OH_AVSession* avsession,
56180922886Sopenharmony_ci    OH_AVSessionCallback_OnRewind callback, void* userData)
56280922886Sopenharmony_ci{
56380922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
56480922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(callback != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "callback is null");
56580922886Sopenharmony_ci
56680922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
56780922886Sopenharmony_ci    return oh_avsession->RegisterRewindCallback(callback, userData);
56880922886Sopenharmony_ci}
56980922886Sopenharmony_ci
57080922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_UnregisterRewindCallback(OH_AVSession* avsession,
57180922886Sopenharmony_ci    OH_AVSessionCallback_OnRewind callback)
57280922886Sopenharmony_ci{
57380922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
57480922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(callback != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "callback is null");
57580922886Sopenharmony_ci
57680922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
57780922886Sopenharmony_ci    return oh_avsession->UnregisterRewindCallback(callback);
57880922886Sopenharmony_ci}
57980922886Sopenharmony_ci
58080922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_RegisterSeekCallback(OH_AVSession* avsession,
58180922886Sopenharmony_ci    OH_AVSessionCallback_OnSeek callback, void* userData)
58280922886Sopenharmony_ci{
58380922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
58480922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(callback != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "callback is null");
58580922886Sopenharmony_ci
58680922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
58780922886Sopenharmony_ci    return oh_avsession->RegisterSeekCallback(callback, userData);
58880922886Sopenharmony_ci}
58980922886Sopenharmony_ci
59080922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_UnregisterSeekCallback(OH_AVSession* avsession,
59180922886Sopenharmony_ci    OH_AVSessionCallback_OnSeek callback)
59280922886Sopenharmony_ci{
59380922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
59480922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(callback != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "callback is null");
59580922886Sopenharmony_ci
59680922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
59780922886Sopenharmony_ci    return oh_avsession->UnregisterSeekCallback(callback);
59880922886Sopenharmony_ci}
59980922886Sopenharmony_ci
60080922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_RegisterSetLoopModeCallback(OH_AVSession* avsession,
60180922886Sopenharmony_ci    OH_AVSessionCallback_OnSetLoopMode callback, void* userData)
60280922886Sopenharmony_ci{
60380922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
60480922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(callback != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "callback is null");
60580922886Sopenharmony_ci
60680922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
60780922886Sopenharmony_ci    return oh_avsession->RegisterSetLoopModeCallback(callback, userData);
60880922886Sopenharmony_ci}
60980922886Sopenharmony_ci
61080922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_UnregisterSetLoopModeCallback(OH_AVSession* avsession,
61180922886Sopenharmony_ci    OH_AVSessionCallback_OnSetLoopMode callback)
61280922886Sopenharmony_ci{
61380922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
61480922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(callback != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "callback is null");
61580922886Sopenharmony_ci
61680922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
61780922886Sopenharmony_ci    return oh_avsession->UnregisterSetLoopModeCallback(callback);
61880922886Sopenharmony_ci}
61980922886Sopenharmony_ci
62080922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_RegisterToggleFavoriteCallback(OH_AVSession* avsession,
62180922886Sopenharmony_ci    OH_AVSessionCallback_OnToggleFavorite callback, void* userData)
62280922886Sopenharmony_ci{
62380922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
62480922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(callback != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "callback is null");
62580922886Sopenharmony_ci
62680922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
62780922886Sopenharmony_ci    return oh_avsession->RegisterToggleFavoriteCallback(callback, userData);
62880922886Sopenharmony_ci}
62980922886Sopenharmony_ci
63080922886Sopenharmony_ciAVSession_ErrCode OH_AVSession_UnregisterToggleFavoriteCallback(OH_AVSession* avsession,
63180922886Sopenharmony_ci    OH_AVSessionCallback_OnToggleFavorite callback)
63280922886Sopenharmony_ci{
63380922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(avsession != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "AVSession is null");
63480922886Sopenharmony_ci    CHECK_AND_RETURN_RET_LOG(callback != nullptr, AV_SESSION_ERR_INVALID_PARAMETER, "callback is null");
63580922886Sopenharmony_ci
63680922886Sopenharmony_ci    OHOS::AVSession::OHAVSession *oh_avsession = (OHOS::AVSession::OHAVSession *)avsession;
63780922886Sopenharmony_ci    return oh_avsession->UnregisterToggleFavoriteCallback(callback);
63880922886Sopenharmony_ci}