1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| https:
{ video->frameq.deQueue(&video->frame);
double current_pts = *(double *)video->frame->opaque; double delay = current_pts - video->frame_last_pts; if (delay <= 0 || delay >= 1.0) { delay = video->frame_last_delay; } double ref_clock = audio->get_audio_clock(); double diff = current_pts - ref_clock; double sync_threshold = FFMAX(MIN_SYNC_THRESHOLD, FFMIN(MAX_SYNC_THRESHOLD, delay)) ; audio->audio_wait_video(current_pts,false); video->video_drop_frame(ref_clock,false);
if (!isnan(diff) && fabs(diff) < NOSYNC_THRESHOLD) { if (diff <= -sync_threshold) { delay = FFMAX(0, delay + diff); static int last_delay_zero_counts = 0; if(video->frame_last_delay <= 0) { last_delay_zero_counts++; } else { last_delay_zero_counts = 0; } if(diff < -1.0 && last_delay_zero_counts >= 10) { printf("maybe video codec too slow, adjust video&audio\n"); #ifndef DORP_PACK audio->audio_wait_video(current_pts,true); #endif video->video_drop_frame(ref_clock,true); } } else if (diff >= sync_threshold && delay > SYNC_FRAMEDUP_THRESHOLD) delay = delay + diff; else if (diff >= sync_threshold) delay = 2 * delay; } video->frame_last_delay = delay; video->frame_last_pts = current_pts;
double curr_time = static_cast<double>(av_gettime()) / 1000000.0; if(video->frame_timer == 0) { video->frame_timer = curr_time; }
double actual_delay = video->frame_timer + delay - curr_time; if (actual_delay <= MIN_REFRSH_S) { actual_delay = MIN_REFRSH_S; } usleep(static_cast<int>(actual_delay * 1000 * 1000)); SDL_UpdateTexture(video->texture, &(video->rect), video->frame->data[0], video->frame->linesize[0]); SDL_RenderClear(video->renderer); SDL_RenderCopy(video->renderer, video->texture, &video->rect, &video->rect); SDL_RenderPresent(video->renderer); video->frame_timer = static_cast<double>(av_gettime()) / 1000000.0 ; av_frame_unref(video->frame); schedule_refresh(media, 1); }
|