17dd1e68 by David LaPalomento

Create test harness and start porting segment parser

Create a qunit test to verify the flv header. Start work on parsing the m2ts packets. The test harness is using a hard-coded Uint8Array which is the first segment of the "bipbop" video. Currently the segment parser is consuming bytes and passing them off to the internal packet parsing function but that isn't yet implemented.
1 parent 7f0a59b2
......@@ -53,7 +53,7 @@ module.exports = function(grunt) {
options: {
jshintrc: 'test/.jshintrc'
},
src: ['test/**/*.js']
src: ['test/**/*.js', '!test/tsSegment.js']
},
},
watch: {
......
{
"curly": true,
"eqeqeq": true,
"globals": {
"console": true
},
"immed": true,
"latedef": true,
"newcap": true,
......
/*
* aac-stream
*
*
* Copyright (c) 2013 Brightcove
* All rights reserved.
*/
(function(window) {
window.videojs.hls.AacStream = function(){
this.tags = [];
};
})(this);
(function(window) {
window.videojs.hls.FlvTag = function() {};
/*
package com.videojs.providers.hls.utils{
import flash.utils.ByteArray;
import flash.utils.Endian;
public class FlvTag extends ByteArray
{
public static const AUDIO_TAG:uint = 0x08;
public static const VIDEO_TAG:uint = 0x09;
public static const METADATA_TAG:uint = 0x12;
public var keyFrame:Boolean = false;
private var extraData:Boolean = false;
private var adHoc:uint = 0; // Counter if this is a metadata tag, nal start marker if this is a video tag. unused if this is an audio tag
public var pts:uint;
public var dts:uint;
public static function isAudioFrame(tag:ByteArray):Boolean
{
return AUDIO_TAG == tag[0];
}
public static function isVideoFrame(tag:ByteArray):Boolean
{
return VIDEO_TAG == tag[0];
}
public static function isMetaData(tag:ByteArray):Boolean
{
return METADATA_TAG == tag[0];
}
public static function isKeyFrame(tag:ByteArray):Boolean
{
if ( isVideoFrame(tag) )
return tag[11] == 0x17;
if( isAudioFrame(tag) )
return true;
if( isMetaData(tag) )
return true;
return false;
}
public static function frameTime(tag:ByteArray):uint
{
var pts:uint = tag[ 4] << 16;
pts |= tag[ 5] << 8;
pts |= tag[ 6] << 0;
pts |= tag[ 7] << 24;
return pts;
}
public function FlvTag(type:uint, ed:Boolean = false)
{
super();
extraData = ed;
this.endian = Endian.BIG_ENDIAN;
switch(type)
{
case VIDEO_TAG: this.length = 16; break;
case AUDIO_TAG: this.length = 13; keyFrame = true; break;
case METADATA_TAG: this.length = 29; keyFrame = true; break;
default: throw("Error Unknown TagType");
}
this[0] = type
this.position = this.length;
keyFrame = extraData; // Defaults to false
pts = dts = 0;
}
// Negative index into array
public function negIndex(pos:uint):int
{
return this[this.length - pos];
}
// The functions below ONLY work when this[0] == VIDEO_TAG.
// We are not going to check for that because we dont want the overhead
public function nalUnitSize(nal:ByteArray = null):int
{
if( 0 == adHoc )
return 0;
return this.length - ( adHoc + 4 );
}
public function startNalUnit():void
{ // remember position and add 4 bytes
if ( 0 < adHoc )
{
throw new Error("Attempted to create new NAL wihout closing the old one");
}
// reserve 4 bytes for nal unit size
adHoc = this.length;
this.length += 4;
this.position = this.length;
}
public function endNalUnit(nal:ByteArray = null):void
{ // Rewind to the marker and write the size
if ( this.length == adHoc + 4 )
{
this.length -= 4; // we started a nal unit, but didnt write one, so roll back the 4 byte size value
}
else
if ( 0 < adHoc )
{
var nalStart:uint = adHoc + 4;
var nalLength:uint = this.length - nalStart;
this.position = adHoc;
this.writeUnsignedInt( nalLength );
this.position = this.length;
if ( null != nal ) // If the user pass in a ByteArray, copy the NAL to it.
nal.writeBytes( this, nalStart, nalLength );
}
adHoc = 0;
}
public function writeMetaDataDouble(key:String, val:Number):void
{
writeShort ( key.length );
writeUTFBytes ( key );
writeByte ( 0x00 );
writeDouble ( val );
++adHoc;
}
public function writeMetaDataBoolean(key:String, val:Boolean):void
{
writeShort ( key.length );
writeUTFBytes ( key );
writeByte ( 0x01 );
writeByte ( true == val ? 0x01 : 0x00 );
++adHoc;
}
public function finalize():ByteArray
{
switch(this[0])
{ // Video Data
case VIDEO_TAG:
this[11] = ( ( keyFrame || extraData ) ? 0x10 : 0x20 ) | 0x07; // We only support AVC, 1 = key frame (for AVC, a seekable frame), 2 = inter frame (for AVC, a non-seekable frame)
this[12] = extraData ? 0x00 : 0x01;
var dtsDelta:int = pts - dts;
this[13] = ( dtsDelta & 0x00FF0000 ) >>> 16;
this[14] = ( dtsDelta & 0x0000FF00 ) >>> 8;
this[15] = ( dtsDelta & 0x000000FF ) >>> 0;
break;
case AUDIO_TAG:
this[11] = 0xAF;
this[12] = extraData ? 0x00 : 0x01;
break;
case METADATA_TAG:
this.position = 11;
writeByte(0x02); // String type
writeShort(0x0A); // 10 Bytes
writeUTFBytes("onMetaData");
writeByte(0x08); // Array type
writeUnsignedInt( adHoc );
this.position = this.length;
writeUnsignedInt( 0x09 ); // End Data Tag
break;
}
var len:int = this.length - 11;
this[ 1] = ( len & 0x00FF0000 ) >>> 16;
this[ 2] = ( len & 0x0000FF00 ) >>> 8;
this[ 3] = ( len & 0x000000FF ) >>> 0;
this[ 4] = ( pts & 0x00FF0000 ) >>> 16;
this[ 5] = ( pts & 0x0000FF00 ) >>> 8;
this[ 6] = ( pts & 0x000000FF ) >>> 0;
this[ 7] = ( pts & 0xFF000000 ) >>> 24;
this[ 8] = 0;
this[ 9] = 0;
this[10] = 0;
this.writeUnsignedInt( this.length );
return this;
}
}
}
*/
})(this);
/*
* h264-stream
*
*
* Copyright (c) 2013 Brightcove
* All rights reserved.
*/
(function(window) {
window.videojs.hls.H264Stream = function(){
this.tags = [];
};
})(this);
......@@ -6,6 +6,8 @@
* All rights reserved.
*/
(function() {
(function(window) {
})();
window.videojs.hls = {};
})(this);
......
This diff could not be displayed because it is too large.
......@@ -6,8 +6,46 @@
<!-- Load local QUnit. -->
<link rel="stylesheet" href="../libs/qunit/qunit.css" media="screen">
<script src="../libs/qunit/qunit.js"></script>
<!-- Load local lib and tests. -->
<!-- video.js -->
<script src="../libs/video-js/src/js/core.js"></script>
<script src="../libs/video-js/src/js/core-object.js"></script>
<script src="../libs/video-js/src/js/events.js"></script>
<script src="../libs/video-js/src/js/lib.js"></script>
<script src="../libs/video-js/src/js/component.js"></script>
<script src="../libs/video-js/src/js/button.js"></script>
<script src="../libs/video-js/src/js/slider.js"></script>
<script src="../libs/video-js/src/js/menu.js"></script>
<script src="../libs/video-js/src/js/player.js"></script>
<script src="../libs/video-js/src/js/control-bar/control-bar.js"></script>
<script src="../libs/video-js/src/js/control-bar/play-toggle.js"></script>
<script src="../libs/video-js/src/js/control-bar/time-display.js"></script>
<script src="../libs/video-js/src/js/control-bar/fullscreen-toggle.js"></script>
<script src="../libs/video-js/src/js/control-bar/progress-control.js"></script>
<script src="../libs/video-js/src/js/control-bar/volume-control.js"></script>
<script src="../libs/video-js/src/js/control-bar/mute-toggle.js"></script>
<script src="../libs/video-js/src/js/control-bar/volume-menu-button.js"></script>
<script src="../libs/video-js/src/js/poster.js"></script>
<script src="../libs/video-js/src/js/loading-spinner.js"></script>
<script src="../libs/video-js/src/js/big-play-button.js"></script>
<script src="../libs/video-js/src/js/media/media.js"></script>
<script src="../libs/video-js/src/js/media/html5.js"></script>
<script src="../libs/video-js/src/js/media/flash.js"></script>
<script src="../libs/video-js/src/js/media/loader.js"></script>
<script src="../libs/video-js/src/js/tracks.js"></script>
<script src="../libs/video-js/src/js/json.js"></script>
<script src="../libs/video-js/src/js/setup.js"></script>
<script src="../libs/video-js/src/js/plugins.js"></script>
<!-- HLS plugin -->
<script src="../src/video-js-hls.js"></script>
<script src="../src/h264-stream.js"></script>
<script src="../src/aac-stream.js"></script>
<script src="../src/flv-tag.js"></script>
<script src="../src/segment-parser.js"></script>
<!-- an example MPEG2-TS segment -->
<script src="tsSegment.js"></script>
<script src="video-js-hls_test.js"></script>
</head>
<body>
......
(function() {
(function(window) {
/*
======== A Handy Little QUnit Reference ========
http://api.qunitjs.com/
......@@ -19,15 +19,33 @@
notStrictEqual(actual, expected, [message])
throws(block, [expected], [message])
*/
var parser;
module('environment', {
// This will run before each test in this module.
setup: function() {
}
});
module('environment');
test('is sane', function() {
expect(1);
ok(true);
});
}());
module('segment parser', {
setup: function() {
parser = new window.videojs.hls.SegmentParser();
}
});
test('creates an flv header', function() {
var header = parser.getFlvHeader();
ok(header, 'the header is truthy');
equal(9 + 4, header.byteLength, 'the header length is correct');
equal(header[0], 'F'.charCodeAt(0), 'the signature is correct');
equal(header[1], 'L'.charCodeAt(0), 'the signature is correct');
equal(header[2], 'V'.charCodeAt(0), 'the signature is correct');
});
test('parses the first bipbop segment', function() {
parser.parseSegmentBinaryData(window.testSegment);
ok(parser.tagsAvailable(), 'tags should be available');
});
})(this);
......