[7/8] lavd: Use av_gettime_relative

Message ID 1413975796-90524-7-git-send-email-martin@martin.st
State New
Headers show

Commit Message

Martin Storsjö Oct. 22, 2014, 11:03 a.m.
The one occurrance of av_gettime in libavdevice that I didn't
change was in pulseaudio, for the wallclock option.
---
 libavdevice/bktr.c          | 6 +++---
 libavdevice/fbdev.c         | 4 ++--
 libavdevice/jack_audio.c    | 4 ++--
 libavdevice/oss_audio_dec.c | 2 +-
 libavdevice/sndio_dec.c     | 2 +-
 libavdevice/x11grab.c       | 4 ++--
 6 files changed, 11 insertions(+), 11 deletions(-)

Comments

Luca Barbato Oct. 22, 2014, 12:10 p.m. | #1
On 22/10/14 13:03, Martin Storsjö wrote:
> The one occurrance of av_gettime in libavdevice that I didn't
> change was in pulseaudio, for the wallclock option.
> ---
>   libavdevice/bktr.c          | 6 +++---
>   libavdevice/fbdev.c         | 4 ++--
>   libavdevice/jack_audio.c    | 4 ++--
>   libavdevice/oss_audio_dec.c | 2 +-
>   libavdevice/sndio_dec.c     | 2 +-
>   libavdevice/x11grab.c       | 4 ++--
>   6 files changed, 11 insertions(+), 11 deletions(-)
>

This need a retouch then, since all the libavdevice timestamps should be 
wallclock.

lu
Martin Storsjö Oct. 22, 2014, 4:31 p.m. | #2
On Wed, 22 Oct 2014, Luca Barbato wrote:

> On 22/10/14 13:03, Martin Storsjö wrote:
>> The one occurrance of av_gettime in libavdevice that I didn't
>> change was in pulseaudio, for the wallclock option.
>> ---
>>   libavdevice/bktr.c          | 6 +++---
>>   libavdevice/fbdev.c         | 4 ++--
>>   libavdevice/jack_audio.c    | 4 ++--
>>   libavdevice/oss_audio_dec.c | 2 +-
>>   libavdevice/sndio_dec.c     | 2 +-
>>   libavdevice/x11grab.c       | 4 ++--
>>   6 files changed, 11 insertions(+), 11 deletions(-)
>>
>
> This need a retouch then, since all the libavdevice timestamps should be 
> wallclock.

Sure, I can leave out this patch and let somebody else look closer at 
which ones should be changed, if any at all. Some devices only seem to use 
it for pacing frame grabbing at a certain framerate, while some also set 
timestamps using it.

// Martin
Luca Barbato Oct. 22, 2014, 10:37 p.m. | #3
On 22/10/14 18:31, Martin Storsjö wrote:
> Sure, I can leave out this patch and let somebody else look closer at
> which ones should be changed, if any at all. Some devices only seem to
> use it for pacing frame grabbing at a certain framerate, while some also
> set timestamps using it.

thanks, in _theory_ all the devices should have a start offset equal to
some shared time reference and then would be better that the clock is
monotonous since some unlucky people already experienced bogus pts with
the former non-monotonous gettime apparently.

lu
Martin Storsjö Oct. 24, 2014, 7:01 a.m. | #4
On Thu, 23 Oct 2014, Luca Barbato wrote:

> On 22/10/14 18:31, Martin Storsjö wrote:
>> Sure, I can leave out this patch and let somebody else look closer at
>> which ones should be changed, if any at all. Some devices only seem to
>> use it for pacing frame grabbing at a certain framerate, while some also
>> set timestamps using it.
>
> thanks, in _theory_ all the devices should have a start offset equal to
> some shared time reference and then would be better that the clock is
> monotonous since some unlucky people already experienced bogus pts with
> the former non-monotonous gettime apparently.

