Class: ONVIF::MediaAction::GetProfile

Inherits:
Action
  • Object
show all
Defined in:
lib/ruby_onvif_client/media/get_profile.rb

Instance Method Summary collapse

Methods inherited from Action

#attribute, #callback, #create_event_onvif_message, #create_media_onvif_message, #create_ptz_onvif_message, #initialize, #send_message, #value

Constructor Details

This class inherits a constructor from ONVIF::Action

Instance Method Details

#_get_audio_encoder_configuration(parent_node) ⇒ Object



126
127
128
129
130
131
132
133
134
# File 'lib/ruby_onvif_client/media/get_profile.rb', line 126

def _get_audio_encoder_configuration parent_node
    configuration = _get_public_sector(parent_node)
    configuration[:encoding] = value(parent_node, "tt:Encoding")
    configuration[:bitrate] = value(parent_node, "tt:Bitrate")
    configuration[:sample_rate] = value(parent_node, "tt:SampleRate")
    configuration[:multicast] = _get_multicast(parent_node)
    configuration[:session_timeout] = value(parent_node, "tt:SessionTimeout")
    return configuration
end

#_get_audio_source_configuration(parent_node) ⇒ Object



90
91
92
93
94
# File 'lib/ruby_onvif_client/media/get_profile.rb', line 90

def _get_audio_source_configuration parent_node
    configuration = _get_public_sector(parent_node)
    configuration[:source_token] = value(parent_node, "tt:SourceToken")
    return configuration
end

#_get_metadata_configuration(parent_node) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/ruby_onvif_client/media/get_profile.rb', line 204

def  parent_node
    configuration = _get_public_sector(parent_node)
    configuration[:ptz_status] = {
        status: value(_get_node(parent_node, "tt:PTZStatus"), "tt:Status"),
        sosition: value(_get_node(parent_node, "tt:PTZStatus"), "tt:Position")
    }
    configuration[:events] = {
        filter: value(_get_node(parent_node, "tt:Events"), "tt:Filter"),
        subscription_policy: value(_get_node(parent_node, "tt:Events"), "tt:SubscriptionPolicy")
    }
    configuration[:analytics] = value(parent_node, "tt:Analytics")
    configuration[:multicast] = _get_multicast(parent_node)
    configuration[:session_timeout] = value(parent_node, "tt:SessionTimeout")
    unless parent_node.at_xpath("tt:AnalyticsEngineConfiguration//tt:AnalyticsModule").nil?
        analytics_module = []
        parent_node.at_xpath("tt:AnalyticsEngineConfiguration//tt:AnalyticsModule").each do |node|
            analytics_module << {
                name: attribute(node, "Name"),
                type: attribute(node, "Type"),
                parameters: _get_parameters(node)
            }
        end
        configuration[:analytics_engine_configuration] = {
            analytics_module: analytics_module,
            extension: ""
        }
    end
    configuration[:extension] = ""
    return configuration
end

#_get_min_max(xml_doc, parent_name) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/ruby_onvif_client/media/get_profile.rb', line 59

def _get_min_max xml_doc, parent_name
    this_node = xml_doc
    unless parent_name.nil?
        this_node = xml_doc.at_xpath(parent_name)
    end
    return {
        min: value(this_node, "tt:Min"),
        max: value(this_node, "tt:Max")
    }
end

#_get_multicast(parent_node) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/ruby_onvif_client/media/get_profile.rb', line 235

def _get_multicast parent_node
    {
        address: {
            type: value(_get_node(parent_node, "//tt:Multicast//tt:Address"), '//tt:Type'),
            ipv4_address: value(_get_node(parent_node, "//tt:Multicast//tt:Address"), '//tt:IPv4Address'),
            ipv6_address: value(_get_node(parent_node, "//tt:Multicast//tt:Address"), '//tt:IPv6Address')
        },
        port: value(_get_node(parent_node, "//tt:Multicast"), "tt:Port"),
        ttl: value(_get_node(parent_node, "//tt:Multicast"), "tt:TTL"),
        auto_start: value(_get_node(parent_node, "//tt:Multicast"), "tt:AutoStart")
    }
end

#_get_name(parent_node) ⇒ Object



50
51
52
# File 'lib/ruby_onvif_client/media/get_profile.rb', line 50

def _get_name parent_node
    value(parent_node, "tt:Name")
end

#_get_node(parent_node, node_name) ⇒ Object



47
48
49
# File 'lib/ruby_onvif_client/media/get_profile.rb', line 47

def _get_node parent_node, node_name
    parent_node.at_xpath(node_name)
end

#_get_parameters(parent_node) ⇒ Object



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/ruby_onvif_client/media/get_profile.rb', line 248

