[xiph-commits] r14517 - in experimental/ribamar/etheora/examples: . client-server-sdl encode_vorbis

ribamar at svn.xiph.org ribamar at svn.xiph.org
Fri Feb 15 14:09:01 PST 2008


Author: ribamar
Date: 2008-02-15 14:09:00 -0800 (Fri, 15 Feb 2008)
New Revision: 14517

Added:
   experimental/ribamar/etheora/examples/README.txt
   experimental/ribamar/etheora/examples/encode_vorbis/
   experimental/ribamar/etheora/examples/encode_vorbis/README.txt
   experimental/ribamar/etheora/examples/encode_vorbis/encoder-example.c
Modified:
   experimental/ribamar/etheora/examples/client-server-sdl/client-decoder.c
Log:
starting things towards audio support in etheora.

Added: experimental/ribamar/etheora/examples/README.txt
===================================================================
--- experimental/ribamar/etheora/examples/README.txt	                        (rev 0)
+++ experimental/ribamar/etheora/examples/README.txt	2008-02-15 22:09:00 UTC (rev 14517)
@@ -0,0 +1,3 @@
+
+Examples: 
+

Modified: experimental/ribamar/etheora/examples/client-server-sdl/client-decoder.c
===================================================================
--- experimental/ribamar/etheora/examples/client-server-sdl/client-decoder.c	2008-02-15 04:58:33 UTC (rev 14516)
+++ experimental/ribamar/etheora/examples/client-server-sdl/client-decoder.c	2008-02-15 22:09:00 UTC (rev 14517)
@@ -8,8 +8,8 @@
 
   note this doesn't have a good performance yet and can't deal with 
   the real fps rate. Its performance is improved by defining OVERLAY, 
-  however, as of this writing (19-nov-2007) etheora doesn't provide
-  a good way to use overlays. 
+  however, as of this writing (19-nov-2007) etheora doesn't provide 
+  yet a good way to use overlays. 
 
   usage: 
   ./client-decoder server_hostname server_port
@@ -35,7 +35,7 @@
 
 
 #define YUV_DECODING 1
