Revision 6c7d3ead

View differences:

ffplay.c
90 90
    SDL_Overlay *bmp;
91 91
    int width, height; /* source height & width */
92 92
    int allocated;
93
    SDL_TimerID timer_id;
93 94
} VideoPicture;
94 95

  
95 96
typedef struct SubPicture {
......
913 914
}
914 915

  
915 916
/* schedule a video refresh in 'delay' ms */
916
static void schedule_refresh(VideoState *is, int delay)
917
static SDL_TimerID schedule_refresh(VideoState *is, int delay)
917 918
{
918 919
    if(!delay) delay=1; //SDL seems to be buggy when the delay is 0
919
    SDL_AddTimer(delay, sdl_refresh_timer_cb, is);
920
    return SDL_AddTimer(delay, sdl_refresh_timer_cb, is);
920 921
}
921 922

  
922 923
/* get the current audio clock value */
......
1122 1123
                is->pictq_rindex = 0;
1123 1124

  
1124 1125
            SDL_LockMutex(is->pictq_mutex);
1126
            vp->timer_id= 0;
1125 1127
            is->pictq_size--;
1126 1128
            SDL_CondSignal(is->pictq_cond);
1127 1129
            SDL_UnlockMutex(is->pictq_mutex);
......
1277 1279
            is->pictq_windex = 0;
1278 1280
        SDL_LockMutex(is->pictq_mutex);
1279 1281
        is->pictq_size++;
1282
        //We must schedule in a mutex as we must store the timer id before the timer dies or might end up freeing a alraedy freed id
1283
        vp->timer_id= schedule_refresh(is, (int)(compute_frame_delay(vp->pts, is) * 1000 + 0.5));
1280 1284
        SDL_UnlockMutex(is->pictq_mutex);
1281
        schedule_refresh(is, (int)(compute_frame_delay(vp->pts, is) * 1000 + 0.5));
1282 1285
    }
1283 1286
    return 0;
1284 1287
}
......
1326 1329
{
1327 1330
    VideoState *is = arg;
1328 1331
    AVPacket pkt1, *pkt = &pkt1;
1329
    int len1, got_picture;
1332
    int len1, got_picture, i;
1330 1333
    AVFrame *frame= avcodec_alloc_frame();
1331 1334
    double pts;
1332 1335

  
......
1339 1342

  
1340 1343
        if(pkt->data == flush_pkt.data){
1341 1344
            avcodec_flush_buffers(is->video_st->codec);
1345

  
1346
            SDL_LockMutex(is->pictq_mutex);
1347
            //Make sure there are no long delay timers (ideally we should just flush the que but thats harder)
1348
            for(i=0; i<VIDEO_PICTURE_QUEUE_SIZE; i++){
1349
                if(is->pictq[i].timer_id){
1350
                    SDL_RemoveTimer(is->pictq[i].timer_id);
1351
                    is->pictq[i].timer_id=0;
1352
                    schedule_refresh(is, 1);
1353
                }
1354
            }
1355
            while (is->pictq_size && !is->videoq.abort_request) {
1356
                SDL_CondWait(is->pictq_cond, is->pictq_mutex);
1357
            }
1358
            SDL_UnlockMutex(is->pictq_mutex);
1359

  
1342 1360
            is->last_dts_for_fault_detection=
1343 1361
            is->last_pts_for_fault_detection= INT64_MIN;
1344 1362
            continue;

Also available in: Unified diff