[xiph-commits] r15873 - branches/theora-thusnelda/tests
giles at svn.xiph.org
giles at svn.xiph.org
Fri Mar 27 21:05:46 PDT 2009
Author: giles
Date: 2009-03-27 21:05:46 -0700 (Fri, 27 Mar 2009)
New Revision: 15873
Modified:
branches/theora-thusnelda/tests/granulepos.c
Log:
Update the 'granulepos' unit test to use the 1.0 encoder api. It now
matches the version from trunk r15872.
This is built twice, once to test the new api linking against
libtheoraenc, and once linking against libtheora. The separate
granulepos_theora.c tests the legacy api when linking against
libtheoraenc.
This was apparently omitted from the merge in c15861.
Modified: branches/theora-thusnelda/tests/granulepos.c
===================================================================
--- branches/theora-thusnelda/tests/granulepos.c 2009-03-28 04:01:00 UTC (rev 15872)
+++ branches/theora-thusnelda/tests/granulepos.c 2009-03-28 04:05:46 UTC (rev 15873)
@@ -5,7 +5,7 @@
* 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 *
+ * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2008 *
* by the Xiph.Org Foundation http://www.xiph.org/ *
* *
********************************************************************
@@ -16,7 +16,8 @@
********************************************************************/
#include <stdlib.h>
-#include <theora/theora.h>
+#include <theora/theoraenc.h>
+#include <math.h>
#include "tests.h"
@@ -30,82 +31,72 @@
}
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;
- yuv_buffer yuv;
+ double rate, ttime;
+ 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;
+/* INFO ("+ Setting up dummy 4:2:0 frame data"); */
+ framedata = calloc(ti.frame_height, ti.frame_width);
+ yuv[0].width = ti.frame_width;
+ yuv[0].height = ti.frame_height;
+ yuv[0].stride = ti.frame_width;
+ yuv[0].data = framedata;
+ yuv[1].width = ti.frame_width / 2;
+ yuv[1].height = ti.frame_width / 2;
+ yuv[1].stride = ti.frame_width;
+ yuv[1].data = framedata;
+ yuv[2].width = ti.frame_width / 2;
+ yuv[2].height = ti.frame_width / 2;
+ yuv[2].stride = 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");
}
- result = theora_encode_packetout (&th, frame >= frequency * 2, &op);
+ result = th_encode_packetout (te, frame >= frequency * 2, &op);
if (result <= 0) {
- printf("theora_encode_packetout() returned %d\n", result);
+ printf("th_encode_packetout() returned %d\n", result);
FAIL("failed to retrieve compressed frame");
}
if ((long long int)op.granulepos < last_granule)
@@ -113,27 +104,33 @@
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 + 1)
- FAIL ("theora_granule_frame returned incorrect results");
+ tframe = th_granule_frame (te, op.granulepos);
+ ttime = th_granule_time(te, op.granulepos);
#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
+ /* granulepos stores the frame count */
+ if ((keyframe + keydist) != frame + 1)
+ FAIL ("encoder granulepos does not map to the correct frame number");
+ /* th_granule_frame() returns the frame index */
+ if (tframe != frame)
+ FAIL ("th_granule_frame() returned incorrect results");
+ /* th_granule_time() returns the end time */
+ if (fabs(rate*(frame+1) - ttime) > 1.0e-6)
+ FAIL ("th_granule_time() returned incorrect results");
}
/* clean up */
- INFO ("+ Freeing dummy frame data");
- free (framedata);
+/* INFO ("+ Freeing dummy frame data"); */
+ 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;
}
@@ -141,12 +138,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);
}
More information about the commits
mailing list