[PATCH] Statically linking libdvbv5 must include -ludev

2017-12-19 Thread Rafaël Carré
Signed-off-by: Rafaël Carré <fun...@videolan.org>
---
 lib/libdvbv5/libdvbv5.pc.in | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/libdvbv5/libdvbv5.pc.in b/lib/libdvbv5/libdvbv5.pc.in
index 7e3c4f5c..6b5f292d 100644
--- a/lib/libdvbv5/libdvbv5.pc.in
+++ b/lib/libdvbv5/libdvbv5.pc.in
@@ -6,5 +6,6 @@ libdir=@libdir@
 Name: libdvbv5
 Description: DVBv5 utility library
 Version: @PACKAGE_VERSION@
+Requires.private: libudev
 Libs: -L${libdir} -ldvbv5
 Cflags: -I${includedir}
-- 
2.14.1



Re: [PATCH] dvb-sat: do the best to tune if DiSEqC is disabled

2017-12-13 Thread Rafaël Carré
On 13/12/2017 13:58, Mauro Carvalho Chehab wrote:
> If sat_number is not filled (e.g. it is -1), the dvb-sat
> disables DiSEqC. However, currently, it also breaks support
> for non-bandstacking LNBf.
> 
> Change the logic to fix it. There is a drawback on this
> approach, though: usually, on bandstacking arrangements,
> only one device needs to feed power to the LNBf. The
> others don't need to send power. With the previous code,
> no power would be sent at all, if sat_number == -1.
> 
> Now, it will always power the LNBf when using it.
> 
> Signed-off-by: Mauro Carvalho Chehab <mche...@s-opensource.com>
> ---
>  lib/libdvbv5/dvb-sat.c | 48 
>  1 file changed, 24 insertions(+), 24 deletions(-)
> 
> diff --git a/lib/libdvbv5/dvb-sat.c b/lib/libdvbv5/dvb-sat.c
> index b012318c4195..8c04f66f973b 100644
> --- a/lib/libdvbv5/dvb-sat.c
> +++ b/lib/libdvbv5/dvb-sat.c
> @@ -523,11 +523,8 @@ static int dvbsat_diseqc_set_input(struct 
> dvb_v5_fe_parms_priv *parms,
>   struct diseqc_cmd cmd;
>   const struct dvb_sat_lnb_priv *lnb = (void *)parms->p.lnb;
>  
> - /* Negative numbers means to not use a DiSEqC switch */
> - if (parms->p.sat_number < 0) {
> - /* If not bandstack, warn if DiSEqC is disabled */
> - if (!lnb->freqrange[0].pol)
> - dvb_logwarn(_("DiSEqC disabled. Probably won't tune."));
> + if (sat_number < 0 && t) {
> + dvb_logwarn(_("DiSEqC disabled. Can't tune using 
> SCR/Unicable."));
>   return 0;
>   }
>  
> @@ -546,7 +543,7 @@ static int dvbsat_diseqc_set_input(struct 
> dvb_v5_fe_parms_priv *parms,
>   vol_high = 1;
>   } else {
>   /* Adjust voltage/tone accordingly */
> - if (parms->p.sat_number < 2) {
> + if (sat_number < 2) {
>   vol_high = pol_v ? 0 : 1;
>   tone_on = high_band;
>   }
> @@ -560,28 +557,31 @@ static int dvbsat_diseqc_set_input(struct 
> dvb_v5_fe_parms_priv *parms,
>   if (rc)
>   return rc;
>  
> - usleep(15 * 1000);
> -
> - if (!t)
> - rc = dvbsat_diseqc_write_to_port_group(parms, , high_band,
> - pol_v, sat_number);
> - else
> - rc = dvbsat_scr_odu_channel_change(parms, , high_band,
> - pol_v, sat_number, t);
> + if (sat_number >= 0) {
> + /* DiSEqC is enabled. Send DiSEqC commands */
> + usleep(15 * 1000);
>  
> - if (rc) {
> - dvb_logerr(_("sending diseq failed"));
> - return rc;
> - }
> - usleep((15 + parms->p.diseqc_wait) * 1000);
> + if (!t)
> + rc = dvbsat_diseqc_write_to_port_group(parms, , 
> high_band,
> + pol_v, 
> sat_number);
> + else
> + rc = dvbsat_scr_odu_channel_change(parms, , 
> high_band,
> + pol_v, 
> sat_number, t);
>  
> - /* miniDiSEqC/Toneburst commands are defined only for up to 2 
> sattelites */
> - if (parms->p.sat_number < 2) {
> - rc = dvb_fe_diseqc_burst(>p, parms->p.sat_number);
> - if (rc)
> + if (rc) {
> + dvb_logerr(_("sending diseq failed"));
>   return rc;
> + }
> + usleep((15 + parms->p.diseqc_wait) * 1000);
> +
> + /* miniDiSEqC/Toneburst commands are defined only for up to 2 
> sattelites */
> +         if (parms->p.sat_number < 2) {
> + rc = dvb_fe_diseqc_burst(>p, 
> parms->p.sat_number);
> + if (rc)
> + return rc;
> + }
> + usleep(15 * 1000);
>   }
> - usleep(15 * 1000);
>  
>   rc = dvb_fe_sec_tone(>p, tone_on ? SEC_TONE_ON : SEC_TONE_OFF);
>  
>



Tested-by:  Rafaël Carré <fun...@videolan.org>


[PATCH] dvbv5-zap: accept -S 0 option

2017-12-13 Thread Rafaël Carré
Signed-off-by: Rafaël Carré <fun...@videolan.org>
---
 utils/dvb/dvbv5-zap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/utils/dvb/dvbv5-zap.c b/utils/dvb/dvbv5-zap.c
index a88500d1..1b6dabd0 100644
--- a/utils/dvb/dvbv5-zap.c
+++ b/utils/dvb/dvbv5-zap.c
@@ -930,7 +930,7 @@ int main(int argc, char **argv)
goto err;
if (lnb >= 0)
parms->lnb = dvb_sat_get_lnb(lnb);
-   if (args.sat_number > 0)
+   if (args.sat_number >= 0)
parms->sat_number = args.sat_number;
parms->diseqc_wait = args.diseqc_wait;
parms->freq_bpf = args.freq_bpf;
-- 
2.14.1



[PATCH] dvb_local_read: ignore EAGAIN

2017-11-23 Thread Rafaël Carré
If the device has been opened with O_NONBLOCK, EAGAIN is a legitimate error

Signed-off-by: Rafaël Carré <fun...@videolan.org>
---
 lib/libdvbv5/dvb-dev-local.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/libdvbv5/dvb-dev-local.c b/lib/libdvbv5/dvb-dev-local.c
index eb2f0775..a9571ca5 100644
--- a/lib/libdvbv5/dvb-dev-local.c
+++ b/lib/libdvbv5/dvb-dev-local.c
@@ -577,7 +577,7 @@ static ssize_t dvb_local_read(struct dvb_open_descriptor 
*open_dev,
 
ret = read(fd, buf, count);
if (ret == -1) {
-   if (errno != EOVERFLOW)
+   if (errno != EOVERFLOW && errno != EAGAIN)
dvb_perror("read()");
return -errno;
}
-- 
2.14.1



[PATCH v2] dvb_logfunc: add a user private parameter

2017-11-16 Thread Rafaël Carré
This is useful if an application is using 2 different devices,
and want logging to be split by device, or if application logging
needs some private context.

Care has been taken to not break the API/ABI and only add new functions,
or only modify private structures.

A drawback is that when dvb_fe_open_flags() is called, the custom function
can not be set yet, so dvb_fe_open_flags() will log errors using the old
function without private context.

Signed-off-by: Rafaël Carré <fun...@videolan.org>
---
 lib/include/libdvbv5/dvb-dev.h | 21 
 lib/include/libdvbv5/dvb-log.h | 73 --
 lib/libdvbv5/dvb-dev.c | 13 
 lib/libdvbv5/dvb-fe-priv.h |  3 ++
 lib/libdvbv5/dvb-fe.c  |  8 +
 utils/dvb/dvbv5-daemon.c   |  9 +++---
 6 files changed, 85 insertions(+), 42 deletions(-)

diff --git a/lib/include/libdvbv5/dvb-dev.h b/lib/include/libdvbv5/dvb-dev.h
index 55e0f065..6dbd2ae7 100644
--- a/lib/include/libdvbv5/dvb-dev.h
+++ b/lib/include/libdvbv5/dvb-dev.h
@@ -234,6 +234,27 @@ struct dvb_dev_list *dvb_get_dev_info(struct dvb_device 
*dvb,
  */
 void dvb_dev_stop_monitor(struct dvb_device *dvb);
 
+/**
+ * @brief Sets the DVB verbosity and log function with context private data
+ * @ingroup dvb_device
+ *
+ * @param dvb  pointer to struct dvb_device to be used
+ * @param verbose  Verbosity level of the messages that will be printed
+ * @param logfunc  Callback function to be called when a log event
+ * happens. Can either store the event into a file or
+ * to print it at the TUI/GUI. Can be null.
+ * @param logpriv   Private data for log function
+ *
+ * @details Sets the function to report log errors and to set the verbosity
+ * level of debug report messages. If not called, or if logfunc is
+ * NULL, the libdvbv5 will report error and debug messages via stderr,
+ * and will use colors for the debug messages.
+ *
+ */
+void dvb_dev_set_logpriv(struct dvb_device *dvb,
+unsigned verbose,
+dvb_logfunc_priv logfunc, void *logpriv);
+
 /**
  * @brief Sets the DVB verbosity and log function
  * @ingroup dvb_device
diff --git a/lib/include/libdvbv5/dvb-log.h b/lib/include/libdvbv5/dvb-log.h
index 181a23c8..23cceede 100644
--- a/lib/include/libdvbv5/dvb-log.h
+++ b/lib/include/libdvbv5/dvb-log.h
@@ -43,61 +43,58 @@
 
 typedef void (*dvb_logfunc)(int level, const char *fmt, ...) __attribute__ (( 
format( printf, 2, 3 )));
 
+/**
+ * @typedef void (*dvb_logfunc)(void *logpriv, int level, const char *fmt, ...)
+ * @brief typedef used by dvb_fe_open2 for the log function with private 
context
+ * @ingroup ancillary
+ */
+
+typedef void (*dvb_logfunc_priv)(void *logpriv, int level, const char *fmt, 
...);
+
 /*
  * Macros used internally inside libdvbv5 frontend part, to output logs
  */
 
 #ifndef _DOXYGEN
 
-#ifndef __DVB_FE_PRIV_H
+struct dvb_v5_fe_parms;
+/**
+ * @brief retrieve the logging function with private data from the private fe 
params.
+ */
+dvb_logfunc_priv dvb_get_log_priv(struct dvb_v5_fe_parms *, void **);
 
-#define dvb_log(fmt, arg...) do {\
-   parms->logfunc(LOG_INFO, fmt, ##arg); \
-} while (0)
-#define dvb_logerr(fmt, arg...) do {\
-   parms->logfunc(LOG_ERR, fmt, ##arg); \
-} while (0)
-#define dvb_logdbg(fmt, arg...) do {\
-   parms->logfunc(LOG_DEBUG, fmt, ##arg); \
-} while (0)
-#define dvb_logwarn(fmt, arg...) do {\
-   parms->logfunc(LOG_WARNING, fmt, ##arg); \
-} while (0)
-#define dvb_loginfo(fmt, arg...) do {\
-   parms->logfunc(LOG_NOTICE, fmt, ##arg); \
-} while (0)
+#ifndef __DVB_FE_PRIV_H
 
-#define dvb_perror(msg) do {\
-   parms->logfunc(LOG_ERR, "%s: %s", msg, strerror(errno)); \
+#define dvb_loglevel(level, fmt, arg...) do {\
+void *priv;\
+dvb_logfunc_priv f = dvb_get_log_priv(parms, );\
+if (f) {\
+f(priv, level, fmt, ##arg);\
+} else {\
+parms->logfunc(level, fmt, ##arg); \
+}\
 } while (0)
 
 #else
 
-#define dvb_log(fmt, arg...) do {\
-   parms->p.logfunc(LOG_INFO, fmt, ##arg); \
-} while (0)
-#define dvb_logerr(fmt, arg...) do {\
-   parms->p.logfunc(LOG_ERR, fmt, ##arg); \
-} while (0)
-#define dvb_logdbg(fmt, arg...) do {\
-   parms->p.logfunc(LOG_DEBUG, fmt, ##arg); \
-} while (0)
-#define dvb_logwarn(fmt, arg...) do {\
-   parms->p.logfunc(LOG_WARNING, fmt, ##arg); \
-} while (0)
-#define dvb_loginfo(fmt, arg...) do {\
-   parms->p.logfunc(LOG_NOTICE, fmt, ##arg); \
-} while (0)
 #define dvb_loglevel(level, fmt, arg...) do {\
-   parms->p.logfunc(level, fmt, ##arg); \
-} while (0)
-
-#define dvb_perror(msg) do {\
-   parms->p.logfunc(LOG_ERR, "%s: %s", msg, strerror(errno)); \
+if (parms->logfunc_priv) {\
+parms->logfunc_priv(parms->logpriv, level, fmt, ##arg);\
+} else {\
+parms->p.logfunc(

Re: [PATCH v2] dvb_dev_get_fd(): return fd of local devices

2017-11-16 Thread Rafaël Carré
On 15/11/2017 15:25, Rafaël Carré wrote:
> This makes it possible to poll a local device.
> Getting the fd is preferrable to adding a dvb_dev_poll() function,
> because we can poll several fds together in an event-based program.
> 
> This is not implemented for remote devices, as polling a remote fd
> does not make sense.
> We could instead return the socket to know when to expect messages
> from the remote device, but the current implementation in
> dvb-dev-remote.c already runs a thread to receive remote messages
> as soon as possible.
> ---
> v2: get the private dvb_device_priv correctly
> 
>  lib/include/libdvbv5/dvb-dev.h | 12 
>  lib/libdvbv5/dvb-dev-local.c   |  6 ++
>  lib/libdvbv5/dvb-dev-priv.h|  1 +
>  lib/libdvbv5/dvb-dev.c | 11 +++
>  4 files changed, 30 insertions(+)
> 
> diff --git a/lib/include/libdvbv5/dvb-dev.h b/lib/include/libdvbv5/dvb-dev.h
> index 98bee5e7..55e0f065 100644
> --- a/lib/include/libdvbv5/dvb-dev.h
> +++ b/lib/include/libdvbv5/dvb-dev.h
> @@ -289,6 +289,18 @@ struct dvb_open_descriptor *dvb_dev_open(struct 
> dvb_device *dvb,
>   */
>  void dvb_dev_close(struct dvb_open_descriptor *open_dev);
>  
> +/**
> + * @brief returns fd from a local device
> + * This will not work for remote devices.
> + * @ingroup dvb_device
> + *
> + * @param open_dev   Points to the struct dvb_open_descriptor
> + *
> + * @return On success, returns the fd.
> + * Returns -1 on error.
> + */
> +int dvb_dev_get_fd(struct dvb_open_descriptor *open_dev);
> +
>  /**
>   * @brief read from a dvb demux or dvr file
>   * @ingroup dvb_device
> diff --git a/lib/libdvbv5/dvb-dev-local.c b/lib/libdvbv5/dvb-dev-local.c
> index b50b61b4..eb2f0775 100644
> --- a/lib/libdvbv5/dvb-dev-local.c
> +++ b/lib/libdvbv5/dvb-dev-local.c
> @@ -775,6 +775,11 @@ static void dvb_dev_local_free(struct dvb_device_priv 
> *dvb)
>   free(priv);
>  }
>  
> +static int dvb_local_get_fd(struct dvb_open_descriptor *open_dev)
> +{
> +return open_dev->fd;
> +}
> +
>  /* Initialize for local usage */
>  void dvb_dev_local_init(struct dvb_device_priv *dvb)
>  {
> @@ -788,6 +793,7 @@ void dvb_dev_local_init(struct dvb_device_priv *dvb)
>   ops->stop_monitor = dvb_local_stop_monitor;
>   ops->open = dvb_local_open;
>   ops->close = dvb_local_close;
> + ops->get_fd = dvb_local_get_fd;
>  
>   ops->dmx_stop = dvb_local_dmx_stop;
>   ops->set_bufsize = dvb_local_set_bufsize;
> diff --git a/lib/libdvbv5/dvb-dev-priv.h b/lib/libdvbv5/dvb-dev-priv.h
> index e05fcad2..2e69f766 100644
> --- a/lib/libdvbv5/dvb-dev-priv.h
> +++ b/lib/libdvbv5/dvb-dev-priv.h
> @@ -72,6 +72,7 @@ struct dvb_dev_ops {
>   int (*fe_get_stats)(struct dvb_v5_fe_parms *p);
>  
>   void (*free)(struct dvb_device_priv *dvb);
> + int (*get_fd)(struct dvb_open_descriptor *dvb);
>  };
>  
>  struct dvb_device_priv {
> diff --git a/lib/libdvbv5/dvb-dev.c b/lib/libdvbv5/dvb-dev.c
> index 7e2da1fb..e6a8fc76 100644
> --- a/lib/libdvbv5/dvb-dev.c
> +++ b/lib/libdvbv5/dvb-dev.c
> @@ -218,6 +218,17 @@ struct dvb_open_descriptor *dvb_dev_open(struct 
> dvb_device *d,
>   return ops->open(dvb, sysname, flags);
>  }
>  
> +int dvb_dev_get_fd(struct dvb_open_descriptor *open_dev)
> +{
> + struct dvb_device_priv *dvb = open_dev->dvb;
> + struct dvb_dev_ops *ops = >ops;
> +
> + if (!ops->get_fd)
> + return -1;
> +
> + return ops->get_fd(open_dev);
> +}
> +
>  void dvb_dev_close(struct dvb_open_descriptor *open_dev)
>  {
>   struct dvb_device_priv *dvb = open_dev->dvb;
> 

Signed-off-by: Rafaël Carré <fun...@videolan.org>


Re: [PATCH 2/2] dvbv5-daemon: 0 is a valid fd

2017-11-16 Thread Rafaël Carré
On 16/11/2017 12:25, Mauro Carvalho Chehab wrote:
> Em Wed, 15 Nov 2017 12:33:36 +0100
> Rafaël Carré <fun...@videolan.org> escreveu:
> 
>> ---
>>  utils/dvb/dvbv5-daemon.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/utils/dvb/dvbv5-daemon.c b/utils/dvb/dvbv5-daemon.c
>> index 58485ac6..711694e0 100644
>> --- a/utils/dvb/dvbv5-daemon.c
>> +++ b/utils/dvb/dvbv5-daemon.c
>> @@ -570,7 +570,7 @@ void dvb_remote_log(void *priv, int level, const char 
>> *fmt, ...)
>>  
>>  va_end(ap);
>>  
>> -if (fd > 0)
>> +if (fd >= 0)
>>  send_data(fd, "%i%s%i%s", 0, "log", level, buf);
>>  else
>>  local_log(level, buf);

Signed-off-by: Rafaël Carré <fun...@videolan.org>

> 
> Patch looks OK. Just need a description explaining why we
> need to consider fd == 0 and a SOB.

Sorry, I am not used to do sign-off, will try to remember.

fd == 0 can happen if the application closes stdin/out/err then opens a
new fd.

Should I put this in the commit log?

> Thanks,
> Mauro
> 



[PATCH v2] dvb_dev_get_fd(): return fd of local devices

2017-11-15 Thread Rafaël Carré
This makes it possible to poll a local device.
Getting the fd is preferrable to adding a dvb_dev_poll() function,
because we can poll several fds together in an event-based program.

This is not implemented for remote devices, as polling a remote fd
does not make sense.
We could instead return the socket to know when to expect messages
from the remote device, but the current implementation in
dvb-dev-remote.c already runs a thread to receive remote messages
as soon as possible.
---
v2: get the private dvb_device_priv correctly

 lib/include/libdvbv5/dvb-dev.h | 12 
 lib/libdvbv5/dvb-dev-local.c   |  6 ++
 lib/libdvbv5/dvb-dev-priv.h|  1 +
 lib/libdvbv5/dvb-dev.c | 11 +++
 4 files changed, 30 insertions(+)

diff --git a/lib/include/libdvbv5/dvb-dev.h b/lib/include/libdvbv5/dvb-dev.h
index 98bee5e7..55e0f065 100644
--- a/lib/include/libdvbv5/dvb-dev.h
+++ b/lib/include/libdvbv5/dvb-dev.h
@@ -289,6 +289,18 @@ struct dvb_open_descriptor *dvb_dev_open(struct dvb_device 
*dvb,
  */
 void dvb_dev_close(struct dvb_open_descriptor *open_dev);
 
+/**
+ * @brief returns fd from a local device
+ * This will not work for remote devices.
+ * @ingroup dvb_device
+ *
+ * @param open_dev Points to the struct dvb_open_descriptor
+ *
+ * @return On success, returns the fd.
+ * Returns -1 on error.
+ */
+int dvb_dev_get_fd(struct dvb_open_descriptor *open_dev);
+
 /**
  * @brief read from a dvb demux or dvr file
  * @ingroup dvb_device
diff --git a/lib/libdvbv5/dvb-dev-local.c b/lib/libdvbv5/dvb-dev-local.c
index b50b61b4..eb2f0775 100644
--- a/lib/libdvbv5/dvb-dev-local.c
+++ b/lib/libdvbv5/dvb-dev-local.c
@@ -775,6 +775,11 @@ static void dvb_dev_local_free(struct dvb_device_priv *dvb)
free(priv);
 }
 
+static int dvb_local_get_fd(struct dvb_open_descriptor *open_dev)
+{
+return open_dev->fd;
+}
+
 /* Initialize for local usage */
 void dvb_dev_local_init(struct dvb_device_priv *dvb)
 {
@@ -788,6 +793,7 @@ void dvb_dev_local_init(struct dvb_device_priv *dvb)
ops->stop_monitor = dvb_local_stop_monitor;
ops->open = dvb_local_open;
ops->close = dvb_local_close;
+   ops->get_fd = dvb_local_get_fd;
 
ops->dmx_stop = dvb_local_dmx_stop;
ops->set_bufsize = dvb_local_set_bufsize;
diff --git a/lib/libdvbv5/dvb-dev-priv.h b/lib/libdvbv5/dvb-dev-priv.h
index e05fcad2..2e69f766 100644
--- a/lib/libdvbv5/dvb-dev-priv.h
+++ b/lib/libdvbv5/dvb-dev-priv.h
@@ -72,6 +72,7 @@ struct dvb_dev_ops {
int (*fe_get_stats)(struct dvb_v5_fe_parms *p);
 
void (*free)(struct dvb_device_priv *dvb);
+   int (*get_fd)(struct dvb_open_descriptor *dvb);
 };
 
 struct dvb_device_priv {
diff --git a/lib/libdvbv5/dvb-dev.c b/lib/libdvbv5/dvb-dev.c
index 7e2da1fb..e6a8fc76 100644
--- a/lib/libdvbv5/dvb-dev.c
+++ b/lib/libdvbv5/dvb-dev.c
@@ -218,6 +218,17 @@ struct dvb_open_descriptor *dvb_dev_open(struct dvb_device 
*d,
return ops->open(dvb, sysname, flags);
 }
 
+int dvb_dev_get_fd(struct dvb_open_descriptor *open_dev)
+{
+   struct dvb_device_priv *dvb = open_dev->dvb;
+   struct dvb_dev_ops *ops = >ops;
+
+   if (!ops->get_fd)
+   return -1;
+
+   return ops->get_fd(open_dev);
+}
+
 void dvb_dev_close(struct dvb_open_descriptor *open_dev)
 {
struct dvb_device_priv *dvb = open_dev->dvb;
-- 
2.14.1



[PATCH 1/2] dvb_logfunc: add a user private parameter

2017-11-15 Thread Rafaël Carré
---
 lib/include/libdvbv5/dvb-dev.h |  3 ++-
 lib/include/libdvbv5/dvb-fe.h  |  9 +++--
 lib/include/libdvbv5/dvb-log.h | 33 +
 lib/libdvbv5/dvb-dev.c |  3 ++-
 lib/libdvbv5/dvb-fe.c  | 15 ---
 lib/libdvbv5/dvb-log.c |  3 ++-
 utils/dvb/dvb-fe-tool.c|  2 +-
 utils/dvb/dvbv5-daemon.c   |  9 +
 utils/dvb/dvbv5-scan.c |  2 +-
 utils/dvb/dvbv5-zap.c  |  2 +-
 10 files changed, 46 insertions(+), 35 deletions(-)

diff --git a/lib/include/libdvbv5/dvb-dev.h b/lib/include/libdvbv5/dvb-dev.h
index 55e0f065..396fcd07 100644
--- a/lib/include/libdvbv5/dvb-dev.h
+++ b/lib/include/libdvbv5/dvb-dev.h
@@ -243,6 +243,7 @@ void dvb_dev_stop_monitor(struct dvb_device *dvb);
  * @param logfunc  Callback function to be called when a log event
  * happens. Can either store the event into a file or
  * to print it at the TUI/GUI. Can be null.
+ * @param logpriv   Private data for log function
  *
  * @details Sets the function to report log errors and to set the verbosity
  * level of debug report messages. If not called, or if logfunc is
@@ -252,7 +253,7 @@ void dvb_dev_stop_monitor(struct dvb_device *dvb);
  */
 void dvb_dev_set_log(struct dvb_device *dvb,
 unsigned verbose,
-dvb_logfunc logfunc);
+dvb_logfunc logfunc, void *logpriv);
 
 /**
  * @brief Opens a dvb device
diff --git a/lib/include/libdvbv5/dvb-fe.h b/lib/include/libdvbv5/dvb-fe.h
index 1d3565ec..107cb03d 100644
--- a/lib/include/libdvbv5/dvb-fe.h
+++ b/lib/include/libdvbv5/dvb-fe.h
@@ -107,6 +107,7 @@
  * @param freq_bpf SCR/Unicable band-pass filter frequency to use, 
in kHz
  * @param verbose  Verbosity level of the library (RW)
  * @param dvb_logfunc  Function used to write log messages (RO)
+ * @param logpriv  Private data for logging function (RO)
  * @param default_charset  Name of the charset used by the DVB standard 
(RW)
  * @param output_charset   Name of the charset to output (system specific) 
(RW)
  *
@@ -140,7 +141,8 @@ struct dvb_v5_fe_parms {
 
/* Function to write DVB logs */
unsignedverbose;
-   dvb_logfunc logfunc;
+   dvb_logfunc logfunc;
+   void*logpriv;
 
/* Charsets to be used by the conversion utilities */
char*default_charset;
@@ -176,6 +178,7 @@ struct dvb_v5_fe_parms *dvb_fe_dummy(void);
  * happens. Can either store the event into a file
  * or to print it at the TUI/GUI. If NULL, the
  * library will use its internal handler.
+ * @param logpriv  Private data for dvb_logfunc
  * @param flagsFlags to be passed to open. Currently 
only two
  * flags are supported: O_RDONLY or O_RDWR.
  * Using O_NONBLOCK may hit unexpected issues.
@@ -195,6 +198,7 @@ struct dvb_v5_fe_parms *dvb_fe_open_flags(int adapter, int 
frontend,
  unsigned verbose,
  unsigned use_legacy_call,
  dvb_logfunc logfunc,
+ void *logpriv,
  int flags);
 
 /**
@@ -231,6 +235,7 @@ struct dvb_v5_fe_parms *dvb_fe_open(int adapter, int 
frontend,
  * @param logfunc  Callback function to be called when a log event
  * happens. Can either store the event into a file
  * or to print it at the TUI/GUI.
+ * @param logpriv  Private data for dvb_logfunc
  *
  * @details This function should be called before using any other function at
  * the frontend library (or the other alternatives: dvb_fe_open() or
@@ -240,7 +245,7 @@ struct dvb_v5_fe_parms *dvb_fe_open(int adapter, int 
frontend,
  */
 struct dvb_v5_fe_parms *dvb_fe_open2(int adapter, int frontend,
unsigned verbose, unsigned use_legacy_call,
-   dvb_logfunc logfunc);
+   dvb_logfunc logfunc, void *logpriv);
 
 /**
  * @brief Closes the frontend and frees allocated resources
diff --git a/lib/include/libdvbv5/dvb-log.h b/lib/include/libdvbv5/dvb-log.h
index 181a23c8..beba7aba 100644
--- a/lib/include/libdvbv5/dvb-log.h
+++ b/lib/include/libdvbv5/dvb-log.h
@@ -36,12 +36,12 @@
  */
 
 /**
- * @typedef void (*dvb_logfunc)(int level, const char *fmt, ...)
+ * @typedef void (*dvb_logfunc)(void *logpriv, int level, const char *fmt, ...)
  * @brief typedef used by dvb_fe_open2 for the log function
  * @ingroup ancillary
  */
 
-typedef void 

[PATCH 2/2] dvbv5-daemon: 0 is a valid fd

2017-11-15 Thread Rafaël Carré
---
 utils/dvb/dvbv5-daemon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/utils/dvb/dvbv5-daemon.c b/utils/dvb/dvbv5-daemon.c
index 58485ac6..711694e0 100644
--- a/utils/dvb/dvbv5-daemon.c
+++ b/utils/dvb/dvbv5-daemon.c
@@ -570,7 +570,7 @@ void dvb_remote_log(void *priv, int level, const char *fmt, 
...)
 
va_end(ap);
 
-   if (fd > 0)
+   if (fd >= 0)
send_data(fd, "%i%s%i%s", 0, "log", level, buf);
else
local_log(level, buf);
-- 
2.14.1



[PATCH] dvb_dev_get_fd(): return fd of local devices

2017-11-15 Thread Rafaël Carré
This makes it possible to poll a local device.
Getting the fd is preferrable to adding a dvb_dev_poll() function,
because we can poll several fds together in an event-based program.

This is not implemented for remote devices, as polling a remote fd
does not make sense.
We could instead return the socket to know when to expect messages
from the remote device, but the current implementation in
dvb-dev-remote.c already runs a thread to receive remote messages
as soon as possible.
---

Note, after reading README, I did not bump the library version.

Comments welcome

 lib/include/libdvbv5/dvb-dev.h | 12 
 lib/libdvbv5/dvb-dev-local.c   |  6 ++
 lib/libdvbv5/dvb-dev-priv.h|  1 +
 lib/libdvbv5/dvb-dev.c | 11 +++
 4 files changed, 30 insertions(+)

diff --git a/lib/include/libdvbv5/dvb-dev.h b/lib/include/libdvbv5/dvb-dev.h
index 98bee5e7..55e0f065 100644
--- a/lib/include/libdvbv5/dvb-dev.h
+++ b/lib/include/libdvbv5/dvb-dev.h
@@ -289,6 +289,18 @@ struct dvb_open_descriptor *dvb_dev_open(struct dvb_device 
*dvb,
  */
 void dvb_dev_close(struct dvb_open_descriptor *open_dev);
 
+/**
+ * @brief returns fd from a local device
+ * This will not work for remote devices.
+ * @ingroup dvb_device
+ *
+ * @param open_dev Points to the struct dvb_open_descriptor
+ *
+ * @return On success, returns the fd.
+ * Returns -1 on error.
+ */
+int dvb_dev_get_fd(struct dvb_open_descriptor *open_dev);
+
 /**
  * @brief read from a dvb demux or dvr file
  * @ingroup dvb_device
diff --git a/lib/libdvbv5/dvb-dev-local.c b/lib/libdvbv5/dvb-dev-local.c
index b50b61b4..eb2f0775 100644
--- a/lib/libdvbv5/dvb-dev-local.c
+++ b/lib/libdvbv5/dvb-dev-local.c
@@ -775,6 +775,11 @@ static void dvb_dev_local_free(struct dvb_device_priv *dvb)
free(priv);
 }
 
+static int dvb_local_get_fd(struct dvb_open_descriptor *open_dev)
+{
+return open_dev->fd;
+}
+
 /* Initialize for local usage */
 void dvb_dev_local_init(struct dvb_device_priv *dvb)
 {
@@ -788,6 +793,7 @@ void dvb_dev_local_init(struct dvb_device_priv *dvb)
ops->stop_monitor = dvb_local_stop_monitor;
ops->open = dvb_local_open;
ops->close = dvb_local_close;
+   ops->get_fd = dvb_local_get_fd;
 
ops->dmx_stop = dvb_local_dmx_stop;
ops->set_bufsize = dvb_local_set_bufsize;
diff --git a/lib/libdvbv5/dvb-dev-priv.h b/lib/libdvbv5/dvb-dev-priv.h
index e05fcad2..2e69f766 100644
--- a/lib/libdvbv5/dvb-dev-priv.h
+++ b/lib/libdvbv5/dvb-dev-priv.h
@@ -72,6 +72,7 @@ struct dvb_dev_ops {
int (*fe_get_stats)(struct dvb_v5_fe_parms *p);
 
void (*free)(struct dvb_device_priv *dvb);
+   int (*get_fd)(struct dvb_open_descriptor *dvb);
 };
 
 struct dvb_device_priv {
diff --git a/lib/libdvbv5/dvb-dev.c b/lib/libdvbv5/dvb-dev.c
index 7e2da1fb..447c9fd5 100644
--- a/lib/libdvbv5/dvb-dev.c
+++ b/lib/libdvbv5/dvb-dev.c
@@ -218,6 +218,17 @@ struct dvb_open_descriptor *dvb_dev_open(struct dvb_device 
*d,
return ops->open(dvb, sysname, flags);
 }
 
+int dvb_dev_get_fd(struct dvb_open_descriptor *open_dev)
+{
+   struct dvb_device_priv *dvb = (void *)open_dev;
+   struct dvb_dev_ops *ops = >ops;
+
+   if (!ops->get_fd)
+   return -1;
+
+   return ops->get_fd(open_dev);
+}
+
 void dvb_dev_close(struct dvb_open_descriptor *open_dev)
 {
struct dvb_device_priv *dvb = open_dev->dvb;
-- 
2.14.1



[PATCH] dvb_local_open(): strdup fname before calling dvb_fe_open_fname()

2017-11-14 Thread Rafaël Carré
Issue spotted by valgrind:

==5290== Invalid free() / delete / delete[] / realloc()
==5290==at 0x4C30D3B: free (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5290==by 0x4E54401: free_dvb_dev (dvb-dev.c:49)
==5290==by 0x4E5449A: dvb_dev_free_devices (dvb-dev.c:94)
==5290==by 0x4E547BA: dvb_dev_free (dvb-dev.c:121)
==5290==by 0x10881A: main (leak.c:26)
==5290==  Address 0x5e55910 is 0 bytes inside a block of size 28 free'd
==5290==at 0x4C30D3B: free (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5290==by 0x4E56504: dvb_v5_free (dvb-fe.c:85)
==5290==by 0x4E547B2: dvb_dev_free (dvb-dev.c:119)
==5290==by 0x10881A: main (leak.c:26)
==5290==  Block was alloc'd at
==5290==at 0x4C2FB0F: malloc (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5290==by 0x5119C39: strdup (strdup.c:42)
==5290==by 0x4E55B42: handle_device_change (dvb-dev-local.c:137)
==5290==by 0x4E561DA: dvb_local_find (dvb-dev-local.c:323)
==5290==by 0x10880E: main (leak.c:10)

Signed-off-by: Rafaël Carré <fun...@videolan.org>
---
 lib/libdvbv5/dvb-dev-local.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/libdvbv5/dvb-dev-local.c b/lib/libdvbv5/dvb-dev-local.c
index 920e81fb..b50b61b4 100644
--- a/lib/libdvbv5/dvb-dev-local.c
+++ b/lib/libdvbv5/dvb-dev-local.c
@@ -440,7 +440,7 @@ static struct dvb_open_descriptor
 */
flags &= ~O_NONBLOCK;
 
-   ret = dvb_fe_open_fname(parms, dev->path, flags);
+   ret = dvb_fe_open_fname(parms, strdup(dev->path), flags);
if (ret) {
free(open_dev);
return NULL;
-- 
2.14.1



Re: [PATCH 2/2] sdlcam: ignore binary

2017-11-13 Thread Rafaël Carré
Adding linux-media, thanks

On 13/11/2017 10:20, Pavel Machek wrote:
> On Mon 2017-11-13 10:19:08, Rafaël Carré wrote:
>> Signed-off-by: Rafaël Carré <fun...@videolan.org>
> 
> Acked-by: PavelMachek <pa...@ucw.cz>
> 
>> ---
>>  contrib/test/.gitignore | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/contrib/test/.gitignore b/contrib/test/.gitignore
>> index ad64325b..5bd81d01 100644
>> --- a/contrib/test/.gitignore
>> +++ b/contrib/test/.gitignore
>> @@ -8,3 +8,4 @@ stress-buffer
>>  v4l2gl
>>  v4l2grab
>>  mc_nextgen_test
>> +sdlcam
> 



[PATCH 2/2] sdlcam: ignore binary

2017-11-13 Thread Rafaël Carré
Signed-off-by: Rafaël Carré <fun...@videolan.org>
---
 contrib/test/.gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/contrib/test/.gitignore b/contrib/test/.gitignore
index ad64325b..5bd81d01 100644
--- a/contrib/test/.gitignore
+++ b/contrib/test/.gitignore
@@ -8,3 +8,4 @@ stress-buffer
 v4l2gl
 v4l2grab
 mc_nextgen_test
+sdlcam
-- 
2.14.1



[PATCH 1/2] sdlcam: fix linking

2017-11-13 Thread Rafaël Carré
Signed-off-by: Rafaël Carré <fun...@videolan.org>
---
 contrib/test/Makefile.am | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/test/Makefile.am b/contrib/test/Makefile.am
index 6a4303d7..0188fe21 100644
--- a/contrib/test/Makefile.am
+++ b/contrib/test/Makefile.am
@@ -37,7 +37,7 @@ v4l2gl_LDADD = ../../lib/libv4l2/libv4l2.la 
../../lib/libv4lconvert/libv4lconver
 
 sdlcam_LDFLAGS = $(JPEG_LIBS) $(SDL2_LIBS) -lm -ldl -lrt
 sdlcam_CFLAGS = -I../.. $(SDL2_CFLAGS)
-sdlcam_LDADD = ../../lib/libv4l2/.libs/libv4l2.a  
../../lib/libv4lconvert/.libs/libv4lconvert.a
+sdlcam_LDADD = ../../lib/libv4l2/libv4l2.la  
../../lib/libv4lconvert/libv4lconvert.la
 
 mc_nextgen_test_CFLAGS = $(LIBUDEV_CFLAGS)
 mc_nextgen_test_LDFLAGS = $(LIBUDEV_LIBS)
-- 
2.14.1



Re: [PATCH 2/2] sdlcam: ignore binary

2017-11-11 Thread Rafaël Carré
On 11/10/2017 05:05 PM, Rafaël Carré wrote:
> ---
>  contrib/test/.gitignore | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/contrib/test/.gitignore b/contrib/test/.gitignore
> index ad64325b..5bd81d01 100644
> --- a/contrib/test/.gitignore
> +++ b/contrib/test/.gitignore
> @@ -8,3 +8,4 @@ stress-buffer
>  v4l2gl
>  v4l2grab
>  mc_nextgen_test
> +sdlcam
> 

Signed-off-by: Rafaël Carré <fun...@videolan.org>


Re: [PATCH 1/2] sdlcam: fix linking

2017-11-11 Thread Rafaël Carré
On 11/10/2017 05:05 PM, Rafaël Carré wrote:
> ---
>  contrib/test/Makefile.am | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/contrib/test/Makefile.am b/contrib/test/Makefile.am
> index 6a4303d7..0188fe21 100644
> --- a/contrib/test/Makefile.am
> +++ b/contrib/test/Makefile.am
> @@ -37,7 +37,7 @@ v4l2gl_LDADD = ../../lib/libv4l2/libv4l2.la 
> ../../lib/libv4lconvert/libv4lconver
>  
>  sdlcam_LDFLAGS = $(JPEG_LIBS) $(SDL2_LIBS) -lm -ldl -lrt
>  sdlcam_CFLAGS = -I../.. $(SDL2_CFLAGS)
> -sdlcam_LDADD = ../../lib/libv4l2/.libs/libv4l2.a  
> ../../lib/libv4lconvert/.libs/libv4lconvert.a
> +sdlcam_LDADD = ../../lib/libv4l2/libv4l2.la  
> ../../lib/libv4lconvert/libv4lconvert.la
>  
>  mc_nextgen_test_CFLAGS = $(LIBUDEV_CFLAGS)
>  mc_nextgen_test_LDFLAGS = $(LIBUDEV_LIBS)
> 

Signed-off-by: Rafaël Carré <fun...@videolan.org>


[PATCH 1/2] sdlcam: fix linking

2017-11-10 Thread Rafaël Carré
---
 contrib/test/Makefile.am | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/test/Makefile.am b/contrib/test/Makefile.am
index 6a4303d7..0188fe21 100644
--- a/contrib/test/Makefile.am
+++ b/contrib/test/Makefile.am
@@ -37,7 +37,7 @@ v4l2gl_LDADD = ../../lib/libv4l2/libv4l2.la 
../../lib/libv4lconvert/libv4lconver
 
 sdlcam_LDFLAGS = $(JPEG_LIBS) $(SDL2_LIBS) -lm -ldl -lrt
 sdlcam_CFLAGS = -I../.. $(SDL2_CFLAGS)
-sdlcam_LDADD = ../../lib/libv4l2/.libs/libv4l2.a  
../../lib/libv4lconvert/.libs/libv4lconvert.a
+sdlcam_LDADD = ../../lib/libv4l2/libv4l2.la  
../../lib/libv4lconvert/libv4lconvert.la
 
 mc_nextgen_test_CFLAGS = $(LIBUDEV_CFLAGS)
 mc_nextgen_test_LDFLAGS = $(LIBUDEV_LIBS)
-- 
2.14.1



[PATCH 2/2] sdlcam: ignore binary

2017-11-10 Thread Rafaël Carré
---
 contrib/test/.gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/contrib/test/.gitignore b/contrib/test/.gitignore
index ad64325b..5bd81d01 100644
--- a/contrib/test/.gitignore
+++ b/contrib/test/.gitignore
@@ -8,3 +8,4 @@ stress-buffer
 v4l2gl
 v4l2grab
 mc_nextgen_test
+sdlcam
-- 
2.14.1