sonycam 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sonycam/device_description.rb +24 -22
- data/lib/sonycam/liveview.rb +41 -39
- data/lib/sonycam/packet.rb +27 -25
- data/lib/sonycam/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 267685466ea2942f1aaeb2de7a06390c6755a25a
|
4
|
+
data.tar.gz: 6324ddf7763fe498cf7a574a243fb7dffa8eab20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db15ae7fe31a6432daf7ecdfe2369903ac0a26233fead4e5cc8abdda1a892553c6e55802e4c2ca6f396e22d50464d9d2eed64d1d738581b3b65e8744c7fdaae4
|
7
|
+
data.tar.gz: 9b2e817e2e67beea7f2691ecf773f295214077e398156cba48aac6ab47e0142e31c86f937bbba0661bdf3db7464fd4c94c133eaf20aac57104106e620d8a9b41
|
@@ -1,32 +1,34 @@
|
|
1
1
|
require 'nokogiri'
|
2
2
|
require 'open-uri'
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
module Sonycam
|
5
|
+
class DeviceDescription
|
6
|
+
attr_reader :doc
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
# document: String or Nokogiri::XML::Node
|
9
|
+
def initialize document
|
10
|
+
@doc = Nokogiri::XML(open(document))
|
11
|
+
@camera_name = @doc.at_xpath('//xmlns:friendlyName').content
|
12
|
+
@api_url_hash = {}
|
13
|
+
@doc.xpath('//av:X_ScalarWebAPI_Service', av: 'urn:schemas-sony-com:av').each do |node|
|
14
|
+
type = node.at_xpath('av:X_ScalarWebAPI_ServiceType', av: 'urn:schemas-sony-com:av').content
|
15
|
+
url = node.at_xpath('av:X_ScalarWebAPI_ActionList_URL', av: 'urn:schemas-sony-com:av').content
|
16
|
+
@api_url_hash[type.to_sym] = url
|
17
|
+
end
|
16
18
|
end
|
17
|
-
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
# type: :camera, :system, :guide
|
21
|
+
def api_url type = :camera
|
22
|
+
# Hush, it's a secret, don't tell anyone.
|
23
|
+
if @camera_name == 'DSC-RX100M2'
|
24
|
+
url = @api_url_hash[type].sub('sony', 'camera')
|
25
|
+
puts "DSC-RX100M2 detected, API URL \"#{url}\" was used insteadly."
|
26
|
+
return url
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
29
|
+
if action_list_url = @api_url_hash[type] then "#{action_list_url}/#{type}"
|
30
|
+
else raise "Can't not find service type \"#{type}\"."
|
31
|
+
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
data/lib/sonycam/liveview.rb
CHANGED
@@ -1,42 +1,44 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'sonycam/packet'
|
3
3
|
|
4
|
-
module
|
5
|
-
|
6
|
-
|
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
|
-
end #
|
4
|
+
module Sonycam
|
5
|
+
module Liveview
|
6
|
+
extend self
|
7
|
+
def stream liveview_url
|
8
|
+
uri = URI(liveview_url)
|
9
|
+
Net::HTTP.start(uri.host, uri.port) do |http|
|
10
|
+
request = Net::HTTP::Get.new uri
|
11
|
+
http.request request do |response|
|
12
|
+
state = :commen_header
|
13
|
+
buf = ''.force_encoding('BINARY')
|
14
|
+
commen_header = nil
|
15
|
+
payload_header = nil
|
16
|
+
response.read_body do |chunk|
|
17
|
+
buf += chunk
|
18
|
+
until buf.empty?
|
19
|
+
case state
|
20
|
+
when :commen_header # 8 bytes
|
21
|
+
break if buf.size < 8
|
22
|
+
commen_header = buf.slice!(0, 8).unpack('H2CnN')
|
23
|
+
state = :payload_header
|
24
|
+
when :payload_header # 128 bytes
|
25
|
+
break if buf.size < 128
|
26
|
+
payload_header = buf.slice!(0, 128).unpack('H8H6CH8CH*')
|
27
|
+
state = :payload_data
|
28
|
+
when :payload_data
|
29
|
+
jpeg_data_size = payload_header[1].to_i(16)
|
30
|
+
padding_size = payload_header[2]
|
31
|
+
break if buf.size < jpeg_data_size + padding_size
|
32
|
+
jpeg_data = buf.slice!(0, jpeg_data_size)
|
33
|
+
padding_data = buf.slice!(0, padding_size)
|
34
|
+
state = :commen_header
|
35
|
+
yield Packet.new(commen_header, payload_header, jpeg_data, padding_data)
|
36
|
+
end # case state
|
37
|
+
# gets
|
38
|
+
end # until buf.empty?
|
39
|
+
end # response.read_body do |chunk|
|
40
|
+
end # http.request request do |response|
|
41
|
+
end rescue retry # Net::HTTP.start(uri.host, uri.port) do |http|
|
42
|
+
end # def stream
|
43
|
+
end # class Liveview
|
44
|
+
end
|
data/lib/sonycam/packet.rb
CHANGED
@@ -1,28 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
1
|
+
module Sonycam
|
2
|
+
class Packet
|
3
|
+
def initialize commen_header, payload_header, jpeg_data, padding_data
|
4
|
+
@packet = {
|
5
|
+
commen_header: {
|
6
|
+
start_byte: commen_header[0], # hex, fixed "FF"
|
7
|
+
payload_type: commen_header[1], # int
|
8
|
+
sequence_number: commen_header[2], # int
|
9
|
+
time_stamp: commen_header[3] # int
|
10
|
+
},
|
11
|
+
payload_header: {
|
12
|
+
star_code: payload_header[0], # hex, fixed "24356879"
|
13
|
+
jpeg_data_size: payload_header[1].to_i(16), # int
|
14
|
+
padding_size: payload_header[2], # int
|
15
|
+
reserved: payload_header[3], # hex
|
16
|
+
flag: payload_header[4], # int, fixed "00"
|
17
|
+
reserved_2: payload_header[5]
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
},
|
20
|
+
payload_data: {
|
21
|
+
jpeg_data: jpeg_data,
|
22
|
+
padding_data: padding_data
|
23
|
+
},
|
24
|
+
}
|
25
|
+
end
|
26
|
+
def [] key
|
27
|
+
@packet[key]
|
28
|
+
end
|
27
29
|
end
|
28
30
|
end
|
data/lib/sonycam/version.rb
CHANGED