Add raw video/audio playback with ffmpeg

This commit is contained in:
Calvin Montgomery 2014-06-07 16:57:25 -07:00
commit 02771e6623
17 changed files with 428 additions and 141 deletions

View file

@ -36,7 +36,8 @@ LibraryModule.prototype.getItem = function (id, cb) {
if (err) {
cb(err, null);
} else {
cb(null, new Media(row.id, row.title, row.seconds, row.type, {}));
var meta = JSON.parse(row.meta || "{}");
cb(null, new Media(row.id, row.title, row.seconds, row.type, meta));
}
});
};

View file

@ -16,6 +16,7 @@ const DEFAULT_PERMISSIONS = {
oplaylistjump: 1.5,
oplaylistaddlist: 1.5,
playlistaddcustom: 3, // Add custom embed to the playlist
playlistaddrawfile: 2, // Add raw file to the playlist
playlistaddlive: 1.5, // Add a livestream to the playlist
exceedmaxlength: 2, // Add a video longer than the maximum length set
addnontemp: 2, // Add a permanent video to the playlist
@ -195,6 +196,10 @@ PermissionsModule.prototype.canAddCustom = function (account) {
return this.hasPermission(account, "playlistaddcustom");
};
PermissionsModule.prototype.canAddRawFile = function (account) {
return this.hasPermission(account, "playlistaddrawfile");
};
PermissionsModule.prototype.canMoveVideo = function (account) {
return this.hasPermission(account, "playlistmove");
};

View file

@ -110,9 +110,8 @@ PlaylistModule.prototype.load = function (data) {
var i = 0;
playlist.pos = parseInt(playlist.pos);
playlist.pl.forEach(function (item) {
/* Backwards compatibility */
var m = new Media(item.media.id, item.media.title, item.media.seconds,
item.media.type);
item.media.type, item.media.meta || {});
var newitem = new PlaylistItem(m, {
uid: self._nextuid++,
temp: item.temp,
@ -134,6 +133,7 @@ PlaylistModule.prototype.load = function (data) {
PlaylistModule.prototype.save = function (data) {
var arr = this.items.toArray().map(function (item) {
/* Clear Google Docs and Vimeo meta */
if (item.media && item.media.meta) {
delete item.media.meta.object;
delete item.media.meta.params;
@ -313,8 +313,11 @@ PlaylistModule.prototype.handleQueue = function (user, data) {
return;
}
/* Specifying a custom title is currently only allowed for custom media */
if (typeof data.title !== "string" || data.type !== "cu") {
/**
* Specifying a custom title is currently only allowed for custom media
* and raw files
*/
if (typeof data.title !== "string" || (data.type !== "cu" && data.type !== "fi")) {
data.title = false;
}
@ -348,6 +351,12 @@ PlaylistModule.prototype.handleQueue = function (user, data) {
link: link
});
return;
} else if (type === "fi" && !perms.canAddRawFile(user)) {
user.socket.emit("queueFail", {
msg: "You don't have permission to add raw video files",
link: link
});
return;
}
var temp = data.temp || !perms.canAddNonTemp(user);
@ -397,6 +406,7 @@ PlaylistModule.prototype.handleQueue = function (user, data) {
title: data.title,
link: link,
temp: temp,
shouldAddToLibrary: !temp,
queueby: queueby,
duration: duration,
maxlength: maxlength
@ -430,6 +440,8 @@ PlaylistModule.prototype.queueStandard = function (user, data) {
}
if (item !== null) {
/* Don't re-cache data we got from the library */
data.shouldAddToLibrary = false;
self._addItem(item, data, user, function () {
lock.release();
self.channel.activeLock.release();
@ -864,14 +876,33 @@ PlaylistModule.prototype._addItem = function (media, data, user, cb) {
});
}
/* Warn about high bitrate for raw files */
if (media.type === "fi" && media.meta.bitrate > 1000) {
user.socket.emit("queueWarn", {
msg: "This video has a bitrate over 1000kbps. Clients with slow " +
"connections may experience lots of buffering."
});
}
/* Warn about possibly unsupported formats */
if (media.type === "fi" && media.meta.codec.indexOf("/") !== -1 &&
media.meta.codec !== "mov/h264" &&
media.meta.codec !== "flv/h264") {
user.socket.emit("queueWarn", {
msg: "The codec <code>" + media.meta.codec + "</code> is not supported " +
"by all browsers, and is not supported by the flash fallback layer. " +
"This video may not play for some users."
});
}
var item = new PlaylistItem(media, {
uid: self._nextuid++,
temp: data.temp,
queueby: data.queueby
});
if (data.title && media.type === "cu") {
media.title = data.title;
if (data.title && (media.type === "cu" || media.type === "fi")) {
media.setTitle(data.title);
}
var success = function () {
@ -893,7 +924,7 @@ PlaylistModule.prototype._addItem = function (media, data, user, cb) {
u.socket.emit("setPlaylistMeta", self.meta);
});
if (!data.temp && !util.isLive(media.type)) {
if (data.shouldAddToLibrary && !util.isLive(media.type)) {
if (self.channel.modules.library) {
self.channel.modules.library.cacheMedia(media);
}