Class: VNCRec::Recorder
- Inherits:
-
Object
- Object
- VNCRec::Recorder
- Defined in:
- lib/vncrec/recorder.rb
Overview
A recorder itself.
Constant Summary collapse
- DEFAULTS =
{ :pix_fmt => :BGR8, :debug => nil, :encoding => VNCRec::ENC_RAW, :filename => nil, :fps => 6, :input => nil, :port => 5900, :auth => [VNCRec::RFB::Authentication::None] }
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#filesize ⇒ Object
Return current size of file.
-
#initialize(options = {}) ⇒ Recorder
constructor
A new instance of Recorder.
-
#run ⇒ Object
Start routine: wait for connection, perform handshake, get data, write data.
- #running? ⇒ Boolean
-
#stop ⇒ Object
Safely stop any interaction with VNC server, close file.
-
#stopped? ⇒ bool
Find out if main loop thread is alive.
Constructor Details
#initialize(options = {}) ⇒ Recorder
Returns a new instance of Recorder.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/vncrec/recorder.rb', line 48 def initialize( = {}) = VNCRec::Recorder::DEFAULTS.merge() @logging = [:logging] || [:logger] || [:log] || false if @logging @logger = Logger.new STDERR @logger.datetime_format = '% d_%m %H-%M-%S.%6N' @logger.info .inspect end @debug = [:debug] $stderr.puts 'Debug mode' if @debug @port = [:port] fail ArgumentError, 'Invalid port value' unless @port.is_a?(Numeric) && (1024..65_535).include?(@port) @host = [:host] @client = nil @auth = [:auth] @password = [:password] @framerate = [:fps] fail ArgumentError if !@framerate.is_a?(Numeric) || @framerate <= 0 @filename = [:filename] || ([:port].to_s + '.raw') fail "Cannot create file #{@filename}" unless system "touch #{@filename}" if [:geometry] @geometry = [:geometry] fail ArgumentError, "Geometry is invalid, expected: <x>x<y>, \ got: #{@geometry.inspect}" unless valid_geometry?(@geometry) end @enc = [:encoding] pf = [:pix_fmt].to_s.dup.prepend('PIX_FMT_').upcase.to_sym fail ArgumentError, "Unknown pix_fmt #{[:pix_fmt]}" unless VNCRec.const_defined? pf @pix_fmt = VNCRec.const_get(pf) @ffmpeg_iv_opts = [:ffmpeg_iv_opts] @ffmpeg_ia_opts = [:ffmpeg_ia_opts] @ffmpeg_out_opts = [:ffmpeg_out_opts] Thread.abort_on_exception = true @on_exit = [:close_file, :close_proxy] @file = nil @sleep_time = 0.01 @recording_starttime = nil end |
Instance Attribute Details
#on_exit ⇒ Object
46 47 48 |
# File 'lib/vncrec/recorder.rb', line 46 def on_exit @on_exit end |
Instance Method Details
#filesize ⇒ Object
Return current size of file
122 123 124 125 |
# File 'lib/vncrec/recorder.rb', line 122 def filesize return @file.size if @file 0 end |
#run ⇒ Object
Start routine: wait for connection, perform handshake, get data, write data. Non-blocking.
102 103 104 105 106 |
# File 'lib/vncrec/recorder.rb', line 102 def run @loop = Thread.new do routine end end |
#running? ⇒ Boolean
133 134 135 |
# File 'lib/vncrec/recorder.rb', line 133 def running? @loop && @loop.alive? end |
#stop ⇒ Object
Safely stop any interaction with VNC server, close file. Execute all on_exit hooks.
112 113 114 115 116 117 118 |
# File 'lib/vncrec/recorder.rb', line 112 def stop @loop.kill unless Thread.current == @loop @on_exit.each do |bl| send bl if bl.is_a? Symbol bl.call if bl.respond_to?(:call) end end |
#stopped? ⇒ bool
Find out if main loop thread is alive.
129 130 131 |
# File 'lib/vncrec/recorder.rb', line 129 def stopped? !(@loop.nil? && @loop.alive?) end |