Module: Vidibus::Recording::Mongoid

Extended by:
ActiveSupport::Concern
Included in:
Recording
Defined in:
lib/vidibus/recording/mongoid.rb

Instance Method Summary collapse

Instance Method Details

#backendObject

TODO: really a public method? Returns an instance of a fitting recording backend.



131
132
133
134
135
136
137
# File 'lib/vidibus/recording/mongoid.rb', line 131

def backend
  @backend ||= Vidibus::Recording::Backend.load({
    :stream => stream,
    :file => current_part.data_file,
    :live => true
  })
end

#basenameObject



189
190
191
# File 'lib/vidibus/recording/mongoid.rb', line 189

def basename
  "#{folder}/#{uuid}"
end

#current_partObject



210
211
212
# File 'lib/vidibus/recording/mongoid.rb', line 210

def current_part
  parts.last
end

#done?Boolean

Returns true if recording has either been stopped or failed.

Returns:

  • (Boolean)


140
141
142
# File 'lib/vidibus/recording/mongoid.rb', line 140

def done?
  stopped? || failed?
end

#fail(msg) ⇒ Object

Receives an error from recording worker and stores it. The worker gets stopped and postprocessing is started.



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/vidibus/recording/mongoid.rb', line 93

def fail(msg)
  return false unless running?
  stop_worker do
    self.pid = nil
    self.error = msg
    self.failed_at = Time.now
    self.running = false
    self.active = false
    postprocess
  end
end

#failed?Boolean

Returns true if recording has failed.

Returns:

  • (Boolean)


145
146
147
# File 'lib/vidibus/recording/mongoid.rb', line 145

def failed?
  !!failed_at
end

#fileObject

Returns the file name of this recording. DEPRECATED: this is kept for existing records only.



200
201
202
# File 'lib/vidibus/recording/mongoid.rb', line 200

def file
  @file ||= "#{basename}.rec"
end

#folderObject

Return folder to store recordings in.



179
180
181
182
183
184
185
186
187
# File 'lib/vidibus/recording/mongoid.rb', line 179

def folder
  @folder ||= begin
    f = ['recordings']
    f.unshift(Rails.root) if defined?(Rails)
    path = File.join(f)
    FileUtils.mkdir_p(path) unless File.exist?(path)
    path
  end
end

#haltObject

Gets called from recording worker if it receives no more data.



82
83
84
85
86
87
88
89
# File 'lib/vidibus/recording/mongoid.rb', line 82

def halt
  return false unless running?
  stop_worker do
    self.pid = nil
    self.running = false
    postprocess
  end
end

#has_data?Boolean

Returns:

  • (Boolean)


158
159
160
# File 'lib/vidibus/recording/mongoid.rb', line 158

def has_data?
  size.to_i > 0
end

#log_fileObject

Returns the log file name for this recording.



194
195
196
# File 'lib/vidibus/recording/mongoid.rb', line 194

def log_file
  @log_file ||= "#{basename}.log"
end

#resetObject

TODO: really a public method? Removes all acquired data!



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/vidibus/recording/mongoid.rb', line 107

def reset
  remove_files
  blank = {}
  [
    :started_at,
    :stopped_at,
    :failed_at,
    :info,
    :error,
    :size,
    :duration
  ].map {|a| blank[a] = nil }
  update_attributes!(blank)
  destroy_all_parts
end

#restartObject

Resets data and starts anew.



63
64
65
66
67
# File 'lib/vidibus/recording/mongoid.rb', line 63

def restart
  stop
  reset
  start
end

#resumeObject

Continue recording that is not running anymore.



54
55
56
57
58
59
60
# File 'lib/vidibus/recording/mongoid.rb', line 54

def resume
  return false if running? || !started?
  self.stopped_at = nil
  self.failed_at = nil
  self.active = true
  start!
end

#start(time = :now) ⇒ Object

Starts a recording worker now, unless it has been done already. Provide a Time object to schedule start.



42
43
44
45
46
47
48
49
50
51
# File 'lib/vidibus/recording/mongoid.rb', line 42

def start(time = :now)
  return false if done? || started?
  if time == :now
    self.started_at = Time.now
    self.active = true
    start!
  else
    schedule(time)
  end
end

#started?Boolean

Returns true if recording has been started.

Returns:

  • (Boolean)


150
151
152
# File 'lib/vidibus/recording/mongoid.rb', line 150

def started?
  !!started_at
end

#stopObject

Stops the recording worker and starts postprocessing.



70
71
72
73
74
75
76
77
78
79
# File 'lib/vidibus/recording/mongoid.rb', line 70

def stop
  return false if done? || !started?
  stop_worker do
    self.pid = nil
    self.stopped_at = Time.now
    self.running = false
    self.active = false
    postprocess
  end
end

#stopped?Boolean

Returns:

  • (Boolean)


154
155
156
# File 'lib/vidibus/recording/mongoid.rb', line 154

def stopped?
  !!stopped_at
end

#track_progressObject



214
215
216
217
218
219
# File 'lib/vidibus/recording/mongoid.rb', line 214

def track_progress
  current_part.track_progress if current_part
  set_size
  set_duration
  save!
end

#workerObject

TODO: really a public method? Returns an instance of the recording worker.



125
126
127
# File 'lib/vidibus/recording/mongoid.rb', line 125

def worker
  @worker ||= Vidibus::Recording::Worker.new(self)
end

#worker_running?Boolean

Returns true if recording worker is still running. Persists attributes accordingly.

Returns:

  • (Boolean)


164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/vidibus/recording/mongoid.rb', line 164

def worker_running?
  if fresh_worker.running?
    unless running?
      self.update_attributes!(:running => true)
    end
    true
  else
    if running?
      self.update_attributes!(:pid => nil, :running => false)
    end
    false
  end
end

#yml_fileObject

Returns the YAML file name for this recording. DEPRECATED: this is kept for existing records only.



206
207
208
# File 'lib/vidibus/recording/mongoid.rb', line 206

def yml_file
  @yml_file ||= "#{basename}.yml"
end