Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@seki
Created April 4, 2014 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seki/9984288 to your computer and use it in GitHub Desktop.
Save seki/9984288 to your computer and use it in GitHub Desktop.
require 'av_capture'
require 'drb'
class PhotoServer
attr_reader :worker
def initialize
@worker = Queue.new
end
def take_photo
connection = @worker.pop
connection.capture
ensure
@worker.push connection
end
end
server = PhotoServer.new
Thread.new do
session = AVCapture::Session.new
dev = AVCapture.devices.find(&:video?)
session.run_with(dev) do |connection|
server.worker.push connection
sleep
end
end
URI = "druby://localhost:8787"
DRb.start_service(URI, server)
DRb.thread.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment