Skip to content

Commit ffdea02

Browse files
authored
ndk/native_window: Add missing function wrappers (#425)
* ndk/native_window: Add `set_buffers_transform()` API This was added to the NDK with API level 26 but never made it to Rust. Allows the user to apply mirror and rotation effects. * ndk/native_window: Add `try_allocate_buffers()` API * ndk/native_window: Add `set_frame_rate*()` APIs since level 30/31
1 parent eb445c6 commit ffdea02

File tree

5 files changed

+216
-44
lines changed

5 files changed

+216
-44
lines changed

ndk/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- event: Add `tool_type` getter for `Pointer`. (#323)
66
- input_queue: Allow any non-zero return code from `pre_dispatch()` again, as per documentation. (#325)
77
- asset: Use entire asset length when mapping buffer. (#387)
8-
- Bump MSRV to 1.66 for `raw-window-handle 0.5.1`, `num_enum`'s `catch_all` with arbitrary enum discriminants. (#388,#431)
8+
- Bump MSRV to 1.66 for `raw-window-handle 0.5.1`, `num_enum`'s `catch_all` with arbitrary enum discriminants. (#388, #431)
99
- Bump optional `jni` dependency for doctest example from `0.19` to `0.21`. (#390)
1010
- **Breaking:** Upgrade to [`ndk-sys 0.5.0`](../ndk-sys/CHANGELOG.md#050-TODO). (#370)
1111
- **Breaking:** Upgrade `bitflags` crate from `1` to `2`. (#394)
@@ -25,6 +25,7 @@
2525
- **Breaking:** Use `BorrowedFd` and `OwnedFd` to clarify possible ownership transitions. (#417)
2626
- **Breaking:** Upgrade to [`ndk-sys 0.5.0`](../ndk-sys/CHANGELOG.md#050-beta0-2023-08-15). (#420)
2727
- **Breaking:** bitmap: Provide detailed implementation for `AndroidBitmapInfoFlags`. (#424)
28+
- ndk/native_window: Add `set_buffers_transform()`, `try_allocate_buffers()` and `set_frame_rate*()`. (#425)
2829
- hardware_buffer: Add `id()` to retrieve a system-wide unique identifier for a `HardwareBuffer`. (#428)
2930

3031
# 0.7.0 (2022-07-24)

ndk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repository = "https://github.com/rust-mobile/ndk"
1313
rust-version = "1.66"
1414

1515
[features]
16-
all = ["audio", "bitmap","media", "api-level-30"]
16+
all = ["audio", "bitmap","media", "api-level-31"]
1717

1818
audio = ["ffi/audio", "api-level-26"]
1919
bitmap = ["ffi/bitmap"]

ndk/src/audio.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,9 @@ impl AudioStreamBuilder {
451451
///
452452
/// Available since API level 29.
453453
///
454-
/// # Arguments
454+
/// # Parameters
455455
///
456-
/// * `policy` - the desired level of opt-out from being captured.
456+
/// - `policy`: the desired level of opt-out from being captured.
457457
///
458458
/// [`android.media.AudioAttributes#setAllowedCapturePolicy(int)`]: https://developer.android.com/reference/android/media/AudioAttributes.Builder#setAllowedCapturePolicy(int)
459459
#[cfg(feature = "api-level-29")]
@@ -474,9 +474,9 @@ impl AudioStreamBuilder {
474474
///
475475
/// Available since API level 26.
476476
///
477-
/// # Arguments
477+
/// # Parameters
478478
///
479-
/// * `num_frames` - the desired buffer capacity in frames or 0 for unspecified
479+
/// - `num_frames`: the desired buffer capacity in frames or 0 for unspecified
480480
pub fn buffer_capacity_in_frames(self, num_frames: i32) -> Self {
481481
unsafe { ffi::AAudioStreamBuilder_setBufferCapacityInFrames(self.as_ptr(), num_frames) };
482482
self
@@ -494,9 +494,9 @@ impl AudioStreamBuilder {
494494
///
495495
/// Available since API level 26.
496496
///
497-
/// # Arguments
497+
/// # Parameters
498498
///
499-
/// * `channel_count` - Number of channels desired.
499+
/// - `channel_count`: Number of channels desired.
500500
pub fn channel_count(self, channel_count: i32) -> Self {
501501
unsafe { ffi::AAudioStreamBuilder_setChannelCount(self.as_ptr(), channel_count) };
502502
self
@@ -512,9 +512,9 @@ impl AudioStreamBuilder {
512512
///
513513
/// Available since API level 28.
514514
///
515-
/// # Arguments
515+
/// # Parameters
516516
///
517-
/// * `content_type` - the type of audio data, eg. [`AudioContentType::Speech`]
517+
/// - `content_type`: the type of audio data, eg. [`AudioContentType::Speech`]
518518
#[cfg(feature = "api-level-28")]
519519
pub fn content_type(self, content_type: AudioContentType) -> Self {
520520
unsafe {
@@ -605,9 +605,9 @@ impl AudioStreamBuilder {
605605
///
606606
/// Available since API level 26.
607607
///
608-
/// # Arguments
608+
/// # Parameters
609609
///
610-
/// * `device_id` - device identifier or 0 for unspecified
610+
/// - `device_id`: device identifier or 0 for unspecified
611611
pub fn device_id(self, device_id: i32) -> Self {
612612
unsafe { ffi::AAudioStreamBuilder_setDeviceId(self.as_ptr(), device_id) };
613613
self
@@ -619,9 +619,9 @@ impl AudioStreamBuilder {
619619
///
620620
/// Available since API level 26.
621621
///
622-
/// # Arguments
622+
/// # Parameters
623623
///
624-
/// * `direction` - [`Output`][AudioDirection::Output] or [`Input`][AudioDirection::Input]
624+
/// - `direction`: [`Output`][AudioDirection::Output] or [`Input`][AudioDirection::Input]
625625
pub fn direction(self, direction: AudioDirection) -> Self {
626626
unsafe {
627627
ffi::AAudioStreamBuilder_setDirection(
@@ -695,9 +695,9 @@ impl AudioStreamBuilder {
695695
///
696696
/// Available since API level 26.
697697
///
698-
/// # Arguments
698+
/// # Parameters
699699
///
700-
/// * `format` - the sample data format.
700+
/// - `format`: the sample data format.
701701
pub fn format(self, format: AudioFormat) -> Self {
702702
unsafe {
703703
ffi::AAudioStreamBuilder_setFormat(self.as_ptr(), format as ffi::aaudio_format_t)
@@ -727,7 +727,7 @@ impl AudioStreamBuilder {
727727
///
728728
/// Available since API level 26.
729729
///
730-
/// * `num_frames` - the desired buffer size in frames or 0 for unspecified
730+
/// - `num_frames`: the desired buffer size in frames or 0 for unspecified
731731
pub fn frames_per_data_callback(self, num_frames: i32) -> Self {
732732
unsafe { ffi::AAudioStreamBuilder_setFramesPerDataCallback(self.as_ptr(), num_frames) };
733733
self
@@ -745,9 +745,9 @@ impl AudioStreamBuilder {
745745
///
746746
/// Available since API level 28.
747747
///
748-
/// # Arguments
748+
/// # Parameters
749749
///
750-
/// * `input_preset` - the desired configuration for recording
750+
/// - `input_preset`: the desired configuration for recording
751751
#[cfg(feature = "api-level-28")]
752752
pub fn input_preset(self, input_preset: AudioInputPreset) -> Self {
753753
unsafe {
@@ -771,9 +771,9 @@ impl AudioStreamBuilder {
771771
///
772772
/// Available since API level 26.
773773
///
774-
/// # Arguments
774+
/// # Parameters
775775
///
776-
/// * `mode` - the desired performance mode, eg. LowLatency
776+
/// - `mode`: the desired performance mode, eg. LowLatency
777777
pub fn performance_mode(self, mode: AudioPerformanceMode) -> Self {
778778
unsafe {
779779
ffi::AAudioStreamBuilder_setPerformanceMode(
@@ -796,9 +796,9 @@ impl AudioStreamBuilder {
796796
///
797797
/// Available since API level 26.
798798
///
799-
/// # Arguments
799+
/// # Parameters
800800
///
801-
/// * `sample_rate` - frames per second. Common rates include 44100 and 48000 Hz.
801+
/// - `sample_rate`: frames per second. Common rates include 44100 and 48000 Hz.
802802
pub fn sample_rate(self, sample_rate: i32) -> Self {
803803
unsafe { ffi::AAudioStreamBuilder_setSampleRate(self.as_ptr(), sample_rate) };
804804
self
@@ -830,9 +830,9 @@ impl AudioStreamBuilder {
830830
///
831831
/// Available since API level 28.
832832
///
833-
/// # Arguments
833+
/// # Parameters
834834
///
835-
/// * `session_id` - an allocated sessionID or [`Option::None`] to allocate a new sessionID
835+
/// - `session_id`: an allocated sessionID or [`Option::None`] to allocate a new sessionID
836836
#[cfg(feature = "api-level-28")]
837837
pub fn session_id(self, session_id_or_allocate: Option<SessionId>) -> Self {
838838
let session_id = match session_id_or_allocate {
@@ -854,9 +854,9 @@ impl AudioStreamBuilder {
854854
///
855855
/// Available since API level 26.
856856
///
857-
/// # Arguments
857+
/// # Parameters
858858
///
859-
/// * `sharing_mode` - [`AudioSharingMode::Shared`] or [`AudioSharingMode::Exclusive`]
859+
/// - `sharing_mode`: [`AudioSharingMode::Shared`] or [`AudioSharingMode::Exclusive`]
860860
pub fn sharing_mode(self, sharing_mode: AudioSharingMode) -> Self {
861861
unsafe {
862862
ffi::AAudioStreamBuilder_setSharingMode(
@@ -877,7 +877,7 @@ impl AudioStreamBuilder {
877877
///
878878
/// Available since API level 28.
879879
///
880-
/// * `usage` - the desired usage, eg. [`AudioUsage::Game`]
880+
/// - `usage`: the desired usage, eg. [`AudioUsage::Game`]
881881
#[cfg(feature = "api-level-28")]
882882
pub fn usage(self, usage: AudioUsage) -> Self {
883883
unsafe { ffi::AAudioStreamBuilder_setUsage(self.as_ptr(), usage as ffi::aaudio_usage_t) };
@@ -1207,11 +1207,11 @@ impl AudioStream {
12071207
///
12081208
/// Available since API level 26.
12091209
///
1210-
/// # Arguments
1210+
/// # Parameters
12111211
///
1212-
/// * `buffer` - The slice with the samples.
1213-
/// * `num_frames` - Number of frames to read. Only complete frames will be written.
1214-
/// * `timeout_nanoseconds` - Maximum number of nanoseconds to wait for completion.
1212+
/// - `buffer`: The slice with the samples.
1213+
/// - `num_frames`: Number of frames to read. Only complete frames will be written.
1214+
/// - `timeout_nanoseconds`: Maximum number of nanoseconds to wait for completion.
12151215
///
12161216
/// # Safety
12171217
/// `buffer` must be a valid pointer to at least `num_frames` samples.
@@ -1295,9 +1295,9 @@ impl AudioStream {
12951295
///
12961296
/// Available since API level 26.
12971297
///
1298-
/// # Arguments
1298+
/// # Parameters
12991299
///
1300-
/// * `num_frames` - requested number of frames that can be filled without blocking
1300+
/// - `num_frames`: requested number of frames that can be filled without blocking
13011301
pub fn set_buffer_size_in_frames(&self, num_frames: i32) -> Result<i32> {
13021302
let result = unsafe { ffi::AAudioStream_setBufferSizeInFrames(self.as_ptr(), num_frames) };
13031303
AudioError::from_result(result, || result)
@@ -1342,11 +1342,11 @@ impl AudioStream {
13421342
///
13431343
/// Available since API level 26.
13441344
///
1345-
/// # Arguments
1345+
/// # Parameters
13461346
///
1347-
/// * `buffer` - The address of the first sample.
1348-
/// * `num_frames` - Number of frames to write. Only complete frames will be written.
1349-
/// * `timeout_nanoseconds` - Maximum number of nanoseconds to wait for completion.
1347+
/// - `buffer`: The address of the first sample.
1348+
/// - `num_frames`: Number of frames to write. Only complete frames will be written.
1349+
/// - `timeout_nanoseconds`: Maximum number of nanoseconds to wait for completion.
13501350
///
13511351
/// # Safety
13521352
/// `buffer` must be a valid pointer to at least `num_frames` samples.

ndk/src/font.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,12 @@ impl FontMatcher {
442442
/// Even if no font can render the given text, this function will return a non-null result for
443443
/// drawing Tofu character.
444444
///
445-
/// # Arguments
445+
/// # Parameters
446446
///
447-
/// * `family_name`: A font family name.
448-
/// * `text`: A UTF-16 encoded text buffer to be rendered. If an empty string is given, this
447+
/// - `family_name`: A font family name.
448+
/// - `text`: A UTF-16 encoded text buffer to be rendered. If an empty string is given, this
449449
/// function will panic.
450-
/// * `run_length_out`: Set this to [`Some`] if you want to get the length of the text run with
450+
/// - `run_length_out`: Set this to [`Some`] if you want to get the length of the text run with
451451
/// the font returned.
452452
pub fn match_font(
453453
&mut self,
@@ -483,8 +483,9 @@ impl FontMatcher {
483483
///
484484
/// If this function is not called, the match is performed with an empty locale list.
485485
///
486-
/// # Arguments
487-
/// * `language_tags`: comma separated IETF BCP47 compliant language tags.
486+
/// # Parameters
487+
///
488+
/// - `language_tags`: comma separated IETF BCP47 compliant language tags.
488489
pub fn set_locales(&mut self, language_tags: &CStr) {
489490
unsafe { ffi::AFontMatcher_setLocales(self.ptr.as_ptr(), language_tags.as_ptr()) }
490491
}

0 commit comments

Comments
 (0)