Skip to content

Commit

Permalink
some fix
Browse files Browse the repository at this point in the history
  • Loading branch information
harlanc authored and hailiang8 committed Jan 24, 2024
1 parent ca583fc commit ae363d1
Show file tree
Hide file tree
Showing 10 changed files with 652 additions and 690 deletions.
6 changes: 5 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions library/container/flv/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ pub enum MpegErrorValue {
ShouldNotComeHere,
#[fail(display = "the sps nal unit type is not correct")]
SPSNalunitTypeNotCorrect,
#[fail(display = "not supported sampling frequency")]
NotSupportedSamplingFrequency,
}
#[derive(Debug)]
pub struct Mpeg4AvcHevcError {
Expand Down
34 changes: 34 additions & 0 deletions library/container/flv/src/mpeg4_aac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,40 @@ pub struct Mpeg4Aac {
}

impl Mpeg4Aac {
pub fn new(
object_type: u8,
sampling_frequency: u32,
channel_configuration: u8,
) -> Result<Self, MpegAacError> {
let sampling_frequency_index = match sampling_frequency {
96000 => 0,
88200 => 1,
64000 => 2,
48000 => 3,
44100 => 4,
32000 => 5,
24000 => 6,
22050 => 7,
16000 => 8,
12000 => 9,
11025 => 10,
8000 => 11,
7350 => 12,
_ => {
return Err(MpegAacError {
value: MpegErrorValue::NotSupportedSamplingFrequency,
});
}
};

Ok(Self {
object_type,
sampling_frequency_index,
channel_configuration,
sampling_frequency,
..Default::default()
})
}
// 11 90
// 00010 0011 0010 000
// 2 3 2
Expand Down
14 changes: 13 additions & 1 deletion library/streamhub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,19 @@ impl Transmitter {
}
}
}
FrameData::MediaInfo { media_info: _ } => {}
FrameData::MediaInfo { media_info: info_value } => {
let data = FrameData::MediaInfo {
media_info: info_value
};
for (_, v) in frame_senders.lock().await.iter() {
if let Err(media_err) = v.send(data.clone()).map_err(|_| ChannelError {
value: ChannelErrorValue::SendVideoError,
}) {
log::error!("Transmiter send error: {}", media_err);
}
}

}
}
}
}
Expand Down
19 changes: 7 additions & 12 deletions protocol/rtmp/src/remuxer/whip2rtmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct Whip2RtmpRemuxerSession {
subscribe_id: Uuid,
video_clock_rate: u32,
audio_clock_rate: u32,
//because
base_video_timestamp: u32,
base_audio_timestamp: u32,

Expand Down Expand Up @@ -84,8 +85,8 @@ impl Whip2RtmpRemuxerSession {

subscribe_id: Uuid::new(RandomDigitCount::Four),
publishe_id: Uuid::new(RandomDigitCount::Four),
video_clock_rate: 90000,
audio_clock_rate: 48000,
video_clock_rate: 1000,
audio_clock_rate: 1000,
base_audio_timestamp: 0,
base_video_timestamp: 0,
rtmp_handler: Common::new(None, event_producer, SessionType::Server, None),
Expand Down Expand Up @@ -187,7 +188,7 @@ impl Whip2RtmpRemuxerSession {

pub async fn receive_whip_data(&mut self) -> Result<(), RtmpRemuxerError> {
let mut retry_count = 0;

log::info!("begin receive whip data...");
loop {
if let Some(data) = self.data_receiver.recv().await {
match data {
Expand Down Expand Up @@ -246,6 +247,7 @@ impl Whip2RtmpRemuxerSession {

let timestamp_adjust =
(timestamp - self.base_audio_timestamp) / (self.audio_clock_rate / 1000);

self.rtmp_handler
.on_audio_data(&mut audio_frame, &timestamp_adjust)
.await?;
Expand All @@ -258,8 +260,6 @@ impl Whip2RtmpRemuxerSession {
nalus: &mut BytesMut,
timestamp: u32,
) -> Result<(), RtmpRemuxerError> {
// print(nalus.clone());
// log::info!("on_whip_video begin");
if self.base_video_timestamp == 0 {
self.base_video_timestamp = timestamp;
}
Expand Down Expand Up @@ -297,26 +297,20 @@ impl Whip2RtmpRemuxerSession {
let nalu_type = nalu_reader.read_u8()?;
match nalu_type & 0x1F {
H264_NAL_SPS => {
log::info!("on_whip_video: sps");
let mut sps_parser = SpsParser::new(nalu_reader);
(width, height) = if let Ok((width, height)) = sps_parser.parse() {
(width, height)
} else {
(0, 0)
};

log::info!("width:{}x{}", width, height);
level = sps_parser.sps.level_idc;
profile = sps_parser.sps.profile_idc;

self.sps = Some(nalu.clone());
}
H264_NAL_PPS => {
log::info!("on_whip_video: pps");
self.pps = Some(nalu.clone())
}
H264_NAL_PPS => self.pps = Some(nalu.clone()),
H264_NAL_IDR => {
log::info!("on_whip_video: key");
contains_idr = true;
}
_ => {}
Expand All @@ -342,6 +336,7 @@ impl Whip2RtmpRemuxerSession {

let timestamp_adjust =
(timestamp - self.base_video_timestamp) / (self.video_clock_rate / 1000);

self.rtmp_handler
.on_video_data(&mut frame_data, &timestamp_adjust)
.await?;
Expand Down
3 changes: 1 addition & 2 deletions protocol/webrtc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ failure = "0.1.1"
log = "0.4"
webrtc = "0.8.0"
async-trait = "0.1.70"
# fdk-aac = "0.5.0"
fdk-aac = "0.6.0"
opus = "0.3.0"
hex = "0.4.3"

Expand All @@ -28,4 +28,3 @@ bytesio = { path = "../../library/bytesio/" }
streamhub = { path = "../../library/streamhub/" }

xflv = { path = "../../library/container/flv" }
fdk-aac = { path = "/Users/zexu/github/fdk-aac-rs" }
15 changes: 15 additions & 0 deletions protocol/webrtc/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use {
fdk_aac::enc::EncoderError as AacEncoderError,
opus::Error as OpusError,
std::fmt,
std::num::ParseIntError,
webrtc::error::Error as RTCError,
webrtc::util::Error as RTCUtilError,
};
Expand All @@ -18,10 +19,16 @@ pub enum WebRTCErrorValue {
RTCError(#[cause] RTCError),
#[fail(display = "webrtc util error: {}", _0)]
RTCUtilError(#[cause] RTCUtilError),
#[fail(display = "webrtc util error: {}", _0)]
ParseIntError(#[cause] ParseIntError),
#[fail(display = "cannot get local description")]
CanNotGetLocalDescription,
#[fail(display = "opus2aac error")]
Opus2AacError,
#[fail(display = "missing whitespace")]
MissingWhitespace,
#[fail(display = "missing colon")]
MissingColon,
}

impl From<RTCError> for WebRTCError {
Expand All @@ -40,6 +47,14 @@ impl From<RTCUtilError> for WebRTCError {
}
}

impl From<ParseIntError> for WebRTCError {
fn from(error: ParseIntError) -> Self {
WebRTCError {
value: WebRTCErrorValue::ParseIntError(error),
}
}
}

impl fmt::Display for WebRTCError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.value, f)
Expand Down
Loading

0 comments on commit ae363d1

Please sign in to comment.