RDK Documentation (Open Sourced RDK Components)
ClosedCaptionsPacket.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 2020 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 "SubtecPacket.hpp"
23 #include "SubtecChannel.hpp"
24 #include "PacketSender.hpp"
25 
26 
28 {
29 public:
30 
31  ClosedCaptionsPacket(uint32_t channelId, uint32_t counter, uint32_t ptsValue, uint8_t* data, size_t dataLen)
32  {
33  appendType(Packet::PacketType::CC_DATA);
34  append32(counter);
35  append32(CC_DATA_HEADER_LEN+dataLen);
36  append32(channelId);
37  append32(CC_CHANNEL_TYPE);
38  append32(1); // pts presence
39  append32(ptsValue);
40  for(int i = 0; i<dataLen; ++i)
41  getBuffer().push_back(data[i]);
42  }
43 
44  ClosedCaptionsPacket(uint32_t channelId, uint32_t counter, uint8_t* data, size_t dataLen)
45  {
46  appendType(Packet::PacketType::CC_DATA);
47  append32(counter);
48  append32(CC_DATA_HEADER_LEN+dataLen);
49  append32(channelId);
50  append32(CC_CHANNEL_TYPE);
51  append32(0); // pts presence
52  append32(0); // no pts value
53  for(int i = 0; i<dataLen; ++i)
54  getBuffer().push_back(data[i]);
55  }
56 
57 private:
58  static constexpr std::uint8_t CC_DATA_HEADER_LEN = 16;
59  static constexpr std::uint8_t CC_CHANNEL_TYPE = 3;
60 };
61 
63 {
64 public:
65  enum class CEA : uint32_t
66  {
67  type_608 = 0,
68  type_708 = 1
69  };
70 
71  ClosedCaptionsActiveTypePacket(uint32_t channelId, uint32_t counter, CEA type, int service)
72  {
73  auto to_integral = [](CEA e) -> uint32_t
74  {
75  return static_cast<uint32_t>(e);
76  };
77 
78  appendType(Packet::PacketType::SUBTITLE_SELECTION);
79  append32(counter);
80  append32(CC_SELECTION_LEN);
81  append32(channelId);
82  append32(CC_USERDATA_SUBTITLE_TYPE);
83  append32(to_integral(type)); //aux id 1
84  append32(service);//aux id 2
85 
86 
87  }
88 
89 
90 private:
91  static constexpr std::uint8_t CC_SELECTION_LEN = 16;
92  static constexpr std::uint8_t CC_USERDATA_SUBTITLE_TYPE = 3;
93 };
94 
96 {
97 public:
99 
100  void SendDataPacketWithPTS(uint32_t ptsValue, uint8_t* data, size_t dataLen)
101  {
102  std::unique_lock<std::mutex> lock(mChannelMtx);
103  PacketSender::Instance()->SendPacket(std::unique_ptr<ClosedCaptionsPacket>(new ClosedCaptionsPacket(m_channelId, m_counter++, ptsValue, data, dataLen)));
104  }
105 
106  void SendDataPacketNoPTS(uint8_t* data, size_t dataLen)
107  {
108  std::unique_lock<std::mutex> lock(mChannelMtx);
109  PacketSender::Instance()->SendPacket(std::unique_ptr<ClosedCaptionsPacket>(new ClosedCaptionsPacket(m_channelId, m_counter++, data, dataLen)));
110  }
111 
112  void SendActiveTypePacket(ClosedCaptionsActiveTypePacket::CEA type, unsigned int channel)
113  {
114  std::unique_lock<std::mutex> lock(mChannelMtx);
115  PacketSender::Instance()->SendPacket(std::unique_ptr<ClosedCaptionsActiveTypePacket>(new ClosedCaptionsActiveTypePacket(m_channelId, m_counter++, type, channel)));
116  }
117 };
ClosedCaptionsPacket
Definition: ClosedCaptionsPacket.hpp:27
ClosedCaptionsActiveTypePacket
Definition: ClosedCaptionsPacket.hpp:62
SubtecChannel
Definition: SubtecChannel.hpp:42
ClosedCaptionsChannel
Definition: ClosedCaptionsPacket.hpp:95
Packet
Definition: SubtecPacket.hpp:31