180922886Sopenharmony_ci/*
280922886Sopenharmony_ci * Copyright (c) 2022-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#ifndef OHOS_AVSESSION_ITEM_H
1780922886Sopenharmony_ci#define OHOS_AVSESSION_ITEM_H
1880922886Sopenharmony_ci
1980922886Sopenharmony_ci#include <dlfcn.h>
2080922886Sopenharmony_ci#include <string>
2180922886Sopenharmony_ci#include <map>
2280922886Sopenharmony_ci
2380922886Sopenharmony_ci#include "avsession_stub.h"
2480922886Sopenharmony_ci#include "avsession_callback_proxy.h"
2580922886Sopenharmony_ci#include "avsession_display_interface.h"
2680922886Sopenharmony_ci#include "avsession_dynamic_loader.h"
2780922886Sopenharmony_ci#include "avcontrol_command.h"
2880922886Sopenharmony_ci#include "audio_info.h"
2980922886Sopenharmony_ci#include "avcast_control_command.h"
3080922886Sopenharmony_ci#include "system_ability_definition.h"
3180922886Sopenharmony_ci#include "collaboration_manager_utils.h"
3280922886Sopenharmony_ci
3380922886Sopenharmony_ci#ifdef CASTPLUS_CAST_ENGINE_ENABLE
3480922886Sopenharmony_ci#include <condition_variable>
3580922886Sopenharmony_ci#include <chrono>
3680922886Sopenharmony_ci
3780922886Sopenharmony_ci#include "i_avcast_controller_proxy.h"
3880922886Sopenharmony_ci#include "avcast_controller_item.h"
3980922886Sopenharmony_ci#include "hw_cast_display_listener.h"
4080922886Sopenharmony_ci#endif
4180922886Sopenharmony_ci
4280922886Sopenharmony_cinamespace OHOS::AVSession {
4380922886Sopenharmony_ciclass AVControllerItem;
4480922886Sopenharmony_ciclass RemoteSessionSink;
4580922886Sopenharmony_ciclass RemoteSessionSource;
4680922886Sopenharmony_ciclass AVSessionItem : public AVSessionStub {
4780922886Sopenharmony_ci#ifdef CASTPLUS_CAST_ENGINE_ENABLE
4880922886Sopenharmony_ciclass CssListener : public IAVCastSessionStateListener {
4980922886Sopenharmony_cipublic:
5080922886Sopenharmony_ci    explicit CssListener(AVSessionItem *ptr)
5180922886Sopenharmony_ci    {
5280922886Sopenharmony_ci        ptr_ = ptr;
5380922886Sopenharmony_ci    }
5480922886Sopenharmony_ci
5580922886Sopenharmony_ci    void OnCastStateChange(int32_t castState, DeviceInfo deviceInfo)
5680922886Sopenharmony_ci    {
5780922886Sopenharmony_ci        ptr_->OnCastStateChange(castState, deviceInfo);
5880922886Sopenharmony_ci    }
5980922886Sopenharmony_ci
6080922886Sopenharmony_ci    void OnCastEventRecv(int32_t errorCode, std::string& errorMsg)
6180922886Sopenharmony_ci    {
6280922886Sopenharmony_ci        ptr_->OnCastEventRecv(errorCode, errorMsg);
6380922886Sopenharmony_ci    }
6480922886Sopenharmony_ci
6580922886Sopenharmony_ci    AVSessionItem *ptr_;
6680922886Sopenharmony_ci};
6780922886Sopenharmony_ci#endif
6880922886Sopenharmony_cipublic:
6980922886Sopenharmony_ci    explicit AVSessionItem(const AVSessionDescriptor& descriptor, int32_t userId = DEFAULT_USER_ID);
7080922886Sopenharmony_ci
7180922886Sopenharmony_ci    ~AVSessionItem() override;
7280922886Sopenharmony_ci
7380922886Sopenharmony_ci#ifdef CASTPLUS_CAST_ENGINE_ENABLE
7480922886Sopenharmony_ci    void DealCastState(int32_t castState);
7580922886Sopenharmony_ci
7680922886Sopenharmony_ci    void DealDisconnect(DeviceInfo deviceInfo);
7780922886Sopenharmony_ci
7880922886Sopenharmony_ci    void DealCollaborationPublishState(int32_t castState, DeviceInfo deviceInfo);
7980922886Sopenharmony_ci
8080922886Sopenharmony_ci    void OnCastStateChange(int32_t castState, DeviceInfo deviceInfo);
8180922886Sopenharmony_ci
8280922886Sopenharmony_ci    void OnCastEventRecv(int32_t errorCode, std::string& errorMsg);
8380922886Sopenharmony_ci
8480922886Sopenharmony_ci    void OnRemoveCastEngine();
8580922886Sopenharmony_ci
8680922886Sopenharmony_ci    void ListenCollaborationRejectToStopCast();
8780922886Sopenharmony_ci#endif
8880922886Sopenharmony_ci
8980922886Sopenharmony_ci    std::string GetSessionId() override;
9080922886Sopenharmony_ci
9180922886Sopenharmony_ci    std::string GetSessionType() override;
9280922886Sopenharmony_ci
9380922886Sopenharmony_ci    int32_t SetAVCallMetaData(const AVCallMetaData& avCallMetaData) override;
9480922886Sopenharmony_ci
9580922886Sopenharmony_ci    int32_t SetAVCallState(const AVCallState& avCallState) override;
9680922886Sopenharmony_ci
9780922886Sopenharmony_ci    int32_t GetAVMetaData(AVMetaData& meta) override;
9880922886Sopenharmony_ci
9980922886Sopenharmony_ci    int32_t SetAVMetaData(const AVMetaData& meta) override;
10080922886Sopenharmony_ci
10180922886Sopenharmony_ci    int32_t GetAVQueueItems(std::vector<AVQueueItem>& items) override;
10280922886Sopenharmony_ci
10380922886Sopenharmony_ci    int32_t SetAVQueueItems(const std::vector<AVQueueItem>& items) override;
10480922886Sopenharmony_ci
10580922886Sopenharmony_ci    int32_t GetAVQueueTitle(std::string& title) override;
10680922886Sopenharmony_ci
10780922886Sopenharmony_ci    int32_t SetAVQueueTitle(const std::string& title) override;
10880922886Sopenharmony_ci
10980922886Sopenharmony_ci    int32_t GetAVPlaybackState(AVPlaybackState& state) override;
11080922886Sopenharmony_ci
11180922886Sopenharmony_ci    int32_t SetLaunchAbility(const AbilityRuntime::WantAgent::WantAgent& ability) override;
11280922886Sopenharmony_ci
11380922886Sopenharmony_ci    int32_t GetExtras(AAFwk::WantParams& extras) override;
11480922886Sopenharmony_ci
11580922886Sopenharmony_ci    int32_t SetExtras(const AAFwk::WantParams& extras) override;
11680922886Sopenharmony_ci
11780922886Sopenharmony_ci    int32_t Activate() override;
11880922886Sopenharmony_ci
11980922886Sopenharmony_ci    int32_t Deactivate() override;
12080922886Sopenharmony_ci
12180922886Sopenharmony_ci    bool IsActive() override;
12280922886Sopenharmony_ci
12380922886Sopenharmony_ci    int32_t Destroy() override;
12480922886Sopenharmony_ci
12580922886Sopenharmony_ci    int32_t AddSupportCommand(int32_t cmd) override;
12680922886Sopenharmony_ci
12780922886Sopenharmony_ci    int32_t DeleteSupportCommand(int32_t cmd) override;
12880922886Sopenharmony_ci
12980922886Sopenharmony_ci    int32_t DestroyTask();
13080922886Sopenharmony_ci
13180922886Sopenharmony_ci    AVSessionDescriptor GetDescriptor();
13280922886Sopenharmony_ci
13380922886Sopenharmony_ci    int32_t SetAVPlaybackState(const AVPlaybackState& state) override;
13480922886Sopenharmony_ci
13580922886Sopenharmony_ci    AVCallState GetAVCallState();
13680922886Sopenharmony_ci
13780922886Sopenharmony_ci    AVCallMetaData GetAVCallMetaData();
13880922886Sopenharmony_ci
13980922886Sopenharmony_ci    AVPlaybackState GetPlaybackState();
14080922886Sopenharmony_ci
14180922886Sopenharmony_ci    AVMetaData GetMetaData();
14280922886Sopenharmony_ci
14380922886Sopenharmony_ci    std::vector<AVQueueItem> GetQueueItems();
14480922886Sopenharmony_ci
14580922886Sopenharmony_ci    std::string GetQueueTitle();
14680922886Sopenharmony_ci
14780922886Sopenharmony_ci    AAFwk::WantParams GetExtras();
14880922886Sopenharmony_ci
14980922886Sopenharmony_ci    std::vector<int32_t> GetSupportCommand();
15080922886Sopenharmony_ci
15180922886Sopenharmony_ci    AbilityRuntime::WantAgent::WantAgent GetLaunchAbility();
15280922886Sopenharmony_ci
15380922886Sopenharmony_ci    void HandleMediaKeyEvent(const MMI::KeyEvent& keyEvent);
15480922886Sopenharmony_ci
15580922886Sopenharmony_ci    void HandleOutputDeviceChange(const int32_t connectionState, const OutputDeviceInfo& outputDeviceInfo);
15680922886Sopenharmony_ci
15780922886Sopenharmony_ci    void HandleSkipToQueueItem(const int32_t& itemId);
15880922886Sopenharmony_ci
15980922886Sopenharmony_ci    void ExecuteControllerCommand(const AVControlCommand& cmd);
16080922886Sopenharmony_ci
16180922886Sopenharmony_ci    void ExecueCommonCommand(const std::string& commonCommand, const AAFwk::WantParams& commandArgs);
16280922886Sopenharmony_ci
16380922886Sopenharmony_ci    int32_t AddController(pid_t pid, sptr<AVControllerItem>& controller);
16480922886Sopenharmony_ci
16580922886Sopenharmony_ci    void SetPid(pid_t pid);
16680922886Sopenharmony_ci
16780922886Sopenharmony_ci    void SetUid(pid_t uid);
16880922886Sopenharmony_ci
16980922886Sopenharmony_ci    pid_t GetPid() const;
17080922886Sopenharmony_ci
17180922886Sopenharmony_ci    pid_t GetUid() const;
17280922886Sopenharmony_ci
17380922886Sopenharmony_ci    int32_t GetUserId() const;
17480922886Sopenharmony_ci
17580922886Sopenharmony_ci    std::string GetAbilityName() const;
17680922886Sopenharmony_ci
17780922886Sopenharmony_ci    std::string GetBundleName() const;
17880922886Sopenharmony_ci
17980922886Sopenharmony_ci    void SetTop(bool top);
18080922886Sopenharmony_ci
18180922886Sopenharmony_ci    std::shared_ptr<RemoteSessionSource> GetRemoteSource();
18280922886Sopenharmony_ci
18380922886Sopenharmony_ci    void HandleControllerRelease(pid_t pid);
18480922886Sopenharmony_ci
18580922886Sopenharmony_ci    void SetServiceCallbackForRelease(const std::function<void(AVSessionItem&)>& callback);
18680922886Sopenharmony_ci
18780922886Sopenharmony_ci    void SetServiceCallbackForCallStart(const std::function<void(AVSessionItem&)>& callback);
18880922886Sopenharmony_ci
18980922886Sopenharmony_ci    void SetOutputDevice(const OutputDeviceInfo& info);
19080922886Sopenharmony_ci
19180922886Sopenharmony_ci    void GetOutputDevice(OutputDeviceInfo& info);
19280922886Sopenharmony_ci
19380922886Sopenharmony_ci    int32_t CastAudioToRemote(const std::string& sourceDevice, const std::string& sinkDevice,
19480922886Sopenharmony_ci                              const std::string& sinkCapability);
19580922886Sopenharmony_ci
19680922886Sopenharmony_ci    int32_t SourceCancelCastAudio(const std::string& sinkDevice);
19780922886Sopenharmony_ci
19880922886Sopenharmony_ci    int32_t CastAudioFromRemote(const std::string& sourceSessionId, const std::string& sourceDevice,
19980922886Sopenharmony_ci                                const std::string& sinkDevice, const std::string& sourceCapability);
20080922886Sopenharmony_ci
20180922886Sopenharmony_ci    int32_t SinkCancelCastAudio();
20280922886Sopenharmony_ci
20380922886Sopenharmony_ci    int32_t SetSessionEvent(const std::string& event, const AAFwk::WantParams& args) override;
20480922886Sopenharmony_ci
20580922886Sopenharmony_ci    void SetServiceCallbackForAVQueueInfo(const std::function<void(AVSessionItem&)>& callback);
20680922886Sopenharmony_ci
20780922886Sopenharmony_ci    void SetServiceCallbackForUpdateSession(const std::function<void(std::string, bool)>& callback);
20880922886Sopenharmony_ci
20980922886Sopenharmony_ci#ifdef CASTPLUS_CAST_ENGINE_ENABLE
21080922886Sopenharmony_ci    void InitializeCastCommands();
21180922886Sopenharmony_ci
21280922886Sopenharmony_ci    void AddSessionCommandToCast(int32_t cmd);
21380922886Sopenharmony_ci
21480922886Sopenharmony_ci    void RemoveSessionCommandFromCast(int32_t cmd);
21580922886Sopenharmony_ci
21680922886Sopenharmony_ci    int32_t SessionCommandToCastCommand(int32_t cmd);
21780922886Sopenharmony_ci
21880922886Sopenharmony_ci    int32_t RegisterListenerStreamToCast(const std::map<std::string, std::string>& serviceNameMapState,
21980922886Sopenharmony_ci        DeviceInfo deviceInfo);
22080922886Sopenharmony_ci
22180922886Sopenharmony_ci    int32_t AddSupportCastCommand(int32_t cmd);
22280922886Sopenharmony_ci
22380922886Sopenharmony_ci    int32_t DeleteSupportCastCommand(int32_t cmd);
22480922886Sopenharmony_ci
22580922886Sopenharmony_ci    void HandleCastValidCommandChange(std::vector<int32_t> &cmds);
22680922886Sopenharmony_ci
22780922886Sopenharmony_ci    int32_t ReleaseCast() override;
22880922886Sopenharmony_ci
22980922886Sopenharmony_ci    int32_t StartCast(const OutputDeviceInfo& outputDeviceInfo);
23080922886Sopenharmony_ci
23180922886Sopenharmony_ci    int32_t CastAddToCollaboration(const OutputDeviceInfo& outputDeviceInfo);
23280922886Sopenharmony_ci
23380922886Sopenharmony_ci    int32_t AddDevice(const int64_t castHandle, const OutputDeviceInfo& outputDeviceInfo);
23480922886Sopenharmony_ci
23580922886Sopenharmony_ci    int32_t StopCast();
23680922886Sopenharmony_ci
23780922886Sopenharmony_ci    sptr<IRemoteObject> GetAVCastControllerInner() override;
23880922886Sopenharmony_ci
23980922886Sopenharmony_ci    void ReleaseAVCastControllerInner();
24080922886Sopenharmony_ci
24180922886Sopenharmony_ci    void UpdateCastDeviceMap(DeviceInfo deviceInfo);
24280922886Sopenharmony_ci
24380922886Sopenharmony_ci    void SetCastHandle(int64_t castHandle);
24480922886Sopenharmony_ci
24580922886Sopenharmony_ci    void RegisterDeviceStateCallback();
24680922886Sopenharmony_ci
24780922886Sopenharmony_ci    void UnRegisterDeviceStateCallback();
24880922886Sopenharmony_ci
24980922886Sopenharmony_ci    void StopCastSession();
25080922886Sopenharmony_ci
25180922886Sopenharmony_ci    int32_t StartCastDisplayListener() override;
25280922886Sopenharmony_ci
25380922886Sopenharmony_ci    int32_t StopCastDisplayListener() override;
25480922886Sopenharmony_ci
25580922886Sopenharmony_ci    void GetDisplayListener(sptr<IAVSessionCallback> callback);
25680922886Sopenharmony_ci
25780922886Sopenharmony_ci    int32_t GetAllCastDisplays(std::vector<CastDisplayInfo>& castDisplays) override;
25880922886Sopenharmony_ci
25980922886Sopenharmony_ci    void SetExtrasInner(AAFwk::IArray* list);
26080922886Sopenharmony_ci
26180922886Sopenharmony_ci    void SetServiceCallbackForStream(const std::function<void(std::string)>& callback);
26280922886Sopenharmony_ci#endif
26380922886Sopenharmony_ci
26480922886Sopenharmony_ciprotected:
26580922886Sopenharmony_ci    int32_t RegisterCallbackInner(const sptr<IAVSessionCallback>& callback) override;
26680922886Sopenharmony_ci    sptr<IRemoteObject> GetControllerInner() override;
26780922886Sopenharmony_ci
26880922886Sopenharmony_ciprivate:
26980922886Sopenharmony_ci    bool HasAvQueueInfo();
27080922886Sopenharmony_ci    void HandleOnAVCallAnswer(const AVControlCommand& cmd);
27180922886Sopenharmony_ci    void HandleOnAVCallHangUp(const AVControlCommand& cmd);
27280922886Sopenharmony_ci    void HandleOnAVCallToggleCallMute(const AVControlCommand& cmd);
27380922886Sopenharmony_ci    void HandleOnPlay(const AVControlCommand& cmd);
27480922886Sopenharmony_ci    void HandleOnPause(const AVControlCommand& cmd);
27580922886Sopenharmony_ci    void HandleOnPlayOrPause(const AVControlCommand& cmd);
27680922886Sopenharmony_ci    void HandleOnStop(const AVControlCommand& cmd);
27780922886Sopenharmony_ci    void HandleOnPlayNext(const AVControlCommand& cmd);
27880922886Sopenharmony_ci    void HandleOnPlayPrevious(const AVControlCommand& cmd);
27980922886Sopenharmony_ci    void HandleOnFastForward(const AVControlCommand& cmd);
28080922886Sopenharmony_ci    void HandleOnRewind(const AVControlCommand& cmd);
28180922886Sopenharmony_ci    void HandleOnSeek(const AVControlCommand& cmd);
28280922886Sopenharmony_ci    void HandleOnSetSpeed(const AVControlCommand& cmd);
28380922886Sopenharmony_ci    void HandleOnSetLoopMode(const AVControlCommand& cmd);
28480922886Sopenharmony_ci    void HandleOnToggleFavorite(const AVControlCommand& cmd);
28580922886Sopenharmony_ci    void HandleOnPlayFromAssetId(const AVControlCommand& cmd);
28680922886Sopenharmony_ci
28780922886Sopenharmony_ci    void ReportConnectFinish(const std::string func, const DeviceInfo &deviceInfo);
28880922886Sopenharmony_ci    void ReportStopCastFinish(const std::string func, const DeviceInfo &deviceInfo);
28980922886Sopenharmony_ci    void SaveLocalDeviceInfo();
29080922886Sopenharmony_ci    int32_t ProcessFrontSession(const std::string& source);
29180922886Sopenharmony_ci    void HandleFrontSession();
29280922886Sopenharmony_ci    int32_t DoContinuousTaskRegister();
29380922886Sopenharmony_ci    int32_t DoContinuousTaskUnregister();
29480922886Sopenharmony_ci    AVSessionDisplayIntf* GetAVSessionDisplayIntf();
29580922886Sopenharmony_ci    void ReportSetAVMetaDataInfo(const AVMetaData& meta);
29680922886Sopenharmony_ci    std::string GetAnonymousDeviceId(std::string deviceId);
29780922886Sopenharmony_ci    void ReportAVCastControllerInfo();
29880922886Sopenharmony_ci    void InitAVCastControllerProxy();
29980922886Sopenharmony_ci
30080922886Sopenharmony_ci    using HandlerFuncType = std::function<void(const AVControlCommand&)>;
30180922886Sopenharmony_ci    std::map<uint32_t, HandlerFuncType> cmdHandlers = {
30280922886Sopenharmony_ci        {AVControlCommand::SESSION_CMD_PLAY,
30380922886Sopenharmony_ci            [this](const AVControlCommand& cmd) { HandleOnPlay(cmd); }},
30480922886Sopenharmony_ci        {AVControlCommand::SESSION_CMD_PAUSE,
30580922886Sopenharmony_ci            [this](const AVControlCommand& cmd) { HandleOnPause(cmd); }},
30680922886Sopenharmony_ci        {AVControlCommand::SESSION_CMD_STOP,
30780922886Sopenharmony_ci            [this](const AVControlCommand& cmd) { HandleOnStop(cmd); }},
30880922886Sopenharmony_ci        {AVControlCommand::SESSION_CMD_PLAY_NEXT,
30980922886Sopenharmony_ci            [this](const AVControlCommand& cmd) { HandleOnPlayNext(cmd); }},
31080922886Sopenharmony_ci        {AVControlCommand::SESSION_CMD_PLAY_PREVIOUS,
31180922886Sopenharmony_ci            [this](const AVControlCommand& cmd) { HandleOnPlayPrevious(cmd); }},
31280922886Sopenharmony_ci        {AVControlCommand::SESSION_CMD_FAST_FORWARD,
31380922886Sopenharmony_ci            [this](const AVControlCommand& cmd) { HandleOnFastForward(cmd); }},
31480922886Sopenharmony_ci        {AVControlCommand::SESSION_CMD_REWIND,
31580922886Sopenharmony_ci            [this](const AVControlCommand& cmd) { HandleOnRewind(cmd); }},
31680922886Sopenharmony_ci        {AVControlCommand::SESSION_CMD_SEEK,
31780922886Sopenharmony_ci            [this](const AVControlCommand& cmd) { HandleOnSeek(cmd); }},
31880922886Sopenharmony_ci        {AVControlCommand::SESSION_CMD_SET_SPEED,
31980922886Sopenharmony_ci            [this](const AVControlCommand& cmd) { HandleOnSetSpeed(cmd); }},
32080922886Sopenharmony_ci        {AVControlCommand::SESSION_CMD_SET_LOOP_MODE,
32180922886Sopenharmony_ci            [this](const AVControlCommand& cmd) { HandleOnSetLoopMode(cmd); }},
32280922886Sopenharmony_ci        {AVControlCommand::SESSION_CMD_TOGGLE_FAVORITE,
32380922886Sopenharmony_ci            [this](const AVControlCommand& cmd) { HandleOnToggleFavorite(cmd); }},
32480922886Sopenharmony_ci        {AVControlCommand::SESSION_CMD_PLAY_FROM_ASSETID,
32580922886Sopenharmony_ci            [this](const AVControlCommand& cmd) { HandleOnPlayFromAssetId(cmd); }},
32680922886Sopenharmony_ci        {AVControlCommand::SESSION_CMD_AVCALL_ANSWER,
32780922886Sopenharmony_ci            [this](const AVControlCommand& cmd) { HandleOnAVCallAnswer(cmd); }},
32880922886Sopenharmony_ci        {AVControlCommand::SESSION_CMD_AVCALL_HANG_UP,
32980922886Sopenharmony_ci            [this](const AVControlCommand& cmd) { HandleOnAVCallHangUp(cmd); }},
33080922886Sopenharmony_ci        {AVControlCommand::SESSION_CMD_AVCALL_TOGGLE_CALL_MUTE,
33180922886Sopenharmony_ci            [this](const AVControlCommand& cmd) { HandleOnAVCallToggleCallMute(cmd); }}
33280922886Sopenharmony_ci    };
33380922886Sopenharmony_ci
33480922886Sopenharmony_ci    std::map<int32_t, HandlerFuncType> keyEventCaller_ = {
33580922886Sopenharmony_ci        {MMI::KeyEvent::KEYCODE_MEDIA_PLAY, [this](const AVControlCommand& cmd) { HandleOnPlay(cmd); }},
33680922886Sopenharmony_ci        {MMI::KeyEvent::KEYCODE_MEDIA_PAUSE, [this](const AVControlCommand& cmd) { HandleOnPause(cmd); }},
33780922886Sopenharmony_ci        {MMI::KeyEvent::KEYCODE_MEDIA_PLAY_PAUSE, [this](const AVControlCommand& cmd) { HandleOnPlayOrPause(cmd); }},
33880922886Sopenharmony_ci        {MMI::KeyEvent::KEYCODE_MEDIA_STOP, [this](const AVControlCommand& cmd) { HandleOnPause(cmd); }},
33980922886Sopenharmony_ci        {MMI::KeyEvent::KEYCODE_MEDIA_NEXT, [this](const AVControlCommand& cmd) { HandleOnPlayNext(cmd); }},
34080922886Sopenharmony_ci        {MMI::KeyEvent::KEYCODE_MEDIA_PREVIOUS, [this](const AVControlCommand& cmd) { HandleOnPlayPrevious(cmd); }},
34180922886Sopenharmony_ci        {MMI::KeyEvent::KEYCODE_MEDIA_REWIND, [this](const AVControlCommand& cmd) { HandleOnRewind(cmd); }},
34280922886Sopenharmony_ci        {MMI::KeyEvent::KEYCODE_MEDIA_FAST_FORWARD, [this](const AVControlCommand& cmd) { HandleOnFastForward(cmd); }}
34380922886Sopenharmony_ci    };
34480922886Sopenharmony_ci
34580922886Sopenharmony_ci    std::map<pid_t, sptr<AVControllerItem>> controllers_;
34680922886Sopenharmony_ci    AVCallMetaData avCallMetaData_;
34780922886Sopenharmony_ci    AVCallState avCallState_;
34880922886Sopenharmony_ci
34980922886Sopenharmony_ci    AVSessionDescriptor descriptor_;
35080922886Sopenharmony_ci    int32_t userId_;
35180922886Sopenharmony_ci    AVPlaybackState playbackState_;
35280922886Sopenharmony_ci    AVMetaData metaData_;
35380922886Sopenharmony_ci    std::vector<AVQueueItem> queueItems_;
35480922886Sopenharmony_ci    std::string queueTitle_;
35580922886Sopenharmony_ci    AbilityRuntime::WantAgent::WantAgent launchAbility_;
35680922886Sopenharmony_ci    AAFwk::WantParams extras_;
35780922886Sopenharmony_ci    std::vector<int32_t> supportedCmd_;
35880922886Sopenharmony_ci    std::vector<int32_t> supportedCastCmds_;
35980922886Sopenharmony_ci    sptr<IAVSessionCallback> callback_;
36080922886Sopenharmony_ci    std::shared_ptr<AVSessionCallback> remoteCallback_;
36180922886Sopenharmony_ci    std::function<void(AVSessionItem&)> serviceCallback_;
36280922886Sopenharmony_ci    std::function<void(AVSessionItem&)> callStartCallback_;
36380922886Sopenharmony_ci    friend class AVSessionDumper;
36480922886Sopenharmony_ci
36580922886Sopenharmony_ci    std::shared_ptr<RemoteSessionSource> remoteSource_;
36680922886Sopenharmony_ci    std::shared_ptr<RemoteSessionSink> remoteSink_;
36780922886Sopenharmony_ci
36880922886Sopenharmony_ci    std::function<void(AVSessionItem&)> serviceCallbackForAddAVQueueInfo_;
36980922886Sopenharmony_ci    std::function<void(std::string, bool)> serviceCallbackForUpdateSession_;
37080922886Sopenharmony_ci    volatile bool isFirstAddToFront_ = true;
37180922886Sopenharmony_ci    bool isMediaKeySupport = false;
37280922886Sopenharmony_ci
37380922886Sopenharmony_ci    int32_t castConnectStateForDisconnect_ = 5;
37480922886Sopenharmony_ci    int32_t castConnectStateForConnected_ = 6;
37580922886Sopenharmony_ci    int32_t removeCmdStep_ = 1000;
37680922886Sopenharmony_ci
37780922886Sopenharmony_ci    volatile bool isDestroyed_ = false;
37880922886Sopenharmony_ci
37980922886Sopenharmony_ci    AVSessionDisplayIntf *avsessionDisaplayIntf_;
38080922886Sopenharmony_ci    std::unique_ptr<AVSessionDynamicLoader> dynamicLoader_ {};
38180922886Sopenharmony_ci
38280922886Sopenharmony_ci    static const int32_t DEFAULT_USER_ID = 100;
38380922886Sopenharmony_ci
38480922886Sopenharmony_ci    // The following locks are used in the defined order of priority
38580922886Sopenharmony_ci    std::recursive_mutex avsessionItemLock_;
38680922886Sopenharmony_ci
38780922886Sopenharmony_ci    std::recursive_mutex controllersLock_;
38880922886Sopenharmony_ci
38980922886Sopenharmony_ci    std::recursive_mutex callbackLock_;
39080922886Sopenharmony_ci
39180922886Sopenharmony_ci    std::recursive_mutex destroyLock_;
39280922886Sopenharmony_ci
39380922886Sopenharmony_ci    std::recursive_mutex displayListenerLock_;
39480922886Sopenharmony_ci
39580922886Sopenharmony_ci    std::recursive_mutex remoteCallbackLock_;
39680922886Sopenharmony_ci
39780922886Sopenharmony_ci    std::recursive_mutex remoteSourceLock_;
39880922886Sopenharmony_ci
39980922886Sopenharmony_ci    std::recursive_mutex remoteSinkLock_;
40080922886Sopenharmony_ci
40180922886Sopenharmony_ci#ifdef CASTPLUS_CAST_ENGINE_ENABLE
40280922886Sopenharmony_ci    std::recursive_mutex castHandleLock_;
40380922886Sopenharmony_ci    int64_t castHandle_ = 0;
40480922886Sopenharmony_ci    std::string castHandleDeviceId_ = "-100";
40580922886Sopenharmony_ci    const int32_t streamStateConnection = 6;
40680922886Sopenharmony_ci    const int32_t virtualDeviceStateConnection = -6;
40780922886Sopenharmony_ci    const std::string deviceStateConnection = "CONNECT_SUCC";
40880922886Sopenharmony_ci    const int32_t firstStep = 1;
40980922886Sopenharmony_ci    const int32_t secondStep = 2;
41080922886Sopenharmony_ci    int32_t removeTimes = 0;
41180922886Sopenharmony_ci    int32_t newCastState = -1;
41280922886Sopenharmony_ci    int32_t counter_ = -1;
41380922886Sopenharmony_ci    bool isUpdate = false;
41480922886Sopenharmony_ci    std::map<std::string, std::string> castServiceNameMapState_;
41580922886Sopenharmony_ci
41680922886Sopenharmony_ci    bool collaborationRejectFlag_ = false;
41780922886Sopenharmony_ci    bool applyUserResultFlag_ = false;
41880922886Sopenharmony_ci    bool applyResultFlag_ = false;
41980922886Sopenharmony_ci    bool networkIdIsEmpty_ = false;
42080922886Sopenharmony_ci    bool waitUserDecisionFlag_ = false;
42180922886Sopenharmony_ci    bool mirrorToStreamFlag_ = false;
42280922886Sopenharmony_ci    std::string collaborationNeedNetworkId_;
42380922886Sopenharmony_ci    std::mutex collaborationApplyResultMutex_;
42480922886Sopenharmony_ci    std::condition_variable connectWaitCallbackCond_;
42580922886Sopenharmony_ci    const int32_t collaborationCallbackTimeOut_ = 10;
42680922886Sopenharmony_ci    const int32_t collaborationUserCallbackTimeOut_ = 60;
42780922886Sopenharmony_ci
42880922886Sopenharmony_ci    std::recursive_mutex castControllerProxyLock_;
42980922886Sopenharmony_ci    std::shared_ptr<IAVCastControllerProxy> castControllerProxy_;
43080922886Sopenharmony_ci    std::recursive_mutex castControllersLock_;
43180922886Sopenharmony_ci    std::vector<std::shared_ptr<AVCastControllerItem>> castControllers_;
43280922886Sopenharmony_ci    std::shared_ptr<CssListener> cssListener_;
43380922886Sopenharmony_ci    std::shared_ptr<IAVCastSessionStateListener> iAVCastSessionStateListener_;
43480922886Sopenharmony_ci    sptr<HwCastDisplayListener> displayListener_;
43580922886Sopenharmony_ci    std::recursive_mutex displayListenerLock_;
43680922886Sopenharmony_ci
43780922886Sopenharmony_ci    std::map<std::string, DeviceInfo> castDeviceInfoMap_;
43880922886Sopenharmony_ci    std::function<void(std::string)> serviceCallbackForStream_;
43980922886Sopenharmony_ci#endif
44080922886Sopenharmony_ci};
44180922886Sopenharmony_ci} // namespace OHOS::AVSession
44280922886Sopenharmony_ci#endif // OHOS_AVSESSION_ITEM_H
443