shithub: h264bsd

Download patch

ref: 2e937b74d3d5f044c77200b8c3ee0a0b4f487571
parent: 5afe62a5d1fa30102da9468a4eb6b17c93d5c1ec
author: Sam Leitch <sam@luceva.net>
date: Fri Dec 6 18:12:40 EST 2013

Started teasing out a JS H264Decoder class

--- a/README.md
+++ b/README.md
@@ -2,11 +2,12 @@
 
 This is a software-based library that was extracted from the Android project with the intention of being used elsewhere.
 
-The only modification that have been made are to remove the top-level API and add an opaque pointer for encoder storage.
+Only minor modifications have been made in order to remove the top-level API and add an opaque pointer with alloc and free for encoder storage.
 
 The intention is to provide a simple H.264 decoder that can be easily invoked from [ffi](http://en.wikipedia.org/wiki/Foreign_function_interface) systems. 
 
 ## Directories
 
-* *src* Contains the modified source.
-* *win* Contains Visual Studio project files for building.
+* *src* The modified source.
+* *win* Visual Studio project files for building.
+* *js* JavaScript version of the library created using emscripten.
--- a/js/Rakefile
+++ b/js/Rakefile
@@ -14,7 +14,8 @@
 	"_h264bsdNextOutputPicture",
 	"_h264bsdPicWidth",
 	"_h264bsdPicHeight",
-	"_h264bsdCroppingParams"
+	"_h264bsdCroppingParams",
+	"_h264bsdCheckValidParamSets"
 ]
 
 file "h264bsd_asm.js" => o_files do
--- a/js/h264bsd.js
+++ b/js/h264bsd.js
@@ -20,36 +20,55 @@
 //  IN THE SOFTWARE.
 //
 
-var H264BSD_RDY = 0;
-var H264BSD_PIC_RDY = 1;
-var H264BSD_HDRS_RDY = 2;
-var H264BSD_ERROR = 3;
-var H264BSD_PARAM_SET_ERROR = 4;
-var H264BSD_MEMALLOC_ERROR = 5;
+/*
+ * This class wraps the details of the h264bsd library.
+ */
+function H264Decoder(Module) {
+	this.Module = Module;
+	this.released = false;
 
+	this.pStorage = H264Decoder.h264bsdAlloc();
+	H264Decoder.h264bsdInit(this.Module, this.pStorage, 0);
+}
+
+H264Decoder.prototype.release = function() {
+	if(this.released) return;
+
+	this.released = true;
+	H264Decoder.h264bsdShutdown(this.Module, this.pStorage);
+	H264Decoder.h264bsdFree(this.Module, this.pStorage);
+}
+
+H264Decoder.RDY = 0;
+H264Decoder.PIC_RDY = 1;
+H264Decoder.HDRS_RDY = 2;
+H264Decoder.ERROR = 3;
+H264Decoder.PARAM_SET_ERROR = 4;
+H264Decoder.MEMALLOC_ERROR = 5;
+
 // storage_t* h264bsdAlloc();
-function h264bsdAlloc() {
-	return Module.ccall('h264bsdAlloc', number);
+H264Decoder.h264bsdAlloc = function(Module) {
+	return Module.ccall('_h264bsdAlloc', number);
 }
 
 // void h264bsdFree(storage_t *pStorage);
-function h264bsdFree(pStorage) {
-	Module.ccall('h264bsdFree', null, [number], [decoder]);
+H264Decoder.h264bsdFree = function(Module, pStorage) {
+	Module.ccall('_h264bsdFree', null, [number], [pStorage]);
 }
 
 // u32 h264bsdInit(storage_t *pStorage, u32 noOutputReordering);
-function h264bsdInit(pStorage, noOutputReordering) {
-	return Module.ccall('h264bsdInit', number, [number, number], [decoder, noOutputReordering]);
+H264Decoder.h264bsdInit = function(Module, pStorage, noOutputReordering) {
+	return Module.ccall('_h264bsdInit', number, [number, number], [pStorage, noOutputReordering]);
 }
 
 //void h264bsdShutdown(storage_t *pStorage);
-function h264bsdShutdown(pStorage) {
-	Module.ccall('h264bsdShutdown', null, [number], [decoder]);
+H264Decoder.h264bsdShutdown = function(Module, pStorage) {
+	Module.ccall('_h264bsdShutdown', null, [number], [pStorage]);
 }
 
 // u32 h264bsdDecode(storage_t *pStorage, u8 *byteStrm, u32 len, u32 picId, u32 *readBytes);
-function h264bsdDecode(pStorage, pBytes, len, picId, pBytesRead) {
-	return Module.ccall('h264bsdDecode', 
+H264Decoder.h264bsdDecode = function(Module, pStorage, pBytes, len, picId, pBytesRead) {
+	return Module.ccall('_h264bsdDecode', 
 		number, 
 		[number, number, number, number, number], 
 		[pStorage, pBytes, len, picId, pReadBytes]);
@@ -56,8 +75,8 @@
 }
 
 // u8* h264bsdNextOutputPicture(storage_t *pStorage, u32 *picId, u32 *isIdrPic, u32 *numErrMbs);
-function h264bsdNextOutputPicture(pStorage, pPicId, pIsIdrPic, pNumErrMbs) {
-	return Module.ccall('h264bsdNextOutputPicture', 
+H264Decoder.h264bsdNextOutputPicture = function(Module, pStorage, pPicId, pIsIdrPic, pNumErrMbs) {
+	return Module.ccall('_h264bsdNextOutputPicture', 
 		number, 
 		[number, number, number, number], 
 		[pStorage, pPicId, pIsIdrPic, pNumErrMbs]);
@@ -64,19 +83,24 @@
 }
 
 // u32 h264bsdPicWidth(storage_t *pStorage);
-function h264bsdPicWidth(pStorage) {
-	return Module.ccall('h264bsdPicWidth', number, [number], [decoder]);
+H264Decoder.h264bsdPicWidth = function(Module, pStorage) {
+	return Module.ccall('_h264bsdPicWidth', number, [number], [pStorage]);
 }
 
 // u32 h264bsdPicHeight(storage_t *pStorage);
-function h264bsdPicHeight(pStorage) {
-	return Module.ccall('h264bsdPicHeight', number, [number], [decoder]);
+H264Decoder.h264bsdPicHeight = function(Module, pStorage) {
+	return Module.ccall('_h264bsdPicHeight', number, [number], [pStorage]);
 }
 
 // void h264bsdCroppingParams(storage_t *pStorage, u32 *croppingFlag, u32 *left, u32 *width, u32 *top, u32 *height);
-function h264bsdCroppingParams(pStorage, pCroppingFlag, pLeft, pWidth, pTop, pHeight) {
-	return Module.ccall('h264bsdCroppingParams', 
+H264Decoder.h264bsdCroppingParams = function(Module, pStorage, pCroppingFlag, pLeft, pWidth, pTop, pHeight) {
+	return Module.ccall('_h264bsdCroppingParams', 
 		number, 
 		[number, number, number, number, number, number, number], 
 		[pStorage, pCroppingFlag, pLeft, pWidth, pTop, pHeight]);
+}
+
+// u32 h264bsdCheckValidParamSets(storage_t *pStorage);
+H264Decoder.h264bsdCheckValidParamSets = function(Module, pStorage){
+	return Module.ccall('_h264bsdCheckValidParamSets', number, [number], [pStorage]);
 }