25 #include "AampUtils.h"
34 #ifdef USE_CPP_THUNDER_PLUGIN_ACCESS
35 #include <core/core.h>
36 #include <websocket/websocket.h>
39 using namespace WPEFramework;
41 #define RMF_PLUGIN_CALLSIGN "org.rdk.MediaEngineRMF.1"
42 #define APP_ID "MainPlayer"
44 #define RDKSHELL_CALLSIGN "org.rdk.RDKShell.1"
46 RMFGlobalSettings gRMFSettings;
48 void StreamAbstractionAAMP_RMF::onPlayerStatusHandler(
const JsonObject& parameters) {
50 parameters.ToString(message);
52 JsonObject playerData = parameters[APP_ID].Object();
53 AAMPLOG_WARN(
"[RMF_SHIM]Received event : message : %s ", message.c_str());
56 std::string title = parameters[
"title"].String();
58 if(0 == title.compare(
"report first video frame"))
61 aamp->SendTunedEvent(
false);
63 aamp->LogFirstFrame();
64 aamp->LogTuneComplete();
70 void StreamAbstractionAAMP_RMF::onPlayerErrorHandler(
const JsonObject& parameters) {
72 parameters.ToString(message);
74 AAMPLOG_WARN(
"[RMF_SHIM]Received error : message : %s ", message.c_str());
76 std::string error_message = parameters[
"source"].String() +
": " + parameters[
"title"].String() +
"- " + parameters[
"message"].String();
87 AAMPLOG_INFO(
"[RMF_SHIM]Inside" );
92 aamp->SetContentType(
"RMF");
94 thunderAccessObj.ActivatePlugin();
97 param[
"source_type"] =
"qam";
98 if(
false == thunderAccessObj.InvokeJSONRPC(
"initialize", param, result))
100 AAMPLOG_ERR(
"Failed to initialize %s plugin.\n", RMF_PLUGIN_CALLSIGN);
112 thunderAccessObj(RMF_PLUGIN_CALLSIGN, logObj),
113 thunderRDKShellObj(RDKSHELL_CALLSIGN,logObj)
120 StreamAbstractionAAMP_RMF::~StreamAbstractionAAMP_RMF()
122 AAMPLOG_INFO(
"[RMF_SHIM]StreamAbstractionAAMP_RMF Destructor called !! ");
128 void StreamAbstractionAAMP_RMF::Start(
void)
130 std::string url = aamp->GetManifestUrl();
132 AAMPLOG_INFO(
"[RMF_SHIM] url : %s ", url.c_str());
137 std::function<void(
const WPEFramework::Core::JSON::VariantContainer&)> eventHandler = std::bind(&StreamAbstractionAAMP_RMF::onPlayerStatusHandler,
this, std::placeholders::_1);
138 std::function<void(
const WPEFramework::Core::JSON::VariantContainer&)> errorHandler = std::bind(&StreamAbstractionAAMP_RMF::onPlayerErrorHandler,
this, std::placeholders::_1);
140 if(
true != thunderAccessObj.SubscribeEvent(_T(
"onStatusChanged"), eventHandler))
142 AAMPLOG_ERR(
"Failed to register for onStatusChanged notification from RMF plugin.\n");
144 if(
true != thunderAccessObj.SubscribeEvent(_T(
"onError"), errorHandler))
146 AAMPLOG_ERR(
"Failed to register for onError notification from RMF plugin.\n");
149 JsonObject playParam;
150 playParam[
"source_type"] =
"qam";
151 playParam[
"identifier"] = url;
152 if(
true != thunderAccessObj.InvokeJSONRPC(
"play", playParam, result))
154 AAMPLOG_ERR(
"Failed to play RMF URL %s.\n", url.c_str());
161 void StreamAbstractionAAMP_RMF::Stop(
bool clearChannelData)
167 if(!clearChannelData)
172 if(
true != thunderAccessObj.InvokeJSONRPC(
"stop", param, result))
174 AAMPLOG_ERR(
"Failed to stop RMF playback. URL: %s.\n", aamp->GetManifestUrl().c_str());
176 thunderAccessObj.UnSubscribeEvent(_T(
"onStatusChanged"));
177 thunderAccessObj.UnSubscribeEvent(_T(
"onError"));
181 bool StreamAbstractionAAMP_RMF::GetScreenResolution(
int & screenWidth,
int & screenHeight)
185 bool bRetVal =
false;
187 if( thunderRDKShellObj.InvokeJSONRPC(
"getScreenResolution", param, result) )
189 screenWidth = result[
"w"].Number();
190 screenHeight = result[
"h"].Number();
191 AAMPLOG_INFO(
"StreamAbstractionAAMP_RMF: screenWidth:%d screenHeight:%d ",screenWidth, screenHeight);
200 void StreamAbstractionAAMP_RMF::SetVideoRectangle(
int x,
int y,
int w,
int h)
212 if(
true != thunderAccessObj.InvokeJSONRPC(
"setVideoRectangle", param, result))
214 AAMPLOG_ERR(
"Failed to set video rectangle for URL: %s.\n", aamp->GetManifestUrl().c_str());
221 std::vector<AudioTrackInfo> & StreamAbstractionAAMP_RMF::GetAvailableAudioTracks(
bool allTrack)
223 if (mAudioTrackIndex.empty())
232 int StreamAbstractionAAMP_RMF::GetAudioTrack()
235 if (mAudioTrackIndex.empty())
238 if (!mAudioTrackIndex.empty())
240 for (
auto it = mAudioTracks.begin(); it != mAudioTracks.end(); it++)
242 if (it->index == mAudioTrackIndex)
244 index = std::distance(mAudioTracks.begin(), it);
254 bool StreamAbstractionAAMP_RMF::GetCurrentAudioTrack(
AudioTrackInfo &audioTrack)
258 if (mAudioTrackIndex.empty())
261 if (!mAudioTrackIndex.empty())
263 for (
auto it = mAudioTracks.begin(); it != mAudioTracks.end(); it++)
265 if (it->index == mAudioTrackIndex)
278 void StreamAbstractionAAMP_RMF::SetPreferredAudioLanguages()
280 JsonObject properties;
281 bool modifiedLang =
false;
282 bool modifiedRend =
false;
284 if((0 != aamp->preferredLanguagesString.length()) && (aamp->preferredLanguagesString != gRMFSettings.preferredLanguages)){
285 properties[
"preferredAudioLanguage"] = aamp->preferredLanguagesString.c_str();
288 if(modifiedLang || modifiedRend)
290 bool rpcResult =
false;
294 param[
"properties"] = properties;
303 void StreamAbstractionAAMP_RMF::SetAudioTrackByLanguage(
const char* lang)
307 JsonObject properties;
312 if(mAudioTrackIndex.empty())
315 std::vector<AudioTrackInfo>::iterator itr;
316 for(itr = mAudioTracks.begin(); itr != mAudioTracks.end(); itr++)
318 if(0 == strcmp(lang, itr->language.c_str()))
320 index = std::distance(mAudioTracks.begin(), itr);
327 SetAudioTrack(index);
335 void StreamAbstractionAAMP_RMF::GetAudioTracks()
345 int StreamAbstractionAAMP_RMF::GetAudioTrackInternal()
354 void StreamAbstractionAAMP_RMF::SetAudioTrack(
int trackId)
362 std::vector<TextTrackInfo> & StreamAbstractionAAMP_RMF::GetAvailableTextTracks(
bool all)
371 void StreamAbstractionAAMP_RMF::GetTextTracks()
380 void StreamAbstractionAAMP_RMF::DisableContentRestrictions(
long grace,
long time,
bool eventChange)
388 void StreamAbstractionAAMP_RMF::EnableContentRestrictions()
396 void StreamAbstractionAAMP_RMF::DumpProfiles(
void)
422 double StreamAbstractionAAMP_RMF::GetStreamPosition()
430 StreamInfo* StreamAbstractionAAMP_RMF::GetStreamInfo(
int idx)
438 double StreamAbstractionAAMP_RMF::GetFirstPTS()
446 double StreamAbstractionAAMP_RMF::GetStartTimeOfFirstPTS()
454 double StreamAbstractionAAMP_RMF::GetBufferedDuration()
462 bool StreamAbstractionAAMP_RMF::IsInitialCachingSupported()
470 int StreamAbstractionAAMP_RMF::GetBWIndex(
long bitrate)
478 std::vector<long> StreamAbstractionAAMP_RMF::GetVideoBitrates(
void)
480 return std::vector<long>();
486 long StreamAbstractionAAMP_RMF::GetMaxBitrate()
494 std::vector<long> StreamAbstractionAAMP_RMF::GetAudioBitrates(
void)
496 return std::vector<long>();
502 std::vector<StreamInfo*> StreamAbstractionAAMP_RMF::GetAvailableVideoTracks(
void)
504 return std::vector<StreamInfo*>();
510 std::vector<StreamInfo*> StreamAbstractionAAMP_RMF::GetAvailableThumbnailTracks(
void)
512 return std::vector<StreamInfo*>();
518 bool StreamAbstractionAAMP_RMF::SetThumbnailTrack(
int thumbnailIndex)
520 (void) thumbnailIndex;
527 std::vector<ThumbnailData> StreamAbstractionAAMP_RMF::GetThumbnailRangeData(
double start,
double end, std::string *baseurl,
int *raw_w,
int *raw_h,
int *width,
int *height)
529 return std::vector<ThumbnailData>();
535 void StreamAbstractionAAMP_RMF::StopInjection(
void)
542 void StreamAbstractionAAMP_RMF::StartInjection(
void)
546 #endif //USE_CPP_THUNDER_PLUGIN_ACCESS