Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

prepping transcoder

  • Loading branch information...
commit 236d86e8cd7e73b67770563ab9e12d6b91935851 1 parent 8be3601
@benvanik authored
Showing with 61 additions and 0 deletions.
  1. +8 −0 api.js
  2. +27 −0 transcoder.js
  3. +26 −0 transcoderlist.js
View
8 api.js
@@ -30,6 +30,8 @@ var API = function(port) {
self.dispatchDeviceDefaultRequest(req, requestBody, res);
} else if (req.url.indexOf('/device/') == 0) {
self.dispatchDeviceRequest(req, requestBody, res);
+ } else if (req.url.indexOf('/content/') == 0) {
+ self.dispatchContentRequest(req, requestBody, res);
} else {
res.writeHead(404, 'Invalid URL format');
res.end();
@@ -95,3 +97,9 @@ API.prototype.dispatchDeviceRequest = function(req, requestBody, res) {
res.end();
}
};
+
+API.prototype.dispatchContentRequest = function(req, requestBody, res) {
+ var requestObject = requestBody.length ? JSON.parse(requestBody) : {};
+
+ // TODO: content requests
+};
View
27 transcoder.js
@@ -0,0 +1,27 @@
+var events = require('events');
+var util = require('util');
+
+var Transcoder = function(source, target) {
+ this.source = source;
+ this.target = target;
+};
+util.inherits(Transcoder, events.EventEmitter);
+
+var NullTranscoder = function(source, target) {
+ Transcoder.call(this, source, target);
+};
+util.inherits(NullTranscoder, Transcoder);
+
+NullTranscoder.canTranscode = function(sourceMimeType, targetMimeType) {
+ // Identity
+ if (sourceMimeType == targetMimeType) {
+ return true;
+ }
+ return false;
+};
+
+// Order is highest to lowest priority
+exports.transcoderTypes = [
+ FfmpegTranscoder,
+ NullTranscoder
+];
View
26 transcoderlist.js
@@ -0,0 +1,26 @@
+var transcoderTypes = require('./transcoder').transcoderTypes;
+
+var TranscoderList = function() {
+ this.transcoderTypes_ = transcoderTypes.slice();
+};
+exports.TranscoderList = TranscoderList;
+
+TranscoderList.prototype.find_ = function(sourceMimeType, targetMimeType) {
+ for (var n = 0; n < this.transcoderTypes_.length; n++) {
+ var transcoderType = this.transcoderTypes_[n];
+ if (transcoderType.canTranscode(sourceMimeType, targetMimeType)) {
+ return transcoderType;
+ }
+ }
+ return null;
+};
+
+TranscoderList.prototype.createTranscoder = function(source, target) {
+ var transcoderType = this.find_(source.mimeType, target.mimeType);
+ if (!transcoderType) {
+ return false;
+ }
+ var transcoder = new transcoderType(source, target);
+ // TODO: verify?
+ return transcoder;
+};
Please sign in to comment.
Something went wrong with that request. Please try again.