[Cvs-annodex] commit (annodex): liboggplay/trunk/include/oggplay/oggplay_enums.h liboggplay/trunk/src/liboggplay/oggplay.c liboggplay/trunk/src/liboggplay/oggplay_callback_info.c liboggplay/trunk/src/liboggplay/oggplay_private.h +liboggplay/trunk/src/liboggplay/oggplay_buffer.c

shans nobody at lists.annodex.net
Wed Oct 18 05:31:41 UTC 2006


Update of /var/local/lib/svn/annodex (new revision 2527)

Added files:
   liboggplay/trunk/src/liboggplay/oggplay_buffer.c

Modified files:
   liboggplay/trunk/include/oggplay/oggplay_enums.h
   liboggplay/trunk/src/liboggplay/oggplay.c
   liboggplay/trunk/src/liboggplay/oggplay_callback_info.c
   liboggplay/trunk/src/liboggplay/oggplay_private.h

Log Message:
*BROKEN CHECKIN* started lock-free buffer implementation



Modified: liboggplay/trunk/include/oggplay/oggplay_enums.h
===================================================================
--- liboggplay/trunk/include/oggplay/oggplay_enums.h	2006-10-17 05:33:26 UTC (rev 2526)
+++ liboggplay/trunk/include/oggplay/oggplay_enums.h	2006-10-18 05:31:41 UTC (rev 2527)
@@ -53,7 +53,10 @@
   E_OGGPLAY_TRACK_IS_OVER     = -9,
   E_OGGPLAY_BAD_CALLBACK_INFO = -10,
   E_OGGPLAY_WRONG_TRACK_TYPE  = -11,
