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

Commit 3f390a9f authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "mpq8092: Porting audio HAL changes"

parents 72ce3a32 09cbbf0c
Loading
Loading
Loading
Loading
+57 −17
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@
#include <math.h>

#define LOG_TAG "AudioBitstreamStateMachine"
//#define LOG_NDEBUG 0
#define LOG_NDEBUG 0
#define LOG_NDDEBUG 0
#include <utils/Log.h>

@@ -36,7 +36,6 @@
#include <platform.h>
// ----------------------------------------------------------------------------


/*
Initialize all input and output pointers
Allocate twice the max buffer size of input and output for sufficient buffering
@@ -45,52 +44,62 @@ int audio_bitstream_init(struct audio_bitstream_sm *bstream, int buffering_facto
{
    bstream->buffering_factor = buffering_factor;
    bstream->buffering_factor_cnt = 0;

    bstream->inp_buf=(char *)malloc(SAMPLES_PER_CHANNEL*
    bstream->inp_buf_size = SAMPLES_PER_CHANNEL *
                        MAX_INPUT_CHANNELS_SUPPORTED*
                (bstream->buffering_factor+1));
                        (bstream->buffering_factor+1);
    bstream->inp_buf = (char *)malloc( bstream->inp_buf_size);

                                // multiplied by 2 to convert to bytes
    if(bstream->inp_buf != NULL) {
        bstream->inp_buf_curr_ptr = bstream->inp_buf;
        bstream->inp_buf_write_ptr = bstream->inp_buf;
    } else {
        ALOGE("MS11 input buffer not allocated");
        bstream->inp_buf_size = 0;
        return 0;
    }

    bstream->enc_out_buf =(char *)malloc(SAMPLES_PER_CHANNEL*
                MAX_INPUT_CHANNELS_SUPPORTED*
                FACTOR_FOR_BUFFERING);
    bstream->enc_out_buf_size = SAMPLES_PER_CHANNEL * MAX_INPUT_CHANNELS_SUPPORTED*
                        FACTOR_FOR_BUFFERING;
    bstream->enc_out_buf =(char *)malloc(bstream->enc_out_buf_size);

    if(bstream->enc_out_buf) {
        bstream->enc_out_buf_write_ptr = bstream->enc_out_buf;
    } else {
        ALOGE("MS11 Enc output buffer not allocated");
        bstream->enc_out_buf_size = 0;
        return 0;
    }
    bstream->pcm_2_out_buf =(char *)malloc(SAMPLES_PER_CHANNEL*STEREO_CHANNELS *
                    FACTOR_FOR_BUFFERING);
    bstream->pcm_2_out_buf_size =  SAMPLES_PER_CHANNEL*STEREO_CHANNELS *
                    FACTOR_FOR_BUFFERING;
    bstream->pcm_2_out_buf =(char *)malloc(bstream->pcm_2_out_buf_size);
    if(bstream->pcm_2_out_buf) {
        bstream->pcm_2_out_buf_write_ptr = bstream->pcm_2_out_buf;
    } else {
        ALOGE("MS11 PCM2Ch output buffer not allocated");
        bstream->pcm_2_out_buf_size = 0;
        return 0;
    }
    bstream->pcm_mch_out_buf =(char *)malloc(SAMPLES_PER_CHANNEL *
                     MAX_OUTPUT_CHANNELS_SUPPORTED *
                     FACTOR_FOR_BUFFERING);
    bstream->pcm_mch_out_buf_size = SAMPLES_PER_CHANNEL * MAX_OUTPUT_CHANNELS_SUPPORTED *
                     FACTOR_FOR_BUFFERING;

    bstream->pcm_mch_out_buf =(char *)malloc(bstream->pcm_mch_out_buf_size);
    if(bstream->pcm_mch_out_buf) {
        bstream->pcm_mch_out_buf_write_ptr = bstream->pcm_mch_out_buf;
    } else {
        ALOGE("MS11 PCMMCh output buffer not allocated");
        bstream->pcm_mch_out_buf_size = 0;
        return 0;
    }
    bstream->passt_out_buf =(char *)malloc(SAMPLES_PER_CHANNEL *
    bstream->passt_out_buf_size =SAMPLES_PER_CHANNEL *
                       MAX_INPUT_CHANNELS_SUPPORTED *
                       FACTOR_FOR_BUFFERING);
                       FACTOR_FOR_BUFFERING;
    bstream->passt_out_buf =(char *)malloc(bstream->passt_out_buf_size);
    if(bstream->passt_out_buf) {
        bstream->passt_out_buf_write_ptr = bstream->passt_out_buf;
    } else {
        ALOGE("MS11 Enc output buffer not allocated");
        bstream->passt_out_buf_size  = 0;
        return 0;
    }
    return 1;
@@ -159,9 +168,8 @@ void audio_bitstream_copy_to_internal_buffer(
                    struct audio_bitstream_sm *bstream,
                    char *buf_ptr, size_t bytes)
{
    int32_t bufLen = SAMPLES_PER_CHANNEL*MAX_INPUT_CHANNELS_SUPPORTED*(bstream->buffering_factor+1);
    // flush the input buffer if input is not consumed
    if( (bstream->inp_buf_write_ptr+bytes) > (bstream->inp_buf+bufLen) ) {
    if( (bstream->inp_buf_write_ptr+bytes) > (bstream->inp_buf+bstream->inp_buf_size) ) {
        ALOGE("Input bitstream is not consumed");
        return;
    }
@@ -226,6 +234,38 @@ char* audio_bitstream_get_input_buffer_write_ptr(
    return bstream->inp_buf_write_ptr;
}

int audio_bitstream_set_input_buffer_ptr(
                        struct audio_bitstream_sm *bstream, int bytes)
{
    if(((bstream->inp_buf_curr_ptr + bytes) <=
                        (bstream->inp_buf + bstream->inp_buf_size)) &&
        ((bstream->inp_buf_curr_ptr + bytes) >= bstream->inp_buf))

        bstream->inp_buf_curr_ptr += bytes;
     else {
        ALOGE("Invalid input buffer size %d bytes", bytes);
        return -EINVAL;
     }

    return 0;
}

int audio_bitstream_set_input_buffer_write_ptr(
                        struct audio_bitstream_sm *bstream, int bytes)
{
    if(((bstream->inp_buf_write_ptr + bytes) <=
                        (bstream->inp_buf + bstream->inp_buf_size)) &&
        ((bstream->inp_buf_write_ptr + bytes) >= bstream->inp_buf))

        bstream->inp_buf_write_ptr += bytes;
     else {
        ALOGE("Invalid input buffer size %d bytes", bytes);
        return -EINVAL;
     }

    return 0;
}

/*
Get the output buffer start pointer to start rendering the pcm sampled to driver
*/
+110 −5
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@
#include <hardware/audio.h>
#include <tinyalsa/asoundlib.h>
#include <tinycompress/tinycompress.h>