Ok - I pushed the other patches in the set except this one, I'll leave it 
up to you to check these ones (I'm quite unfamiliar with all of them) and 
figure out if all of them really are ok with relative time.

// Martin
Luca Barbato Oct. 24, 2014, 9:14 a.m. | #5
On 24/10/14 09:01, Martin Storsjö wrote:
> On Thu, 23 Oct 2014, Luca Barbato wrote:
>
>> On 22/10/14 18:31, Martin Storsjö wrote:
>>> Sure, I can leave out this patch and let somebody else look closer at
>>> which ones should be changed, if any at all. Some devices only seem to
>>> use it for pacing frame grabbing at a certain framerate, while some also
>>> set timestamps using it.
>>
>> thanks, in _theory_ all the devices should have a start offset equal to
>> some shared time reference and then would be better that the clock is
>> monotonous since some unlucky people already experienced bogus pts with
>> the former non-monotonous gettime apparently.
>
> Ok - I pushed the other patches in the set except this one, I'll leave
> it up to you to check these ones (I'm quite unfamiliar with all of them)
> and figure out if all of them really are ok with relative time.
>

Monday remind me to document how avdevice currently works so we can see 
if that makes sense to everybody.

I hadn't had the time to make it any saner so ideas will be welcome.

lu

Patch

diff --git a/libavdevice/bktr.c b/libavdevice/bktr.c
index 695e13f..ccde0ea 100644
--- a/libavdevice/bktr.c
+++ b/libavdevice/bktr.c
@@ -213,14 +213,14 @@  static void bktr_getframe(uint64_t per_frame)
 {
     uint64_t curtime;
 
-    curtime = av_gettime();
+    curtime = av_gettime_relative();
     if (!last_frame_time
         || ((last_frame_time + per_frame) > curtime)) {
         if (!usleep(last_frame_time + per_frame + per_frame / 8 - curtime)) {
             if (!nsignals)
                 av_log(NULL, AV_LOG_INFO,
                        "SLEPT NO signals - %d microseconds late\n",
-                       (int)(av_gettime() - last_frame_time - per_frame));
+                       (int)(av_gettime_relative() - last_frame_time - per_frame));
         }
     }
     nsignals = 0;
@@ -238,7 +238,7 @@  static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
 
     bktr_getframe(s->per_frame);
 
-    pkt->pts = av_gettime();
+    pkt->pts = av_gettime_relative();
     memcpy(pkt->data, video_buf, video_buf_size);
 
     return video_buf_size;
diff --git a/libavdevice/fbdev.c b/libavdevice/fbdev.c
index 34e09f9..27130f4 100644
--- a/libavdevice/fbdev.c
+++ b/libavdevice/fbdev.c
@@ -189,10 +189,10 @@  static int fbdev_read_packet(AVFormatContext *avctx, AVPacket *pkt)
     uint8_t *pin, *pout;
 
     if (fbdev->time_frame == AV_NOPTS_VALUE)
-        fbdev->time_frame = av_gettime();
+        fbdev->time_frame = av_gettime_relative();
 
     /* wait based on the frame rate */
-    curtime = av_gettime();
+    curtime = av_gettime_relative();
     delay = fbdev->time_frame - curtime;
     av_dlog(avctx,
             "time_frame:%"PRId64" curtime:%"PRId64" delay:%"PRId64"\n",
diff --git a/libavdevice/jack_audio.c b/libavdevice/jack_audio.c
index 8ce3321..3ca3093 100644
--- a/libavdevice/jack_audio.c
+++ b/libavdevice/jack_audio.c
@@ -75,7 +75,7 @@  static int process_callback(jack_nframes_t nframes, void *arg)
 
     /* Retrieve filtered cycle time */
     cycle_time = ff_timefilter_update(self->timefilter,
-                                      av_gettime() / 1000000.0 - (double) cycle_delay / self->sample_rate,
+                                      av_gettime_relative() / 1000000.0 - (double) cycle_delay / self->sample_rate,
                                       self->buffer_size);
 
     /* Check if an empty packet is available, and if there's enough space to send it back once filled */
@@ -283,7 +283,7 @@  static int audio_read_packet(AVFormatContext *context, AVPacket *pkt)
     }
 
     /* Wait for a packet coming back from process_callback(), if one isn't available yet */
-    timeout.tv_sec = av_gettime() / 1000000 + 2;
+    timeout.tv_sec = av_gettime_relative() / 1000000 + 2;
     if (sem_timedwait(&self->packet_count, &timeout)) {
         if (errno == ETIMEDOUT) {
             av_log(context, AV_LOG_ERROR,
diff --git a/libavdevice/oss_audio_dec.c b/libavdevice/oss_audio_dec.c
index 601d91c..fb80467 100644
--- a/libavdevice/oss_audio_dec.c
+++ b/libavdevice/oss_audio_dec.c
@@ -90,7 +90,7 @@  static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
     pkt->size = ret;
 
     /* compute pts of the start of the packet */
-    cur_time = av_gettime();
+    cur_time = av_gettime_relative();
     bdelay = ret;
     if (ioctl(s->fd, SNDCTL_DSP_GETISPACE, &abufi) == 0) {
         bdelay += abufi.bytes;
diff --git a/libavdevice/sndio_dec.c b/libavdevice/sndio_dec.c
index 58caaa1..d01cac0 100644
--- a/libavdevice/sndio_dec.c
+++ b/libavdevice/sndio_dec.c
@@ -73,7 +73,7 @@  static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
     s->softpos += ret;
 
     /* compute pts of the start of the packet */
-    cur_time = av_gettime();
+    cur_time = av_gettime_relative();
 
     bdelay = ret + s->hwpos - s->softpos;
 
diff --git a/libavdevice/x11grab.c b/libavdevice/x11grab.c
index 3aa4294..da16970 100644
--- a/libavdevice/x11grab.c
+++ b/libavdevice/x11grab.c
@@ -340,7 +340,7 @@  static int x11grab_read_header(AVFormatContext *s1)
     x11grab->frame_size = x11grab->width * x11grab->height * image->bits_per_pixel / 8;
     x11grab->dpy        = dpy;
     x11grab->time_base  = (AVRational) { framerate.den, framerate.num };
-    x11grab->time_frame = av_gettime() / av_q2d(x11grab->time_base);
+    x11grab->time_frame = av_gettime_relative() / av_q2d(x11grab->time_base);
     x11grab->x_off      = x_off;
     x11grab->y_off      = y_off;
     x11grab->image      = image;
@@ -497,7 +497,7 @@  static int x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
 
     /* wait based on the frame rate */
     for (;;) {
-        curtime = av_gettime();
+        curtime = av_gettime_relative();
         delay   = s->time_frame * av_q2d(s->time_base) - curtime;
         if (delay <= 0) {
             if (delay < INT64_C(-1000000) * av_q2d(s->time_base))