1 /* 2 * Copyright (C) 2021-2022 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 /** 17 * @file media_service.h 18 * 19 * @brief Declares the class of the media service framework, including attributes and methods. 20 * 21 * @since 1.0 22 * @version 1.0 23 */ 24 25 #ifndef MEDIA_SERVICE_H 26 #define MEDIA_SERVICE_H 27 28 #include <stdint.h> 29 #include <deque> 30 #include <vector> 31 #include <string> 32 #include "log.h" 33 namespace stub { 34 #define MEDIA_SERVICE_DISALLOW_COPY_AND_ASSIGN(TypeName) \ 35 TypeName(const TypeName &) = delete; \ 36 void operator=(const TypeName &) = delete 37 38 #define MEDIA_SERVICE_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ 39 TypeName() = delete; \ 40 MEDIA_SERVICE_DISALLOW_COPY_AND_ASSIGN(TypeName) 41 42 class MediaService { 43 public: 44 struct MediaPlayer { 45 uint8_t itemType_ {0xFF}; 46 uint8_t majorType_ {0xFF}; 47 uint8_t playStatus_ {0xFF}; 48 uint16_t playerId_ {0xFFFF}; 49 uint32_t subType_ {0xFFFFFFFF}; 50 std::string name_ {}; 51 std::vector<uint8_t> features_ {}; 52 }; 53 54 struct MediaItem { 55 uint8_t itemType_ {0xFF}; 56 uint8_t mediaType_ {0xFF}; 57 uint8_t playable_ {0xFF}; 58 uint64_t uid_ {0xFFFFFFFFFFFFFFFF}; 59 std::string name_ {}; 60 std::vector<uint32_t> attributes_ {}; 61 std::vector<std::string> values_ {}; 62 }; 63 64 class IObserver { 65 public: 66 IObserver() = default; 67 virtual ~IObserver() = default; 68 69 virtual void OnConnectionStateChanged(const std::string &addr, int state) = 0; 70 71 virtual void OnPressButton(const std::string &addr, uint8_t button) = 0; 72 73 virtual void OnReleaseButton(const std::string &addr, uint8_t button) = 0; 74 75 virtual void OnSetAddressedPlayer(const std::string &addr, uint8_t label, int status) = 0; 76 77 virtual void OnSetBrowsedPlayer(const std::string &addr, uint16_t uidCounter, uint32_t numOfItems, 78 const std::vector<std::string> &folderNames, uint8_t label, int status) = 0; 79 80 virtual void OnGetPlayerAppSettingAttributes( 81 const std::string &addr, const std::deque<uint8_t> &attributes, uint8_t label) = 0; 82 83 virtual void OnGetPlayerAppSettingValues( 84 const std::string &addr, const std::deque<uint8_t> &values, uint8_t label) = 0; 85 86 virtual void OnGetPlayerAppSettingCurrentValue(const std::string &addr, const std::deque<uint8_t> &attributes, 87 const std::deque<uint8_t> &values, uint8_t label, uint8_t context) = 0; 88 89 virtual void OnSetPlayerAppSettingCurrentValue(const std::string &addr, uint8_t label) = 0; 90 91 virtual void OnGetPlayerAppSettingAttributeText(const std::string &addr, const std::vector<uint8_t> &attributes, 92 const std::vector<std::string> &attrStr, uint8_t label) = 0; 93 94 virtual void OnGetPlayerAppSettingValueText(const std::string &addr, const std::vector<uint8_t> &values, 95 const std::vector<std::string> &valueStr, uint8_t label) = 0; 96 97 virtual void OnGetElementAttributes(const std::string &addr, const std::vector<uint32_t> &attribtues, 98 const std::vector<std::string> &values, uint8_t label) = 0; 99 100 virtual void OnGetPlayStatus(const std::string &addr, uint32_t songLength, uint32_t songPosition, 101 uint8_t playStatus, uint8_t label, uint8_t context) = 0; 102 103 virtual void OnPlayItem(const std::string &addr, uint8_t label, int status) = 0; 104 105 virtual void OnAddToNowPlaying(const std::string &addr, uint8_t label, int status) = 0; 106 107 virtual void OnChangePath(const std::string &addr, uint32_t numOfItems, uint8_t label, int status) = 0; 108 109 virtual void OnGetMediaPlayers(const std::string &addr, uint16_t uidCounter, 110 const std::vector<stub::MediaService::MediaPlayer> &items, uint8_t label, int status) = 0; 111 112 virtual void OnGetFolderItems(const std::string &addr, uint16_t uidCounter, 113 const std::vector<stub::MediaService::MediaItem> &items, uint8_t label, int status) = 0; 114 115 virtual void OnGetItemAttributes(const std::string &addr, const std::vector<uint32_t> &attributes, 116 const std::vector<std::string> &values, uint8_t label, int status) = 0; 117 118 virtual void OnGetTotalNumberOfItems( 119 const std::string &addr, uint16_t uidCounter, uint32_t numOfItems, uint8_t label, int status) = 0; 120 121 virtual void OnSetAbsoluteVolume(const std::string &addr, uint8_t volume, uint8_t label) = 0; 122 123 virtual void OnGetSelectedTrack(const std::string &addr, uint64_t uid, uint8_t label) = 0; 124 125 virtual void OnGetAddressedPlayer( 126 const std::string &addr, uint16_t playerId, uint16_t uidCounter, uint8_t label) = 0; 127 128 virtual void OnGetUidCounter(const std::string &addr, uint16_t uidCounter, uint8_t label) = 0; 129 130 virtual void OnGetCurrentAbsoluteVolume(const std::string &addr, uint8_t volume, uint8_t label) = 0; 131 }; 132 133 static MediaService *GetInstance(); 134 135 /****************************************************************** 136 * REGISTER / UNREGISTER OBSERVER * 137 ******************************************************************/ RegisterObserver(MediaService::IObserver * observer)138 void RegisterObserver(MediaService::IObserver *observer) 139 { 140 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 141 } UnregisterObserver(MediaService::IObserver * observer)142 void UnregisterObserver(MediaService::IObserver *observer) 143 { 144 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 145 } 146 147 /****************************************************************** 148 * CONNECTION * 149 ******************************************************************/ SetActiveDevice(const std::string & addr)150 void SetActiveDevice(const std::string &addr) 151 { 152 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 153 } 154 155 /****************************************************************** 156 * BUTTON OPERATION * 157 ******************************************************************/ PressButton(const std::string & addr,uint8_t button,uint8_t label)158 int PressButton(const std::string &addr, uint8_t button, uint8_t label) 159 { 160 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 161 return -1; 162 } ReleaseButton(const std::string & addr,uint8_t button,uint8_t label)163 int ReleaseButton(const std::string &addr, uint8_t button, uint8_t label) 164 { 165 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 166 return -1; 167 } 168 169 /****************************************************************** 170 * Media Player Selection * 171 ******************************************************************/ SetAddressedPlayer(const std::string & addr,uint16_t playerId,uint16_t uidCounter,uint8_t label)172 int SetAddressedPlayer(const std::string &addr, uint16_t playerId, uint16_t uidCounter, uint8_t label) 173 { 174 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 175 return -1; 176 } SetBrowsedPlayer(const std::string & addr,uint16_t playerId,uint16_t uidCounter,uint8_t label)177 int SetBrowsedPlayer(const std::string &addr, uint16_t playerId, uint16_t uidCounter, uint8_t label) 178 { 179 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 180 return -1; 181 } 182 183 /****************************************************************** 184 * Capabilities * 185 ******************************************************************/ GetCapabilities(const std::string & addr,uint8_t label)186 std::vector<uint8_t> GetCapabilities(const std::string &addr, uint8_t label) 187 { 188 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 189 std::vector<uint8_t> tmp; 190 return tmp; 191 } 192 193 /****************************************************************** 194 * PLAYER APPLICATION SETTINGS * 195 ******************************************************************/ GetPlayerAppSettingAttributes(const std::string & addr,uint8_t label)196 int GetPlayerAppSettingAttributes(const std::string &addr, uint8_t label) 197 { 198 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 199 return -1; 200 } GetPlayerAppSettingValues(const std::string & addr,uint8_t attribute,uint8_t label)201 int GetPlayerAppSettingValues(const std::string &addr, uint8_t attribute, uint8_t label) 202 { 203 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 204 return -1; 205 } GetPlayerAppSettingCurrentValue(const std::string & addr,const std::deque<uint8_t> & attributes,uint8_t label,uint8_t context)206 int GetPlayerAppSettingCurrentValue( 207 const std::string &addr, const std::deque<uint8_t> &attributes, uint8_t label, uint8_t context) 208 { 209 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 210 return -1; 211 } SetPlayerAppSettingCurrentValue(const std::string & addr,const std::deque<uint8_t> & attributes,const std::deque<uint8_t> & values,uint8_t label)212 int SetPlayerAppSettingCurrentValue(const std::string &addr, const std::deque<uint8_t> &attributes, 213 const std::deque<uint8_t> &values, uint8_t label) 214 { 215 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 216 return -1; 217 } GetPlayerAppSettingAttributeText(const std::string & addr,const std::vector<uint8_t> & attributes,uint8_t label)218 int GetPlayerAppSettingAttributeText( 219 const std::string &addr, const std::vector<uint8_t> &attributes, uint8_t label) 220 { 221 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 222 return -1; 223 } GetPlayerAppSettingValueText(const std::string & addr,uint8_t attribute,const std::vector<uint8_t> & values,uint8_t label)224 int GetPlayerAppSettingValueText( 225 const std::string &addr, uint8_t attribute, const std::vector<uint8_t> &values, uint8_t label) 226 { 227 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 228 return -1; 229 } 230 231 /****************************************************************** 232 * MEDIA INFORMATION PDUS * 233 ******************************************************************/ GetElementAttributes(const std::string & addr,uint64_t identifier,const std::vector<uint32_t> & attributes,uint8_t label)234 int GetElementAttributes( 235 const std::string &addr, uint64_t identifier, const std::vector<uint32_t> &attributes, uint8_t label) 236 { 237 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 238 return -1; 239 } 240 241 /****************************************************************** 242 * PLAY * 243 ******************************************************************/ GetPlayStatus(const std::string & addr,uint8_t label,uint8_t context)244 int GetPlayStatus(const std::string &addr, uint8_t label, uint8_t context) 245 { 246 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 247 return -1; 248 } PlayItem(const std::string & addr,uint8_t scope,uint64_t uid,uint16_t uidCounter,uint8_t label)249 int PlayItem(const std::string &addr, uint8_t scope, uint64_t uid, uint16_t uidCounter, uint8_t label) 250 { 251 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 252 return -1; 253 } AddToNowPlaying(const std::string & addr,uint8_t scope,uint64_t uid,uint16_t uidCounter,uint8_t label)254 int AddToNowPlaying(const std::string &addr, uint8_t scope, uint64_t uid, uint16_t uidCounter, uint8_t label) 255 { 256 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 257 return -1; 258 } 259 260 /****************************************************************** 261 * OPERATE THE VIRTUAL FILE SYSTEM * 262 ******************************************************************/ ChangePath(const std::string & addr,uint16_t uidCounter,uint8_t direction,uint64_t folderUid,uint8_t label)263 int ChangePath(const std::string &addr, uint16_t uidCounter, uint8_t direction, uint64_t folderUid, uint8_t label) 264 { 265 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 266 return -1; 267 } GetFolderItems(const std::string & addr,uint8_t scope,uint32_t startItem,uint32_t endItem,const std::vector<uint32_t> & attributes,uint8_t label)268 int GetFolderItems(const std::string &addr, uint8_t scope, uint32_t startItem, uint32_t endItem, 269 const std::vector<uint32_t> &attributes, uint8_t label) 270 { 271 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 272 return -1; 273 } GetItemAttributes(const std::string & addr,uint8_t scope,uint64_t uid,uint16_t uidCounter,const std::vector<uint32_t> & attributes,uint8_t label)274 int GetItemAttributes(const std::string &addr, uint8_t scope, uint64_t uid, uint16_t uidCounter, 275 const std::vector<uint32_t> &attributes, uint8_t label) 276 { 277 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 278 return -1; 279 } GetTotalNumberOfItems(const std::string & addr,uint8_t scope,uint8_t label)280 int GetTotalNumberOfItems(const std::string &addr, uint8_t scope, uint8_t label) 281 { 282 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 283 return -1; 284 } 285 286 /****************************************************************** 287 * ABSOLUTE VOLUME * 288 ******************************************************************/ SetAbsoluteVolume(const std::string & addr,uint8_t volume,uint8_t label)289 int SetAbsoluteVolume(const std::string &addr, uint8_t volume, uint8_t label) 290 { 291 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 292 return -1; 293 } GetSelectedTrack(const std::string addr,uint8_t label)294 int GetSelectedTrack(const std::string addr, uint8_t label) 295 { 296 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 297 return -1; 298 } GetAddressedPlayer(const std::string & addr,uint8_t label)299 int GetAddressedPlayer(const std::string &addr, uint8_t label) 300 { 301 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 302 return -1; 303 } GetUidCounter(const std::string & addr,uint8_t label)304 int GetUidCounter(const std::string &addr, uint8_t label) 305 { 306 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 307 return -1; 308 } GetCurrentAbsoluteVolume(const std::string & addr,uint8_t label)309 int GetCurrentAbsoluteVolume(const std::string &addr, uint8_t label) 310 { 311 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 312 return -1; 313 } SetPlaybackInterval(const std::string & addr,uint32_t interval)314 void SetPlaybackInterval(const std::string &addr, uint32_t interval) 315 { 316 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 317 } ResponseNotification(uint16_t events)318 void ResponseNotification(uint16_t events) 319 { 320 LOG_DEBUG("[AVRCP TG] MediaService::%{public}s", __func__); 321 } 322 323 private: 324 MediaService() = default; 325 ~MediaService() = default; 326 327 MEDIA_SERVICE_DISALLOW_COPY_AND_ASSIGN(MediaService); 328 }; 329 } // namespace stub 330 #endif // MEDIA_SERVICE_H