[MPlayer-cvslog] r26865 - in trunk/stream: cache2.c cache2.h stream.c stream_dvd.c

reimar subversion at mplayerhq.hu
Sat May 24 09:48:35 CEST 2008


Author: reimar
Date: Sat May 24 09:48:35 2008
New Revision: 26865

Log:
Add basic support for stream controls with cache enabled.


Modified:
   trunk/stream/cache2.c
   trunk/stream/cache2.h
   trunk/stream/stream.c
   trunk/stream/stream_dvd.c

Modified: trunk/stream/cache2.c
==============================================================================
--- trunk/stream/cache2.c	(original)
+++ trunk/stream/cache2.c	Sat May 24 09:48:35 2008
@@ -7,6 +7,7 @@
 #define READ_USLEEP_TIME 10000
 #define FILL_USLEEP_TIME 50000
 #define PREFILL_SLEEP_TIME 200
+#define CONTROL_SLEEP_TIME 0
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -57,6 +58,11 @@ typedef struct {
 //  int fifo_flag;  // 1 if we should use FIFO to notice cache about buffer reads.
   // callback
   stream_t* stream;
+  volatile int control;
+  volatile unsigned control_uint_arg;
+  volatile double control_double_arg;
+  volatile int control_res;
+  volatile off_t control_new_pos;
 } cache_vars_t;
 
 static int min_fill=0;
@@ -191,6 +197,31 @@ int cache_fill(cache_vars_t* s){
   
 }
 
+static void cache_execute_control(cache_vars_t *s) {
+  if (s->control == -1) return;
+  switch (s->control) {
+    case STREAM_CTRL_GET_TIME_LENGTH:
+    case STREAM_CTRL_GET_CURRENT_TIME:
+    case STREAM_CTRL_SEEK_TO_TIME:
+    case STREAM_CTRL_GET_ASPECT_RATIO:
+      s->control_res = s->stream->control(s->stream, s->control, &s->control_double_arg);
+      break;
+    case STREAM_CTRL_SEEK_TO_CHAPTER:
+    case STREAM_CTRL_GET_NUM_CHAPTERS:
+    case STREAM_CTRL_GET_CURRENT_CHAPTER:
+    case STREAM_CTRL_GET_NUM_ANGLES:
+    case STREAM_CTRL_GET_ANGLE:
+    case STREAM_CTRL_SET_ANGLE:
+      s->control_res = s->stream->control(s->stream, s->control, &s->control_uint_arg);
+      break;
+    default:
+      s->control_res = STREAM_UNSUPPORTED;
+      break;
+  }
+  s->control_new_pos = s->stream->pos;
+  s->control = -1;
+}
+
 cache_vars_t* cache_init(int size,int sector){
   int num;
 #if !defined(WIN32) && !defined(__OS2__)
@@ -331,6 +362,7 @@ static void ThreadProc( void *s ){
     if(!cache_fill((cache_vars_t*)s)){
 	 usec_sleep(FILL_USLEEP_TIME); // idle
     }
+    cache_execute_control((cache_vars_t*)s);
 //	 cache_stats(s->cache_data);
   }
 }
@@ -384,3 +416,51 @@ int cache_stream_seek_long(stream_t *str
   mp_msg(MSGT_CACHE,MSGL_V,"cache_stream_seek: WARNING! Can't seek to 0x%"PRIX64" !\n",(int64_t)(pos+newpos));
   return 0;
 }
+
+int cache_do_control(stream_t *stream, int cmd, void *arg) {
+  cache_vars_t* s = stream->cache_data;
+  switch (cmd) {
+    case STREAM_CTRL_SEEK_TO_TIME:
+      s->control_double_arg = *(double *)arg;
+      s->control = cmd;
+      break;
+    case STREAM_CTRL_SEEK_TO_CHAPTER:
+    case STREAM_CTRL_SET_ANGLE:
+      s->control_uint_arg = *(unsigned *)arg;
+      s->control = cmd;
+      break;
+    case STREAM_CTRL_GET_NUM_CHAPTERS:
+    case STREAM_CTRL_GET_CURRENT_CHAPTER:
+// the core might call these every frame, they are too slow for this...
+//    case STREAM_CTRL_GET_TIME_LENGTH:
+//    case STREAM_CTRL_GET_CURRENT_TIME:
+    case STREAM_CTRL_GET_ASPECT_RATIO:
+    case STREAM_CTRL_GET_NUM_ANGLES:
+    case STREAM_CTRL_GET_ANGLE:
+      s->control = cmd;
+      break;
+    default:
+      return STREAM_UNSUPPORTED;
+  }
+  while (s->control != -1)
+    usec_sleep(CONTROL_SLEEP_TIME);
+  switch (cmd) {
+    case STREAM_CTRL_GET_TIME_LENGTH:
+    case STREAM_CTRL_GET_CURRENT_TIME:
+    case STREAM_CTRL_GET_ASPECT_RATIO:
+      *(double *)arg = s->control_double_arg;
+      break;
+    case STREAM_CTRL_GET_NUM_CHAPTERS:
+    case STREAM_CTRL_GET_CURRENT_CHAPTER:
+    case STREAM_CTRL_GET_NUM_ANGLES:
+    case STREAM_CTRL_GET_ANGLE:
+      *(unsigned *)arg = s->control_uint_arg;
+      break;
+    case STREAM_CTRL_SEEK_TO_CHAPTER:
+    case STREAM_CTRL_SEEK_TO_TIME:
+    case STREAM_CTRL_SET_ANGLE:
+      stream->pos = s->read_filepos = s->control_new_pos;
+      break;
+  }
+  return s->control_res;
+}

