29 extern void tsdemuxer_InduceRollover(
bool enable );
33 mEnableProgressLog(false),
35 mTuneFailureDescription(
""),
38 mAampGstPlayerMainLoop(NULL),
39 mAampMainLoopThread(NULL),
44 Aampcli::Aampcli(
const Aampcli& aampcli):
46 mEnableProgressLog(false),
48 mTuneFailureDescription(
""),
51 mAampGstPlayerMainLoop(NULL),
52 mAampMainLoopThread(NULL),
56 mSingleton = aampcli.mSingleton;
57 mEventListener = aampcli.mEventListener;
68 if(mSingleton != NULL)
70 SAFE_DELETE(mSingleton);
74 void Aampcli::doAutomation(
int startChannel,
int stopChannel,
int maxTuneTimeS,
int playTimeS,
int betweenTimeS )
76 #if defined (__APPLE__) || defined(UBUNTU)
77 std::string outPath(getenv(
"HOME"));
79 std::string outPath(
"/opt");
81 outPath +=
"/test-results.csv";
82 const char *mod =
"wb";
85 if (mVirtualChannelMap.next() == NULL)
87 printf(
"[AAMPCLI] Can not auto channels, empty virtual channel map.\n");
91 for(
int chan=startChannel; chan<=stopChannel; chan++ )
96 if( strstr(info->name.c_str(),
"ClearKey") ||
97 strstr(info->name.c_str(),
"MultiDRM") ||
98 strstr(info->name.c_str(),
"DTS Audio") ||
99 strstr(info->name.c_str(),
"AC-4") )
105 printf(
"%d,\"%s\",%s,%s\n",
106 info->channelNumber, info->name.c_str(), info->uri.c_str(),
"TUNING...");
109 snprintf( cmd,
sizeof(cmd),
"%d", chan );
110 mTuneFailureDescription.clear();
111 lCommandHandler.dispatchAampcliCommands(cmd,mSingleton);
113 for(
int i=0; i<maxTuneTimeS; i++ )
122 const char *stateName;
128 printf(
"***STOP***\n" );
130 sleep( betweenTimeS );
131 printf(
"***NEXT***\n" );
137 stateName =
"TIMEOUT";
140 printf(
"***%s\n", stateName );
141 FILE *f = fopen( outPath.c_str(), mod );
143 fprintf( f,
"%d,\"%s\",%s,%s,%s\n",
144 info->channelNumber, info->name.c_str(), info->uri.c_str(), stateName, mTuneFailureDescription.c_str() );
151 void Aampcli::runCommand(
void* args )
153 char cmd[mMaxBufferLength] = {
'\0'};
154 std::vector<std::string> *arguments;
155 std::vector<std::string> cmdVec;
158 lCommandHandler.registerAampcliCommands();
163 arguments =
static_cast<std::vector<std::string>*
>(args);
168 for(
auto param : cmdVec)
170 snprintf( cmd+strlen(cmd),mMaxBufferLength-strlen(cmd),
"%s ", param.c_str());
172 lCommandHandler.dispatchAampcliCommands(cmd,mAampcli.mSingleton);
177 printf(
"[AAMPCLI] type 'help' for list of available commands\n");
181 rl_attempted_completion_function = lCommandHandler.commandCompletion;
182 char *buffer = readline(
"[AAMPCLI] Enter cmd: ");
195 if(strncmp(cmd,
"history",7) == 0)
197 HISTORY_STATE *historyState = history_get_history_state ();
199 for (
int i = 0; i < historyState->length; i++)
201 printf (
"%s\n", history_get(i+1)->line);
205 if( memcmp(cmd,
"autoplay",8)!=0 &&
206 memcmp(cmd,
"auto",4)==0 )
208 int start=500, end=1000;
209 int maxTuneTimeS = 6;
211 int betweenTimeS = 15;
212 int matched = sscanf(cmd,
"auto %d %d %d %d %d", &start, &end, &maxTuneTimeS, &playTimeS, &betweenTimeS );
213 mAampcli.doAutomation( start, end, maxTuneTimeS, playTimeS, betweenTimeS );
217 bool l_status =
false;
219 l_status = lCommandHandler.dispatchAampcliCommands(cmd,mAampcli.mSingleton);
221 if(l_status ==
false)
232 FILE * Aampcli::getConfigFile(
const std::string& cfgFile)
239 std::string cfgBasePath(getenv(
"HOME"));
240 std::string cfgPath = cfgBasePath + cfgFile;
241 FILE *f = fopen(cfgPath.c_str(),
"rb");
243 std::string cfgPath =
"/opt" + cfgFile;
244 FILE *f = fopen(cfgPath.c_str(),
"rb");
257 if (mAampcli.mAampGstPlayerMainLoop)
259 g_main_loop_run(mAampcli.mAampGstPlayerMainLoop);
260 printf(
"[AAMPCLI] aampGstPlayerStreamThread: exited main event loop\n");
262 g_main_loop_unref(mAampcli.mAampGstPlayerMainLoop);
263 mAampcli.mAampGstPlayerMainLoop = NULL;
277 gst_init(&argc, &argv);
278 mAampGstPlayerMainLoop = g_main_loop_new(NULL, FALSE);
283 void Aampcli::newPlayerInstance(
void )
286 #ifdef RENDER_FRAMES_IN_APP_CONTEXT
288 ,Shader::updateYUVFrame
291 if( !mEventListener )
293 printf(
"allocating new MyAAMPEventListener\n");
297 int playerIndex = mPlayerInstances.size();
298 printf(
"new playerInstance; index=%d\n", playerIndex );
299 mPlayerInstances.push_back(player);
311 int main(
int argc,
char **argv)
313 char driveName = (*argv)[0];
315 AampLogManager::disableLogRedirection =
true;
316 ABRManager mAbrManager;
318 signal(SIGINT, Harvestor::harvestTerminateHandler);
322 mAbrManager.setLogDirectory(driveName);
324 printf(
"**************************************************************************\n");
325 printf(
"** ADVANCED ADAPTIVE MEDIA PLAYER (AAMP) - COMMAND LINE INTERFACE (CLI) **\n");
326 printf(
"**************************************************************************\n");
329 mAampcli.newPlayerInstance();
332 const std::string cfgCSV(
"/aampcli.csv");
333 const std::string cfgLegacy(
"/aampcli.cfg");
335 if ( (f = mAampcli.getConfigFile(cfgCSV)) != NULL)
337 printf(
"[AAMPCLI] opened aampcli.csv\n");
338 mVirtualChannelMap.loadVirtualChannelMapFromCSV( f );
342 else if ( (f = mAampcli.getConfigFile(cfgLegacy)) != NULL)
344 printf(
"[AAMPCLI] opened aampcli.cfg\n");
350 std::vector<std::string> arguments;
351 for(
int i = 1; i < argc; i++)
353 arguments.push_back(std::string(argv[i]));
356 std::thread cmdThreadId;
358 cmdThreadId = std::thread(&mAampcli.runCommand, (
void *) &arguments);
359 }
catch (std::exception& e)
361 printf(
"[AAMPCLI] Failed at create thread error %s\n",e.what());
364 #ifdef RENDER_FRAMES_IN_APP_CONTEXT
366 glutInit(&argc, argv);
367 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
368 glutInitWindowPosition(80, 80);
369 glutInitWindowSize(640, 480);
370 glutCreateWindow(
"AAMP Texture Player");
371 printf(
"[AAMPCLI] OpenGL Version[%s] GLSL Version[%s]\n", glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION));
376 l_Shader.InitShaders();
377 glutDisplayFunc(l_Shader.glRender);
378 glutTimerFunc(40, l_Shader.timer, 0);
384 createAndRunCocoaWindow();
387 if(cmdThreadId.joinable())
393 const char *MyAAMPEventListener::stringifyPrivAAMPState(
PrivAAMPState state)
395 static const char *stateName[] =
414 return stateName[state];
428 switch (e->getType())
432 StateChangedEventPtr ev = std::dynamic_pointer_cast<StateChangedEvent>(e);
433 printf(
"[AAMPCLI] AAMP_EVENT_STATE_CHANGED: %s (%d)\n", mAampcli.mEventListener->stringifyPrivAAMPState(ev->getState()), ev->getState());
438 SeekedEventPtr ev = std::dynamic_pointer_cast<SeekedEvent>(e);
439 printf(
"[AAMPCLI] AAMP_EVENT_SEEKED: new positionMs %f\n", ev->getPosition());
444 MediaMetadataEventPtr ev = std::dynamic_pointer_cast<MediaMetadataEvent>(e);
445 std::vector<std::string> languages = ev->getLanguages();
446 int langCount = ev->getLanguagesCount();
447 printf(
"[AAMPCLI] AAMP_EVENT_MEDIA_METADATA\n");
448 for (
int i = 0; i < langCount; i++)
450 printf(
"[AAMPCLI] language: %s\n", languages[i].c_str());
452 printf(
"[AAMPCLI] AAMP_EVENT_MEDIA_METADATA\n\tDuration=%ld\n\twidth=%d\n\tHeight=%d\n\tHasDRM=%d\n\tProgreamStartTime=%f\n", ev->getDuration(), ev->getWidth(), ev->getHeight(), ev->hasDrm(), ev->getProgramStartTime());
453 int bitrateCount = ev->getBitratesCount();
454 std::vector<long> bitrates = ev->getBitrates();
455 printf(
"[AAMPCLI] Bitrates:\n");
456 for(
int i = 0; i < bitrateCount; i++)
458 printf(
"\t[AAMPCLI] bitrate(%d)=%ld\n", i, bitrates.at(i));
464 printf(
"[AAMPCLI] AAMP_EVENT_TUNED\n");
469 MediaErrorEventPtr ev = std::dynamic_pointer_cast<MediaErrorEvent>(e);
470 mAampcli.mTuneFailureDescription = ev->getDescription();
471 printf(
"[AAMPCLI] AAMP_EVENT_TUNE_FAILED reason=%s\n",mAampcli.mTuneFailureDescription.c_str());
476 SpeedChangedEventPtr ev = std::dynamic_pointer_cast<SpeedChangedEvent>(e);
477 printf(
"[AAMPCLI] AAMP_EVENT_SPEED_CHANGED current rate=%f\n", ev->getRate());
482 DrmMetaDataEventPtr ev = std::dynamic_pointer_cast<DrmMetaDataEvent>(e);
483 printf(
"[AAMPCLI] AAMP_DRM_FAILED Tune failure:%d\t\naccess status str:%s\t\naccess status val:%d\t\nResponce code:%ld\t\nIs SecClient error:%d\t\n",ev->getFailure(), ev->getAccessStatus().c_str(), ev->getAccessStatusValue(), ev->getResponseCode(), ev->getSecclientError());
487 printf(
"[AAMPCLI] AAMP_EVENT_EOS\n");
488 mAampcli.mPlayerInstances[mLogObj->
getPlayerId()]->aamp->PausePipeline(
true,
false);
491 printf(
"[AAMPCLI] AAMP_EVENT_PLAYLIST_INDEXED\n");
495 ProgressEventPtr ev = std::dynamic_pointer_cast<ProgressEvent>(e);
498 snprintf(
string,
sizeof(
string),
"%f", ev->getPosition()/1000.0 );
499 setSimulatorWindowTitle(
string);
501 if(mAampcli.mEnableProgressLog)
503 printf(
"[AAMPCLI] AAMP_EVENT_PROGRESS\n\tDuration=%lf\n\tposition=%lf\n\tstart=%lf\n\tend=%lf\n\tcurrRate=%f\n\tBufferedDuration=%lf\n\tPTS=%lld\n\ttimecode=%s\n",ev->getDuration(),ev->getPosition(),ev->getStart(),ev->getEnd(),ev->getSpeed(),ev->getBufferedDuration(),ev->getPTS(),ev->getSEITimeCode());
509 CCHandleEventPtr ev = std::dynamic_pointer_cast<CCHandleEvent>(e);
510 printf(
"[AAMPCLI] AAMP_EVENT_CC_HANDLE_RECEIVED CCHandle=%lu\n",ev->getCCHandle());
515 BitrateChangeEventPtr ev = std::dynamic_pointer_cast<BitrateChangeEvent>(e);
516 printf(
"[AAMPCLI] AAMP_EVENT_BITRATE_CHANGED\n\tbitrate=%ld\n\tdescription=\"%s\"\n\tresolution=%dx%d@%ffps\n\ttime=%d\n\tposition=%lf\n", ev->getBitrate(), ev->getDescription().c_str(), ev->getWidth(), ev->getHeight(), ev->getFrameRate(), ev->getTime(), ev->getPosition());
520 printf(
"[AAMPCLI] AAMP_EVENT_AUDIO_TRACKS_CHANGED\n");
523 printf(
"[AAMPCLI] AAMP_EVENT_TEXT_TRACKS_CHANGED\n");
526 printf(
"[AAMPCLI] AAMP_EVENT_ID3_METADATA\n");
530 BlockedEventPtr ev = std::dynamic_pointer_cast<BlockedEvent>(e);
531 printf(
"[AAMPCLI] AAMP_EVENT_BLOCKED Reason:%s\n" ,ev->getReason().c_str());
536 ContentGapEventPtr ev = std::dynamic_pointer_cast<ContentGapEvent>(e);
537 printf(
"[AAMPCLI] AAMP_EVENT_CONTENT_GAP\n\tStart:%lf\n\tDuration:%lf\n", ev->getTime(), ev->getDuration());
542 WatermarkSessionUpdateEventPtr ev = std::dynamic_pointer_cast<WatermarkSessionUpdateEvent>(e);
543 printf(
"[AAMPCLI] AAMP_EVENT_WATERMARK_SESSION_UPDATE SessionHandle:%d Status:%d System:%s\n" ,ev->getSessionHandle(), ev->getStatus(), ev->getSystem().c_str());
548 BufferingChangedEventPtr ev = std::dynamic_pointer_cast<BufferingChangedEvent>(e);
549 printf(
"[AAMPCLI] AAMP_EVENT_BUFFERING_CHANGED Sending Buffer Change event status (Buffering): %s", (ev->buffering() ?
"End":
"Start"));
554 ContentProtectionDataEventPtr ev = std::dynamic_pointer_cast<ContentProtectionDataEvent>(e);
555 printf(
"[AMPCLI] AAMP_EVENT_CONTENT_PROTECTION_UPDATE received stream type %s\n",ev->getStreamType().c_str());
556 std::vector<uint8_t> key = ev->getKeyID();
557 printf(
"[AMPCLI] AAMP_EVENT_CONTENT_PROTECTION_UPDATE received key is ");
558 for(
int i=0;i<key.size();i++)
559 printf(
"%x",key.at(i)&0xff);
561 cJSON *root = cJSON_CreateObject();
562 cJSON *KeyId = cJSON_CreateArray();
563 for(
int i=0;i<key.size();i++)
564 cJSON_AddItemToArray(KeyId, cJSON_CreateNumber(key.at(i)));
565 cJSON_AddItemToObject(root,
"keyID",KeyId);
568 std::string json = cJSON_Print(root);