[MPlayer-dev-eng] [RFC] stream controls with cache

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Thu May 22 12:24:16 CEST 2008


Hello,
something is still behaving a bit weird, but in principle attached patch
makes stream controls work through the cache (chapter seeking only so
far).
At least for cdda:// it works, though there is some code in the stream
layer that prints the current track number which results in really ugly
output...
Do you think this is an acceptable way to do this?

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: stream/cache2.c
===================================================================
--- stream/cache2.c	(revision 26849)
+++ stream/cache2.c	(working copy)
@@ -7,6 +7,7 @@
 #define READ_USLEEP_TIME 10000
 #define FILL_USLEEP_TIME 50000
 #define PREFILL_SLEEP_TIME 200
+#define CONTROL_SLEEP_TIME 200
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -57,6 +58,10 @@
 //  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 int control_res;
+  volatile off_t control_new_pos;
 } cache_vars_t;
 
 static int min_fill=0;
@@ -191,6 +196,22 @@
   
 }
 
+static void cache_execute_control(cache_vars_t *s) {
+  if (s->control == -1) return;
+  switch (s->control) {
+    case STREAM_CTRL_SEEK_TO_CHAPTER:
+    case STREAM_CTRL_GET_NUM_CHAPTERS:
+    case STREAM_CTRL_GET_CURRENT_CHAPTER:
+      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 +352,7 @@
     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 +406,27 @@
   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_CHAPTER:
+      s->control_uint_arg = *(unsigned int *)arg;
+    case STREAM_CTRL_GET_NUM_CHAPTERS:
+    case STREAM_CTRL_GET_CURRENT_CHAPTER:
+      s->control = cmd;
+      break;
+    default:
+      return STREAM_UNSUPPORTED;
+  }
+  while (s->control != -1)
+    usec_sleep(CONTROL_SLEEP_TIME);
+  switch (cmd) {
+    case STREAM_CTRL_GET_NUM_CHAPTERS:
+    case STREAM_CTRL_GET_CURRENT_CHAPTER:
+      *(unsigned int *)arg = s->control_uint_arg;
+      break;
+  }
+  stream->pos = s->read_filepos = s->control_new_pos;
+  return s->control_res;
+}
Index: stream/cache2.h
===================================================================
--- stream/cache2.h	(revision 26849)
+++ stream/cache2.h	(working copy)
@@ -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 */
Index: stream/stream.c
===================================================================
--- stream/stream.c	(revision 26849)
+++ stream/stream.c	(working copy)
@@ -381,6 +381,8 @@
 
 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);
 }
 


More information about the MPlayer-dev-eng mailing list