-  E_OGGPLAY_UNINITIALISED     = -12
+  E_OGGPLAY_UNINITIALISED     = -12,
+  E_OGGPLAY_CALLBACK_MODE     = -13,
+  E_OGGPLAY_BUFFER_MODE       = -14,
+  E_OGGPLAY_USER_INTERRUPT    = -15
 } OggPlayErrorCode;
 
 typedef enum OggPlayDataType {

Modified: liboggplay/trunk/src/liboggplay/oggplay.c
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay.c	2006-10-17 05:33:26 UTC (rev 2526)
+++ liboggplay/trunk/src/liboggplay/oggplay.c	2006-10-18 05:31:41 UTC (rev 2527)
@@ -70,6 +70,7 @@
   me->callback = NULL;
   me->target = 0;
   me->active_tracks = 0;
+  me->buffer = NULL;
 
   /*
    * start to retrieve data, until we get all of the track info.  We need
@@ -110,6 +111,10 @@
     return E_OGGPLAY_BAD_OGGPLAY;
   }
 
+  if (me->buffer != NULL) {
+    return E_OGGPLAY_BUFFER_MODE;
+  }
+  
   me->callback = callback;
   me->callback_user_ptr = user;
     
@@ -128,6 +133,10 @@
     return E_OGGPLAY_BAD_TRACK;
   }
   
+  if (me->buffer != NULL) {
+    return E_OGGPLAY_BUFFER_MODE;
+  }
+  
   me->callback_period = me->decode_data[track]->granuleperiod * frames;
   me->target = me->callback_period - 1;
  

Added: liboggplay/trunk/src/liboggplay/oggplay_buffer.c
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay_buffer.c	2006-10-17 05:33:26 UTC (rev 2526)
+++ liboggplay/trunk/src/liboggplay/oggplay_buffer.c	2006-10-18 05:31:41 UTC (rev 2527)
@@ -0,0 +1,101 @@
+/*
+ * Call this function to initialise the oggplay lock-free buffer.  Do not use
+ * the buffer and the callback together!
+ */
+
+#include "oggplay_private.h"
+
+#define OGGPLAY_DEFAULT_BUFFER_SIZE   20
+
+OggPlayBuffer *
+oggplay_buffer_new_buffer(void, int size) {
+
+  if (size < 0) {
+    size = OGGPLAY_DEFAULT_BUFFER_SIZE;
+  
+  OggPlayBuffer *buffer = malloc(sizeof (OggPlayBuffer));
+
+  buffer->buffer_list = malloc(sizeof (void *) * size);
+  memset(buffer->buffer_list, 0, sizeof (void *) * size);
+  buffer->buffer_mirror = malloc(sizeof (void *) * size);
+  memset(buffer->buffer_mirror, 0, sizeof (void *) * size);
+
+  buffer->buffer_size = size;
+  buffer->last_filled = -1;
+  buffer->last_emptied = -1;
+  
+}
+
+int
+oggplay_buffer_callback(OggPlay *me, int tracks, 
+                 OggPlayCallbackInfo **track_info, void *user) {
+
+  int                   i;
+  int                   j;
+  int                   k;
+  OggPlayDataHeader  ** headers;
+  OggPlayBuffer       * buffer;
+
+  if (me->buffer == NULL) {
+    return -1;
+  }
+ 
+  /*
+   * lock the item going into the buffer so that it doesn't get cleaned up
+   */
+  for (i = 0; i < tracks; i++) {
+    headers = oggplay_callback_info_get_headers(track_info[i]);
+    required = oggplay_callback_info_get_required(track_info[i]);
+    for (j = 0; j < required; j++) {
+      oggplay_callback_info_lock_item(headers[j]);
+    }
+  }
+
+  buffer = me->buffer;
+
+  /*
+   * fill both mirror and list, mirror first to avoid getting inconsistencies
+   */
+
+  buffer->buffer_mirror[++(buffer->last_filled)] = track_info;
+  buffer->buffer_list[buffer->last_filled] = track_info;
+  
+  /*
+   * check for empties
+   */
+
+  for (k = 0; i < buffer->size; k++) {
+    if (buffer->buffer_list[k] == NULL && buffer->buffer_mirror[k] != NULL) {
+      OggPlayCallbackInfo **ti = (OggPlayCallbackInfo **)
+  
+}
+
+OggPlayErrorCode
+oggplay_use_buffer(OggPlay *me, int size) {
+
+  int i;
+  
+  if (me == NULL) {
+    return E_OGGPLAY_BAD_OGGPLAY;
+  }
+
+  if (me->callback != NULL) {
+    return E_OGGPLAY_CALLBACK_MODE;
+  }
+
+  if (me->buffer != NULL) {
+    continue;
+  }
+  
+  me->buffer = oggplay_buffer_new_buffer(size);
+
+  oggplay_set_data_callback(me, oggplay_buffer_callback, NULL);
+  for (i = 0; i < me->num_frames; i++) {
+    if (oggplay_get_track_type(me, i) == OGGZ_CONTENT_THEORA) { 
+      oggplay_set_callback_num_frames(me, i, 1);
+      break;
+    }
+  }
+
+  return E_OGGPLAY_OK;
+}

Modified: liboggplay/trunk/src/liboggplay/oggplay_callback_info.c
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay_callback_info.c	2006-10-17 05:33:26 UTC (rev 2526)
+++ liboggplay/trunk/src/liboggplay/oggplay_callback_info.c	2006-10-18 05:31:41 UTC (rev 2527)
@@ -162,6 +162,27 @@
 
 }
 
+void
+oggplay_callback_info_lock_item(OggPlayDataHeader *header) {
+
+  if (header == NULL) {
+    return;
+  }
+  
+  header->lock = 2;
+
+}
+
+void
+oggplay_callback_info_unlock_item(OggPlayDataHeader *header) {
+  
+  if (header == NULL) {
+    return;
+  }
+
+  header->lock = 1;
+}
+
 OggPlayVideoData *
 oggplay_callback_info_get_video_data(OggPlayDataHeader *header) {
 

Modified: liboggplay/trunk/src/liboggplay/oggplay_private.h
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay_private.h	2006-10-17 05:33:26 UTC (rev 2526)
+++ liboggplay/trunk/src/liboggplay/oggplay_private.h	2006-10-18 05:31:41 UTC (rev 2527)
@@ -67,6 +67,7 @@
   OggPlayDataType       data_type;
   int                   available_records;
   int                   required_records;
+  int                   lock;
   OggPlayDataHeader **  records;
 };
 
@@ -106,6 +107,14 @@
   FishSoundInfo   sound_info;
 } OggPlayVorbisDecode;
 
+typedef struct {
+  void ** buffer_list;
+  void ** buffer_mirror;
+  int     buffer_size;
+  int     last_filled;
+  int     last_emptied;
+} OggPlayBuffer;
+
 struct _OggPlay {
   OggPlayReader       * reader;
   char                * input_name;
@@ -118,6 +127,7 @@
   void                * callback_user_ptr;
   ogg_int64_t           target;
   int                   active_tracks;
+  OggPlayBuffer       * buffer;
 };
 
 #include "oggplay_callback.h"


-- 
shans



More information about the cvs-annodex mailing list