Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/Tizen.Multimedia.AudioIO/AudioIO/AudioCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,18 @@ internal void ValidateNotDisposed()
}
#endregion

internal void ValidateState(params AudioIOState[] desiredStates)
internal void ValidateState(AudioIOState desired)
{
ValidateNotDisposed();

AudioIOUtil.ValidateState(_state, desiredStates);
AudioIOUtil.ValidateState(_state, desired);
}

internal void ValidateState(AudioIOState desired1, AudioIOState desired2)
{
ValidateNotDisposed();

AudioIOUtil.ValidateState(_state, desired1, desired2);
}

/// <summary>
Expand Down
30 changes: 23 additions & 7 deletions src/Tizen.Multimedia.AudioIO/AudioIO/AudioIOUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,40 @@
*/

using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;

namespace Tizen.Multimedia
{
internal static class AudioIOUtil
{
internal static void ValidateState(AudioIOState curState, params AudioIOState[] desiredStates)
internal static void ValidateState(AudioIOState curState, AudioIOState desired)
{
Debug.Assert(desiredStates.Length > 0);
if (curState == desired)
{
return;
}

if (desiredStates.Contains(curState))
ThrowInvalidState(curState, desired);
}
Comment on lines +25 to +33

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Since these methods are part of a performance-critical hot path (as mentioned in the PR description), it is recommended to mark them with [MethodImpl(MethodImplOptions.AggressiveInlining)]. This encourages the JIT compiler to inline these small validation checks directly into the calling methods (like Read or Write), reducing method call overhead and potentially enabling further optimizations.

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        internal static void ValidateState(AudioIOState curState, AudioIOState desired)
        {
            if (curState == desired)
            {
                return;
            }

            ThrowInvalidState(curState, desired);
        }


internal static void ValidateState(AudioIOState curState, AudioIOState desired1, AudioIOState desired2)
{
if (curState == desired1 || curState == desired2)
{
return;
}

throw new InvalidOperationException($"The audio is not in a valid state. " +
$"Current State : { curState }, Valid State : { string.Join(", ", desiredStates) }.");
ThrowInvalidState(curState, desired1, desired2);
}
Comment on lines +36 to 44

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Similar to the 1-argument overload, this method should also be marked with [MethodImpl(MethodImplOptions.AggressiveInlining)] to ensure optimal performance in the streaming hot path.

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        internal static void ValidateState(AudioIOState curState, AudioIOState desired1, AudioIOState desired2)
        {
            if (curState == desired1 || curState == desired2)
            {
                return;
            }

            ThrowInvalidState(curState, desired1, desired2);
        }


[MethodImpl(MethodImplOptions.NoInlining)]
private static void ThrowInvalidState(AudioIOState curState, AudioIOState desired) =>
throw new InvalidOperationException($"The audio is not in a valid state. " +
$"Current State : { curState }, Valid State : { desired }.");

[MethodImpl(MethodImplOptions.NoInlining)]
private static void ThrowInvalidState(AudioIOState curState, AudioIOState desired1, AudioIOState desired2) =>
throw new InvalidOperationException($"The audio is not in a valid state. " +
$"Current State : { curState }, Valid State : { desired1 }, { desired2 }.");
}
}
11 changes: 9 additions & 2 deletions src/Tizen.Multimedia.AudioIO/AudioIO/AudioPlayback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,18 @@ private void ValidateNotDisposed()
}
#endregion

private void ValidateState(params AudioIOState[] desiredStates)
private void ValidateState(AudioIOState desired)
{
ValidateNotDisposed();

AudioIOUtil.ValidateState(_state, desiredStates);
AudioIOUtil.ValidateState(_state, desired);
}

private void ValidateState(AudioIOState desired1, AudioIOState desired2)
{
ValidateNotDisposed();

AudioIOUtil.ValidateState(_state, desired1, desired2);
}

/// <summary>
Expand Down
Loading