shithub: h264bsd

Download patch

ref: 698250ec631d0a54932dab5a5b5b61995c42222b
parent: bdf6173d6dfff6ac1627fd61bd3e0aff6a6193ec
author: unknown <chris.jarabek@1073w7w-chrisj.CalgaryScientific.local>
date: Wed Jan 15 11:17:34 EST 2014

More comments.  h264bsd_asm.js is likely bungled, so recompiling with emcc will be necessary.

--- a/js/h264bsd.js
+++ b/js/h264bsd.js
@@ -57,35 +57,44 @@
 	
 	data = new Uint8Array(data);
 	
-	var offset = 0; //The offset into the heap when decoding 
-	var length = data.byteLength; //The byte-wise length of the data to decode
+	var pData = 0; //The offset into the heap when decoding 
 	var pAlloced = 0; //The original pointer to the data buffer (for freeing)
 	var pBytesRead = 0; //Pointer to bytesRead
-	var bytesRead;  //UInt32 containing the number of bytes read from a decode operation
+	var length = data.byteLength; //The byte-wise length of the data to decode	
+	var bytesRead = 0;  //The number of bytes read from a decode operation
 	var retCode = 0; //Return code from a decode operation
+	var lastPicId = 0; //ID of the last picture decoded
 
 	//Get a pointer into the heap were our decoded bytes will live
-	offset = pAlloced = H264Decoder.malloc(H264Decoder.Module, length);
-	H264Decoder.Module.HEAPU8.set(data, offset);
+	pData = pAlloced = H264Decoder.malloc(H264Decoder.Module, length);
+	H264Decoder.Module.HEAPU8.set(data, pData);
 
 	//get a pointer to where bytesRead will be stored: Uint32 = 4 bytes
 	pBytesRead = H264Decoder.malloc(H264Decoder.Module, 4);
-	bytesRead = new Uint32Array(H264Decoder.Module.HEAPU32.buffer, pBytesRead, 1);		
 
-	//Keep deocding frames while there is still something to decode
+	//Keep decoding frames while there is still something to decode
 	while(length > 0) {
 
-		retCode = H264Decoder.h264bsdDecode(H264Decoder.Module, H264Decoder.pStorage, offset, length, 0, pBytesRead);
-		console.log('Ret: ' , retCode,' pStorage: ', H264Decoder.pStorage, ' offset: ', offset, ' length: ', length, ' pBytesRead: ', pBytesRead, ' bytesRead: ', bytesRead);
+		console.log('pStorage: ', H264Decoder.pStorage, ' pData: ', pData, ' byteLength: ', data.byteLength, ' lastPicId: ', lastPicId);		
+		retCode = H264Decoder.h264bsdDecode(H264Decoder.Module, H264Decoder.pStorage, pData, data.byteLength, lastPicId, pBytesRead);		
 
-		var numBytesRead = bytesRead[0];
-		length = length - numBytesRead;
-		offset = offset + numBytesRead;
+		bytesRead = H264Decoder.Module.getValue(pBytesRead, 'i32')
+		console.log('Ret: ' , retCode, ' bytesRead: ', bytesRead);
+
+		length = length - bytesRead;		
+		pData = pData + bytesRead;
+		console.log('Length: ', length);
+
 	}
 
 	if(pAlloced != 0) {
 		H264Decoder.free(H264Decoder.Module, pAlloced);
 	}
+	
+	if(pBytesRead != 0) {
+		H264Decoder.free(H264Decoder.Module, pBytesRead);
+	}
+
 }
 
 // u32 h264bsdDecode(storage_t *pStorage, u8 *byteStrm, u32 len, u32 picId, u32 *readBytes);