Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5c00d01c authored by Ari Hausman-Cohen's avatar Ari Hausman-Cohen
Browse files

Add helper method to convert usage to stream type.

Adds audio_usage_to_stream_type method to aid in converting
audio_usage_t to the legacy audio_stream_type_t.

Bug: 78527120
Test: Builds
Change-Id: I411bb687d0f46b82afef3a2e9ac6a974f922da91
parent 2046ec75
Loading
Loading
Loading
Loading
+38 −32
Original line number Diff line number Diff line
@@ -19,18 +19,9 @@
#include <system/audio.h>

static inline
audio_stream_type_t audio_attributes_to_stream_type(const audio_attributes_t *attr)
audio_stream_type_t audio_usage_to_stream_type(const audio_usage_t usage)
{
    // flags to stream type mapping
    if ((attr->flags & AUDIO_FLAG_AUDIBILITY_ENFORCED) == AUDIO_FLAG_AUDIBILITY_ENFORCED) {
        return AUDIO_STREAM_ENFORCED_AUDIBLE;
    }
    if ((attr->flags & AUDIO_FLAG_SCO) == AUDIO_FLAG_SCO) {
        return AUDIO_STREAM_BLUETOOTH_SCO;
    }

    // usage to stream type mapping
    switch (attr->usage) {
    switch(usage) {
        case AUDIO_USAGE_MEDIA:
        case AUDIO_USAGE_GAME:
        case AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE:
@@ -64,6 +55,21 @@ audio_stream_type_t audio_attributes_to_stream_type(const audio_attributes_t *at
    }
}

static inline
audio_stream_type_t audio_attributes_to_stream_type(const audio_attributes_t *attr)
{
    // flags to stream type mapping
    if ((attr->flags & AUDIO_FLAG_AUDIBILITY_ENFORCED) == AUDIO_FLAG_AUDIBILITY_ENFORCED) {
        return AUDIO_STREAM_ENFORCED_AUDIBLE;
    }
    if ((attr->flags & AUDIO_FLAG_SCO) == AUDIO_FLAG_SCO) {
        return AUDIO_STREAM_BLUETOOTH_SCO;
    }

    // usage to stream type mapping
    return audio_usage_to_stream_type(attr->usage);
}

static inline
void stream_type_to_audio_attributes(audio_stream_type_t streamType,
                                     audio_attributes_t *attr) {
+1 −33
Original line number Diff line number Diff line
@@ -5813,39 +5813,7 @@ audio_stream_type_t AudioPolicyManager::streamTypefromAttributesInt(const audio_
        return AUDIO_STREAM_TTS;
    }

    // usage to stream type mapping
    switch (attr->usage) {
    case AUDIO_USAGE_MEDIA:
    case AUDIO_USAGE_GAME:
    case AUDIO_USAGE_ASSISTANT:
    case AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE:
        return AUDIO_STREAM_MUSIC;
    case AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY:
        return AUDIO_STREAM_ACCESSIBILITY;
    case AUDIO_USAGE_ASSISTANCE_SONIFICATION:
        return AUDIO_STREAM_SYSTEM;
    case AUDIO_USAGE_VOICE_COMMUNICATION:
        return AUDIO_STREAM_VOICE_CALL;

    case AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING:
        return AUDIO_STREAM_DTMF;

    case AUDIO_USAGE_ALARM:
        return AUDIO_STREAM_ALARM;
    case AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE:
        return AUDIO_STREAM_RING;

    case AUDIO_USAGE_NOTIFICATION:
    case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST:
    case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT:
    case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED:
    case AUDIO_USAGE_NOTIFICATION_EVENT:
        return AUDIO_STREAM_NOTIFICATION;

    case AUDIO_USAGE_UNKNOWN:
    default:
        return AUDIO_STREAM_MUSIC;
    }
    return audio_usage_to_stream_type(attr->usage);
}

bool AudioPolicyManager::isValidAttributes(const audio_attributes_t *paa)