Skip to content

feat(example): encode audio with Opus#643

Merged
Benoît Cortier (CBenoit) merged 1 commit intoDevolutions:masterfrom
elmarco:opus
Jan 27, 2025
Merged

feat(example): encode audio with Opus#643
Benoît Cortier (CBenoit) merged 1 commit intoDevolutions:masterfrom
elmarco:opus

Conversation

@elmarco
Copy link
Copy Markdown
Contributor

Demonstrates Opus audio codec support (and also fixes sine wave phase)

Copy link
Copy Markdown
Member

@CBenoit Benoît Cortier (CBenoit) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Comment thread crates/ironrdp/examples/server.rs Outdated
let mut data = generate_sine_wave(fmt.n_samples_per_sec, 440.0, 20, &mut phase);

if let Some(ref mut enc) = opus_enc {
let input = unsafe { slice::from_raw_parts(data.as_ptr() as *const i16, data.len() / 2) };
Copy link
Copy Markdown
Member

@CBenoit Benoît Cortier (CBenoit) Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: My typical suggestion for this kind of code is to go with the bytemuck crate instead of writing the unsafe code each time; or to make a copy of the data. The latter solution is obviously less performant, but does not require an additional dependency. (I’m almost sure bytemuck is already to be found somewhere in our stack though.)

Otherwise, you need to ensure the alignment is correct and provide a convincing safety comment describing how the code is correct.

   error: unsafe block missing a safety comment
     --> crates/ironrdp/examples/server.rs:331:33
      |
  331 |                     let input = unsafe { slice::from_raw_parts(data.as_ptr() as *const i16, data.len() / 2) };
      |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = help: consider adding a safety comment on the preceding line
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks
      = note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings`
      = help: to override `-D warnings` add `#[allow(clippy::undocumented_unsafe_blocks)]`
  
  error: casting from `*const u8` to a more-strictly-aligned pointer (`*const i16`) (1 < 2 bytes)
     --> crates/ironrdp/examples/server.rs:331:64
      |
  331 |                     let input = unsafe { slice::from_raw_parts(data.as_ptr() as *const i16, data.len() / 2) };
      |                                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_ptr_alignment
      = note: `-D clippy::cast-ptr-alignment` implied by `-D warnings`
      = help: to override `-D warnings` add `#[allow(clippy::cast_ptr_alignment)]`
  
  error: could not compile `ironrdp` (example "server") due to 2 previous errors

@CBenoit
Copy link
Copy Markdown
Member

Benoît Cortier (CBenoit) commented Jan 27, 2025

Lints step is failed.

Demonstrates Opus audio codec support (and also fixes sine wave phase)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants