[xiph-commits] r9102 - trunk/dryice/src

arc at motherfish-iii.xiph.org arc at motherfish-iii.xiph.org
Thu Mar 31 22:08:35 PST 2005


Author: arc
Date: 2005-03-31 22:08:34 -0800 (Thu, 31 Mar 2005)
New Revision: 9102

Modified:
   trunk/dryice/src/core.c
Log:
low-grade cleaning up.. things still really messy. 

next time i try to work on serious stuff at 5am, please, someone stop me


Modified: trunk/dryice/src/core.c
===================================================================
--- trunk/dryice/src/core.c	2005-03-31 08:06:10 UTC (rev 9101)
+++ trunk/dryice/src/core.c	2005-04-01 06:08:34 UTC (rev 9102)
@@ -42,10 +42,8 @@
 
 int main(int argc, char **argv)
 {
-  int c;
 
 
-
   /* BIG TODO
 
   Take the packets from the codec(s), toss them into an Ogg, ship the 
@@ -61,125 +59,92 @@
 
 
 typedef struct dryice_theora_state {
-  int video_x;
-  int video_y;
-  int frame_x;
-  int frame_y;
-  int frame_x_offset;  
-  int frame_y_offset;
-  int video_raten;
-  int video_rated;
-  int video_an;
-  int video_ad;
-
-  int video_r;
-  int video_q;
-
   theora_state  td;
-  ogg_packet packet_buff[4]; /* most packets we'll ever have to return */
-
+  ogg_packet   *packet_buff[4];
   yuv_buffer    yuv;
-  
 } dryice_theora_state;
 
