[cvs-annodex] commit (/annodex): phpannodex/trunk/src/phpannodex.c phpannodex/trunk/src/phpanx_general.c phpannodex/trunk/src/phpanx_types.c phpannodex/trunk/src/phpanx_types.h phpannodex/trunk/src/phpanx_write.c phpannodex/trunk/src/phpanx_write.h

ctford nobody at lists.annodex.net
Wed Dec 21 09:44:31 EST 2005


Update of /annodex (new revision 1715)

Modified files:
   phpannodex/trunk/src/phpannodex.c
   phpannodex/trunk/src/phpanx_general.c
   phpannodex/trunk/src/phpanx_types.c
   phpannodex/trunk/src/phpanx_types.h
   phpannodex/trunk/src/phpanx_write.c
   phpannodex/trunk/src/phpanx_write.h

Log Message:
anx_write_output() now works to the point that it can be used to spit out anx to a browser. It may have memory leakage issues though.

Modified: phpannodex/trunk/src/phpannodex.c
===================================================================
--- phpannodex/trunk/src/phpannodex.c	2005-12-19 02:47:18 UTC (rev 1714)
+++ phpannodex/trunk/src/phpannodex.c	2005-12-20 22:44:30 UTC (rev 1715)
@@ -78,7 +78,9 @@
 
 void register_anx_resource( int module_number ) {
 
-	le_anx_handle = zend_register_list_destructors_ex( anx_destruction_handler, NULL, LE_ANX_HANDLE_NAME, module_number);
+	le_anx_handle = zend_register_list_destructors_ex( 
+			anx_destruction_handler, NULL, LE_ANX_HANDLE_NAME, 
+			module_number);
 
 	return;
 }

Modified: phpannodex/trunk/src/phpanx_general.c
===================================================================
--- phpannodex/trunk/src/phpanx_general.c	2005-12-19 02:47:18 UTC (rev 1714)
+++ phpannodex/trunk/src/phpanx_general.c	2005-12-20 22:44:30 UTC (rev 1715)
@@ -39,7 +39,7 @@
 	/* Call Annodex function */
 	error = anx_strerror( anx );
 
-	RETURN_STRING(error, 1);
+	RETURN_STRING(error, DUPLICATE);
 }
 
 PHP_FUNCTION(anx_open)
@@ -48,14 +48,18 @@
 	int filename_length, resource_id;
 	long mode;
 	ANNODEX* anx;
+	AnxClip my_clip;
 
 	/* Process arguments */
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", 
 			&filename, &filename_length, &mode) == FAILURE) {
 		RETURN_NULL();
 	}
-		
+	
 	/* Call Annodex function */
+	if( mode == ANX_WRITE ) {
+		anx_init_importers("*/*");
+	}
 	anx = anx_open(filename, mode);
 
 	if( anx == NULL ) {
@@ -64,6 +68,8 @@
 
 	resource_id = anx_to_resource_id( anx );
 	RETURN_RESOURCE( resource_id );
+	
+
 }
 
 PHP_FUNCTION(anx_new)

Modified: phpannodex/trunk/src/phpanx_types.c
===================================================================
--- phpannodex/trunk/src/phpanx_types.c	2005-12-19 02:47:18 UTC (rev 1714)
+++ phpannodex/trunk/src/phpanx_types.c	2005-12-20 22:44:30 UTC (rev 1715)
@@ -9,6 +9,52 @@
 zval* meta_to_object( AnxMetaElement *meta, void* tsrm_ls );
 zval* link_to_object( AnxLinkElement *link, void* tsrm_ls );
 		
+PHP_FUNCTION(regurgitate)
+{
+	FILE* in;
+	unsigned char c;
+
+	in = fopen( "/home/ctford/phpannodex/php_tests/a_new_computer.ogg.anx", "r");
+	if( in == NULL ) {
+		php_printf("can't open file");
+	}
+	while( (c=getc( in))!=EOF) {
+	       php_printf("%c");
+	}
+	return;
+}
+
+PHP_FUNCTION(write_test) 
+{
+	ANNODEX *anx = NULL;
+	char *ogg_file = "/home/ctford/phpannodex/php_tests/a_new_computer.ogg";
+	long n;
+	char* buf[1024];
+	int i;
+
+
+	buf[1023] = '\0';
+
+	anx_init_importers("*/*");
+	anx = anx_new(ANX_WRITE );
+	anx_write_import(anx, ogg_file, NULL, NULL, 0, -1, 0);
+
+	//php_printf("error is %s<br>",anx_strerror(anx));
+
+	while( (n=anx_write_output( anx,buf, 1023 )) > 0 ) {
+		//fwrite(buf,n,1,stdout);
+		for(i=0; i<n; i++) {
+			php_printf("%c", buf[i]);
+		}
+	//		php_printf("%s", buf);
+			//php_printf("mark<br>");
+	}
+		
+	anx_close( anx );
+
+	return;
+}
+
 /* head_to_object() (indirectly) calls add_property_string() from the ZEND API
  * to copy the values of AnxHead fields into a zval* object.
  */	
