From 09747188041fe653c0f34f63fb6f6f63d90924b5 Mon Sep 17 00:00:00 2001 From: amcharhal mohamed Date: Fri, 25 Oct 2024 05:52:34 -0400 Subject: [PATCH 1/3] Added Media2 support for the following functions: GetVideoEncoderConfigurations and GetVideoEncoderConfigurationOptions SetVideoEncoderConfiguration --- lib/media.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/media.js b/lib/media.js index 02967f7..c5e25ca 100644 --- a/lib/media.js +++ b/lib/media.js @@ -304,13 +304,15 @@ module.exports = function(Cam) { } else if (!(options && (options.configurationToken || options.profileToken))) { return callback(new Error("'options' must have one or both 'configurationToken' or 'profileToken'")); } + const service = this.media2Support ? 'media2' : 'media'; + const xmlns = this.media2Support? 'http://www.onvif.org/ver20/media/wsdl': 'http://www.onvif.org/ver10/media/wsdl'; this._request({ service: 'media' , body: this._envelopeHeader() + ( (options) ? ( - '' + + `` + ( (options.configurationToken) ? '' + options.configurationToken + '' @@ -323,7 +325,7 @@ module.exports = function(Cam) { ) + '' ) - : '' + : `` ) + this._envelopeFooter() }, function(err, data, xml) { @@ -338,10 +340,13 @@ module.exports = function(Cam) { * @param {Cam~VideoEncoderConfigurationsCallback} callback */ Cam.prototype.getVideoEncoderConfigurations = function(callback) { + + const service = this.media2Support ? 'media2' : 'media'; + const xmlns = this.media2Support? 'http://www.onvif.org/ver20/media/wsdl': 'http://www.onvif.org/ver10/media/wsdl'; this._request({ - service: 'media' + service: service , body: this._envelopeHeader() + - '' + + `` + this._envelopeFooter() }, function(err, data, xml) { if (!err) { @@ -392,11 +397,13 @@ module.exports = function(Cam) { if (!options.token && !(options.$ && options.$.token)) { return callback(new Error('No video encoder configuration token is present!')); } + const service = this.media2Support ? 'media2' : 'media'; + const xmlns = this.media2Support? 'http://www.onvif.org/ver20/media/wsdl': 'http://www.onvif.org/ver10/media/wsdl'; this._request({ - service: 'media', + service: service, body: this._envelopeHeader() + - '' + - '' + + ``+ + `' + ( options.name ? '' + options.name + '' : '' ) + ( options.useCount ? '' + options.useCount + '' : '' ) + ( options.encoding ? '' + options.encoding + '' : '' ) + @@ -407,7 +414,7 @@ module.exports = function(Cam) { '' : '') + ( options.quality ? '' + options.quality + '' : '' ) + ( options.rateControl ? - '' + + ` ` + ( options.rateControl.frameRateLimit ? '' + options.rateControl.frameRateLimit + '' : '' ) + ( options.rateControl.encodingInterval ? '' + options.rateControl.encodingInterval + '' : '' ) + ( options.rateControl.bitrateLimit ? '' + options.rateControl.bitrateLimit + '' : '' ) + @@ -440,7 +447,7 @@ module.exports = function(Cam) { options.sessionTimeout + '' : '' ) + '' + - 'true' + + (!this.media2Support?'true':'') + '' + this._envelopeFooter() }, function(err, data, xml) { @@ -450,7 +457,10 @@ module.exports = function(Cam) { : err, data, xml); } //get new encoding settings from device - this.getVideoEncoderConfiguration(options.token || options.$.token, callback); + if(!this.media2Support) + this.getVideoEncoderConfiguration(options.token || options.$.token, callback); + else + this.getVideoEncoderConfigurations( callback); }.bind(this)); }; From e08f5d622916aa79264a509ab150e117f6c0c76c Mon Sep 17 00:00:00 2001 From: amcharhal mohamed Date: Fri, 25 Oct 2024 06:10:13 -0400 Subject: [PATCH 2/3] fix eslint errors --- lib/media.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/media.js b/lib/media.js index c5e25ca..3402b25 100644 --- a/lib/media.js +++ b/lib/media.js @@ -305,9 +305,9 @@ module.exports = function(Cam) { return callback(new Error("'options' must have one or both 'configurationToken' or 'profileToken'")); } const service = this.media2Support ? 'media2' : 'media'; - const xmlns = this.media2Support? 'http://www.onvif.org/ver20/media/wsdl': 'http://www.onvif.org/ver10/media/wsdl'; + const xmlns = this.media2Support ? 'http://www.onvif.org/ver20/media/wsdl' : 'http://www.onvif.org/ver10/media/wsdl'; this._request({ - service: 'media' + service: service , body: this._envelopeHeader() + ( (options) ? @@ -342,7 +342,7 @@ module.exports = function(Cam) { Cam.prototype.getVideoEncoderConfigurations = function(callback) { const service = this.media2Support ? 'media2' : 'media'; - const xmlns = this.media2Support? 'http://www.onvif.org/ver20/media/wsdl': 'http://www.onvif.org/ver10/media/wsdl'; + const xmlns = this.media2Support ? 'http://www.onvif.org/ver20/media/wsdl' : 'http://www.onvif.org/ver10/media/wsdl'; this._request({ service: service , body: this._envelopeHeader() + @@ -398,12 +398,13 @@ module.exports = function(Cam) { return callback(new Error('No video encoder configuration token is present!')); } const service = this.media2Support ? 'media2' : 'media'; - const xmlns = this.media2Support? 'http://www.onvif.org/ver20/media/wsdl': 'http://www.onvif.org/ver10/media/wsdl'; + const xmlns = this.media2Support ? 'http://www.onvif.org/ver20/media/wsdl' : 'http://www.onvif.org/ver10/media/wsdl'; + const ConstantBitRate = (options.rateControl && options.rateControl.$ && options.rateControl.$.ConstantBitRate) || false; this._request({ service: service, body: this._envelopeHeader() + - ``+ - `' + + `` + + `' + ( options.name ? '' + options.name + '' : '' ) + ( options.useCount ? '' + options.useCount + '' : '' ) + ( options.encoding ? '' + options.encoding + '' : '' ) + @@ -414,7 +415,7 @@ module.exports = function(Cam) { '' : '') + ( options.quality ? '' + options.quality + '' : '' ) + ( options.rateControl ? - ` ` + + ` ` + ( options.rateControl.frameRateLimit ? '' + options.rateControl.frameRateLimit + '' : '' ) + ( options.rateControl.encodingInterval ? '' + options.rateControl.encodingInterval + '' : '' ) + ( options.rateControl.bitrateLimit ? '' + options.rateControl.bitrateLimit + '' : '' ) + @@ -447,7 +448,7 @@ module.exports = function(Cam) { options.sessionTimeout + '' : '' ) + '' + - (!this.media2Support?'true':'') + + (!this.media2Support ? 'true' : '') + '' + this._envelopeFooter() }, function(err, data, xml) { @@ -457,10 +458,7 @@ module.exports = function(Cam) { : err, data, xml); } //get new encoding settings from device - if(!this.media2Support) - this.getVideoEncoderConfiguration(options.token || options.$.token, callback); - else - this.getVideoEncoderConfigurations( callback); + if (!this.media2Support) {this.getVideoEncoderConfiguration(options.token || options.$.token, callback);} else {this.getVideoEncoderConfigurations( callback);} }.bind(this)); }; From 4ac58bf3531f164a80338ef3ee33e6b918984c33 Mon Sep 17 00:00:00 2001 From: amcharhal mohamed Date: Fri, 25 Oct 2024 06:23:55 -0400 Subject: [PATCH 3/3] fix tests --- lib/media.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/media.js b/lib/media.js index 3402b25..01b9097 100644 --- a/lib/media.js +++ b/lib/media.js @@ -400,11 +400,13 @@ module.exports = function(Cam) { const service = this.media2Support ? 'media2' : 'media'; const xmlns = this.media2Support ? 'http://www.onvif.org/ver20/media/wsdl' : 'http://www.onvif.org/ver10/media/wsdl'; const ConstantBitRate = (options.rateControl && options.rateControl.$ && options.rateControl.$.ConstantBitRate) || false; + const media2GovLength = (options.$ && options.$.GovLength) || undefined; + const media2Profile = (options.$ && options.$.Profile) || undefined; this._request({ service: service, body: this._envelopeHeader() + `` + - `' + + `' + ( options.name ? '' + options.name + '' : '' ) + ( options.useCount ? '' + options.useCount + '' : '' ) + ( options.encoding ? '' + options.encoding + '' : '' ) +