Skip to content

Commit

Permalink
override media capabilities with command args
Browse files Browse the repository at this point in the history
  • Loading branch information
unclekingpin committed Nov 4, 2023
1 parent c2f1a86 commit 5fe9556
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/withStreamingServer/withStreamingServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var hat = require('hat');
var mergeWith = require('lodash.mergewith');
var cloneDeep = require('lodash.clonedeep');
var deepFreeze = require('deep-freeze');
var mediaCapabilities = require('../mediaCapabilities');
var deviceMediaCapabilities = require('../mediaCapabilities');
var convertStream = require('./convertStream');
var fetchVideoParams = require('./fetchVideoParams');
var ERROR = require('../error');
Expand Down Expand Up @@ -108,8 +108,9 @@ function withStreamingServer(Video) {
var mediaURL = result.url;
var infoHash = result.infoHash;
var fileIdx = result.fileIdx;
var mediaCapabilities = mergeWith({}, deviceMediaCapabilities, commandArgs.mediaCapabilities)
var canPlayStreamOptions = Object.assign({}, commandArgs, {
mediaCapabilities: mergeWith({}, mediaCapabilities, commandArgs.mediaCapabilities)
mediaCapabilities: mediaCapabilities
});
return (commandArgs.forceTranscoding ? Promise.resolve(false) : VideoWithStreamingServer.canPlayStream({ url: mediaURL }, canPlayStreamOptions))
.catch(function(error) {
Expand All @@ -134,14 +135,23 @@ function withStreamingServer(Video) {
queryParams.set('forceTranscoding', '1');
}

var videoCodecs = Object.keys(mediaCapabilities).reduce(function(result, format) {
return result.concat(mediaCapabilities[format].videoCodecs);
}, []);
videoCodecs.forEach(function(videoCodec) {
queryParams.append('videoCodecs', videoCodec);
});

var audioCodecs = Object.keys(mediaCapabilities).reduce(function(result, format) {
return result.concat(mediaCapabilities[format].audioCodecs);
}, []);
audioCodecs.forEach(function(audioCodec) {
queryParams.append('audioCodecs', audioCodec);
});

const maxAudioChannels = Object.keys(mediaCapabilities).reduce(function(result, format) {
return Math.max(result, mediaCapabilities[format].maxAudioChannels);
}, 2);
queryParams.set('maxAudioChannels', maxAudioChannels);

return {
Expand Down

0 comments on commit 5fe9556

Please sign in to comment.