shithub: h264bsd

Download patch

ref: ac47fb12e8cac244fc7703607a42e54f37948270
parent: af1bec840492f50128b60546b3cf06bc202214a2
parent: 947024fb1ce0ab5b51a4464184969c6c06b4c966
author: Sam Leitch <sam@luceva.net>
date: Wed Feb 19 15:18:18 EST 2014

Merge branch 'crossbridge'

--- /dev/null
+++ b/flex/Makefile
@@ -1,0 +1,38 @@
+SOURCES = $(wildcard ../src/*.c) main.c
+
+FLASCC:=X
+FLEX:=X
+AS3COMPILER:=asc2.jar
+BASE_CFLAGS:=-DFLASCC -O4
+
+$?UNAME=$(shell uname -s)
+ifneq (,$(findstring CYGWIN,$(UNAME)))
+	$?nativepath=$(shell cygpath -at mixed $(1))
+	$?unixpath=$(shell cygpath -at unix $(1))
+else
+	$?nativepath=$(abspath $(1))
+	$?unixpath=$(abspath $(1))
+endif
+
+ifneq (,$(findstring "asc2.jar","$(AS3COMPILER)"))
+	$?AS3COMPILERARGS=$(JAVA_HOME)/bin/java $(JVMARGS) -jar $(call nativepath,$(FLASCC)/usr/lib/$(AS3COMPILER)) -merge -md 
+else
+	echo "ASC is no longer supported" ; exit 1 ;
+endif
+
+check:
+	@if [ -d $(FLASCC)/usr/bin ] ; then true ; \
+	else echo "Couldn't locate FLASCC sdk directory, please invoke make with \"make FLASCC=/path/to/FLASCC/sdk ...\"" ; exit 1 ; \
+	fi
+
+	@if [ -d "$(FLEX)/bin" ] ; then true ; \
+	else echo "Couldn't locate Flex sdk directory, please invoke make with \"make FLEX=/path/to/flex  ...\"" ; exit 1 ; \
+	fi
+
+swc: check
+	"$(FLASCC)/usr/bin/gcc" $(BASE_CFLAGS) $(SOURCES) -emit-swc=h264bsd -o h264bsd.swc
+	"$(FLEX)/bin/mxmlc" -static-link-runtime-shared-libraries -compiler.omit-trace-statements=false -library-path=h264bsd.swc -debug=true h264test.as -o h264test.swf
+
+
+clean:
+	rm -f *.swf *.swc *.bc *.exe
--- /dev/null
+++ b/flex/h264test.as
@@ -1,0 +1,43 @@
+package
+{
+  import flash.display.Sprite;
+  import flash.text.TextField;
+  import flash.events.Event;
+  import h264bsd.CModule;
+  
+  public class h264test extends Sprite
+  {
+    public function h264test()
+    {
+      addEventListener(Event.ADDED_TO_STAGE, initCode);
+    }
+ 
+    public function initCode(e:Event):void
+    {
+      CModule.startAsync(this)
+	  
+	  var ret:int = 0;
+	  var tf:TextField = new TextField
+      tf.multiline = true
+      tf.width = stage.stageWidth
+      tf.height = stage.stageHeight
+      addChild(tf)
+	  
+	  trace("Logging Started...");
+	  
+	  var h264:int = 0;
+	  var args:Vector.<int> = new Vector.<int>;
+      h264 = CModule.callI(CModule.getPublicSymbol("h264bsdAlloc"), args);	  
+	  tf.appendText("h264bsdAlloc ... " + ( h264 != 0 ? "Success" : "Failure") + "\n");
+	  
+	  
+	  args = new <int>[h264,0];
+	  ret = CModule.callI(CModule.getPublicSymbol("h264bsdInit"), args);	  	  
+	  tf.appendText("h264bsdInit ... " + ( ret == 0 ? "Success" : "Failure" + ret) + "\n");  
+	  
+	  args = new <int>[h264];
+	  CModule.callI(CModule.getPublicSymbol("h264bsdShutdown"), args);	  	  
+	  tf.appendText("h264bsdShutdown ... Success\n");  
+    }
+  }
+}
--- /dev/null
+++ b/flex/main.c
@@ -1,0 +1,6 @@
+#include "AS3/AS3.h"
+
+int main()
+{
+     AS3_GoAsync();
+}
\ No newline at end of file
--- a/src/h264bsd_conceal.c
+++ b/src/h264bsd_conceal.c
@@ -176,8 +176,13 @@
              refData == NULL)
             memset(currImage->data, 128, width*height*384);
         else
-            memcpy(currImage->data, refData, width*height*384);
-
+        {
+            int ii = 0;
+            int size = width*height*384;
+            u8* curr_data = currImage->data;
+            for (ii = 0; ii < size;ii++);
+                curr_data[i] = refData[i];
+        }
         pStorage->numConcealedMbs = pStorage->picSizeInMbs;
 
         /* no filtering if whole picture concealed */
--- a/src/h264bsd_decoder.c
+++ b/src/h264bsd_decoder.c
@@ -42,7 +42,6 @@
 /*------------------------------------------------------------------------------
     1. Include headers
 ------------------------------------------------------------------------------*/
-
 #include "h264bsd_decoder.h"
 #include "h264bsd_nal_unit.h"
 #include "h264bsd_byte_stream.h"
@@ -110,6 +109,9 @@
     if (noOutputReordering)
         pStorage->noReordering = HANTRO_TRUE;
 
+    pStorage->rgbConversionBuffer = NULL;
+    pStorage->rgbConversionBufferLength = 0;
+
     return HANTRO_OK;
 }
 
