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

Commit e3b59ac2 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

Convert mask types from uint32_t to enum type

This applies to the following types:

- audio_gain_mode_t;
- audio_flags_mask_t;
- audio_channel_representation_t;
- audio_channel_mask_t;
- audio_devices_t.

Enum types are distinct thus proper overloading on the type
is possible in C++. Also, assignments to enum types are
less prone to errors.

Bug: 169889714
Test: basic audio functionality
      m stagefright
      atest audiopolicy_tests
Change-Id: I42506484b1d0b0482618b7314fad4c8012a06fb4
Merged-In: I42506484b1d0b0482618b7314fad4c8012a06fb4
parent 7aacb78d
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -134,15 +134,18 @@ status_t AudioPlayer::start(bool sourceAlreadyStarted) {
    success = format->findInt32(kKeySampleRate, &mSampleRate);
    CHECK(success);

    int32_t numChannels, channelMask;
    int32_t numChannels;
    success = format->findInt32(kKeyChannelCount, &numChannels);
    CHECK(success);

    if(!format->findInt32(kKeyChannelMask, &channelMask)) {
    audio_channel_mask_t channelMask;
    if (int32_t rawChannelMask; !format->findInt32(kKeyChannelMask, &rawChannelMask)) {
        // log only when there's a risk of ambiguity of channel mask selection
        ALOGI_IF(numChannels > 2,
                "source format didn't specify channel mask, using (%d) channel order", numChannels);
        channelMask = CHANNEL_MASK_USE_CHANNEL_ORDER;
    } else {
        channelMask = static_cast<audio_channel_mask_t>(rawChannelMask);
    }

    audio_format_t audioFormat = AUDIO_FORMAT_PCM_16_BIT;
+2 −2
Original line number Diff line number Diff line
@@ -1304,8 +1304,8 @@ void MyOggExtractor::setChannelMask(int channelCount) {
                || audioChannelCount <= 0 || audioChannelCount > FCC_8) {
            ALOGE("Invalid haptic channel count found in metadata: %d", mHapticChannelCount);
        } else {
            const audio_channel_mask_t channelMask = audio_channel_out_mask_from_count(
                    audioChannelCount) | hapticChannelMask;
            const audio_channel_mask_t channelMask = static_cast<audio_channel_mask_t>(
                    audio_channel_out_mask_from_count(audioChannelCount) | hapticChannelMask);
            AMediaFormat_setInt32(mMeta, AMEDIAFORMAT_KEY_CHANNEL_MASK, channelMask);
            AMediaFormat_setInt32(
                    mMeta, AMEDIAFORMAT_KEY_HAPTIC_CHANNEL_COUNT, mHapticChannelCount);
+2 −1
Original line number Diff line number Diff line
@@ -231,7 +231,8 @@ audio_flags_mask_t AAudioConvert_allowCapturePolicyToAudioFlagsMask(
        case AAUDIO_ALLOW_CAPTURE_BY_SYSTEM:
            return AUDIO_FLAG_NO_MEDIA_PROJECTION;
        case AAUDIO_ALLOW_CAPTURE_BY_NONE:
            return AUDIO_FLAG_NO_MEDIA_PROJECTION | AUDIO_FLAG_NO_SYSTEM_CAPTURE;
            return static_cast<audio_flags_mask_t>(
                    AUDIO_FLAG_NO_MEDIA_PROJECTION | AUDIO_FLAG_NO_SYSTEM_CAPTURE);
        default:
            ALOGE("%s() 0x%08X unrecognized", __func__, policy);
            return AUDIO_FLAG_NONE; //
+2 −1
Original line number Diff line number Diff line
@@ -279,7 +279,8 @@ status_t AudioRecord::set(
        mAttributes.source = inputSource;
        if (inputSource == AUDIO_SOURCE_VOICE_COMMUNICATION
                || inputSource == AUDIO_SOURCE_CAMCORDER) {
            mAttributes.flags |= AUDIO_FLAG_CAPTURE_PRIVATE;
            mAttributes.flags = static_cast<audio_flags_mask_t>(
                    mAttributes.flags | AUDIO_FLAG_CAPTURE_PRIVATE);
        }
    } else {
        // stream type shouldn't be looked at, this track has audio attributes
+32 −2
Original line number Diff line number Diff line
@@ -222,7 +222,7 @@ AudioTrack::AudioTrack()
{
    mAttributes.content_type = AUDIO_CONTENT_TYPE_UNKNOWN;
    mAttributes.usage = AUDIO_USAGE_UNKNOWN;
    mAttributes.flags = 0x0;
    mAttributes.flags = AUDIO_FLAG_NONE;
    strcpy(mAttributes.tags, "");
}

@@ -458,7 +458,7 @@ status_t AudioTrack::set(
    if (format == AUDIO_FORMAT_DEFAULT) {
        format = AUDIO_FORMAT_PCM_16_BIT;
    } else if (format == AUDIO_FORMAT_IEC61937) { // HDMI pass-through?
        mAttributes.flags |= AUDIO_OUTPUT_FLAG_IEC958_NONAUDIO;
        flags = static_cast<audio_output_flags_t>(flags | AUDIO_OUTPUT_FLAG_IEC958_NONAUDIO);
    }

    // validate parameters
@@ -635,6 +635,36 @@ exit:
    return status;
}


status_t AudioTrack::set(
        audio_stream_type_t streamType,
        uint32_t sampleRate,
        audio_format_t format,
        uint32_t channelMask,
        size_t frameCount,
        audio_output_flags_t flags,
        callback_t cbf,
        void* user,
        int32_t notificationFrames,
        const sp<IMemory>& sharedBuffer,
        bool threadCanCallJava,
        audio_session_t sessionId,
        transfer_type transferType,
        const audio_offload_info_t *offloadInfo,
        uid_t uid,
        pid_t pid,
        const audio_attributes_t* pAttributes,
        bool doNotReconnect,
        float maxRequiredSpeed,
        audio_port_handle_t selectedDeviceId)
{
    return set(streamType, sampleRate, format,
            static_cast<audio_channel_mask_t>(channelMask),
            frameCount, flags, cbf, user, notificationFrames, sharedBuffer,
            threadCanCallJava, sessionId, transferType, offloadInfo, uid, pid,
            pAttributes, doNotReconnect, maxRequiredSpeed, selectedDeviceId);
}

// -------------------------------------------------------------------------

status_t AudioTrack::start()
Loading