1 /*
2  * Copyright (c) 2023 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_AV_SYNC_MANAGER_H
17 #define OHOS_AV_SYNC_MANAGER_H
18 
19 #include <set>
20 #include <mutex>
21 
22 #include "av_sync_utils.h"
23 #include "av_trans_message.h"
24 #include "av_trans_types.h"
25 
26 namespace OHOS {
27 namespace DistributedHardware {
28 constexpr uint32_t AV_SYNC_STREAM_COUNT = 2;
29 
30 class AVSyncManager {
31 public:
32     AVSyncManager();
33     ~AVSyncManager();
34 
35     void AddStreamInfo(const AVStreamInfo &stream);
36     void RemoveStreamInfo(const AVStreamInfo &stream);
37     void HandleAvSyncMessage(const std::shared_ptr<AVTransMessage> &message);
38 
39 private:
40     void EnableSenderAVSync();
41     void DisableSenderAVSync();
42     void EnableReceiverAVSync(const std::string &groupInfo);
43     void DisableReceiverAVSync(const std::string &groupInfo);
44     bool MergeGroupInfo(std::string &syncGroupInfo);
45     bool MergeGroupInfoInner(std::set<std::string> &groupInfoSet);
46     std::string GetsyncGroupInfo(std::set<std::string> &groupInfoSet);
47 
48 private:
49     std::mutex listMutex_;
50 
51     std::vector<AVStreamInfo> streamInfoList_;
52     AVTransSharedMemory sourceMemory_;
53     AVTransSharedMemory sinkMemory_;
54 };
55 }
56 }
57 #endif