[xiph-commits] r13646 - trunk/theora/tests

giles at svn.xiph.org giles at svn.xiph.org
Tue Aug 28 12:53:25 PDT 2007


Author: giles
Date: 2007-08-28 12:53:24 -0700 (Tue, 28 Aug 2007)
New Revision: 13646

Added:
   trunk/theora/tests/granulepos.c
Modified:
   trunk/theora/tests/
   trunk/theora/tests/Makefile.am
Log:
Add a rough test routine for the encoder's granulepos generation.



Property changes on: trunk/theora/tests
___________________________________________________________________
Name: svn:ignore
   - Makefile
Makefile.in
noop
comment-test
commentexp-test
.libs
.deps
.gdb_history

   + Makefile
Makefile.in
noop
comment-test
commentexp-test
granulepos
.libs
.deps
.gdb_history


Modified: trunk/theora/tests/Makefile.am
===================================================================
--- trunk/theora/tests/Makefile.am	2007-08-28 18:43:40 UTC (rev 13645)
+++ trunk/theora/tests/Makefile.am	2007-08-28 19:53:24 UTC (rev 13646)
@@ -11,7 +11,7 @@
 
 TESTS_ENVIRONMENT = $(VALGRIND_ENVIRONMENT)
 
-TESTS = noop comment-test
+TESTS = noop comment-test granulepos
 
 noinst_PROGRAMS = $(TESTS)
 
@@ -22,3 +22,7 @@
 comment_test_SOURCES = comment-test.c
 comment_test_LDADD = $(THEORA_LIBS)
 comment_test_CFLAGS = $(OGG_CFLAGS)
+
+granulepos_SOURCES = granulepos.c
+granulepos_LDADD = $(THEORA_LIBS)
+granulepos_CFLAGS = $(OGG_CFLAGS)

Added: trunk/theora/tests/granulepos.c
===================================================================
--- trunk/theora/tests/granulepos.c	                        (rev 0)
+++ trunk/theora/tests/granulepos.c	2007-08-28 19:53:24 UTC (rev 13646)
@@ -0,0 +1,148 @@
+/********************************************************************
+ *                                                                  *
+ * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE.   *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
+ *                                                                  *
+ * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2007                *
+ * by the Xiph.Org Foundation http://www.xiph.org/                  *
+ *                                                                  *
+ ********************************************************************
+
+  function: routines for validating encoder granulepos generation
+  last mod: $Id: $
+
+ ********************************************************************/
+
+#include <stdlib.h>
+#include <theora/theora.h>
+
+#include "tests.h"
+
+static int ilog(unsigned int v){
+  int ret=0;
+  while(v){
+    ret++;
+    v>>=1;
+  }
+  return(ret);
+}
+
+static int
+granulepos_test_encode (int frequency, int auto_p)
+{
+  theora_info ti;
+  theora_state th;
+  int result;
+  int frame, tframe, keyframe, keydist;
+  int shift;
+  yuv_buffer yuv;
+  unsigned char *framedata;
+  ogg_packet op;
+  long long int last_granule = -1;
+
+  INFO ("+ Initializing theora_info struct");
+  theora_info_init (&ti);
+
+  ti.width = 32;
+  ti.height = 32;
+  ti.frame_width = ti.width;
+  ti.frame_height = ti.frame_height;
+  ti.offset_x = 0;
+  ti.offset_y = 0;
+  ti.fps_numerator = 16;
+  ti.fps_denominator = 1;
+  ti.aspect_numerator = 1;
+  ti.aspect_denominator = 1;
+  ti.colorspace = OC_CS_UNSPECIFIED;
+  ti.pixelformat = OC_PF_420;
+  ti.target_bitrate = 0;
+  ti.quality = 16;
+
+  ti.dropframes_p = 0;
+  ti.quick_p = 1;
+
+  /* check variations of automatic or forced keyframe choice */
+  ti.keyframe_auto_p = auto_p;
+  /* check with variations of the maximum gap */
+  ti.keyframe_frequency = frequency;
+  ti.keyframe_frequency_force = frequency;
+
+  ti.keyframe_data_target_bitrate = ti.target_bitrate * 1.5;
+  ti.keyframe_auto_threshold = 80;
+  ti.keyframe_mindistance = MIN(8, frequency);
+  ti.noise_sensitivity = 1;
+
+  INFO ("+ Initializing theora_state for encoding");
+  result = theora_encode_init (&th, &ti);
+  if (result == OC_DISABLED) {
+    INFO ("+ Clearing theora_state");
+    theora_clear (&th);
+  } else if (result < 0) {
+    FAIL ("negative return code initializing encoder");
+  }
+
+  INFO ("+ Setting up dummy 4:2:0 frame data");
+  framedata = calloc(ti.height, ti.width);
+  yuv.y_width = ti.width;
+  yuv.y_height = ti.height;
+  yuv.y_stride = ti.width;
+  yuv.y = framedata;
+  yuv.uv_width = ti.width / 2;
+  yuv.uv_height = ti.width / 2;
+  yuv.uv_stride = ti.width;
+  yuv.u = framedata;
+  yuv.v = framedata;
+
+  INFO ("+ Checking granulepos generation");
+  shift = theora_granule_shift(&ti);
+  for (frame = 0; frame < frequency * 2 + 1; frame++) {
+    result = theora_encode_YUVin (&th, &yuv);
+    if (result < 0) {
+      printf("theora_encode_YUVin() returned %d\n", result);
+      FAIL ("negative error code submitting frame for compression");
+    }
+    theora_encode_packetout (&th, frame >= frequency * 2, &op);
+    if ((long long int)op.granulepos < last_granule)
+      FAIL ("encoder returned a decreasing granulepos value");
+    last_granule = op.granulepos;
+    keyframe = op.granulepos >> shift;
+    keydist = op.granulepos - (keyframe << shift);
+    if ((keyframe + keydist) != frame)
+      FAIL ("encoder granulepos does not map to the correct frame index");
+    tframe = theora_granule_frame (&th, op.granulepos);
+    if (tframe != frame)
+      FAIL ("theora_granule_frame returned incorrect results");
+#if DEBUG
+    printf("++ frame %d granulepos %lld %d:%d %d %.3lfs\n", 
+	frame, (long long int)op.granulepos, keyframe, keydist,
+	tframe, theora_granule_time (&th, op.granulepos));
+#endif
+  }
+
+  /* clean up */
+  INFO ("+ Freeing dummy frame data");
+  free (framedata);
+
+  INFO ("+ Clearing theora_info struct");
+  theora_info_clear (&ti);
+
+  INFO ("+ Clearing theora_state");
+  theora_clear (&th);
+
+  return 0;
+}
+
+int main(int argc, char *argv[])
+{
+
+  granulepos_test_encode (1, 1);
+  granulepos_test_encode (2, 1);
+  granulepos_test_encode (3, 1);
+  granulepos_test_encode (4, 1);
+  granulepos_test_encode (8, 1);
+  granulepos_test_encode (64, 1);
+
+  exit (0);
+}



More information about the commits mailing list