RDK Documentation (Open Sourced RDK Components)
WebVttSubtecParser.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 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 #include "WebVttSubtecParser.hpp"
21 #include "TextStyleAttributes.h"
22 
23 WebVTTSubtecParser::WebVTTSubtecParser(AampLogManager *logObj, PrivateInstanceAAMP *aamp, SubtitleMimeType type) : SubtitleParser(logObj, aamp, type), m_channel(nullptr)
24 {
25  m_channel = SubtecChannel::SubtecChannelFactory(SubtecChannel::ChannelType::WEBVTT);
26  if (!m_channel->InitComms())
27  {
28  AAMPLOG_INFO("Init failed - subtitle parsing disabled");
29  throw std::runtime_error("PacketSender init failed");
30  }
31  AAMPLOG_INFO("Sending RESET ALL");
32  m_channel->SendResetAllPacket();
33  int width = 1920, height = 1080;
34  m_channel->SendMutePacket();
35  mAamp->GetPlayerVideoSize(width, height);
36  m_channel->SendSelectionPacket(width, height);
37 }
38 
39 void WebVTTSubtecParser::updateTimestamp(unsigned long long positionMs)
40 {
41  AAMPLOG_INFO("positionMs %lld", positionMs);
42  m_channel->SendTimestampPacket(positionMs);
43 }
44 
45 void WebVTTSubtecParser::reset()
46 {
47  m_channel->SendMutePacket();
48  m_channel->SendResetChannelPacket();
49 }
50 
51 bool WebVTTSubtecParser::init(double startPosSeconds, unsigned long long basePTS)
52 {
53  AAMPLOG_INFO("startPos %f basePTS %lld", startPosSeconds, basePTS);
54 
55  m_channel->SendTimestampPacket(static_cast<uint64_t>(startPosSeconds*1000.0));
56 
58 
59  return true;
60 }
61 
62 bool WebVTTSubtecParser::processData(char* buffer, size_t bufferLen, double position, double duration)
63 {
64  std::string str(const_cast<const char*>(buffer), bufferLen);
65  std::vector<uint8_t> data(str.begin(), str.end());
66 
67  m_channel->SendDataPacket(std::move(data), 0);
68 
69  return true;
70 }
71 
72 void WebVTTSubtecParser::mute(bool mute)
73 {
74  if (mute)
75  m_channel->SendMutePacket();
76  else
77  m_channel->SendUnmutePacket();
78 }
79 
80 void WebVTTSubtecParser::pause(bool pause)
81 {
82  if (pause)
83  m_channel->SendPausePacket();
84  else
85  m_channel->SendResumePacket();
86 }
87 
88 
89 void WebVTTSubtecParser::setTextStyle(const std::string &options)
90 {
91  TextStyleAttributes textStyleAttributes(mLogObj);
92  uint32_t attributesMask = 0;
93  attributesType attributesValues = {0};
94 
95  int ccType = 0; /* Value not used by WebVTT */
96 
97  if (!textStyleAttributes.getAttributes(options, attributesValues, attributesMask))
98  {
99  if (attributesMask)
100  {
101  m_channel->SendCCSetAttributePacket(ccType, attributesMask, attributesValues);
102  }
103  }
104 }
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
TextStyleAttributes
Definition: TextStyleAttributes.h:34
SubtitleMimeType
SubtitleMimeType
Subtitle data types.
Definition: subtitleParser.h:37
attributesType
std::array< uint32_t, 14 > attributesType
Definition: SubtecAttribute.hpp:30
PrivateInstanceAAMP::GetPlayerVideoSize
void GetPlayerVideoSize(int &w, int &h)
Get player video size.
Definition: priv_aamp.cpp:8198
PrivateInstanceAAMP
Class representing the AAMP player's private instance, which is not exposed to outside world.
Definition: priv_aamp.h:640
TextStyleAttributes.h
This file provides class and other definition related to subtitle text attributes.
eMEDIATYPE_SUBTITLE
@ eMEDIATYPE_SUBTITLE
Definition: AampMediaType.h:41
PrivateInstanceAAMP::ResumeTrackDownloads
void ResumeTrackDownloads(MediaType type)
Resume downloads for a track. Called from StreamSink to control flow.
Definition: priv_aamp.cpp:3202
SubtitleParser
Subtitle parser class.
Definition: subtitleParser.h:52