Remove duplicated code byusing a foreach. Add streamtype to returned profiles
This commit is contained in:
parent
9aa297f7cd
commit
43b776bc80
|
@ -66,7 +66,7 @@ sub deserialize_message {
|
|||
# get deserializer
|
||||
my $deserializer = $wsdl_client->get_deserializer();
|
||||
|
||||
if(! $deserializer) {
|
||||
if ( !$deserializer ) {
|
||||
$deserializer = SOAP::WSDL::Factory::Deserializer->get_deserializer({
|
||||
soap_version => $wsdl_client->get_soap_version(),
|
||||
%{ $wsdl_client->get_deserializer_args() },
|
||||
|
@ -89,7 +89,7 @@ sub deserialize_message {
|
|||
my ($success, $result_body, $result_header) = eval {
|
||||
(1, $deserializer->deserialize( $response ));
|
||||
};
|
||||
if (defined $success) {
|
||||
if ( defined $success ) {
|
||||
return wantarray
|
||||
? ($result_body, $result_header)
|
||||
: $result_body;
|
||||
|
@ -97,7 +97,6 @@ sub deserialize_message {
|
|||
return $@;
|
||||
}
|
||||
|
||||
#else
|
||||
return $deserializer->generate_fault({
|
||||
code => 'soap:Server',
|
||||
role => 'urn:localhost',
|
||||
|
@ -107,7 +106,7 @@ sub deserialize_message {
|
|||
} # end sub deserialize_message
|
||||
|
||||
sub interpret_messages {
|
||||
my ($svc_discover, $services, @responses ) = @_;
|
||||
my ( $svc_discover, $services, @responses ) = @_;
|
||||
|
||||
my @results;
|
||||
foreach my $response ( @responses ) {
|
||||
|
@ -143,19 +142,19 @@ sub interpret_messages {
|
|||
next if defined $services->{$xaddr};
|
||||
$services->{$xaddr} = 1;
|
||||
|
||||
print "$xaddr, " . $svc_discover->get_soap_version() . ", ";
|
||||
print $xaddr.', '.$svc_discover->get_soap_version().', ';
|
||||
|
||||
print "(";
|
||||
print '(';
|
||||
my $scopes = $result->get_ProbeMatch()->get_Scopes();
|
||||
my $count = 0;
|
||||
my %scopes;
|
||||
foreach my $scope(split ' ', $scopes) {
|
||||
if($scope =~ m|onvif://www\.onvif\.org/(.+)/(.*)|) {
|
||||
foreach my $scope (split ' ', $scopes) {
|
||||
if ( $scope =~ m|onvif://www\.onvif\.org/(.+)/(.*)| ) {
|
||||
my ($attr, $value) = ($1,$2);
|
||||
if( 0 < $count ++) {
|
||||
print ", ";
|
||||
if ( 0 < $count ++) {
|
||||
print ', ';
|
||||
}
|
||||
print $attr . "=\'" . $value . "\'";
|
||||
print $attr . '=\'' . $value . '\'';
|
||||
$scopes{$attr} = $value;
|
||||
}
|
||||
}
|
||||
|
@ -164,7 +163,6 @@ sub interpret_messages {
|
|||
soap_version => $svc_discover->get_soap_version(),
|
||||
scopes => \%scopes,
|
||||
};
|
||||
|
||||
}
|
||||
return @results;
|
||||
} # end sub interpret_messages
|
||||
|
@ -187,14 +185,14 @@ sub discover {
|
|||
|
||||
my $uuid_gen = Data::UUID->new();
|
||||
|
||||
if ( ( ! $soap_version ) or ( $soap_version eq '1.1' ) ) {
|
||||
foreach my $version ( $soap_version ? ( $soap_version ) : ( '1.1', '1.2') ) {
|
||||
my %services;
|
||||
|
||||
print "Probing for SOAP 1.1\n" if $verbose;
|
||||
print "Probing for SOAP $version\n" if $verbose;
|
||||
my $svc_discover = WSDiscovery10::Interfaces::WSDiscovery::WSDiscoveryPort->new({
|
||||
# no_dispatch => '1',
|
||||
});
|
||||
$svc_discover->set_soap_version('1.1');
|
||||
$svc_discover->set_soap_version($version);
|
||||
if ( $net_interface ) {
|
||||
my $transport = $svc_discover->get_transport();
|
||||
print "Setting net interface for $transport to $net_interface\n";
|
||||
|
@ -217,42 +215,8 @@ sub discover {
|
|||
print $result."\n" if $verbose;
|
||||
|
||||
push @results, interpret_messages($svc_discover, \%services, @responses);
|
||||
@responses = ();
|
||||
} # end if doing soap 1.1
|
||||
} # end foreach version
|
||||
|
||||
if ( ( ! $soap_version ) or ( $soap_version eq '1.2' ) ) {
|
||||
my %services;
|
||||
print "Probing for SOAP 1.2\n" if $verbose;
|
||||
my $svc_discover = WSDiscovery10::Interfaces::WSDiscovery::WSDiscoveryPort->new({
|
||||
# no_dispatch => '1',
|
||||
});
|
||||
$svc_discover->set_soap_version('1.2');
|
||||
if ( $net_interface ) {
|
||||
my $transport = $svc_discover->get_transport();
|
||||
print "Setting net interface for $transport to $net_interface\n";
|
||||
$transport->set_net_interface($net_interface);
|
||||
}
|
||||
|
||||
# copies of the same Probe message must have the same MessageID.
|
||||
# This is not a copy. So we generate a new uuid.
|
||||
my $uuid = $uuid_gen->create_str();
|
||||
|
||||
# Everyone else, like the nodejs onvif code and odm only ask for NetworkVideoTransmitter
|
||||
my $result = $svc_discover->ProbeOp(
|
||||
{ # WSDiscovery::Types::ProbeType
|
||||
xmlattr => { 'xmlns:dn' => 'http://www.onvif.org/ver10/network/wsdl', },
|
||||
Types => 'dn:NetworkVideoTransmitter', # QNameListType
|
||||
Scopes => { value => '' },
|
||||
},
|
||||
WSDiscovery10::Elements::Header->new({
|
||||
Action => { value => 'http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe' },
|
||||
MessageID => { value => "urn:uuid:$uuid" },
|
||||
To => { value => 'urn:schemas-xmlsoap-org:ws:2005:04:discovery' },
|
||||
})
|
||||
);
|
||||
print $result."\n" if $verbose;
|
||||
push @results, interpret_messages($svc_discover, \%services, @responses);
|
||||
} # end if doing soap 1.2
|
||||
return @results;
|
||||
} # end sub discover
|
||||
|
||||
|
@ -309,16 +273,37 @@ sub profiles {
|
|||
print "No StreamUri or no MediaUri on profile $Name of type $streamtype\n" if $verbose;
|
||||
next;
|
||||
}
|
||||
if ( $verbose ) {
|
||||
eval {
|
||||
use XML::LibXML;
|
||||
my $dom = XML::LibXML->load_xml(string=>$StreamUri);
|
||||
print "Received message:\n" . $dom->toString(1) . "\n";
|
||||
};
|
||||
}
|
||||
my $MediaUri = $StreamUri->get_MediaUri();
|
||||
if ( ! $MediaUri ) {
|
||||
if ( !$MediaUri ) {
|
||||
print "No MediaUri in profile $Name of type $streamtype\n";
|
||||
next;
|
||||
}
|
||||
if ( $verbose ) {
|
||||
eval {
|
||||
use XML::LibXML;
|
||||
my $dom = XML::LibXML->load_xml(string=>$MediaUri);
|
||||
print "Received message:\n" . $dom->toString(1) . "\n";
|
||||
};
|
||||
}
|
||||
my $Uri = $MediaUri->get_Uri();
|
||||
if ( ! $Uri ) {
|
||||
print "No Uri in profile $Name of type $streamtype\n";
|
||||
next;
|
||||
}
|
||||
if ( $verbose ) {
|
||||
eval {
|
||||
use XML::LibXML;
|
||||
my $dom = XML::LibXML->load_xml(string=>$Uri);
|
||||
print "Received message:\n" . $dom->toString(1) . "\n";
|
||||
};
|
||||
}
|
||||
my $Resolution = $VideoEncoderConfiguration->get_Resolution();
|
||||
my $Width = $Resolution ? $Resolution->get_Width() : 0;
|
||||
my $Height = $Resolution ? $Resolution->get_Height() : 0;
|
||||
|
@ -330,6 +315,7 @@ sub profiles {
|
|||
$Width,
|
||||
$Height,
|
||||
$VideoEncoderConfiguration->get_RateControl()->get_FrameRateLimit(),
|
||||
$streamtype,
|
||||
$Uri,
|
||||
];
|
||||
} # end foreach streamtype
|
||||
|
|
Loading…
Reference in New Issue