ref: cbd8817fcd1a48c189d4fb06061161971b86cd95
parent: dc113711f18d3e35f22fbb34a747604b41f91ded
author: Sam Leitch <sam.leitch@calgaryscientific.com>
date: Tue Mar 18 19:06:32 EDT 2014
Changed Flex to draw to bitmapData (more flexible). Added flex test app.
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,6 @@
node_modules
js/h264bsd_asm.js.map
*.suo
-flex/.settings/
flex/bin/
*.swf
+.settings
--- a/flex/Makefile
+++ b/flex/Makefile
@@ -25,12 +25,12 @@
mkdir -p bin
"$(FLEX)/bin/compc" -library-path=lib/h264bsd_asm.swc -source-path=src -include-sources=src -o bin/h264bsd.swc
-test/h264test.swf: test/h264test.as lib/h264bsd_asm.swc
+test/h264test.swf: test/h264test.mxml bin/h264bsd.swc
@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
- "$(FLEX)/bin/mxmlc" -static-link-runtime-shared-libraries -compiler.omit-trace-statements=false -library-path=lib/h264bsd_asm.swc -debug=true test/h264test.as -o test/h264test.swf
+ "$(FLEX)/bin/mxmlc" -static-link-runtime-shared-libraries -compiler.omit-trace-statements=false -library-path=bin/h264bsd.swc -debug=true test/h264test.mxml -o test/h264test.swf
clean:
rm -f test/*.swf lib/*.swc bin/*.swc *.bc *.exe
--- a/flex/src/h264bsd/Decoder.as
+++ b/flex/src/h264bsd/Decoder.as
@@ -1,6 +1,5 @@
package h264bsd
{
- import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.EventDispatcher;
import flash.filters.ColorMatrixFilter;
@@ -174,8 +173,10 @@
return bytes;
}
- public function drawNextOutputPicture(target:Bitmap, transform:Matrix = null):void
+ public function drawNextOutputPicture(target:BitmapData, transform:Matrix = null):void
{
+ if(target == null) return;
+
var outputPictureBytes:ByteArray = getNextOutputPictureBytesYCbCrA();
var cinfo:CroppingInfo = getCroppingInfo();
@@ -194,9 +195,9 @@
outputPicture.applyFilter(outputPicture, outputPicture.rect, new Point(0,0), bt601Filter);
- target.bitmapData.lock();
- target.bitmapData.draw(outputPicture, transform, null, null, new Rectangle(0,0, cinfo.width, cinfo.height), true);
- target.bitmapData.unlock();
+ target.lock();
+ target.draw(outputPicture, transform, null, null, new Rectangle(0,0, cinfo.width, cinfo.height), true);
+ target.unlock();
}
private function get outputByteLength():int {
--- /dev/null
+++ b/flex/test/.actionScriptProperties
@@ -1,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<actionScriptProperties analytics="false" mainApplicationPath="h264test.mxml" projectUUID="2eadc222-6e29-45d3-9261-1774c726c2a0" version="10">
+ <compiler additionalCompilerArguments="-locale en_US" autoRSLOrdering="true" copyDependentFiles="true" fteInMXComponents="false" generateAccessible="true" htmlExpressInstall="true" htmlGenerate="false" htmlHistoryManagement="true" htmlPlayerVersionCheck="true" includeNetmonSwc="false" outputFolderPath="" removeUnusedRSL="true" strict="true" targetPlayerVersion="0.0.0" useApolloConfig="false" useDebugRSLSwfs="true" verifyDigests="true" warn="true">
+ <compilerSourcePath/>
+ <libraryPath defaultLinkType="0">
+ <libraryPathEntry kind="4" path="">
+ <excludedEntries>
+ <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/flex.swc" useDefaultLinkType="false"/>
+ <libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/core.swc" useDefaultLinkType="false"/>
+ </excludedEntries>
+ </libraryPathEntry>
+ <libraryPathEntry kind="3" linkType="1" path="/h264bsd/bin/h264bsd.swc" useDefaultLinkType="false"/>
+ </libraryPath>
+ <sourceAttachmentPath/>
+ </compiler>
+ <applications>
+ <application path="h264test.mxml"/>
+ </applications>
+ <modules/>
+ <buildCSSFiles/>
+ <flashCatalyst validateFlashCatalystCompatibility="false"/>
+</actionScriptProperties>
--- /dev/null
+++ b/flex/test/.flexProperties
@@ -1,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<flexProperties enableServiceManager="false" flexServerFeatures="0" flexServerType="0" toolCompile="true" useServerFlexSDK="false" version="2"/>
--- /dev/null
+++ b/flex/test/.project
@@ -1,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>h264test</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.adobe.flexbuilder.project.flexbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.adobe.flexbuilder.project.flexnature</nature>
+ <nature>com.adobe.flexbuilder.project.actionscriptnature</nature>
+ </natures>
+</projectDescription>
--- a/flex/test/h264test.as
+++ /dev/null
@@ -1,43 +1,0 @@
-package
-{
- import flash.display.Sprite;
- import flash.text.TextField;
- import flash.events.Event;
- import h264bsd_asm.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/test/h264test.mxml
@@ -1,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8"?>
+<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
+ xmlns:s="library://ns.adobe.com/flex/spark"
+ xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
+ <fx:Script>
+ <![CDATA[
+ import h264bsd.CroppingInfo;
+ import h264bsd.Decoder;
+
+ import mx.core.UIComponent;
+
+ private function loadFile():void {
+ var fileRef:FileReference = new FileReference();
+ fileRef.addEventListener(Event.SELECT, onFileSelected);
+ fileRef.browse();
+
+ function onFileSelected(e:Event):void {
+ e.target.addEventListener(Event.COMPLETE, onFileComplete);
+ e.target.load();
+ }
+
+ function onFileComplete(e:Event):void {
+ loopH264Data(e.target.data as ByteArray);
+ }
+ }
+
+ private function loopH264Data(data:ByteArray):void {
+ if(data == null) return;
+
+ var decoder:Decoder = new Decoder();
+
+ var renderTarget:Bitmap = new Bitmap();
+ var renderComponent:UIComponent = new UIComponent();
+ renderComponent.addChild(renderTarget);
+ main.addElement(renderComponent);
+
+ decoder.queueInput(data);
+ loopBody();
+
+ function loopBody():void {
+ var result:int = decoder.decode();
+
+ switch(result)
+ {
+ case Decoder.NO_INPUT:
+ decoder.queueInput(data);
+ setTimeout(loopBody, 0);
+ break;
+ case Decoder.HDRS_RDY:
+ var cinfo:CroppingInfo = decoder.getCroppingInfo();
+ renderTarget.bitmapData = new BitmapData(cinfo.width, cinfo.height);
+ setTimeout(loopBody, 0);
+ break;
+ case Decoder.PIC_RDY:
+ decoder.drawNextOutputPicture(renderTarget.bitmapData);
+ setTimeout(loopBody, 0);
+ break;
+ case Decoder.RDY:
+ loopBody();
+ break;
+ default:
+ throw new Error("An error has occured in the decoder");
+ break;
+ }
+ }
+ }
+ ]]>
+ </fx:Script>
+
+ <s:VGroup id="main">
+ <s:Button label="Load File" click="loadFile()"/>
+ </s:VGroup>
+</s:Application>