RDK Documentation (Open Sourced RDK Components)
AampcliSmokeTest.cpp
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file
3  * the following copyright and licenses apply:
4  *
5  * Copyright 2022 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 <time.h>
21 #include "Aampcli.h"
22 #include "AampcliSmokeTest.h"
23 
24 extern Aampcli mAampcli;
25 static PlayerInstanceAAMP *mPlayerInstanceAamp;
26 std::map<std::string, std::string> SmokeTest::smokeTestUrls = std::map<std::string, std::string>();
27 
28 bool SmokeTest::execute(char *cmd, PlayerInstanceAAMP *playerInstanceAamp)
29 {
30  int result;
31 
32  mPlayerInstanceAamp = playerInstanceAamp;
33 
34  loadSmokeTestUrls();
35  vodTune("Dash");
36  vodTune("Hls");
37  liveTune("Live");
38 
39  return true;
40 }
41 
42 void SmokeTest::loadSmokeTestUrls()
43 {
44 
45  const std::string smokeurlFile("/smoketest.csv");
46  int BUFFER_SIZE = 500;
47  char buffer[BUFFER_SIZE];
48  FILE *fp;
49 
50  if ( (fp = mAampcli.getConfigFile(smokeurlFile)) != NULL)
51  {
52  printf("%s:%d: opened smoketest file\n",__FUNCTION__,__LINE__);
53 
54  while(!feof(fp))
55  {
56  if(fgets(buffer, BUFFER_SIZE, fp) != NULL)
57  {
58  buffer[strcspn(buffer, "\n")] = 0;
59  std::string urlData(buffer);
60 
61  std::size_t delimiterPos = urlData.find(",");
62 
63  if(delimiterPos != std::string::npos)
64  {
65  smokeTestUrls[ urlData.substr(0, delimiterPos) ] = urlData.substr(delimiterPos + 1);
66  }
67  }
68  }
69 
70  fclose(fp);
71  }
72 
73 }
74 
75 void SmokeTest::vodTune(const char *stream)
76 {
77  const char *url = NULL;
78  std::string fileName;
79  std::string testFilePath;
80  FILE *fp;
81  time_t initialTime = 0, currentTime = 0;
82  std::map<std::string, std::string>::iterator itr;
83 
84  createTestFilePath(testFilePath);
85  if(strncmp(stream,"Dash",4) == 0)
86  {
87  fileName = testFilePath + "tuneDashStream.txt";
88  itr = smokeTestUrls.find("VOD_DASH");
89 
90  itr = smokeTestUrls.find("VOD_DASH");
91 
92  if(itr != smokeTestUrls.end())
93  {
94  url = (itr->second).c_str();
95  }
96 
97  if(url == NULL)
98  {
99  url = "https://cpetestutility.stb.r53.xcal.tv/VideoTestStream/main.mpd";
100  }
101 
102  }
103  else if(strncmp(stream,"Hls",3) == 0)
104  {
105  fileName = testFilePath + "tuneHlsStream.txt";
106  itr = smokeTestUrls.find("VOD_HLS");
107 
108  if(itr != smokeTestUrls.end())
109  {
110  url = (itr->second).c_str();
111  }
112 
113  if(url == NULL)
114  {
115  url = "https://cpetestutility.stb.r53.xcal.tv/VideoTestStream/main.m3u8";
116  }
117  }
118 
119  fp = stdout;
120  stdout = fopen(fileName.c_str(),"w");
121 
122  mPlayerInstanceAamp->Tune(url);
123 
124  initialTime = time(NULL);
125 
126  while(1)
127  {
128  sleep(5);
129  if(mPlayerInstanceAamp->GetState() == eSTATE_COMPLETE)
130  {
131  printf("%s:%d: Tune sub task started\n",__FUNCTION__,__LINE__);
132  mPlayerInstanceAamp->Tune(url);
133  mPlayerInstanceAamp->SetRate(0); // To pause
134  mPlayerInstanceAamp->SetRate(4); // To fastforward
135  mPlayerInstanceAamp->SetRate(1); // To play
136  sleep(20);
137  mPlayerInstanceAamp->SetRate(-2); // To rewind
138  sleep(10);
139  mPlayerInstanceAamp->Stop();
140  sleep(3);
141 
142  printf("%s:%d: Tune %s completed\n",__FUNCTION__,__LINE__,stream);
143  break;
144  }
145 
146  currentTime = time(NULL);
147  if((currentTime - initialTime) > 1200)
148  {
149  break;
150  }
151  }
152 
153  fclose(stdout);
154  stdout = fp;
155 }
156 
157 void SmokeTest::liveTune(const char *stream)
158 {
159  const char *url = NULL;
160  std::string fileName;
161  std::string testFilePath;
162  FILE *fp;
163 
164  createTestFilePath(testFilePath);
165 
166  url = "https://ll-usw2.akamaized.net/live/disk/sky/DASH-LL-sky.toml/sky.mpd";
167  fileName = testFilePath +"tuneLive.txt";
168 
169  fp = stdout;
170  stdout = fopen(fileName.c_str(),"w");
171 
172  mPlayerInstanceAamp->Tune(url);
173  sleep(10);
174  mPlayerInstanceAamp->SetRate(0); // To pause
175  mPlayerInstanceAamp->SetRate(1); // To play
176  sleep(10);
177  mPlayerInstanceAamp->Stop();
178  sleep(5);
179 
180  fclose(stdout);
181  stdout = fp;
182 
183 }
184 
185 bool SmokeTest::createTestFilePath(std::string &filePath)
186 {
187 #ifdef AAMP_SIMULATOR_BUILD
188  char *ptr = getenv("HOME");
189  if(ptr)
190  {
191  filePath.append(ptr);
192  filePath += "/smoketest/";
193  }
194  else
195  {
196  printf("%s:%d: Path not found\n",__FUNCTION__,__LINE__);
197  return false;
198  }
199 #else
200  filePath = "/opt/smoketest/";
201 #endif
202  DIR *dir = opendir(filePath.c_str());
203  if (!dir)
204  {
205  mkdir(filePath.c_str(), 0777);
206  }
207  else
208  {
209  closedir(dir);
210  }
211 
212  return true;
213 }
214 
Aampcli
Definition: Aampcli.h:61
Aampcli.h
AAMPcli header file.
PlayerInstanceAAMP
Player interface class for the JS pluggin.
Definition: main_aamp.h:692
PlayerInstanceAAMP::GetState
PrivAAMPState GetState(void)
To get the current AAMP state.
Definition: main_aamp.cpp:1765
PlayerInstanceAAMP::SetRate
void SetRate(float rate, int overshootcorrection=0)
Set playback rate.
Definition: main_aamp.cpp:561
PlayerInstanceAAMP::Tune
void Tune(const char *mainManifestUrl, const char *contentType, bool bFirstAttempt, bool bFinalAttempt, const char *traceUUID, bool audioDecoderStreamSync)
Tune to a URL. DEPRECATED! This is included for backwards compatibility with current Sky AS integrati...
Definition: main_aamp.cpp:312
PlayerInstanceAAMP::Stop
void Stop(bool sendStateChangeEvent=true)
Stop playback and release resources.
Definition: main_aamp.cpp:282
AampcliSmokeTest.h
AampcliSmokeTest header file.
eSTATE_COMPLETE
@ eSTATE_COMPLETE
Definition: AampEvent.h:169