Skip to content

Commit 8cdd72e

Browse files
committed
- Default filenames are now millisecond time stamps
- API endpoint and path now picked from .env
1 parent 8bc9078 commit 8cdd72e

File tree

8 files changed

+38
-18
lines changed

8 files changed

+38
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/target
22
Cargo.lock
3+
.env

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ gstreamer-video = "0.17.2"
1313
num-rational = "0.4.0"
1414

1515
home = "0.5.3"
16-
chrono = "0.4"
16+
17+
18+
[build-dependencies]
19+
dotenv-build = "0.1"

build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
// getting environment variables from .env
3+
dotenv_build::output(dotenv_build::Config::default()).unwrap();
4+
}

src/constants.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,3 @@ pub const VERSION: &str = "0.1.1";
66
/* App constants */
77
pub const CONFIG_FILE_NAME: &str = "spur_config.txt";
88
pub const VIDEOS_FOLDER_FROM_HOME: &str = "Videos/spur";
9-
pub const STREAM_API: &str = "rtmp://someendpoint:1935"; // todo : get from env
10-
pub const STREAM_API_PATH: &str = "live"; // todo : get from env

src/parser.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ use crate::{
66
Config,
77
};
88
use clap::{Arg, ArgMatches, Command};
9-
use std::{fs, io::Write, process, str::FromStr};
9+
use std::{
10+
fs,
11+
io::Write,
12+
process,
13+
str::FromStr,
14+
time::{SystemTime, UNIX_EPOCH},
15+
};
1016

1117
/* Utils */
12-
// use chrono;
13-
1418
fn create_sub_command(st: SType) -> Command<'static> {
1519
Command::new(st.get_name()).args([
1620
overlay::create_arg(),
@@ -26,13 +30,24 @@ fn create_sub_command(st: SType) -> Command<'static> {
2630

2731
pub fn get_filename_from_arg(st: SType, arg_filename: Option<&str>) -> String {
2832
let name = match arg_filename {
29-
Some(fname) => fname,
30-
// None => format!("{:?}", chrono::offset::Utc::now()).as_str(), // todo : generate from datetime
31-
None => "123", // todo : generate from datetime
33+
Some(fname) => String::from(fname),
34+
None => {
35+
// Getting millisecond timestamp
36+
// https://stackoverflow.com/a/44378174/11565176
37+
let start = SystemTime::now();
38+
let since_the_epoch = start
39+
.duration_since(UNIX_EPOCH)
40+
.expect("Time went backwards");
41+
format!(
42+
"{:?}",
43+
since_the_epoch.as_secs() * 1000
44+
+ since_the_epoch.subsec_nanos() as u64 / 1_000_000
45+
)
46+
}
3247
};
3348
match st {
3449
SType::Record => format!("{}.mkv", name),
35-
SType::Stream => format!("/{}/{}", constants::STREAM_API_PATH, name),
50+
SType::Stream => format!("/{}/{}", env!("STREAM_API_PATH"), name),
3651
}
3752
}
3853

src/paths.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,5 @@ pub fn get_video_path(filename: &String) -> PathBuf {
2323
}
2424

2525
pub fn get_stream_path(filename: &String) -> String {
26-
// todo: gets api from environment variables
27-
let mut path = String::from(constants::STREAM_API);
28-
path.push_str(filename);
29-
path
26+
format!("{}{}", env!("STREAM_API"), filename)
3027
}

src/session.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Session {
4343
task_obj.start_pipeline();
4444
return Task::Record(task_obj);
4545
} else {
46-
// self.s_type == SType::Stream {
46+
println!("Stream does not currently work");
4747
let mut task_obj = Streamer::new(conf.clone());
4848
task_obj.create_pipeline();
4949
task_obj.start_pipeline();
@@ -58,6 +58,7 @@ impl Session {
5858
return Task::Overlay(task_obj);
5959
}
6060
pub fn start(&mut self) {
61+
// println!("{:?}", self); // DEBUG
6162
self.tasks.push(self.start_media_pipeline());
6263
if self.overlay {
6364
self.tasks.push(self.start_overlay_pipeline());

src/streamer.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,16 @@ impl Media for Streamer {
197197
&muxer,
198198
Some(muxer_video_sink_pad.name().as_str()),
199199
)
200-
.unwrap(); // Video to muxer // TODO (probably overcomlicating): use `link_pad` with sync handler
201-
// encoder_audio.link_pads(Some(audio_pipeline_source_pad.name().as_str()), &muxer, Some(muxer_audio_sink_pad.name().as_str())).unwrap(); // Audio to muxer // TODO (probably overcomlicating): use `link_pad` with sync handler
200+
.unwrap(); // Video to muxer // TODO (probably overcomplicating): use `link_pad` with sync handler
201+
202+
// encoder_audio.link_pads(Some(audio_pipeline_source_pad.name().as_str()), &muxer, Some(muxer_audio_sink_pad.name().as_str())).unwrap(); // Audio to muxer // TODO (probably overcomplicating): use `link_pad` with sync handler
202203
queue_audio
203204
.link_pads(
204205
Some(audio_pipeline_source_pad.name().as_str()),
205206
&muxer,
206207
Some(muxer_audio_sink_pad.name().as_str()),
207208
)
208-
.unwrap(); // Audio to muxer // TODO (probably overcomlicating): use `link_pad` with sync handler
209+
.unwrap(); // Audio to muxer // TODO (probably overcomplicating): use `link_pad` with sync handler
209210

210211
self.pipeline = Some(main_pipeline)
211212
}

0 commit comments

Comments
 (0)