@@ -608,7 +610,7 @@
     ASSERT(pStorage);
 
     pOut = h264bsdDpbOutputPicture(pStorage->dpb);
-
+    
     if (pOut != NULL)
     {
         *picId = pOut->picId;
@@ -621,8 +623,59 @@
 
 }
 
+
 /*------------------------------------------------------------------------------
 
+    Function: h264bsdNextOutputPictureARGB
+
+        Functional description:
+            Get next output picture in display order, converted from YUV to ARGB.
+            Freeing the resulting buffer is the callers responsibility.
+
+        Inputs:
+            pStorage    pointer to storage data structure
+
+        Outputs:
+            picId       identifier of the picture will be stored here
+            isIdrPic    IDR flag of the picture will be stored here
+            numErrMbs   number of concealed macroblocks in the picture
+                        will be stored here
+            length      The length of the resulting buffer
+
+        Returns:
+            pointer to the picture data
+            NULL if no pictures available for display
+
+------------------------------------------------------------------------------*/
+u8* h264bsdNextOutputPictureARGB(storage_t *pStorage, u32 *picId, u32 *isIdrPic, u32 *numErrMbs, u32 *length)
+{
+    /* Variables */
+
+    dpbOutPicture_t *pOut;
+    u8              *data;
+    /* Code */
+
+    ASSERT(pStorage);
+
+    pOut = h264bsdDpbOutputPicture(pStorage->dpb);
+    
+    if (pOut != NULL)
+    {
+        *picId = pOut->picId;
+        *isIdrPic = pOut->isIdr;
+        *numErrMbs = pOut->numErrMbs;
+
+        data = yuv2rgb(pStorage, pOut->data);
+
+        *length = pStorage->rgbConversionBufferLength;
+        return data;
+    }
+    else
+        return(NULL);
+}
+
+/*------------------------------------------------------------------------------
+
     Function: h264bsdPicWidth
 
         Functional description:
@@ -1006,3 +1059,92 @@
 {
     free(pStorage);
 }
+
+void yuvtorgb(int Y, int U, int V, u8 *rgb)
+{
+    int r, g, b, c, d, e;
+    
+    c = Y - 16;
+    d = U - 128;
+    e = V - 128;
+    r = 1.164383 * c                   + 1.596027 * e ;
+    g = 1.164383 * c - (0.391762 * d) - (0.812968 * e);
+    b = 1.164383 * c +  2.017232 * d                  ;
+   
+    rgb[0] = 0xff;
+    rgb[1] = CLIP1(r);
+    rgb[2] = CLIP1(g);
+    rgb[3] = CLIP1(b);
+}
+
+
+u8* yuv2rgb(storage_t *pStorage, u8* yuvBytes)
+{
+    int x;    
+    int i,j;
+
+    u8* y = yuvBytes;
+    u8* u = 0;
+    u8* v = 0;
+    u8* out = 0;
+    
+    int w = h264bsdPicWidth(pStorage) * 16;
+    int W = w*4;
+    int w_2 = w/2;
+    int h = h264bsdPicHeight(pStorage) * 16;
+
+    int rgbLength = w*h*4;
+
+    int uoffset = w*h;
+    int voffset = w*h+((w*h)>>2);
+    int luma = 0;
+    
+    u = yuvBytes+uoffset;
+    v = yuvBytes+voffset;
+
+    if (pStorage->rgbConversionBuffer != NULL && pStorage->rgbConversionBufferLength != rgbLength)
+    {
+        FREE(pStorage->rgbConversionBuffer);
+        pStorage->rgbConversionBufferLength = 0;
+    }
+
+    if (pStorage->rgbConversionBuffer == NULL)
+    {
+        pStorage->rgbConversionBuffer = (u8*)malloc(rgbLength);
+        if (pStorage->rgbConversionBuffer == NULL)
+            return NULL;
+        pStorage->rgbConversionBufferLength = rgbLength;
+    }
+
+    out = pStorage->rgbConversionBuffer;
+    
+    for(; h -= 2;){
+        for(j = w_2; j--; ) {
+            int u,v,y1,y2;
+            
+            y2 = yuvBytes[luma + w];
+            y1 = yuvBytes[luma++];
+
+            u = yuvBytes[uoffset++];
+            v = yuvBytes[voffset++];
+
+            yuvtorgb(y1, u, v, out);    
+            yuvtorgb(y2, u, v, (out+W));
+           
+            out += 4;
+
+            y2 = yuvBytes[luma + w];
+            y1 = yuvBytes[luma++];
+
+            yuvtorgb(y1, u, v, out);    
+            yuvtorgb(y2, u, v, (out+W));
+
+            out += 4;
+        }
+
+        luma += w;
+        out += W;
+    }
+   
+    return pStorage->rgbConversionBuffer;
+}
\ No newline at end of file
--- a/src/h264bsd_decoder.h
+++ b/src/h264bsd_decoder.h
@@ -35,6 +35,8 @@
 
 #include "basetype.h"
 
+#include "h264bsd_storage.h"
+
 /*------------------------------------------------------------------------------
     2. Module defines
 ------------------------------------------------------------------------------*/
