Skip to content

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
francois2metz committed Nov 17, 2010
0 parents commit 44dfc0e
Show file tree
Hide file tree
Showing 8 changed files with 696 additions and 0 deletions.
502 changes: 502 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions Main.hx
@@ -0,0 +1,65 @@
/* ************************************************************************ */
/* */
/* haXe Video */
/* Copyright (c)2007 Nicolas Cannasse */
/* Copyright (c)2010 af83 */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
/* Lesser General Public License or the LICENSE file for more details. */
/* */
/* ************************************************************************ */

class Main {
static var trace : flash.text.TextField;
static var bpos : Float = 2;

static function initTrace() {
var mc = flash.Lib.current;
trace = new flash.text.TextField();
trace.y = 20;
trace.thickness = 2;
trace.width = mc.stage.stageWidth;
trace.height = mc.stage.stageHeight - 20;
trace.selectable = false;
trace.textColor = 0xFFFFFF;
trace.mouseEnabled = false;
trace.filters = [new flash.filters.GlowFilter(0x7F7F7F,90,2,2,10)];
}

static function doTrace( v : Dynamic, ?pos : haxe.PosInfos ) {
trace.text += pos.fileName+"("+pos.lineNumber+") : "+Std.string(v)+"\n";
flash.Lib.current.addChild(trace);
}

static function main() {
initTrace();
haxe.Log.trace = doTrace;
var server = flash.Lib.current.loaderInfo.parameters.server;
var stream = flash.Lib.current.loaderInfo.parameters.stream;
flash.net.NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;

var cam = flash.media.Camera.getCamera();
if (cam == null)
{
throw "webcam not found";
}
cam.setMode(640, 480, 15, false);
cam.setQuality(0, 100);
if( cam == null )
doTrace("camera not found");
var video = new flash.media.Video(cam.width, cam.height);
video.x = 0;
video.y = 0;
video.attachCamera(cam);
flash.Lib.current.addChild(video);

var webcam = new Webcam(server, stream, "live");
}
}
5 changes: 5 additions & 0 deletions Makefile
@@ -0,0 +1,5 @@
debug:
haxe -debug video.hxml

release:
haxe video.hxml
41 changes: 41 additions & 0 deletions README.md
@@ -0,0 +1,41 @@
# Stream webcam and microphone to a rtmp server

## Usage

### vars

* server
* stream

### Example

<embed src="video.swf"
flashvars="server=rtmp://localhost/live&stream=plop"
bgcolor="#ffffff"
width="500"
height="500"
name="haxe"
quality="high"
align="middle"
allowScriptAccess="always"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" />

## Compile

# debug version
make debug

# release version
make release

## License

LGPL 2.1

## Credits

Original code haXe Video by Nicolas Cannasse

Copyright (c)2007 Nicolas Cannasse
Copyright (c)2010 af83xs
60 changes: 60 additions & 0 deletions Webcam.hx
@@ -0,0 +1,60 @@
/* ************************************************************************ */
/* */
/* haXe Video */
/* Copyright (c)2007 Nicolas Cannasse */
/* Copyright (c)2010 af83 */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */
/* */
/* This library is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
/* Lesser General Public License or the LICENSE file for more details. */
/* */
/* ************************************************************************ */
class Webcam {
var nc : flash.net.NetConnection;
var ns : flash.net.NetStream;
var cam : flash.media.Camera;
var mic : flash.media.Microphone;
var file : String;
var share : String;

public function new(host, file,?share) {
this.file = file;
this.share = share;
this.cam = flash.media.Camera.getCamera();
this.cam.setMode(640, 480, 15, true);
this.mic = flash.media.Microphone.getMicrophone();
if( this.cam == null )
throw "Webcam not found";
this.nc = new flash.net.NetConnection();
this.nc.addEventListener(flash.events.NetStatusEvent.NET_STATUS,onEvent);
this.nc.connect(host);
}

function onKey( e : flash.events.KeyboardEvent ) {
ns.send("onMetaData",{ keypress : e.keyCode });
}

function onEvent(e) {
if( e.info.code == "NetConnection.Connect.Success" ) {
this.ns = new flash.net.NetStream(nc);
this.ns.addEventListener(flash.events.NetStatusEvent.NET_STATUS,onEvent);
this.ns.publish(this.file,this.share);
} else if (e.info.code == "NetStream.Publish.Start") {
this.ns.attachCamera(this.cam);
this.ns.attachAudio(this.mic);
//this.ns.bufferTime = 1;
}
}

public function doStop() {
if( ns != null )
ns.close();
nc.close();
}
}
21 changes: 21 additions & 0 deletions video.html
@@ -0,0 +1,21 @@
<html>
<head><title>haXe Video</title></head>
<body bgcolor="#dddddd">

<embed src="video.swf"
flashvars="server=rtmp://localhost/live&stream=plop"
bgcolor="#ffffff"
width="500"
height="500"
name="haxe"
quality="high"
align="middle"
allowScriptAccess="always"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" />

<p>
If you don't see the SWF, check that you have Flash Player 9 installed.
</p>
</body>
</html>
2 changes: 2 additions & 0 deletions video.hxml
@@ -0,0 +1,2 @@
-swf9 video.swf
-main Main
Binary file added video.swf
Binary file not shown.

0 comments on commit 44dfc0e

Please sign in to comment.