#include "sound/compress_params.h"
#include <audio_route/audio_route.h>

#define VISUALIZER_LIBRARY_PATH "/system/lib/soundfx/libqcomvisualizer.so"
@@ -45,6 +45,7 @@
#define DEFAULT_HDMI_OUT_CHANNELS   2

typedef int snd_device_t;
#include <platform.h>

/* These are the supported use cases by the hardware.
 * Each usecase is mapped to a specific PCM device.
@@ -56,11 +57,11 @@ typedef enum {
    USECASE_AUDIO_PLAYBACK_DEEP_BUFFER = 0,
    USECASE_AUDIO_PLAYBACK_LOW_LATENCY,
    USECASE_AUDIO_PLAYBACK_MULTI_CH,
    USECASE_AUDIO_PLAYBACK_OFFLOAD,

    /* FM usecase */
    USECASE_AUDIO_PLAYBACK_FM,

    USECASE_AUDIO_PLAYBACK_OFFLOAD,
    USECASE_AUDIO_PLAYBACK_OFFLOAD1,
    USECASE_AUDIO_PLAYBACK_OFFLOAD2,
    USECASE_AUDIO_PLAYBACK_OFFLOAD3,
    /* Capture usecases */
    USECASE_AUDIO_RECORD,
    USECASE_AUDIO_RECORD_COMPRESS,
