30 extern void tsdemuxer_InduceRollover(
bool enable );
32 std::map<string,string> PlaybackCommand::playbackCommands = std::map<string,string>();
33 std::vector<std::string> PlaybackCommand::commands(0);
41 bool eventChange =
false;
42 char lang[MAX_LANGUAGE_TAG_LENGTH];
47 long unlockSeconds = 0;
54 while( *cmd==
' ' ) cmd++;
58 printf(
"skipping comment\n" );
68 else if (strcmp(cmd,
"help") == 0)
72 else if( strcmp(cmd,
"rollover")==0 )
74 printf(
"enabling artificial pts rollover (10s after next tune)\n" );
75 tsdemuxer_InduceRollover(
true );
77 else if (strcmp(cmd,
"list") == 0)
79 mVirtualChannelMap.showList();
81 else if( strcmp(cmd,
"autoplay") == 0 )
83 mAampcli.mbAutoPlay = !mAampcli.mbAutoPlay;
84 printf(
"autoplay = %s\n", mAampcli.mbAutoPlay?
"true":
"false" );
86 else if( strcmp(cmd,
"new") == 0 )
88 mAampcli.newPlayerInstance();
90 else if( sscanf(cmd,
"sleep %d", &ms ) == 1 )
94 printf(
"sleeping for %f seconds\n", ms/1000.0 );
96 printf(
"sleep complete\n" );
99 else if( sscanf(cmd,
"select %d", &playerIndex ) == 1 )
102 playerInstanceAamp = mAampcli.mPlayerInstances.at(playerIndex);
103 if (playerInstanceAamp->
aamp)
105 printf(
"selected player %d (at %p)\n", playerInstanceAamp->
aamp->mPlayerId, playerInstanceAamp);
106 mAampcli.mSingleton=playerInstanceAamp;
110 printf(
"error - player exists but is not valid/ready, playerInstanceAamp->aamp is not a valid ptr\n");
112 }
catch (std::out_of_range
const& exc) {
113 if (mAampcli.mPlayerInstances.size() == 0)
115 printf(
"error - no player instances\n" );
119 printf(
"valid range = 0..%lu\n", mAampcli.mPlayerInstances.size()-1 );
123 else if (strcmp(cmd,
"select") == 0)
125 printf(
"player instances:\n" );
127 for(
auto playerInstance : mAampcli.mPlayerInstances )
129 printf(
"\t%d", playerIndex++ );
130 if( playerInstance == playerInstanceAamp )
132 printf(
" (selected)");
137 else if( strcmp(cmd,
"detach") == 0 )
139 playerInstanceAamp->
detach();
144 if (memcmp(cmd,
"live", 4) == 0)
150 playerInstanceAamp->
Tune(cmd,mAampcli.mbAutoPlay);
154 else if( memcmp(cmd,
"next", 4) == 0 )
159 printf(
"[AAMPCLI] next %d: %s\n", pNextChannel->channelNumber, pNextChannel->name.c_str());
160 mVirtualChannelMap.tuneToChannel( *pNextChannel, playerInstanceAamp);
164 printf(
"[AAMPCLI] can not fetch 'next' channel, empty virtual channel map\n");
167 else if( memcmp(cmd,
"prev", 4) == 0 )
172 printf(
"[AAMPCLI] next %d: %s\n", pPrevChannel->channelNumber, pPrevChannel->name.c_str());
173 mVirtualChannelMap.tuneToChannel( *pPrevChannel, playerInstanceAamp);
177 printf(
"[AAMPCLI] can not fetch 'prev' channel, empty virtual channel map\n");
182 int channelNumber = atoi(cmd);
185 if (pChannelInfo != NULL)
187 printf(
"[AAMPCLI] channel number: %d\n", channelNumber);
188 mVirtualChannelMap.tuneToChannel( *pChannelInfo, playerInstanceAamp);
192 printf(
"[AAMPCLI] channel number: %d was not found\n", channelNumber);
195 else if (sscanf(cmd,
"seek %lf %d", &seconds, &keepPaused) >= 1)
197 bool seekWhilePaused = (keepPaused==1);
199 playerInstanceAamp->
Seek(seconds, (keepPaused==1) );
203 else if (strcmp(cmd,
"sf") == 0)
205 playerInstanceAamp->
SetRate((
float)0.5);
207 else if (sscanf(cmd,
"ff%d", &rate) == 1)
209 playerInstanceAamp->
SetRate((
float)rate);
211 else if (strcmp(cmd,
"play") == 0)
213 playerInstanceAamp->
SetRate(1);
215 else if (sscanf(cmd,
"pause%lf", &seconds) == 1)
217 playerInstanceAamp->
PauseAt(seconds);
219 else if (strcmp(cmd,
"pause") == 0)
221 playerInstanceAamp->
SetRate(0);
223 else if (sscanf(cmd,
"rw%d", &rate) == 1)
225 playerInstanceAamp->
SetRate((
float)(-rate));
227 else if (sscanf(cmd,
"bps %d", &rate) == 1)
229 printf(
"[AAMPCLI] Set video bitrate %d.\n", rate);
232 else if (strcmp(cmd,
"flush") == 0)
234 playerInstanceAamp->
aamp->mStreamSink->
Flush();
236 else if (strcmp(cmd,
"stop") == 0)
238 playerInstanceAamp->
Stop();
239 tsdemuxer_InduceRollover(
false);
241 else if (strcmp(cmd,
"underflow") == 0)
245 else if (strcmp(cmd,
"retune") == 0)
249 else if (strcmp(cmd,
"status") == 0)
253 else if (strcmp(cmd,
"live") == 0)
257 else if (strcmp(cmd,
"exit") == 0)
259 playerInstanceAamp = NULL;
260 for(
auto playerInstance : mAampcli.mPlayerInstances )
262 playerInstance->
Stop();
263 SAFE_DELETE( playerInstance );
268 else if (memcmp(cmd,
"rect", 4) == 0)
271 if (sscanf(cmd,
"rect %d %d %d %d", &x, &y, &w, &h) == 4)
276 else if (memcmp(cmd,
"zoom", 4) == 0)
279 if (sscanf(cmd,
"zoom %d", &zoom) == 1)
283 printf(
"[AAMPCLI] Set zoom to full\n");
288 printf(
"[AAMPCLI] Set zoom to none\n");
293 else if( sscanf(cmd,
"sap %s",lang ) )
295 size_t len = strlen(lang);
296 printf(
"[AAMPCLI] aamp cli sap called for language %s\n",lang);
306 else if( strcmp(cmd,
"getplaybackrate") == 0 )
308 printf(
"[AAMPCLI] Playback Rate: %d\n", playerInstanceAamp->
GetPlaybackRate());
310 else if (memcmp(cmd,
"islive", 6) == 0 )
312 printf(
"[AAMPCLI] VIDEO IS %s\n",
313 (playerInstanceAamp->
IsLive() ==
true )?
"LIVE":
"NOT LIVE");
315 else if (memcmp(cmd,
"customheader", 12) == 0 )
318 std::vector<std::string> headerValue;
319 printf(
"[AAMPCLI] customheader Command is %s\n" , cmd);
322 else if (sscanf(cmd,
"unlock %ld", &unlockSeconds) >= 1)
324 printf(
"[AAMPCLI] unlocking for %ld seconds\n" , unlockSeconds);
325 if(-1 == unlockSeconds)
328 time = unlockSeconds;
331 else if (memcmp(cmd,
"unlock", 6) == 0 )
333 printf(
"[AAMPCLI] unlocking till next program change\n");
337 else if (memcmp(cmd,
"lock", 4) == 0 )
341 else if (strcmp(cmd,
"progress") == 0)
343 mAampcli.mEnableProgressLog = mAampcli.mEnableProgressLog ? false :
true;
345 else if(strcmp(cmd,
"stats") == 0)
347 printf(
"[AAMPCLI] Playback stats: %s", playerInstanceAamp->
GetPlaybackStats().c_str());
368 if (*s >=
'0' && *s <=
'9')
390 const char *protocol[5] = {
"http:",
"https:",
"live:",
"hdmiin:",
"file:" };
391 for(
int i=0; i<5; i++ )
393 size_t len = strlen(protocol[i]);
394 if( memcmp( cmd, protocol[i],len )==0 )
409 std::string src = *cmd;
410 size_t first = src.find_first_not_of(
' ');
411 if (first != std::string::npos)
413 size_t last = src.find_last_not_of(
" \r\n");
414 std::string dst = src.substr(first, (last - first + 1));
415 strncpy(*cmd, (
char*)dst.c_str(), dst.size());
416 (*cmd)[dst.size()] =
'\0';
425 if(mAampcli.mAampGstPlayerMainLoop)
427 g_main_loop_quit(mAampcli.mAampGstPlayerMainLoop);
428 g_thread_join(mAampcli.mAampMainLoopThread);
430 printf(
"[AAMPCLI] %s(): Exit\n", __FUNCTION__);
434 void PlaybackCommand::registerPlaybackCommands()
436 addCommand(
"list",
"Type list to view virtual channel map");
437 addCommand(
"get help",
"Show help of get command");
438 addCommand(
"set help",
"Show help of set command");
439 addCommand(
"<channelNumber>",
"Play selected channel from guide");
440 addCommand(
"<url>",
"Play arbitrary stream");
441 addCommand(
"sleep <ms>",
"Sleep <ms> milliseconds");
442 addCommand(
"autoplay",
"Toggle tune autoplay (default = true)");
443 addCommand(
"new",
"Create new player instance");
444 addCommand(
"select",
"Enumerate available player instances");
445 addCommand(
"select <index>",
"Select player instance for use");
446 addCommand(
"detach",
"Detach (lightweight stop) selected player instance");
447 addCommand(
"pause",
"Pause the existing playback");
448 addCommand(
"pause <seconds>",
"Pause at specified position, negative value to cancel");
449 addCommand(
"play",
"Continue existing playback");
450 addCommand(
"stop",
"Stop the existing playback");
451 addCommand(
"status",
"get the status of existing playback");
452 addCommand(
"flush",
"Flush the existing playback");
453 addCommand(
"sf",
"slow");
454 addCommand(
"ff<x>",
"Trickmodes (x <= 128. y <= 128)");
455 addCommand(
"rw<y>",
"Trickmodes (x <= 128. y <= 128)");
456 addCommand(
"bps <x>",
"set bitrate (x= bitrate)");
457 addCommand(
"sap",
"Use SAP track (if avail)");
458 addCommand(
"seek <seconds>",
"Specify start time within manifest");
459 addCommand(
"live",
"Seek to live point");
460 addCommand(
"underflow",
"Simulate underflow");
461 addCommand(
"retune",
"schedule retune");
462 addCommand(
"unlock <cond>",
"unlock a channel <long int - time in seconds>");
463 addCommand(
"lock",
"lock the current channel");
464 addCommand(
"next",
"Play next virtual channel");
465 addCommand(
"rollover",
"Schedule artificial pts rollover 10s after next tune");
466 addCommand(
"prev",
"Play previous virtual channel");
467 addCommand(
"exit",
"Exit from application");
468 addCommand(
"help",
"Show this list again");
469 addCommand(
"progress",
"Enable/disable Progress event logging");
470 addCommand(
"auto <opt params>",
471 "startChan=500 endChan=1000 maxTuneTime=6 playTime=15 betweenTime=15" );
474 void PlaybackCommand::addCommand(
string command,
string description)
476 playbackCommands.insert(make_pair(command,description));
477 commands.push_back(command);
486 std::map<string,string>::iterator playbackCmdItr;
488 printf(
"******************************************************************************************\n");
489 printf(
"* <command> [<arguments>]\n");
490 printf(
"* Usage of Commands, and arguments expected\n");
491 printf(
"******************************************************************************************\n");
493 for(
auto itr:commands)
495 playbackCmdItr = playbackCommands.find(itr);
497 if(playbackCmdItr != playbackCommands.end())
499 std::cout << std::setw(20) << std::left << (playbackCmdItr->first).c_str() <<
"// "<< (playbackCmdItr->second).c_str() <<
"\n";
503 printf(
"******************************************************************************************\n");
506 char * PlaybackCommand::commandRecommender(
const char *text,
int state)
510 static std::vector<std::string>::iterator itr;
514 itr = commands.begin();
518 while (itr != commands.end())
520 name = (
char *) itr->c_str();
522 if (strncmp(name, text, len) == 0)