Modified: trunk/stream/cache2.h
==============================================================================
--- trunk/stream/cache2.h	(original)
+++ trunk/stream/cache2.h	Sat May 24 09:48:35 2008
@@ -4,5 +4,6 @@
 #include "stream.h"
 
 extern void cache_uninit(stream_t *s);
+int cache_do_control(stream_t *stream, int cmd, void *arg);
 
 #endif /* MPLAYER_CACHE2_H */

Modified: trunk/stream/stream.c
==============================================================================
--- trunk/stream/stream.c	(original)
+++ trunk/stream/stream.c	Sat May 24 09:48:35 2008
@@ -381,6 +381,8 @@ void stream_reset(stream_t *s){
 
 int stream_control(stream_t *s, int cmd, void *arg){
   if(!s->control) return STREAM_UNSUPPORTED;
+  if (s->cache_pid)
+    return cache_do_control(s, cmd, arg);
   return s->control(s, cmd, arg);
 }
 

Modified: trunk/stream/stream_dvd.c
==============================================================================
--- trunk/stream/stream_dvd.c	(original)
+++ trunk/stream/stream_dvd.c	Sat May 24 09:48:35 2008
@@ -41,7 +41,6 @@
 #include "libmpdemux/demuxer.h"
 #include "libavutil/intreadwrite.h"
 
-extern int stream_cache_size;
 extern char* dvd_device;
 int dvd_angle=1;
 int dvd_speed=0; /* 0 => don't touch speed */
@@ -708,7 +707,6 @@ static int control(stream_t *stream,int 
         case STREAM_CTRL_SEEK_TO_CHAPTER:
         {
             int r;
-            if(stream_cache_size > 0) return STREAM_UNSUPPORTED;
             r = seek_to_chapter(stream, d->vts_file, d->tt_srpt, d->cur_title-1, *((unsigned int *)arg));
             if(! r) return STREAM_UNSUPPORTED;
 
@@ -716,14 +714,12 @@ static int control(stream_t *stream,int 
         }
         case STREAM_CTRL_GET_CURRENT_CHAPTER:
         {
-            if(stream_cache_size > 0) return STREAM_UNSUPPORTED;
             *((unsigned int *)arg) = dvd_chapter_from_cell(d, d->cur_title-1, d->cur_cell);
             return 1;
         }
         case STREAM_CTRL_GET_CURRENT_TIME:
         {
             double tm;
-            if(stream_cache_size > 0) return STREAM_UNSUPPORTED;
             tm = dvd_get_current_time(stream, 0);
             if(tm != -1) {
               *((double *)arg) = tm;
@@ -733,7 +729,6 @@ static int control(stream_t *stream,int 
         }
         case STREAM_CTRL_SEEK_TO_TIME:
         {
-            if(stream_cache_size > 0) return STREAM_UNSUPPORTED;
             if(dvd_seek_to_time(stream, d->vts_file, *((double*)arg)))
               return 1;
             break;
@@ -1062,8 +1057,6 @@ static int open_s(stream_t *stream,int m
     *file_format = DEMUXER_TYPE_MPEG_PS;
     mp_msg(MSGT_DVD,MSGL_V,"DVD start=%d end=%d  \n",d->cur_pack,d->cur_pgc->cell_playback[d->last_cell-1].last_sector);
     stream->priv = (void*)d;
-    if(stream_cache_size > 0)
-      mp_msg(MSGT_DVD,MSGL_INFO,"[stream_dvd] Warning! the cache is enabled. Seeking won't work correctly\n");
     return STREAM_OK;
 
 fail:



More information about the MPlayer-cvslog mailing list