RDK Documentation (Open Sourced RDK Components)
player_test_cli.cpp
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt 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 /******* This is the test code for rdkmediaplayer *********/
21 
22 #include <unistd.h>
23 #include <stdio.h>
24 #include <sys/prctl.h>
25 #include <sys/stat.h>
26 #include <glib.h>
27 #ifdef ENABLE_BREAKPAD
28 #include <client/linux/handler/exception_handler.h>
29 #endif
30 #include <rtRemote.h>
31 #include "rdkmediaplayer.h"
32 #include "logger.h"
33 #include "glib_tools.h"
34 #include <string>
35 
36 GMainLoop *gMainLoop = 0;
37 
38 #ifdef ENABLE_BREAKPAD
39 namespace
40 {
41 
42 bool breakpadCallback(const google_breakpad::MinidumpDescriptor& /*descriptor*/, void* /*context*/, bool succeeded) {
43  rtRemoteShutdown();
44  return succeeded;
45 }
46 
47 void installExceptionHandler() {
48  static google_breakpad::ExceptionHandler* excHandler = NULL;
49  delete excHandler;
50  excHandler = new google_breakpad::ExceptionHandler(
51  google_breakpad::MinidumpDescriptor("/opt/minidumps"),
52  NULL,
53  breakpadCallback,
54  NULL,
55  true,
56  -1);
57 }
58 
59 } // namespace
60 #endif
61 
62 rtError
63 onEvent(int argc, rtValue const* argv, rtValue* result, void* argp)
64 {
65  // this matches the signature of the server's function
66  LOG_TRACE("******** onEvent ********");
67  LOG_TRACE("argc:%d", argc);
68  LOG_TRACE("argv[0]:%s", argv[0].toString().cString());
69 
70  if (argc >= 1)
71  {
72  rtObjectRef event = argv[0].toObject();
73  rtString eventName = event.get<rtString>("name");
74  LOG_TRACE("Received event: %s", eventName.cString());
75  }
76 
77  (void) result;
78  (void) argp;
79 
80  if (result)
81  *result = rtValue(true);
82 
83  LOG_TRACE("******** onEvent - End ********");
84  return RT_OK;
85 }
86 
87 void* processMessage(void* args)
88 {
89  while(1)
90  {
91  rtError err = rtRemoteProcessSingleItem();
92  usleep(10000);
93  }
94 }
95 
96 int main(int argc, char *argv[]) {
97 
98  int quit = 0; /* 1 == quit loop */
99  int c = 0;
100  char lang;
101  rtString url_out;
102  log_init();
103  LOG_INFO("Init rtRemote");
104  rtError rc;
105  rc = rtRemoteInit();
106  pthread_t processMsgThread;
107  ASSERT(rc == RT_OK);
108  const char opendata[256] = "{\"mediaurl\": \"tune://frequency=306000000&modulation=16&symbol_rate=6900000&pgmno=1001&\",\"mode\": \"MODE_LIVE\",\"manage\": \"MANAGE_NONE\",\"casinitdata\": \"<base64 data>\",\"casocdmid\": \"\"}";
109  const char opendata1[256] = "{\"mediaurl\": \"tune://frequency=322000000&modulation=16&symbol_rate=6900000&pgmno=1&\",\"mode\": \"MODE_LIVE\",\"manage\": \"MANAGE_NONE\",\"casinitdata\": \"<base64 data>\",\"casocdmid\": \"\"}";
110  bool channel1 = 0;
111 
112  const char* objectName = getenv("PX_WAYLAND_CLIENT_REMOTE_OBJECT_NAME");
113  if (!objectName) objectName = "rdkmediaplayer";
114  LOG_INFO("Locate: %s", objectName);
115 
116  rtObjectRef playerRef;
117  rc = rtRemoteLocateObject(objectName, playerRef);
118  pthread_create(&processMsgThread, NULL, processMessage, NULL);
119  ASSERT(rc == RT_OK);
120  LOG_INFO("found object : %s", objectName);
121  LOG_INFO("Start main loop");
122 
123  rtString supSpeeds;
124  rc = playerRef.get("availableSpeeds", supSpeeds);
125  if (rc != RT_OK)
126  {
127  LOG_INFO("failed to get availableSpeeds: %d", rc);
128  }
129  else
130  {
131  LOG_INFO("supSpeeds = %s", supSpeeds.cString());
132  }
133 
134  if(argc <= 1)
135  {
136  printf("URI was NULL. Use the default json data with url");
137  rc = playerRef.send("open", rtString(opendata));
138  }
139  else if(strchr(argv[1], '{') != NULL)
140  {
141  printf("URI contains json data");
142  rc = playerRef.send("open", rtString(argv[1]));
143  }
144  else
145  {
146  printf( "URL is: %s\n", argv[1] );
147  rc = playerRef.set("url", rtString(argv[1]));
148  }
149 
150  if (rc != RT_OK)
151  {
152  LOG_INFO("failed to set URL: %d", rc);
153  }
154  else
155  {
156  playerRef.send("on","onMediaOpened",new rtFunctionCallback(onEvent));
157  playerRef.send("on","onProgress",new rtFunctionCallback(onEvent));
158  playerRef.send("on","onStatus",new rtFunctionCallback(onEvent));
159  playerRef.send("on","onWarning",new rtFunctionCallback(onEvent));
160  playerRef.send("on","onError",new rtFunctionCallback(onEvent));
161  playerRef.send("on","onSpeedChange",new rtFunctionCallback(onEvent));
162  playerRef.send("on","onClosed",new rtFunctionCallback(onEvent));
163  playerRef.send("on","onPlayerInitialized",new rtFunctionCallback(onEvent));
164  playerRef.send("on","onBuffering",new rtFunctionCallback(onEvent));
165  playerRef.send("on","onPlaying",new rtFunctionCallback(onEvent));
166  playerRef.send("on","onPaused",new rtFunctionCallback(onEvent));
167  playerRef.send("on","onComplete",new rtFunctionCallback(onEvent));
168  playerRef.send("on","onIndividualizing",new rtFunctionCallback(onEvent));
169  playerRef.send("on","onAcquiringLicense",new rtFunctionCallback(onEvent));
170  playerRef.send("on","onDRMMetadata",new rtFunctionCallback(onEvent));
171  playerRef.send("on","onSegmentStarted",new rtFunctionCallback(onEvent));
172  playerRef.send("on","onSegmentCompleted",new rtFunctionCallback(onEvent));
173  playerRef.send("on","onSegmentWatched",new rtFunctionCallback(onEvent));
174  playerRef.send("on","onBufferWarning",new rtFunctionCallback(onEvent));
175  playerRef.send("on","onPlaybackSpeedsChanged",new rtFunctionCallback(onEvent));
176  playerRef.send("on","onAdditionalAuthRequired",new rtFunctionCallback(onEvent));
177 
178  LOG_INFO("URL is set.");
179  url_out = playerRef.get<rtString>("url");
180  LOG_INFO("get url value : %s", url_out.cString());
181 
182  rc = playerRef.send("play");
183  if (rc != RT_OK)
184  {
185  LOG_INFO("failed to set URL to play: %d", rc);
186  }
187  LOG_INFO("Play the url %s, result: %d", url_out.cString(), rc);
188  }
189 
190  /* loop until user wants to quick playback */
191  while( !quit )
192  {
193  printf("Playback Options:\n");
194  printf("p - Pause Playback\n");
195  printf("r - Resume Playback\n");
196  printf("s - Stop Playback\n");
197  printf("l - Set Audio Language\n");
198  printf("t - Set speed\n");
199  printf("c - Enable Subt.\n");
200  printf("z - Channel Change\n");
201  printf("q - Quit\n");
202  printf("\n");
203 
204  c = getchar();
205  switch (c)
206  {
207  case 'p':
208  /* Pause playback */
209  rc = playerRef.send("pause");
210  if (rc != RT_OK)
211  {
212  LOG_INFO("failed to set URL to PAUSE: %d", rc);
213  }
214  LOG_INFO("PAUSE the url %s, result: %d", url_out.cString(), rc);
215  break;
216  case 'r':
217  /* resume playback */
218  rc = playerRef.send("play");
219  if (rc != RT_OK)
220  {
221  LOG_INFO("failed to set URL play: %d", rc);
222  }
223  LOG_INFO("Play the url %s, result: %d", url_out.cString(), rc);
224  break;
225  case 's':
226  /* stop playback */
227  rc = playerRef.send("stop");
228  if (rc != RT_OK)
229  {
230  LOG_INFO("failed to set URL play: %d", rc);
231  }
232  LOG_INFO("stop the url %s, result: %d", url_out.cString(), rc);
233  break;
234  case 'l':
235  printf("e - To Set English Language\n");
236  printf("d - To Set deustch Language\n");
237  scanf(" %c", &lang);
238  switch(lang)
239  {
240  case 'e':
241  LOG_INFO("Set English language");
242  rc = playerRef.set("audioLanguage", "eng");
243  if (rc != RT_OK)
244  {
245  LOG_INFO("failed to set English Language: %d", rc);
246  }
247  break;
248  case 'd':
249  LOG_INFO("Set Deustch language");
250  rc = playerRef.set("audioLanguage", "deu");
251  if (rc != RT_OK)
252  {
253  LOG_INFO("failed to set Deustch Language: %d", rc);
254  }
255  break;
256  default:
257  break;
258  }
259  break;
260  case 't':
261  LOG_INFO("feature not implemeted");
262  break;
263  case 'c':
264  LOG_INFO("feature not implemeted");
265  break;
266  case 'z':
267  /* Stop and Zap channels */
268  rc = playerRef.send("stop");
269  if (rc != RT_OK)
270  {
271  LOG_INFO("failed to set URL play: %d", rc);
272  }
273  LOG_INFO("stop the url %s, result: %d", url_out.cString(), rc);
274 
275  if(channel1)
276  {
277  channel1 = 0;
278  printf("[CC] URI contains json data = %s\n", opendata);
279  rc = playerRef.send("open", rtString(opendata));
280  }
281  else{
282  channel1 = 1;
283  printf("[CC] URI contains json data = %s\n", opendata1);
284  rc = playerRef.send("open", rtString(opendata1));
285  }
286  sleep(1);
287  url_out = playerRef.get<rtString>("url");
288  LOG_INFO("get url value : %s", url_out.cString());
289  /* Start playback */
290  rc = playerRef.send("play");
291  if (rc != RT_OK)
292  {
293  LOG_INFO("failed to set URL play: %d", rc);
294  }
295  LOG_INFO("Play the url %s, result: %d", url_out.cString(), rc);
296  break;
297  case 'q':
298  quit = 1;
299  break;
300  default:
301  break;
302  }
303  }
304 
305  gMainLoop = 0;
306 
307  playerRef = nullptr;
308 
309  LOG_INFO("Shutdown");
310  rc = rtRemoteShutdown();
311  ASSERT(rc == RT_OK);
312 
313  return 0;
314 }
LOG_INFO
#define LOG_INFO(AAMP_JS_OBJECT, FORMAT,...)
Definition: jsutils.h:39
LOG_TRACE
#define LOG_TRACE
Definition: rdk_debug_priv.c:83