[xiph-commits] r14379 - trunk/theora/tests
giles at svn.xiph.org
giles at svn.xiph.org
Mon Jan 7 18:07:05 PST 2008
Author: giles
Date: 2008-01-07 18:07:04 -0800 (Mon, 07 Jan 2008)
New Revision: 14379
Added:
trunk/theora/tests/granulepos_theora.c
Modified:
trunk/theora/tests/Makefile.am
trunk/theora/tests/granulepos.c
Log:
Port the granulepos test to the new api. It currently fails.
Test the old api from both the new and old libraries.
Modified: trunk/theora/tests/Makefile.am
===================================================================
--- trunk/theora/tests/Makefile.am 2008-01-08 01:08:12 UTC (rev 14378)
+++ trunk/theora/tests/Makefile.am 2008-01-08 02:07:04 UTC (rev 14379)
@@ -15,7 +15,7 @@
TESTS = noop noop_theoraenc noop_theora \
comment comment_theoradec comment_theora \
- granulepos
+ granulepos granulepos_theoraenc granulepos_theora
noinst_PROGRAMS = $(TESTS)
@@ -50,5 +50,13 @@
comment_theora_CFLAGS = $(OGG_CFLAGS)
granulepos_SOURCES = granulepos.c
-granulepos_LDADD = $(THEORA_LIBS)
+granulepos_LDADD = $(THEORAENC_LIBS)
granulepos_CFLAGS = $(OGG_CFLAGS)
+
+granulepos_theoraenc_SOURCES = granulepos_theora.c
+granulepos_theoraenc_LDADD = $(THEORAENC_LIBS)
+granulepos_theoraenc_CFLAGS = $(OGG_CFLAGS)
+
+granulepos_theora_SOURCES = granulepos_theora.c
+granulepos_theora_LDADD = $(THEORA_LIBS)
+granulepos_theora_CFLAGS = $(OGG_CFLAGS)
Modified: trunk/theora/tests/granulepos.c
===================================================================
--- trunk/theora/tests/granulepos.c 2008-01-08 01:08:12 UTC (rev 14378)
+++ trunk/theora/tests/granulepos.c 2008-01-08 02:07:04 UTC (rev 14379)
@@ -16,7 +16,7 @@
********************************************************************/
#include <stdlib.h>
-#include <theora/theora.h>
+#include <theora/theoraenc.h>
#include <math.h>
#include "tests.h"
@@ -31,82 +31,70 @@
}
static int
-granulepos_test_encode (int frequency, int auto_p)
+granulepos_test_encode (int frequency)
{
- theora_info ti;
- theora_state th;
+ th_info ti;
+ th_enc_ctx *te;
int result;
int frame, tframe, keyframe, keydist;
int shift;
double rate, ttime;
- yuv_buffer yuv;
+ th_ycbcr_buffer yuv;
unsigned char *framedata;
ogg_packet op;
long long int last_granule = -1;
- INFO ("+ Initializing theora_info struct");
- theora_info_init (&ti);
+ INFO ("+ Initializing th_info struct");
+ th_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.frame_width = 32;
+ ti.frame_height = 32;
+ ti.pic_width = ti.frame_width;
+ ti.pic_height = ti.frame_height;
+ ti.pic_x = 0;
+ ti.pic_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.colorspace = TH_CS_UNSPECIFIED;
+ ti.pixel_fmt = TH_PF_420;
ti.quality = 16;
+ ti.keyframe_granule_shift=ilog(frequency);
- 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) {
+ INFO ("+ Allocating encoder context");
+ te = th_encode_alloc(&ti);
+ if (te == NULL) {
+ INFO ("+ Clearing th_info");
+ th_info_clear(&ti);
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;
+ framedata = calloc(ti.frame_height, ti.frame_width);
+ yuv[0].width = ti.frame_width;
+ yuv[0].height = ti.frame_height;
+ yuv[0].ystride = ti.frame_width;
+ yuv[0].data = framedata;
+ yuv[1].width = ti.frame_width / 2;
+ yuv[1].height = ti.frame_width / 2;
+ yuv[1].ystride = ti.frame_width;
+ yuv[1].data = framedata;
+ yuv[2].width = ti.frame_width / 2;
+ yuv[2].height = ti.frame_width / 2;
+ yuv[2].ystride = ti.frame_width;
+ yuv[2].data = framedata;
INFO ("+ Checking granulepos generation");
- shift = theora_granule_shift(&ti);
+ shift = ti.keyframe_granule_shift;
rate = (double)ti.fps_denominator/ti.fps_numerator;
for (frame = 0; frame < frequency * 2 + 1; frame++) {
- result = theora_encode_YUVin (&th, &yuv);
+ result = th_encode_ycbcr_in (te, &yuv);
if (result < 0) {
- printf("theora_encode_YUVin() returned %d\n", result);
+ printf("th_encode_ycbcr_in() returned %d\n", result);
FAIL ("negative error code submitting frame for compression");
}
- theora_encode_packetout (&th, frame >= frequency * 2, &op);
+ th_encode_packetout (te, frame >= frequency * 2, &op);
if ((long long int)op.granulepos < last_granule)
FAIL ("encoder returned a decreasing granulepos value");
last_granule = op.granulepos;
@@ -114,28 +102,28 @@
keydist = op.granulepos - (keyframe << shift);
if ((keyframe + keydist) != frame + 1)
FAIL ("encoder granulepos does not map to the correct frame number");
- tframe = theora_granule_frame (&th, op.granulepos);
+ tframe = th_granule_frame (te, op.granulepos);
if (tframe != frame)
- FAIL ("theora_granule_frame returned incorrect results");
- ttime = theora_granule_time(&th, op.granulepos);
+ FAIL ("th_granule_frame returned incorrect results");
+ ttime = th_granule_time(te, op.granulepos);
if (fabs(rate*(frame+1) - ttime) > 1.0e-6)
- FAIL ("theora_granule_time returned incorrect results");
+ FAIL ("th_granule_time 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));
+ tframe, th_granule_time (te, op.granulepos));
#endif
}
/* clean up */
INFO ("+ Freeing dummy frame data");
- free (framedata);
+ free(framedata);
- INFO ("+ Clearing theora_info struct");
- theora_info_clear (&ti);
+ INFO ("+ Clearing th_info struct");
+ th_info_clear(&ti);
- INFO ("+ Clearing theora_state");
- theora_clear (&th);
+ INFO ("+ Freeing encoder context");
+ th_encode_free(te);
return 0;
}
@@ -143,12 +131,12 @@
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);
+ granulepos_test_encode (1);
+ granulepos_test_encode (2);
+ granulepos_test_encode (3);
+ granulepos_test_encode (4);
+ granulepos_test_encode (8);
+ granulepos_test_encode (64);
exit (0);
}
Copied: trunk/theora/tests/granulepos_theora.c (from rev 14377, trunk/theora/tests/granulepos.c)
===================================================================
--- trunk/theora/tests/granulepos_theora.c (rev 0)
+++ trunk/theora/tests/granulepos_theora.c 2008-01-08 02:07:04 UTC (rev 14379)
@@ -0,0 +1,154 @@
+/********************************************************************
+ * *
+ * 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 <math.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;
+ double rate, ttime;
+ 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);
+ rate = (double)ti.fps_denominator/ti.fps_numerator;
+ 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 + 1)
+ FAIL ("encoder granulepos does not map to the correct frame number");
+ tframe = theora_granule_frame (&th, op.granulepos);
+ if (tframe != frame)
+ FAIL ("theora_granule_frame returned incorrect results");
+ ttime = theora_granule_time(&th, op.granulepos);
+ if (fabs(rate*(frame+1) - ttime) > 1.0e-6)
+ FAIL ("theora_granule_time 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