Re: [FFmpeg-devel] [PATCH] lavu/threadmessage: add av_thread_message_queue_nelem()

2018-04-26 Thread Clément Bœsch
On Mon, Apr 23, 2018 at 02:13:41AM +0200, Michael Niedermayer wrote:
[...]
> doesnt document the AVERROR case
> 

added

> should be ok otherwise, no more comments from me
> 

thx, applied

-- 
Clément B.


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavu/threadmessage: add av_thread_message_queue_nelem()

2018-04-22 Thread Michael Niedermayer
On Sun, Apr 22, 2018 at 09:33:04AM +0200, Clément Bœsch wrote:
> On Sun, Apr 22, 2018 at 02:51:16AM +0100, Rostislav Pehlivanov wrote:
> [...]
> > I think av_thread_message_queue_elems would be a better name, had to think
> > for a good period of time what "nelem" meant.
> 
> I'm afraid of "queue_elems" implying "queuing elements" so I went for
> the more explicit av_thread_message_queue_nb_elems() instead.
> 

> Also fixed the problem raised by Michael.

confirmed

[...]
> diff --git a/libavutil/threadmessage.h b/libavutil/threadmessage.h
> index 8480a0a3db..7ebf03a8ac 100644
> --- a/libavutil/threadmessage.h
> +++ b/libavutil/threadmessage.h
> @@ -95,6 +95,11 @@ void 
> av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq,
>  void av_thread_message_queue_set_free_func(AVThreadMessageQueue *mq,
> void (*free_func)(void *msg));
>  
> +/**
> + * Return the current number of messages in the queue.
> + */

doesnt document the AVERROR case

should be ok otherwise, no more comments from me

thx
also welcome back !

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

"Nothing to hide" only works if the folks in power share the values of
you and everyone you know entirely and always will -- Tom Scott



signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavu/threadmessage: add av_thread_message_queue_nelem()

2018-04-22 Thread Clément Bœsch
On Sun, Apr 22, 2018 at 12:33:14PM +0200, Marton Balint wrote:
> 
> 
> On Sun, 22 Apr 2018, Clément Bœsch wrote:
> 
> > On Sun, Apr 22, 2018 at 02:51:16AM +0100, Rostislav Pehlivanov wrote:
> > [...]
> > > I think av_thread_message_queue_elems would be a better name, had to think
> > > for a good period of time what "nelem" meant.
> > 
> > I'm afraid of "queue_elems" implying "queuing elements" so I went for
> > the more explicit av_thread_message_queue_nb_elems() instead.
> 
> I generally prefer nb_items instead of nb_elems. Use whichever you like.
> 

No personal opinion on this but the "element" semantic is already in use
in the API so I'd rather follow that.

-- 
Clément B.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavu/threadmessage: add av_thread_message_queue_nelem()

2018-04-22 Thread Marton Balint



On Sun, 22 Apr 2018, Clément Bœsch wrote:


On Sun, Apr 22, 2018 at 02:51:16AM +0100, Rostislav Pehlivanov wrote:
[...]

I think av_thread_message_queue_elems would be a better name, had to think
for a good period of time what "nelem" meant.


I'm afraid of "queue_elems" implying "queuing elements" so I went for
the more explicit av_thread_message_queue_nb_elems() instead.


I generally prefer nb_items instead of nb_elems. Use whichever you like.

Thanks,
Marton
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavu/threadmessage: add av_thread_message_queue_nelem()

2018-04-22 Thread Clément Bœsch
On Sun, Apr 22, 2018 at 02:51:16AM +0100, Rostislav Pehlivanov wrote:
[...]
> I think av_thread_message_queue_elems would be a better name, had to think
> for a good period of time what "nelem" meant.

I'm afraid of "queue_elems" implying "queuing elements" so I went for
the more explicit av_thread_message_queue_nb_elems() instead.

Also fixed the problem raised by Michael.

-- 
Clément B.
From 6647c716a31481b2d1348d03616557a63a6a0cef Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= 
Date: Sat, 21 Apr 2018 21:42:19 +0200
Subject: [PATCH] lavu/threadmessage: add av_thread_message_queue_nb_elems()

