• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_CJ_AVSESSION_CONTROLLER_IMPL_H
17 #define OHOS_CJ_AVSESSION_CONTROLLER_IMPL_H
18 
19 #include <functional>
20 #include <map>
21 #include <optional>
22 #include <string>
23 #include <mutex>
24 #include <memory>
25 
26 #include "singleton.h"
27 #include "key_event.h"
28 #include "avsession_controller.h"
29 #include "avsession_errors.h"
30 #include "cj_avsession_controller_ffi.h"
31 #include "cj_avsession_manager_impl.h"
32 #include "cj_avsession_controller_callback.h"
33 
34 namespace OHOS::AVSession {
35 class CJAVSessionControllerBase {
36 public:
~CJAVSessionControllerBase()37     virtual ~CJAVSessionControllerBase() {}
38     virtual int32_t Destroy() = 0;
39     virtual int32_t GetAVCallState(CAVCallState& avCallState) = 0;
40     virtual int32_t GetAVCallMetaData(CAVCallMetaData& avCallMetadata) = 0;
41     virtual int32_t GetAVPlaybackState(CAVPlaybackState& avPlaybackState) = 0;
42     virtual int32_t GetAVMetaData(CAVMetaData& avMetadata) = 0;
43     virtual int32_t GetOutputDevice(COutputDeviceInfo& outputDeviceInfo) = 0;
44     virtual int32_t GetRealPlaybackPosition(int64_t& position) = 0;
45     virtual int32_t IsActive(bool& isActive) = 0;
46     virtual int32_t GetValidCommands(CArray& commands) = 0;
47     virtual int32_t GetAVQueueItems(CArray& items) = 0;
48     virtual int32_t GetAVQueueTitle(char*& title) = 0;
49     virtual int32_t GetExtras(CArray& extras) = 0;
50     virtual int32_t GetLaunchAbility(int64_t& abilityId) = 0;
51     virtual int32_t SendCommonCommand(char*& command, CArray& args) = 0;
52     virtual int32_t SendControlCommand(CAVSessionCommand& command) = 0;
53     virtual int32_t SendAVKeyEvent(CKeyEvent& event) = 0;
54     virtual int32_t SkipToQueueItem(int32_t& itemId) = 0;
55     virtual bool Exists() = 0;
56     virtual int32_t OnEvent(int32_t type, int64_t id) = 0;
57     virtual int32_t OffEvent(int32_t type) = 0;
58     virtual int32_t OnEventCallMetadataChange(int32_t type, CParameters* filter, int64_t id) = 0;
59     virtual int32_t OnEventCallStateChange(int32_t type, CParameters* filter, int64_t id) = 0;
60     virtual int32_t OnEventPlaybackStateChange(int32_t type, CParameters* filter, int64_t id) = 0;
61     virtual int32_t OnEventMetaDataChang(int32_t type, CParameters* filter, int64_t id) = 0;
62 };
63 
64 class CJAVSessionControllerImpl : public CJAVSessionControllerBase {
65     friend class CJAVSessionManagerImpl;
66 private:
67     CJAVSessionControllerImpl(std::shared_ptr<AVSessionController>& nativeController);
68 public:
69     ~CJAVSessionControllerImpl();
70     static std::shared_ptr<CJAVSessionControllerBase> GetInstance(const std::string &sessionId);
71     static std::shared_ptr<CJAVSessionControllerImpl>
72         NewInstance(std::shared_ptr<AVSessionController>& nativeController);
73     int32_t Destroy();
74     int32_t GetAVCallState(CAVCallState& avCallState);
75     int32_t GetAVCallMetaData(CAVCallMetaData& avCallMetadata);
76     int32_t GetAVPlaybackState(CAVPlaybackState& avPlaybackState);
77     int32_t GetAVMetaData(CAVMetaData& avMetadata);
78     int32_t GetOutputDevice(COutputDeviceInfo& outputDeviceInfo);
79     int32_t GetRealPlaybackPosition(int64_t& position);
80     int32_t IsActive(bool& isActive);
81     int32_t GetValidCommands(CArray& commands);
82     int32_t GetAVQueueItems(CArray& items);
83     int32_t GetAVQueueTitle(char*& title);
84     int32_t GetExtras(CArray& extras);
85     int32_t GetLaunchAbility(int64_t& abilityId);
86     int32_t SendCommonCommand(char*& command, CArray& args);
87     int32_t SendControlCommand(CAVSessionCommand& command);
88     int32_t SendAVKeyEvent(CKeyEvent& event);
89     int32_t SkipToQueueItem(int32_t& itemId);
Exists()90     bool Exists() { return true; }
91     int32_t OnEvent(int32_t type, int64_t id);
92     int32_t OffEvent(int32_t type);
93     int32_t OnEventCallMetadataChange(int32_t type, CParameters* filter, int64_t id);
94     int32_t OnEventCallStateChange(int32_t type, CParameters* filter, int64_t id);
95     int32_t OnEventPlaybackStateChange(int32_t type, CParameters* filter, int64_t id);
96     int32_t OnEventMetaDataChang(int32_t type, CParameters* filter, int64_t id);
97 private:
98     std::string sessionId_;
99     std::shared_ptr<AVSessionController> controller_;
100     static std::mutex controllerListMutex_;
101     std::shared_ptr<CJAVControllerCallback> callback_;
102 
103     static std::map<std::string, std::shared_ptr<CJAVSessionControllerImpl>> ControllerList_;
104 };
105 
106 class CJAVSessionControllerInvalidImpl : public CJAVSessionControllerBase {
107     DECLARE_DELAYED_SINGLETON(CJAVSessionControllerInvalidImpl);
108 public:
109     DISALLOW_COPY_AND_MOVE(CJAVSessionControllerInvalidImpl);
Destroy()110     int32_t Destroy() { return ERR_CONTROLLER_NOT_EXIST; }
GetAVCallState(CAVCallState & avCallState)111     int32_t GetAVCallState(CAVCallState& avCallState) { return ERR_CONTROLLER_NOT_EXIST; }
GetAVCallMetaData(CAVCallMetaData & avCallMetadata)112     int32_t GetAVCallMetaData(CAVCallMetaData& avCallMetadata) { return ERR_CONTROLLER_NOT_EXIST; }
GetAVPlaybackState(CAVPlaybackState & avPlaybackState)113     int32_t GetAVPlaybackState(CAVPlaybackState& avPlaybackState) { return ERR_CONTROLLER_NOT_EXIST; }
GetAVMetaData(CAVMetaData & avMetadata)114     int32_t GetAVMetaData(CAVMetaData& avMetadata) { return ERR_CONTROLLER_NOT_EXIST; }
GetOutputDevice(COutputDeviceInfo & outputDeviceInfo)115     int32_t GetOutputDevice(COutputDeviceInfo& outputDeviceInfo) { return ERR_CONTROLLER_NOT_EXIST; }
GetRealPlaybackPosition(int64_t & position)116     int32_t GetRealPlaybackPosition(int64_t& position) { return ERR_CONTROLLER_NOT_EXIST; }
IsActive(bool & isActive)117     int32_t IsActive(bool& isActive) { return ERR_CONTROLLER_NOT_EXIST; }
GetValidCommands(CArray & commands)118     int32_t GetValidCommands(CArray& commands) { return ERR_CONTROLLER_NOT_EXIST; }
GetAVQueueItems(CArray & items)119     int32_t GetAVQueueItems(CArray& items) { return ERR_CONTROLLER_NOT_EXIST; }
GetAVQueueTitle(char * & title)120     int32_t GetAVQueueTitle(char*& title) { return ERR_CONTROLLER_NOT_EXIST; }
GetExtras(CArray & extras)121     int32_t GetExtras(CArray& extras) { return ERR_CONTROLLER_NOT_EXIST; }
GetLaunchAbility(int64_t & abilityId)122     int32_t GetLaunchAbility(int64_t& abilityId) { return ERR_CONTROLLER_NOT_EXIST; }
SendCommonCommand(char * & command,CArray & args)123     int32_t SendCommonCommand(char*& command, CArray& args) { return ERR_CONTROLLER_NOT_EXIST; }
SendControlCommand(CAVSessionCommand & command)124     int32_t SendControlCommand(CAVSessionCommand& command) { return ERR_CONTROLLER_NOT_EXIST; }
SendAVKeyEvent(CKeyEvent & event)125     int32_t SendAVKeyEvent(CKeyEvent& event) { return ERR_CONTROLLER_NOT_EXIST; }
SkipToQueueItem(int32_t & itemId)126     int32_t SkipToQueueItem(int32_t& itemId) { return ERR_CONTROLLER_NOT_EXIST; }
Exists()127     bool Exists() { return false; }
OnEvent(int32_t type,int64_t id)128     int32_t OnEvent(int32_t type, int64_t id) { return ERR_CONTROLLER_NOT_EXIST; }
OffEvent(int32_t type)129     int32_t OffEvent(int32_t type) { return ERR_CONTROLLER_NOT_EXIST; }
OnEventCallMetadataChange(int32_t type,CParameters * filter,int64_t id)130     int32_t OnEventCallMetadataChange(int32_t type, CParameters* filter, int64_t id)
131     {
132         return ERR_CONTROLLER_NOT_EXIST;
133     }
OnEventCallStateChange(int32_t type,CParameters * filter,int64_t id)134     int32_t OnEventCallStateChange(int32_t type, CParameters* filter, int64_t id) { return ERR_CONTROLLER_NOT_EXIST; }
OnEventPlaybackStateChange(int32_t type,CParameters * filter,int64_t id)135     int32_t OnEventPlaybackStateChange(int32_t type, CParameters* filter, int64_t id)
136     {
137         return ERR_CONTROLLER_NOT_EXIST;
138     }
OnEventMetaDataChang(int32_t type,CParameters * filter,int64_t id)139     int32_t OnEventMetaDataChang(int32_t type, CParameters* filter, int64_t id) { return ERR_CONTROLLER_NOT_EXIST; }
140 };
141 
142 #define CJ_AVSESSION_CONTROLLER_INVALID_IMPL OHOS::DelayedSingleton<CJAVSessionControllerInvalidImpl>::GetInstance()
143 
144 } // namespace AVSession::OHOS
145 
146 #endif // OHOS_CJ_AVSESSION_CONTROLLER_IMPL_H