• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "remote_session_capability_set.h"
17 #include "avcontrol_command.h"
18 #include "avmeta_data.h"
19 #include "avplayback_state.h"
20 #include "avmedia_description.h"
21 #include "avqueue_item.h"
22 
23 namespace OHOS::AVSession {
GetInstance()24 RemoteSessionCapabilitySet& RemoteSessionCapabilitySet::GetInstance()
25 {
26     static RemoteSessionCapabilitySet sessionCapabilitySet;
27     return sessionCapabilitySet;
28 }
29 
30 // LCOV_EXCL_START
GetLocalCapability()31 std::string RemoteSessionCapabilitySet::GetLocalCapability()
32 {
33     std::vector<std::vector<int32_t>> localCapability(SESSION_DATA_CATEGORY_MAX);
34     localCapability[SESSION_DATA_META] = AVMetaData::localCapability;
35     localCapability[SESSION_DATA_PLAYBACK_STATE] = AVPlaybackState::localCapability;
36     localCapability[SESSION_DATA_CONTROL_COMMAND] = AVControlCommand::localCapability;
37     std::string jsonSinkCap;
38     int32_t ret = JsonUtils::GetJsonCapability(localCapability, jsonSinkCap);
39     CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, "", "AddRemoteCapability error");
40     return jsonSinkCap;
41 }
42 // LCOV_EXCL_STOP
43 
44 // LCOV_EXCL_START
AddRemoteCapability(const std::string & sessionId,const std::string & sinkDeviceId,const std::string & sinkCapability)45 void RemoteSessionCapabilitySet::AddRemoteCapability(const std::string& sessionId, const std::string& sinkDeviceId,
46                                                      const std::string& sinkCapability)
47 {
48     std::string key = sessionId + "-" + sinkDeviceId;
49     std::vector<std::vector<int32_t>> value(SESSION_DATA_CATEGORY_MAX);
50     int32_t ret = JsonUtils::GetVectorCapability(sinkCapability, value);
51     CHECK_AND_RETURN_LOG(ret == AVSESSION_SUCCESS, "AddRemoteCapability error");
52     capabilitys_[key] = value;
53 }
54 // LCOV_EXCL_STOP
55 
56 // LCOV_EXCL_START
RemoveRemoteCapability(const std::string & sessionId,const std::string & sinkDevice)57 void RemoteSessionCapabilitySet::RemoveRemoteCapability(const std::string& sessionId, const std::string& sinkDevice)
58 {
59     CHECK_AND_RETURN_LOG(capabilitys_.size() > 0, " Don't have Capability");
60     std::string key = sessionId + "-" + sinkDevice;
61     capabilitys_.erase(key);
62 }
63 // LCOV_EXCL_STOP
64 
65 // LCOV_EXCL_START
HasCapability(const std::string & sessionId,const std::string & sinkDevice,SessionDataCategory category,int32_t key)66 bool RemoteSessionCapabilitySet::HasCapability(const std::string& sessionId, const std::string& sinkDevice,
67                                                SessionDataCategory category, int32_t key)
68 {
69     CHECK_AND_RETURN_RET_LOG(capabilitys_.size() > 0, false, "Don't have Capability");
70     std::string strKey = sessionId + "-" + sinkDevice;
71     auto iter = capabilitys_.find(strKey);
72     CHECK_AND_RETURN_RET_LOG(iter != capabilitys_.end(), false, "Don't have the key");
73     std::vector<std::vector<int32_t>> capability = iter->second;
74     CHECK_AND_RETURN_RET_LOG(capability[category].size() > 0, false, "Don't have Capability");
75     for (const auto &item : capability[category]) {
76         if (item == key) {
77             return true;
78         }
79     }
80     return false;
81 }
82 // LCOV_EXCL_STOP
83 } // namespace OHOS::AVSession