RDK Documentation (Open Sourced RDK Components)
SubtecFactory.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 #include <string>
21 
22 #include "WebvttSubtecDevParser.hpp"
23 #include "WebVttSubtecParser.hpp"
24 #include "TtmlSubtecParser.hpp"
25 #include "subtitleParser.h" //required for gpGlobalConfig also
26 
27 namespace
28 {
29  template<typename T, typename ...Args>
30  std::unique_ptr<T> subtec_make_unique(Args&& ...args)
31  {
32  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
33  }
34 }
35 
37 {
38 public:
39  static std::unique_ptr<SubtitleParser> createSubtitleParser(AampLogManager *mLogObj, PrivateInstanceAAMP *aamp, std::string mimeType)
40  {
41  SubtitleMimeType type = eSUB_TYPE_UNKNOWN;
42 
43  AAMPLOG_INFO("createSubtitleParser: mimeType %s\n", mimeType.c_str());
44 
45  if (!mimeType.compare("text/vtt"))
46  type = eSUB_TYPE_WEBVTT;
47  else if (!mimeType.compare("application/ttml+xml") ||
48  !mimeType.compare("application/mp4"))
49  type = eSUB_TYPE_TTML;
50 
51  return createSubtitleParser(mLogObj, aamp, type);
52  }
53 
54  static std::unique_ptr<SubtitleParser> createSubtitleParser(AampLogManager *mLogObj, PrivateInstanceAAMP *aamp, SubtitleMimeType mimeType)
55  {
56  AAMPLOG_INFO("createSubtitleParser: mimeType: %d\n", mimeType);
57  std::unique_ptr<SubtitleParser> empty;
58 
59  try {
60  switch (mimeType)
61  {
62  case eSUB_TYPE_WEBVTT:
63  // If JavaScript cue listeners have been registered use WebVTTParser,
64  // otherwise use subtec
65  if (!aamp->WebVTTCueListenersRegistered())
67  return subtec_make_unique<WebVTTSubtecParser>(mLogObj, aamp, mimeType);
68  else
69  return subtec_make_unique<WebVTTSubtecDevParser>(mLogObj, aamp, mimeType);
70  else
71  return subtec_make_unique<WebVTTParser>(mLogObj, aamp, mimeType);
72  case eSUB_TYPE_TTML:
73  return subtec_make_unique<TtmlSubtecParser>(mLogObj, aamp, mimeType);
74  default:
75  AAMPLOG_WARN("Unknown subtitle parser type %d, returning empty", mimeType);
76  break;
77  }
78  } catch (const std::runtime_error &e) {
79  AAMPLOG_WARN("%s", e.what());
80  AAMPLOG_WARN(" Failed on SubtitleParser construction - returning empty");
81  }
82 
83  return empty;
84  }
85 };
subtitleParser.h
This file provides interfaces for a subtitle parser in AAMP.
eAAMPConfig_WebVTTNative
@ eAAMPConfig_WebVTTNative
Definition: AampConfig.h:172
ISCONFIGSET
#define ISCONFIGSET(x)
Definition: AampConfig.h:84
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
PrivateInstanceAAMP::WebVTTCueListenersRegistered
bool WebVTTCueListenersRegistered(void)
To check if JavaScript cue listeners are registered.
Definition: priv_aamp.cpp:9211
SubtitleMimeType
SubtitleMimeType
Subtitle data types.
Definition: subtitleParser.h:37
PrivateInstanceAAMP
Class representing the AAMP player's private instance, which is not exposed to outside world.
Definition: priv_aamp.h:640
SubtecFactory
Definition: SubtecFactory.hpp:36