---
 doc/APIchanges |  3 +++
 libavutil/threadmessage.c  | 13 +
 libavutil/threadmessage.h  |  5 +
 libavutil/version.h|  2 +-
 tests/api/api-threadmessage-test.c |  4 +++-
 5 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 4f6ac2a031..8d305d5867 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2018-04-xx - xx - lavu 56.16.100 - threadmessage.h
+  Add av_thread_message_queue_nb_elems().
+
  8< - FFmpeg 4.0 was cut here  8< -
 
 2018-04-03 - d6fc031caf - lavu 56.13.100 - pixdesc.h
diff --git a/libavutil/threadmessage.c b/libavutil/threadmessage.c
index 872e9392b1..764b7fb813 100644
--- a/libavutil/threadmessage.c
+++ b/libavutil/threadmessage.c
@@ -102,6 +102,19 @@ void av_thread_message_queue_free(AVThreadMessageQueue 
**mq)
 #endif
 }
 
+int av_thread_message_queue_nb_elems(AVThreadMessageQueue *mq)
+{
+#if HAVE_THREADS
+int ret;
+pthread_mutex_lock(>lock);
+ret = av_fifo_size(mq->fifo);
+pthread_mutex_unlock(>lock);
+return ret / mq->elsize;
+#else
+return AVERROR(ENOSYS);
+#endif
+}
+
 #if HAVE_THREADS
 
 static int av_thread_message_queue_send_locked(AVThreadMessageQueue *mq,
diff --git a/libavutil/threadmessage.h b/libavutil/threadmessage.h
index 8480a0a3db..7ebf03a8ac 100644
--- a/libavutil/threadmessage.h
+++ b/libavutil/threadmessage.h
@@ -95,6 +95,11 @@ void 
av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq,
 void av_thread_message_queue_set_free_func(AVThreadMessageQueue *mq,
void (*free_func)(void *msg));
 
+/**
+ * Return the current number of messages in the queue.
+ */
+int av_thread_message_queue_nb_elems(AVThreadMessageQueue *mq);
+
 /**
  * Flush the message queue
  *
diff --git a/libavutil/version.h b/libavutil/version.h
index 387421775f..23567000a3 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR  15
+#define LIBAVUTIL_VERSION_MINOR  16
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
diff --git a/tests/api/api-threadmessage-test.c 
b/tests/api/api-threadmessage-test.c
index 05a8062b8c..3c693a70d1 100644
--- a/tests/api/api-threadmessage-test.c
+++ b/tests/api/api-threadmessage-test.c
@@ -130,7 +130,9 @@ static void *receiver_thread(void *arg)
 
 for (i = 0; i < rd->workload; i++) {
 if (rand() % rd->workload < rd->workload / 10) {
-av_log(NULL, AV_LOG_INFO, "receiver #%d: flushing the queue\n", 
rd->id);
+av_log(NULL, AV_LOG_INFO, "receiver #%d: flushing the queue, "
+   "discarding %d message(s)\n", rd->id,
+   av_thread_message_queue_nb_elems(rd->queue));
 av_thread_message_flush(rd->queue);
 } else {
 struct message msg;
-- 
2.17.0



signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavu/threadmessage: add av_thread_message_queue_nelem()

2018-04-21 Thread Rostislav Pehlivanov
On 21 April 2018 at 20:51, Clément Bœsch  wrote:

> ---
> Been away from FFmpeg for way too long. Hope this patch get me back on
> track. Feel free to nitpick on the name.
> ---
>  doc/APIchanges | 3 +++
>  libavutil/threadmessage.c  | 9 +
>  libavutil/threadmessage.h  | 5 +
>  libavutil/version.h| 2 +-
>  tests/api/api-threadmessage-test.c | 4 +++-
>  5 files changed, 21 insertions(+), 2 deletions(-)
>
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 4f6ac2a031..393491c8e9 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -15,6 +15,9 @@ libavutil: 2017-10-21
>
>  API changes, most recent first:
>
> +2018-04-xx - xx - lavu 56.16.100 - threadmessage.h
> +  Add av_thread_message_queue_nelem().
> +
>   8< - FFmpeg 4.0 was cut here  8< -
>
>  2018-04-03 - d6fc031caf - lavu 56.13.100 - pixdesc.h
> diff --git a/libavutil/threadmessage.c b/libavutil/threadmessage.c
> index 872e9392b1..fed398926a 100644
> --- a/libavutil/threadmessage.c
> +++ b/libavutil/threadmessage.c
> @@ -102,6 +102,15 @@ void av_thread_message_queue_free(AVThreadMessageQueue
> **mq)
>  #endif
>  }
>
> +int av_thread_message_queue_nelem(AVThreadMessageQueue *mq)
> +{
> +int ret;
> +pthread_mutex_lock(>lock);
> +ret = av_fifo_size(mq->fifo);
> +pthread_mutex_unlock(>lock);
> +return ret / mq->elsize;
> +}
> +
>  #if HAVE_THREADS
>
>  static int av_thread_message_queue_send_locked(AVThreadMessageQueue *mq,
> diff --git a/libavutil/threadmessage.h b/libavutil/threadmessage.h
> index 8480a0a3db..e41d95ccf7 100644
> --- a/libavutil/threadmessage.h
> +++ b/libavutil/threadmessage.h
> @@ -95,6 +95,11 @@ void 
> av_thread_message_queue_set_err_recv(AVThreadMessageQueue
> *mq,
>  void av_thread_message_queue_set_free_func(AVThreadMessageQueue *mq,
> void (*free_func)(void *msg));
>
> +/**
> + * Return the current number of messages in the queue.
> + */
> +int av_thread_message_queue_nelem(AVThreadMessageQueue *mq);
> +
>  /**
>   * Flush the message queue
>   *
> diff --git a/libavutil/version.h b/libavutil/version.h
> index 387421775f..23567000a3 100644
> --- a/libavutil/version.h
> +++ b/libavutil/version.h
> @@ -79,7 +79,7 @@
>   */
>
>  #define LIBAVUTIL_VERSION_MAJOR  56
> -#define LIBAVUTIL_VERSION_MINOR  15
> +#define LIBAVUTIL_VERSION_MINOR  16
>  #define LIBAVUTIL_VERSION_MICRO 100
>
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
> diff --git a/tests/api/api-threadmessage-test.c
> b/tests/api/api-threadmessage-test.c
> index 05a8062b8c..494808f176 100644
> --- a/tests/api/api-threadmessage-test.c
> +++ b/tests/api/api-threadmessage-test.c
> @@ -130,7 +130,9 @@ static void *receiver_thread(void *arg)
>
>  for (i = 0; i < rd->workload; i++) {
>  if (rand() % rd->workload < rd->workload / 10) {
> -av_log(NULL, AV_LOG_INFO, "receiver #%d: flushing the
> queue\n", rd->id);
> +av_log(NULL, AV_LOG_INFO, "receiver #%d: flushing the queue, "
> +   "discarding %d message(s)\n", rd->id,
> +   av_thread_message_queue_nelem(rd->queue));
>  av_thread_message_flush(rd->queue);
>  } else {
>  struct message msg;
> --
> 2.17.0
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

I think av_thread_message_queue_elems would be a better name, had to think
for a good period of time what "nelem" meant.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavu/threadmessage: add av_thread_message_queue_nelem()

2018-04-21 Thread Michael Niedermayer
On Sat, Apr 21, 2018 at 09:51:37PM +0200, Clément Bœsch wrote:
> ---
> Been away from FFmpeg for way too long. Hope this patch get me back on
> track. Feel free to nitpick on the name.
> ---
>  doc/APIchanges | 3 +++
>  libavutil/threadmessage.c  | 9 +
>  libavutil/threadmessage.h  | 5 +
>  libavutil/version.h| 2 +-
>  tests/api/api-threadmessage-test.c | 4 +++-
>  5 files changed, 21 insertions(+), 2 deletions(-)

breaks build with:
make distclean ; ./configure --disable-pthreads && make -j12

libavutil/threadmessage.c: In function ‘av_thread_message_queue_nelem’:
libavutil/threadmessage.c:108:5: error: implicit declaration of function 
‘pthread_mutex_lock’ [-Werror=implicit-function-declaration]
 pthread_mutex_lock(>lock);
 ^
libavutil/threadmessage.c:108:27: error: ‘AVThreadMessageQueue’ has no member 
named ‘lock’
 pthread_mutex_lock(>lock);
   ^
libavutil/threadmessage.c:109:26: error: ‘AVThreadMessageQueue’ has no member 
named ‘fifo’
 ret = av_fifo_size(mq->fifo);
  ^
libavutil/threadmessage.c:110:5: error: implicit declaration of function 
‘pthread_mutex_unlock’ [-Werror=implicit-function-declaration]
 pthread_mutex_unlock(>lock);
 ^
libavutil/threadmessage.c:110:29: error: ‘AVThreadMessageQueue’ has no member 
named ‘lock’
 pthread_mutex_unlock(>lock);
 ^
libavutil/threadmessage.c:111:20: error: ‘AVThreadMessageQueue’ has no member 
named ‘elsize’
 return ret / mq->elsize;
^
libavutil/threadmessage.c:112:1: error: control reaches end of non-void 
function [-Werror=return-type]
 }
 ^

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The real ebay dictionary, page 2
"100% positive feedback" - "All either got their money back or didnt complain"
"Best seller ever, very honest" - "Seller refunded buyer after failed scam"


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavu/threadmessage: add av_thread_message_queue_nelem()

2018-04-21 Thread Clément Bœsch
---
Been away from FFmpeg for way too long. Hope this patch get me back on
track. Feel free to nitpick on the name.
---
 doc/APIchanges | 3 +++
 libavutil/threadmessage.c  | 9 +
 libavutil/threadmessage.h  | 5 +
 libavutil/version.h| 2 +-
 tests/api/api-threadmessage-test.c | 4 +++-
 5 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 4f6ac2a031..393491c8e9 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2018-04-xx - xx - lavu 56.16.100 - threadmessage.h
+  Add av_thread_message_queue_nelem().
+
  8< - FFmpeg 4.0 was cut here  8< -
 
 2018-04-03 - d6fc031caf - lavu 56.13.100 - pixdesc.h
diff --git a/libavutil/threadmessage.c b/libavutil/threadmessage.c
index 872e9392b1..fed398926a 100644
--- a/libavutil/threadmessage.c
+++ b/libavutil/threadmessage.c
@@ -102,6 +102,15 @@ void av_thread_message_queue_free(AVThreadMessageQueue 
**mq)
 #endif
 }
 
+int av_thread_message_queue_nelem(AVThreadMessageQueue *mq)
+{
+int ret;
+pthread_mutex_lock(>lock);
+ret = av_fifo_size(mq->fifo);
+pthread_mutex_unlock(>lock);
+return ret / mq->elsize;
+}
+
 #if HAVE_THREADS
 
 static int av_thread_message_queue_send_locked(AVThreadMessageQueue *mq,
diff --git a/libavutil/threadmessage.h b/libavutil/threadmessage.h
index 8480a0a3db..e41d95ccf7 100644
--- a/libavutil/threadmessage.h
+++ b/libavutil/threadmessage.h
@@ -95,6 +95,11 @@ void 
av_thread_message_queue_set_err_recv(AVThreadMessageQueue *mq,
 void av_thread_message_queue_set_free_func(AVThreadMessageQueue *mq,
void (*free_func)(void *msg));
 
+/**
+ * Return the current number of messages in the queue.
+ */
+int av_thread_message_queue_nelem(AVThreadMessageQueue *mq);
+
 /**
  * Flush the message queue
  *
diff --git a/libavutil/version.h b/libavutil/version.h
index 387421775f..23567000a3 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR  15
+#define LIBAVUTIL_VERSION_MINOR  16
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
diff --git a/tests/api/api-threadmessage-test.c 
b/tests/api/api-threadmessage-test.c
index 05a8062b8c..494808f176 100644
--- a/tests/api/api-threadmessage-test.c
+++ b/tests/api/api-threadmessage-test.c
@@ -130,7 +130,9 @@ static void *receiver_thread(void *arg)
 
 for (i = 0; i < rd->workload; i++) {
 if (rand() % rd->workload < rd->workload / 10) {
-av_log(NULL, AV_LOG_INFO, "receiver #%d: flushing the queue\n", 
rd->id);
+av_log(NULL, AV_LOG_INFO, "receiver #%d: flushing the queue, "
+   "discarding %d message(s)\n", rd->id,
+   av_thread_message_queue_nelem(rd->queue));
 av_thread_message_flush(rd->queue);
 } else {
 struct message msg;
-- 
2.17.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel