[Mplayer-cvslog] CVS: main mplayer.c,1.404,1.405

Alban Bedel CVS albeu at mplayer.dev.hu
Sat Feb 23 22:22:57 CET 2002


Update of /cvsroot/mplayer/main
In directory mplayer:/var/tmp.root/cvs-serv4053

Modified Files:
	mplayer.c 
Log Message:
Make blocking call in libmpdemux interuptable (only with new input,
awnser to quit, pt_next, pt_up_step and alt_src_step)


Index: mplayer.c
===================================================================
RCS file: /cvsroot/mplayer/main/mplayer.c,v
retrieving revision 1.404
retrieving revision 1.405
diff -u -r1.404 -r1.405
--- mplayer.c	23 Feb 2002 15:12:45 -0000	1.404
+++ mplayer.c	23 Feb 2002 21:22:54 -0000	1.405
@@ -343,7 +343,7 @@
     stream=NULL;
   }
 
-#ifdef HAVE_LIRC
+#if defined(HAVE_LIRC) && ! defined(HAVE_NEW_INPUT)
   if(mask&INITED_LIRC){
     inited_flags&=~INITED_LIRC;
     current_module="uninit_lirc";
@@ -422,6 +422,34 @@
 }
 }
 
+// When libmpdemux perform a blocking operation (network connection or cache filling)
+// if the operation fail we use this function to check if it was interrupted by the user.
+// The function return a new value for eof.
+static int libmpdemux_was_interrupted(int eof) {
+#ifdef HAVE_NEW_INPUT
+  mp_cmd_t* cmd;
+  if((cmd = mp_input_get_cmd(0,0)) != NULL) {
+       switch(cmd->id) {
+       case MP_CMD_QUIT:
+	 exit_player(MSGTR_Exit_quit);
+       case MP_CMD_PLAY_TREE_STEP: {
+	 eof = (cmd->args[0].v.i > 0) ? PT_NEXT_ENTRY : PT_PREV_ENTRY;
+       } break;
+       case MP_CMD_PLAY_TREE_UP_STEP: {
+	 eof = (cmd->args[0].v.i > 0) ? PT_UP_NEXT : PT_UP_PREV;
+       } break;	  
+       case MP_CMD_PLAY_ALT_SRC_STEP: {
+	 eof = (cmd->args[0].v.i > 0) ?  PT_NEXT_SRC : PT_PREV_SRC;
+       } break;
+       }
+       mp_cmd_free(cmd);
+  }
+  return eof;
+#else
+  return 0;
+#endif
+}
+
 int main(int argc,char* argv[], char *envp[]){
 
 #ifdef USE_SUB
@@ -724,6 +752,11 @@
 
 play_next_file:
 
+if(!use_stdin && !slave_mode){
+  getch2_enable();  // prepare stdin for hotkeys...
+  inited_flags|=INITED_GETCH2;
+}
+
 #ifdef HAVE_NEW_GUI
     if ( use_gui ) {
 
@@ -891,11 +924,24 @@
     }
   }
 
