RDK Documentation (Open Sourced RDK Components)
WebVttPacket.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  WebVttSelectionPacket(uint32_t channelId, uint32_t counter, uint32_t width, uint32_t height) : Packet(counter)
41  {
42  appendType(Packet::PacketType::WEBVTT_SELECTION);
43  append32(counter);
44  append32(WEBVTT_SELECTION_PACKET_SIZE);
45  append32(channelId);
46  append32(width);
47  append32(height);
48  }
49 
50 private:
51  static constexpr std::uint8_t WEBVTT_SELECTION_PACKET_SIZE = 12;
52 };
53 
54 class WebVttDataPacket : public Packet
55 {
56 public:
57 
58  /**
59  * Constructor.
60  *
61  * @param channelId
62  * Packet channelId.
63  * @param counter
64  * Packet counter.
65  * @param timeOffsetMs
66  * Data offset if needed
67  * @param dataBuffer
68  * Packet data.
69  */
70  WebVttDataPacket(std::uint32_t channelId,
71  std::uint32_t counter,
72  std::int64_t timeOffsetMs,
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::WEBVTT_DATA);
79  append32(counter);
80  append32(size);
81  append32(channelId);
82  append64(timeOffsetMs);
83 
84  for (auto &byte : dataBuffer)
85  buffer.push_back(byte);
86  }
87 };
88 
89 
91 {
92 public:
93 
94  /**
95  * Constructor.
96  *
97  * @param counter
98  * Packet counter.
99  */
100  WebVttTimestampPacket(std::uint32_t channelId,
101  std::uint32_t counter,
102  std::uint64_t timestamp) : Packet(counter)
103  {
104  appendType(PacketType::WEBVTT_TIMESTAMP);
105  append32(counter);
106  append32(WEBVTT_TIMESTAMP_PACKET_SIZE);
107  append32(channelId);
108  append64(timestamp);
109  }
110 
111 private:
112 
113  static constexpr std::uint8_t WEBVTT_TIMESTAMP_PACKET_SIZE = 12;
114 };
115 
116 
118 {
119 public:
121 
122  virtual void SendSelectionPacket(uint32_t width, uint32_t height) override {
123  sendPacket<WebVttSelectionPacket>(width, height);
124  }
125  virtual void SendDataPacket(std::vector<uint8_t> &&data, std::int64_t time_offset_ms = 0) override {
126  sendPacket<WebVttDataPacket>(time_offset_ms, std::move(data));
127  }
128  virtual void SendTimestampPacket(uint64_t timestampMs) override {
129  sendPacket<WebVttTimestampPacket>(timestampMs);
130  }
131 };
WebVttTimestampPacket::WebVttTimestampPacket
WebVttTimestampPacket(std::uint32_t channelId, std::uint32_t counter, std::uint64_t timestamp)
Definition: WebVttPacket.hpp:100
WebVttSelectionPacket
Definition: WebVttPacket.hpp:25
SubtecChannel
Definition: SubtecChannel.hpp:42
WebVttChannel
Definition: WebVttPacket.hpp:117
WebVttDataPacket::WebVttDataPacket
WebVttDataPacket(std::uint32_t channelId, std::uint32_t counter, std::int64_t timeOffsetMs, std::vector< std::uint8_t > &&dataBuffer)
Definition: WebVttPacket.hpp:70
WebVttSelectionPacket::WebVttSelectionPacket
WebVttSelectionPacket(uint32_t channelId, uint32_t counter, uint32_t width, uint32_t height)
Definition: WebVttPacket.hpp:40
WebVttTimestampPacket
Definition: WebVttPacket.hpp:90
WebVttDataPacket
Definition: WebVttPacket.hpp:54
Packet
Definition: SubtecPacket.hpp:31