[xiph-cvs] cvs commit: theora/win32/experimental/splayer splayer.c
Mauricio Piacentini
mauricio at xiph.org
Tue Jun 3 18:25:35 PDT 2003
mauricio 03/06/03 21:25:35
Modified: examples dump_video.c player_example.c
lib Makefile.am huffman.c toplevel.c
win32/experimental/splayer splayer.c
Log:
commit of danxor patch for packing of huffman tables
this saves approx 3k in the header
*IMPORTANT* this is being checked in order to complete the bitstream changes outlined for the next alpha release.
*NOTE* there is code in huffman.c that needs to be cleanup to be made reentrant, but this is already in derf's plans regarding a major cleanup of huffman initialization. bitstream should not change, however.
Revision Changes Path
1.2 +4 -4 theora/examples/dump_video.c
Index: dump_video.c
===================================================================
RCS file: /usr/local/cvsroot/theora/examples/dump_video.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- dump_video.c 2 Jun 2003 19:07:08 -0000 1.1
+++ dump_video.c 4 Jun 2003 01:25:34 -0000 1.2
@@ -11,7 +11,7 @@
********************************************************************
function: example dumpvid application; dumps Theora streams
- last mod: $Id: dump_video.c,v 1.1 2003/06/02 19:07:08 mauricio Exp $
+ last mod: $Id: dump_video.c,v 1.2 2003/06/04 01:25:34 mauricio Exp $
********************************************************************/
@@ -249,9 +249,9 @@
/* and now we have it all. initialize decoders */
if(theora_p){
theora_decode_init(&td,&ti);
- fprintf(stderr,"Ogg logical stream %x is Theora %dx%d %.02f fps video.\n",
- to.serialno,ti.width,ti.height,
- (double)ti.fps_numerator/ti.fps_denominator);
+ fprintf(stderr,"Ogg logical stream %x is Theora %dx%d %.02f fps video\nEncoded frame content is %dx%d with %dx%d offset\n",
+ to.serialno,ti.width,ti.height, (double)ti.fps_numerator/ti.fps_denominator,
+ ti.frame_width, ti.frame_height, ti.offset_x, ti.offset_y);
}
<p><p>1.17 +4 -4 theora/examples/player_example.c
Index: player_example.c
===================================================================
RCS file: /usr/local/cvsroot/theora/examples/player_example.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- player_example.c 4 Jun 2003 00:04:28 -0000 1.16
+++ player_example.c 4 Jun 2003 01:25:34 -0000 1.17
@@ -12,7 +12,7 @@
function: example SDL player application; plays Ogg Theora files (with
optional Vorbis audio second stream)
- last mod: $Id: player_example.c,v 1.16 2003/06/04 00:04:28 giles Exp $
+ last mod: $Id: player_example.c,v 1.17 2003/06/04 01:25:34 mauricio Exp $
********************************************************************/
@@ -551,9 +551,9 @@
/* and now we have it all. initialize decoders */
if(theora_p){
theora_decode_init(&td,&ti);
- fprintf(stderr,"Ogg logical stream %x is Theora %dx%d %.02f fps video.\n",
- to.serialno,ti.width,ti.height,
- (double)ti.fps_numerator/ti.fps_denominator);
+ printf("Ogg logical stream %x is Theora %dx%d %.02f fps video\nEncoded frame content is %dx%d with %dx%d offset\n",
+ to.serialno,ti.width,ti.height, (double)ti.fps_numerator/ti.fps_denominator,
+ ti.frame_width, ti.frame_height, ti.offset_x, ti.offset_y);
report_colorspace(&ti);
}
if(vorbis_p){
<p><p>1.4 +1 -1 theora/lib/Makefile.am
Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/theora/lib/Makefile.am,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Makefile.am 12 May 2003 00:20:06 -0000 1.3
+++ Makefile.am 4 Jun 2003 01:25:35 -0000 1.4
@@ -9,7 +9,7 @@
encoder_lookup.h mcomp.c scan.c blockmap.c misc_common.c \
dct.c frarray.c pb.c dct_decode.c frinit.c pp.c dct_encode.c \
huffman.c pp.h toplevel.c decode.c huffman.h quant.c \
- comment.c toplevel_lookup.h
+ comment.c toplevel_lookup.h toplevel.h
libtheora_la_LDFLAGS = -version-info @V_LIB_CURRENT@:@V_LIB_REVISION@:@V_LIB_AGE@
<p><p>1.6 +89 -11 theora/lib/huffman.c
Index: huffman.c
===================================================================
RCS file: /usr/local/cvsroot/theora/lib/huffman.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- huffman.c 26 Feb 2003 21:04:33 -0000 1.5
+++ huffman.c 4 Jun 2003 01:25:35 -0000 1.6
@@ -11,11 +11,12 @@
********************************************************************
function:
- last mod: $Id: huffman.c,v 1.5 2003/02/26 21:04:33 giles Exp $
+ last mod: $Id: huffman.c,v 1.6 2003/06/04 01:25:35 mauricio Exp $
********************************************************************/
#include <stdlib.h>
+#include <stdio.h>
#include <ogg/ogg.h>
#include "encoder_internal.h"
#include "hufftables.h"
@@ -97,6 +98,67 @@
}
}
+/*TODO note: not reentrant, scheduled for cleanup/optimization before beta1 */
+static int huff_x; /// rude!
+static unsigned char huffset_bits[2230]; /// totally rude!
+
+static void write_root(oggpack_buffer* opb, HUFF_ENTRY * HuffRoot) {
+ if(HuffRoot->Value >= 0) { /// if we have a leaf,
+ oggpackB_write(opb, 1, 1);
+ oggpackB_write(opb, HuffRoot->Value, 5);
+ } else {
+ oggpackB_write(opb, 0, 1);
+ if(HuffRoot->ZeroChild) {
+ write_root(opb, HuffRoot->ZeroChild);
+ }
+ if(HuffRoot->OneChild) {
+ write_root(opb, HuffRoot->OneChild);
+ }
+ }
+}
+
+
+static int read_root_bit() {
+ int i = huff_x >> 3;
+ int r = huff_x & 7;
+ int m = 0x80 >> r;
+ int b = huffset_bits[i];
+ huff_x++;
+ if(b & m) b = 1;
+ else b = 0;
+ return b;
+}
+
+static int read_root_(int cnt) {
+ int v=0;
+ int x;
+ for(x=0; x< cnt; x++) {
+ v <<= 1;
+ v += read_root_bit();
+ }
+ return v;
+}
+
+static void read_root( HUFF_ENTRY * HuffRoot) {
+ if(!read_root_bit()) {
+// entry_ptr = (HUFF_ENTRY *)_ogg_calloc(1,sizeof(*entry_ptr));
+ HuffRoot->ZeroChild = (HUFF_ENTRY *)_ogg_calloc(1,sizeof(HUFF_ENTRY));
+ read_root(HuffRoot->ZeroChild);
+ HuffRoot->OneChild = (HUFF_ENTRY *)_ogg_calloc(1,sizeof(HUFF_ENTRY));
+ read_root(HuffRoot->OneChild);
+ HuffRoot->Value = -1;
+ } else {
+ HuffRoot->ZeroChild = NULL;
+ HuffRoot->OneChild = NULL;
+ HuffRoot->Value = read_root_(5);
+ }
+}
+
+static void read_hufftree(HUFF_ENTRY ** huffarray, int index) {
+ huffarray[index] = (HUFF_ENTRY *)_ogg_calloc(1,sizeof(HUFF_ENTRY));
+ read_root(huffarray[index]);
+}
+
static void BuildHuffmanTree( HUFF_ENTRY **HuffRoot,
ogg_uint32_t *HuffCodeArray,
unsigned char *HuffCodeLengthArray,
@@ -241,20 +303,36 @@
}
}
-void write_FrequencyCounts(oggpack_buffer* opb) {
- int x, y;
- for(x=0; x<NUM_HUFF_TABLES; x++) {
- for(y=0; y<MAX_ENTROPY_TOKENS; y++) {
- oggpackB_write(opb, FrequencyCounts_VP3[x][y], 16);
- }
+void InitHuffmanSetPlay( PB_INSTANCE *pbi ){
+ int i;
+
+ ClearHuffmanSet(pbi);
+
+ pbi->HuffRoot_VP3x =
+ _ogg_calloc(NUM_HUFF_TABLES,sizeof(*pbi->HuffRoot_VP3x));
+ pbi->HuffCodeArray_VP3x =
+ _ogg_calloc(NUM_HUFF_TABLES,sizeof(*pbi->HuffCodeArray_VP3x));
+ pbi->HuffCodeLengthArray_VP3x =
+ _ogg_calloc(NUM_HUFF_TABLES,sizeof(*pbi->HuffCodeLengthArray_VP3x));
+ pbi->ExtraBitLengths_VP3x = ExtraBitLengths_VP31;
+
+ huff_x = 0;
+ for ( i = 0; i < NUM_HUFF_TABLES; i++ ){
+ read_hufftree(pbi->HuffRoot_VP3x,i);
}
}
-void read_FrequencyCounts(oggpack_buffer* opb) {
- int x, y;
+void write_HuffmanSet(oggpack_buffer* opb, HUFF_ENTRY **hroot) {
+ int x;
+
for(x=0; x<NUM_HUFF_TABLES; x++) {
- for(y=0; y<MAX_ENTROPY_TOKENS; y++) {
- FrequencyCounts_VP3[x][y]=oggpackB_read(opb, 16);
- }
+ write_root(opb, hroot[x]);
+ }
+}
+
+void read_HuffmanSet(oggpack_buffer* opb) {
+ int x;
+ for(x=0; x<2230; x++) {
+ huffset_bits[x]=oggpackB_read(opb, 8);
}
}
<p><p>1.22 +6 -5 theora/lib/toplevel.c
Index: toplevel.c
===================================================================
RCS file: /usr/local/cvsroot/theora/lib/toplevel.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- toplevel.c 4 Jun 2003 00:04:29 -0000 1.21
+++ toplevel.c 4 Jun 2003 01:25:35 -0000 1.22
@@ -11,7 +11,7 @@
********************************************************************
function:
- last mod: $Id: toplevel.c,v 1.21 2003/06/04 00:04:29 giles Exp $
+ last mod: $Id: toplevel.c,v 1.22 2003/06/04 01:25:35 mauricio Exp $
********************************************************************/
@@ -20,6 +20,7 @@
#include <theora/theora.h>
#include "encoder_internal.h"
#include "toplevel_lookup.h"
+#include "toplevel.h"
#define VERSION_MAJOR 3
#define VERSION_MINOR 1
@@ -1074,7 +1075,7 @@
const char *vendor = theora_version_string();
const int vendor_length = strlen(vendor);
oggpack_buffer opb;
-
+
oggpack_writeinit(&opb);
oggpack_write(&opb, 0x81, 8);
_tp_writebuffer(&opb, "theora", 6);
@@ -1121,7 +1122,7 @@
_tp_writebuffer(&cpi->oggbuffer,"theora",6);
write_Qtables(&cpi->oggbuffer);
- write_FrequencyCounts(&cpi->oggbuffer);
+ write_HuffmanSet(&cpi->oggbuffer,cpi->pb.HuffRoot_VP3x);
op->packet=oggpackB_get_buffer(&cpi->oggbuffer);
op->bytes=oggpackB_bytes(&cpi->oggbuffer);
@@ -1285,7 +1286,7 @@
/* todo: check for error */
read_Qtables(&opb);
- read_FrequencyCounts(&opb);
+ read_HuffmanSet(&opb);
return(0);
}
@@ -1314,7 +1315,7 @@
InitQTables( pbi );
/* Huffman setup */
- InitHuffmanSet( pbi );
+ InitHuffmanSetPlay( pbi );
return(0);
<p><p>1.3 +27 -3 theora/win32/experimental/splayer/splayer.c
Index: splayer.c
===================================================================
RCS file: /usr/local/cvsroot/theora/win32/experimental/splayer/splayer.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- splayer.c 25 May 2003 16:37:06 -0000 1.2
+++ splayer.c 4 Jun 2003 01:25:35 -0000 1.3
@@ -271,6 +271,29 @@
return(0);
}
+/* Report the encoder-specified colorspace for the video, if any.
+ We don't actually make use of the information in this example;
+ a real player should attempt to perform color correction for
+ whatever display device it supports. */
+static void report_colorspace(theora_info *ti)
+{
+ switch(ti->colorspace){
+ case not_specified:
+ /* nothing to report */
+ break;;
+ case ITU_Rec_601:
+ fprintf(stderr," encoder specified ITU Rec 601 color.\n");
+ break;;
+ case CIE_Rec_709:
+ fprintf(stderr," encoder specified CIE Rec 709 color.\n");
+ break;;
+ default:
+ fprintf(stderr,"warning: encoder specified unknown colorspace (%d).\n",
+ ti->colorspace);
+ break;;
+ }
+}
+
/* helper: push a page into the appropriate steam */
/* this can be done blindly; a stream won't accept a page
that doesn't belong to it */
@@ -425,9 +448,10 @@
/* initialize decoders */
if(theora_p){
theora_decode_init(&td,&ti);
- printf("Ogg logical stream %x is Theora %dx%d %.02f fps video.\n",
- to.serialno,ti.width,ti.height,
- (double)ti.fps_numerator/ti.fps_denominator);
+ printf("Ogg logical stream %x is Theora %dx%d %.02f fps video\nEncoded frame content is %dx%d with %dx%d offset\n",
+ to.serialno,ti.width,ti.height, (double)ti.fps_numerator/ti.fps_denominator,
+ ti.frame_width, ti.frame_height, ti.offset_x, ti.offset_y);
+ report_colorspace(&ti);
}
if(vorbis_p){
vorbis_synthesis_init(&vd,&vi);
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list