-void * dryice_theora_init(dryice_params *dp) {
+void * dryice_theora_init(dryice_video_params *dvp) {
 
   theora_info          ti;
   dryice_theora_state *dts;
 
-  /* allocate module state and initialise video parameters */
+  theora_info_init(&ti);
+
+  /* allocate encode state */
   dts = malloc(sizeof(dryice_theora_state));
-  dts->frame_x = dp->frame_width;
-  dts->frame_y = dp->frame_height;
-  dts->video_raten = dp->framerate_numerator;
-  dts->video_rated = dp->framerate_denominator;
-  dts->packet_buff = malloc(sizeof(void *)*4);
 
+  /* Is this nessesary?  Hmm.. artifact of a late night of hacking..
+  dts->packet_buff = malloc(sizeof(void *)*4); */
+
   /* Theora has a divisible-by-sixteen restriction for the encoded video size */
   /* scale the frame size up to the nearest /16 and calculate offsets */
-  dts->video_x = ((dts->frame_x + 15) >>4)<<4;
-  dts->video_y = ((dts->frame_y + 15) >>4)<<4;
-  dts->frame_x_offset = (dts->video_x - dts->frame_x)/2;
-  dts->frame_y_offset = (dts->video_y - dts->frame_y)/2;
+  ti.frame_width = dvp->frame_width;
+  ti.frame_height = dvp->frame_height;
+  ti.width = ((dvp->frame_width + 15) >>4)<<4;
+  ti.height = ((dvp->frame_height + 15) >>4)<<4;
+  ti.offset_x = (ti.width - dvp->frame_width)/2;
+  ti.offset_y = (ti.height - dvp->frame_height)/2;
+  ti.fps_numerator = dvp->framerate_numerator;
+  ti.fps_denominator = dvp->framerate_denominator;
   
-  dts->video_an = -1;
-  dts->video_ad = -1;
-  dts->video_r = -1;
-  dts->video_q = 8;
-
-  theora_info_init(&ti);
-  ti.width = dts->video_x;
-  ti.height = dts->video_y;
-  ti.frame_width = dts->frame_x;
-  ti.frame_height = dts->frame_y;
-  ti.offset_x = dts->frame_x_offset;
-  ti.offset_y = dts->frame_y_offset;
-  ti.fps_numerator = dts->video_raten;
-  ti.fps_denominator = dts->video_rated;
-  ti.aspect_numerator = dts->video_an;
-  ti.aspect_denominator = dts->video_ad;
+  /* These are unspecified/undetermined */
+  ti.aspect_numerator = -1;
+  ti.aspect_denominator = -1;
   ti.colorspace = OC_CS_UNSPECIFIED;
-  ti.target_bitrate = dts->video_r;
-  ti.quality = dts->video_q;
+  ti.target_bitrate = -1;
+  ti.quality = 8;
 
   ti.dropframes_p = 0;
   ti.quick_p = 1;
   ti.keyframe_auto_p = 1;
   ti.keyframe_frequency = 64;
   ti.keyframe_frequency_force = 64;
-  ti.keyframe_data_target_bitrate = dts->video_r*1.5;
+  ti.keyframe_data_target_bitrate = ti.target_bitrate*1.5;
   ti.keyframe_auto_threshold = 80;
   ti.keyframe_mindistance = 8;
   ti.noise_sensitivity = 1;
 
-  theora_encode_init(&dts->td,&ti);
+  theora_encode_init(&dts->td, &ti);
   theora_info_clear(&ti);
 
+  dts->yuv.y_width = dvp->frame_width;
+  dts->yuv.y_height = dvp->frame_height;
+  dts->yuv.y_stride = dvp->frame_width;
+  dts->yuv.uv_width = dvp->frame_width / 2;
+  dts->yuv.uv_height = dvp->frame_height / 2;
+  dts->yuv.uv_stride = dvp->frame_width / 2;
+
   return dts;
 }
 
-ogg_packet **
+void 
 dryice_theora_encode_headers(dryice_theora_state *dts) {
   
   theora_comment tc;
 
-  theora_encode_header(&dts->td, &dts->packet_buff[0]);
+  theora_encode_header(&dts->td, dts->packet_buff[0]);
   theora_comment_init(&tc);
-  theora_encode_comment(&tc, &dts->packet_buff[1]);
-  theora_encode_tables(&dts->td, &dts->packet_buff[2]);
-  &dts->packet_buff[3] = 0;  /* null-terminate the array */
-
-  return dts->packet_buff;
+  theora_encode_comment(&tc, dts->packet_buff[1]);
+  theora_encode_tables(&dts->td, dts->packet_buff[2]);
+  dts->packet_buff[3] = 0;  /* null-terminate the array */
 }
 
-ogg_packet **
+void
 dryice_theora_encode_frame(dryice_theora_state *dts,
                            char *yuvframe) {
-  signed char        *line;
-  int i, e;
-
-  yuv.y_width = dts->video_x;
-  yuv.y_height = dts->video_y;
-  yuv.y_stride = dts->video_x;
-
-  yuv.uv_width = dts->video_x / 2;
-  yuv.uv_height = dts->video_y / 2;
-  yuv.uv_stride = dts->video_x / 2;
-
-  yuv.y = yuvframe;
-  yuv.u = yuvframe + dts->video_x * dts->video_y;
-  yuv.v = yuvframe + dts->video_x * dts->video_y * 5/4 ;
+  /* These calculations need to be checked */
+  dts->yuv.y = yuvframe;
+  dts->yuv.u = dts->yuv.y + dts->yuv.y_width * dts->yuv.y_height;
+  dts->yuv.v = dts->yuv.u + dts->yuv.uv_width * dts->yuv.uv_height;
   
-  theora_encode_YUVin(&dts->td, &yuv);
-  theora_encode_packetout(&dts->td, 0, &dts->packet_buff[0]);
-  &dts->packet_buff[1] = 0;
- 
-  return dts->packet_buff;
+  theora_encode_YUVin(&dts->td, &dts->yuv);
+  theora_encode_packetout(&dts->td, 0, dts->packet_buff[0]);
+  dts->packet_buff[1] = 0;
 }
 
 void
 dryice_theora_clear(dryice_theora_state *dts) {
-  free(dts->packet_buff);
   theora_clear(&dts->td);
   free(dts);
 }



More information about the commits mailing list