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 }
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.
46 47 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 |
# File 'lib/vncrec/recorder.rb', line 46 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 @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
44 45 46 |
# File 'lib/vncrec/recorder.rb', line 44 def on_exit @on_exit end |
Instance Method Details
#filesize ⇒ Object
Return current size of file
117 118 119 120 |
# File 'lib/vncrec/recorder.rb', line 117 def filesize return @file.size if @file 0 end |
#run ⇒ Object
Start routine: wait for connection, perform handshake, get data, write data. Non-blocking.
97 98 99 100 101 |
# File 'lib/vncrec/recorder.rb', line 97 def run @loop = Thread.new do routine end end |
#running? ⇒ Boolean
128 129 130 |
# File 'lib/vncrec/recorder.rb', line 128 def running? @loop && @loop.alive? end |
#stop ⇒ Object
Safely stop any interaction with VNC server, close file. Execute all on_exit hooks.
107 108 109 110 111 112 113 |
# File 'lib/vncrec/recorder.rb', line 107 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.
124 125 126 |
# File 'lib/vncrec/recorder.rb', line 124 def stopped? !(@loop.nil? && @loop.alive?) end |