Skip to content

Commit

Permalink
fix some errors for cross compile on github action
Browse files Browse the repository at this point in the history
  • Loading branch information
harlanc committed Feb 27, 2024
1 parent dce1a72 commit 0b822bf
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
13 changes: 13 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[target.x86_64-unknown-linux-musl]
rustflags = ["-C", "link-args=-lm"]

[target.aarch64-unknown-linux-musl]
rustflags = ["-C", "link-args=-std=c99 -lm"]

[target.armv7-unknown-linux-musleabihf]
rustflags = ["-C", "link-args=-lm"]

[target.arm-unknown-linux-musleabihf]
rustflags = ["-C", "link-args=-lm"]


3 changes: 2 additions & 1 deletion library/streamhub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ rand = "0.8"
log = "0.4"
chrono = "0.4"
indexmap = "1.9.3"
reqwest = "0.11.14"
#use vendored feature to enable cross compile for openssl
reqwest = {version = "0.11.24",features = ["native-tls-vendored"]}
async-trait = "0.1.70"
serde_json = { version = "1", default-features = false, features = [
"alloc",
Expand Down
4 changes: 2 additions & 2 deletions protocol/webrtc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ bytes = "1.0.0"
tokio = "1.4.0"
failure = "0.1.1"
log = "0.4"
webrtc = "0.8.0"
webrtc = "0.10.1"
async-trait = "0.1.70"
fdk-aac = "0.6.0"
opus = "0.3.0"
audiopus = "0.3.0-rc.0"

bytesio = { path = "../../library/bytesio/" }
streamhub = { path = "../../library/streamhub/" }
Expand Down
2 changes: 1 addition & 1 deletion protocol/webrtc/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use {
audiopus::error::Error as OpusError,
failure::{Backtrace, Fail},
fdk_aac::enc::EncoderError as AacEncoderError,
opus::Error as OpusError,
std::fmt,
std::num::ParseIntError,
webrtc::error::Error as RTCError,
Expand Down
22 changes: 15 additions & 7 deletions protocol/webrtc/src/opus2aac.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::errors::Opus2AacError;
use audiopus::coder::Decoder as OpusDecoder;
use audiopus::MutSignals;
use fdk_aac::enc::{Encoder as AacEncoder, EncoderParams};
use opus::Decoder as OpusDecoder;
pub struct Opus2AacTranscoder {
decoder_channels_size: usize,
decoder: OpusDecoder,
Expand All @@ -10,12 +11,15 @@ pub struct Opus2AacTranscoder {

impl Opus2AacTranscoder {
pub fn new(
decoder_sample_rate: u32,
decoder_channels: opus::Channels,
decoder_sample_rate: i32,
decoder_channels: audiopus::Channels,
encoder_sample_rate: u32,
encoder_channels: fdk_aac::enc::ChannelMode,
) -> Result<Self, Opus2AacError> {
let decoder = OpusDecoder::new(decoder_sample_rate, decoder_channels)?;
let decoder = OpusDecoder::new(
audiopus::SampleRate::try_from(decoder_sample_rate)?,
decoder_channels,
)?;
let encoder = AacEncoder::new(EncoderParams {
bit_rate: fdk_aac::enc::BitRate::VbrMedium,
transport: fdk_aac::enc::Transport::Raw,
Expand All @@ -24,8 +28,8 @@ impl Opus2AacTranscoder {
})?;

let decoder_channels_size = match decoder_channels {
opus::Channels::Stereo => 2,
opus::Channels::Mono => 1,
audiopus::Channels::Stereo | audiopus::Channels::Auto => 2,
audiopus::Channels::Mono => 1,
};

Ok(Opus2AacTranscoder {
Expand All @@ -39,7 +43,11 @@ impl Opus2AacTranscoder {
pub fn transcode(&mut self, input: &[u8]) -> Result<Vec<Vec<u8>>, Opus2AacError> {
//https://opus-codec.org/docs/opus_api-1.1.2/group__opus__decoder.html#ga7d1111f64c36027ddcb81799df9b3fc9
let mut pcm_output: Vec<i16> = vec![0; 1024 * 2];
let pcm_output_len = self.decoder.decode(input, &mut pcm_output[..], false)?;
let input_packet = audiopus::packet::Packet::try_from(input)?;
let mut_signals = MutSignals::try_from(&mut pcm_output)?;
let pcm_output_len = self
.decoder
.decode(Some(input_packet), mut_signals, false)?;
self.pcm_data
.extend_from_slice(&pcm_output[..pcm_output_len * self.decoder_channels_size]);

Expand Down
10 changes: 5 additions & 5 deletions protocol/webrtc/src/whip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ pub async fn handle_whip(
let mut vcodec: VideoCodecType = VideoCodecType::H264;
let mut opus2aac_transcoder = Opus2AacTranscoder::new(
48000,
opus::Channels::Stereo,
audiopus::Channels::Stereo,
48000,
fdk_aac::enc::ChannelMode::Stereo,
)
Expand All @@ -212,13 +212,13 @@ pub async fn handle_whip(
audio_codec = codec;
let channels =
match audio_codec.encoding_parameters.as_str() {
"1" => opus::Channels::Mono,
"2" => opus::Channels::Stereo,
_ => opus::Channels::Stereo,
"1" => audiopus::Channels::Mono,
"2" => audiopus::Channels::Stereo,
_ => audiopus::Channels::Stereo,
};

opus2aac_transcoder = Opus2AacTranscoder::new(
audio_codec.clock_rate,
audio_codec.clock_rate as i32,
channels,
audio_codec.clock_rate,
fdk_aac::enc::ChannelMode::Stereo,
Expand Down

0 comments on commit 0b822bf

Please sign in to comment.