@@ -88,6 +89,28 @@ typedef enum {
    AUDIO_USECASE_MAX
} audio_usecase_t;

typedef enum {
    DEEP_BUFFER_PLAYBACK_STREAM = 0,
    LOW_LATENCY_PLAYBACK_STREAM,
    MCH_PCM_PLAYBACK_STREAM,
    OFFLOAD_PLAYBACK_STREAM,
    LOW_LATENCY_RECORD_STREAM,
    RECORD_STREAM,
    VOICE_CALL_STREAM
} audio_usecase_stream_type_t;

#define STRING_TO_ENUM(string) { #string, string }
struct string_to_enum {
    const char *name;
    uint32_t value;
};

static const struct string_to_enum out_channels_name_to_enum_table[] = {
    STRING_TO_ENUM(AUDIO_CHANNEL_OUT_STEREO),
    STRING_TO_ENUM(AUDIO_CHANNEL_OUT_5POINT1),
    STRING_TO_ENUM(AUDIO_CHANNEL_OUT_7POINT1),
};

#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

/*
@@ -118,14 +141,43 @@ struct offload_cmd {
    int data[];
};

struct alsa_handle {

    struct listnode list;
//Parameters of the stream
    struct pcm *pcm;
    struct pcm_config config;

    struct compress *compr;
    struct compr_config compr_config;

    struct stream_out *out;

    audio_usecase_t usecase;
    int device_id;
    unsigned int sample_rate;
    audio_channel_mask_t channel_mask;
    audio_format_t input_format;
    audio_format_t output_format;
    audio_devices_t devices;

    route_format_t route_format;
    int decoder_type;

    bool cmd_pending ;
};

struct stream_out {
    struct audio_stream_out stream;
    pthread_mutex_t lock; /* see note below on mutex acquisition order */
    pthread_cond_t  cond;
    /* TODO remove this */
    /*
    struct pcm_config config;
    struct compr_config compr_config;
    struct pcm *pcm;
    struct compress *compr;
    */
    int standby;
    int pcm_device_id;
    unsigned int sample_rate;
@@ -154,6 +206,54 @@ struct stream_out {
    int send_new_metadata;

    struct audio_device *dev;

    /*devices configuration */
    int left_volume;
    int right_volume;
    audio_usecase_stream_type_t uc_strm_type;
    int hdmi_format;
    int spdif_format;
    int* device_formats;   //TODO:Needs to come from AudioRutingManager
    struct audio_config *config;

    /* list of the session handles */
    struct listnode session_list;

    /* /MS11 instance */
    int use_ms11_decoder;
    void  *ms11_decoder;
    struct compr_config compr_config;

    int channels;

    /* Buffering utility */
    struct audio_bitstream_sm    *bitstrm;

    int                 buffer_size;
    int                 decoder_type;
    bool                dec_conf_set;
    uint32_t            min_bytes_req_to_dec;
    bool                is_m11_file_mode;
    void                *dec_conf_buf;
    int32_t             dec_conf_bufLength;
    bool                first_bitstrm_buf;

    bool                open_dec_route;
    int                 dec_format_devices;
    bool                open_dec_mch_route;
    int                 dec_mch_format_devices;
    bool                open_passt_route;
    int                 passt_format_devices;
    bool                sw_open_trans_route;
    int                 sw_trans_format_devices;
    bool                hw_open_trans_route;
    int                 hw_trans_format_devices;
    bool                channel_status_set;
    unsigned char       channel_status[24];
    int                 route_audio_to_a2dp;
    int                 is_ms11_file_playback_mode;
    char *              write_temp_buf;
    struct output_metadata  output_meta_data;
};

