aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Huang2019-08-27 15:07:08 -0500
committerDavid Huang2019-09-12 14:29:24 -0500
commit66d5068dfe67de9a6ec59b3cd6d6700ec06ed872 (patch)
tree82f99430d75575171aea5a1656f003d8d2108238
parentf4962461d6ac758f2365b7d8964e241b7470bdfb (diff)
downloadviddec-test-app-66d5068dfe67de9a6ec59b3cd6d6700ec06ed872.tar.gz
viddec-test-app-66d5068dfe67de9a6ec59b3cd6d6700ec06ed872.tar.xz
viddec-test-app-66d5068dfe67de9a6ec59b3cd6d6700ec06ed872.zip
Enable automatic detection of decoder node
Signed-off-by: David Huang <d-huang@ti.com>
-rw-r--r--main.c80
1 files changed, 75 insertions, 5 deletions
diff --git a/main.c b/main.c
index 621029c..f5d1583 100644
--- a/main.c
+++ b/main.c
@@ -1294,9 +1294,8 @@ static int open_device(char *dev_name)
1294{ 1294{
1295 struct v4l2_capability cap; 1295 struct v4l2_capability cap;
1296 struct v4l2_fmtdesc argp; 1296 struct v4l2_fmtdesc argp;
1297 int ret = 0;
1298 int fd = -1;
1299 struct v4l2_event_subscription sub; 1297 struct v4l2_event_subscription sub;
1298 int ret = 0, fd = -1;
1300 1299
1301 fd = open(dev_name, O_RDWR | O_NONBLOCK, 0); 1300 fd = open(dev_name, O_RDWR | O_NONBLOCK, 0);
1302 if (-1 == fd) { 1301 if (-1 == fd) {
@@ -1361,9 +1360,66 @@ static int open_device(char *dev_name)
1361 return fd; 1360 return fd;
1362} 1361}
1363 1362
1363static int find_device(char *dev_name)
1364{
1365 const char *default_dev_path = "/dev/";
1366 const char *dev_name_mask = "videox";
1367 const char *driver_name = "vxd-dec";
1368 struct v4l2_capability cap = {0};
1369 char name[256] = "";
1370 DIR *d;
1371 struct dirent *dir;
1372 int fd = -1;
1373
1374 d = opendir(default_dev_path);
1375 if (!d) {
1376 printf("Failed to open device path %s %d %s\n",
1377 default_dev_path, errno, strerror(errno));
1378 return -1;
1379 }
1380
1381 while ((dir = readdir(d)) != NULL) {
1382 if (strncmp(dir->d_name, dev_name_mask, 5) == 0) {
1383 strncpy(name, default_dev_path, sizeof(name));
1384 strncat(name, dir->d_name, sizeof(name));
1385
1386 fd = open(name, O_RDWR | O_NONBLOCK, 0);
1387 if (fd < 0) {
1388 printf("Failed to open device %s %d %s\n",
1389 name, errno, strerror(errno));
1390 continue;
1391 }
1392
1393 memset(&cap, 0, sizeof(cap));
1394
1395 if (ioctl(fd, VIDIOC_QUERYCAP, &cap)) {
1396 printf("VIDIOC_QUERYCAP failed on device %s %d %s\n",
1397 name, errno, strerror(errno));
1398 close(fd);
1399 continue;
1400 }
1401
1402 if (strcmp((const char *)cap.driver, driver_name) == 0) {
1403 close(fd);
1404 fd = -1;
1405 debug_printf("No device specified, using %s\n",
1406 name);
1407 snprintf(dev_name, sizeof(name), "%s", name);
1408 return 0;
1409 }
1410
1411 close(fd);
1412 fd = -1;
1413 }
1414 }
1415
1416 printf("Failed to find device in %s\n", default_dev_path);
1417 return -1;
1418}
1419
1364int main(int argc, char **argv) 1420int main(int argc, char **argv)
1365{ 1421{
1366 char *dev_name = "/dev/video0"; 1422 char dev_name[256] = "";
1367 int i = 0; 1423 int i = 0;
1368 int ret = 0; 1424 int ret = 0;
1369 unsigned int num_devs = 1; 1425 unsigned int num_devs = 1;
@@ -1395,7 +1451,7 @@ int main(int argc, char **argv)
1395 /* Parse the input args */ 1451 /* Parse the input args */
1396 while (1) 1452 while (1)
1397 { 1453 {
1398 c = getopt (argc, argv, "nf:hbi:o:d:te:"); 1454 c = getopt (argc, argv, "nf:hbi:o:d:te:v:");
1399 if (c == -1) 1455 if (c == -1)
1400 break; 1456 break;
1401 1457
@@ -1423,6 +1479,8 @@ int main(int argc, char **argv)
1423 printf("\t\t-e <number of ms> Number of milliseconds to sleep between\n"); 1479 printf("\t\t-e <number of ms> Number of milliseconds to sleep between\n");
1424 printf("\t\t\tqueueing the last bitstream buffer and sending CMD_STOP\n"); 1480 printf("\t\t\tqueueing the last bitstream buffer and sending CMD_STOP\n");
1425 printf("\t\t\tUsed to test various timing scenarios for EOS\n"); 1481 printf("\t\t\tUsed to test various timing scenarios for EOS\n");
1482 printf("\t\t-v <dev_name>\n");
1483 printf("\t\t\tUsed to specify which device node is the decoder\n");
1426 break; 1484 break;
1427 case 'b': 1485 case 'b':
1428 use_drm_capbuff = 0; /* DO NOT use drm dss device*/ 1486 use_drm_capbuff = 0; /* DO NOT use drm dss device*/
@@ -1449,6 +1507,10 @@ int main(int argc, char **argv)
1449 case 'e': 1507 case 'e':
1450 sleep_time = 1000 * atoi(optarg); 1508 sleep_time = 1000 * atoi(optarg);
1451 break; 1509 break;
1510 case 'v':
1511 snprintf(dev_name, sizeof(dev_name),
1512 "%s", optarg);
1513 break;
1452 default: 1514 default:
1453 printf("Unrecognized argument %c\n", c); 1515 printf("Unrecognized argument %c\n", c);
1454 } 1516 }
@@ -1467,11 +1529,19 @@ int main(int argc, char **argv)
1467 return EXIT_FAILURE; 1529 return EXIT_FAILURE;
1468 } 1530 }
1469 1531
1532 if (strlen(dev_name) == 0) {
1533 ret = find_device(dev_name);
1534 if (ret)
1535 return EXIT_FAILURE;
1536 }
1537
1470 for (i = 0; i < num_devs; i++) { 1538 for (i = 0; i < num_devs; i++) {
1471 debug_printf("*** Calling open_device for device %d \n", i); 1539 debug_printf("*** Calling open_device for device %d \n", i);
1472 fds[i] = open_device(dev_name); 1540 fds[i] = open_device(dev_name);
1473 if (fds[i] < 0) 1541 if (fds[i] < 0) {
1542 printf("Failed to open device %s\n", dev_name);
1474 return EXIT_FAILURE; 1543 return EXIT_FAILURE;
1544 }
1475 debug_printf("*** device %d is fd %d", i, fds[i]); 1545 debug_printf("*** device %d is fd %d", i, fds[i]);
1476 } 1546 }
1477 1547