// Fill mpctx->next_frames[] with a newly filtered or decoded image. // returns VD_* code static int video_output_image(struct MPContext *mpctx, double endpts) { bool hrseek = mpctx->hrseek_active && mpctx->video_status == STATUS_SYNCING; if (mpctx->d_video->header->attached_picture) { if (vo_has_frame(mpctx->video_out)) return VD_EOF; if (mpctx->num_next_frames >= 1) return VD_NEW_FRAME; int r = video_decode_and_filter(mpctx); video_filter(mpctx, true); // force EOF filtering (avoid decoding more) mpctx->next_frames[0] = vf_read_output_frame(mpctx->d_video->vfilter); if (mpctx->next_frames[0]) { mpctx->next_frames[0]->pts = MP_NOPTS_VALUE; mpctx->num_next_frames = 1; } return r <= 0 ? VD_EOF : VD_PROGRESS; } if (have_new_frame(mpctx, false)) return VD_NEW_FRAME; // Get a new frame if we need one. int r = VD_PROGRESS; if (needs_new_frame(mpctx)) { // Filter a new frame. r = video_decode_and_filter(mpctx); if (r < 0) return r; // error struct mp_image *img = vf_read_output_frame(mpctx->d_video->vfilter); if (img) { // Always add these; they make backstepping after seeking faster. add_frame_pts(mpctx, img->pts); if (endpts != MP_NOPTS_VALUE && img->pts >= endpts) { r = VD_EOF; } else if (mpctx->max_frames == 0) { r = VD_EOF; } else if (hrseek && mpctx->hrseek_lastframe) { mp_image_setrefp(&mpctx->saved_frame, img); } else if (hrseek && img->pts < mpctx->hrseek_pts - .005) { /* just skip */ } else { add_new_frame(mpctx, img); img = NULL; } talloc_free(img); } } // Last-frame seek if (r <= 0 && hrseek && mpctx->hrseek_lastframe && mpctx->saved_frame) { add_new_frame(mpctx, mpctx->saved_frame); mpctx->saved_frame = NULL; r = VD_PROGRESS; } return have_new_frame(mpctx, r <= 0) ? VD_NEW_FRAME : r; }
// Fill mpctx->next_frame[] with a newly filtered or decoded image. // returns VD_* code static int video_output_image(struct MPContext *mpctx, double endpts) { bool hrseek = mpctx->hrseek_active && mpctx->video_status == STATUS_SYNCING; if (mpctx->d_video->header->attached_picture) { if (vo_has_frame(mpctx->video_out)) return VD_EOF; if (mpctx->next_frame[0]) return VD_NEW_FRAME; int r = video_decode_and_filter(mpctx); video_filter(mpctx, true); // force EOF filtering (avoid decoding more) mpctx->next_frame[0] = vf_read_output_frame(mpctx->d_video->vfilter); if (mpctx->next_frame[0]) mpctx->next_frame[0]->pts = MP_NOPTS_VALUE; return r <= 0 ? VD_EOF : VD_PROGRESS; } if (have_new_frame(mpctx)) return VD_NEW_FRAME; if (!mpctx->next_frame[0] && mpctx->next_frame[1]) { mpctx->next_frame[0] = mpctx->next_frame[1]; mpctx->next_frame[1] = NULL; double pts = mpctx->next_frame[0]->pts; double last_pts = mpctx->video_pts; if (last_pts == MP_NOPTS_VALUE) last_pts = pts; double frame_time = pts - last_pts; if (frame_time < 0 || frame_time >= 60) { // Assume a PTS difference >= 60 seconds is a discontinuity. MP_WARN(mpctx, "Jump in video pts: %f -> %f\n", last_pts, pts); frame_time = 0; } mpctx->video_next_pts = pts; if (mpctx->d_audio) mpctx->delay -= frame_time; if (mpctx->video_status >= STATUS_READY) { mpctx->time_frame += frame_time / mpctx->opts->playback_speed; adjust_sync(mpctx, pts, frame_time); } mpctx->dropped_frames = 0; MP_TRACE(mpctx, "frametime=%5.3f\n", frame_time); } if (have_new_frame(mpctx)) return VD_NEW_FRAME; // Get a new frame if we need one. int r = VD_PROGRESS; if (!mpctx->next_frame[1]) { // Filter a new frame. r = video_decode_and_filter(mpctx); if (r < 0) return r; // error struct mp_image *img = vf_read_output_frame(mpctx->d_video->vfilter); if (img) { // Always add these; they make backstepping after seeking faster. add_frame_pts(mpctx, img->pts); bool drop = false; if ((endpts != MP_NOPTS_VALUE && img->pts >= endpts) || mpctx->max_frames == 0) { drop = true; r = VD_EOF; } if (!drop && hrseek && mpctx->hrseek_lastframe) { mp_image_setrefp(&mpctx->saved_frame, img); drop = true; } if (hrseek && img->pts < mpctx->hrseek_pts - .005) drop = true; if (drop) { talloc_free(img); } else { mpctx->next_frame[1] = img; } } } // On EOF, always allow the playloop to use the remaining frame. if (have_new_frame(mpctx) || (r <= 0 && mpctx->next_frame[0])) return VD_NEW_FRAME; // Last-frame seek if (r <= 0 && hrseek && mpctx->hrseek_lastframe && mpctx->saved_frame) { mpctx->next_frame[1] = mpctx->saved_frame; mpctx->saved_frame = NULL; return VD_PROGRESS; } return r; }
// Fill the VO buffer with a newly filtered or decoded image. // returns VD_* code static int video_output_image(struct MPContext *mpctx, double endpts, bool reconfig_ok) { struct vf_chain *vf = mpctx->d_video->vfilter; struct vo *vo = mpctx->video_out; // Already enough video buffered in VO? // (This implies vo_has_next_frame(vo, false/true) returns true.) if (!vo_needs_new_image(vo) && vo->params) return 1; // Filter a new frame. int r = video_decode_and_filter(mpctx); if (r < 0) return r; // error vf_output_frame(vf, false); if (vf->output) { double pts = vf->output->pts; // Always add these; they make backstepping after seeking faster. add_frame_pts(mpctx, pts); bool drop = false; bool hrseek = mpctx->hrseek_active && mpctx->video_status == STATUS_SYNCING && !mpctx->d_video->header->attached_picture; if (hrseek && pts < mpctx->hrseek_pts - .005) drop = true; if (endpts != MP_NOPTS_VALUE && pts >= endpts) { drop = true; r = VD_EOF; } if (drop) { talloc_free(vf->output); vf->output = NULL; return r; } } // Filter output is different from VO input? bool need_vo_reconfig = !vo->params || !mp_image_params_equal(&vf->output_params, vo->params); if (need_vo_reconfig) { // Draining VO buffers. if (vo_has_next_frame(vo, true)) return 0; // EOF so that caller displays remaining VO frames // There was no decoded image yet - must not signal fake EOF. // Likewise, if there's no filtered frame yet, don't reconfig yet. if (!vf->output_params.imgfmt || !vf->output) return r; // Force draining. if (!reconfig_ok) return 0; struct mp_image_params p = vf->output_params; const struct vo_driver *info = mpctx->video_out->driver; MP_INFO(mpctx, "VO: [%s] %dx%d => %dx%d %s\n", info->name, p.w, p.h, p.d_w, p.d_h, vo_format_name(p.imgfmt)); MP_VERBOSE(mpctx, "VO: Description: %s\n", info->description); int vo_r = vo_reconfig(vo, &p, 0); if (vo_r < 0) { vf->initialized = -1; return VD_ERROR; } init_vo(mpctx); // Display the frame queued after this immediately. // (Neutralizes frame time calculation in update_video.) mpctx->video_next_pts = MP_NOPTS_VALUE; } // Queue new frame, if there's one. struct mp_image *img = vf_read_output_frame(vf); if (img) { vo_queue_image(vo, img); return VD_PROGRESS; } return r; // includes the true EOF case }