+#ifdef HAVE_NEW_INPUT
+    if(!slave_mode && filename && !use_stdin && !strcmp(filename,"-")) {      
+    mp_input_rm_key_fd(0);
+    use_stdin = 1;
+  }
+  else if(!slave_mode && use_stdin && (!filename || strcmp(filename,"-"))) {
+    mp_input_add_key_fd(0,1,NULL,NULL);
+    use_stdin = 0;
+  }
+#else
+  use_stdin=filename && (!strcmp(filename,"-"));
+#endif
+
   current_module="open_stream";
   stream=open_stream(filename,vcd_track,&file_format);
   if(!stream) { // error...
-    uninit_player(inited_flags-(INITED_GUI+INITED_LIRC+INITED_INPUT));
-    goto goto_next_file_src;
+    eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY);
+    goto goto_next_file;
   }
   inited_flags|=INITED_STREAM;
   if(stream->type == STREAMTYPE_PLAYLIST) {
@@ -905,23 +951,29 @@
     entry = parse_playtree(stream);
     if(!entry) {      
       entry = playtree_iter->tree;
-      if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY)
+      if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
+	eof = PT_NEXT_ENTRY;
 	goto goto_next_file;
-      if(playtree_iter->tree == entry) { // Loop with a single file
-	if(play_tree_iter_up_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY)
+      }
+      if(playtree_iter->tree == entry ) { // Loop with a single file
+	if(play_tree_iter_up_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
+	  eof = PT_NEXT_ENTRY;
 	  goto goto_next_file;
+	}
       }
       play_tree_remove(entry,1,1);
-      uninit_player(inited_flags-(INITED_GUI+INITED_LIRC+INITED_INPUT));
-      goto goto_next_file_src;
+      eof = PT_NEXT_SRC;
+      goto goto_next_file;
     }
     play_tree_insert_entry(playtree_iter->tree,entry);
     entry = playtree_iter->tree;
-    if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY)
+    if(play_tree_iter_step(playtree_iter,1,0) != PLAY_TREE_ITER_ENTRY) {
+      eof = PT_NEXT_ENTRY;
       goto goto_next_file;
+    }      
     play_tree_remove(entry,1,1);
-    uninit_player(inited_flags-(INITED_GUI+INITED_LIRC+INITED_INPUT));
-    goto goto_next_file_src;
+    eof = PT_NEXT_SRC;
+    goto goto_next_file;
   }
   stream->start_pos+=seek_to_byte;
 
@@ -954,20 +1006,11 @@
 #endif
 
     // initial prefill: 20%  later: 5%  (should be set by -cacheopts)
-  if(stream_cache_size) stream_enable_cache(stream,stream_cache_size*1024,stream_cache_size*1024/5,stream_cache_size*1024/20);
-
-#ifdef HAVE_NEW_INPUT
-    if(!slave_mode && filename && !use_stdin && !strcmp(filename,"-")) {      
-    mp_input_rm_key_fd(0);
-    use_stdin = 1;
-  }
-  else if(!slave_mode && use_stdin && (!filename || strcmp(filename,"-"))) {
-    mp_input_add_key_fd(0,1,NULL,NULL);
-    use_stdin = 0;
-  }
-#else
-  use_stdin=filename && (!strcmp(filename,"-"));
-#endif
+ if(stream_cache_size && ! stream_enable_cache(stream,stream_cache_size*1024,stream_cache_size*1024/5,stream_cache_size*1024/20)) {
+   eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY);
+   if(eof)
+     goto goto_next_file;
+ }
 
 #ifdef HAVE_LIBCSS
   current_module="libcss";
@@ -1532,7 +1575,12 @@
   ao_data.pts=sh_audio->timer*90000.0;
   playsize=audio_out->get_space();
   
-  if(!playsize) break; // buffer is full, do not block here!!!
+  if(!playsize) {
+    if(sh_video)
+      break; // buffer is full, do not block here!!!
+    usec_sleep(10000); // Wait a tick before retry
+    continue;
+  }
   
   if(playsize>MAX_OUTBURST) playsize=MAX_OUTBURST; // we shouldn't exceed it!
   //if(playsize>outburst) playsize=outburst;
@@ -1592,7 +1640,6 @@
 		    ,(sh_audio->timer>0.5)?100.0*audio_time_usage/(double)sh_audio->timer:0
 		    ,cache_fill_status
 		    );
-  usec_sleep(sh_audio->a_buffer_len/(float)sh_audio->o_bps*1000000);
   goto read_input;
 }
 
@@ -2826,8 +2873,6 @@
      uninit_player(INITED_ALL-(INITED_GUI+INITED_LIRC+INITED_INPUT));
      eof = eof == PT_PREV_SRC ? -1 : 1;
 }
-
-goto_next_file_src: // When we have multiple src for file
 
 if(eof == 0) eof = 1;
 




More information about the MPlayer-cvslog mailing list