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

Commit fcc5be99 authored by Eric Laurent's avatar Eric Laurent Committed by The Android Open Source Project
Browse files

am 88e209dc: Fix issue 1743700e: AudioTrack: setPlaybackRate can not set the...

am 88e209dc: Fix issue 1743700e: AudioTrack: setPlaybackRate can not set the playback rate to twice of the ouputSR

Merge commit '88e209dc'

* commit '88e209dc':
  Fix issue 1743700e: AudioTrack: setPlaybackRate can not set the playback rate to twice of the ouputSR
parents 43488fc7 88e209dc
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -539,16 +539,17 @@ static jint android_media_AudioTrack_get_native_frame_count(JNIEnv *env, jobjec


// ----------------------------------------------------------------------------
static void android_media_AudioTrack_set_playback_rate(JNIEnv *env,  jobject thiz,
static jint android_media_AudioTrack_set_playback_rate(JNIEnv *env,  jobject thiz,
        jint sampleRateInHz) {
    AudioTrack *lpTrack = (AudioTrack *)env->GetIntField(
                thiz, javaAudioTrackFields.nativeTrackInJavaObj);

    if (lpTrack) {
        lpTrack->setSampleRate(sampleRateInHz);   
        return android_media_translateErrorCode(lpTrack->setSampleRate(sampleRateInHz));
    } else {
        jniThrowException(env, "java/lang/IllegalStateException",
            "Unable to retrieve AudioTrack pointer for setSampleRate()");
        return AUDIOTRACK_ERROR;
    }
}

@@ -788,7 +789,7 @@ static JNINativeMethod gMethods[] = {
    {"native_get_native_frame_count",
                             "()I",      (void *)android_media_AudioTrack_get_native_frame_count},
    {"native_set_playback_rate",
                             "(I)V",     (void *)android_media_AudioTrack_set_playback_rate},
                             "(I)I",     (void *)android_media_AudioTrack_set_playback_rate},
    {"native_get_playback_rate",
                             "()I",      (void *)android_media_AudioTrack_get_playback_rate},
    {"native_set_marker_pos","(I)I",     (void *)android_media_AudioTrack_set_marker_pos},
+1 −3
Original line number Diff line number Diff line
@@ -197,7 +197,6 @@ public:

   /* getters, see constructor */

            uint32_t    sampleRate() const;
            int         format() const;
            int         channelCount() const;
            uint32_t    frameCount() const;
@@ -217,7 +216,7 @@ public:
            status_t    stop();
            bool        stopped() const;

    /* get sample rate for this track
    /* get sample rate for this record track
     */
            uint32_t    getSampleRate();

@@ -323,7 +322,6 @@ private:
    sp<ClientRecordThread>  mClientRecordThread;
    Mutex                   mRecordThreadLock;

    uint32_t                mSampleRate;
    uint32_t                mFrameCount;

    audio_track_cblk_t*     mCblk;
+1 −2
Original line number Diff line number Diff line
@@ -201,7 +201,6 @@ public:
    /* getters, see constructor */

            int         streamType() const;
            uint32_t    sampleRate() const;
            int         format() const;
            int         channelCount() const;
            uint32_t    frameCount() const;
@@ -246,7 +245,7 @@ public:

    /* set sample rate for this track, mostly used for games' sound effects
     */
            void        setSampleRate(int sampleRate);
            status_t    setSampleRate(int sampleRate);
            uint32_t    getSampleRate();

    /* Enables looping and sets the start and end points of looping.
+3 −4
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ namespace android {

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

#define MAX_SAMPLE_RATE     65535
#define THREAD_PRIORITY_AUDIO_CLIENT (ANDROID_PRIORITY_AUDIO)
// Maximum cumulated timeout milliseconds before restarting audioflinger thread
#define MAX_STARTUP_TIMEOUT_MS  3000    // Longer timeout period at startup to cope with A2DP init time
@@ -55,9 +54,9 @@ struct audio_track_cblk_t
                    uint16_t    volume[2];
                    uint32_t    volumeLR;
                };
                uint16_t    sampleRate;
                uint16_t    channels;
                int16_t     flowControlFlag; // underrun (out) or overrrun (in) indication
                uint32_t    sampleRate;
                uint8_t     channels;
                uint8_t     flowControlFlag; // underrun (out) or overrrun (in) indication
                uint8_t     out;        // out equals 1 for AudioTrack and 0 for AudioRecord
                uint8_t     forceReady; 
                uint16_t    bufferTimeoutMs; // Maximum cumulated timeout before restarting audioflinger
+6 −12
Original line number Diff line number Diff line
@@ -1288,7 +1288,7 @@ sp<AudioFlinger::MixerThread::Track> AudioFlinger::MixerThread::createTrack_l(
    status_t lStatus;
    
    // Resampler implementation limits input sampling rate to 2 x output sampling rate.
    if (sampleRate > MAX_SAMPLE_RATE || sampleRate > mSampleRate*2) {
    if (sampleRate > mSampleRate*2) {
        LOGE("Sample rate out of range: %d mSampleRate %d", sampleRate, mSampleRate);
        lStatus = BAD_VALUE;
        goto Exit;
@@ -1603,8 +1603,8 @@ AudioFlinger::MixerThread::TrackBase::TrackBase(
                new(mCblk) audio_track_cblk_t();
                // clear all buffers
                mCblk->frameCount = frameCount;
                mCblk->sampleRate = (uint16_t)sampleRate;
                mCblk->channels = (uint16_t)channelCount;
                mCblk->sampleRate = sampleRate;
                mCblk->channels = (uint8_t)channelCount;
                if (sharedBuffer == 0) {
                    mBuffer = (char*)mCblk + sizeof(audio_track_cblk_t);
                    memset(mBuffer, 0, frameCount*channelCount*sizeof(int16_t));
@@ -1627,8 +1627,8 @@ AudioFlinger::MixerThread::TrackBase::TrackBase(
           new(mCblk) audio_track_cblk_t();
           // clear all buffers
           mCblk->frameCount = frameCount;
           mCblk->sampleRate = (uint16_t)sampleRate;
           mCblk->channels = (uint16_t)channelCount;
           mCblk->sampleRate = sampleRate;
           mCblk->channels = (uint8_t)channelCount;
           mBuffer = (char*)mCblk + sizeof(audio_track_cblk_t);
           memset(mBuffer, 0, frameCount*channelCount*sizeof(int16_t));
           // Force underrun condition to avoid false underrun callback until first data is
@@ -1689,7 +1689,7 @@ int AudioFlinger::MixerThread::TrackBase::sampleRate() const {
}

int AudioFlinger::MixerThread::TrackBase::channelCount() const {
    return mCblk->channels;
    return (int)mCblk->channels;
}

void* AudioFlinger::MixerThread::TrackBase::getBuffer(uint32_t offset, uint32_t frames) const {
@@ -2274,12 +2274,6 @@ sp<IAudioRecord> AudioFlinger::openRecord(
        goto Exit;
    }

    if (sampleRate > MAX_SAMPLE_RATE) {
        LOGE("Sample rate out of range");
        lStatus = BAD_VALUE;
        goto Exit;
    }

    if (mAudioRecordThread == 0) {
        LOGE("Audio record thread not started");
        lStatus = NO_INIT;
Loading