@@ -403,7 +449,6 @@
 	return( link );
 }
 
-//BLAHBLAH
 zval* clip_to_object( AnxClip *clip, void* tsrm_ls ) {
 
 	AnxMetaElement* meta;

Modified: phpannodex/trunk/src/phpanx_types.h
===================================================================
--- phpannodex/trunk/src/phpanx_types.h	2005-12-19 02:47:18 UTC (rev 1714)
+++ phpannodex/trunk/src/phpanx_types.h	2005-12-20 22:44:30 UTC (rev 1715)
@@ -3,6 +3,8 @@
 
 #define PHPANX_TYPES_FUNCTIONS		\
 	PHP_FE( object_test, NULL ) 	\
+	PHP_FE( write_test, NULL ) 	\
+	PHP_FE( regurgitate, NULL ) 	\
 
 #include <annodex/annodex.h>
 
@@ -10,6 +12,8 @@
 typedef void* (*FromObjectConverter) (zval* object);
 
 PHP_FUNCTION( object_test);
+PHP_FUNCTION( write_test);
+PHP_FUNCTION( regurgitate);
 
 extern zval* head_to_object( AnxHead* head, void* tsrm_ls );
 extern AnxHead* object_to_head( zval* object );

Modified: phpannodex/trunk/src/phpanx_write.c
===================================================================
--- phpannodex/trunk/src/phpanx_write.c	2005-12-19 02:47:18 UTC (rev 1714)
+++ phpannodex/trunk/src/phpanx_write.c	2005-12-20 22:44:30 UTC (rev 1715)
@@ -124,3 +124,39 @@
 
 	RETURN_LONG( result );
 }
+
+PHP_FUNCTION(anx_write_output)
+{
+	long n;
+	ANNODEX *anx;
+	int bytes_written, buffer_length;
+	zval *anx_resource, *raw_data;
+	unsigned char* buffer;
+
+	/* Process arguments */
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", 
+			&anx_resource, &n) ==FAILURE) {
+		RETURN_NULL();
+	}
+	ZEND_FETCH_RESOURCE( anx, ANNODEX*, &anx_resource, -1, 
+		LE_ANX_HANDLE_NAME, le_anx_handle);
+
+	buffer = malloc( sizeof(char) * n );
+
+	if( buffer == NULL ) {
+		RETURN_NULL();
+	}
+	
+	/* Call Annodex function */
+	if ( (bytes_written = anx_write_output( anx, buffer, n )) > 0){
+		buffer = realloc( buffer, sizeof(char) * bytes_written );
+
+		/* FIXME This seems to be leaking memory like a sieve
+		 * Should be freeing buffer each time
+		 */
+		RETURN_STRINGL(buffer, bytes_written, DUPLICATE );
+	} else {
+		RETURN_NULL();
+	}
+}
+

Modified: phpannodex/trunk/src/phpanx_write.h
===================================================================
--- phpannodex/trunk/src/phpanx_write.h	2005-12-19 02:47:18 UTC (rev 1714)
+++ phpannodex/trunk/src/phpanx_write.h	2005-12-20 22:44:30 UTC (rev 1715)
@@ -7,12 +7,14 @@
 	PHP_FE(anx_insert_clip, NULL)		\
 	PHP_FE(anx_insert_cmml, NULL)		\
 	PHP_FE(anx_write, NULL)			\
+	PHP_FE(anx_write_output, NULL)		\
 
 PHP_FUNCTION(anx_init_importers);
 PHP_FUNCTION(anx_write_import);
 PHP_FUNCTION(anx_insert_clip);
 PHP_FUNCTION(anx_insert_cmml);
 PHP_FUNCTION(anx_write);
+PHP_FUNCTION(anx_write_output);
 
 #endif
 


-- 
ctford



More information about the cvs-annodex mailing list