RDK Documentation (Open Sourced RDK Components)
SubtecChannel.cpp
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 #include <memory>
21 
22 #include "PacketSender.hpp"
23 #include "SubtecChannel.hpp"
24 #include "SubtecPacket.hpp"
25 #include "TtmlPacket.hpp"
26 #include "WebVttPacket.hpp"
27 #include "ClosedCaptionsPacket.hpp"
28 
29 namespace
30 {
31  template<typename T, typename ...Args>
32  std::unique_ptr<T> make_unique(Args&& ...args)
33  {
34  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
35  }
36 }
37 
38 std::unique_ptr<SubtecChannel> SubtecChannel::SubtecChannelFactory(ChannelType type)
39 {
40  std::unique_ptr<SubtecChannel> subtecChannel;
41 
42  switch (type)
43  {
44  case ChannelType::TTML:
45  subtecChannel = make_unique<TtmlChannel>();
46  break;
47  case ChannelType::WEBVTT:
48  subtecChannel = make_unique<WebVttChannel>();
49  break;
50  case ChannelType::CC:
51  break;
52  default:
53  break;
54  }
55 
56  return subtecChannel;
57 }
58 
59 bool SubtecChannel::InitComms()
60 {
61  const char *socket_path = ::getenv("AAMP_SUBTITLE_SOCKET");
62 
63  if (socket_path)
64  return InitComms(socket_path);
65  else
66  return InitComms(SOCKET_PATH);
67 }
68 
69 bool SubtecChannel::InitComms(const char* socket_path)
70 {
71  return PacketSender::Instance()->Init(socket_path);
72 }
73 
74 
75 template<typename PacketType, typename ...Args>
76 void SubtecChannel::sendPacket(Args && ...args)
77 {
78  std::unique_lock<std::mutex> lock(mChannelMtx);
79  PacketSender::Instance()->SendPacket(make_unique<PacketType>(m_channelId, m_counter++, std::forward<Args>(args)...));
80 }
81 
82 void SubtecChannel::SendResetAllPacket()
83 {
84  std::unique_lock<std::mutex> lock(mChannelMtx);
85  m_counter = 1;
86  PacketSender::Instance()->SendPacket(make_unique<ResetAllPacket>());
87 }
88 
89 void SubtecChannel::SendResetChannelPacket() {
90  sendPacket<ResetChannelPacket>();
91 }
92 void SubtecChannel::SendPausePacket() {
93  sendPacket<PausePacket>();
94 }
95 void SubtecChannel::SendResumePacket() {
96  sendPacket<ResumePacket>();
97 }
98 void SubtecChannel::SendMutePacket() {
99  sendPacket<MutePacket>();
100 }
101 void SubtecChannel::SendUnmutePacket() {
102  sendPacket<UnmutePacket>();
103 }
104 void SubtecChannel::SendCCSetAttributePacket(std::uint32_t ccType, std::uint32_t attribType, const attributesType &attributesValues) {
105  AAMPLOG_INFO("SendCCSetAttributePacket, the bit mask is 0x%X", attribType);
106  sendPacket<CCSetAttributePacket>(ccType, attribType, attributesValues);
107 }
108 
109 SubtecChannel::~SubtecChannel() {}
attributesType
std::array< uint32_t, 14 > attributesType
Definition: SubtecAttribute.hpp:30