RDK Documentation (Open Sourced RDK Components)
SubtecChannel.hpp
1 /*
2  * If not stated otherwise in this file or this component's license file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2021 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 #pragma once
21 
22 #include <memory>
23 #include <vector>
24 #include <mutex>
25 #include "SubtecAttribute.hpp"
26 
28 {
29 public:
30  static SubtecChannelManager *getInstance()
31  {
32  static SubtecChannelManager instance;
33  return &instance;
34  }
35  int getNextChannelId() { return m_nextChannelId++; }
36 protected:
37  SubtecChannelManager() : m_nextChannelId(0) {}
38 private:
39  uint32_t m_nextChannelId;
40 };
41 
43 {
44 
45 protected:
46  template<typename PacketType, typename ...Args>
47  void sendPacket(Args && ...args);
48 public:
49  enum class ChannelType
50  {
51  TTML,
52  WEBVTT,
53  CC
54  };
55 
56  SubtecChannel() : m_counter(0), m_channelId(0), mChannelMtx()
57  {
58  m_channelId = SubtecChannelManager::getInstance()->getNextChannelId();
59  }
60 
61  static std::unique_ptr<SubtecChannel> SubtecChannelFactory(ChannelType type);
62 
63  static bool InitComms();
64  static bool InitComms(const char* socket_path);
65  void SendResetAllPacket();
66  void SendResetChannelPacket();
67  void SendPausePacket();
68  void SendResumePacket();
69  void SendMutePacket();
70  void SendUnmutePacket();
71  void SendCCSetAttributePacket(std::uint32_t ccType, std::uint32_t attribType, const attributesType &attributesValues);
72 
73  virtual void SendSelectionPacket(uint32_t width, uint32_t height){};
74  virtual void SendDataPacket(std::vector<uint8_t> &&data, std::int64_t time_offset_ms = 0){};
75  virtual void SendTimestampPacket(uint64_t timestampMs){};
76 
77  virtual ~SubtecChannel() = 0;
78 
79 protected:
80  uint32_t m_channelId;
81  uint32_t m_counter;
82  std::mutex mChannelMtx;
83 };
SubtecAttribute.hpp
This file has been created to provide common definition related to Attribute.
SubtecChannelManager
Definition: SubtecChannel.hpp:27
SubtecChannel
Definition: SubtecChannel.hpp:42
attributesType
std::array< uint32_t, 14 > attributesType
Definition: SubtecAttribute.hpp:30