def _get_parameters parent_node
    simple_item = []
    element_item = []
    parent_node.at_xpath("tt:SimpleItem").each do |node|
        simple_item << {
            name: attribute(node, "Name"),
            value: attribute(node, "Value")
        }
    end
    parent_node.at_xpath("tt:ElementItem").each do |node|
        element_item << {
            xsd_any: value(node, "tt:xsd:any"),
            name:  attribute(node, "Name")
        }
    end
    return {
        simple_item: simple_item,
        element_item: element_item,
        extension: ""
    }
end

#_get_ptz_configuration(parent_node) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/ruby_onvif_client/media/get_profile.rb', line 164

def _get_ptz_configuration parent_node
    configuration = _get_public_sector(parent_node)
    configuration[:node_token] = value(parent_node, "tt:NodeToken")
    configuration[:default_absolute_pant_tilt_position_space] = value(parent_node, "tt:DefaultAbsolutePantTiltPositionSpace")
    configuration[:default_absolute_zoom_position_space] = value(parent_node, "tt:DefaultAbsoluteZoomPositionSpace")
    configuration[:default_relative_pan_tilt_translation_space] = value(parent_node, "tt:DefaultRelativePanTiltTranslationSpace")
    configuration[:default_relative_zoom_translation_space] = value(parent_node, "tt:DefaultRelativeZoomTranslationSpace")
    configuration[:default_continuous_pan_tilt_velocity_space] = value(parent_node, "tt:DefaultContinuousPanTiltVelocitySpace")
    configuration[:default_continuous_zoom_velocity_space] = value(parent_node, "tt:DefaultContinuousZoomVelocitySpace")
    pan_tilt = _get_node(parent_node,"//tt:DefaultPTZSpeed//tt:PanTilt")
    zoom = _get_node(parent_node,"//tt:DefaultPTZSpeed//tt:Zoom")
    configuration[:default_ptz_speed] = {
        pan_tilt:{
            x: attribute(pan_tilt, "x"),
            y: attribute(pan_tilt, "y"),
            space: attribute(pan_tilt, "space")
        },
        zoom: {
            x: attribute(zoom, "x"),
            space: attribute(zoom, "space")
        }
    }
    configuration[:fefault_ptz_timeout] = value(parent_node, "tt:DefaultPTZTimeout")
    configuration[:pan_tilt_limits] = {
        range: {
            uri: value(_get_node(parent_node, "tt:PanTiltLimits//tt:Range"), "tt:URI"),
            x_range: _get_min_max(_get_node(parent_node,"tt:PanTiltLimits//tt:Range"), "tt:XRange"),
            y_range: _get_min_max(_get_node(parent_node,"tt:PanTiltLimits//tt:Range"), "tt:YRange")
        }
    }
    configuration[:zoom_limits] = {
        range: {
            uri: value(_get_node(parent_node, "tt:PanTiltLimits//tt:Range"), "tt:URI"),
            x_range: _get_min_max(_get_node(parent_node,"tt:PanTiltLimits//tt:Range"), "tt:XRange"),
        }
    }
    configuration[:extension] = ""
    return configuration
end

#_get_public_sector(parent_node) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/ruby_onvif_client/media/get_profile.rb', line 69

def _get_public_sector parent_node
    {
        name: _get_name(parent_node),
        token: _get_token(parent_node),
        use_count: _get_use_count(parent_node)
    }
end

#_get_token(parent_node) ⇒ Object



56
57
58
# File 'lib/ruby_onvif_client/media/get_profile.rb', line 56

def _get_token parent_node
    attribute(parent_node, "token")
end

#_get_use_count(parent_node) ⇒ Object



53
54
55
# File 'lib/ruby_onvif_client/media/get_profile.rb', line 53

def _get_use_count parent_node
    value(parent_node, "tt:UseCount")
end

#_get_video_analytics_configuration(parent_node) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/ruby_onvif_client/media/get_profile.rb', line 136

def _get_video_analytics_configuration parent_node
    configuration = _get_public_sector(parent_node)
    analytics_module = []; rule = []
    parent_node.at_xpath("tt:AnalyticsEngineConfiguration//tt:AnalyticsModule").each do |node|
        analytics_module << {
            name: attribute(node, "Name"),
            type: attribute(node, "Type"),
            parameters: _get_parameters(node)
        }
    end
    parent_node.at_xpath("tt:AnalyticsEngineConfiguration//tt:RuleEngineConfiguration").each do |node|
        rule << {
            name: attribute(node, "Name"),
            type: attribute(node, "Type"),
            parameters: _get_parameters(node)
        }
    end
    configuration[:analytics_engine_configuration] = {
        analytics_module: analytics_module,
        extension: ""
    }
    configuration[:rule_engine_configuration] = {
        rule: rule,
        extension: ""
    }
    return configuration
