Skip to content

Commit

Permalink
feat: add duration_ms to compose record result (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
giangndm authored Nov 13, 2024
1 parent 436d7ea commit f61ecd2
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/user-guide/features/recording.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ message ComposeEvent {
message ComposeSummary {
string media_uri = 1;
uint64 duration_ms = 2;
}
TransmuxSummary transmux = 1;
Expand Down
5 changes: 4 additions & 1 deletion packages/media_record/bin/convert_record_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ impl HttpApis {
log::info!("Convert job {job_id_c} completed");
compose_event::Event::Completed(RecordJobCompleted {
transmux: summary.transmux.map(|s| s.into()),
compose: summary.compose.map(|s| ComposeSummary { media_uri: s }),
compose: summary.compose.map(|s| ComposeSummary {
media_uri: s.media_uri,
duration_ms: s.duration_ms,
}),
})
}
Err(e) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/media_record/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct RecordConvertConfig {
#[derive(Debug, Clone)]
pub struct RecordConvertOutput {
pub transmux: Option<TransmuxSummary>,
pub compose: Option<String>,
pub compose: Option<RecordComposerResult>,
}

pub struct RecordConvert {
Expand Down
4 changes: 4 additions & 0 deletions packages/media_record/src/convert/codec/vpx_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ impl<W: Write + Seek> VpxWriter<W> {
last_ts: start_ts,
}
}

pub fn duration(&self) -> u64 {
self.last_ts - self.start_ts
}
}

impl<W: Write + Seek> CodecWriter for VpxWriter<W> {
Expand Down
18 changes: 13 additions & 5 deletions packages/media_record/src/convert/composer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ impl Ord for SessionWrapper {
}
}

#[derive(Debug, Clone)]
pub struct RecordComposerResult {
pub media_uri: String,
pub duration_ms: u64,
}

pub struct RecordComposer {
audio: bool,
video: bool,
Expand Down Expand Up @@ -111,7 +117,7 @@ impl RecordComposer {
}
}

pub async fn compose(mut self) -> Result<String, String> {
pub async fn compose(mut self) -> Result<RecordComposerResult, String> {
let (s3, credentials, s3_sub_folder) = convert_s3_uri(&self.in_s3).map_err(|e| e.to_string())?;

let room_reader = RoomReader::new(s3, credentials, &s3_sub_folder);
Expand Down Expand Up @@ -208,16 +214,18 @@ impl RecordComposer {
}
}

self.track_writer.take();
let track_writer = self.track_writer.take().ok_or("record empty".to_string())?;
let duration_ms = track_writer.duration();

if let Some(out_s3) = self.out_s3.take() {
surf::put(&out_s3)
.body(Body::from_file(&self.out_local_path).await.map_err(|e| e.to_string())?)
.await
.map_err(|e| e.to_string())?;
Ok(self.out_relative)
} else {
Ok(self.out_relative)
}
Ok(RecordComposerResult {
media_uri: self.out_relative,
duration_ms,
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ impl<TID: Hash + Eq + Copy> MixerBuffer<TID> {

impl<T> Drop for MixerBuffer<T> {
fn drop(&mut self) {
log::warn!("drop audio mixer buffer with remaining {} frames", self.frames.len());
if !self.frames.is_empty() {
log::warn!("drop audio mixer buffer with remaining {} frames", self.frames.len());
}
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/protocol/proto/cluster/connector.proto
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ message ComposeEvent {

message ComposeSummary {
string media_uri = 1;
uint64 duration_ms = 2;
}

TransmuxSummary transmux = 1;
Expand Down
2 changes: 2 additions & 0 deletions packages/protocol/src/protobuf/cluster_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ pub mod compose_event {
pub struct ComposeSummary {
#[prost(string, tag = "1")]
pub media_uri: ::prost::alloc::string::String,
#[prost(uint64, tag = "2")]
pub duration_ms: u64,
}
}
#[derive(serde::Serialize)]
Expand Down

0 comments on commit f61ecd2

Please sign in to comment.