Media Recorder 录像流程中时间戳的处理
[Audio]
1 AudioSource
1.1 AudioSource构造函数
52AudioSource::AudioSource( 53 audio_source_t inputSource, const String16 &opPackageName, 54 uint32_t sampleRate, uint32_t channelCount, uint32_t outSampleRate, 55 uid_t uid, pid_t pid)
1.2 DataCallBack
299status_t AudioSource::dataCallback(const AudioRecord::Buffer& audioBuffer) { 300 int64_t timeUs, position, timeNs; 301 ExtendedTimestamp ts; 302 ExtendedTimestamp::Location location; 303 const int32_t usPerSec = 1000000; 304 305 if (mRecord->getTimestamp(&ts) == OK && 306 ts.getBestTimestamp(&position, &timeNs, ExtendedTimestamp::TIMEBASE_MONOTONIC, 307 &location) == OK) { 308 // Use audio timestamp. 309 timeUs = timeNs / 1000 - 310 (position - mNumFramesSkipped - 311 mNumFramesReceived + mNumFramesLost) * usPerSec / mSampleRate; 312 } else { 313 // This should not happen in normal case. 314 ALOGW("Failed to get audio timestamp, fallback to use systemclock"); 315 timeUs = systemTime() / 1000ll; 316 // Estimate the real sampling time of the 1st sample in this buffer 317 // from AudioRecord's latency. (Apply this adjustment first so that 318 // the start time logic is not affected.) 319 timeUs -= mRecord->latency() * 1000LL; 320 } 321 322 ALOGV("dataCallbackTimestamp: %" PRId64 " us", timeUs);
1.3 Read
235status_t AudioSource::read( 236 MediaBuffer **out, const ReadOptions * /* options */) {
280 if (mSampleRate != mOutSampleRate) { 281 timeUs *= (int64_t)mSampleRate / (int64_t)mOutSampleRate; 282 buffer->meta_data()->setInt64(kKeyTime, timeUs); 283 } 284 285 *out = buffer; 286 return OK; 287}
[Video][Camera API 1.0]
2 CameraSource / CameraSourceTimeLapse (for time-lapse-recording)
1575 mCameraSourceTimeLapse = CameraSourceTimeLapse::CreateFromCamera( 1576 mCamera, mCameraProxy, mCameraId, mClientName, mClientUid, mClientPid, 1577 videoSize, mFrameRate, mPreviewSurface, 1578 std::llround(1e6 / mCaptureFps));
3 VideoEncoder(Acodec OnFillBufferDone)
4 MediaCodecSource(MediaCodec::CB_OUTPUT_AVAILABLE)
5 Writer(source->read buffer->meta_data kKeyTime)
[Video][Camera API 2.0]
6 GraphicBufferSource
6.1
897void GraphicBufferSource::onFrameAvailable(const BufferItem& item __unused) { 898 Mutex::Autolock autoLock(mMutex); 899 900 ALOGV("onFrameAvailable: executing=%d available=%zu+%d", 901 mExecuting, mAvailableBuffers.size(), mNumAvailableUnacquiredBuffers); 902 ++