Revision 9580ba26 libavdevice/v4l.c

View differences:

libavdevice/v4l.c
21 21

  
22 22
#undef __STRICT_ANSI__ //workaround due to broken kernel headers
23 23
#include "config.h"
24
#include "libavutil/rational.h"
24 25
#include "libavformat/avformat.h"
25 26
#include "libavcodec/dsputil.h"
26 27
#include <unistd.h>
......
38 39
    int frame_format; /* see VIDEO_PALETTE_xxx */
39 40
    int use_mmap;
40 41
    int width, height;
41
    int frame_rate;
42
    int frame_rate_base;
42
    AVRational time_base;
43 43
    int64_t time_frame;
44 44
    int frame_size;
45 45
    struct video_capability video_cap;
......
72 72
    AVStream *st;
73 73
    int width, height;
74 74
    int video_fd, frame_size;
75
    int frame_rate, frame_rate_base;
76 75
    int desired_palette, desired_depth;
77 76
    struct video_tuner tuner;
78 77
    struct video_audio audio;
......
88 87
        av_log(s1, AV_LOG_ERROR, "Wrong time base (%d)\n", ap->time_base.den);
89 88
        return -1;
90 89
    }
90
    s->time_base = ap->time_base;
91 91

  
92 92
    width = ap->width;
93 93
    height = ap->height;
94
    frame_rate      = ap->time_base.den;
95
    frame_rate_base = ap->time_base.num;
96 94

  
97 95
    if((unsigned)width > 32767 || (unsigned)height > 32767) {
98 96
        av_log(s1, AV_LOG_ERROR, "Capture size is out of range: %dx%d\n",
......
108 106

  
109 107
    s->width = width;
110 108
    s->height = height;
111
    s->frame_rate      = frame_rate;
112
    s->frame_rate_base = frame_rate_base;
113 109

  
114 110
    video_fd = open(s1->filename, O_RDWR);
115 111
    if (video_fd < 0) {
......
197 193
        val = 1;
198 194
        ioctl(video_fd, VIDIOCCAPTURE, &val);
199 195

  
200
        s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base;
196
        s->time_frame = av_gettime() * s->time_base.den / s->time_base.num;
201 197
        s->use_mmap = 0;
202 198
    } else {
203 199
        s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,video_fd,0);
......
209 205
            }
210 206
        }
211 207
        s->gb_frame = 0;
212
        s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base;
208
        s->time_frame = av_gettime() * s->time_base.den / s->time_base.num;
213 209

  
214 210
        /* start to grab the first frame */
215 211
        s->gb_buf.frame = s->gb_frame % s->gb_buffers.frames;
......
252 248
    st->codec->codec_id = CODEC_ID_RAWVIDEO;
253 249
    st->codec->width = width;
254 250
    st->codec->height = height;
255
    st->codec->time_base.den      = frame_rate;
256
    st->codec->time_base.num = frame_rate_base;
251
    st->codec->time_base = s->time_base;
257 252
    st->codec->bit_rate = frame_size * 1/av_q2d(st->codec->time_base) * 8;
258 253

  
259 254
    return 0;
......
301 296
    /* wait based on the frame rate */
302 297
    for(;;) {
303 298
        curtime = av_gettime();
304
        delay = s->time_frame  * s->frame_rate_base / s->frame_rate - curtime;
299
        delay = s->time_frame * s->time_base.num / s->time_base.den - curtime;
305 300
        if (delay <= 0) {
306
            if (delay < INT64_C(-1000000) * s->frame_rate_base / s->frame_rate) {
301
            if (delay < INT64_C(-1000000) * s->time_base.num / s->time_base.den) {
307 302
                /* printf("grabbing is %d frames late (dropping)\n", (int) -(delay / 16666)); */
308 303
                s->time_frame += INT64_C(1000000);
309 304
            }

Also available in: Unified diff