setpid.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #define USAGE \
  2. "\n" \
  3. "\nSet video and audio PIDs in the demux; useful only if you have" \
  4. "\na hardware MPEG decoder and you're tuned to a transport stream." \
  5. "\n" \
  6. "\nusage: DEMUX=/dev/dvb/adapterX/demuxX setpid video_pid audio_pid" \
  7. "\n"
  8. #include <unistd.h>
  9. #include <stdlib.h>
  10. #include <sys/types.h>
  11. #include <sys/stat.h>
  12. #include <sys/ioctl.h>
  13. #include <fcntl.h>
  14. #include <stdio.h>
  15. #include <linux/dvb/dmx.h>
  16. static
  17. int setup_demux (char *dmxdev, int video_pid, int audio_pid)
  18. {
  19. int vfd, afd;
  20. struct dmx_pes_filter_params pesfilter;
  21. printf ("video_pid == 0x%04x\n", video_pid);
  22. printf ("audio_pid == 0x%04x\n", audio_pid);
  23. if ((vfd = open (dmxdev, O_RDWR)) < 0) {
  24. perror("open 1");
  25. return -1;
  26. }
  27. pesfilter.pid = video_pid;
  28. pesfilter.input = DMX_IN_FRONTEND;
  29. pesfilter.output = DMX_OUT_DECODER;
  30. pesfilter.pes_type = DMX_PES_VIDEO;
  31. pesfilter.flags = DMX_IMMEDIATE_START;
  32. if (ioctl (vfd, DMX_SET_PES_FILTER, &pesfilter) < 0) {
  33. perror("ioctl DMX_SET_PES_FILTER (video)");
  34. return -1;
  35. }
  36. close (vfd);
  37. if ((afd = open (dmxdev, O_RDWR)) < 0) {
  38. perror("open 1");
  39. return -1;
  40. }
  41. pesfilter.pid = audio_pid;
  42. pesfilter.input = DMX_IN_FRONTEND;
  43. pesfilter.output = DMX_OUT_DECODER;
  44. pesfilter.pes_type = DMX_PES_AUDIO;
  45. pesfilter.flags = DMX_IMMEDIATE_START;
  46. if (ioctl (afd, DMX_SET_PES_FILTER, &pesfilter) < 0) {
  47. perror("ioctl DMX_SET_PES_FILTER (audio)");
  48. return -1;
  49. }
  50. close (afd);
  51. return 0;
  52. }
  53. int main (int argc, char **argv)
  54. {
  55. char *dmxdev = "/dev/dvb/adapter0/demux0";
  56. int video_pid, audio_pid;
  57. if (argc != 3) {
  58. printf ("\nusage: %s <video pid> <audio pid>\n\n" USAGE, argv[0]);
  59. exit (1);
  60. }
  61. if (getenv("DEMUX"))
  62. dmxdev = getenv("DEMUX");
  63. printf("setpid: using '%s'\n", dmxdev);
  64. video_pid = strtol(argv[1], NULL, 0);
  65. audio_pid = strtol(argv[2], NULL, 0);
  66. if (setup_demux (dmxdev, video_pid, audio_pid) < 0)
  67. return 1;
  68. return 0;
  69. }