mirror of https://github.com/ossrs/srs.git
support play hls
parent
69ec66ee36
commit
46a31f4884
@ -0,0 +1,97 @@
|
||||
package
|
||||
{
|
||||
import flash.utils.ByteArray;
|
||||
|
||||
/**
|
||||
* a piece of flv, fetch from cdn or p2p.
|
||||
*/
|
||||
public class FlvPiece
|
||||
{
|
||||
private var _pieceId:Number;
|
||||
protected var _flv:ByteArray;
|
||||
/**
|
||||
* the private object for the channel,
|
||||
* for example, the cdn channel will set to CdnEdge object.
|
||||
*/
|
||||
private var _privateObject:Object;
|
||||
/**
|
||||
* when encoder error, this piece cannot be generated,
|
||||
* and it should be skip. default to false.
|
||||
*/
|
||||
private var _skip:Boolean;
|
||||
|
||||
public function FlvPiece(pieceId:Number)
|
||||
{
|
||||
_pieceId = pieceId;
|
||||
_flv = null;
|
||||
_skip = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* when piece is fetch ok.
|
||||
*/
|
||||
public function onPieceDone(flv:ByteArray):void
|
||||
{
|
||||
// save body.
|
||||
_flv = flv;
|
||||
}
|
||||
|
||||
/**
|
||||
* when piece is fetch error.
|
||||
*/
|
||||
public function onPieceError():void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* when piece is empty.
|
||||
*/
|
||||
public function onPieceEmpty():void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* destroy the object, set reference to null.
|
||||
*/
|
||||
public function destroy():void
|
||||
{
|
||||
_privateObject = null;
|
||||
_flv = null;
|
||||
}
|
||||
|
||||
public function get privateObject():Object
|
||||
{
|
||||
return _privateObject;
|
||||
}
|
||||
|
||||
public function set privateObject(v:Object):void
|
||||
{
|
||||
_privateObject = v;
|
||||
}
|
||||
|
||||
public function get skip():Boolean
|
||||
{
|
||||
return _skip;
|
||||
}
|
||||
|
||||
public function set skip(v:Boolean):void
|
||||
{
|
||||
_skip = v;
|
||||
}
|
||||
|
||||
public function get pieceId():Number
|
||||
{
|
||||
return _pieceId;
|
||||
}
|
||||
|
||||
public function get flv():ByteArray
|
||||
{
|
||||
return _flv;
|
||||
}
|
||||
|
||||
public function get completed():Boolean
|
||||
{
|
||||
return _flv != null;
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,12 @@
|
||||
package
|
||||
{
|
||||
public interface ILogger
|
||||
{
|
||||
function debug0(message:String, ... rest):void;
|
||||
function debug(message:String, ... rest):void;
|
||||
function info(message:String, ... rest):void;
|
||||
function warn(message:String, ... rest):void;
|
||||
function error(message:String, ... rest):void;
|
||||
function fatal(message:String, ... rest):void;
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package
|
||||
{
|
||||
import flash.globalization.DateTimeFormatter;
|
||||
|
||||
public class TraceLogger implements ILogger
|
||||
{
|
||||
private var _category:String;
|
||||
|
||||
public function get category():String
|
||||
{
|
||||
return _category;
|
||||
}
|
||||
public function TraceLogger(category:String)
|
||||
{
|
||||
_category = category;
|
||||
}
|
||||
public function debug0(message:String, ...rest):void
|
||||
{
|
||||
}
|
||||
|
||||
public function debug(message:String, ...rest):void
|
||||
{
|
||||
}
|
||||
|
||||
public function info(message:String, ...rest):void
|
||||
{
|
||||
logMessage(LEVEL_INFO, message, rest);
|
||||
}
|
||||
|
||||
public function warn(message:String, ...rest):void
|
||||
{
|
||||
logMessage(LEVEL_WARN, message, rest);
|
||||
}
|
||||
|
||||
public function error(message:String, ...rest):void
|
||||
{
|
||||
logMessage(LEVEL_ERROR, message, rest);
|
||||
}
|
||||
|
||||
public function fatal(message:String, ...rest):void
|
||||
{
|
||||
logMessage(LEVEL_FATAL, message, rest);
|
||||
}
|
||||
protected function logMessage(level:String, message:String, params:Array):void
|
||||
{
|
||||
var msg:String = "";
|
||||
|
||||
// add datetime
|
||||
var date:Date = new Date();
|
||||
var dtf:DateTimeFormatter = new DateTimeFormatter("UTC");
|
||||
dtf.setDateTimePattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
// TODO: FIXME: the SSS format not run, use date.milliseconds instead.
|
||||
msg += '[' + dtf.format(date) + "." + date.milliseconds + ']';
|
||||
msg += " [" + level + "] ";
|
||||
|
||||
// add category and params
|
||||
msg += "[" + category + "] " + applyParams(message, params);
|
||||
|
||||
// trace the message
|
||||
Utility.log("CORE", msg);
|
||||
}
|
||||
private function leadingZeros(x:Number):String
|
||||
{
|
||||
if (x < 10) {
|
||||
return "00" + x.toString();
|
||||
}
|
||||
|
||||
if (x < 100) {
|
||||
return "0" + x.toString();
|
||||
}
|
||||
|
||||
return x.toString();
|
||||
}
|
||||
private function applyParams(message:String, params:Array):String
|
||||
{
|
||||
var result:String = message;
|
||||
|
||||
var numParams:int = params.length;
|
||||
|
||||
for (var i:int = 0; i < numParams; i++) {
|
||||
result = result.replace(new RegExp("\\{" + i + "\\}", "g"), params[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static const LEVEL_DEBUG:String = "DEBUG";
|
||||
private static const LEVEL_WARN:String = "WARN";
|
||||
private static const LEVEL_INFO:String = "INFO";
|
||||
private static const LEVEL_ERROR:String = "ERROR";
|
||||
private static const LEVEL_FATAL:String = "FATAL";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue