[xiph-commits] r9100 - in trunk/dryice: . src

arc at motherfish-iii.xiph.org arc at motherfish-iii.xiph.org
Wed Mar 30 23:39:02 PST 2005


Author: arc
Date: 2005-03-30 23:39:00 -0800 (Wed, 30 Mar 2005)
New Revision: 9100

Removed:
   trunk/dryice/codec_modules/
Modified:
   trunk/dryice/Makefile.am
   trunk/dryice/configure.in
   trunk/dryice/src/core.c
Log:
Some house-cleaning, trying to get back into this.


Modified: trunk/dryice/Makefile.am
===================================================================
--- trunk/dryice/Makefile.am	2005-03-30 03:31:21 UTC (rev 9099)
+++ trunk/dryice/Makefile.am	2005-03-31 07:39:00 UTC (rev 9100)
@@ -5,7 +5,7 @@
 
 SUBDIRS = src
 
-EXTRA_DIST = m4/ogg.m4 m4/xiph_compiler.m4 m4/theora.m4
+EXTRA_DIST = m4/ogg.m4 m4/xiph_compiler.m4 m4/theora.m4 m4/vorbis.m4 m4/shout.m4
 
 debug:
 	$(MAKE) all CFLAGS="@DEBUG@"

Modified: trunk/dryice/configure.in
===================================================================
--- trunk/dryice/configure.in	2005-03-30 03:31:21 UTC (rev 9099)
+++ trunk/dryice/configure.in	2005-03-31 07:39:00 UTC (rev 9100)
@@ -61,11 +61,6 @@
 
 dnl -- configure options --
 
-XIPH_PATH_THEORA([DRYICE_OPTIONAL="$DRYICE_OPTIONAL ../codec_modules/theora.o"],
-        AC_MSG_WARN([Theora support disabled!]))
-XIPH_VAR_APPEND([XIPH_CPPFLAGS],[$THEORA_CFLAGS])
-XIPH_VAR_PREPEND([XIPH_LIBS],[$THEORA_LIBS])
-
 dnl Make substitutions
 
 AC_SUBST(XIPH_CPPFLAGS)

Modified: trunk/dryice/src/core.c
===================================================================
--- trunk/dryice/src/core.c	2005-03-30 03:31:21 UTC (rev 9099)
+++ trunk/dryice/src/core.c	2005-03-31 07:39:00 UTC (rev 9100)
@@ -1,7 +1,7 @@
 /*
  * core.c, "the core" of the DryIce source client for Icecast2
  *
- * Copyright (c) 2004 Arc Riley <arc at xiph.org>
+ * Copyright (c) 2004,2005 Arc Riley <arc at xiph.org>
  *
  *    This program is free software; you can redistribute it and/or modify
  *    it under the terms of the GNU General Public License as published by
@@ -29,54 +29,25 @@
 #include <unistd.h>
 #include <sys/ioctl.h>
 #include <libgen.h>
+#include <math.h>
 #include <shout/shout.h>
+#include <theora/theora.h>
+#include "dryice/dryice.h"
 
-void
-usage (char *pname)
-{
-  fprintf (stderr,
-           "Usage: %s <options>\n"
-           " -c <file>            location of configuration file to use\n",
-           (char*)basename(pname));
-  exit (1);
-}
+/* I have no idea what this is used for */
+#ifdef _WIN32
+#include <fcntl.h>
+#endif
 
+
 int main(int argc, char **argv)
 {
-  FILE *config;
-  char config_filename[256]="dryice.conf";
-
   int c;
 
 
-/* This obviously needs more work 
 
-  while ((c = getopt (argc, argv, "c:")) != EOF) {
-    switch (c) {
-      case 'c':
-        config_filename = optarg;
-        break;
-      default:
-        usage (argv[0]);
-        break;
-    }
-  }
-
-
-  if ((config = fopen(config_filename, "r")) == NULL) {
-    printf("Could not open configuration file\n", config_filename);
-    return -1;
-  } 
-  fclose(config);
-*/
-
   /* BIG TODO
 
-  Ok after the configs are read, which for now will be hard-coded 
-  because I'm lazy and want to leave config file parsing for someone
-  else, we'll open the input module(s), get the parameters for encoding,
-  then open the codec module(s) with those parameters.
-
   Take the packets from the codec(s), toss them into an Ogg, ship the 
   whole thing out to libtheora with raw packets.  There is no need to 
   sleep since the stream is already running realtime, and thus, no need
@@ -87,3 +58,128 @@
 
   return 0;
 }
+
+
+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 */
+
+  yuv_buffer    yuv;
+  
+} dryice_theora_state;
+
+void * dryice_theora_init(dryice_params *dp) {
+
+  theora_info          ti;
+  dryice_theora_state *dts;
+
+  /* allocate module state and initialise video parameters */
+  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);
+
+  /* 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;
+  
+  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;
+  ti.colorspace = OC_CS_UNSPECIFIED;
+  ti.target_bitrate = dts->video_r;
+  ti.quality = dts->video_q;
+
+  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_auto_threshold = 80;
+  ti.keyframe_mindistance = 8;
+  ti.noise_sensitivity = 1;
+
+  theora_encode_init(&dts->td,&ti);
+  theora_info_clear(&ti);
+
+  return dts;
+}
+
+ogg_packet **
+dryice_theora_encode_headers(dryice_theora_state *dts) {
+  
+  theora_comment tc;
+
+  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;
+}
+
+ogg_packet **
+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 ;
+  
+  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;
+}
+
+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