Revert "VCMGenericDecoder threading updates for all but Android."
This reverts commit a4e71b9e7e59be21b98d63cf8cb676096d9c74b0.
Reason for revert: Breaking internal project
Original change's description:
> VCMGenericDecoder threading updates for all but Android.
>
> * All methods now have thread checks.
> * Variable access associated with thread checkers.
> * Remove need for |rtc::CriticalSection lock_|
>
> Since the android decoder is inherently asynchronous, and
> FrameBuffer2's decoder doesn't support posting tasks to it
> yet (for async decode completion), we need to tackle android
> separately. Once FrameBuffer2 gets changed to use a TaskQueue
> or ProcessThread, we can move Android over to delivering decoded
> frames on the right thread/queue and delete generic_decoder_android.*.
>
> Note: This is a subset of code that was previously reviewed here:
> - https://codereview.webrtc.org/2764573002/
>
> Bug: webrtc:7361, webrtc:8907, chromium:695438
> Change-Id: I118609dfa5c0f0180287d8c2b6d62987b7473c5c
> Reviewed-on: https://webrtc-review.googlesource.com/55060
> Commit-Queue: Tommi <tommi@webrtc.org>
> Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#22119}
TBR=sakal@webrtc.org,tommi@webrtc.org
Change-Id: I3afe4671f9d06bb4a2b17e4f14c21d79f773e067
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:7361, webrtc:8907, chromium:695438
Reviewed-on: https://webrtc-review.googlesource.com/56282
Reviewed-by: Lu Liu <lliuu@webrtc.org>
Commit-Queue: Lu Liu <lliuu@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22143}
diff --git a/modules/video_coding/generic_decoder.cc b/modules/video_coding/generic_decoder.cc
index fe68998..a7d6a85 100644
--- a/modules/video_coding/generic_decoder.cc
+++ b/modules/video_coding/generic_decoder.cc
@@ -28,13 +28,11 @@
_timing(timing),
_timestampMap(kDecoderFrameMemoryLength),
_lastReceivedPictureID(0) {
- decoder_thread_.DetachFromThread();
ntp_offset_ =
_clock->CurrentNtpInMilliseconds() - _clock->TimeInMilliseconds();
}
VCMDecodedFrameCallback::~VCMDecodedFrameCallback() {
- RTC_DCHECK(construction_thread_.CalledOnValidThread());
}
void VCMDecodedFrameCallback::SetUserReceiveCallback(
@@ -43,15 +41,9 @@
RTC_DCHECK((!_receiveCallback && receiveCallback) ||
(_receiveCallback && !receiveCallback));
_receiveCallback = receiveCallback;
- // When the callback is cleared, it signals to us that the decoder thread
- // is no longer running. Another decoder thread might be started, so it's
- // important to reset the thread checker first.
- if (!receiveCallback)
- decoder_thread_.DetachFromThread();
}
VCMReceiveCallback* VCMDecodedFrameCallback::UserReceiveCallback() {
- RTC_DCHECK_RUN_ON(&decoder_thread_);
// Called on the decode thread via VCMCodecDataBase::GetDecoder.
// The callback must always have been set before this happens.
RTC_DCHECK(_receiveCallback);
@@ -74,14 +66,16 @@
void VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage,
rtc::Optional<int32_t> decode_time_ms,
rtc::Optional<uint8_t> qp) {
- RTC_DCHECK_RUN_ON(&decoder_thread_);
RTC_DCHECK(_receiveCallback) << "Callback must not be null at this point";
-
TRACE_EVENT_INSTANT1("webrtc", "VCMDecodedFrameCallback::Decoded",
"timestamp", decodedImage.timestamp());
// TODO(holmer): We should improve this so that we can handle multiple
// callbacks from one call to Decode().
- VCMFrameInformation* frameInfo = _timestampMap.Pop(decodedImage.timestamp());
+ VCMFrameInformation* frameInfo;
+ {
+ rtc::CritScope cs(&lock_);
+ frameInfo = _timestampMap.Pop(decodedImage.timestamp());
+ }
if (frameInfo == NULL) {
RTC_LOG(LS_WARNING) << "Too many frames backed up in the decoder, dropping "
@@ -155,37 +149,36 @@
int32_t VCMDecodedFrameCallback::ReceivedDecodedReferenceFrame(
const uint64_t pictureId) {
- RTC_DCHECK_RUN_ON(&decoder_thread_);
return _receiveCallback->ReceivedDecodedReferenceFrame(pictureId);
}
int32_t VCMDecodedFrameCallback::ReceivedDecodedFrame(
const uint64_t pictureId) {
- RTC_DCHECK_RUN_ON(&decoder_thread_);
_lastReceivedPictureID = pictureId;
return 0;
}
uint64_t VCMDecodedFrameCallback::LastReceivedPictureID() const {
- RTC_DCHECK_RUN_ON(&decoder_thread_);
return _lastReceivedPictureID;
}
void VCMDecodedFrameCallback::OnDecoderImplementationName(
const char* implementation_name) {
- RTC_DCHECK_RUN_ON(&decoder_thread_);
_receiveCallback->OnDecoderImplementationName(implementation_name);
}
void VCMDecodedFrameCallback::Map(uint32_t timestamp,
VCMFrameInformation* frameInfo) {
- RTC_DCHECK_RUN_ON(&decoder_thread_);
+ rtc::CritScope cs(&lock_);
_timestampMap.Add(timestamp, frameInfo);
}
int32_t VCMDecodedFrameCallback::Pop(uint32_t timestamp) {
- RTC_DCHECK_RUN_ON(&decoder_thread_);
- return _timestampMap.Pop(timestamp) == nullptr ? VCM_GENERAL_ERROR : VCM_OK;
+ rtc::CritScope cs(&lock_);
+ if (_timestampMap.Pop(timestamp) == NULL) {
+ return VCM_GENERAL_ERROR;
+ }
+ return VCM_OK;
}
VCMGenericDecoder::VCMGenericDecoder(std::unique_ptr<VideoDecoder> decoder)
@@ -211,7 +204,6 @@
int32_t VCMGenericDecoder::InitDecode(const VideoCodec* settings,
int32_t numberOfCores) {
- RTC_DCHECK_RUN_ON(&decoder_thread_);
TRACE_EVENT0("webrtc", "VCMGenericDecoder::InitDecode");
_codecType = settings->codecType;
@@ -219,58 +211,50 @@
}
int32_t VCMGenericDecoder::Decode(const VCMEncodedFrame& frame, int64_t nowMs) {
- RTC_DCHECK_RUN_ON(&decoder_thread_);
- TRACE_EVENT2("webrtc", "VCMGenericDecoder::Decode", "timestamp",
- frame.EncodedImage()._timeStamp, "decoder",
- decoder_->ImplementationName());
- _frameInfos[_nextFrameInfoIdx].decodeStartTimeMs = nowMs;
- _frameInfos[_nextFrameInfoIdx].renderTimeMs = frame.RenderTimeMs();
- _frameInfos[_nextFrameInfoIdx].rotation = frame.rotation();
- _frameInfos[_nextFrameInfoIdx].timing = frame.video_timing();
- // Set correctly only for key frames. Thus, use latest key frame
- // content type. If the corresponding key frame was lost, decode will fail
- // and content type will be ignored.
- if (frame.FrameType() == kVideoFrameKey) {
- _frameInfos[_nextFrameInfoIdx].content_type = frame.contentType();
- _last_keyframe_content_type = frame.contentType();
- } else {
- _frameInfos[_nextFrameInfoIdx].content_type = _last_keyframe_content_type;
- }
- _callback->Map(frame.TimeStamp(), &_frameInfos[_nextFrameInfoIdx]);
+ TRACE_EVENT1("webrtc", "VCMGenericDecoder::Decode", "timestamp",
+ frame.EncodedImage()._timeStamp);
+ _frameInfos[_nextFrameInfoIdx].decodeStartTimeMs = nowMs;
+ _frameInfos[_nextFrameInfoIdx].renderTimeMs = frame.RenderTimeMs();
+ _frameInfos[_nextFrameInfoIdx].rotation = frame.rotation();
+ _frameInfos[_nextFrameInfoIdx].timing = frame.video_timing();
+ // Set correctly only for key frames. Thus, use latest key frame
+ // content type. If the corresponding key frame was lost, decode will fail
+ // and content type will be ignored.
+ if (frame.FrameType() == kVideoFrameKey) {
+ _frameInfos[_nextFrameInfoIdx].content_type = frame.contentType();
+ _last_keyframe_content_type = frame.contentType();
+ } else {
+ _frameInfos[_nextFrameInfoIdx].content_type = _last_keyframe_content_type;
+ }
+ _callback->Map(frame.TimeStamp(), &_frameInfos[_nextFrameInfoIdx]);
- _nextFrameInfoIdx = (_nextFrameInfoIdx + 1) % kDecoderFrameMemoryLength;
- const RTPFragmentationHeader dummy_header;
- int32_t ret = decoder_->Decode(frame.EncodedImage(), frame.MissingFrame(),
- &dummy_header, frame.CodecSpecific(),
- frame.RenderTimeMs());
+ _nextFrameInfoIdx = (_nextFrameInfoIdx + 1) % kDecoderFrameMemoryLength;
+ const RTPFragmentationHeader dummy_header;
+ int32_t ret = decoder_->Decode(frame.EncodedImage(), frame.MissingFrame(),
+ &dummy_header,
+ frame.CodecSpecific(), frame.RenderTimeMs());
- // TODO(tommi): Necessary every time?
- // Maybe this should be the first thing the function does, and only the first
- // time around?
- _callback->OnDecoderImplementationName(decoder_->ImplementationName());
-
- if (ret != WEBRTC_VIDEO_CODEC_OK) {
+ _callback->OnDecoderImplementationName(decoder_->ImplementationName());
if (ret < WEBRTC_VIDEO_CODEC_OK) {
RTC_LOG(LS_WARNING) << "Failed to decode frame with timestamp "
<< frame.TimeStamp() << ", error code: " << ret;
+ _callback->Pop(frame.TimeStamp());
+ return ret;
+ } else if (ret == WEBRTC_VIDEO_CODEC_NO_OUTPUT ||
+ ret == WEBRTC_VIDEO_CODEC_REQUEST_SLI) {
+ // No output
+ _callback->Pop(frame.TimeStamp());
}
- // We pop the frame for all non-'OK', failure or success codes such as
- // WEBRTC_VIDEO_CODEC_NO_OUTPUT and WEBRTC_VIDEO_CODEC_REQUEST_SLI.
- _callback->Pop(frame.TimeStamp());
- }
-
- return ret;
+ return ret;
}
int32_t VCMGenericDecoder::RegisterDecodeCompleteCallback(
VCMDecodedFrameCallback* callback) {
- RTC_DCHECK_RUN_ON(&decoder_thread_);
_callback = callback;
return decoder_->RegisterDecodeCompleteCallback(callback);
}
bool VCMGenericDecoder::PrefersLateDecoding() const {
- RTC_DCHECK_RUN_ON(&decoder_thread_);
return decoder_->PrefersLateDecoding();
}