Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

media2 support for videoencoders #339

Merged
merged 3 commits into from
Oct 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions lib/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
service: service
, body: this._envelopeHeader() +
(
(options) ?
(
'<GetVideoEncoderConfigurationOptions xmlns="http://www.onvif.org/ver10/media/wsdl">' +
`<GetVideoEncoderConfigurationOptions xmlns="${xmlns}">` +
(
(options.configurationToken)
? '<ConfigurationToken>' + options.configurationToken + '</ConfigurationToken>'
Expand All @@ -323,7 +325,7 @@ module.exports = function(Cam) {
) +
'</GetVideoEncoderConfigurationOptions>'
)
: '<GetVideoEncoderConfigurationOptions xmlns="http://www.onvif.org/ver10/media/wsdl" />'
: `<GetVideoEncoderConfigurationOptions xmlns="${xmlns}">`
) +
this._envelopeFooter()
}, function(err, data, xml) {
Expand All @@ -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() +
'<GetVideoEncoderConfigurations xmlns="http://www.onvif.org/ver10/media/wsdl"/>' +
`<GetVideoEncoderConfigurations xmlns="${xmlns}"/>` +
this._envelopeFooter()
}, function(err, data, xml) {
if (!err) {
Expand Down Expand Up @@ -392,11 +397,16 @@ 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';
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: 'media',
service: service,
body: this._envelopeHeader() +
'<SetVideoEncoderConfiguration xmlns="http://www.onvif.org/ver10/media/wsdl">' +
'<Configuration token = "' + (options.token || options.$.token) + '">' +
`<SetVideoEncoderConfiguration xmlns="${xmlns}">` +
`<Configuration token="${options.token || options.$.token}"` + (media2GovLength ? ` GovLength="${media2GovLength}"` : '') + (media2Profile ? ` Profile="${media2Profile}"` : '') + '>' +
( options.name ? '<Name xmlns="http://www.onvif.org/ver10/schema">' + options.name + '</Name>' : '' ) +
( options.useCount ? '<UseCount xmlns="http://www.onvif.org/ver10/schema">' + options.useCount + '</UseCount>' : '' ) +
( options.encoding ? '<Encoding xmlns="http://www.onvif.org/ver10/schema">' + options.encoding + '</Encoding>' : '' ) +
Expand All @@ -407,7 +417,7 @@ module.exports = function(Cam) {
'</Resolution>' : '') +
( options.quality ? '<Quality xmlns="http://www.onvif.org/ver10/schema">' + options.quality + '</Quality>' : '' ) +
( options.rateControl ?
'<RateControl xmlns="http://www.onvif.org/ver10/schema">' +
`<RateControl ConstantBitRate="${ConstantBitRate}" xmlns="http://www.onvif.org/ver10/schema"> ` +
( options.rateControl.frameRateLimit ? '<FrameRateLimit>' + options.rateControl.frameRateLimit + '</FrameRateLimit>' : '' ) +
( options.rateControl.encodingInterval ? '<EncodingInterval>' + options.rateControl.encodingInterval + '</EncodingInterval>' : '' ) +
( options.rateControl.bitrateLimit ? '<BitrateLimit>' + options.rateControl.bitrateLimit + '</BitrateLimit>' : '' ) +
Expand Down Expand Up @@ -440,7 +450,7 @@ module.exports = function(Cam) {
options.sessionTimeout +
'</SessionTimeout>' : '' ) +
'</Configuration>' +
'<ForcePersistence>true</ForcePersistence>' +
(!this.media2Support ? '<ForcePersistence>true</ForcePersistence>' : '') +
'</SetVideoEncoderConfiguration>' +
this._envelopeFooter()
}, function(err, data, xml) {
Expand All @@ -450,7 +460,7 @@ 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));
};

Expand Down