status_t AudioStreamInALSA::setAcousticParams(void *params)
{
    android::AutoMutex lock(mLock);

    acoustic_device_t *aDev = acoustics();

    return aDev ? aDev->set_params(aDev, mAcoustics, params) : (status_t)NO_ERROR;
}
AudioStreamInALSA::AudioStreamInALSA(AudioHardwareALSA *parent,
        alsa_handle_t *handle,
        AudioSystem::audio_in_acoustics audio_acoustics) :
    ALSAStreamOps(parent, handle),
    mFramesLost(0),
    mAcoustics(audio_acoustics)
{
    acoustic_device_t *aDev = acoustics();

    if (aDev) aDev->set_params(aDev, mAcoustics, NULL);
}
Ejemplo n.º 3
0
status_t AudioStreamInALSA::setAcousticParams(void *params)
{
    /*m@nufront start*/
    /*AutoMutex lock(mLock);*/
    android::AutoMutex lock(mLock);
    /*m@nufront end*/

    acoustic_device_t *aDev = acoustics();

    return aDev ? aDev->set_params(aDev, mAcoustics, params) : (status_t)NO_ERROR;
}
status_t AudioStreamInALSA::open(int mode)
{
    android::AutoMutex lock(mLock);

    status_t status = ALSAStreamOps::open(mode);

    acoustic_device_t *aDev = acoustics();

    if (status == NO_ERROR && aDev)
        status = aDev->use_handle(aDev, mHandle);

    return status;
}
status_t AudioStreamInALSA::close()
{
    android::AutoMutex lock(mLock);

    acoustic_device_t *aDev = acoustics();

    if (mHandle && aDev) aDev->cleanup(aDev);

    ALSAStreamOps::close();

    if (mPowerLock) {
        release_wake_lock ("AudioInLock");
        mPowerLock = false;
    }

    return NO_ERROR;
}
Ejemplo n.º 6
0
ssize_t AudioStreamInALSA::read(void *buffer, ssize_t bytes)
{
    /*m@nufront start*/
    /*AutoMutex lock(mLock);*/
    android::AutoMutex lock(mLock);
    /*m@nufront end*/

    if (!mPowerLock) {
        acquire_wake_lock (PARTIAL_WAKE_LOCK, "AudioInLock");
        mPowerLock = true;
    }

    acoustic_device_t *aDev = acoustics();

    // If there is an acoustics module read method, then it overrides this
    // implementation (unlike AudioStreamOutALSA write).
    if (aDev && aDev->read)
        return aDev->read(aDev, buffer, bytes);

    snd_pcm_sframes_t n, frames = snd_pcm_bytes_to_frames(mHandle->handle, bytes);
    status_t          err;

    do {
        n = snd_pcm_readi(mHandle->handle, buffer, frames);
        /*a@nufront start*/
        if (n == -EPIPE) {
            ZJFLOGD("xrun.");
            xrun(mHandle->handle);
        }
        /*a@nufront end*/
        if (n < frames) {
            if (mHandle->handle) {

                if (n < 0) {
                    n = snd_pcm_recover(mHandle->handle, n, 0);

                    if (aDev && aDev->recover) aDev->recover(aDev, n);
                } else
                    n = snd_pcm_prepare(mHandle->handle);
            }
            return static_cast<ssize_t>(n);
        }
    } while (n == -EAGAIN);

    return static_cast<ssize_t>(snd_pcm_frames_to_bytes(mHandle->handle, n));
}
ssize_t AudioStreamOutALSA::write(const void *buffer, size_t bytes)
{
    AutoMutex lock(mLock);

    if (!mPowerLock) {
        acquire_wake_lock (PARTIAL_WAKE_LOCK, "AudioOutLock");
        mPowerLock = true;
		mHandle->module->popAttenu(0);        // 20100604 [email protected], No pop noise set(amp on delay) [START_LGE]
		mHandle->module->route(mHandle, mHandle->curDev, mHandle->curMode); //[email protected] 20100308 codec_onoff
		usleep(35000);  //201104011 [email protected], fix sound tick noise from global B
    }

	/* check if handle is still valid, otherwise we are coming out of standby */
	if(mHandle->handle == NULL) {
         nsecs_t previously = systemTime();
	     mHandle->module->open(mHandle, mHandle->curDev, mHandle->curMode);
         nsecs_t delta = systemTime() - previously;
         LOGE("1.RE-OPEN AFTER STANDBY:: took %llu msecs\n", ns2ms(delta));
	}

    acoustic_device_t *aDev = acoustics();

    // For output, we will pass the data on to the acoustics module, but the actual
    // data is expected to be sent to the audio device directly as well.
    if (aDev && aDev->write)
        aDev->write(aDev, buffer, bytes);

#if 0
    snd_pcm_sframes_t n;
#else
//[email protected] - BT connect -> music play -> voice dialer start/end 시 music restart 되는 현상 수정.
    snd_pcm_sframes_t n = 0;  
#endif
    size_t            sent = 0;
    status_t          err;

    do {
//[email protected] - BT connect -> music play -> voice dialer start/end 시 music restart 되는 현상 수정. [START]
		if(mHandle->handle != NULL)   
		{                 
//[email protected] - BT connect -> music play -> voice dialer start/end 시 music restart 되는 현상 수정. [END]		
        n = snd_pcm_writei(mHandle->handle,
                           (char *)buffer + sent,
                           snd_pcm_bytes_to_frames(mHandle->handle, bytes - sent));
//[email protected] - BT connect -> music play -> voice dialer start/end 시 music restart 되는 현상 수정. [START]
		}
		else{
          	nsecs_t previously = systemTime();
          	mHandle->module->open(mHandle, mHandle->curDev, mHandle->curMode);
          	nsecs_t delta = systemTime() - previously;
          	LOGD("2.RE-OPEN AFTER STANDBY:: took %llu msecs\n", ns2ms(delta));
        }
//[email protected] - BT connect -> music play -> voice dialer start/end 시 music restart 되는 현상 수정. [END] 	
        if (n == -EBADFD) {
            // Somehow the stream is in a bad state. The driver probably
            // has a bug and snd_pcm_recover() doesn't seem to handle this.
            mHandle->module->open(mHandle, mHandle->curDev, mHandle->curMode);

            if (aDev && aDev->recover) aDev->recover(aDev, n);
            //bail
            if (n) return static_cast<ssize_t>(n);
        }
        else if (n < 0) {
            if (mHandle->handle) {

                // snd_pcm_recover() will return 0 if successful in recovering from
                // an error, or -errno if the error was unrecoverable.
                n = snd_pcm_recover(mHandle->handle, n, 1);

                if (aDev && aDev->recover) aDev->recover(aDev, n);

                if (n) return static_cast<ssize_t>(n);
            }
        }
        else {
			if(mHandle->handle){	//[email protected] - BT connect -> music play -> voice dialer start/end 시 music restart 되는 현상 수정.		
            	mFrameCount += n;
            	sent += static_cast<ssize_t>(snd_pcm_frames_to_bytes(mHandle->handle, n));
//[email protected] - BT connect -> music play -> voice dialer start/end 시 music restart 되는 현상 수정. [START]
				}   
			else{
          		nsecs_t previously = systemTime();
         		mHandle->module->open(mHandle, mHandle->curDev, mHandle->curMode);
          		nsecs_t delta = systemTime() - previously;
         	    LOGD("3.RE-OPEN AFTER STANDBY:: took %llu msecs\n", ns2ms(delta));
			}
//[email protected] - BT connect -> music play -> voice dialer start/end 시 music restart 되는 현상 수정. [END]
        }

    } while (mHandle->handle && sent < bytes);

    return sent;
}
Ejemplo n.º 8
0
ssize_t AudioStreamOutALSA::write(const void *buffer, size_t bytes)
{
    AutoMutex lock(mLock);

    if (!mPowerLock) {
        acquire_wake_lock (PARTIAL_WAKE_LOCK, "AudioOutLock");
        mPowerLock = true;
        usleep(35000);  //201104011 [email protected], fix sound tick noise from global B

    }

    /* check if handle is still valid, otherwise we are coming out of standby */
    if(mHandle->handle == NULL) {
         nsecs_t previously = systemTime();
         mHandle->module->open(mHandle, mHandle->curDev, mHandle->curMode, mHandle->curChannels);
         nsecs_t delta = systemTime() - previously;
         LOGE("RE-OPEN AFTER STANDBY:: took %llu msecs\n", ns2ms(delta));
    }

    acoustic_device_t *aDev = acoustics();

    // For output, we will pass the data on to the acoustics module, but the actual
    // data is expected to be sent to the audio device directly as well.
    if (aDev && aDev->write)
        aDev->write(aDev, buffer, bytes);

    snd_pcm_sframes_t n;
    size_t            sent = 0;
    status_t          err;

    while (mHandle->handle && sent < bytes) {
        n = snd_pcm_writei(mHandle->handle,
                           (char *)buffer + sent,
                           snd_pcm_bytes_to_frames(mHandle->handle, bytes - sent));
        if (n == -EBADFD) {
            // Somehow the stream is in a bad state. The driver probably
            // has a bug and snd_pcm_recover() doesn't seem to handle this.
            mHandle->module->open(mHandle, mHandle->curDev, mHandle->curMode, mHandle->curChannels);

            if (aDev && aDev->recover) aDev->recover(aDev, n);
        }
        else if (n < 0) {
            if (mHandle->handle) {
                // snd_pcm_recover() will return 0 if successful in recovering from
                // an error, or -errno if the error was unrecoverable.
                n = snd_pcm_recover(mHandle->handle, n, 1);

                if (aDev && aDev->recover) aDev->recover(aDev, n);

                if (n) return static_cast<ssize_t>(n);
            }
        }
        else {
            if (mHandle->handle) {
                mFrameCount += n;
                sent += static_cast<ssize_t>(snd_pcm_frames_to_bytes(mHandle->handle, n));
            }
        }

    } 

    return sent;
}
ssize_t AudioStreamInALSA::read(void *buffer, ssize_t bytes)
{
    AutoMutex lock(mLock);

    if (!mPowerLock) {
        acquire_wake_lock (PARTIAL_WAKE_LOCK, "AudioInLock");
        mPowerLock = true;
    }

    acoustic_device_t *aDev = acoustics();

    // If there is an acoustics module read method, then it overrides this
    // implementation (unlike AudioStreamOutALSA write).
    if (aDev && aDev->read)
        return aDev->read(aDev, buffer, bytes);

    snd_pcm_sframes_t n, frames = snd_pcm_bytes_to_frames(mHandle->handle, bytes);
    status_t          err;

    do {
        n = snd_pcm_readi(mHandle->handle, buffer, frames);
#ifdef DROPFRAME
#ifdef DROPFRAME2
        FrameNumber++;
        if (!(FrameNumber % 17) && (FrameNumber <= 1700))
        {
            n = snd_pcm_readi(mHandle->handle, buffer, frames);
        }
        if (!(FrameNumber % 176))
        {
            n = snd_pcm_readi(mHandle->handle, buffer, frames);
        }
        if (FrameNumber == 1764)
        {
            FrameNumber = 0;
            n = snd_pcm_readi(mHandle->handle, buffer, frames);
        }
#else
        FrameNumber++;
        if (FrameNumber == 624/*137* rane@2012 07 20*/)
        {
            FrameNumber = 0;
            n = snd_pcm_readi(mHandle->handle, buffer, frames);
        }
#endif
#endif
        if (n < frames) {
            if (mHandle->handle) {
                if (n < 0) {
                    n = snd_pcm_recover(mHandle->handle, n, 0);

                    if (aDev && aDev->recover) aDev->recover(aDev, n);
                } else
                    n = snd_pcm_prepare(mHandle->handle);
            }
            return static_cast<ssize_t>(n);
        }
    } while (n == -EAGAIN);

    return static_cast<ssize_t>(snd_pcm_frames_to_bytes(mHandle->handle, n));
}
ssize_t AudioStreamOutALSA::write(const void *buffer, size_t bytes)
{
    android::AutoMutex lock(mLock);

    if (!mPowerLock) {
        acquire_wake_lock (PARTIAL_WAKE_LOCK, "AudioOutLock");
        mPowerLock = true;
    }

    acoustic_device_t *aDev = acoustics();

    // For output, we will pass the data on to the acoustics module, but the actual
    // data is expected to be sent to the audio device directly as well.
    if (aDev && aDev->write)
        aDev->write(aDev, buffer, bytes);

    snd_pcm_sframes_t n;
    size_t            sent = 0;
    status_t          err = 0;

    do {
        if (mHandle->mmap)
            n = snd_pcm_mmap_writei(mHandle->handle,
                               (char *)buffer + sent,
                               snd_pcm_bytes_to_frames(mHandle->handle, bytes - sent));
	else
            n = snd_pcm_writei(mHandle->handle,
                               (char *)buffer + sent,
                               snd_pcm_bytes_to_frames(mHandle->handle, bytes - sent));
        if (n == -EBADFD) {
            LOGW("badstate and do recovery.....");
            switch(snd_pcm_state(mHandle->handle)){
                case SND_PCM_STATE_SETUP:
                    err = snd_pcm_prepare(mHandle->handle);
                    if(err < 0) LOGW("snd_pcm_prepare failed");
                    break;
                case SND_PCM_STATE_SUSPENDED:
                    snd_pcm_resume(mHandle->handle);
                    if(err < 0) LOGW("snd_pcm_resume failed");
                    snd_pcm_prepare(mHandle->handle);
                    if(err < 0) LOGW("snd_pcm_prepare failed");
                    break;
                default:
                    // Somehow the stream is in a bad state. The driver probably
                    // has a bug and snd_pcm_recover() doesn't seem to handle this.
                    mHandle->module->open(mHandle, mHandle->curDev, mHandle->curMode);
                    break;
            }

            if(err < 0 ) mHandle->module->open(mHandle, mHandle->curDev, mHandle->curMode);

            if (aDev && aDev->recover) aDev->recover(aDev, n);
        }
        else if (n < 0) {
            if (mHandle->handle) {
                LOGW("underrun and do recovery.....");
                // snd_pcm_recover() will return 0 if successful in recovering from
                // an error, or -errno if the error was unrecoverable.
                n = snd_pcm_recover(mHandle->handle, n, 1);

                if (aDev && aDev->recover) aDev->recover(aDev, n);

                if (n) return static_cast<ssize_t>(n);
            }
        }
        else {
            mFrameCount += n;
            sent += static_cast<ssize_t>(snd_pcm_frames_to_bytes(mHandle->handle, n));
        }

    } while (mHandle->handle && sent < bytes);

    return sent;
}