struct stream_in {
@@ -194,6 +294,7 @@ struct audio_usecase {
    snd_device_t out_snd_device;
    snd_device_t in_snd_device;
    union stream_ptr stream;
    struct alsa_handle *handle;
};

struct audio_device {
@@ -225,6 +326,9 @@ static const char * const use_case_table[AUDIO_USECASE_MAX] = {
    [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = "low-latency-playback",
    [USECASE_AUDIO_PLAYBACK_MULTI_CH] = "multi-channel-playback",
    [USECASE_AUDIO_PLAYBACK_OFFLOAD] = "compress-offload-playback",
    [USECASE_AUDIO_PLAYBACK_OFFLOAD1] = "compress-offload-playback1",
    [USECASE_AUDIO_PLAYBACK_OFFLOAD2] = "compress-offload-playback2",
    [USECASE_AUDIO_PLAYBACK_OFFLOAD3] = "compress-offload-playback3",
    [USECASE_AUDIO_RECORD] = "audio-record",
    [USECASE_AUDIO_RECORD_COMPRESS] = "audio-record-compress",
    [USECASE_AUDIO_RECORD_LOW_LATENCY] = "low-latency-record",
@@ -245,6 +349,7 @@ static const char * const use_case_table[AUDIO_USECASE_MAX] = {
    [USECASE_AUDIO_SPKR_CALIB_TX] = "spkr-vi-record",
};


int adev_open_output_stream(struct audio_hw_device *dev,
                                   audio_io_handle_t handle,
                                   audio_devices_t devices,
+1899 −218

File changed.

Preview size limit exceeded, changes collapsed.

+62 −15
Original line number Diff line number Diff line
@@ -91,20 +91,39 @@ struct platform_data {
    struct csd_data *csd;
};

static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
    [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {DEEP_BUFFER_PCM_DEVICE,
                                            DEEP_BUFFER_PCM_DEVICE},
    [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
                                           LOWLATENCY_PCM_DEVICE},
    [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {MULTIMEDIA2_PCM_DEVICE,
                                        MULTIMEDIA2_PCM_DEVICE},
static int pcm_device_table[AUDIO_USECASE_MAX][4] = {
    [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {USECASE_AUDIO_PLAYBACK_DEEP_BUFFER,
                                            DEEP_BUFFER_PCM_DEVICE,
                                            DEEP_BUFFER_PCM_DEVICE, 0},
    [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {USECASE_AUDIO_PLAYBACK_LOW_LATENCY,
                                           LOWLATENCY_PCM_DEVICE,
                                           LOWLATENCY_PCM_DEVICE, 0},
    [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {USECASE_AUDIO_PLAYBACK_MULTI_CH,
                                        MULTIMEDIA2_PCM_DEVICE,
                                        MULTIMEDIA2_PCM_DEVICE, 0},
    [USECASE_AUDIO_PLAYBACK_MULTI_CH] =    {USECASE_AUDIO_PLAYBACK_MULTI_CH,
                                            MULTI_CHANNEL_PCM_DEVICE,
                                            MULTI_CHANNEL_PCM_DEVICE, 0},
    [USECASE_AUDIO_PLAYBACK_OFFLOAD] =
                     {PLAYBACK_OFFLOAD_DEVICE, PLAYBACK_OFFLOAD_DEVICE},
    [USECASE_AUDIO_RECORD] = {AUDIO_RECORD_PCM_DEVICE, AUDIO_RECORD_PCM_DEVICE},
    [USECASE_AUDIO_RECORD_COMPRESS] = {COMPRESS_CAPTURE_DEVICE, COMPRESS_CAPTURE_DEVICE},
    [USECASE_AUDIO_RECORD_LOW_LATENCY] = {LOWLATENCY_PCM_DEVICE,
                                          LOWLATENCY_PCM_DEVICE},
    [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {MULTIMEDIA2_PCM_DEVICE,
                     {USECASE_AUDIO_PLAYBACK_OFFLOAD, PLAYBACK_OFFLOAD_DEVICE1,
                     PLAYBACK_OFFLOAD_DEVICE1, 0},
    [USECASE_AUDIO_PLAYBACK_OFFLOAD1] =    {USECASE_AUDIO_PLAYBACK_OFFLOAD,
                                            PLAYBACK_OFFLOAD_DEVICE2,
                                            PLAYBACK_OFFLOAD_DEVICE2, 0},
    [USECASE_AUDIO_PLAYBACK_OFFLOAD2] =    {USECASE_AUDIO_PLAYBACK_OFFLOAD,
                                            PLAYBACK_OFFLOAD_DEVICE3,
                                            PLAYBACK_OFFLOAD_DEVICE3, 0},
    [USECASE_AUDIO_PLAYBACK_OFFLOAD3] =    {USECASE_AUDIO_PLAYBACK_OFFLOAD,
                                            PLAYBACK_OFFLOAD_DEVICE4,
                                            PLAYBACK_OFFLOAD_DEVICE4, 0},
    [USECASE_AUDIO_RECORD] = {USECASE_AUDIO_RECORD, AUDIO_RECORD_PCM_DEVICE,
                             AUDIO_RECORD_PCM_DEVICE, 0},
    [USECASE_AUDIO_RECORD_COMPRESS] = {USECASE_AUDIO_RECORD_COMPRESS, COMPRESS_CAPTURE_DEVICE,
                                       COMPRESS_CAPTURE_DEVICE, 0},
    [USECASE_AUDIO_RECORD_LOW_LATENCY] = {USECASE_AUDIO_RECORD_LOW_LATENCY,
                                          LOWLATENCY_PCM_DEVICE,
                                          LOWLATENCY_PCM_DEVICE, 0},
   /* [USECASE_AUDIO_RECORD_FM_VIRTUAL] = {,
                                  MULTIMEDIA2_PCM_DEVICE},
    [USECASE_AUDIO_PLAYBACK_FM] = {FM_PLAYBACK_PCM_DEVICE, FM_CAPTURE_PCM_DEVICE},
    [USECASE_VOICE_CALL] = {VOICE_CALL_PCM_DEVICE, VOICE_CALL_PCM_DEVICE},
@@ -124,6 +143,7 @@ static const int pcm_device_table[AUDIO_USECASE_MAX][2] = {
                                      INCALL_MUSIC_UPLINK2_PCM_DEVICE},
    [USECASE_AUDIO_SPKR_CALIB_RX] = {SPKR_PROT_CALIB_RX_PCM_DEVICE, -1},
    [USECASE_AUDIO_SPKR_CALIB_TX] = {-1, SPKR_PROT_CALIB_TX_PCM_DEVICE},
*/
};

/* Array to store sound devices */
@@ -593,12 +613,39 @@ int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
{
    int device_id;
    if (device_type == PCM_PLAYBACK)
        device_id = pcm_device_table[usecase][0];
    else
        device_id = pcm_device_table[usecase][1];
    else
        device_id = pcm_device_table[usecase][2];
    return device_id;
}

audio_usecase_t platform_get_usecase(
        audio_usecase_stream_type_t uc_type)
{
    int i = 0;
    for(i =0;i<AUDIO_USECASE_MAX; i++)
        if((pcm_device_table[i][0] == (int)uc_type) &&
                (pcm_device_table[i][3] == 0)) {
            pcm_device_table[i][3] = 1;
            break;
        }

    if(i == AUDIO_USECASE_MAX)
        return -EINVAL;
    else
        return (audio_usecase_t)i;
}

int platform_free_usecase(audio_usecase_t uc_id)
{
    if(uc_id >= AUDIO_USECASE_MAX) {
        ALOGV("%s: enter: invalid usecase(%d)", __func__, uc_id);
        return -EINVAL;
    }
    pcm_device_table[uc_id][3] = 0;
    return 0;
}

int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
{
    struct platform_data *my_data = (struct platform_data *)platform;
+400 −2

File changed.

Preview size limit exceeded, changes collapsed.

Loading