Permalink
Browse files

Merge pull request #26 from inaes-tic/jmrunge/mvcp-driver-methods

Jmrunge/mvcp driver methods
  • Loading branch information...
2 parents ac3d5e3 + c4054ef commit 67c72b005aef91ced8bb3a7cf2c3261d647f8e30 @fabriciocosta fabriciocosta committed Apr 5, 2013
Showing with 895 additions and 116 deletions.
  1. +108 −88 drivers/mvcp/melted-node-driver.js
  2. +733 −0 drivers/mvcp/mvcp-driver-test.js
  3. +14 −17 drivers/mvcp/mvcp-driver.js
  4. +40 −11 mosto.js
@@ -11,93 +11,9 @@ function melted(host, port) {
this.mlt = new melted_node(host, port);
console.log("mbc-mosto: [INFO] Server instance created [" + this.mlt.host + ":" + this.mlt.port + "]")
- melted.prototype.playPlaylist = function(playlist, callback) {
- console.log("mbc-mosto: [INFO] Preparing xml for playlist " + playlist.name);
- var xmlFiles = [];
- playlist.medias.forEach(function(element, index, array){
- var xml = new melted_xml();
-
- var type = element.type;
- var file = element.file;
-
-// var filters = self.config.types[type].filters;
-
- console.log("mbc-mosto: [INFO] Adding file " + file);
- var video = new melted_xml.Producer.Video({source: file});
- xml.push(video);
-
- console.log("mbc-mosto: [INFO] Creating playlist xml object for file " + file);
- var pl = new melted_xml.Playlist;
- pl.entry({producer: video});
- xml.push(pl);
-
- console.log("mbc-mosto: [INFO] Creating track xml object for file " + file);
- var track = new melted_xml.Multitrack.Track(pl);
-
- console.log("mbc-mosto: [INFO] Creating multitrack xml object for file " + file);
- var multitrack = new melted_xml.Multitrack;
- multitrack.addTrack(track);
-
- console.log("mbc-mosto: [INFO] Creating tractor xml object for file " + file);
- var tractor = new melted_xml.Tractor;
- tractor.push(multitrack);
-
-// console.log("mbc-mosto: [INFO] Creating filter xml objects for file " + file);
-// console.log("mbc-mosto: [INFO] Filters: " + filters);
-// filters.forEach(function(element, index, array){
-// var filter = self.config.filters[element];
-// var filterObj = new melted_xml.Filter[filter.filter.charAt(0).toUpperCase() + filter.filter.slice(1)](filter.properties);
-// console.log("mbc-mosto: [INFO] Adding filter " + filter.filter);
-// console.log(filter.properties);
-// tractor.push(filterObj);
-// });
-
- console.log("mbc-mosto: [INFO] Pushing xml for file " + file);
- xml.push(tractor);
-
- var fileName = file.substring(file.lastIndexOf("/") + 1);
- var xmlFile = config.playlists_xml_dir + "/" + fileName + ".xml";
- xmlFiles.push(xmlFile);
-
- console.log("mbc-mosto: [INFO] Writing file " + xmlFile);
- fs.writeFile(xmlFile, xml.toString({pretty:true}), function(err){
- if (err) {
- console.error("mbc-mosto: [ERROR] " + err.toString());
- return;
- } else {
- console.log("mbc-mosto: [INFO] File ready: " + xmlFile + " at " + playlist.startDate);
- if (index === (array.length - 1))
- self.sendFiles(xmlFiles, callback);
- }
- });
- });
- };
-
- melted.prototype.sendFiles = function(xmlFiles, callback) {
- console.log("mbc-mosto: [INFO] Received files: " + xmlFiles);
- var xmlFile = xmlFiles.shift();
- if (xmlFile !== undefined) {
- console.log('mbc-mosto: [INFO] Sending file ' + xmlFile);
- self.mlt.sendCommand("apnd u0 " + xmlFile, "200 OK", function() {
- self.mlt.sendCommand("play u0", "200 OK", function() {
- self.sendFiles(xmlFiles, callback);
- }, function(error) {
- var err = new Error("mbc-mosto: [ERROR] Error playing u0 for file: " + xmlFile + " [" + error + "]");
- console.error(err);
- throw err;
- });
- }, function(error) {
- var err = new Error("mbc-mosto: [ERROR] Error appending u0 for file: " + xmlFile + " [" + error + "]");
- console.error(err);
- throw err;
- });
- } else {
- console.log('mbc-mosto: [INFO] Finish sending files');
- if (callback !== undefined) {
- console.log('mbc-mosto: [INFO] Calling callback function');
- callback();
- }
- }
+ melted.prototype.sendCommand = function(command, successCallback, errorCallback) {
+ console.log("mbc-mosto: [INFO] Sending command: " + command);
+ self.mlt.sendCommand(command, "200 OK", successCallback, errorCallback);
};
melted.prototype.getServerPlaylist = function(successCallback, errorCallback) {
@@ -143,13 +59,14 @@ function melted(host, port) {
var media = {};
var parse = split[1].split(" ");
+ media.status = parse[1];
media.file = parse[2];
media.currentFrame = parse[3];
media.fps = parse[5];
media.in = parse[6];
media.out = parse[7];
media.length = parse[8];
- media.index = parse[16]
+ media.index = parse[16];
successCallback(media);
}, function(error) {
var err = new Error("mbc-mosto: [ERROR] Error getting server status: " + error)
@@ -164,6 +81,109 @@ function melted(host, port) {
return result;
};
+ melted.prototype.sendClip = function(clip, command, successCallback, errorCallback) {
+ var xml = new melted_xml();
+
+ var type = clip.type;
+ var file = clip.file;
+
+// var filters = self.config.types[type].filters;
+
+ console.log("mbc-mosto: [INFO] Generating file " + file);
+ var video = new melted_xml.Producer.Video({source: file});
+ xml.push(video);
+
+ console.log("mbc-mosto: [INFO] Creating playlist xml object for file " + file);
+ var pl = new melted_xml.Playlist;
+ pl.entry({producer: video});
+ xml.push(pl);
+
+ console.log("mbc-mosto: [INFO] Creating track xml object for file " + file);
+ var track = new melted_xml.Multitrack.Track(pl);
+
+ console.log("mbc-mosto: [INFO] Creating multitrack xml object for file " + file);
+ var multitrack = new melted_xml.Multitrack;
+ multitrack.addTrack(track);
+
+ console.log("mbc-mosto: [INFO] Creating tractor xml object for file " + file);
+ var tractor = new melted_xml.Tractor;
+ tractor.push(multitrack);
+
+// console.log("mbc-mosto: [INFO] Creating filter xml objects for file " + file);
+// console.log("mbc-mosto: [INFO] Filters: " + filters);
+// filters.forEach(function(element, index, array){
+// var filter = self.config.filters[element];
+// var filterObj = new melted_xml.Filter[filter.filter.charAt(0).toUpperCase() + filter.filter.slice(1)](filter.properties);
+// console.log("mbc-mosto: [INFO] Adding filter " + filter.filter);
+// console.log(filter.properties);
+// tractor.push(filterObj);
+// });
+
+ console.log("mbc-mosto: [INFO] Pushing xml for file " + file);
+ xml.push(tractor);
+
+ var fileName = file.substring(file.lastIndexOf("/") + 1);
+ var xmlFile = config.playlists_xml_dir + "/" + fileName + ".xml";
+
+ console.log("mbc-mosto: [INFO] Writing file " + xmlFile);
+ fs.writeFile(xmlFile, xml.toString({pretty:true}), function(err){
+ if (err) {
+ errorCallback(err);
+ } else {
+ console.log("mbc-mosto: [INFO] File ready: " + xmlFile);
+ self.sendCommand(command.replace("{xmlFile}", xmlFile), successCallback, errorCallback);
+ }
+ });
+ };
+
+ melted.prototype.loadClip = function(clip, successCallback, errorCallback) {
+ //Load clip removing the whole playlist and starting playback
+ self.sendClip(clip, "LOAD U0 {xmlFile}", successCallback, errorCallback);
+ };
+ melted.prototype.appendClip = function(clip, successCallback, errorCallback) {
+ //Appends clip to the end of the playlist
+ self.sendClip(clip, "APND UO {xmlFile}", successCallback, errorCallback);
+ };
+ melted.prototype.insertClip = function(clip, index, successCallback, errorCallback) {
+ //Insert clip at specified index
+ self.sendClip(clip, "INSERT UO {xmlFile} " + index, successCallback, errorCallback);
+ };
+ melted.prototype.removeClip = function(index, successCallback, errorCallback) {
+ //Removes clip at specified index
+ self.sendCommand("REMOVE U0 " + index, successCallback, errorCallback);
+ };
+ melted.prototype.cleanPlaylist = function(successCallback, errorCallback) {
+ //Removes all clips but playing clip
+ self.sendCommand("CLEAN U0", successCallback, errorCallback);
+ };
+// melted.prototype.wipePlaylist = function(successCallback, errorCallback) {
+// //Removes all clips before playing clip
+// self.sendCommand("WIPE U0", successCallback, errorCallback);
+// };
+ melted.prototype.clearPlaylist = function(successCallback, errorCallback) {
+ //Removes all clips, including playing clip
+ self.sendCommand("CLEAR U0", successCallback, errorCallback);
+ };
+ melted.prototype.moveClip = function(oldIndex, newIndex, successCallback, errorCallback) {
+ //Moves the clip at oldIndex to newIndex (use it with getServerPlaylist)
+ self.sendCommand("MOVE U0 " + oldIndex + " " + newIndex, successCallback, errorCallback);
+ };
+ melted.prototype.play = function(successCallback, errorCallback) {
+ //Play
+ self.sendCommand("PLAY U0", successCallback, errorCallback);
+ };
+ melted.prototype.stop = function(successCallback, errorCallback) {
+ //Stop
+ self.sendCommand("STOP U0", successCallback, errorCallback);
+ };
+ melted.prototype.pause = function(successCallback, errorCallback) {
+ //Pause
+ self.sendCommand("PAUSE U0", successCallback, errorCallback);
+ };
+ melted.prototype.goto = function(index, frame, successCallback, errorCallback) {
+ //Starts playing clip at specified index and frame (use with getServerPlaylist and getServerStatus)
+ self.sendCommand("GOTO U0 " + frame + " " + index, successCallback, errorCallback);
+ };
}
exports = module.exports = function(host, port) {
Oops, something went wrong.

0 comments on commit 67c72b0

Please sign in to comment.