您的位置:首页 > 编程语言 > Go语言

Google Time Lapse Recording 在高档手机上的一个实现

2018-03-15 21:36 225 查看

实现的配置是 mCaptureFp=240 mFrameRate=30

设置的SampleRate=48K,计算得到的sampleRate为384K 

1047 if (mCaptureFpsEnable && mCaptureFps >= mFrameRate) {1048 // Upscale the sample rate for slow motion recording.1049 // Fail audio source creation if source sample rate is too high, as it could1050 // cause out-of-memory due to large input buffer size. And audio recording1051 // probably doesn't make sense in the scenario, since the slow-down factor1052 // is probably huge (eg. mSampleRate=48K, mCaptureFps=240, mFrameRate=1).1053 const static int32_t SAMPLE_RATE_HZ_MAX = 192000;1054 sourceSampleRate =1055 (mSampleRate * mCaptureFps + mFrameRate / 2) / mFrameRate;1056 if (sourceSampleRate < mSampleRate || sourceSampleRate > SAMPLE_RATE_HZ_MAX) {1057 ALOGE("source sample rate out of range! "1058 "(mSampleRate %d, mCaptureFps %.2f, mFrameRate %d",1059 mSampleRate, mCaptureFps, mFrameRate);1060 return NULL;1061 }1062 }

1064 sp<AudioSource> audioSource =1065 new AudioSource(1066 mAudioSource,1067 mOpPackageName,1068 sourceSampleRate,//AudioRecord使用这个值来设置采样率1069 mAudioChannels,1070 mSampleRate,1071 mClientUid,1072 mClientPid);
如果需要有Pause/Resume功能的话,这里代码可能需要修改

1954 // 30 ms buffer to avoid timestamp overlap1955 mTotalPausedDurationUs += resumeStartTimeUs - mPauseStartTimeUs - 30000;1956 }1957 double timeOffset = -mTotalPausedDurationUs;1958 if (mCaptureFpsEnable) {1959 timeOffset *= mCaptureFps / mFrameRate;1960 }

[测试中出现的问题]

在240FPS的Video状态下,系统忙(CPU占用90%以上)

导致:Audio PCM数据在编码前的queue中堆积

可以查看的方法如下:

121void MediaCodecSource::Puller::Queue::pushBuffer(MediaBuffer *mbuf) {push buffer
122    mReadBuffers.push_back(mbuf);123}124125bool MediaCodecSource::Puller::Queue::readBuffer(MediaBuffer **mbuf) {pop buffer126    if (mReadBuffers.empty()) {127        *mbuf = NULL;128        return false;129    }130    *mbuf = *mReadBuffers.begin();131    mReadBuffers.erase(mReadBuffers.begin());132    return true;133}134135void MediaCodecSource::Puller::Queue::flush() {清空buffer136    MediaBuffer *mbuf;
需要在这里打印 mReadBuffers.size(),就知道audio Encoder性能不够
137    while (readBuffer(&mbuf)) {138        // there are no null buffers in the queue139        mbuf->release();140    }141}

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