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

Commit 560637e3 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

libaudiohal: Address TODO in StreamHalInterface

- Remove getSampleRate, getChannelMask, getFormat
  methods;

- Add an overload of getAudioProperties which takes
  audio_config_base_t;

- Update client code.

Test: m, test audio on device
Change-Id: I36bd1119a2b75991e42aa07b431359da1364fd42
parent c31f1502
Loading
Loading
Loading
Loading
+7 −36
Original line number Diff line number Diff line
@@ -57,8 +57,7 @@ StreamHalHidl::StreamHalHidl(IStream *stream)
    // Note: This assumes channel mask, format, and sample rate do not change after creation.
    audio_config_base_t config = AUDIO_CONFIG_BASE_INITIALIZER;
    if (/* mStreamPowerLog.isUserDebugOrEngBuild() && */
        StreamHalHidl::getAudioProperties(
                &config.sample_rate, &config.channel_mask, &config.format) == NO_ERROR) {
        StreamHalHidl::getAudioProperties(&config) == NO_ERROR) {
        mStreamPowerLog.init(config.sample_rate, config.channel_mask, config.format);
    }
}
@@ -67,14 +66,6 @@ StreamHalHidl::~StreamHalHidl() {
    mStream = nullptr;
}

// Note: this method will be removed
status_t StreamHalHidl::getSampleRate(uint32_t *rate) {
    audio_config_base_t config = AUDIO_CONFIG_BASE_INITIALIZER;
    status_t status = getAudioProperties(&config.sample_rate, &config.channel_mask, &config.format);
    *rate = config.sample_rate;
    return status;
}

