Skip to content

Commit

Permalink
Rename get_* methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fengalin committed Aug 24, 2020
1 parent 8fba4f6 commit 30b5305
Show file tree
Hide file tree
Showing 34 changed files with 214 additions and 228 deletions.
2 changes: 1 addition & 1 deletion application/src/command_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct CommandLineArguments {
pub disable_gl: bool,
}

pub fn get_command_line() -> CommandLineArguments {
pub fn command_line() -> CommandLineArguments {
let about_msg =
gettext("Build a table of contents from a media file\nor split a media file into chapters");
let help_msg = gettext("Display this message");
Expand Down
2 changes: 1 addition & 1 deletion application/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ lazy_static! {
}

mod command_line;
pub use self::command_line::{get_command_line, CommandLineArguments};
pub use self::command_line::{command_line, CommandLineArguments};

mod configuration;
pub use self::configuration::CONFIG;
Expand Down
4 changes: 2 additions & 2 deletions main/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use gettextrs::gettext;
use log::error;

use application::{get_command_line, init_locale};
use application::{command_line, init_locale};

fn main() {
env_logger::init();
Expand All @@ -12,7 +12,7 @@ fn main() {
let is_gtk_ok = gtk::init().is_ok();

if is_gtk_ok {
ui::run(get_command_line());
ui::run(command_line());
} else {
error!("{}", gettext("Failed to initialize GTK"));
}
Expand Down
2 changes: 1 addition & 1 deletion media/benches/audio_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const CHANNELS: usize = 2;

fn build_buffer(lower_value: usize, upper_value: usize) -> gst::Buffer {
let lower: SampleIndex = lower_value.into();
let pts = Timestamp::new(lower.get_ts(SAMPLE_DURATION).as_u64() + 1);
let pts = Timestamp::new(lower.as_ts(SAMPLE_DURATION).as_u64() + 1);
let samples_u8_len = (upper_value - lower_value) * CHANNELS * 2;

let mut buffer = gst::Buffer::with_size(samples_u8_len).unwrap();
Expand Down
8 changes: 4 additions & 4 deletions media/src/audio_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl StreamState {
debug!(
"have_gst_segment {} ({})",
segment_start,
segment_start.get_sample_index(self.sample_duration),
segment_start.sample_index(self.sample_duration),
);

match self.segment_start {
Expand Down Expand Up @@ -522,14 +522,14 @@ impl<'slice> SampleConverterIter<'slice> {
two_x_bytes_per_channel: 2 * bytes_per_channel,
output_channels,
extra_positions,
convert: SampleConverterIter::get_convert(audio_buffer.stream_state.format),
convert: SampleConverterIter::convert_fn(audio_buffer.stream_state.format),
first: lower,
idx: None,
last: upper,
})
}

fn get_convert(format: gst_audio::AudioFormat) -> ConvertFn {
fn convert_fn(format: gst_audio::AudioFormat) -> ConvertFn {
let convert: ConvertFn = match format {
AudioFormat::S8 => |rdr| to_sample_value!(rdr.read_i8()),
AudioFormat::U8 => |rdr| to_sample_value!(rdr.read_u8()),
Expand Down Expand Up @@ -722,7 +722,7 @@ mod tests {
// if all samples are rendered in the range [0:SAMPLE_RATE]
fn build_buffer(lower_value: usize, upper_value: usize) -> gst::Buffer {
let lower: SampleIndex = lower_value.into();
let pts = Timestamp::new(lower.get_ts(SAMPLE_DURATION).as_u64() + 1);
let pts = Timestamp::new(lower.as_ts(SAMPLE_DURATION).as_u64() + 1);
let samples_u8_len = (upper_value - lower_value) * CHANNELS * 2;

let mut buffer = gst::Buffer::with_size(samples_u8_len).unwrap();
Expand Down
8 changes: 4 additions & 4 deletions media/src/dbl_audio_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<SE: SampleExtractor + 'static> DoubleAudioBuffer<SE> {
}

// Get a reference on the exposed buffer mutex.
pub fn get_exposed_buffer_mtx(&self) -> Arc<Mutex<Box<SE>>> {
pub fn exposed_buffer_mtx(&self) -> Arc<Mutex<Box<SE>>> {
Arc::clone(&self.exposed_buffer_mtx)
}

Expand Down Expand Up @@ -229,9 +229,9 @@ impl<SE: SampleExtractor + 'static> DoubleAudioBuffer<SE> {
mem::swap(exposed_buffer_box, &mut working_buffer);
}

self.lower_to_keep = working_buffer.get_lower();
self.lower_to_keep = working_buffer.lower();
self.sample_window = working_buffer
.get_requested_sample_window()
.req_sample_window()
.map(|req_sample_window| req_sample_window.min(self.max_sample_window));

self.working_buffer = Some(working_buffer);
Expand Down Expand Up @@ -259,7 +259,7 @@ impl<SE: SampleExtractor + 'static> DoubleAudioBuffer<SE> {
mem::swap(exposed_buffer_box, &mut working_buffer);
}

self.lower_to_keep = working_buffer.get_lower();
self.lower_to_keep = working_buffer.lower();

self.working_buffer = Some(working_buffer);
// self.working_buffer is now the buffer previously in
Expand Down
4 changes: 2 additions & 2 deletions media/src/playback_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<SE: SampleExtractor + 'static> PlaybackPipeline<SE> {
})
}

pub fn get_current_ts(&self) -> Option<Timestamp> {
pub fn current_ts(&self) -> Option<Timestamp> {
let mut position_query = gst::query::Position::new(gst::Format::Time);
self.pipeline.query(&mut position_query);
let position = position_query.get_result().get_value();
Expand All @@ -112,7 +112,7 @@ impl<SE: SampleExtractor + 'static> PlaybackPipeline<SE> {
}
}

pub fn get_state(&self) -> gst::State {
pub fn state(&self) -> gst::State {
let (_, current, _) = self.pipeline.get_state(ClockTime::from(10_000_000));
current
}
Expand Down
18 changes: 9 additions & 9 deletions media/src/sample_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,27 @@ impl SampleExtractionState {
}

pub trait SampleExtractor: Send {
fn get_extraction_state(&self) -> &SampleExtractionState;
fn get_extraction_state_mut(&mut self) -> &mut SampleExtractionState;
fn extraction_state(&self) -> &SampleExtractionState;
fn extraction_state_mut(&mut self) -> &mut SampleExtractionState;

fn cleanup(&mut self);

fn set_state(&mut self, new_state: gst::State) {
let state = self.get_extraction_state_mut();
let state = self.extraction_state_mut();
state.state = new_state;
}

fn set_time_ref(&mut self, audio_ref: &gst::Element) {
self.get_extraction_state_mut().audio_ref = Some(audio_ref.clone());
self.extraction_state_mut().audio_ref = Some(audio_ref.clone());
}

fn set_channels(&mut self, channels: &[AudioChannel]);

fn set_sample_duration(&mut self, per_sample: Duration, per_1000_samples: Duration);

fn get_lower(&self) -> SampleIndex;
fn lower(&self) -> SampleIndex;

fn get_requested_sample_window(&self) -> Option<SampleIndexRange>;
fn req_sample_window(&self) -> Option<SampleIndexRange>;

fn switch_to_paused(&mut self);

Expand All @@ -65,16 +65,16 @@ pub trait SampleExtractor: Send {
// extraction process by keeping conditions between frames
fn update_concrete_state(&mut self, other: &mut Self);

fn get_current_sample(&mut self) -> Option<(Timestamp, SampleIndex)> {
let state = &self.get_extraction_state();
fn current_sample(&mut self) -> Option<(Timestamp, SampleIndex)> {
let state = &self.extraction_state();

let mut query = gst::query::Position::new(gst::Format::Time);
if !state.audio_ref.as_ref().unwrap().query(&mut query) {
return None;
}

let ts = Timestamp::new(query.get_result().get_value() as u64);
Some((ts, ts.get_sample_index(state.sample_duration)))
Some((ts, ts.sample_index(state.sample_duration)))
}

// Update the extractions taking account new
Expand Down
4 changes: 2 additions & 2 deletions media/src/sample_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ impl SampleIndex {
SampleIndex((ts.as_u64() / sample_duration.as_u64()) as usize)
}

pub fn get_aligned(self, sample_step: SampleIndexRange) -> SampleIndex {
pub fn snap_to(self, sample_step: SampleIndexRange) -> SampleIndex {
SampleIndex(self.0 / sample_step.as_usize() * sample_step.as_usize())
}

pub fn get_ts(self, sample_duration: Duration) -> Timestamp {
pub fn as_ts(self, sample_duration: Duration) -> Timestamp {
Timestamp::new(self.0 as u64 * sample_duration.as_u64())
}

Expand Down
6 changes: 3 additions & 3 deletions media/src/sample_index_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ impl SampleIndexRange {
SampleIndexRange((duration / sample_duration).as_usize())
}

pub fn get_duration(self, sample_duration: Duration) -> Duration {
pub fn duration(self, sample_duration: Duration) -> Duration {
sample_duration * (self.0 as u64)
}

pub fn get_scaled<T: Into<usize>>(self, num: T, denom: T) -> Self {
pub fn scale<T: Into<usize>>(self, num: T, denom: T) -> Self {
SampleIndexRange(num.into() / denom.into() * self.0)
}

pub fn get_step_range(self, sample_step: SampleIndexRange) -> usize {
pub fn step_range(self, sample_step: SampleIndexRange) -> usize {
self.0 / sample_step.0
}

Expand Down
4 changes: 2 additions & 2 deletions media/src/splitter_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ impl SplitterPipeline {
.map_err(|_| gettext("do you have permission to write the file?"))
}

pub fn get_current_ts(&self) -> Option<Timestamp> {
// `get_current_ts` might be called when the pipeline is not ready yet
pub fn current_ts(&self) -> Option<Timestamp> {
// `current_ts` might be called when the pipeline is not ready yet
// because we build a new pipeline for each split file.
// When this happen, the ts position is negative so don't force it to 0
// because we are most likely not at the begining of the source file.
Expand Down
4 changes: 2 additions & 2 deletions media/src/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ impl Timestamp {
Timestamp4Humans::from_nano(self.0)
}

pub fn get_halfway_to(self, other: Timestamp) -> Timestamp {
pub fn halfway_to(self, other: Timestamp) -> Timestamp {
Timestamp((self.0 + other.0) / 2)
}

pub fn get_sample_index(self, sample_duration: Duration) -> SampleIndex {
pub fn sample_index(self, sample_duration: Duration) -> SampleIndex {
SampleIndex::new((self.0 / sample_duration.as_u64()) as usize)
}

Expand Down
4 changes: 2 additions & 2 deletions media/src/toc_setter_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl TocSetterPipeline {
.map_err(|_| gettext("do you have permission to write the file?"))
}

pub fn get_muxer(&self) -> Option<&gst::Element> {
pub fn muxer(&self) -> Option<&gst::Element> {
self.muxer.as_ref()
}

Expand All @@ -80,7 +80,7 @@ impl TocSetterPipeline {
.map_err(|_| gettext("Could not set media in Playing mode"))
}

pub fn get_current_ts(&self) -> Timestamp {
pub fn current_ts(&self) -> Timestamp {
let mut position_query = gst::query::Position::new(gst::Format::Time);
self.pipeline.query(&mut position_query);
let position = position_query.get_result().get_value();
Expand Down
41 changes: 20 additions & 21 deletions metadata/src/cue_sheet_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ use log::error;

use std::{io::Write, string::ToString};

use super::{get_default_chapter_title, MediaInfo, Timestamp4Humans, TocVisitor, Writer};
use super::{default_chapter_title, MediaInfo, Timestamp4Humans, TocVisitor, Writer};

static EXTENSION: &str = "cue";

pub struct CueSheetFormat {}

impl CueSheetFormat {
pub fn get_extension() -> &'static str {
pub fn extension() -> &'static str {
EXTENSION
}
}

pub fn new_as_boxed() -> Box<Self> {
Box::new(CueSheetFormat {})
impl Default for CueSheetFormat {
fn default() -> Self {
CueSheetFormat {}
}
}

Expand All @@ -39,32 +41,29 @@ impl Writer for CueSheetFormat {
return Err(msg);
}

let media_title = info.get_media_title();
let media_title = info.media_title();
if let Some(title) = &media_title {
write_fmt!(destination, "TITLE \"{}\"\n", title);
}

let media_artist = info.get_media_artist();
let media_artist = info.media_artist();
if let Some(artist) = &media_artist {
write_fmt!(destination, "PERFORMER \"{}\"\n", artist);
}

let audio_codec = info
.streams
.get_audio_codec()
.map_or("WAVE", |audio_codec| {
if audio_codec.to_lowercase().find("mp3").is_some() {
"MP3"
} else if audio_codec.to_lowercase().find("aiff").is_some() {
"AIFF"
} else {
"WAVE"
}
});
let audio_codec = info.streams.audio_codec().map_or("WAVE", |audio_codec| {
if audio_codec.to_lowercase().find("mp3").is_some() {
"MP3"
} else if audio_codec.to_lowercase().find("aiff").is_some() {
"AIFF"
} else {
"WAVE"
}
});
write_fmt!(
destination,
"FILE \"{}\" {}\n",
info.get_file_name(),
info.file_name(),
audio_codec
);

Expand All @@ -82,7 +81,7 @@ impl Writer for CueSheetFormat {
.and_then(|value| value.get().map(ToString::to_string))
})
.or_else(|| media_title.clone())
.unwrap_or_else(get_default_chapter_title);
.unwrap_or_else(default_chapter_title);
write_fmt!(destination, " TITLE \"{}\"\n", &title);

let artist = chapter
Expand All @@ -92,7 +91,7 @@ impl Writer for CueSheetFormat {
.and_then(|value| value.get().map(ToString::to_string))
})
.or_else(|| media_artist.clone())
.unwrap_or_else(get_default_chapter_title);
.unwrap_or_else(default_chapter_title);
write_fmt!(destination, " PERFORMER \"{}\"\n", &artist);

if let Some((start, _end)) = chapter.get_start_stop_times() {
Expand Down
Loading

0 comments on commit 30b5305

Please sign in to comment.