Class: ONVIF::MediaAction::GetVideoEncoderConfiguration

Inherits:
Action
  • Object
show all
Defined in:
lib/ruby_onvif_client/media/get_video_encoder_configuration.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_node(parent_node, node_name) ⇒ Object



65
66
67
# File 'lib/ruby_onvif_client/media/get_video_encoder_configuration.rb', line 65

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

#run(c_token, cb) ⇒ Object

c_token 的结构 // [ReferenceToken] Token of the requested video encoder configuration.



7
8
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ruby_onvif_client/media/get_video_encoder_configuration.rb', line 7

def run c_token, cb
    message = create_media_onvif_message
    message.body =  ->(xml) do
        xml.wsdl(:GetVideoEncoderConfiguration) do
            xml.wsdl :ConfigurationToken, c_token
        end
    end
    send_message message do |success, result|
        if success
            xml_doc = Nokogiri::XML(result[:content])
            cfr = xml_doc.at_xpath("//trt:Configuration")
            rcl = xml_doc.at_xpath("//tt:RateControl")
            configuration = {
                name: value(xml_doc, "//tt:Name"),
                use_count: value(xml_doc, "//tt:UseCount"),
                token: attribute(cfr,"token"),
                encoding: value(xml_doc, "//tt:Encoding"),
                resolution: {
                    width: value(_get_node(xml_doc, "//tt:Resolution"), "//tt:Width"),
                    height: value(_get_node(xml_doc, "//tt:Resolution"), "//tt:Height")
                },
                quality: value(xml_doc, "//tt:Quality"),
                rateControl: {
                    frame_rate_limit: value(rcl, "tt:FrameRateLimit"),
                    encoding_interval: value(rcl, "tt:EncodingInterval"),
                    bitrate_limit: value(rcl, "tt:BitrateLimit")
                },
                multicast: {
                    address: {
                        type: value(_get_node(xml_doc, "//tt:Multicast//tt:Address"), '//tt:Type'),
                        ipv4_address: value(_get_node(xml_doc, "//tt:Multicast//tt:Address"), '//tt:IPv4Address'),
                        ipv6_address: value(_get_node(xml_doc, "//tt:Multicast//tt:Address"), '//tt:IPv6Address')
                    },
                    port: value(_get_node(xml_doc, "//tt:Multicast"), "tt:Port"),
                    ttl: value(_get_node(xml_doc, "//tt:Multicast"), "tt:TTL"),
                    auto_start: value(_get_node(xml_doc, "//tt:Multicast"), "tt:AutoStart")
                },
                session_timeout: value(xml_doc, "//tt:SessionTimeout")
            }
            unless xml_doc.at_xpath('//tt:MPEG4').nil?
                configuration[:mpeg4] = {
                    gov_length: value(_get_node(xml_doc, "//tt:MPEG4"), "//tt:GovLength"),
                    mpeg4_profile: value(_get_node(xml_doc, "//tt:MPEG4"), "//tt:Mpeg4Profile")
                }
            end
            unless xml_doc.at_xpath('//tt:H264').nil?
                configuration[:h264] = {
                    gov_length: value(_get_node(xml_doc, "//tt:H264"), "//tt:GovLength"),
                    h264_profile: value(_get_node(xml_doc, "//tt:H264"), "//tt:H264Profile")
                }
            end
            callback cb, success, configuration
        else
            callback cb, success, result
        end
    end
end