mirror of
https://github.com/ivabus/lonelyradio
synced 2024-11-21 23:55:09 +03:00
Encode PCM the same way as any other encoder
Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
parent
dfb86522fb
commit
3804653512
2 changed files with 7 additions and 35 deletions
|
@ -103,7 +103,7 @@ pub enum Encoder {
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq)]
|
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq)]
|
||||||
pub struct FragmentMetadata {
|
pub struct FragmentMetadata {
|
||||||
// In bytes or samples, depends on encoder: Pcm* - samples, any compressed - bytes
|
// In bytes
|
||||||
#[serde(rename = "le")]
|
#[serde(rename = "le")]
|
||||||
pub length: u64,
|
pub length: u64,
|
||||||
|
|
||||||
|
|
40
src/main.rs
40
src/main.rs
|
@ -102,46 +102,18 @@ async fn stream_track(
|
||||||
let mut _samples = _samples.concat();
|
let mut _samples = _samples.concat();
|
||||||
|
|
||||||
match md.encoder {
|
match md.encoder {
|
||||||
Encoder::Pcm16 => {
|
Encoder::Pcm16
|
||||||
let _md = PlayMessage::F(FragmentMetadata {
|
| Encoder::PcmFloat
|
||||||
length: _samples.len() as u64 * 2,
|
| Encoder::Flac
|
||||||
magic_cookie: None,
|
| Encoder::Alac
|
||||||
});
|
| Encoder::Vorbis => {
|
||||||
if s.write_all(rmp_serde::to_vec(&_md).unwrap().as_slice()).is_err() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if s.write_all(
|
|
||||||
&encode(Encoder::Pcm16, _samples, md.sample_rate, md.channels).unwrap().0,
|
|
||||||
)
|
|
||||||
.is_err()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Encoder::PcmFloat => {
|
|
||||||
let _md = PlayMessage::F(FragmentMetadata {
|
|
||||||
length: _samples.len() as u64 * 4,
|
|
||||||
magic_cookie: None,
|
|
||||||
});
|
|
||||||
if s.write_all(rmp_serde::to_vec(&_md).unwrap().as_slice()).is_err() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if s.write_all(
|
|
||||||
&encode(Encoder::PcmFloat, _samples, md.sample_rate, md.channels).unwrap().0,
|
|
||||||
)
|
|
||||||
.is_err()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Encoder::Flac | Encoder::Alac | Encoder::Vorbis => {
|
|
||||||
let (encoded, magic_cookie) =
|
let (encoded, magic_cookie) =
|
||||||
encode(md.encoder, _samples, md.sample_rate, md.channels).unwrap();
|
encode(md.encoder, _samples, md.sample_rate, md.channels).unwrap();
|
||||||
let _md = PlayMessage::F(FragmentMetadata {
|
let _md = PlayMessage::F(FragmentMetadata {
|
||||||
length: encoded.as_slice().len() as u64,
|
length: encoded.as_slice().len() as u64,
|
||||||
magic_cookie,
|
magic_cookie,
|
||||||
});
|
});
|
||||||
if s.write_all(rmp_serde::to_vec(&_md).unwrap().as_slice()).is_err() {
|
if s.write_all(rmp_serde::to_vec_named(&_md).unwrap().as_slice()).is_err() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if s.write_all(encoded.as_slice()).is_err() {
|
if s.write_all(encoded.as_slice()).is_err() {
|
||||||
|
|
Loading…
Reference in a new issue