access callback, only one frame/video extraction thread. make sure all frames are extracted before returning them

This commit is contained in:
j 2010-09-08 19:16:07 +02:00
parent 6bdeb5ef85
commit 0af4304e88
4 changed files with 39 additions and 14 deletions

View file

@ -90,6 +90,7 @@ def hash_prefix(h):
return [h[:2], h[2:4], h[4:6], h[6:]] return [h[:2], h[2:4], h[4:6], h[6:]]
def run_command(cmd, timeout=25): def run_command(cmd, timeout=25):
#print cmd
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
while timeout > 0: while timeout > 0:
time.sleep(0.2) time.sleep(0.2)
@ -152,6 +153,7 @@ def extract_frame(video, target, position):
framedir = tempfile.mkdtemp() framedir = tempfile.mkdtemp()
os.chdir(framedir) os.chdir(framedir)
cmd = ['mplayer', '-noautosub', video, '-ss', str(position), '-frames', '2', '-vo', 'png:z=9', '-ao', 'null'] cmd = ['mplayer', '-noautosub', video, '-ss', str(position), '-frames', '2', '-vo', 'png:z=9', '-ao', 'null']
print cmd
r = run_command(cmd) r = run_command(cmd)
images = glob('%s/*.png' % framedir) images = glob('%s/*.png' % framedir)
if images: if images:
@ -292,7 +294,7 @@ class Database(object):
def __init__(self, db_conn): def __init__(self, db_conn):
self.extract = Queue.Queue() self.extract = Queue.Queue()
for i in range(2): #for i in range(2):
t = ExtractThread(self) t = ExtractThread(self)
t.setDaemon(True) t.setDaemon(True)
t.start() t.start()
@ -459,7 +461,6 @@ class Database(object):
self.derivative(oshash, frame_name, STATUS_FAILED) self.derivative(oshash, frame_name, STATUS_FAILED)
elif name.endswith('.webm'): elif name.endswith('.webm'):
profile = name[:-5] profile = name[:-5]
print 'now lets go, are we having fun?'
self.derivative(oshash, name, STATUS_EXTRACTING) self.derivative(oshash, name, STATUS_EXTRACTING)
if extract_video(f['path'], derivative['path'], profile, f['info']): if extract_video(f['path'], derivative['path'], profile, f['info']):
self.derivative(oshash, name, STATUS_AVAILABLE) self.derivative(oshash, name, STATUS_AVAILABLE)
@ -732,21 +733,30 @@ class OxControl(Resource):
derivative = self.db.derivative(oshash, name) derivative = self.db.derivative(oshash, name)
if derivative['status'] == STATUS_FAILED and retry: if derivative['status'] == STATUS_FAILED and retry:
derivative = self.db.derivative(oshash, name, STATUS_NEW) derivative = self.db.derivative(oshash, name, STATUS_NEW)
response['status'] = { _STATUS = {
STATUS_NEW: 'extracting', STATUS_NEW: 'extracting',
STATUS_EXTRACTING: 'extracting', STATUS_EXTRACTING: 'extracting',
STATUS_AVAILABLE: 'available', STATUS_AVAILABLE: 'available',
STATUS_FAILED: 'failed', STATUS_FAILED: 'failed',
}.get(derivative['status'], 'extracting') }
response['status'] = _STATUS.get(derivative['status'], 'extracting')
if derivative['status'] == STATUS_NEW: if derivative['status'] == STATUS_NEW:
self.db.extract.put((oshash, name)) self.db.extract.put((oshash, name))
if derivative['status'] == STATUS_EXTRACTING: if derivative['status'] == STATUS_EXTRACTING:
print "queue", self.db.extract.qsize()
response['progress'] = enc_status.get(oshash, 0) response['progress'] = enc_status.get(oshash, 0)
files = [f['path'] for f in self.db.derivatives(oshash)] files = [f['path'] for f in self.db.derivatives(oshash)]
if media == 'frames': if media == 'frames':
status = derivative['status']
for f in self.db.derivatives(oshash):
if f['path'].endswith('.png'):
status = min(status, f['status'])
if status == derivative['status']:
response['frames'] = filter(lambda f: f.endswith('.png'), files) response['frames'] = filter(lambda f: f.endswith('.png'), files)
else:
response['status'] = _STATUS.get(status, 'extracting')
else: else:
response['video'] = filter(lambda f: f.endswith(media), files) response['video'] = filter(lambda f: f.endswith(media), files)
if response['video']: response['video'] = response['video'][0] if response['video']: response['video'] = response['video'][0]

View file

@ -129,8 +129,7 @@ OxFF.prototype = {
//nsIOxFF //nsIOxFF
version: "bzr", version: "bzr",
access: function(request) { access: function(callback) {
if (typeof(request) == 'undefined') request = false;
var _this = this; var _this = this;
var conn = oxff.getDB(); var conn = oxff.getDB();
@ -144,22 +143,28 @@ OxFF.prototype = {
} }
q.finalize(); q.finalize();
if (request && !this._access) { if (callback && !this._access) {
var windowMediator = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator); var windowMediator = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
var nsWindow = windowMediator.getMostRecentWindow("navigator:browser"); var nsWindow = windowMediator.getMostRecentWindow("navigator:browser");
var box = nsWindow.gBrowser.getNotificationBox(); var box = nsWindow.gBrowser.getNotificationBox();
var buttons = [{ var buttons = [{
label : "Allow", label : "Allow",
accessKey : "A", accessKey : "A",
callback : function() { _this.permitAccess(); } callback : function() { _this.permitAccess();
if(callback) callback.callback(true);
}
}, },
{ {
label : "Deny", label : "Deny",
accessKey : "D", accessKey : "D",
callback : function() { _this.denyAccess(); } callback : function() { _this.denyAccess();
if(callback) callback.callback(false);
}
}]; }];
box.appendNotification("Do you wnat to allow "+_this._site+" to manage archvies on your computer", box.appendNotification("Do you wnat to allow "+_this._site+" to manage archvies on your computer",
'oxff_permission' , null , box.PRIORITY_INFO_MEDIUM , buttons); 'oxff_permission' , null , box.PRIORITY_INFO_MEDIUM , buttons);
} else if(callback) {
callback.callback(this._access);
} }
return this._access; return this._access;
}, },
@ -225,6 +230,7 @@ OxFF.prototype = {
var formData = options.data; var formData = options.data;
else else
var formData = {}; var formData = {};
var url = options.url; var url = options.url;
if (callback) if (callback)

Binary file not shown.

View file

@ -9,6 +9,15 @@ interface oxICallback : nsISupports
void callback(in AString result); void callback(in AString result);
}; };
[function, scriptable, uuid(70015be1-2620-4682-ba3c-8024e7cb41ac)]
interface oxIBooleanCallback : nsISupports
{
/**
* @param result boolean
*/
void callback(in boolean result);
};
[scriptable, uuid(333280ed-2620-46ed-916d-b9c29e84d9ba)] [scriptable, uuid(333280ed-2620-46ed-916d-b9c29e84d9ba)]
interface nsIOxFF : nsISupports interface nsIOxFF : nsISupports
@ -16,7 +25,7 @@ interface nsIOxFF : nsISupports
readonly attribute string version; readonly attribute string version;
boolean login(in AString user); boolean login(in AString user);
boolean access([optional] in boolean request); boolean access([optional] in oxIBooleanCallback callback);
boolean logout(); boolean logout();
string volumes(in oxICallback callback); string volumes(in oxICallback callback);