status_t StreamHalHidl::getBufferSize(size_t *size) {
    if (!mStream) return NO_INIT;
    status_t status = processReturn("getBufferSize", mStream->getBufferSize(), size);
@@ -84,48 +75,28 @@ status_t StreamHalHidl::getBufferSize(size_t *size) {
    return status;
}

// Note: this method will be removed
status_t StreamHalHidl::getChannelMask(audio_channel_mask_t *mask) {
    audio_config_base_t config = AUDIO_CONFIG_BASE_INITIALIZER;
    status_t status = getAudioProperties(&config.sample_rate, &config.channel_mask, &config.format);
    *mask = config.channel_mask;
    return status;
}

// Note: this method will be removed
status_t StreamHalHidl::getFormat(audio_format_t *format) {
    audio_config_base_t config = AUDIO_CONFIG_BASE_INITIALIZER;
    status_t status = getAudioProperties(&config.sample_rate, &config.channel_mask, &config.format);
    *format = config.format;
    return status;
}

status_t StreamHalHidl::getAudioProperties(
        uint32_t *sampleRate, audio_channel_mask_t *mask, audio_format_t *format) {
status_t StreamHalHidl::getAudioProperties(audio_config_base_t *configBase) {
    *configBase = AUDIO_CONFIG_BASE_INITIALIZER;
    if (!mStream) return NO_INIT;
#if MAJOR_VERSION <= 6
    Return<void> ret = mStream->getAudioProperties(
            [&](uint32_t sr, auto m, auto f) {
                *sampleRate = sr;
                *mask = static_cast<audio_channel_mask_t>(m);
                *format = static_cast<audio_format_t>(f);
                configBase->sample_rate = sr;
                configBase->channel_mask = static_cast<audio_channel_mask_t>(m);
                configBase->format = static_cast<audio_format_t>(f);
            });
    return processReturn("getAudioProperties", ret);
#else
    Result retval;
    status_t conversionStatus = BAD_VALUE;
    audio_config_base_t halConfig = AUDIO_CONFIG_BASE_INITIALIZER;
    Return<void> ret = mStream->getAudioProperties(
            [&](Result r, const AudioConfigBase& config) {
                retval = r;
                if (retval == Result::OK) {
                    conversionStatus = HidlUtils::audioConfigBaseToHal(config, &halConfig);
                    conversionStatus = HidlUtils::audioConfigBaseToHal(config, configBase);
                }
            });
    if (status_t status = processReturn("getAudioProperties", ret, retval); status == NO_ERROR) {
        *sampleRate = halConfig.sample_rate;
        *mask = halConfig.channel_mask;
        *format = halConfig.format;
        return conversionStatus;
    } else {
        return status;
+5 −12
Original line number Diff line number Diff line
@@ -48,21 +48,14 @@ class DeviceHalHidl;
class StreamHalHidl : public virtual StreamHalInterface, public ConversionHelperHidl
{
  public:
    // Return the sampling rate in Hz - eg. 44100.
    virtual status_t getSampleRate(uint32_t *rate);

    // Return size of input/output buffer in bytes for this stream - eg. 4800.
    virtual status_t getBufferSize(size_t *size);

    // Return the channel mask.
    virtual status_t getChannelMask(audio_channel_mask_t *mask);

    // Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT.
    virtual status_t getFormat(audio_format_t *format);

    // Convenience method.
    virtual status_t getAudioProperties(
            uint32_t *sampleRate, audio_channel_mask_t *mask, audio_format_t *format);
    // Return the base configuration of the stream:
    //   - channel mask;
    //   - format - e.g. AUDIO_FORMAT_PCM_16_BIT;
    //   - sampling rate in Hz - eg. 44100.
    virtual status_t getAudioProperties(audio_config_base_t *configBase);

    // Set audio stream parameters.
    virtual status_t setParameters(const String8& kvPairs);
+4 −20
Original line number Diff line number Diff line
@@ -45,31 +45,15 @@ StreamHalLocal::~StreamHalLocal() {
    mDevice.clear();
}

status_t StreamHalLocal::getSampleRate(uint32_t *rate) {
    *rate = mStream->get_sample_rate(mStream);
    return OK;
}

status_t StreamHalLocal::getBufferSize(size_t *size) {
    *size = mStream->get_buffer_size(mStream);
    return OK;
}

status_t StreamHalLocal::getChannelMask(audio_channel_mask_t *mask) {
    *mask = mStream->get_channels(mStream);
    return OK;
}

status_t StreamHalLocal::getFormat(audio_format_t *format) {
    *format = mStream->get_format(mStream);
    return OK;
}

status_t StreamHalLocal::getAudioProperties(
        uint32_t *sampleRate, audio_channel_mask_t *mask, audio_format_t *format) {
    *sampleRate = mStream->get_sample_rate(mStream);
    *mask = mStream->get_channels(mStream);
    *format = mStream->get_format(mStream);
status_t StreamHalLocal::getAudioProperties(audio_config_base_t *configBase) {
    configBase->sample_rate = mStream->get_sample_rate(mStream);
    configBase->channel_mask = mStream->get_channels(mStream);
    configBase->format = mStream->get_format(mStream);
    return OK;
}

+5 −12
Original line number Diff line number Diff line
@@ -28,21 +28,14 @@ class DeviceHalLocal;
class StreamHalLocal : public virtual StreamHalInterface
{
  public:
    // Return the sampling rate in Hz - eg. 44100.
    virtual status_t getSampleRate(uint32_t *rate);

    // Return size of input/output buffer in bytes for this stream - eg. 4800.
    virtual status_t getBufferSize(size_t *size);

    // Return the channel mask.
    virtual status_t getChannelMask(audio_channel_mask_t *mask);

    // Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT.
    virtual status_t getFormat(audio_format_t *format);

    // Convenience method.
    virtual status_t getAudioProperties(
            uint32_t *sampleRate, audio_channel_mask_t *mask, audio_format_t *format);
    // Return the base configuration of the stream:
    //   - channel mask;
    //   - format - e.g. AUDIO_FORMAT_PCM_16_BIT;
    //   - sampling rate in Hz - eg. 44100.
    virtual status_t getAudioProperties(audio_config_base_t *configBase);

    // Set audio stream parameters.
    virtual status_t setParameters(const String8& kvPairs);
+16 −14
Original line number Diff line number Diff line
@@ -31,25 +31,27 @@ namespace android {
class StreamHalInterface : public virtual RefBase
{
  public:
    // TODO(mnaganov): Remove
    // Return the sampling rate in Hz - eg. 44100.
    virtual status_t getSampleRate(uint32_t *rate) = 0;

    // Return size of input/output buffer in bytes for this stream - eg. 4800.
    virtual status_t getBufferSize(size_t *size) = 0;

    // TODO(mnaganov): Remove
    // Return the channel mask.
    virtual status_t getChannelMask(audio_channel_mask_t *mask) = 0;

    // TODO(mnaganov): Remove
    // Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT.
    virtual status_t getFormat(audio_format_t *format) = 0;
    // Return the base configuration of the stream:
    //   - channel mask;
    //   - format - e.g. AUDIO_FORMAT_PCM_16_BIT;
    //   - sampling rate in Hz - eg. 44100.
    virtual status_t getAudioProperties(audio_config_base_t *configBase) = 0;

    // TODO(mnaganov): Change to use audio_config_base_t
    // Convenience method.
    virtual status_t getAudioProperties(
            uint32_t *sampleRate, audio_channel_mask_t *mask, audio_format_t *format) = 0;
    inline status_t getAudioProperties(
            uint32_t *sampleRate, audio_channel_mask_t *mask, audio_format_t *format) {
        audio_config_base_t config = AUDIO_CONFIG_BASE_INITIALIZER;
        const status_t result = getAudioProperties(&config);
        if (result == NO_ERROR) {
            if (sampleRate != nullptr) *sampleRate = config.sample_rate;
            if (mask != nullptr) *mask = config.channel_mask;
            if (format != nullptr) *format = config.format;
        }
        return result;
    }

    // Set audio stream parameters.
    virtual status_t setParameters(const String8& kvPairs) = 0;
Loading