Media Recorder 录像流程中时间戳的处理

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    ++
  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值