Media Recorder 录像流程中时间戳系统时间的处理2 PauseResume的时间戳处理

xiaoxiao2021-02-28  55

Media Recorder 录像流程中时间戳/系统时间的处理2 

Pause/Resume的时间处理

[Pause]

1897status_t StagefrightRecorder::pause() { 1898 ALOGV("pause"); 1899 if (!mStarted) { 1900 return INVALID_OPERATION; 1901 } 1902 1903 // Already paused --- no-op. 1904 if (mPauseStartTimeUs != 0) { 1905 return OK; 1906 } 1907 1908 mPauseStartTimeUs = systemTime() / 1000; 1909 sp<MetaData> meta = new MetaData; 1910 meta->setInt64(kKeyTime, mPauseStartTimeUs); 1911 1912 if (mAudioEncoderSource != NULL) { 1913 mAudioEncoderSource->pause(); 1914 } 1915 if (mVideoEncoderSource != NULL) { 1916 mVideoEncoderSource->pause(meta.get()); 1917 } 1918 1919 return OK; 1920}

[Resume]

1922status_t StagefrightRecorder::resume() { 1923 ALOGV("resume"); 1924 if (!mStarted) { 1925 return INVALID_OPERATION; 1926 } 1927 1928 // Not paused --- no-op. 1929 if (mPauseStartTimeUs == 0) { 1930 return OK; 1931 } 1932 1933 int64_t resumeStartTimeUs = systemTime() / 1000; 1934 1935 int64_t bufferStartTimeUs = 0; 1936 bool allSourcesStarted = true; 1937 for (const auto &source : { mAudioEncoderSource, mVideoEncoderSource }) { 1938 if (source == nullptr) { 1939 continue; 1940 } 1941 int64_t timeUs = source->getFirstSampleSystemTimeUs();//Source收到的第1帧数据的时间 1942 if (timeUs < 0) { 1943 allSourcesStarted = false; 1944 } 1945 if (bufferStartTimeUs < timeUs) { 1946 bufferStartTimeUs = timeUs; 1947 } 1948 } 1949 1950 if (allSourcesStarted) { 1951 if (mPauseStartTimeUs < bufferStartTimeUs) { 1952 mPauseStartTimeUs = bufferStartTimeUs; 1953 } 1954 // 30 ms buffer to avoid timestamp overlap 1955 mTotalPausedDurationUs += resumeStartTimeUs - mPauseStartTimeUs - 30000;//这里必须调整,因为有 time-lapse-recording的功能 1956 } 1957 double timeOffset = -mTotalPausedDurationUs; 1958 if (mCaptureFpsEnable) { 1959 timeOffset *= mCaptureFps / mFrameRate; 1960 } 1961 sp<MetaData> meta = new MetaData; 1962 meta->setInt64(kKeyTime, resumeStartTimeUs); 1963 for (const auto &source : { mAudioEncoderSource, mVideoEncoderSource }) { 1964 if (source == nullptr) { 1965 continue; 1966 } 1967 source->setInputBufferTimeOffset((int64_t)timeOffset); 1968 source->start(meta.get()); 1969 } 1970 mPauseStartTimeUs = 0; 1971 1972 return OK; 1973}

[MediaCodecSource]

951 case kWhatStart: 952 { 953 sp<AReplyToken> replyID; 954 CHECK(msg->senderAwaitsResponse(&replyID)); 955 956 sp<RefBase> obj; 957 CHECK(msg->findObject("meta", &obj)); 958 MetaData *params = static_cast<MetaData *>(obj.get()); 959 960 sp<AMessage> response = new AMessage; 961 response->setInt32("err", onStart(params)); 962 response->postReply(replyID); 963 break; 964 }

729status_t MediaCodecSource::onStart(MetaData *params) { 730 if (mStopping) { 731 ALOGE("Failed to start while we're stopping"); 732 return INVALID_OPERATION; 733 } 734 int64_t startTimeUs; 735 if (params == NULL || !params->findInt64(kKeyTime, &startTimeUs)) { 736 startTimeUs = -1ll; 737 } 738 739 if (mStarted) { 740 ALOGI("MediaCodecSource (%s) resuming", mIsVideo ? "video" : "audio"); 741 if (mPausePending) { 742 mPausePending = false; 743 return OK; 744 } 745 if (mIsVideo) { 746 mEncoder->requestIDRFrame(); 747 } 748 if (mFlags & FLAG_USE_SURFACE_INPUT) { 749 resume(startTimeUs); 750 } else { 751 CHECK(mPuller != NULL); 752 mPuller->resume(); 753 } 754 return OK; 755 }

[Video][Resume][CameraAPI 2.0]

639void MediaCodecSource::resume(int64_t resumeStartTimeUs) { 640 CHECK(mFlags & FLAG_USE_SURFACE_INPUT); 641 if (mEncoder != NULL) { 642 sp<AMessage> params = new AMessage; 643 params->setInt32("drop-input-frames", false); 644 if (resumeStartTimeUs > 0) { 645 params->setInt64("drop-start-time-us", resumeStartTimeUs); 646 } 647 mEncoder->setParameters(params);//encoder来处理停止帧发送等情况 648 } 649}

[Video][Resume][CameraAPI 1.0] or [Audio][Resume]

748 if (mFlags & FLAG_USE_SURFACE_INPUT) { 749 resume(startTimeUs); 750 } else { 751 CHECK(mPuller != NULL); 752 mPuller->resume();//here---[Video][Resume][CameraAPI 1.0] or [Audio][Resume] 753 }

转载请注明原文地址: https://www.6miu.com/read-2628208.html

最新回复(0)