WIP Merging basic player to master #6

Merged
blue merged 17 commits from player into master 2019-02-01 22:32:52 +00:00
13 changed files with 11711 additions and 41 deletions
Showing only changes of commit 22323b504f - Show all commits

View File

@ -59,21 +59,13 @@ void M::Audio::h_requestFrames(const W::Event& ev)
evc->insert(u"result", new W::Uint64(1));
} else {
evc->insert(u"result", new W::Uint64(0));
uint64_t start = 0;
uint64_t size = 0;
bool first = true;
W::Vector* vframes = new W::Vector();
for (int i = 0; i < amount; ++i) {
const std::pair<uint64_t, uint64_t>& pair = frames[index + i];
if (first) {
start = pair.first;
first = false;
}
size += pair.second;
const std::pair<uint64_t, uint64_t>& pair = frames[index + i]; //TODO optimize?
vframes->push(file->slice(pair.first, pair.second));
}
evc->insert(u"data", file->slice(start, size));
evc->insert(u"amount", new W::Uint64(amount));
evc->insert(u"frames", vframes);
}
response(evc, W::Address{u"responseFrames"}, ev);

View File

@ -2,6 +2,7 @@
var File = require("./file");
var Vocabulary = require("../../wType/vocabulary");
var Vector = require("../../wType/vector");
var Uint64 = require("../../wType/uint64");
var Audio = File.inherit({
@ -12,10 +13,15 @@ var Audio = File.inherit({
this._loadedFrames = 0;
this._totalFrames = 0;
this._waitingForFrames = false;
this._portions = [];
this._frames = new Vector();
this.addHandler("responseFrames");
},
destructor: function() {
this._frames.destructor();
File.fn.destructor.call(this);
},
hasMore: function() {
return this._totalFrames > this._loadedFrames;
},
@ -37,12 +43,25 @@ var Audio = File.inherit({
var success = data.at("result").valueOf();
if (success === 0) {
var amount = data.at("amount").valueOf();
var blob = data.at("data").clone();
var frames = data.at("frames");
var amount = frames.length();
var buffer = new ArrayBuffer(0);
for (var i = 0; i < amount; ++i) {
var blob = frames.at(i).clone();
this._frames.push(blob);
var frame = blob.valueOf();
var newArr = new Uint8Array(buffer.byteLength + frame.byteLength);
newArr.set(new Uint8Array(buffer), 0);
newArr.set(new Uint8Array(frame), buffer.byteLength);
buffer = newArr.buffer;
}
this._loadedFrames += amount;
this._waitingForFrames = false;
this._portions.push(blob);
this.trigger("newFrames", blob);
this.trigger("newFrames", buffer);
}
}
},

View File

@ -12,6 +12,12 @@ var Audio = require("./file/audio");
var Enum = require("../utils/enum");
var StateMachine = require("../utils/stateMachine");
var Source = AV.EventEmitter.extend(function() {
this.prototype.start = function(){}
this.prototype.pause = function(){}
this.prototype.reset = function(){}
});
var Player = Controller.inherit({
className: "Player",
constructor: function(addr) {
@ -21,11 +27,11 @@ var Player = Controller.inherit({
this.views = Object.create(null);
this.mode = PlayerMode.straight.playback;
this._audio = null;
this._sound = new window.Audio();
this._ctx = new AudioContext();
this._currentTime = 0;
this._source = new Source();
this._asset = new AV.Asset(this._source);
this._player = new AV.Player(this._asset);
this._player.play();
this._createStateMachine();
this._proxySchedule = this._schedule.bind(this);
this.addHandler("get");
this.addHandler("viewsChange");
@ -34,8 +40,7 @@ var Player = Controller.inherit({
},
destructor: function() {
this._fsm.destructor();
this._sound.pause();
this._ctx.close();
this._player.stop();
Controller.fn.destructor.call(this);
},
@ -140,7 +145,7 @@ var Player = Controller.inherit({
this.trigger("data");
},
_h_pause: function(ev) {
this._fsm.manipulation("plause");
this._fsm.manipulation("pause");
},
_h_play: function(ev) {
this._fsm.manipulation("play");
@ -164,7 +169,9 @@ var Player = Controller.inherit({
}
},
_onAudioNewFrames: function(frames) {
this._ctx.decodeAudioData(frames.valueOf(), this._proxySchedule);
var data = new Uint8Array(frames);
this._source.emit("data", new AV.Buffer(data));
this._fsm.manipulation("newFrames");
if (this._audio.hasMore()) {
this._audio.requestMore();
@ -218,24 +225,24 @@ var Player = Controller.inherit({
case "paused":
switch (e.oldState) {
case "playing":
this._sound.pause();
this._player.pause();
break;
}
break;
case "pausedAllLoaded":
switch (e.oldState) {
case "playingAllLoaded":
this._sound.pause();
this._player.pause();
break;
}
break;
case "playing":
this._sound.play();
this._player.play();
break;
case "playingAllLoaded":
switch (e.oldState) {
case "pausedAllLoaded":
this._sound.play();
this._player.play();
break;
}
break;
@ -246,14 +253,6 @@ var Player = Controller.inherit({
},
_removeView: function(type) {
//TODO
},
_schedule: function(buffer) {
var source = this._ctx.createBufferSource();
source.buffer = buffer;
source.connect(this._ctx.destination);
source.start(this._currentTime);
this._currentTime += buffer.duration;
}
});
@ -294,7 +293,7 @@ graphs[PlayerMode.straight.playback] = {
play: "playingAllLoaded"
},
"playing": {
pause: "pause",
pause: "paused",
noMoreFrames: "playingAllLoaded"
},
"playingAllLoaded": {

View File

@ -45,7 +45,7 @@ var Vocabulary = Controller.inherit({
var keys = insert.getKeys();
for (var j = 0; j < keys.length; ++j) {
key = keys[i];
key = keys[j];
this.addElement(key, insert.at(key).clone());
}
this.trigger("change", data.clone());

View File

@ -10,4 +10,4 @@
<body>
<p>I am</p>
</body>
</html>
</html>

View File

@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 2.8.12)
add_subdirectory(requirejs)
add_subdirectory(wSocket)
add_subdirectory(bintrees)
add_subdirectory(mp3)
add_subdirectory(aurora)
add_subdirectory(wContainer)
add_subdirectory(utils)
add_subdirectory(wType)

View File

@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 2.8.12)
configure_file(aurora.js aurora.js)

3938
lorgar/lib/aurora/aurora.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,3 @@
cmake_minimum_required(VERSION 2.8.12)
configure_file(index.js index.js)
configure_file(index.js index.js)

View File

@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 2.8.12)
configure_file(mp3.js mp3.js)

7706
lorgar/lib/mp3/mp3.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,11 @@
"use strict";
(function main_js() {
requirejs.config({
"baseUrl": "/",
"shim": {
"lib/mp3/mp3": ["lib/aurora/aurora"]
}
});
requirejs.onError = function(e) {
throw e;
}
@ -8,6 +14,7 @@
defineArray.push("test/test");
defineArray.push("core/lorgar");
defineArray.push("lib/utils/globalMethods");
defineArray.push("lib/mp3/mp3");
require(defineArray, function main_module() {
require("lib/utils/globalMethods");

View File

@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 2.8.12)
project(test)
find_package(CxxTest)
cmake_policy(SET CMP0071 NEW)
if(CXXTEST_FOUND)
include_directories(${CXXTEST_INCLUDE_DIR})
enable_testing()