Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify progress bar finish and consolidate dec_bar function #755

Merged
merged 1 commit into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions av1an-core/src/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ use cfg_if::cfg_if;
use smallvec::SmallVec;
use thiserror::Error;

use crate::progress_bar::{dec_bar, dec_mp_bar, update_progress_bar_estimates};
use crate::progress_bar::{dec_bar, update_progress_bar_estimates};
use crate::settings::EncodeArgs;
use crate::util::printable_base10_digits;
use crate::{
finish_multi_progress_bar, finish_progress_bar, get_done, Chunk, DoneChunk, Instant, Verbosity,
};
use crate::{finish_progress_bar, get_done, Chunk, DoneChunk, Instant};

pub struct Broker<'a> {
pub max_tries: usize,
pub chunk_queue: Vec<Chunk>,
pub project: &'a EncodeArgs,
}
Expand Down Expand Up @@ -169,11 +166,7 @@ impl<'a> Broker<'a> {
})
.unwrap();

if self.project.verbosity == Verbosity::Normal {
finish_progress_bar();
} else if self.project.verbosity == Verbosity::Verbose {
finish_multi_progress_bar();
}
finish_progress_bar();
}
}

Expand All @@ -196,21 +189,17 @@ impl<'a> Broker<'a> {

let passes = chunk.passes;
for current_pass in 1..=passes {
for r#try in 1..=self.max_tries {
for r#try in 1..=self.project.max_tries {
let res = self
.project
.create_pipes(chunk, current_pass, worker_id, padding);
if let Err((e, frames)) = res {
if self.project.verbosity == Verbosity::Normal {
dec_bar(frames);
} else if self.project.verbosity == Verbosity::Verbose {
dec_mp_bar(frames);
}
dec_bar(frames);

if r#try == self.max_tries {
if r#try == self.project.max_tries {
error!(
"[chunk {}] encoder failed {} times, shutting down worker",
chunk.index, self.max_tries
chunk.index, self.project.max_tries
);
return Err(e);
}
Expand Down
2 changes: 1 addition & 1 deletion av1an-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use strum::{Display, EnumString, IntoStaticStr};
use sysinfo::SystemExt;

use crate::encoder::Encoder;
use crate::progress_bar::{finish_multi_progress_bar, finish_progress_bar};
use crate::progress_bar::finish_progress_bar;
use crate::target_quality::TargetQuality;

pub mod broker;
Expand Down
26 changes: 11 additions & 15 deletions av1an-core/src/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ pub fn dec_bar(dec: u64) {
if let Some(pb) = PROGRESS_BAR.get() {
pb.set_position(pb.position().saturating_sub(dec));
}

if let Some((_, pbs)) = MULTI_PROGRESS_BAR.get() {
let pb = pbs.last().unwrap();
pb.set_position(pb.position().saturating_sub(dec));
}
}

pub fn update_bar_info(kbps: f64, est_size: HumanBytes) {
Expand All @@ -163,6 +168,12 @@ pub fn finish_progress_bar() {
if let Some(pb) = PROGRESS_BAR.get() {
pb.finish();
}

if let Some((_, pbs)) = MULTI_PROGRESS_BAR.get() {
for pb in pbs.iter() {
pb.finish();
}
}
}

static MULTI_PROGRESS_BAR: OnceCell<(MultiProgress, Vec<ProgressBar>)> = OnceCell::new();
Expand Down Expand Up @@ -258,13 +269,6 @@ pub fn inc_mp_bar(inc: u64) {
}
}

pub fn dec_mp_bar(dec: u64) {
if let Some((_, pbs)) = MULTI_PROGRESS_BAR.get() {
let pb = pbs.last().unwrap();
pb.set_position(pb.position().saturating_sub(dec));
}
}

pub fn update_mp_bar_info(kbps: f64, est_size: HumanBytes) {
if let Some((_, pbs)) = MULTI_PROGRESS_BAR.get() {
pbs
Expand All @@ -274,14 +278,6 @@ pub fn update_mp_bar_info(kbps: f64, est_size: HumanBytes) {
}
}

pub fn finish_multi_progress_bar() {
if let Some((_, pbs)) = MULTI_PROGRESS_BAR.get() {
for pb in pbs.iter() {
pb.finish();
}
}
}

pub fn update_progress_bar_estimates(frame_rate: f64, total_frames: usize, verbosity: Verbosity) {
let completed_frames: usize = get_done()
.done
Expand Down
13 changes: 4 additions & 9 deletions av1an-core/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ use crate::split::{extra_splits, segment, write_scenes_to_file};
use crate::vapoursynth::{create_vs_file, is_ffms2_installed, is_lsmash_installed};
use crate::vmaf::{self, validate_libvmaf};
use crate::{
create_dir, determine_workers, finish_multi_progress_bar, get_done, init_done, into_vec,
read_chunk_queue, save_chunk_queue, ChunkMethod, ChunkOrdering, DashMap, DoneJson, Encoder,
Input, ScenecutMethod, SplitMethod, TargetQuality, Verbosity,
create_dir, determine_workers, get_done, init_done, into_vec, read_chunk_queue, save_chunk_queue,
ChunkMethod, ChunkOrdering, DashMap, DoneJson, Encoder, Input, ScenecutMethod, SplitMethod,
TargetQuality, Verbosity,
};

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
Expand Down Expand Up @@ -1295,7 +1295,6 @@ properly into a mkv file. Specify mkvmerge as the concatenation method by settin
let broker = Broker {
chunk_queue,
project: self,
max_tries: self.max_tries,
};

let (tx, rx) = mpsc::channel();
Expand All @@ -1311,11 +1310,7 @@ properly into a mkv file. Specify mkvmerge as the concatenation method by settin

handle.join().unwrap();

if self.verbosity == Verbosity::Normal {
finish_progress_bar();
} else if self.verbosity == Verbosity::Verbose {
finish_multi_progress_bar();
}
finish_progress_bar();

// TODO add explicit parameter to concatenation functions to control whether audio is also muxed in
let _audio_output_exists =
Expand Down