libdvbv5: fix dvb_get_pmt_pid API
authorMauro Carvalho Chehab <m.chehab@samsung.com>
Sun, 7 Sep 2014 11:48:35 +0000 (08:48 -0300)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Sun, 7 Sep 2014 11:48:35 +0000 (08:48 -0300)
All functions on the demux API uses an opened fd, except for
dvb_get_pmt_pid() that were using a filename.

Change it to make the API coherent.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
lib/include/libdvbv5/dvb-demux.h
lib/libdvbv5/dvb-demux.c
utils/dvb/dvbv5-zap.c

index 13364b8..c57b89c 100644 (file)
@@ -114,18 +114,19 @@ int dvb_set_section_filter(int dmxfd, int pid, unsigned filtsize,
                           unsigned int flags);
 
 /**
- * @fn dvb_get_pmt_pid(const char *dmxdev, int sid)
+ * @fn int dvb_get_pmt_pid(int dmxfd, int sid)
  * @brief read the contents of the MPEG-TS PAT table, seeking for
  *                     an specific service ID
  *
- * @param dmxdev       File name of the demux to be opened
+ * @param dmxfd                File descriptor for the demux device
  * @param sid          Session ID to seeking
  *
  * This function currently assumes that the hope PAT fits into one session.
- * At return, it returns a negative value if error or the PID associated with
+ *
+ * @return At return, it returns a negative value if error or the PID associated with
  * the desired Session ID.
  */
-int dvb_get_pmt_pid(const char *dmxdev, int sid);
+int dvb_get_pmt_pid(int dmxfd, int sid);
 
 #ifdef __cplusplus
 }
index 0bb3d48..81bc9a8 100644 (file)
@@ -125,7 +125,7 @@ int dvb_set_section_filter(int dmxfd, int pid, unsigned filtsize,
        return 0;
 }
 
-int dvb_get_pmt_pid(const char *dmxdev, int sid)
+int dvb_get_pmt_pid(int dmxfd, int sid)
 {
        int patfd, count;
        int pmt_pid = 0;
@@ -142,11 +142,6 @@ int dvb_get_pmt_pid(const char *dmxdev, int sid)
        f.timeout = 0;
        f.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC;
 
-       if ((patfd = open(dmxdev, O_RDWR)) < 0) {
-               perror("openening pat demux failed");
-               return -1;
-       }
-
        if (ioctl(patfd, DMX_SET_FILTER, &f) == -1) {
                perror("ioctl DMX_SET_FILTER failed");
                close(patfd);
@@ -181,6 +176,5 @@ int dvb_get_pmt_pid(const char *dmxdev, int sid)
                }
        }
 
-       close(patfd);
        return pmt_pid;
 }
index 81960de..498d3dd 100644 (file)
@@ -711,7 +711,7 @@ int main(int argc, char **argv)
        int lnb = -1, idx = -1;
        int vpid = -1, apid = -1, sid = -1;
        int pmtpid = 0;
-       int pat_fd = -1, pmt_fd = -1;
+       int pat_fd = -1, pmt_fd = -1, sid_fd = -1;
        int audio_fd = -1, video_fd = -1;
        int dvr_fd = -1, file_fd = -1;
        int err = -1;
@@ -834,10 +834,18 @@ int main(int argc, char **argv)
                                sid);
                        goto err;
                }
-               pmtpid = dvb_get_pmt_pid(args.demux_dev, sid);
+
+               sid_fd = dvb_dmx_open(args.adapter, args.demux);
+               if (sid_fd < 0) {
+                       perror("opening pat demux failed");
+                       return -1;
+               }
+               pmtpid = dvb_get_pmt_pid(sid_fd, sid);
+               dvb_dmx_close(sid_fd);
                if (pmtpid <= 0) {
                        fprintf(stderr, "couldn't find pmt-pid for sid %04x\n",
                                sid);
+
                        goto err;
                }