agsh / onvif

ONVIF node.js implementation
http://agsh.github.io/onvif/
MIT License
693 stars 236 forks source link

Improve `getAudioEncoderConfigurationOptions`. #150

Open bl0ggy opened 4 years ago

bl0ggy commented 4 years ago

Permit to get an AudioEncoderConfigurationOption with either a ConfigurationToken, a ProfileToken or both as first argument. Update JSDoc.

This breaks backward compatibility. But I wonder, I updated the response XML file because with the cameras I have (Samsung and HIK Vision), it's very different. First, there are tt:Options tags inside the trt:Options tag, second, the elements in lists are not tt:List but tt:Items. Did the structure change over years ? Are there cameras still responding the old way ? If that's the case, we will have to convert one structure into the other.

coveralls commented 4 years ago

Coverage Status

Coverage increased (+0.02%) to 87.929% when pulling f89f99287c5291f782f6025773e8b9ef67d431a9 on bl0ggy:improve_getAudioEncoderConfigurationOptions into f8ee914a9f5a8cab0acdb70f4efb0e4d0f56836f on agsh:master.

RogerHardiman commented 4 years ago

Did the structure change over the years.....

Yes the structure did change. Originally we had the Media Service https://www.onvif.org/ver10/media/wsdl/media.wsdl

Now we also have Media2 (Media Service Version 2.0 and the URL has ver20 in it) https://www.onvif.org/ver20/media/wsdl/media.wsdl

So we need to check if a camera uses Media1 or Media2 and then parse the XML differently depending on which Media Service (media 1 or media 2) the camera supports.

RogerHardiman commented 4 years ago

Just to add some extra info. In the original ONVIF spec we had to get the System Date and Time and then call GetCapabilities to get the URLs for each 'Service' (media, imaging, PTZ, device etc) The ONVIF Library's constructor does this as shown below (from cam.js)

/**

  • Connect to the camera and fill device information properties
  • @param {Cam~ConnectionCallback} callback */ Cam.prototype.connect = function(callback) {

    // Must execute getSystemDataAndTime (and wait for callback)
    
    this.getSystemDateAndTime(function(err, date, xml) {
            if (err) {
                    return callback.call(this, err, null, xml);
            }
            this.getCapabilities(function(err, data, xml) {

If you read the latest ONVIF Core Specification it says we are supposed to call getSystemDateAndTime and then call GetServices

The old GetCapabilities ONVIF command is now deprecated and left in for backwards compatibility.

8.1.2.4 GetCapabilities This method provides a backward compatible interface for the base capabilities. Refer to GetServices for a full set of capabilities.

So actually there is a larger issue here. What we need the ONVIF library to do is a) getSystemDateAndTime b) try GetServices. If it works we will know if we are using Media1 or Media2 c) if GetServices fails, we need to fall back to GetCapabilities

So before we can implement this PR we need to fix some other things in the library.

Let me know if you need any more info.

Roger

RogerHardiman commented 4 years ago

Hi. Just a reminder you need to modify the commit to handle 'media' and 'media2' as the APIs are different.

bl0ggy commented 4 years ago

I have a few questions.

RogerHardiman commented 4 years ago

Old ONVIF used the GetCapabilities command to get the ONVIF Services like device and media.

New ONVIF uses the GetServices command to get the Device Services like Media2.

So first step is to edit the library when it first connects to the camera. You need to try Get Services first and fail back to GetCapabilities. If GetServices works you can check if it reports Media or Media2 support.

You need to set a global flag for the class and use it to decide what format XML to send.

Roger

RogerHardiman commented 3 years ago

Hi @bl0ggy . Do you still have access to your Samsung and Hik cameras?

RogerHardiman commented 3 years ago

Hi Jessy, I've made use of your changes to detect Media2 in my 'roger' branch on github. You can now use this to create a Media2 specific version of getAutioEncoderConfigurationOptions that handles the different XML format.

For getProfiles, getStreamUri and getSnapshotUri I made the function handle media1 and media2 and I modified the result so Media2 results look like Media1 results. But your suggestion of having functionNameV2() with V2 added is a good idea.

Roger

bl0ggy commented 3 years ago

Hi @RogerHardiman, yes I still have access to some Samsung cameras and at least one Hik. Unfortunately I don't have much time for that, but I have a coworker who may be able to do it. We will keep you informed.

RogerHardiman commented 2 years ago

@bl0ggy . Just wanted to let you know that in the summer I added code to detect Media API and Media2 API for video. So we could re-visit your code for parsing the Audio Sources

agsh commented 2 years ago

@RogerHardiman I saw your improvements and tried to copy them to the typescript version. So, what to do you think now?