1. 用sdk里面的 emulator 启动的 模拟器没有声音。
2. 源码下的 emulator 启动的模拟器也没有声音。有重新生成新的 模拟器,也没有解决。AudioTrack 不断输出log:
W/AudioTrack(  152): obtainBuffer timed out (is the CPU pegged?) 0x2a202578 name=0x10user=00001000, server=00000000
是在 AudioTrack.cpp的 obtainBuffer()中输出的log。代码:
因为对这部分代码不熟悉,不过我想还是模拟器的原因。想知道具体是什么原因,怎么解决?obtainBuffer代码:status_t AudioTrack::obtainBuffer(Buffer* audioBuffer, int32_t waitCount)
{
    AutoMutex lock(mLock);
    bool active;
    status_t result = NO_ERROR;
    audio_track_cblk_t* cblk = mCblk;
    uint32_t framesReq = audioBuffer->frameCount;
    uint32_t waitTimeMs = (waitCount < 0) ? cblk->bufferTimeoutMs : WAIT_PERIOD_MS;    audioBuffer->frameCount  = 0;
    audioBuffer->size = 0;    uint32_t framesAvail = cblk->framesAvailable();    cblk->lock.lock();
    if (cblk->flags & CBLK_INVALID_MSK) {
        goto create_new_track;
    }
    cblk->lock.unlock();    if (framesAvail == 0) {
        cblk->lock.lock();
        goto start_loop_here;
        while (framesAvail == 0) {
            active = mActive;
            if (CC_UNLIKELY(!active)) {
                ALOGV("Not active and NO_MORE_BUFFERS");
                cblk->lock.unlock();
                return NO_MORE_BUFFERS;
            }
            if (CC_UNLIKELY(!waitCount)) {
                cblk->lock.unlock();
                return WOULD_BLOCK;
            }
            if (!(cblk->flags & CBLK_INVALID_MSK)) {
                mLock.unlock();
                result = cblk->cv.waitRelative(cblk->lock, milliseconds(waitTimeMs));
                cblk->lock.unlock();
                mLock.lock();
                if (!mActive) {
                    return status_t(STOPPED);
                }
                cblk->lock.lock();
            }            if (cblk->flags & CBLK_INVALID_MSK) {
                goto create_new_track;
            }
            if (CC_UNLIKELY(result != NO_ERROR)) {
                cblk->waitTimeMs += waitTimeMs;
                if (cblk->waitTimeMs >= cblk->bufferTimeoutMs) {
                    // timing out when a loop has been set and we have already written upto loop end
                    // is a normal condition: no need to wake AudioFlinger up.
                    if (cblk->user < cblk->loopEnd) {//这个地方不断输出log
                        ALOGW(   "obtainBuffer timed out (is the CPU pegged?) %p name=%#x"
                                "user=%08x, server=%08x", this, cblk->mName, cblk->user, cblk->server);
                        //unlock cblk mutex before calling mAudioTrack->start() (see issue #1617140)
                        cblk->lock.unlock();
                        result = mAudioTrack->start();
                        cblk->lock.lock();
                        if (result == DEAD_OBJECT) {
                            android_atomic_or(CBLK_INVALID_ON, &cblk->flags);
create_new_track:
                            result = restoreTrack_l(cblk, false);
                        }
                        if (result != NO_ERROR) {
                            ALOGW("obtainBuffer create Track error %d", result);
                            cblk->lock.unlock();
                            return result;
                        }
                    }
                    cblk->waitTimeMs = 0;
                }                if (--waitCount == 0) {
                    cblk->lock.unlock();
                    return TIMED_OUT;
                }
            }
            // read the server count again
        start_loop_here:
            framesAvail = cblk->framesAvailable_l();
        }
        cblk->lock.unlock();
    }    cblk->waitTimeMs = 0;    if (framesReq > framesAvail) {
        framesReq = framesAvail;
    }    uint32_t u = cblk->user;
    uint32_t bufferEnd = cblk->userBase + cblk->frameCount;    if (framesReq > bufferEnd - u) {
        framesReq = bufferEnd - u;
    }    audioBuffer->flags = mMuted ? Buffer::MUTE : 0;
    audioBuffer->channelCount = mChannelCount;
    audioBuffer->frameCount = framesReq;
    audioBuffer->size = framesReq * cblk->frameSize;
    if (audio_is_linear_pcm(mFormat)) {
        audioBuffer->format = AUDIO_FORMAT_PCM_16_BIT;
    } else {
        audioBuffer->format = mFormat;
    }
    audioBuffer->raw = (int8_t *)cblk->buffer(u);
    active = mActive;
    return active ? status_t(NO_ERROR) : status_t(STOPPED);
}Android AudioTrackAndroid Emulator音乐

解决方案 »

  1.   

    我先后用:
    emulator -no-snapstorage -sdcard sdcard.img -partition-size 500 -memory 500

    emulator -no-snapshot -sdcard sdcard.img -partition-size 500 -memory 500
    禁用掉snapshot,还是和之前一样,没有声音。
      

  2.   

    请问,我发现我生成的镜像文件 没有cache image。记得以前好像是有的。
    不知道和这个有没有关系?
      

  3.   

    请问,我发现我生成的镜像文件 没有cache image。记得以前好像是有的。
    不知道和这个有没有关系?有关系的...
      

  4.   

    请问,我发现我生成的镜像文件 没有cache image。记得以前好像是有的。
    不知道和这个有没有关系?有关系的...我用 -cache 使用sdk生成的cache.img,還是那個樣子。木用