Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Unified Diff: webrtc/modules/video_coding/generic_decoder.cc

Issue 2811963004: Deliver video frames on Android, on the decode thread.
Patch Set: Rebase Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/modules/video_coding/generic_decoder.h ('k') | webrtc/modules/video_coding/video_coding_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/video_coding/generic_decoder.cc
diff --git a/webrtc/modules/video_coding/generic_decoder.cc b/webrtc/modules/video_coding/generic_decoder.cc
index cc14794e090ce94121bbec4af8ef7458ae61f03a..5c79c4c8dc79f4473c5fe097791037e9b8e464e0 100644
--- a/webrtc/modules/video_coding/generic_decoder.cc
+++ b/webrtc/modules/video_coding/generic_decoder.cc
@@ -28,11 +28,13 @@ VCMDecodedFrameCallback::VCMDecodedFrameCallback(VCMTiming* timing,
_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(
@@ -41,9 +43,15 @@ void VCMDecodedFrameCallback::SetUserReceiveCallback(
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);
@@ -66,16 +74,14 @@ int32_t VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage,
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;
- {
- rtc::CritScope cs(&lock_);
- frameInfo = _timestampMap.Pop(decodedImage.timestamp());
- }
+ VCMFrameInformation* frameInfo = _timestampMap.Pop(decodedImage.timestamp());
if (frameInfo == NULL) {
LOG(LS_WARNING) << "Too many frames backed up in the decoder, dropping "
@@ -149,36 +155,37 @@ void VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage,
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::CritScope cs(&lock_);
+ RTC_DCHECK_RUN_ON(&decoder_thread_);
_timestampMap.Add(timestamp, frameInfo);
}
int32_t VCMDecodedFrameCallback::Pop(uint32_t timestamp) {
- rtc::CritScope cs(&lock_);
- if (_timestampMap.Pop(timestamp) == NULL) {
- return VCM_GENERAL_ERROR;
- }
- return VCM_OK;
+ RTC_DCHECK_RUN_ON(&decoder_thread_);
+ return _timestampMap.Pop(timestamp) == nullptr ? VCM_GENERAL_ERROR : VCM_OK;
}
VCMGenericDecoder::VCMGenericDecoder(VideoDecoder* decoder, bool isExternal)
@@ -201,6 +208,7 @@ VCMGenericDecoder::~VCMGenericDecoder() {
int32_t VCMGenericDecoder::InitDecode(const VideoCodec* settings,
int32_t numberOfCores) {
+ RTC_DCHECK_RUN_ON(&decoder_thread_);
TRACE_EVENT0("webrtc", "VCMGenericDecoder::InitDecode");
_codecType = settings->codecType;
@@ -208,51 +216,66 @@ int32_t VCMGenericDecoder::InitDecode(const VideoCodec* settings,
}
int32_t VCMGenericDecoder::Decode(const VCMEncodedFrame& frame, int64_t nowMs) {
- 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]);
+ 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]);
- _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());
- _callback->OnDecoderImplementationName(decoder_->ImplementationName());
+ // 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) {
if (ret < WEBRTC_VIDEO_CODEC_OK) {
- 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());
+ LOG(LS_WARNING) << "Failed to decode frame with timestamp "
+ << frame.TimeStamp() << ", error code: " << ret;
}
- return ret;
+ // 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;
}
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();
}
+#if defined(WEBRTC_ANDROID)
+void VCMGenericDecoder::PollDecodedFrames() {
+ RTC_DCHECK_RUN_ON(&decoder_thread_);
+ decoder_->PollDecodedFrames();
+}
+#endif
+
} // namespace webrtc
« no previous file with comments | « webrtc/modules/video_coding/generic_decoder.h ('k') | webrtc/modules/video_coding/video_coding_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698