end

#_get_video_encoder_configuration(parent_node) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/ruby_onvif_client/media/get_profile.rb', line 96

def _get_video_encoder_configuration parent_node
    configuration = _get_public_sector(parent_node)
    configuration[:encoding] = value(parent_node, "tt:Encoding")
    configuration[:resolution] = {
        width: value(_get_node(parent_node, "tt:Resolution"), "tt:Width"),
        height: value(_get_node(parent_node, "tt:Resolution"), "tt:Height")
    }
    configuration[:quality] = value(parent_node, "tt:Quality")
    configuration[:rate_control] = {
        frame_rate_limit: value(_get_node(parent_node, "tt:RateControl"), "tt:FrameRateLimit"),
        encoding_interval: value(_get_node(parent_node, "tt:RateControl"), "tt:EncodingInterval"),
        bitrate_limit: value(_get_node(parent_node, "tt:RateControl"), "tt:BitrateLimit")
    }
    unless parent_node.at_xpath('//tt:MPEG4').nil?
        configuration[:MPEG4] = {
            gov_length:  value(_get_node(parent_node, "tt:MPEG4"), "tt:GovLength"),
            mpeg4_profile:  value(_get_node(parent_node, "tt:MPEG4"), "tt:Mpeg4Profile")
        }
    end
    unless parent_node.at_xpath('//tt:H264').nil?
        configuration[:H264] = {
            gov_length:  value(_get_node(parent_node, "tt:H264"), "tt:GovLength"),
            h264_profile:  value(_get_node(parent_node, "tt:H264"), "tt:H264Profile")
        }
    end
    configuration[:multicast] = _get_multicast(parent_node)
    configuration[:session_timeout] = value(parent_node, "tt:SessionTimeout")
    return configuration
end

#_get_video_source_configuration(parent_node) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ruby_onvif_client/media/get_profile.rb', line 77

def _get_video_source_configuration parent_node
    configuration = _get_public_sector(parent_node)
    configuration[:source_token] = value(parent_node, "tt:SourceToken")
    bounds = parent_node.at_xpath("tt:Bounds")
    configuration[:bounds] = {
        x: attribute(bounds, "x"),
        y: attribute(bounds, "y"),
        width: attribute(bounds, "width"),
        height: attribute(bounds, "height")
    }
    return configuration
end

#run(p_token, cb) ⇒ Object

p_token 的结构

p_token //[ReferenceToken]   this command requests a specific profile


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ruby_onvif_client/media/get_profile.rb', line 9

def run p_token, cb
    message = create_media_onvif_message
    message.body = ->(xml) do
        xml.wsdl(:GetProfile) do
            xml.wsdl(:ProfileToken, p_token)
        end
    end
    send_message message do |success, result|
        if success
            xml_doc = Nokogiri::XML(result[:content])
            root_node = xml_doc.at_xpath('//trt:Profile')
            video_source = root_node.at_xpath("tt:VideoSourceConfiguration")
            audio_source = root_node.at_xpath("tt:AudioSourceConfiguration")
            video_encoder = root_node.at_xpath("tt:VideoEncoderConfiguration")
            audio_encoder = root_node.at_xpath("tt:AudioEncoderConfiguration")
            video_analytics = root_node.at_xpath("tt:VideoAnalyticsConfiguration")
            ptz = root_node.at_xpath("tt:PTZConfiguration")
             = root_node.at_xpath("tt:MetadataConfiguration")
            profile = {
                name: _get_name(root_node),
                token: _get_token(root_node),
                fixed: attribute(root_node, "fixed"),
                extension: ""
            }
            profile[:video_source_configuration] = _get_video_source_configuration(video_source) unless video_source.nil?
            profile[:audio_source_configuration] = _get_audio_source_configuration(audio_source) unless audio_source.nil?
            profile[:video_encoder_configuration] = _get_video_encoder_configuration(video_encoder) unless video_encoder.nil?
            profile[:audio_encoder_configuration] = _get_audio_encoder_configuration(audio_encoder) unless audio_encoder.nil?
            #profile[:video_analytics_configuration] = _get_video_analytics_configuration(video_analytics) unless video_analytics.nil?
            #profile[:ptz_configuration] = _get_ptz_configuration(ptz) unless ptz.nil?
            profile[:metadata_configuration] = () unless .nil?
            callback cb, success, profile
        else
            callback cb, success, result
        end
    end
end