Skip to content

Commit

Permalink
fix RTMP publish single AAC from ffmpeg client.
Browse files Browse the repository at this point in the history
  • Loading branch information
suzp1984 committed Mar 28, 2024
1 parent d3a9bbf commit 437d489
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
12 changes: 11 additions & 1 deletion library/container/flv/src/mpeg4_aac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,17 @@ impl Mpeg4AacProcessor {
0xF0 /* 12-syncword */ | (id << 3)/*1-ID*/| 0x01, /*1-protection_absent*/
)?; //1

let profile = self.mpeg4_aac.object_type;
// workaround: profile - 1 overflow error. If profile == 0:reserved, then force
// profile to 2:AAC_LC.
// If publish pure AAC file to RTMP by ffmpeg, the AAC object type is 0:reserved,
// If publish a opus file to RTMP, ffmpeg will convert opus to aac, then use FLV as container,
// the object type is normal 2:AAC_LC.
let profile = if self.mpeg4_aac.object_type > 0 {
self.mpeg4_aac.object_type
} else {
2
};

let sampling_frequency_index = self.mpeg4_aac.sampling_frequency_index;
let channel_configuration = self.mpeg4_aac.channel_configuration;
self.bytes_writer.write_u8(
Expand Down
5 changes: 5 additions & 0 deletions library/streamhub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ impl StreamDataTransceiver {
data: _,
} => {}
FrameData::Audio { timestamp, data } => {
if data.len() <= 4 {
log::info!("ignore received Audio Frame with len {}", data.len());
return;
}

let data = FrameData::Audio {
timestamp,
data: data.clone(),
Expand Down
9 changes: 7 additions & 2 deletions protocol/hls/src/flv2hls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ impl Flv2HlsRemuxer {
pub fn process_flv_data(&mut self, data: FlvData) -> Result<(), MediaError> {
let flv_demux_data: FlvDemuxerData = match data {
FlvData::Audio { timestamp, data } => {
let audio_data = self.audio_demuxer.demux(timestamp, data)?;
FlvDemuxerData::Audio { data: audio_data }
if data.len() > 4 {
// log::error!("process_flv_data len={}", data.len());
let audio_data = self.audio_demuxer.demux(timestamp, data)?;
FlvDemuxerData::Audio { data: audio_data }
} else {
return Ok(());
}
}
FlvData::Video { timestamp, data } => {
if let Some(video_data) = self.video_demuxer.demux(timestamp, data)? {
Expand Down
8 changes: 5 additions & 3 deletions protocol/rtmp/src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub struct Cache {

impl Cache {
pub fn new(gop_num: usize, statistic_data_sender: Option<StatisticDataSender>) -> Self {

Cache {
metadata: metadata::MetaData::new(),
metadata_timestamp: 0,
Expand Down Expand Up @@ -78,7 +77,10 @@ impl Cache {
let mut reader = BytesReader::new(chunk_body.clone());
let tag_header = AudioTagHeader::unmarshal(&mut reader)?;

if tag_header.sound_format == define::SoundFormat::AAC as u8
let remain_bytes = reader.extract_remaining_bytes();

if remain_bytes.len() >= 2
&& tag_header.sound_format == define::SoundFormat::AAC as u8
&& tag_header.aac_packet_type == define::aac_packet_type::AAC_SEQHDR
{
self.audio_seq = chunk_body.clone();
Expand All @@ -88,7 +90,7 @@ impl Cache {
let mut aac_processor = Mpeg4AacProcessor::default();

let aac = aac_processor
.extend_data(reader.extract_remaining_bytes())
.extend_data(remain_bytes)
.audio_specific_config_load()?;

let statistic_audio_codec = StatisticData::AudioCodec {
Expand Down

0 comments on commit 437d489

Please sign in to comment.