framing.c.patch 2.34 KB
--- ./src/framing.c	2005-11-27 21:26:05.000000000 -0700
+++ ./src/framing.c	2007-11-11 13:36:15.000000000 -0700
@@ -315,6 +315,67 @@
 
   return(0);
 }
+#ifdef ELPHEL_OGG
+//! Support for a packet structure to use packets consisting of several memory chunks each (like MJPEG header
+//! and data in circular buffer of Elphel cameras (for now counting on copying packets in libogg)
+//int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
+  int ogg_stream_packetin_elph(ogg_stream_state *os, elph_ogg_packet *op) {
+
+  int lacing_vals=op->bytes/255+1,i;
+
+  if(os->body_returned){
+    /* advance packet data according to the body_returned pointer. We
+       had to keep it around to return a pointer into the buffer last
+       call */
+    
+    os->body_fill-=os->body_returned;
+    if(os->body_fill)
+      memmove(os->body_data,os->body_data+os->body_returned,
+	      os->body_fill);
+    os->body_returned=0;
+  }
+ 
+  /* make sure we have the buffer storage */
+  _os_body_expand(os,op->bytes);
+  _os_lacing_expand(os,lacing_vals);
+
+  /*! Copy in the submitted packet.  Yes, the copy is a waste; this is
+     the liability of overly clean abstraction for the time being.  It
+     will actually be fairly easy to eliminate the extra copy in the
+     future */
+//  memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
+//  os->body_fill+=op->bytes;
+  long bytes_left=op->bytes;
+  int  chunk_index=0;
+  while (bytes_left>0) {
+    memcpy(os->body_data+os->body_fill,op->packet[chunk_index].chunk,op->packet[chunk_index].bytes);
+    os->body_fill+=op->packet[chunk_index].bytes;
+    bytes_left-=op->packet[chunk_index].bytes;
+    chunk_index++;
+  }
+
+  /* Store lacing vals for this packet */
+  for(i=0;i<lacing_vals-1;i++){
+    os->lacing_vals[os->lacing_fill+i]=255;
+    os->granule_vals[os->lacing_fill+i]=os->granulepos;
+  }
+  os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
+  os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
+
+  /* flag the first segment as the beginning of the packet */
+  os->lacing_vals[os->lacing_fill]|= 0x100;
+
+  os->lacing_fill+=lacing_vals;
+
+  /* for the sake of completeness */
+  os->packetno++;
+
+  if(op->e_o_s)os->e_o_s=1;
+
+  return(0);
+}
+#endif
+
 
 /* This will flush remaining packets into a page (returning nonzero),
    even if there is not enough data to trigger a flush normally