[xiph-commits] r14623 - in experimental/ribamar/etheora: examples/encode_vorbis src

ribamar at svn.xiph.org ribamar at svn.xiph.org
Mon Mar 24 22:02:49 PDT 2008


Author: ribamar
Date: 2008-03-24 22:02:48 -0700 (Mon, 24 Mar 2008)
New Revision: 14623

Modified:
   experimental/ribamar/etheora/examples/encode_vorbis/encoder-example.c
   experimental/ribamar/etheora/src/etheora.c
   experimental/ribamar/etheora/src/etheora.h
Log:
first code changes in etheora toward audio support.

Modified: experimental/ribamar/etheora/examples/encode_vorbis/encoder-example.c
===================================================================
--- experimental/ribamar/etheora/examples/encode_vorbis/encoder-example.c	2008-03-25 04:56:34 UTC (rev 14622)
+++ experimental/ribamar/etheora/examples/encode_vorbis/encoder-example.c	2008-03-25 05:02:48 UTC (rev 14623)
@@ -9,7 +9,7 @@
   is printed to standard output. 
 
   build command line example (with gcc): 
-  gcc encoder-example.c etheora.c  -I. -ltheora -o encoder-example
+  gcc encoder-example.c etheora.c  -I. -ltheora -lvorbisenc -o encoder-example
 */
 
 #include <etheora.h>
@@ -51,13 +51,15 @@
 
 	/* last chance to change theora parameters before encoding.
 	   the experienced user can change ec.ti parameters or edit
-	   the ec.tc structure. */
+	   the ec.tc structure or audio parameters. */
 	ec.ti.target_bitrate = 200000; /*200 kbps*/
 	ec.tc.vendor = vendor; 
+	ec.audio_quality = 1.0; /* -0.1 smaller file, worst quality;
+				    1.0 bigger file, best quality. */
 
 	/* start the encoder. */
-	if (etheora_enc_start(&ec)){
-		fprintf(stderr, "Can't start.\n"); 
+	if (f = etheora_enc_start(&ec)){
+		fprintf(stderr, "Can't start (err=%d).\n", f); 
 		return 2; 
 	}
 

Modified: experimental/ribamar/etheora/src/etheora.c
===================================================================
--- experimental/ribamar/etheora/src/etheora.c	2008-03-25 04:56:34 UTC (rev 14622)
+++ experimental/ribamar/etheora/src/etheora.c	2008-03-25 05:02:48 UTC (rev 14623)
@@ -221,6 +221,7 @@
 		ti->aspect_numerator = 16 * frame_height;
 		ti->aspect_denominator = 9 * frame_width;
 	}
+
 	ti->fps_numerator = fps_numerator;
 	ti->fps_denominator = fps_denominator;
 	ti->colorspace = ETHEORA_TINFO_COLORSPACE;  //OC_CS_UNSPECIFIED;
@@ -1499,6 +1500,7 @@
        }
        else return ETHEORA_ERR_NULL_ARGUMENT; 
 