-//#define OVERLAY 1
+#define OVERLAY 1
 
 int tcp_socket_connect(char *host, int port, FILE *finfo){
         struct hostent *h;
@@ -72,7 +72,7 @@
 
 
 
-/*taken from theora player_example.c, but not cropping it yet. */
+/*taken from theora player_example.c, but not cropping yet. */
 
 static void video_write(SDL_Surface *screen, SDL_Overlay *yuv_overlay, 
 	yuv_buffer *yuv, SDL_Rect rect){
@@ -124,7 +124,7 @@
 	int i, j, sock; 
 	etheora_ctx ec; 
 	FILE *finfo, *fin; 
-#if YUV_DECODING
+#ifdef YUV_DECODING
 	unsigned char y, u, v; 
 #endif
 	float r, g, b;
@@ -190,7 +190,8 @@
 	fprintf(stderr, "Bytes per pixel: %i.\n", scr->format->BytesPerPixel); 
 
 #ifdef OVERLAY
-	yuv_overlay = SDL_CreateYUVOverlay(etheora_get_width(&ec), etheora_get_height(&ec),
+	yuv_overlay = SDL_CreateYUVOverlay(etheora_get_width(&ec), 
+			etheora_get_height(&ec),
 			SDL_YV12_OVERLAY, scr);
 	if ( yuv_overlay == NULL ) {
 		fprintf(stderr, "SDL: Couldn't create SDL_yuv_overlay: %s\n",
@@ -220,25 +221,29 @@
 		 * memory without changes appearing in  the screen. */
 #ifndef OVERLAY
 		if(SDL_MUSTLOCK(scr)) SDL_LockSurface(scr); 
+#endif /* TODO: not original*/
 
 		/*now we can read the frame buffer data. */
 		for( i = 0; i < etheora_get_width(&ec);  i++)
 			for( j = 0; j < etheora_get_height(&ec); j++){
-				/* or use etheora_dec_yuv draw() to 
-			           read in yuv colorspace.*/
-#if YUV_DECODING
+#ifdef YUV_DECODING
 				etheora_dec_yuv_read(&ec, i, j, 
 					 &y, &u, &v);  
 				etheora_pixel_yuv2rgb(y, u, v, &r, &g, &b);
 				etheora_pixel_rgb_reescale(&r, &g, &b);
+				etheora_pixel_rgb_unreescale(&r, &g, &b);
+				etheora_enc_rgb_draw(&ec, i, j, r, g, b); 
+				//etheora_enc_yuv_draw(&ec, i, j, y, u, v); 
 
 #else
+				/* or use etheora_dec_yuv draw() to 
+			           read in yuv colorspace.*/
 				etheora_dec_rgb_read(&ec, i, j, 
 					 &r, &g, &b);  
 #endif 
 
 				  /* sdl - drawing the pixel. */
-#if YUV_DECODING
+#ifdef YUV_DECODING
 				  Uint32 a = 0; 
 				  a = (Uint32) 0
 				  	  + (((Uint32)y)*1 << 3*8)
@@ -258,6 +263,7 @@
 #endif 
 			}
 
+#ifndef OVERLAY /* TODO: not original*/
 		/* sdl stuff - unlocking screen/drawing. */
 		if(SDL_MUSTLOCK(scr)) SDL_UnlockSurface(scr); 
 #else 

Added: experimental/ribamar/etheora/examples/encode_vorbis/README.txt
===================================================================
--- experimental/ribamar/etheora/examples/encode_vorbis/README.txt	                        (rev 0)
+++ experimental/ribamar/etheora/examples/encode_vorbis/README.txt	2008-02-15 22:09:00 UTC (rev 14517)
@@ -0,0 +1,86 @@
+
+Steps to encode vorbis: 
+
+vorbis structures needed: 
+
+
+/* bitstream settings.*/
+ vorbis_info      vi; 
+	
+/* comment on headers.*/
+ vorbis_comment   vc; 
+
+/* central working state for the packet->PCM decoder. */
+ vorbis_dsp_state vd; 
+
+/* local working space for packet->PCM decode. */
+ vorbis_block     vb; 
+
+
+/* initialize vorbis_info:*/
+ vorbis_info_init(&vi);
+
+/* choose an encoding mode (VBR, CBR, ABR) */
+/* http://xiph.org/vorbis/doc/vorbisenc/overview.html 
+   explains this. */
+
+ vorbis_encode_init() /*or*/
+ vorbis_encode_init_vbr()
+
+/* setup comments: */
+ vorbis_comment_init(&vc);
+ vorbis_comment_add_tag(&vc,"ENCODER","encoder_example.c");
+
+
+/* setup lasting structures: */
+ vorbis_analysis_init(&vd, &vi);
+ vorbis_block_init(&vd, &vb);
+
+ ogg_stream_init()
+
+/* get the 3 header packets: */
+ vorbis_analysis_headerout()
+ ogg_stream_packetin()
+ ogg_stream_packetin()
+ ogg_stream_packetin()
+ ogg_stream_flush() (or _pageout(), but as the datasize is probably 
+ lesser then a page, it wouldn't pageout the page).
+ fwrite()
+ fwrite()
+
+/* start reading audio data into a buffer. */
+
+ buffer = vorbis_analysis_buffer()
+
+/* this buffer is a matrix where data read from the WAV file must be
+put. */
+
+
+/* tell the library how much we actually submitted */
+ vorbis_analysis_wrote(&vd,i);
+
+/* if there is no more data, submit with i = 0 */
+
+/*loop: submit blocks to encode. */
+ while vorbis_analysis_blockout(&vd,&vb) == 1
+ ogg_stream_packetin()
+
+/* analysis. TODO: don't know what's the difference here with
+ VBR or managed mode.*/
+ vorbis_analysis(&vb,NULL);
+ vorbis_bitrate_addblock(&vb);
+
+ while(vorbis_bitrate_flushpacket(&vd, &op))
+ ogg_stream_packetin()
+ 
+ while !ogg_page_eos()
+ ogg_stream_pageout(), fwrite(), fwrite()
+
+/* end loops and clean up: */ 
+ ogg_stream_clear(&os);
+ vorbis_block_clear(&vb);
+ vorbis_dsp_clear(&vd);
+ vorbis_comment_clear(&vc);
+ vorbis_info_clear(&vi);
+
+

Added: experimental/ribamar/etheora/examples/encode_vorbis/encoder-example.c
===================================================================
--- experimental/ribamar/etheora/examples/encode_vorbis/encoder-example.c	                        (rev 0)
+++ experimental/ribamar/etheora/examples/encode_vorbis/encoder-example.c	2008-02-15 22:09:00 UTC (rev 14517)
@@ -0,0 +1,96 @@
+/*Copyright, 2007, by Ribamar Santarosa, ribamar at gmail.com */
+
+/*a very simple theora video encoder using etheora api.
+  play with etheora_enc_rgb_draw() r, g, b parameters and get
+  different videos. 
+  
+  usage: ./encoder-example [file.ogg] 
+  file.ogg: file to be outputed. if none is passed, video data 
+  is printed to standard output. 
+
+  build command line example (with gcc): 
+  gcc encoder-example.c etheora.c  -I. -ltheora -o encoder-example
+*/
+
+#include <etheora.h>
+#include <stdio.h>
+
+#define NUMBER_OF_FRAMES 20 /* video with 20 frames.*/
+
+int main(int argc, char **args){
+	int f, i, j; 
+	etheora_ctx ec; 
+	char *vendor = "etheora/libtheora"; 
+	FILE *finfo, *fout; 
+
+	/* opening video output file and file to print debuf info. as 
+	   always, sockets could be used.Degub.txt can have a fast 
+	   increase, you may want open a null device file as 
+	   /dev/null. */
+
+	finfo = fopen("Debug.txt", "w"); 
+	if(argc > 1) {
+		fout = fopen(args[1], "w");
+		fprintf(stderr, "opening %s to write video file . \n", args[1]);
+	}
+	else {  
+		fout = stdout;
+		fprintf(stderr, "opening standard output to write video file. \n");
+	}
+	if(fout == NULL || finfo == NULL){
+		fprintf(stderr, "Debug.txt or output file couldn't be open.\n");
+		return 1;
+	}
+
+
+	fprintf(stderr, "debug info in Debug.txt.\n"); 
+
+	/* configuring encoder: 640x480 video 12/1 frames per second. */
+	etheora_enc_setup(&ec, 640, 480, ETHEORA_ASPECT_NORMAL, 
+				12, 1, fout, finfo);
+
+	/* last chance to change theora parameters before encoding.
+	   the experienced user can change ec.ti parameters or edit
+	   the ec.tc structure. */
+	ec.ti.target_bitrate = 200000; /*200 kbps*/
+	ec.tc.vendor = vendor; 
+
+	/* start the encoder. */
+	if (etheora_enc_start(&ec)){
+		fprintf(stderr, "Can't start.\n"); 
+		return 2; 
+	}
+
+	for ( f = 0; f < NUMBER_OF_FRAMES - 1; f++){
+
+		/*now we're ready to draw the frames. */
+		for( i = 0; i < 640; i++)
+			for( j = 0; j < 480; j++)
+			/* or use etheora_enc_yuv_draw() to 
+			   draw in yuv colorspace.*/
+				etheora_enc_rgb_draw(&ec, i, j, 
+					/*r*/ 255, 
+					/*g*/ (i*i+i*j*j-f) % 256, 
+					/*b*/ (j*i+i*i-f) % 256);
+
+		/*submiting drawn frame to encoder.*/
+		etheora_enc_nextframe(&ec); 
+	}
+
+	/*drawing last frame.*/
+	for( i = 0; i < 640; i++)
+		for( j = 0; j < 480; j++)
+			etheora_enc_rgb_draw(&ec, i, j, 
+					/*r*/ 255, 
+					/*g*/ (i*i+i*j*j-f) % 256, 
+					/*b*/ (j*i+i*i-f) % 256);
+
+	/*submiting last frame to encoder and finishing the process. */
+	etheora_enc_finish(&ec); 
+
+	fprintf(stderr, "video file generated. \n"); 
+
+	return 0; 
+}
+
+



More information about the commits mailing list