Skip to content
Browse files

Checks if dvgrab recording has stalled

  • Loading branch information...
1 parent 20fe51a commit 974eaee61938729f80a9f5d95f91f8bc28c005eb Jon Stenqvist committed
Showing with 32 additions and 1 deletion.
  1. +18 −1 lib/fire_grabber/recorder.rb
  2. +14 −0 spec/fire_grabber/recorder_spec.rb
View
19 lib/fire_grabber/recorder.rb
@@ -22,7 +22,7 @@ def self.configure
config.line_ending = "\r"
end
- attr_accessor :filename, :frames, :size, :timecode, :started_at, :ended_at, :logger, :terminated_unexpected
+ attr_accessor :filename, :frames, :size, :timecode, :started_at, :ended_at, :logger, :terminated_unexpected, :stalled
def initialize
@logger = Logger.new(configuration[:log_file] || STDOUT)
@@ -33,6 +33,7 @@ def initialize
@terminated_unexpected = true unless @ended_at
@dvgrab_pipe = nil
end
+ heartbeat
end
def start!
@@ -60,6 +61,10 @@ def dvgrab_running?
@dvgrab_pipe
end
+ def stalled?
+ @dvgrab_pipe && @stalled
+ end
+
def terminated_unexpected?
@terminated_unexpected
end
@@ -86,6 +91,17 @@ def attributes
private
+ def heartbeat
+ @last_checked_frames = nil
+ Thread.new do
+ loop do
+ @stalled = @frames == @last_checked_frames
+ @last_checked_frames = @frames
+ sleep 1
+ end
+ end
+ end
+
def recording_info
/"([.\w\/]*)":\s+(.*)\s+MiB\s+(\d+)\s+frames\s+timecode\s+(.*)\s+date/
end
@@ -121,6 +137,7 @@ def stop_capture_output
end
def nullify_accessors!
+ @stalled = nil
@filename = nil
@frames = nil
@size = nil
View
14 spec/fire_grabber/recorder_spec.rb
@@ -88,6 +88,20 @@
@r.stop!
@r.should_not be_terminated_unexpected
end
+
+ it "should not be stalled" do
+ @r.start!
+ @r.should_not be_stalled
+ @r.stop!
+ end
+
+ it "should be stalled" do
+ @r.stub!(:parse)
+ @r.start!
+ sleep 1
+ @r.should be_stalled
+ @r.stop!
+ end
it "should nil all attributes on start" do
@r.instance_eval { @filename = @frames = @size = @timecode = @started_at = @ended_at = "some value" }

0 comments on commit 974eaee

Please sign in to comment.
Something went wrong with that request. Please try again.