comparison mplayer.c @ 2567:ea6158be8103

video frame reading cleanup
author arpi
date Tue, 30 Oct 2001 20:36:20 +0000
parents fc124f9db88e
children 679d3b21bedb
comparison
equal deleted inserted replaced
2566:a350d8bed636 2567:ea6158be8103
98 #include "parse_es.h" 98 #include "parse_es.h"
99 99
100 #include "dec_audio.h" 100 #include "dec_audio.h"
101 #include "dec_video.h" 101 #include "dec_video.h"
102 102
103 #if 0
103 extern picture_t *picture; // exported from libmpeg2/decode.c 104 extern picture_t *picture; // exported from libmpeg2/decode.c
104 105
105 int frameratecode2framerate[16] = { 106 int frameratecode2framerate[16] = {
106 0, 107 0,
107 // Official mpeg1/2 framerates: 108 // Official mpeg1/2 framerates:
108 24000*10000/1001, 24*10000,25*10000, 30000*10000/1001, 30*10000,50*10000,60000*10000/1001, 60*10000, 109 24000*10000/1001, 24*10000,25*10000, 30000*10000/1001, 30*10000,50*10000,60000*10000/1001, 60*10000,
109 // libmpeg3's "Unofficial economy rates": 110 // libmpeg3's "Unofficial economy rates":
110 1*10000,5*10000,10*10000,12*10000,15*10000,0,0 111 1*10000,5*10000,10*10000,12*10000,15*10000,0,0
111 }; 112 };
113 #endif
112 114
113 //**************************************************************************// 115 //**************************************************************************//
114 //**************************************************************************// 116 //**************************************************************************//
115 117
116 // Common FIFO functions, and keyboard/event FIFO code 118 // Common FIFO functions, and keyboard/event FIFO code
1095 InitTimer(); 1097 InitTimer();
1096 1098
1097 total_time_usage_start=GetTimer(); 1099 total_time_usage_start=GetTimer();
1098 1100
1099 while(!eof){ 1101 while(!eof){
1100 unsigned int aq_total_time=GetTimer(); 1102 // unsigned int aq_total_time=GetTimer();
1101 float aq_sleep_time=0; 1103 float aq_sleep_time=0;
1102 1104
1103 if(play_n_frames>=0){ 1105 if(play_n_frames>=0){
1104 --play_n_frames; 1106 --play_n_frames;
1105 if(play_n_frames<0) exit_player(MSGTR_Exit_frames); 1107 if(play_n_frames<0) exit_player(MSGTR_Exit_frames);
1165 cvideo_base_vtime=video_time_usage; 1167 cvideo_base_vtime=video_time_usage;
1166 1168
1167 if(1) 1169 if(1)
1168 while(1){ 1170 while(1){
1169 1171
1170 float frame_time=1; 1172 float frame_time=0;
1171 float pts1=d_video->pts;
1172 int blit_frame=0; 1173 int blit_frame=0;
1173
1174 current_module="decode_video";
1175 1174
1176 //-------------------- Decode a frame: ----------------------- 1175 //-------------------- Decode a frame: -----------------------
1177 1176 vdecode_time=video_time_usage;
1178 vdecode_time=video_time_usage; 1177 { unsigned char* start=NULL;
1179 1178 int in_size;
1180 if(demuxer->file_format==DEMUXER_TYPE_MPEG_ES || demuxer->file_format==DEMUXER_TYPE_MPEG_PS){ 1179 // get it!
1181 int in_frame=0; 1180 current_module="video_read_frame";
1182 float newfps; 1181 in_size=video_read_frame(sh_video,&frame_time,&start,force_fps);
1183 //videobuf_len=0; 1182 if(in_size<0){ eof=1; break; }
1184 while(videobuf_len<VIDEOBUFFER_SIZE-MAX_VIDEO_PACKET_SIZE){ 1183 if(in_size>max_framesize) max_framesize=in_size; // stats
1185 int i=sync_video_packet(d_video); 1184 // decode:
1186 void* buffer=&videobuffer[videobuf_len+4]; 1185 current_module="decode_video";
1187 if(in_frame){ 1186 // printf("Decode! %p %d \n",start,in_size);
1188 if(i<0x101 || i>=0x1B0){ // not slice code -> end of frame 1187 blit_frame=decode_video(video_out,sh_video,start,in_size,drop_frame);
1189 #if 1 1188 }
1190 // send END OF FRAME code: 1189 vdecode_time=video_time_usage-vdecode_time;
1191 videobuffer[videobuf_len+0]=0; 1190 //------------------------ frame decoded. --------------------
1192 videobuffer[videobuf_len+1]=0; 1191
1193 videobuffer[videobuf_len+2]=1;
1194 videobuffer[videobuf_len+3]=0xFF;
1195 videobuf_len+=4;
1196 #endif
1197 if(!i) eof=2; // EOF
1198 break;
1199 }
1200 } else {
1201 //if(i==0x100) in_frame=1; // picture startcode
1202 if(i>=0x101 && i<0x1B0) in_frame=1; // picture startcode
1203 else if(!i){ eof=3; break;} // EOF
1204 }
1205 if(grab_frames==2 && (i==0x1B3 || i==0x1B8)) grab_frames=1;
1206 if(!read_video_packet(d_video)){ eof=4; break;} // EOF
1207 //printf("read packet 0x%X, len=%d\n",i,videobuf_len);
1208 if(sh_video->codec->driver!=VFM_MPEG){
1209 // if not libmpeg2:
1210 switch(i){
1211 case 0x1B3: header_process_sequence_header (picture, buffer);break;
1212 case 0x1B5: header_process_extension (picture, buffer);break;
1213 }
1214 }
1215 }
1216
1217 if(videobuf_len>max_framesize) max_framesize=videobuf_len; // debug
1218 //printf("--- SEND %d bytes\n",videobuf_len);
1219 if(grab_frames==1){
1220 FILE *f=fopen("grab.mpg","ab");
1221 fwrite(videobuffer,videobuf_len-4,1,f);
1222 fclose(f);
1223 }
1224
1225 blit_frame=decode_video(video_out,sh_video,videobuffer,videobuf_len,drop_frame);
1226
1227 // get mpeg fps:
1228 newfps=frameratecode2framerate[picture->frame_rate_code]*0.0001f;
1229 if(ABS(sh_video->fps-newfps)>0.01f) if(!force_fps){
1230 mp_msg(MSGT_CPLAYER,MSGL_WARN,"Warning! FPS changed %5.3f -> %5.3f (%f) [%d] \n",sh_video->fps,newfps,sh_video->fps-newfps,picture->frame_rate_code);
1231 sh_video->fps=newfps;
1232 sh_video->frametime=10000.0f/(float)frameratecode2framerate[picture->frame_rate_code];
1233 }
1234
1235 // fix mpeg2 frametime:
1236 frame_time=(picture->display_time)*0.01f;
1237 picture->display_time=100;
1238 videobuf_len=0;
1239
1240 } else {
1241 // frame-based file formats: (AVI,ASF,MOV)
1242 unsigned char* start=NULL;
1243 int in_size=ds_get_packet(d_video,&start);
1244 if(in_size<0){ eof=5;break;}
1245 if(in_size>max_framesize) max_framesize=in_size;
1246 blit_frame=decode_video(video_out,sh_video,start,in_size,drop_frame);
1247 }
1248
1249 vdecode_time=video_time_usage-vdecode_time;
1250
1251 //------------------------ frame decoded. --------------------
1252 //------------------------ add OSD to frame contents --------- 1192 //------------------------ add OSD to frame contents ---------
1253 #ifndef USE_LIBVO2 1193 #ifndef USE_LIBVO2
1254 current_module="draw_osd"; 1194 current_module="draw_osd";
1255 video_out->draw_osd(); 1195 video_out->draw_osd();
1256 #endif 1196 #endif
1257 1197
1258 current_module="av_sync"; 1198 current_module="av_sync";
1259 1199
1260 // Increase video timers:
1261 sh_video->num_frames+=frame_time;
1262 ++sh_video->num_frames_decoded;
1263 frame_time*=sh_video->frametime;
1264 if(demuxer->file_format==DEMUXER_TYPE_ASF && !force_fps){
1265 // .ASF files has no fixed FPS - just frame durations!
1266 float d=d_video->pts-pts1;
1267 if(d>=0 && d<5) frame_time=d;
1268 if(d>0){
1269 if(verbose)
1270 if((int)sh_video->fps==1000)
1271 mp_msg(MSGT_CPLAYER,MSGL_STATUS,"\rASF framerate: %d fps \n",(int)(1.0f/d));
1272 sh_video->frametime=d; // 1ms
1273 sh_video->fps=1.0f/d;
1274 }
1275 } else
1276 if(demuxer->file_format==DEMUXER_TYPE_MOV && !force_fps){
1277 // .MOV files has no fixed FPS - just frame durations!
1278 float d=d_video->pts-pts1;
1279 frame_time=d;
1280 }
1281 sh_video->timer+=frame_time; 1200 sh_video->timer+=frame_time;
1282 time_frame+=frame_time; // for nosound 1201 time_frame+=frame_time; // for nosound
1283 1202
1284 if(demuxer->file_format==DEMUXER_TYPE_MPEG_PS) d_video->pts+=frame_time;
1285
1286 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"*** ftime=%5.3f ***\n",frame_time); 1203 mp_dbg(MSGT_AVSYNC,MSGL_DBG2,"*** ftime=%5.3f ***\n",frame_time);
1287 1204
1288 if(drop_frame){ 1205 if(drop_frame){
1289 1206
1290 if(sh_audio && !d_audio->eof){ 1207 if(sh_audio && !d_audio->eof){
1300 if (verbose > 0 && drop_frame_cnt%10 == 0) 1217 if (verbose > 0 && drop_frame_cnt%10 == 0)
1301 mp_msg(MSGT_AVSYNC,MSGL_DBG2,"\nstill dropping, %.2f\n", time_frame); 1218 mp_msg(MSGT_AVSYNC,MSGL_DBG2,"\nstill dropping, %.2f\n", time_frame);
1302 } 1219 }
1303 } 1220 }
1304 #ifdef HAVE_NEW_GUI 1221 #ifdef HAVE_NEW_GUI
1305 if(use_gui){ 1222 if(use_gui) EventHandling();
1306 EventHandling();
1307 }
1308 #endif 1223 #endif
1309 video_out->check_events(); // check events AST 1224 video_out->check_events(); // check events AST
1310 } else { 1225 } else {
1311 // It's time to sleep... 1226 // It's time to sleep...
1312 current_module="sleep"; 1227 current_module="sleep";