RDK Documentation (Open Sourced RDK Components)
videoin_shim.cpp
Go to the documentation of this file.
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 2021 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 /**
21  * @file videoin_shim.cpp
22  * @brief shim for dispatching UVE HDMI input playback
23  */
24 #include "videoin_shim.h"
25 #include "priv_aamp.h"
26 #include <stdlib.h>
27 #include <string.h>
28 #include <pthread.h>
29 #include <signal.h>
30 #include <assert.h>
31 #include "AampUtils.h"
32 
33 
34 #ifdef USE_CPP_THUNDER_PLUGIN_ACCESS
35 
36 #include <core/core.h>
37 #include <websocket/websocket.h>
38 
39 using namespace std;
40 using namespace WPEFramework;
41 
42 #define RDKSHELL_CALLSIGN "org.rdk.RDKShell.1"
43 
44 #define UHD_4K_WIDTH 3840
45 #define UHD_4K_HEIGHT 2160
46 #endif
47 
48 
49 /**
50  * @brief Initialize a newly created object.
51  */
53 {
54  AAMPLOG_WARN("%s Function not implemented",mName.c_str());
55  return eAAMPSTATUS_OK;
56 }
57 
58 
59 AAMPStatusType StreamAbstractionAAMP_VIDEOIN::InitHelper(TuneType tuneType)
60 {
62 #ifdef USE_CPP_THUNDER_PLUGIN_ACCESS
63  RegisterAllEvents();
64 #endif
65  return retval;
66 }
67 
68 /**
69  * @brief StreamAbstractionAAMP_VIDEOIN Constructor
70  */
71 StreamAbstractionAAMP_VIDEOIN::StreamAbstractionAAMP_VIDEOIN( const std::string name, const std::string callSign, AampLogManager *logObj, class PrivateInstanceAAMP *aamp,double seek_pos, float rate)
72  : mName(name),
73  mRegisteredEvents(),
74  StreamAbstractionAAMP(logObj, aamp),
75  mTuned(false),
76  videoInputPort(-1)
77 #ifdef USE_CPP_THUNDER_PLUGIN_ACCESS
78  ,thunderAccessObj(callSign, logObj),
79  thunderRDKShellObj(RDKSHELL_CALLSIGN, logObj)
80 #endif
81 {
82 #ifdef USE_CPP_THUNDER_PLUGIN_ACCESS
83  AAMPLOG_WARN("%s Constructor",mName.c_str());
84  thunderAccessObj.ActivatePlugin();
85 #endif
86 }
87 
88 /**
89  * @brief StreamAbstractionAAMP_VIDEOIN Destructor
90  */
92 {
93  AAMPLOG_WARN("%s destructor",mName.c_str());
94  for (auto const& evtName : mRegisteredEvents) {
95 #ifdef USE_CPP_THUNDER_PLUGIN_ACCESS
96  thunderAccessObj.UnSubscribeEvent(_T(evtName));
97 #endif
98  }
99  mRegisteredEvents.clear();
100 }
101 
102 /**
103  * @brief Starts streaming.
104  */
106 {
107  AAMPLOG_WARN("%s Function not implemented",mName.c_str());
108 }
109 
110 /**
111  * @brief calls start on video in specified by port and method name
112  */
113 void StreamAbstractionAAMP_VIDEOIN::StartHelper(int port, const std::string & methodName)
114 {
115  AAMPLOG_WARN("%s method:%s port:%d",mName.c_str(),methodName.c_str(),port);
116 
117  videoInputPort = port;
118 #ifdef USE_CPP_THUNDER_PLUGIN_ACCESS
119  JsonObject param;
120  JsonObject result;
121  param["portId"] = videoInputPort;
122  thunderAccessObj.InvokeJSONRPC(methodName, param, result);
123 #endif
124 }
125 
126 /**
127  * @brief Stops streaming.
128  */
129 void StreamAbstractionAAMP_VIDEOIN::StopHelper(const std::string & methodName)
130 {
131  if( videoInputPort>=0 )
132  {
133  AAMPLOG_WARN("%s method:%s",mName.c_str(),methodName.c_str());
134 
135 #ifdef USE_CPP_THUNDER_PLUGIN_ACCESS
136  JsonObject param;
137  JsonObject result;
138  thunderAccessObj.InvokeJSONRPC(methodName, param, result);
139 #endif
140 
141  videoInputPort = -1;
142  }
143 }
144 
145 /**
146  * @brief Stops streaming.
147  */
148 void StreamAbstractionAAMP_VIDEOIN::Stop(bool clearChannelData)
149 {
150  AAMPLOG_WARN("%s Function not implemented",mName.c_str());
151 }
152 
153 
154 bool StreamAbstractionAAMP_VIDEOIN::GetScreenResolution(int & screenWidth, int & screenHeight)
155 {
156 #ifndef USE_CPP_THUNDER_PLUGIN_ACCESS
157  return false;
158 #else
159  JsonObject param;
160  JsonObject result;
161  bool bRetVal = false;
162 
163  if( thunderRDKShellObj.InvokeJSONRPC("getScreenResolution", param, result) )
164  {
165  screenWidth = result["w"].Number();
166  screenHeight = result["h"].Number();
167  AAMPLOG_INFO("%s screenWidth:%d screenHeight:%d ",mName.c_str(),screenWidth, screenHeight);
168  bRetVal = true;
169  }
170  return bRetVal;
171 #endif
172 }
173 
174 /**
175  * @brief SetVideoRectangle sets the position coordinates (x,y) & size (w,h)
176  */
177 void StreamAbstractionAAMP_VIDEOIN::SetVideoRectangle(int x, int y, int w, int h)
178 {
179 #ifdef USE_CPP_THUNDER_PLUGIN_ACCESS
180  int screenWidth = 0;
181  int screenHeight = 0;
182  float width_ratio = 1.0, height_ratio = 1.0;
183  if(GetScreenResolution(screenWidth,screenHeight))
184  {
185  /*Temporary fix as hdmiin/composite in expects the scaling in 4k space*/
186  if((0 != screenWidth) && (0 != screenHeight))
187  {
188  width_ratio = UHD_4K_WIDTH / screenWidth;
189  height_ratio = UHD_4K_HEIGHT / screenHeight;
190  }
191  }
192 
193  JsonObject param;
194  JsonObject result;
195  param["x"] = (int) (x * width_ratio);
196  param["y"] = (int) (y * height_ratio);
197  param["w"] = (int) (w * width_ratio);
198  param["h"] = (int) (h * height_ratio);
199  AAMPLOG_WARN("%s x:%d y:%d w:%d h:%d w-ratio:%f h-ratio:%f",mName.c_str(),x,y,w,h,width_ratio,height_ratio);
200  thunderAccessObj.InvokeJSONRPC("setVideoRectangle", param, result);
201 #endif
202 }
203 
204 /**
205  * @brief Stub implementation
206  */
208 { // STUB
209  AAMPLOG_WARN("%s Function not implemented",mName.c_str());
210 }
211 
212 /**
213  * @brief Get output format of stream.
214  *
215  */
216 void StreamAbstractionAAMP_VIDEOIN::GetStreamFormat(StreamOutputFormat &primaryOutputFormat, StreamOutputFormat &audioOutputFormat, StreamOutputFormat &auxAudioOutputFormat, StreamOutputFormat &subtitleOutputFormat)
217 { // STUB
218  AAMPLOG_WARN("%s ",mName.c_str());
219  primaryOutputFormat = FORMAT_INVALID;
220  audioOutputFormat = FORMAT_INVALID;
221  //auxAudioOutputFormat = FORMAT_INVALID;
222 }
223 
224 /**
225  * @brief Return MediaTrack of requested type
226  */
228 { // STUB
229  AAMPLOG_WARN("%s ",mName.c_str());
230  return NULL;
231 }
232 
233 /**
234  * @brief Get current stream position.
235  */
237 { // STUB
238  AAMPLOG_WARN("%s ",mName.c_str());
239  return 0.0;
240 }
241 
242 /**
243  * @brief Get stream information of a profile from subclass.
244  */
246 { // STUB
247  AAMPLOG_WARN("%s ",mName.c_str());
248  return NULL;
249 }
250 
251 /**
252  * @brief Get PTS of first sample.
253  */
255 { // STUB
256  AAMPLOG_WARN("%s ",mName.c_str());
257  return 0.0;
258 }
259 
260 /**
261  * @brief Get Start time PTS of first sample.
262  */
264 { // STUB
265  AAMPLOG_WARN("%s ",mName.c_str());
266  return 0.0;
267 }
268 
269 /**
270  * @brief Get the Duration of buffer
271  */
273 { // STUB
274  AAMPLOG_WARN("%s ",mName.c_str());
275  return -1.0;
276 }
277 
278 /**
279  * @brief Check if Initial caching is supported
280  */
282 {
283  AAMPLOG_WARN("%s ",mName.c_str());
284  return false;
285 }
286 
287 /**
288  * @brief Get index of profile corresponds to bandwidth
289  */
291 {
292  AAMPLOG_WARN("%s ",mName.c_str());
293  return 0;
294 }
295 
296 /**
297  * @brief To get the available video bitrates.
298  */
300 { // STUB
301  AAMPLOG_WARN("%s ",mName.c_str());
302  return std::vector<long>();
303 }
304 
305 /**
306  * @brief Gets Max Bitrate avialable for current playback.
307  */
309 { // STUB
310  AAMPLOG_WARN("%s ",mName.c_str());
311  return 0;
312 }
313 
314 /**
315  * @brief To get the available audio bitrates.
316  */
318 { // STUB
319  AAMPLOG_WARN("%s ",mName.c_str());
320  return std::vector<long>();
321 }
322 
323 /**
324  * @brief Stops injecting fragments to StreamSink.
325  */
327 { // STUB - discontinuity related
328  AAMPLOG_WARN("%s ",mName.c_str());
329 }
330 
331 /**
332  * @brief Start injecting fragments to StreamSink.
333  */
335 { // STUB - discontinuity related
336  AAMPLOG_WARN("%s ",mName.c_str());
337 }
338 
339 
340 
341 #ifdef USE_CPP_THUNDER_PLUGIN_ACCESS
342 
343 /**
344  * @brief Registers Event to input plugin and to mRegisteredEvents list for later use.
345  */
346 void StreamAbstractionAAMP_VIDEOIN::RegisterEvent (string eventName, std::function<void(const WPEFramework::Core::JSON::VariantContainer&)> functionHandler)
347 {
348  bool bSubscribed;
349  bSubscribed = thunderAccessObj.SubscribeEvent(_T(eventName), functionHandler);
350  if(bSubscribed)
351  {
352  mRegisteredEvents.push_back(eventName);
353  }
354 }
355 
356 /**
357  * @brief Registers all Events to input plugin
358  */
359 void StreamAbstractionAAMP_VIDEOIN::RegisterAllEvents ()
360 {
361  std::function<void(const WPEFramework::Core::JSON::VariantContainer&)> inputStatusChangedMethod = std::bind(&StreamAbstractionAAMP_VIDEOIN::OnInputStatusChanged, this, std::placeholders::_1);
362 
363  RegisterEvent("onInputStatusChanged",inputStatusChangedMethod);
364 
365  std::function<void(const WPEFramework::Core::JSON::VariantContainer&)> signalChangedMethod = std::bind(&StreamAbstractionAAMP_VIDEOIN::OnSignalChanged, this, std::placeholders::_1);
366 
367  RegisterEvent("onSignalChanged",signalChangedMethod);
368 }
369 
370 
371 /**
372  * @brief Gets onSignalChanged and translates into aamp events
373  */
374 void StreamAbstractionAAMP_VIDEOIN::OnInputStatusChanged(const JsonObject& parameters)
375 {
376  std::string message;
377  parameters.ToString(message);
378  AAMPLOG_WARN("%s",message.c_str());
379 
380  std::string strStatus = parameters["status"].String();
381 
382  if(0 == strStatus.compare("started"))
383  {
384  if(!mTuned){
385  aamp->SendTunedEvent(false);
386  mTuned = true;
387  aamp->LogFirstFrame();
389  }
391  }
392  else if(0 == strStatus.compare("stopped"))
393  {
395  }
396 }
397 
398 /**
399  * @brief Gets onSignalChanged and translates into aamp events
400  */
401 void StreamAbstractionAAMP_VIDEOIN::OnSignalChanged (const JsonObject& parameters)
402 {
403  std::string message;
404  parameters.ToString(message);
405  AAMPLOG_WARN("%s",message.c_str());
406 
407  std::string strReason;
408  std::string strStatus = parameters["signalStatus"].String();
409 
410  if(0 == strStatus.compare("noSignal"))
411  {
412  strReason = "NO_SIGNAL";
413  }
414  else if (0 == strStatus.compare("unstableSignal"))
415  {
416  strReason = "UNSTABLE_SIGNAL";
417  }
418  else if (0 == strStatus.compare("notSupportedSignal"))
419  {
420  strReason = "NOT_SUPPORTED_SIGNAL";
421  }
422  else if (0 == strStatus.compare("stableSignal"))
423  {
424  // Only Generate after started event, this can come after temp loss of signal.
425  if(mTuned){
427  }
428  }
429 
430  if(!strReason.empty())
431  {
432  AAMPLOG_WARN("GENERATING BLOCKED EVNET :%s",strReason.c_str());
433  aamp->SendBlockedEvent(strReason);
434  }
435 }
436 #endif
437 
eSTATE_STOPPED
@ eSTATE_STOPPED
Definition: AampEvent.h:168
StreamAbstractionAAMP_VIDEOIN::Start
void Start() override
Starts streaming.
Definition: FakeHDMIIN.cpp:40
PrivateInstanceAAMP::SendTunedEvent
bool SendTunedEvent(bool isSynchronous=true)
Send tuned event to listeners if required.
Definition: priv_aamp.cpp:7826
StreamOutputFormat
StreamOutputFormat
Media output format.
Definition: main_aamp.h:106
StreamInfo
Structure holding the information of a stream.
Definition: StreamAbstractionAAMP.h:69
StreamAbstractionAAMP_VIDEOIN::StreamAbstractionAAMP_VIDEOIN
StreamAbstractionAAMP_VIDEOIN(const std::string name, const std::string callSign, AampLogManager *logObj, class PrivateInstanceAAMP *aamp, double seekpos, float rate)
StreamAbstractionAAMP_VIDEOIN Constructor.
Definition: FakeHDMIIN.cpp:27
videoin_shim.h
shim for dispatching UVE Video input playback
PrivateInstanceAAMP::LogTuneComplete
void LogTuneComplete(void)
Notify tune end for profiling/logging.
Definition: priv_aamp.cpp:3045
TuneType
TuneType
Tune Typea.
Definition: priv_aamp.h:190
StreamAbstractionAAMP::aamp
PrivateInstanceAAMP * aamp
Definition: StreamAbstractionAAMP.h:727
FORMAT_INVALID
@ FORMAT_INVALID
Definition: main_aamp.h:108
StreamAbstractionAAMP_VIDEOIN::GetStreamInfo
StreamInfo * GetStreamInfo(int idx) override
Get stream information of a profile from subclass.
Definition: FakeHDMIIN.cpp:68
PrivateInstanceAAMP::SetState
void SetState(PrivAAMPState state)
Set player state.
Definition: priv_aamp.cpp:7731
StreamAbstractionAAMP_VIDEOIN::~StreamAbstractionAAMP_VIDEOIN
~StreamAbstractionAAMP_VIDEOIN()
StreamAbstractionAAMP_VIDEOIN Destructor.
Definition: FakeHDMIIN.cpp:32
StreamAbstractionAAMP_VIDEOIN::GetStartTimeOfFirstPTS
double GetStartTimeOfFirstPTS() override
Get Start time PTS of first sample.
Definition: FakeHDMIIN.cpp:50
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
StreamAbstractionAAMP_VIDEOIN::GetVideoBitrates
std::vector< long > GetVideoBitrates(void) override
To get the available video bitrates.
Definition: FakeHDMIIN.cpp:60
StreamAbstractionAAMP_VIDEOIN::GetAudioBitrates
std::vector< long > GetAudioBitrates(void) override
To get the available audio bitrates.
Definition: FakeHDMIIN.cpp:62
MediaTrack
Base Class for Media Track.
Definition: StreamAbstractionAAMP.h:159
StreamAbstractionAAMP
StreamAbstraction class of AAMP.
Definition: StreamAbstractionAAMP.h:577
StreamAbstractionAAMP_VIDEOIN::StartHelper
void StartHelper(int port, const std::string &methodName)
calls start on video in specified by port and method name
Definition: videoin_shim.cpp:113
StreamAbstractionAAMP_VIDEOIN::DumpProfiles
void DumpProfiles(void) override
Stub implementation.
Definition: FakeHDMIIN.cpp:36
StreamAbstractionAAMP_VIDEOIN::GetBufferedDuration
double GetBufferedDuration() override
Get the Duration of buffer.
Definition: FakeHDMIIN.cpp:54
TrackType
TrackType
Media Track Types.
Definition: StreamAbstractionAAMP.h:48
StreamAbstractionAAMP_VIDEOIN::SetVideoRectangle
void SetVideoRectangle(int x, int y, int w, int h) override
SetVideoRectangle sets the position coordinates (x,y) & size (w,h)
Definition: FakeHDMIIN.cpp:75
StreamAbstractionAAMP_VIDEOIN::Init
AAMPStatusType Init(TuneType tuneType) override
Initialize a newly created object.
Definition: FakeHDMIIN.cpp:38
eAAMPSTATUS_OK
@ eAAMPSTATUS_OK
Definition: priv_aamp.h:207
StreamAbstractionAAMP_VIDEOIN::Stop
void Stop(bool clearChannelData) override
Stops streaming.
Definition: FakeHDMIIN.cpp:42
priv_aamp.h
Private functions and types used internally by AAMP.
StreamAbstractionAAMP_VIDEOIN::StopInjection
void StopInjection(void) override
Stops injecting fragments to StreamSink.
Definition: FakeHDMIIN.cpp:64
PrivateInstanceAAMP::SendBlockedEvent
void SendBlockedEvent(const std::string &reason)
Generate Blocked event based on args passed.
Definition: priv_aamp.cpp:8808
StreamAbstractionAAMP_VIDEOIN::GetMaxBitrate
long GetMaxBitrate(void) override
Gets Max Bitrate avialable for current playback.
Definition: FakeHDMIIN.cpp:70
StreamAbstractionAAMP_VIDEOIN::StopHelper
void StopHelper(const std::string &methodName)
Stops streaming.
Definition: videoin_shim.cpp:129
StreamAbstractionAAMP_VIDEOIN::GetMediaTrack
MediaTrack * GetMediaTrack(TrackType type) override
Return MediaTrack of requested type.
Definition: FakeHDMIIN.cpp:52
PrivateInstanceAAMP
Class representing the AAMP player's private instance, which is not exposed to outside world.
Definition: priv_aamp.h:640
StreamAbstractionAAMP_VIDEOIN::StartInjection
void StartInjection(void) override
Start injecting fragments to StreamSink.
Definition: FakeHDMIIN.cpp:66
AAMPStatusType
AAMPStatusType
AAMP Function return values.
Definition: priv_aamp.h:205
StreamAbstractionAAMP_VIDEOIN::GetFirstPTS
double GetFirstPTS() override
Get PTS of first sample.
Definition: FakeHDMIIN.cpp:48
StreamAbstractionAAMP_VIDEOIN::IsInitialCachingSupported
bool IsInitialCachingSupported() override
Check if Initial caching is supported.
Definition: FakeHDMIIN.cpp:56
StreamAbstractionAAMP_VIDEOIN::GetStreamPosition
double GetStreamPosition() override
Get current stream position.
Definition: FakeHDMIIN.cpp:46
PrivateInstanceAAMP::LogFirstFrame
void LogFirstFrame(void)
Notifies profiler that first frame is presented.
Definition: priv_aamp.cpp:3107
StreamAbstractionAAMP_VIDEOIN::GetBWIndex
int GetBWIndex(long bitrate) override
Get index of profile corresponds to bandwidth.
Definition: FakeHDMIIN.cpp:58
eSTATE_PLAYING
@ eSTATE_PLAYING
Definition: AampEvent.h:166
StreamAbstractionAAMP_VIDEOIN::GetStreamFormat
void GetStreamFormat(StreamOutputFormat &primaryOutputFormat, StreamOutputFormat &audioOutputFormat, StreamOutputFormat &auxOutputFormat, StreamOutputFormat &subtitleOutputFormat) override
Get output format of stream.
Definition: FakeHDMIIN.cpp:44