+	ec->audio = 0; 
        if(etheora_filltinfo_nooffset(&ec->ti,
                 frame_width,
                 frame_height,
@@ -1511,13 +1513,41 @@
 	
 }
 
+/* 
+etheora_enc_audio_append(): tells the library that the video 
+to be encoded is going to have audio too. 
+
+usually called: 
+after  etheora_enc_setup() 
+before etheora_enc_start() 
+
+arguments: 
+ec: pointer to an etheora context. 
+n_channels:  number of audio channels to be encoded. 
+sample_rate: sampling rate of the source audio (Hz). 
+quality: desired quality level
+*/
+
+int  etheora_enc_audio_append(etheora_ctx *ec, long n_channels,
+        long sample_rate){
+	/* sanity test.*/
+	if (ec == NULL) return ETHEORA_ERR_NULL_ARGUMENT; 
+	ec->audio = 1; 
+	ec->n_channels = n_channels; 
+	ec->sample_rate = sample_rate; 
+	ec->audio_quality = 0.4; 
+	return 0; 
+}
+
+
 /*
 etheora_enc_start():
 starts the encoding process. effectively allocate memory for frame buffer
 (ec->yuv) and write video headers to ec->fogg.  
+TODO: write audio headers being implemented. 
 
 usually called: 
-after  etheora_enc_setup() 
+after  etheora_enc_setup() or etheora_enc_audio_append()
 before etheora_enc_yuv_draw() or  etheora_enc_rgb_draw()
 
 arguments: 
@@ -1533,6 +1563,7 @@
 ETHEORA_ERR_CANT_START, theora encoder refuses to start 
 		(theora_encode_init()).
 ETHEORA_ERR_CANT_WRITE_HEADER, can't write headers to file. 
+TODO: update comments to consider audio implementation. 
 */
 
 int  etheora_enc_start(etheora_ctx *ec){
@@ -1540,8 +1571,8 @@
 	/*sanity test.*/
 	if(ec == NULL) return ETHEORA_ERR_NULL_ARGUMENT;
 
-	/*TODO: currently, only video stream supported. */
-	if(etheora_streams_states_init(&ec->ess, 1))
+	/*TODO: currently, audio stream being implemented. */
+	if(etheora_streams_states_init(&ec->ess, 2))
 		return ETHEORA_ERR_MALLOC; 
 
 	if(etheora_fillyuv(&ec->ti, &ec->yuv, ec->finfo))
@@ -1549,7 +1580,20 @@
 
 	if(etheora_encode_init(&ec->ts, &ec->ti))
 		return ETHEORA_ERR_CANT_START; 
+	
+	if(ec->audio){
+		vorbis_info_init(&ec->vi); 
 
+		/* TODO: implement every mode (VBR, CBR, ABR). */
+		if( vorbis_encode_init_vbr(&ec->vi, ec->n_channels, 
+			ec->sample_rate, ec->audio_quality))
+			return ETHEORA_ERR_CANT_START;
+
+		vorbis_comment_init(&ec->vc); 
+		vorbis_analysis_init(&ec->vds, &ec->vi); 
+		vorbis_block_init(&ec->vds, &ec->vb); 
+	}
+
 	if(etheora_writeheaders(&ec->ts,
 				&ec->ess.streams[0],
 				&ec->tc,

Modified: experimental/ribamar/etheora/src/etheora.h
===================================================================
--- experimental/ribamar/etheora/src/etheora.h	2008-03-25 04:56:34 UTC (rev 14622)
+++ experimental/ribamar/etheora/src/etheora.h	2008-03-25 05:02:48 UTC (rev 14623)
@@ -4,6 +4,7 @@
 
 
 #include <theora/theora.h>
+#include <vorbis/vorbisenc.h>
 #include <ogg/ogg.h>
 #include <stdio.h> 
 
@@ -171,7 +172,17 @@
         /* fout - a file to print the ogg packets. 
            note it may be a socket stream.*/
         FILE *fogg; 
-/* TODO: compute pixel callback function too!*/
+/* TODO: compute pixel callback function too! 
+ * Note: i think it's unecessary*/
+	/*audio data:*/
+	char audio; 
+	vorbis_info vi; 
+	vorbis_comment vc; 
+	vorbis_dsp_state vds; 
+	vorbis_block vb; 
+	long n_channels; 
+	long sample_rate; 
+	float audio_quality; 
 }; 
 
 typedef struct etheora_context etheora_ctx; 
@@ -187,6 +198,9 @@
 		etheora_aspect aspect, ogg_uint32_t  fps_numerator, 
 		ogg_uint32_t  fps_denominator, FILE *fout, FILE *finfo); 
 
+int  etheora_enc_audio_append(etheora_ctx *ec, long n_channels, 
+	long sample_rate);
+
 int  etheora_enc_start(etheora_ctx *ec); 
 
 int  etheora_enc_yuv_draw(etheora_ctx *ec, ogg_uint32_t i, ogg_uint32_t j,



More information about the commits mailing list