@@ -53,8 +55,8 @@
     3. Data types
 ------------------------------------------------------------------------------*/
 
-typedef struct storage storage_t;
 
+
 /*------------------------------------------------------------------------------
     4. Function prototypes
 ------------------------------------------------------------------------------*/
@@ -67,6 +69,8 @@
 u8* h264bsdNextOutputPicture(storage_t *pStorage, u32 *picId, u32 *isIdrPic,
     u32 *numErrMbs);
 
+u8* h264bsdNextOutputPictureARGB(storage_t *pStorage, u32 *picId, u32 *isIdrPic, u32 *numErrMbs, u32 *length);
+
 u32 h264bsdPicWidth(storage_t *pStorage);
 u32 h264bsdPicHeight(storage_t *pStorage);
 u32 h264bsdVideoRange(storage_t *pStorage);
@@ -83,6 +87,7 @@
 
 storage_t* h264bsdAlloc();
 void h264bsdFree(storage_t *pStorage);
+u8* yuv2rgb(storage_t *pStorage, u8* yuvBytes);
 
 #endif /* #ifdef H264SWDEC_DECODER_H */
 
--- a/src/h264bsd_reconstruct.c
+++ b/src/h264bsd_reconstruct.c
@@ -2137,12 +2137,35 @@
   i32 center,
   i32 right)
 {
+    int i = 0;    
+    u8 *pdest = (u8*) fill;
+    u8 *psrc = (u8*) ref;
+    int loops = (center / sizeof(u32));
 
     ASSERT(ref);
     ASSERT(fill);
 
-    memcpy(fill, ref, (u32)center);
+    
 
+
+    for(i = 0; i < loops; ++i)
+    {
+        *((u32*)pdest) = *((u32*)psrc);
+        pdest += sizeof(u32);
+        psrc += sizeof(u32);
+    }
+
+    loops = (center % sizeof(u32));
+    for (i = 0; i < loops; ++i)
+    {
+        *pdest = *psrc;
+        ++pdest;
+        ++psrc;
+    }
+
+    // XXX CrossBridge Optimization
+    // memcpy(fill, ref, center);
+
     /*lint -e(715) */
 }
 
@@ -2286,27 +2309,58 @@
     bottom = ystop > (i32)height ? ystop - (i32)height : 0;
     y = (i32)blockHeight - top - bottom;
 
-    /* Top-overfilling */
-    for ( ; top; top-- )
+    if (x0 >= 0 && xstop <= (i32)width)
     {
-        (*fp)(ref, fill, left, x, right);
-        fill += fillScanLength;
+        for ( ; top; top-- )
+        {
+            FillRow1(ref, fill, left, x, right);
+            fill += fillScanLength;
+        }
+        for ( ; top; top-- )
+        {
+            FillRow1(ref, fill, left, x, right);            
+        }
+        for ( ; y; y-- )
+        {
+            FillRow1(ref, fill, left, x, right);
+            ref += width;
+            fill += fillScanLength;
+        }
     }
-
-    /* Lines inside reference image */
-    for ( ; y; y-- )
+    else
     {
-        (*fp)(ref, fill, left, x, right);
-        ref += width;
-        fill += fillScanLength;
+        for ( ; top; top-- )
+        {
+            h264bsdFillRow7(ref, fill, left, x, right);
+            fill += fillScanLength;
+        }
+        for ( ; top; top-- )
+        {
+            h264bsdFillRow7(ref, fill, left, x, right);            
+        }
+        for ( ; y; y-- )
+        {
+            h264bsdFillRow7(ref, fill, left, x, right);
+            ref += width;
+            fill += fillScanLength;
+        }
     }
+    /* Top-overfilling */
+    
 
+    /* Lines inside reference image */
+    
+
     ref -= width;
 
     /* Bottom-overfilling */
     for ( ; bottom; bottom-- )
     {
-        (*fp)(ref, fill, left, x, right);
+        //(*fp)(ref, fill, left, x, right);
+        if (x0 >= 0 && xstop <= (i32)width)
+            FillRow1(ref, fill, left, x, right);
+        else
+            h264bsdFillRow7(ref, fill, left, x, right);
         fill += fillScanLength;
     }
 }
--- a/src/h264bsd_storage.h
+++ b/src/h264bsd_storage.h
@@ -147,6 +147,8 @@
                               HEADERS_RDY to the user */
     u32 intraConcealmentFlag; /* 0 gray picture for corrupted intra
                                  1 previous frame used if available */
+    u8* rgbConversionBuffer; // used to performance yuv conversion
+    int rgbConversionBufferLength;
 } storage_t;
 
 /*------------------------------------------------------------------------------