fix audio no sound, add missing VideoFrame timestamp

move get_time to hbb_common

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2022-09-11 21:46:53 +08:00
parent 302a43d68c
commit 42d17f9d2b
8 changed files with 30 additions and 26 deletions

View File

@@ -228,6 +228,14 @@ pub fn get_uuid() -> Vec<u8> {
Config::get_key_pair().1
}
#[inline]
pub fn get_time() -> i64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|d| d.as_millis())
.unwrap_or(0) as _
}
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -4,10 +4,11 @@ use crate::{
};
use hbb_common::{
anyhow::{anyhow, Context},
bytes::Bytes,
config::HwCodecConfig,
lazy_static, log,
get_time, lazy_static, log,
message_proto::{EncodedVideoFrame, EncodedVideoFrames, Message, VideoFrame},
ResultType, bytes::Bytes,
ResultType,
};
use hwcodec::{
decode::{DecodeContext, DecodeFrame, Decoder},
@@ -105,6 +106,7 @@ impl EncoderApi for HwEncoder {
DataFormat::H264 => vf.set_h264s(frames),
DataFormat::H265 => vf.set_h265s(frames),
}
vf.timestamp = get_time();
msg_out.set_video_frame(vf);
Ok(msg_out)
} else {

View File

@@ -4,15 +4,15 @@
use hbb_common::anyhow::{anyhow, Context};
use hbb_common::message_proto::{EncodedVideoFrame, EncodedVideoFrames, Message, VideoFrame};
use hbb_common::ResultType;
use hbb_common::{ResultType, get_time};
use crate::codec::EncoderApi;
use crate::STRIDE_ALIGN;
use super::vpx::{vp8e_enc_control_id::*, vpx_codec_err_t::*, *};
use hbb_common::bytes::Bytes;
use std::os::raw::{c_int, c_uint};
use std::{ptr, slice};
use hbb_common::bytes::Bytes;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum VpxVideoCodecId {
@@ -285,6 +285,7 @@ impl VpxEncoder {
frames: vp9s.into(),
..Default::default()
});
vf.timestamp = get_time();
msg_out.set_video_frame(vf);
msg_out
}