Now allows the new processes to create child processes (useful for two-pass encoding, or, in a future, to allow mencoder to copy all the audio streams)

This commit is contained in:
Sergio Costas 2014-07-26 20:47:35 +02:00
parent 2564470119
commit 889325aaed
7 changed files with 66 additions and 33 deletions

View file

@ -21,6 +21,7 @@ import subprocess
import os
import devede.configuration_data
import devede.executor
import devede.mux_dvd_menu
class avconv_converter(devede.executor.executor):
@ -303,6 +304,12 @@ class avconv_converter(devede.executor.executor):
self.command_var.append(os.path.join(output_path,"menu_"+str(n_page)+".mpg"))
muxer = devede.mux_dvd_menu.mux_dvd_menu()
muxer.create_mpg(n_page,output_path)
# the muxer process depends of the converter process
muxer.add_dependency(self)
self.add_child_process(muxer)
def process_stdout(self,data):
pass

View file

@ -542,10 +542,6 @@ class dvd_menu(devede.interface_manager.interface_manager):
converter = menu_converter()
converter.create_menu_mpeg(n_page,self.background_music,self.sound_length,self.config.PAL,menu_folder)
# add this process without dependencies
processes.append([converter, None])
muxer = devede.mux_dvd_menu.mux_dvd_menu()
muxer.create_mpg(n_page,menu_folder)
# the muxer process depends of the converter process
processes.append([muxer, [converter]])
processes.append(converter)
n_page += 1
return processes

View file

@ -42,6 +42,44 @@ class executor(GObject.GObject):
self.stdin_file = None
self.stdout_file = None
self.dependencies = None
self.childs = []
self.progress_bar = None
def add_dependency(self, dep):
if (self.dependencies == None):
self.dependencies = []
if (self.dependencies.count(dep) == 0):
self.dependencies.append(dep)
# the childs have the same dependencies than the parent process because, from outside, it is viewed as a single process
for child in self.childs:
child.add_dependency(dep)
def remove_dependency(self,process):
if (self.dependencies != None):
tmp2 = []
for dep in self.dependencies:
if dep != process:
tmp2.append(dep)
if (len(tmp2) != 0):
self.dependencies = tmp2
else:
self.dependencies = None
def add_child_process(self,child):
# the childs have the same dependencies than the parent process because, from outside, it is viewed as a single process
if self.dependencies != None:
for dep in self.dependencies:
child.add_dependency(dep)
if (self.childs.count(child) == 0):
self.childs.append(child)
def run(self, progress_bar):
self.progress_bar = progress_bar

View file

@ -436,10 +436,8 @@ class file_movie(devede.interface_manager.interface_manager):
def do_conversion(self, output_path, duration = 0):
self.set_final_size_aspect()
p = []
cv = devede.converter.converter()
disc_converter = cv.get_disc_converter()
converter = disc_converter()
converter.convert_file(self,output_path,duration)
p.append([converter, None])
return p
return converter

View file

@ -39,7 +39,6 @@ class mux_dvd_menu(devede.executor.executor):
self.stdin_file = os.path.join(output_path,"menu_"+str(n_page)+".mpg")
self.stdout_file = os.path.join(output_path,"menu_"+str(n_page)+"B.mpg")
def process_stderr(self,data):
print("spumux: "+str(data))

View file

@ -263,8 +263,9 @@ class devede_project:
run_window = devede.runner.runner()
file_movies = self.get_all_files()
p = self.menu.create_dvd_menus(file_movies, data.path)
run_window.add_processes(p)
processes = self.menu.create_dvd_menus(file_movies, data.path)
for p in processes:
run_window.add_process(p)
movie_folder = os.path.join(data.path,"movies")
try:
os.makedirs(movie_folder)
@ -273,6 +274,6 @@ class devede_project:
counter = 0
for movie in file_movies:
p = movie.do_conversion(os.path.join(movie_folder,"movie_"+str(counter)+".mpg"))
run_window.add_processes(p)
run_window.add_process(p)
counter += 1
run_window.run()

View file

@ -58,10 +58,14 @@ class runner(GObject.GObject):
box.set_orientation(Gtk.Orientation.VERTICAL)
self.total_processes = 0
def add_processes(self,processes):
for p in processes:
p.append(None) # this will contain the progress bar being used by this process
self.proc_list.append(p)
def add_process(self,process):
if (self.proc_list.count(process) == 0):
self.proc_list.append(process)
for p in process.childs:
self.add_process(p)
self.total_processes = len(self.proc_list)
@ -83,11 +87,10 @@ class runner(GObject.GObject):
# * the process object
# * the list of dependencies, or None if there are no more dependencies
# * the progress bar being used by this process
if (element[1] == None) and (element[2] == None):
self.progress_bars[0][2] = element[0]
element[0].connect("ended",self.process_ended)
element[0].run(self.progress_bars[0])
element[2] = self.progress_bars[0]
if (element.dependencies == None) and (element.progress_bar == None):
element.connect("ended",self.process_ended)
element.run(self.progress_bars[0])
element.progress_bar = self.progress_bars[0]
self.used_progress_bars.append(self.progress_bars[0])
if (len(self.progress_bars) > 1):
self.progress_bars = self.progress_bars[1:]
@ -101,8 +104,7 @@ class runner(GObject.GObject):
# move the progress bar used by this process to the list of available progress bars
tmp = []
for e in self.used_progress_bars:
if (e[2] == process):
e[2] = None
if (process.progress_bar == e):
self.progress_bars.append(e)
e[0].hide()
else:
@ -112,17 +114,9 @@ class runner(GObject.GObject):
# remove this process from the list of processes, and remove it from the dependencies in other processes
tmp = []
for e in self.proc_list:
if (e[0] != process):
if (e != process):
tmp.append(e)
if (e[1] != None):
tmp2 = []
for dep in e[1]:
if dep != process:
tmp2.append(dep)
if (len(tmp2) != 0):
e[1] = tmp2
else:
e[1] = None
e.remove_dependency(process)
self.proc_list = tmp
# launch a new process