RDK Documentation (Open Sourced RDK Components)
TtmlPacket.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 
26 {
27 public:
28  /**
29  * Constructor.
30  *
31  * @param channelId
32  * Packet channelId.
33  * @param counter
34  * Packet counter.
35  * @param width
36  * Display width.
37  * @param height
38  * Display height.
39  */
40  TtmlSelectionPacket(uint32_t channelId, uint32_t counter, uint32_t width, uint32_t height) : Packet(counter)
41  {
42  appendType(Packet::PacketType::TTML_SELECTION);
43  append32(counter);
44  append32(TTML_SELECTION_PACKET_SIZE);
45  append32(channelId);
46  append32(width);
47  append32(height);
48  }
49 
50 private:
51  static constexpr std::uint8_t TTML_SELECTION_PACKET_SIZE = 12;
52 };
53 
54 class TtmlDataPacket : public Packet
55 {
56 public:
57 
58  /**
59  * Constructor.
60  *
61  * @param channelId
62  * Packet channelId.
63  * @param counter
64  * Packet counter.
65  * @param dataOffset
66  * Data offset if needed
67  * @param dataBuffer
68  * Packet data.
69  */
70  TtmlDataPacket(std::uint32_t channelId,
71  std::uint32_t counter,
72  std::int64_t dataOffset,
73  std::vector<std::uint8_t> &&dataBuffer) : Packet(counter)
74  {
75  auto& buffer = getBuffer();
76  uint32_t size = 8 + 4 + dataBuffer.size();
77 
78  appendType(PacketType::TTML_DATA);
79  append32(counter);
80  append32(size);
81  append32(channelId);
82  append64(dataOffset);
83 
84  buffer.insert(buffer.end(), dataBuffer.begin(), dataBuffer.end());
85  }
86 };
87 
88 
90 {
91 public:
92 
93  /**
94  * Constructor.
95  *
96  * @param counter
97  * Packet counter.
98  */
99  TtmlTimestampPacket(std::uint32_t channelId,
100  std::uint32_t counter,
101  std::uint64_t timestamp) : Packet(counter)
102  {
103  appendType(PacketType::TTML_TIMESTAMP);
104  append32(counter);
105  append32(TTML_TIMESTAMP_PACKET_SIZE);
106  append32(channelId);
107  append64(timestamp);
108  }
109 
110 private:
111 
112  static constexpr std::uint8_t TTML_TIMESTAMP_PACKET_SIZE = 12;
113 };
114 
115 
117 {
118 public:
119  TtmlChannel() : SubtecChannel() {}
120 
121  virtual void SendSelectionPacket(uint32_t width, uint32_t height) override {
122  sendPacket<TtmlSelectionPacket>(width, height);
123  }
124  virtual void SendDataPacket(std::vector<uint8_t> &&data, std::int64_t time_offset_ms = 0) override {
125  sendPacket<TtmlDataPacket>(time_offset_ms, std::move(data));
126  }
127  virtual void SendTimestampPacket(uint64_t timestampMs) override {
128  sendPacket<TtmlTimestampPacket>(timestampMs);
129  }
130 };
TtmlSelectionPacket
Definition: TtmlPacket.hpp:25
TtmlDataPacket
Definition: TtmlPacket.hpp:54
SubtecChannel
Definition: SubtecChannel.hpp:42
TtmlChannel
Definition: TtmlPacket.hpp:116
TtmlDataPacket::TtmlDataPacket
TtmlDataPacket(std::uint32_t channelId, std::uint32_t counter, std::int64_t dataOffset, std::vector< std::uint8_t > &&dataBuffer)
Definition: TtmlPacket.hpp:70
TtmlTimestampPacket::TtmlTimestampPacket
TtmlTimestampPacket(std::uint32_t channelId, std::uint32_t counter, std::uint64_t timestamp)
Definition: TtmlPacket.hpp:99
TtmlTimestampPacket
Definition: TtmlPacket.hpp:89
TtmlSelectionPacket::TtmlSelectionPacket
TtmlSelectionPacket(uint32_t channelId, uint32_t counter, uint32_t width, uint32_t height)
Definition: TtmlPacket.hpp:40
Packet
Definition: SubtecPacket.hpp:31