diff --git a/Makefile b/Makefile index 55ea165e1c..3e0af2d55e 100644 --- a/Makefile +++ b/Makefile @@ -198,7 +198,6 @@ SOURCES = talloc.c \ demux/ebml.c \ demux/extension.c \ demux/mf.c \ - demux/video.c \ osdep/io.c \ osdep/numcores.c \ osdep/timer.c \ diff --git a/core/mplayer.c b/core/mplayer.c index b1a7209a97..2f5e103dd1 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -2483,6 +2483,69 @@ static void filter_video(struct MPContext *mpctx, struct mp_image *frame) filter_output_queued_frame(mpctx); } + +static int video_read_frame(sh_video_t *sh_video, float *frame_time_ptr, + unsigned char **start, int force_fps) +{ + demux_stream_t *d_video = sh_video->ds; + demuxer_t *demuxer = d_video->demuxer; + float frame_time = 1; + float pts1 = d_video->pts; + int in_size = 0; + + *start = NULL; + + // frame-based file formats: (AVI,ASF,MOV) + in_size = ds_get_packet(d_video, start); + if (in_size < 0) + return -1; // EOF + + frame_time *= sh_video->frametime; + + // override frame_time for variable/unknown FPS formats: + if (!force_fps) { + switch (demuxer->file_format) { + case DEMUXER_TYPE_MATROSKA: + case DEMUXER_TYPE_MNG: + if (d_video->pts > 0 && pts1 > 0 && d_video->pts>pts1) + frame_time = d_video->pts-pts1; + break; + case DEMUXER_TYPE_TV: { + double next_pts = ds_get_next_pts(d_video); + double d= (next_pts != MP_NOPTS_VALUE) ? next_pts - d_video->pts : d_video->pts-pts1; + if (d >= 0) { + if(d > 0){ + if ((int)sh_video->fps == 1000) + mp_msg(MSGT_CPLAYER,MSGL_V,"\navg. framerate: %d fps \n",(int)(1.0f/d)); + sh_video->frametime = d; // 1ms + sh_video->fps = 1.0f/d; + } + frame_time = d; + } else { + mp_msg(MSGT_CPLAYER,MSGL_WARN,"\nInvalid frame duration value (%5.3f/%5.3f => %5.3f). Defaulting to %5.3f sec.\n",d_video->pts,next_pts,d,frame_time); + // frame_time = 1/25.0; + } + break; + } + case DEMUXER_TYPE_LAVF: + if ((int)sh_video->fps == 1000 || (int)sh_video->fps <= 1) { + double next_pts = ds_get_next_pts(d_video); + double d = (next_pts != MP_NOPTS_VALUE) ? next_pts - d_video->pts : d_video->pts - pts1; + if(d>=0){ + frame_time = d; + } + } + break; + } + } + + sh_video->pts = d_video->pts; + + if (frame_time_ptr) + *frame_time_ptr=frame_time; + return in_size; +} + static double update_video_nocorrect_pts(struct MPContext *mpctx) { struct sh_video *sh_video = mpctx->sh_video; diff --git a/demux/stheader.h b/demux/stheader.h index 0351a29ee7..8b584396ca 100644 --- a/demux/stheader.h +++ b/demux/stheader.h @@ -152,8 +152,4 @@ typedef struct sh_sub { // demuxer.c: struct sh_stream *new_sh_stream(struct demuxer *demuxer, enum stream_type type); -// video.c: -int video_read_frame(struct sh_video *sh_video, float *frame_time_ptr, - unsigned char **start, int force_fps); - #endif /* MPLAYER_STHEADER_H */ diff --git a/demux/video.c b/demux/video.c deleted file mode 100644 index 1a7db255bf..0000000000 --- a/demux/video.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * video frame reading - * - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "config.h" - -#include -#include -#include -#include - -#include - -#include "core/mp_msg.h" - -#include "stream/stream.h" -#include "demux.h" -#include "stheader.h" - -int video_read_frame(sh_video_t* sh_video,float* frame_time_ptr,unsigned char** start,int force_fps){ - demux_stream_t *d_video=sh_video->ds; - demuxer_t *demuxer=d_video->demuxer; - float frame_time=1; - float pts1=d_video->pts; - int in_size=0; - - *start=NULL; - - // frame-based file formats: (AVI,ASF,MOV) - in_size=ds_get_packet(d_video,start); - if(in_size<0) return -1; // EOF - - -//------------------------ frame decoded. -------------------- - - frame_time*=sh_video->frametime; - - // override frame_time for variable/unknown FPS formats: - if(!force_fps) switch(demuxer->file_format){ - case DEMUXER_TYPE_MATROSKA: - case DEMUXER_TYPE_MNG: - if(d_video->pts>0 && pts1>0 && d_video->pts>pts1) - frame_time=d_video->pts-pts1; - break; - case DEMUXER_TYPE_TV: { - double next_pts = ds_get_next_pts(d_video); - double d= (next_pts != MP_NOPTS_VALUE) ? next_pts - d_video->pts : d_video->pts-pts1; - if(d>=0){ - if(d>0){ - if((int)sh_video->fps==1000) - mp_msg(MSGT_CPLAYER,MSGL_V,"\navg. framerate: %d fps \n",(int)(1.0f/d)); - sh_video->frametime=d; // 1ms - sh_video->fps=1.0f/d; - } - frame_time = d; - } else { - mp_msg(MSGT_CPLAYER,MSGL_WARN,"\nInvalid frame duration value (%5.3f/%5.3f => %5.3f). Defaulting to %5.3f sec.\n",d_video->pts,next_pts,d,frame_time); - // frame_time = 1/25.0; - } - } - break; - case DEMUXER_TYPE_LAVF: - if((int)sh_video->fps==1000 || (int)sh_video->fps<=1){ - double next_pts = ds_get_next_pts(d_video); - double d= (next_pts != MP_NOPTS_VALUE) ? next_pts - d_video->pts : d_video->pts-pts1; - if(d>=0){ - frame_time = d; - } - } - break; - } - - sh_video->pts=d_video->pts; - - if(frame_time_ptr) *frame_time_ptr=frame_time; - return in_size; -}