Deliver video frames on Android, on the decode thread.
VideoCoding * Adding a method for polling for frames on Android only until the capture implementation takes care of this (longer term plan). CodecDatabase * Add an accessor for the current decoder * Use std::unique_ptr<> for ownership. * Remove "Release()" and "ReleaseDecoder()". Instead just delete. * Remove |friend| relationship between CodecDatabase and VCMGenericDecoder. VCMDecodedFrameCallback * DCHECKs for thread correctness. * Remove |lock_| now that a threading model has been established and verified. VCMGenericDecoder * All methods now have thread checks. * Variable access associated with thread checkers. VideoReceiver * Added two notification methods, DecoderThreadStarting() and DecoderThreadStopped() * Allows us to establish a period when the decoder thread is not running and it is safe to modify variables such as callbacks, that are only read when the decoder thread is running. * Allows us to DCHECK thread guarantees. * Allows synchronizing callbacks from the module process thread and have them only active while the decoder thread is running. * The above, allows us to establish two modes for the thread, single-threaded-mutable and multi-threaded-const. * Using that knowledge, we can remove |receive_crit_| as well as locking for a number of member variables. MediaCodecVideoDecoder * Removed frame polling code from this class, since this is now done from the root thread function in VideoReceiveStream. VideoReceiveStream * On Android: Polls for decoded frames every 10ms (same interval as previously in MediaCodecVideoDecoder) * [Un]Registers the |video_receiver_| with the module thread only around the time the decoder thread is started/stopped. * Notifies the receiver of start/stop events of the decoder thread. * Changed the decoder thread to use the new PlatformThread callback type. BUG=webrtc:7361, 695438 Review-Url: https://codereview.webrtc.org/2764573002 Cr-Commit-Position: refs/heads/master@{#17527}
This commit is contained in:
@ -138,6 +138,14 @@ bool VideoDecoderSoftwareFallbackWrapper::PrefersLateDecoding() const {
|
|||||||
return decoder_->PrefersLateDecoding();
|
return decoder_->PrefersLateDecoding();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(WEBRTC_ANDROID)
|
||||||
|
void VideoDecoderSoftwareFallbackWrapper::PollDecodedFrames() {
|
||||||
|
if (fallback_decoder_)
|
||||||
|
return fallback_decoder_->PollDecodedFrames();
|
||||||
|
return decoder_->PollDecodedFrames();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
const char* VideoDecoderSoftwareFallbackWrapper::ImplementationName() const {
|
const char* VideoDecoderSoftwareFallbackWrapper::ImplementationName() const {
|
||||||
if (fallback_decoder_)
|
if (fallback_decoder_)
|
||||||
return fallback_implementation_name_.c_str();
|
return fallback_implementation_name_.c_str();
|
||||||
|
@ -41,6 +41,11 @@ class VideoDecoderSoftwareFallbackWrapper : public webrtc::VideoDecoder {
|
|||||||
int32_t Release() override;
|
int32_t Release() override;
|
||||||
bool PrefersLateDecoding() const override;
|
bool PrefersLateDecoding() const override;
|
||||||
|
|
||||||
|
#if defined(WEBRTC_ANDROID)
|
||||||
|
// See https://bugs.chromium.org/p/webrtc/issues/detail?id=7361
|
||||||
|
void PollDecodedFrames() override;
|
||||||
|
#endif
|
||||||
|
|
||||||
const char* ImplementationName() const override;
|
const char* ImplementationName() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -71,6 +71,31 @@ VideoCodecH264 VideoEncoder::GetDefaultH264Settings() {
|
|||||||
return h264_settings;
|
return h264_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create an internal Decoder given a codec type
|
||||||
|
static std::unique_ptr<VCMGenericDecoder> CreateDecoder(VideoCodecType type) {
|
||||||
|
switch (type) {
|
||||||
|
case kVideoCodecVP8:
|
||||||
|
return std::unique_ptr<VCMGenericDecoder>(
|
||||||
|
new VCMGenericDecoder(VP8Decoder::Create()));
|
||||||
|
case kVideoCodecVP9:
|
||||||
|
return std::unique_ptr<VCMGenericDecoder>(
|
||||||
|
new VCMGenericDecoder(VP9Decoder::Create()));
|
||||||
|
case kVideoCodecI420:
|
||||||
|
return std::unique_ptr<VCMGenericDecoder>(
|
||||||
|
new VCMGenericDecoder(new I420Decoder()));
|
||||||
|
case kVideoCodecH264:
|
||||||
|
if (H264Decoder::IsSupported()) {
|
||||||
|
return std::unique_ptr<VCMGenericDecoder>(
|
||||||
|
new VCMGenericDecoder(H264Decoder::Create()));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
LOG(LS_WARNING) << "No internal decoder of this type exists.";
|
||||||
|
return std::unique_ptr<VCMGenericDecoder>();
|
||||||
|
}
|
||||||
|
|
||||||
VCMDecoderMapItem::VCMDecoderMapItem(VideoCodec* settings,
|
VCMDecoderMapItem::VCMDecoderMapItem(VideoCodec* settings,
|
||||||
int number_of_cores,
|
int number_of_cores,
|
||||||
bool require_key_frame)
|
bool require_key_frame)
|
||||||
@ -98,13 +123,12 @@ VCMCodecDataBase::VCMCodecDataBase(
|
|||||||
external_encoder_(nullptr),
|
external_encoder_(nullptr),
|
||||||
internal_source_(false),
|
internal_source_(false),
|
||||||
encoded_frame_callback_(encoded_frame_callback),
|
encoded_frame_callback_(encoded_frame_callback),
|
||||||
ptr_decoder_(nullptr),
|
|
||||||
dec_map_(),
|
dec_map_(),
|
||||||
dec_external_map_() {}
|
dec_external_map_() {}
|
||||||
|
|
||||||
VCMCodecDataBase::~VCMCodecDataBase() {
|
VCMCodecDataBase::~VCMCodecDataBase() {
|
||||||
DeleteEncoder();
|
DeleteEncoder();
|
||||||
ReleaseDecoder(ptr_decoder_);
|
ptr_decoder_.reset();
|
||||||
for (auto& kv : dec_map_)
|
for (auto& kv : dec_map_)
|
||||||
delete kv.second;
|
delete kv.second;
|
||||||
for (auto& kv : dec_external_map_)
|
for (auto& kv : dec_external_map_)
|
||||||
@ -391,11 +415,10 @@ bool VCMCodecDataBase::DeregisterExternalDecoder(uint8_t payload_type) {
|
|||||||
// We can't use payload_type to check if the decoder is currently in use,
|
// We can't use payload_type to check if the decoder is currently in use,
|
||||||
// because payload type may be out of date (e.g. before we decode the first
|
// because payload type may be out of date (e.g. before we decode the first
|
||||||
// frame after RegisterReceiveCodec)
|
// frame after RegisterReceiveCodec)
|
||||||
if (ptr_decoder_ != nullptr &&
|
if (ptr_decoder_ &&
|
||||||
ptr_decoder_->_decoder == (*it).second->external_decoder_instance) {
|
ptr_decoder_->IsSameDecoder((*it).second->external_decoder_instance)) {
|
||||||
// Release it if it was registered and in use.
|
// Release it if it was registered and in use.
|
||||||
ReleaseDecoder(ptr_decoder_);
|
ptr_decoder_.reset();
|
||||||
ptr_decoder_ = nullptr;
|
|
||||||
}
|
}
|
||||||
DeregisterReceiveCodec(payload_type);
|
DeregisterReceiveCodec(payload_type);
|
||||||
delete it->second;
|
delete it->second;
|
||||||
@ -455,12 +478,11 @@ VCMGenericDecoder* VCMCodecDataBase::GetDecoder(
|
|||||||
RTC_DCHECK(decoded_frame_callback->UserReceiveCallback());
|
RTC_DCHECK(decoded_frame_callback->UserReceiveCallback());
|
||||||
uint8_t payload_type = frame.PayloadType();
|
uint8_t payload_type = frame.PayloadType();
|
||||||
if (payload_type == receive_codec_.plType || payload_type == 0) {
|
if (payload_type == receive_codec_.plType || payload_type == 0) {
|
||||||
return ptr_decoder_;
|
return ptr_decoder_.get();
|
||||||
}
|
}
|
||||||
// Check for exisitng decoder, if exists - delete.
|
// Check for exisitng decoder, if exists - delete.
|
||||||
if (ptr_decoder_) {
|
if (ptr_decoder_) {
|
||||||
ReleaseDecoder(ptr_decoder_);
|
ptr_decoder_.reset();
|
||||||
ptr_decoder_ = nullptr;
|
|
||||||
memset(&receive_codec_, 0, sizeof(VideoCodec));
|
memset(&receive_codec_, 0, sizeof(VideoCodec));
|
||||||
}
|
}
|
||||||
ptr_decoder_ = CreateAndInitDecoder(frame, &receive_codec_);
|
ptr_decoder_ = CreateAndInitDecoder(frame, &receive_codec_);
|
||||||
@ -471,36 +493,26 @@ VCMGenericDecoder* VCMCodecDataBase::GetDecoder(
|
|||||||
callback->OnIncomingPayloadType(receive_codec_.plType);
|
callback->OnIncomingPayloadType(receive_codec_.plType);
|
||||||
if (ptr_decoder_->RegisterDecodeCompleteCallback(decoded_frame_callback) <
|
if (ptr_decoder_->RegisterDecodeCompleteCallback(decoded_frame_callback) <
|
||||||
0) {
|
0) {
|
||||||
ReleaseDecoder(ptr_decoder_);
|
ptr_decoder_.reset();
|
||||||
ptr_decoder_ = nullptr;
|
|
||||||
memset(&receive_codec_, 0, sizeof(VideoCodec));
|
memset(&receive_codec_, 0, sizeof(VideoCodec));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return ptr_decoder_;
|
return ptr_decoder_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VCMCodecDataBase::ReleaseDecoder(VCMGenericDecoder* decoder) const {
|
VCMGenericDecoder* VCMCodecDataBase::GetCurrentDecoder() {
|
||||||
if (decoder) {
|
return ptr_decoder_.get();
|
||||||
RTC_DCHECK(decoder->_decoder);
|
|
||||||
decoder->Release();
|
|
||||||
if (!decoder->External()) {
|
|
||||||
delete decoder->_decoder;
|
|
||||||
}
|
|
||||||
delete decoder;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VCMCodecDataBase::PrefersLateDecoding() const {
|
bool VCMCodecDataBase::PrefersLateDecoding() const {
|
||||||
if (!ptr_decoder_)
|
return ptr_decoder_ ? ptr_decoder_->PrefersLateDecoding() : true;
|
||||||
return true;
|
|
||||||
return ptr_decoder_->PrefersLateDecoding();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VCMCodecDataBase::MatchesCurrentResolution(int width, int height) const {
|
bool VCMCodecDataBase::MatchesCurrentResolution(int width, int height) const {
|
||||||
return send_codec_.width == width && send_codec_.height == height;
|
return send_codec_.width == width && send_codec_.height == height;
|
||||||
}
|
}
|
||||||
|
|
||||||
VCMGenericDecoder* VCMCodecDataBase::CreateAndInitDecoder(
|
std::unique_ptr<VCMGenericDecoder> VCMCodecDataBase::CreateAndInitDecoder(
|
||||||
const VCMEncodedFrame& frame,
|
const VCMEncodedFrame& frame,
|
||||||
VideoCodec* new_codec) const {
|
VideoCodec* new_codec) const {
|
||||||
uint8_t payload_type = frame.PayloadType();
|
uint8_t payload_type = frame.PayloadType();
|
||||||
@ -513,13 +525,13 @@ VCMGenericDecoder* VCMCodecDataBase::CreateAndInitDecoder(
|
|||||||
<< static_cast<int>(payload_type);
|
<< static_cast<int>(payload_type);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
VCMGenericDecoder* ptr_decoder = nullptr;
|
std::unique_ptr<VCMGenericDecoder> ptr_decoder;
|
||||||
const VCMExtDecoderMapItem* external_dec_item =
|
const VCMExtDecoderMapItem* external_dec_item =
|
||||||
FindExternalDecoderItem(payload_type);
|
FindExternalDecoderItem(payload_type);
|
||||||
if (external_dec_item) {
|
if (external_dec_item) {
|
||||||
// External codec.
|
// External codec.
|
||||||
ptr_decoder = new VCMGenericDecoder(
|
ptr_decoder.reset(new VCMGenericDecoder(
|
||||||
external_dec_item->external_decoder_instance, true);
|
external_dec_item->external_decoder_instance, true));
|
||||||
} else {
|
} else {
|
||||||
// Create decoder.
|
// Create decoder.
|
||||||
ptr_decoder = CreateDecoder(decoder_item->settings->codecType);
|
ptr_decoder = CreateDecoder(decoder_item->settings->codecType);
|
||||||
@ -538,7 +550,6 @@ VCMGenericDecoder* VCMCodecDataBase::CreateAndInitDecoder(
|
|||||||
}
|
}
|
||||||
if (ptr_decoder->InitDecode(decoder_item->settings.get(),
|
if (ptr_decoder->InitDecode(decoder_item->settings.get(),
|
||||||
decoder_item->number_of_cores) < 0) {
|
decoder_item->number_of_cores) < 0) {
|
||||||
ReleaseDecoder(ptr_decoder);
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
memcpy(new_codec, decoder_item->settings.get(), sizeof(VideoCodec));
|
memcpy(new_codec, decoder_item->settings.get(), sizeof(VideoCodec));
|
||||||
@ -552,26 +563,6 @@ void VCMCodecDataBase::DeleteEncoder() {
|
|||||||
ptr_encoder_.reset();
|
ptr_encoder_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
VCMGenericDecoder* VCMCodecDataBase::CreateDecoder(VideoCodecType type) const {
|
|
||||||
switch (type) {
|
|
||||||
case kVideoCodecVP8:
|
|
||||||
return new VCMGenericDecoder(VP8Decoder::Create());
|
|
||||||
case kVideoCodecVP9:
|
|
||||||
return new VCMGenericDecoder(VP9Decoder::Create());
|
|
||||||
case kVideoCodecI420:
|
|
||||||
return new VCMGenericDecoder(new I420Decoder());
|
|
||||||
case kVideoCodecH264:
|
|
||||||
if (H264Decoder::IsSupported()) {
|
|
||||||
return new VCMGenericDecoder(H264Decoder::Create());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
LOG(LS_WARNING) << "No internal decoder of this type exists.";
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
const VCMDecoderMapItem* VCMCodecDataBase::FindDecoderItem(
|
const VCMDecoderMapItem* VCMCodecDataBase::FindDecoderItem(
|
||||||
uint8_t payload_type) const {
|
uint8_t payload_type) const {
|
||||||
DecoderMap::const_iterator it = dec_map_.find(payload_type);
|
DecoderMap::const_iterator it = dec_map_.find(payload_type);
|
||||||
|
@ -107,9 +107,9 @@ class VCMCodecDataBase {
|
|||||||
const VCMEncodedFrame& frame,
|
const VCMEncodedFrame& frame,
|
||||||
VCMDecodedFrameCallback* decoded_frame_callback);
|
VCMDecodedFrameCallback* decoded_frame_callback);
|
||||||
|
|
||||||
// Deletes the memory of the decoder instance |decoder|. Used to delete
|
// Returns the current decoder (i.e. the same value as was last returned from
|
||||||
// deep copies returned by CreateDecoderCopy().
|
// GetDecoder();
|
||||||
void ReleaseDecoder(VCMGenericDecoder* decoder) const;
|
VCMGenericDecoder* GetCurrentDecoder();
|
||||||
|
|
||||||
// Returns true if the currently active decoder prefer to decode frames late.
|
// Returns true if the currently active decoder prefer to decode frames late.
|
||||||
// That means that frames must be decoded near the render times stamp.
|
// That means that frames must be decoded near the render times stamp.
|
||||||
@ -121,8 +121,9 @@ class VCMCodecDataBase {
|
|||||||
typedef std::map<uint8_t, VCMDecoderMapItem*> DecoderMap;
|
typedef std::map<uint8_t, VCMDecoderMapItem*> DecoderMap;
|
||||||
typedef std::map<uint8_t, VCMExtDecoderMapItem*> ExternalDecoderMap;
|
typedef std::map<uint8_t, VCMExtDecoderMapItem*> ExternalDecoderMap;
|
||||||
|
|
||||||
VCMGenericDecoder* CreateAndInitDecoder(const VCMEncodedFrame& frame,
|
std::unique_ptr<VCMGenericDecoder> CreateAndInitDecoder(
|
||||||
VideoCodec* new_codec) const;
|
const VCMEncodedFrame& frame,
|
||||||
|
VideoCodec* new_codec) const;
|
||||||
|
|
||||||
// Determines whether a new codec has to be created or not.
|
// Determines whether a new codec has to be created or not.
|
||||||
// Checks every setting apart from maxFramerate and startBitrate.
|
// Checks every setting apart from maxFramerate and startBitrate.
|
||||||
@ -130,9 +131,6 @@ class VCMCodecDataBase {
|
|||||||
|
|
||||||
void DeleteEncoder();
|
void DeleteEncoder();
|
||||||
|
|
||||||
// Create an internal Decoder given a codec type
|
|
||||||
VCMGenericDecoder* CreateDecoder(VideoCodecType type) const;
|
|
||||||
|
|
||||||
const VCMDecoderMapItem* FindDecoderItem(uint8_t payload_type) const;
|
const VCMDecoderMapItem* FindDecoderItem(uint8_t payload_type) const;
|
||||||
|
|
||||||
const VCMExtDecoderMapItem* FindExternalDecoderItem(
|
const VCMExtDecoderMapItem* FindExternalDecoderItem(
|
||||||
@ -149,7 +147,7 @@ class VCMCodecDataBase {
|
|||||||
bool internal_source_;
|
bool internal_source_;
|
||||||
VCMEncodedFrameCallback* const encoded_frame_callback_;
|
VCMEncodedFrameCallback* const encoded_frame_callback_;
|
||||||
std::unique_ptr<VCMGenericEncoder> ptr_encoder_;
|
std::unique_ptr<VCMGenericEncoder> ptr_encoder_;
|
||||||
VCMGenericDecoder* ptr_decoder_;
|
std::unique_ptr<VCMGenericDecoder> ptr_decoder_;
|
||||||
DecoderMap dec_map_;
|
DecoderMap dec_map_;
|
||||||
ExternalDecoderMap dec_external_map_;
|
ExternalDecoderMap dec_external_map_;
|
||||||
}; // VCMCodecDataBase
|
}; // VCMCodecDataBase
|
||||||
|
@ -8,11 +8,12 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "webrtc/modules/video_coding/generic_decoder.h"
|
||||||
|
|
||||||
#include "webrtc/base/checks.h"
|
#include "webrtc/base/checks.h"
|
||||||
#include "webrtc/base/logging.h"
|
#include "webrtc/base/logging.h"
|
||||||
#include "webrtc/base/trace_event.h"
|
#include "webrtc/base/trace_event.h"
|
||||||
#include "webrtc/modules/video_coding/include/video_coding.h"
|
#include "webrtc/modules/video_coding/include/video_coding.h"
|
||||||
#include "webrtc/modules/video_coding/generic_decoder.h"
|
|
||||||
#include "webrtc/modules/video_coding/internal_defines.h"
|
#include "webrtc/modules/video_coding/internal_defines.h"
|
||||||
#include "webrtc/system_wrappers/include/clock.h"
|
#include "webrtc/system_wrappers/include/clock.h"
|
||||||
|
|
||||||
@ -23,9 +24,12 @@ VCMDecodedFrameCallback::VCMDecodedFrameCallback(VCMTiming* timing,
|
|||||||
: _clock(clock),
|
: _clock(clock),
|
||||||
_timing(timing),
|
_timing(timing),
|
||||||
_timestampMap(kDecoderFrameMemoryLength),
|
_timestampMap(kDecoderFrameMemoryLength),
|
||||||
_lastReceivedPictureID(0) {}
|
_lastReceivedPictureID(0) {
|
||||||
|
decoder_thread_.DetachFromThread();
|
||||||
|
}
|
||||||
|
|
||||||
VCMDecodedFrameCallback::~VCMDecodedFrameCallback() {
|
VCMDecodedFrameCallback::~VCMDecodedFrameCallback() {
|
||||||
|
RTC_DCHECK(construction_thread_.CalledOnValidThread());
|
||||||
}
|
}
|
||||||
|
|
||||||
void VCMDecodedFrameCallback::SetUserReceiveCallback(
|
void VCMDecodedFrameCallback::SetUserReceiveCallback(
|
||||||
@ -37,6 +41,7 @@ void VCMDecodedFrameCallback::SetUserReceiveCallback(
|
|||||||
}
|
}
|
||||||
|
|
||||||
VCMReceiveCallback* VCMDecodedFrameCallback::UserReceiveCallback() {
|
VCMReceiveCallback* VCMDecodedFrameCallback::UserReceiveCallback() {
|
||||||
|
RTC_DCHECK_RUN_ON(&decoder_thread_);
|
||||||
// Called on the decode thread via VCMCodecDataBase::GetDecoder.
|
// Called on the decode thread via VCMCodecDataBase::GetDecoder.
|
||||||
// The callback must always have been set before this happens.
|
// The callback must always have been set before this happens.
|
||||||
RTC_DCHECK(_receiveCallback);
|
RTC_DCHECK(_receiveCallback);
|
||||||
@ -59,16 +64,14 @@ int32_t VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage,
|
|||||||
void VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage,
|
void VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage,
|
||||||
rtc::Optional<int32_t> decode_time_ms,
|
rtc::Optional<int32_t> decode_time_ms,
|
||||||
rtc::Optional<uint8_t> qp) {
|
rtc::Optional<uint8_t> qp) {
|
||||||
|
RTC_DCHECK_RUN_ON(&decoder_thread_);
|
||||||
RTC_DCHECK(_receiveCallback) << "Callback must not be null at this point";
|
RTC_DCHECK(_receiveCallback) << "Callback must not be null at this point";
|
||||||
|
|
||||||
TRACE_EVENT_INSTANT1("webrtc", "VCMDecodedFrameCallback::Decoded",
|
TRACE_EVENT_INSTANT1("webrtc", "VCMDecodedFrameCallback::Decoded",
|
||||||
"timestamp", decodedImage.timestamp());
|
"timestamp", decodedImage.timestamp());
|
||||||
// TODO(holmer): We should improve this so that we can handle multiple
|
// TODO(holmer): We should improve this so that we can handle multiple
|
||||||
// callbacks from one call to Decode().
|
// callbacks from one call to Decode().
|
||||||
VCMFrameInformation* frameInfo;
|
VCMFrameInformation* frameInfo = _timestampMap.Pop(decodedImage.timestamp());
|
||||||
{
|
|
||||||
rtc::CritScope cs(&lock_);
|
|
||||||
frameInfo = _timestampMap.Pop(decodedImage.timestamp());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (frameInfo == NULL) {
|
if (frameInfo == NULL) {
|
||||||
LOG(LS_WARNING) << "Too many frames backed up in the decoder, dropping "
|
LOG(LS_WARNING) << "Too many frames backed up in the decoder, dropping "
|
||||||
@ -92,101 +95,115 @@ void VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage,
|
|||||||
|
|
||||||
int32_t VCMDecodedFrameCallback::ReceivedDecodedReferenceFrame(
|
int32_t VCMDecodedFrameCallback::ReceivedDecodedReferenceFrame(
|
||||||
const uint64_t pictureId) {
|
const uint64_t pictureId) {
|
||||||
|
RTC_DCHECK_RUN_ON(&decoder_thread_);
|
||||||
return _receiveCallback->ReceivedDecodedReferenceFrame(pictureId);
|
return _receiveCallback->ReceivedDecodedReferenceFrame(pictureId);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t VCMDecodedFrameCallback::ReceivedDecodedFrame(
|
int32_t VCMDecodedFrameCallback::ReceivedDecodedFrame(
|
||||||
const uint64_t pictureId) {
|
const uint64_t pictureId) {
|
||||||
|
RTC_DCHECK_RUN_ON(&decoder_thread_);
|
||||||
_lastReceivedPictureID = pictureId;
|
_lastReceivedPictureID = pictureId;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t VCMDecodedFrameCallback::LastReceivedPictureID() const {
|
uint64_t VCMDecodedFrameCallback::LastReceivedPictureID() const {
|
||||||
|
RTC_DCHECK_RUN_ON(&decoder_thread_);
|
||||||
return _lastReceivedPictureID;
|
return _lastReceivedPictureID;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VCMDecodedFrameCallback::OnDecoderImplementationName(
|
void VCMDecodedFrameCallback::OnDecoderImplementationName(
|
||||||
const char* implementation_name) {
|
const char* implementation_name) {
|
||||||
|
RTC_DCHECK_RUN_ON(&decoder_thread_);
|
||||||
_receiveCallback->OnDecoderImplementationName(implementation_name);
|
_receiveCallback->OnDecoderImplementationName(implementation_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VCMDecodedFrameCallback::Map(uint32_t timestamp,
|
void VCMDecodedFrameCallback::Map(uint32_t timestamp,
|
||||||
VCMFrameInformation* frameInfo) {
|
VCMFrameInformation* frameInfo) {
|
||||||
rtc::CritScope cs(&lock_);
|
RTC_DCHECK_RUN_ON(&decoder_thread_);
|
||||||
_timestampMap.Add(timestamp, frameInfo);
|
_timestampMap.Add(timestamp, frameInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t VCMDecodedFrameCallback::Pop(uint32_t timestamp) {
|
int32_t VCMDecodedFrameCallback::Pop(uint32_t timestamp) {
|
||||||
rtc::CritScope cs(&lock_);
|
RTC_DCHECK_RUN_ON(&decoder_thread_);
|
||||||
if (_timestampMap.Pop(timestamp) == NULL) {
|
return _timestampMap.Pop(timestamp) == nullptr ? VCM_GENERAL_ERROR : VCM_OK;
|
||||||
return VCM_GENERAL_ERROR;
|
|
||||||
}
|
|
||||||
return VCM_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VCMGenericDecoder::VCMGenericDecoder(VideoDecoder* decoder, bool isExternal)
|
VCMGenericDecoder::VCMGenericDecoder(VideoDecoder* decoder, bool isExternal)
|
||||||
: _callback(NULL),
|
: _callback(NULL),
|
||||||
_frameInfos(),
|
_frameInfos(),
|
||||||
_nextFrameInfoIdx(0),
|
_nextFrameInfoIdx(0),
|
||||||
_decoder(decoder),
|
decoder_(decoder),
|
||||||
_codecType(kVideoCodecUnknown),
|
_codecType(kVideoCodecUnknown),
|
||||||
_isExternal(isExternal),
|
_isExternal(isExternal) {}
|
||||||
_keyFrameDecoded(false) {}
|
|
||||||
|
|
||||||
VCMGenericDecoder::~VCMGenericDecoder() {}
|
VCMGenericDecoder::~VCMGenericDecoder() {
|
||||||
|
decoder_->Release();
|
||||||
|
if (_isExternal)
|
||||||
|
decoder_.release();
|
||||||
|
|
||||||
|
RTC_DCHECK(_isExternal || !decoder_);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t VCMGenericDecoder::InitDecode(const VideoCodec* settings,
|
int32_t VCMGenericDecoder::InitDecode(const VideoCodec* settings,
|
||||||
int32_t numberOfCores) {
|
int32_t numberOfCores) {
|
||||||
|
RTC_DCHECK_RUN_ON(&decoder_thread_);
|
||||||
TRACE_EVENT0("webrtc", "VCMGenericDecoder::InitDecode");
|
TRACE_EVENT0("webrtc", "VCMGenericDecoder::InitDecode");
|
||||||
_codecType = settings->codecType;
|
_codecType = settings->codecType;
|
||||||
|
|
||||||
return _decoder->InitDecode(settings, numberOfCores);
|
return decoder_->InitDecode(settings, numberOfCores);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t VCMGenericDecoder::Decode(const VCMEncodedFrame& frame, int64_t nowMs) {
|
int32_t VCMGenericDecoder::Decode(const VCMEncodedFrame& frame, int64_t nowMs) {
|
||||||
TRACE_EVENT1("webrtc", "VCMGenericDecoder::Decode", "timestamp",
|
RTC_DCHECK_RUN_ON(&decoder_thread_);
|
||||||
frame.EncodedImage()._timeStamp);
|
TRACE_EVENT2("webrtc", "VCMGenericDecoder::Decode", "timestamp",
|
||||||
_frameInfos[_nextFrameInfoIdx].decodeStartTimeMs = nowMs;
|
frame.EncodedImage()._timeStamp, "decoder",
|
||||||
_frameInfos[_nextFrameInfoIdx].renderTimeMs = frame.RenderTimeMs();
|
decoder_->ImplementationName());
|
||||||
_frameInfos[_nextFrameInfoIdx].rotation = frame.rotation();
|
_frameInfos[_nextFrameInfoIdx].decodeStartTimeMs = nowMs;
|
||||||
_callback->Map(frame.TimeStamp(), &_frameInfos[_nextFrameInfoIdx]);
|
_frameInfos[_nextFrameInfoIdx].renderTimeMs = frame.RenderTimeMs();
|
||||||
|
_frameInfos[_nextFrameInfoIdx].rotation = frame.rotation();
|
||||||
|
_callback->Map(frame.TimeStamp(), &_frameInfos[_nextFrameInfoIdx]);
|
||||||
|
|
||||||
_nextFrameInfoIdx = (_nextFrameInfoIdx + 1) % kDecoderFrameMemoryLength;
|
_nextFrameInfoIdx = (_nextFrameInfoIdx + 1) % kDecoderFrameMemoryLength;
|
||||||
const RTPFragmentationHeader dummy_header;
|
const RTPFragmentationHeader dummy_header;
|
||||||
int32_t ret = _decoder->Decode(frame.EncodedImage(), frame.MissingFrame(),
|
int32_t ret = decoder_->Decode(frame.EncodedImage(), frame.MissingFrame(),
|
||||||
&dummy_header,
|
&dummy_header, frame.CodecSpecific(),
|
||||||
frame.CodecSpecific(), frame.RenderTimeMs());
|
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) {
|
if (ret < WEBRTC_VIDEO_CODEC_OK) {
|
||||||
LOG(LS_WARNING) << "Failed to decode frame with timestamp "
|
LOG(LS_WARNING) << "Failed to decode frame with timestamp "
|
||||||
<< frame.TimeStamp() << ", error code: " << ret;
|
<< 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());
|
|
||||||
}
|
}
|
||||||
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());
|
||||||
|
}
|
||||||
|
|
||||||
int32_t VCMGenericDecoder::Release() {
|
return ret;
|
||||||
return _decoder->Release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t VCMGenericDecoder::RegisterDecodeCompleteCallback(
|
int32_t VCMGenericDecoder::RegisterDecodeCompleteCallback(
|
||||||
VCMDecodedFrameCallback* callback) {
|
VCMDecodedFrameCallback* callback) {
|
||||||
|
RTC_DCHECK_RUN_ON(&decoder_thread_);
|
||||||
_callback = callback;
|
_callback = callback;
|
||||||
return _decoder->RegisterDecodeCompleteCallback(callback);
|
return decoder_->RegisterDecodeCompleteCallback(callback);
|
||||||
}
|
|
||||||
|
|
||||||
bool VCMGenericDecoder::External() const {
|
|
||||||
return _isExternal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VCMGenericDecoder::PrefersLateDecoding() const {
|
bool VCMGenericDecoder::PrefersLateDecoding() const {
|
||||||
return _decoder->PrefersLateDecoding();
|
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
|
} // namespace webrtc
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
#ifndef WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_
|
#ifndef WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_
|
||||||
#define WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_
|
#define WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_
|
||||||
|
|
||||||
#include "webrtc/base/criticalsection.h"
|
#include <memory>
|
||||||
|
|
||||||
#include "webrtc/base/thread_checker.h"
|
#include "webrtc/base/thread_checker.h"
|
||||||
#include "webrtc/modules/include/module_common_types.h"
|
#include "webrtc/modules/include/module_common_types.h"
|
||||||
#include "webrtc/modules/video_coding/encoded_frame.h"
|
#include "webrtc/modules/video_coding/encoded_frame.h"
|
||||||
@ -36,6 +37,7 @@ class VCMDecodedFrameCallback : public DecodedImageCallback {
|
|||||||
public:
|
public:
|
||||||
VCMDecodedFrameCallback(VCMTiming* timing, Clock* clock);
|
VCMDecodedFrameCallback(VCMTiming* timing, Clock* clock);
|
||||||
~VCMDecodedFrameCallback() override;
|
~VCMDecodedFrameCallback() override;
|
||||||
|
|
||||||
void SetUserReceiveCallback(VCMReceiveCallback* receiveCallback);
|
void SetUserReceiveCallback(VCMReceiveCallback* receiveCallback);
|
||||||
VCMReceiveCallback* UserReceiveCallback();
|
VCMReceiveCallback* UserReceiveCallback();
|
||||||
|
|
||||||
@ -55,7 +57,7 @@ class VCMDecodedFrameCallback : public DecodedImageCallback {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
rtc::ThreadChecker construction_thread_;
|
rtc::ThreadChecker construction_thread_;
|
||||||
// Protect |_timestampMap|.
|
rtc::ThreadChecker decoder_thread_;
|
||||||
Clock* const _clock;
|
Clock* const _clock;
|
||||||
// This callback must be set before the decoder thread starts running
|
// This callback must be set before the decoder thread starts running
|
||||||
// and must only be unset when external threads (e.g decoder thread)
|
// and must only be unset when external threads (e.g decoder thread)
|
||||||
@ -63,15 +65,12 @@ class VCMDecodedFrameCallback : public DecodedImageCallback {
|
|||||||
// while there are more than one threads involved, it must be set
|
// while there are more than one threads involved, it must be set
|
||||||
// from the same thread, and therfore a lock is not required to access it.
|
// from the same thread, and therfore a lock is not required to access it.
|
||||||
VCMReceiveCallback* _receiveCallback = nullptr;
|
VCMReceiveCallback* _receiveCallback = nullptr;
|
||||||
VCMTiming* _timing;
|
VCMTiming* _timing ACCESS_ON(decoder_thread_);
|
||||||
rtc::CriticalSection lock_;
|
VCMTimestampMap _timestampMap ACCESS_ON(decoder_thread_);
|
||||||
VCMTimestampMap _timestampMap GUARDED_BY(lock_);
|
uint64_t _lastReceivedPictureID ACCESS_ON(decoder_thread_);
|
||||||
uint64_t _lastReceivedPictureID;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class VCMGenericDecoder {
|
class VCMGenericDecoder {
|
||||||
friend class VCMCodecDataBase;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit VCMGenericDecoder(VideoDecoder* decoder, bool isExternal = false);
|
explicit VCMGenericDecoder(VideoDecoder* decoder, bool isExternal = false);
|
||||||
~VCMGenericDecoder();
|
~VCMGenericDecoder();
|
||||||
@ -88,27 +87,31 @@ class VCMGenericDecoder {
|
|||||||
*/
|
*/
|
||||||
int32_t Decode(const VCMEncodedFrame& inputFrame, int64_t nowMs);
|
int32_t Decode(const VCMEncodedFrame& inputFrame, int64_t nowMs);
|
||||||
|
|
||||||
/**
|
|
||||||
* Free the decoder memory
|
|
||||||
*/
|
|
||||||
int32_t Release();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set decode callback. Deregistering while decoding is illegal.
|
* Set decode callback. Deregistering while decoding is illegal.
|
||||||
*/
|
*/
|
||||||
int32_t RegisterDecodeCompleteCallback(VCMDecodedFrameCallback* callback);
|
int32_t RegisterDecodeCompleteCallback(VCMDecodedFrameCallback* callback);
|
||||||
|
|
||||||
bool External() const;
|
|
||||||
bool PrefersLateDecoding() const;
|
bool PrefersLateDecoding() const;
|
||||||
|
|
||||||
|
#if defined(WEBRTC_ANDROID)
|
||||||
|
// See https://bugs.chromium.org/p/webrtc/issues/detail?id=7361
|
||||||
|
void PollDecodedFrames();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool IsSameDecoder(VideoDecoder* decoder) const {
|
||||||
|
return decoder_.get() == decoder;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VCMDecodedFrameCallback* _callback;
|
rtc::ThreadChecker decoder_thread_;
|
||||||
VCMFrameInformation _frameInfos[kDecoderFrameMemoryLength];
|
VCMDecodedFrameCallback* _callback ACCESS_ON(decoder_thread_);
|
||||||
uint32_t _nextFrameInfoIdx;
|
VCMFrameInformation _frameInfos[kDecoderFrameMemoryLength] ACCESS_ON(
|
||||||
VideoDecoder* const _decoder;
|
decoder_thread_);
|
||||||
VideoCodecType _codecType;
|
uint32_t _nextFrameInfoIdx ACCESS_ON(decoder_thread_);
|
||||||
bool _isExternal;
|
std::unique_ptr<VideoDecoder> decoder_;
|
||||||
bool _keyFrameDecoded;
|
VideoCodecType _codecType ACCESS_ON(decoder_thread_);
|
||||||
|
const bool _isExternal;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
|
class ProcessThread;
|
||||||
class VideoBitrateAllocator;
|
class VideoBitrateAllocator;
|
||||||
class VideoBitrateAllocationObserver;
|
class VideoBitrateAllocationObserver;
|
||||||
|
|
||||||
@ -150,7 +151,7 @@ class VideoReceiver : public Module {
|
|||||||
VCMTiming* timing,
|
VCMTiming* timing,
|
||||||
NackSender* nack_sender = nullptr,
|
NackSender* nack_sender = nullptr,
|
||||||
KeyFrameRequestSender* keyframe_request_sender = nullptr);
|
KeyFrameRequestSender* keyframe_request_sender = nullptr);
|
||||||
~VideoReceiver();
|
~VideoReceiver() override;
|
||||||
|
|
||||||
int32_t RegisterReceiveCodec(const VideoCodec* receiveCodec,
|
int32_t RegisterReceiveCodec(const VideoCodec* receiveCodec,
|
||||||
int32_t numberOfCores,
|
int32_t numberOfCores,
|
||||||
@ -168,8 +169,10 @@ class VideoReceiver : public Module {
|
|||||||
|
|
||||||
int32_t Decode(const webrtc::VCMEncodedFrame* frame);
|
int32_t Decode(const webrtc::VCMEncodedFrame* frame);
|
||||||
|
|
||||||
// Called on the decoder thread when thread is exiting.
|
#if defined(WEBRTC_ANDROID)
|
||||||
void DecodingStopped();
|
// See https://bugs.chromium.org/p/webrtc/issues/detail?id=7361
|
||||||
|
void PollDecodedFrames();
|
||||||
|
#endif
|
||||||
|
|
||||||
int32_t IncomingPacket(const uint8_t* incomingPayload,
|
int32_t IncomingPacket(const uint8_t* incomingPayload,
|
||||||
size_t payloadLength,
|
size_t payloadLength,
|
||||||
@ -195,39 +198,66 @@ class VideoReceiver : public Module {
|
|||||||
|
|
||||||
int64_t TimeUntilNextProcess() override;
|
int64_t TimeUntilNextProcess() override;
|
||||||
void Process() override;
|
void Process() override;
|
||||||
|
void ProcessThreadAttached(ProcessThread* process_thread) override;
|
||||||
|
|
||||||
void TriggerDecoderShutdown();
|
void TriggerDecoderShutdown();
|
||||||
|
void DecoderThreadStarting();
|
||||||
|
void DecoderThreadStopped();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int32_t Decode(const webrtc::VCMEncodedFrame& frame)
|
int32_t Decode(const webrtc::VCMEncodedFrame& frame);
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(receive_crit_);
|
|
||||||
int32_t RequestKeyFrame();
|
int32_t RequestKeyFrame();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Used for DCHECKing thread correctness.
|
||||||
|
// In build where DCHECKs are enabled, will return false before
|
||||||
|
// DecoderThreadStarting is called, then true until DecoderThreadStopped
|
||||||
|
// is called.
|
||||||
|
// In builds where DCHECKs aren't enabled, it will return true.
|
||||||
|
bool IsDecoderThreadRunning();
|
||||||
|
|
||||||
rtc::ThreadChecker construction_thread_;
|
rtc::ThreadChecker construction_thread_;
|
||||||
|
rtc::ThreadChecker decoder_thread_;
|
||||||
|
rtc::ThreadChecker module_thread_;
|
||||||
Clock* const clock_;
|
Clock* const clock_;
|
||||||
rtc::CriticalSection process_crit_;
|
rtc::CriticalSection process_crit_;
|
||||||
rtc::CriticalSection receive_crit_;
|
|
||||||
VCMTiming* _timing;
|
VCMTiming* _timing;
|
||||||
VCMReceiver _receiver;
|
VCMReceiver _receiver;
|
||||||
VCMDecodedFrameCallback _decodedFrameCallback;
|
VCMDecodedFrameCallback _decodedFrameCallback;
|
||||||
VCMFrameTypeCallback* _frameTypeCallback GUARDED_BY(process_crit_);
|
|
||||||
VCMReceiveStatisticsCallback* _receiveStatsCallback GUARDED_BY(process_crit_);
|
|
||||||
VCMPacketRequestCallback* _packetRequestCallback GUARDED_BY(process_crit_);
|
|
||||||
|
|
||||||
VCMFrameBuffer _frameFromFile;
|
// These callbacks are set on the construction thread before being attached
|
||||||
|
// to the module thread or decoding started, so a lock is not required.
|
||||||
|
VCMFrameTypeCallback* _frameTypeCallback;
|
||||||
|
VCMReceiveStatisticsCallback* _receiveStatsCallback;
|
||||||
|
VCMPacketRequestCallback* _packetRequestCallback;
|
||||||
|
|
||||||
|
// Used on both the module and decoder thread.
|
||||||
bool _scheduleKeyRequest GUARDED_BY(process_crit_);
|
bool _scheduleKeyRequest GUARDED_BY(process_crit_);
|
||||||
bool drop_frames_until_keyframe_ GUARDED_BY(process_crit_);
|
bool drop_frames_until_keyframe_ GUARDED_BY(process_crit_);
|
||||||
size_t max_nack_list_size_ GUARDED_BY(process_crit_);
|
|
||||||
|
|
||||||
VCMCodecDataBase _codecDataBase GUARDED_BY(receive_crit_);
|
// Modified on the construction thread while not attached to the process
|
||||||
EncodedImageCallback* pre_decode_image_callback_;
|
// thread. Once attached to the process thread, its value is only read
|
||||||
|
// so a lock is not required.
|
||||||
|
size_t max_nack_list_size_;
|
||||||
|
|
||||||
VCMProcessTimer _receiveStatsTimer;
|
// Callbacks are set before the decoder thread starts.
|
||||||
VCMProcessTimer _retransmissionTimer;
|
// Once the decoder thread has been started, usage of |_codecDataBase| moves
|
||||||
VCMProcessTimer _keyRequestTimer;
|
// over to the decoder thread.
|
||||||
QpParser qp_parser_;
|
VCMCodecDataBase _codecDataBase;
|
||||||
ThreadUnsafeOneTimeEvent first_frame_received_;
|
EncodedImageCallback* const pre_decode_image_callback_;
|
||||||
|
|
||||||
|
VCMProcessTimer _receiveStatsTimer ACCESS_ON(module_thread_);
|
||||||
|
VCMProcessTimer _retransmissionTimer ACCESS_ON(module_thread_);
|
||||||
|
VCMProcessTimer _keyRequestTimer ACCESS_ON(module_thread_);
|
||||||
|
QpParser qp_parser_ ACCESS_ON(decoder_thread_);
|
||||||
|
ThreadUnsafeOneTimeEvent first_frame_received_ ACCESS_ON(decoder_thread_);
|
||||||
|
// Modified on the construction thread. Can be read without a lock and assumed
|
||||||
|
// to be non-null on the module and decoder threads.
|
||||||
|
ProcessThread* process_thread_ = nullptr;
|
||||||
|
bool is_attached_to_process_thread_ ACCESS_ON(construction_thread_) = false;
|
||||||
|
#if RTC_DCHECK_IS_ON
|
||||||
|
bool decoder_thread_is_running_ = false;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace vcm
|
} // namespace vcm
|
||||||
|
@ -9,12 +9,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "webrtc/base/checks.h"
|
#include "webrtc/base/checks.h"
|
||||||
|
#include "webrtc/base/location.h"
|
||||||
#include "webrtc/base/logging.h"
|
#include "webrtc/base/logging.h"
|
||||||
#include "webrtc/base/trace_event.h"
|
#include "webrtc/base/trace_event.h"
|
||||||
#include "webrtc/common_types.h"
|
#include "webrtc/common_types.h"
|
||||||
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
|
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
|
||||||
#include "webrtc/modules/video_coding/include/video_codec_interface.h"
|
#include "webrtc/modules/utility/include/process_thread.h"
|
||||||
#include "webrtc/modules/video_coding/encoded_frame.h"
|
#include "webrtc/modules/video_coding/encoded_frame.h"
|
||||||
|
#include "webrtc/modules/video_coding/include/video_codec_interface.h"
|
||||||
#include "webrtc/modules/video_coding/jitter_buffer.h"
|
#include "webrtc/modules/video_coding/jitter_buffer.h"
|
||||||
#include "webrtc/modules/video_coding/packet.h"
|
#include "webrtc/modules/video_coding/packet.h"
|
||||||
#include "webrtc/modules/video_coding/video_coding_impl.h"
|
#include "webrtc/modules/video_coding/video_coding_impl.h"
|
||||||
@ -40,7 +42,6 @@ VideoReceiver::VideoReceiver(Clock* clock,
|
|||||||
_frameTypeCallback(nullptr),
|
_frameTypeCallback(nullptr),
|
||||||
_receiveStatsCallback(nullptr),
|
_receiveStatsCallback(nullptr),
|
||||||
_packetRequestCallback(nullptr),
|
_packetRequestCallback(nullptr),
|
||||||
_frameFromFile(),
|
|
||||||
_scheduleKeyRequest(false),
|
_scheduleKeyRequest(false),
|
||||||
drop_frames_until_keyframe_(false),
|
drop_frames_until_keyframe_(false),
|
||||||
max_nack_list_size_(0),
|
max_nack_list_size_(0),
|
||||||
@ -48,18 +49,23 @@ VideoReceiver::VideoReceiver(Clock* clock,
|
|||||||
pre_decode_image_callback_(pre_decode_image_callback),
|
pre_decode_image_callback_(pre_decode_image_callback),
|
||||||
_receiveStatsTimer(1000, clock_),
|
_receiveStatsTimer(1000, clock_),
|
||||||
_retransmissionTimer(10, clock_),
|
_retransmissionTimer(10, clock_),
|
||||||
_keyRequestTimer(500, clock_) {}
|
_keyRequestTimer(500, clock_) {
|
||||||
|
decoder_thread_.DetachFromThread();
|
||||||
|
module_thread_.DetachFromThread();
|
||||||
|
}
|
||||||
|
|
||||||
VideoReceiver::~VideoReceiver() {}
|
VideoReceiver::~VideoReceiver() {
|
||||||
|
RTC_DCHECK_RUN_ON(&construction_thread_);
|
||||||
|
}
|
||||||
|
|
||||||
void VideoReceiver::Process() {
|
void VideoReceiver::Process() {
|
||||||
|
RTC_DCHECK_RUN_ON(&module_thread_);
|
||||||
// Receive-side statistics
|
// Receive-side statistics
|
||||||
|
|
||||||
// TODO(philipel): Remove this if block when we know what to do with
|
// TODO(philipel): Remove this if block when we know what to do with
|
||||||
// ReceiveStatisticsProxy::QualitySample.
|
// ReceiveStatisticsProxy::QualitySample.
|
||||||
if (_receiveStatsTimer.TimeUntilProcess() == 0) {
|
if (_receiveStatsTimer.TimeUntilProcess() == 0) {
|
||||||
_receiveStatsTimer.Processed();
|
_receiveStatsTimer.Processed();
|
||||||
rtc::CritScope cs(&process_crit_);
|
|
||||||
if (_receiveStatsCallback != nullptr) {
|
if (_receiveStatsCallback != nullptr) {
|
||||||
_receiveStatsCallback->OnReceiveRatesUpdated(0, 0);
|
_receiveStatsCallback->OnReceiveRatesUpdated(0, 0);
|
||||||
}
|
}
|
||||||
@ -68,10 +74,10 @@ void VideoReceiver::Process() {
|
|||||||
// Key frame requests
|
// Key frame requests
|
||||||
if (_keyRequestTimer.TimeUntilProcess() == 0) {
|
if (_keyRequestTimer.TimeUntilProcess() == 0) {
|
||||||
_keyRequestTimer.Processed();
|
_keyRequestTimer.Processed();
|
||||||
bool request_key_frame = false;
|
bool request_key_frame = _frameTypeCallback != nullptr;
|
||||||
{
|
if (request_key_frame) {
|
||||||
rtc::CritScope cs(&process_crit_);
|
rtc::CritScope cs(&process_crit_);
|
||||||
request_key_frame = _scheduleKeyRequest && _frameTypeCallback != nullptr;
|
request_key_frame = _scheduleKeyRequest;
|
||||||
}
|
}
|
||||||
if (request_key_frame)
|
if (request_key_frame)
|
||||||
RequestKeyFrame();
|
RequestKeyFrame();
|
||||||
@ -82,13 +88,8 @@ void VideoReceiver::Process() {
|
|||||||
// disabled when NACK is off.
|
// disabled when NACK is off.
|
||||||
if (_retransmissionTimer.TimeUntilProcess() == 0) {
|
if (_retransmissionTimer.TimeUntilProcess() == 0) {
|
||||||
_retransmissionTimer.Processed();
|
_retransmissionTimer.Processed();
|
||||||
bool callback_registered = false;
|
bool callback_registered = _packetRequestCallback != nullptr;
|
||||||
uint16_t length;
|
uint16_t length = max_nack_list_size_;
|
||||||
{
|
|
||||||
rtc::CritScope cs(&process_crit_);
|
|
||||||
length = max_nack_list_size_;
|
|
||||||
callback_registered = _packetRequestCallback != nullptr;
|
|
||||||
}
|
|
||||||
if (callback_registered && length > 0) {
|
if (callback_registered && length > 0) {
|
||||||
// Collect sequence numbers from the default receiver.
|
// Collect sequence numbers from the default receiver.
|
||||||
bool request_key_frame = false;
|
bool request_key_frame = false;
|
||||||
@ -98,7 +99,6 @@ void VideoReceiver::Process() {
|
|||||||
ret = RequestKeyFrame();
|
ret = RequestKeyFrame();
|
||||||
}
|
}
|
||||||
if (ret == VCM_OK && !nackList.empty()) {
|
if (ret == VCM_OK && !nackList.empty()) {
|
||||||
rtc::CritScope cs(&process_crit_);
|
|
||||||
if (_packetRequestCallback != nullptr) {
|
if (_packetRequestCallback != nullptr) {
|
||||||
_packetRequestCallback->ResendPackets(&nackList[0], nackList.size());
|
_packetRequestCallback->ResendPackets(&nackList[0], nackList.size());
|
||||||
}
|
}
|
||||||
@ -107,7 +107,18 @@ void VideoReceiver::Process() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VideoReceiver::ProcessThreadAttached(ProcessThread* process_thread) {
|
||||||
|
RTC_DCHECK_RUN_ON(&construction_thread_);
|
||||||
|
if (process_thread) {
|
||||||
|
is_attached_to_process_thread_ = true;
|
||||||
|
process_thread_ = process_thread;
|
||||||
|
} else {
|
||||||
|
is_attached_to_process_thread_ = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int64_t VideoReceiver::TimeUntilNextProcess() {
|
int64_t VideoReceiver::TimeUntilNextProcess() {
|
||||||
|
RTC_DCHECK_RUN_ON(&module_thread_);
|
||||||
int64_t timeUntilNextProcess = _receiveStatsTimer.TimeUntilProcess();
|
int64_t timeUntilNextProcess = _receiveStatsTimer.TimeUntilProcess();
|
||||||
if (_receiver.NackMode() != kNoNack) {
|
if (_receiver.NackMode() != kNoNack) {
|
||||||
// We need a Process call more often if we are relying on
|
// We need a Process call more often if we are relying on
|
||||||
@ -122,7 +133,7 @@ int64_t VideoReceiver::TimeUntilNextProcess() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t VideoReceiver::SetReceiveChannelParameters(int64_t rtt) {
|
int32_t VideoReceiver::SetReceiveChannelParameters(int64_t rtt) {
|
||||||
rtc::CritScope cs(&receive_crit_);
|
RTC_DCHECK_RUN_ON(&module_thread_);
|
||||||
_receiver.UpdateRtt(rtt);
|
_receiver.UpdateRtt(rtt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -142,7 +153,6 @@ int32_t VideoReceiver::SetVideoProtection(VCMVideoProtection videoProtection,
|
|||||||
}
|
}
|
||||||
|
|
||||||
case kProtectionNackFEC: {
|
case kProtectionNackFEC: {
|
||||||
rtc::CritScope cs(&receive_crit_);
|
|
||||||
RTC_DCHECK(enable);
|
RTC_DCHECK(enable);
|
||||||
_receiver.SetNackMode(kNack,
|
_receiver.SetNackMode(kNack,
|
||||||
media_optimization::kLowRttNackMs,
|
media_optimization::kLowRttNackMs,
|
||||||
@ -165,20 +175,22 @@ int32_t VideoReceiver::SetVideoProtection(VCMVideoProtection videoProtection,
|
|||||||
// ready for rendering.
|
// ready for rendering.
|
||||||
int32_t VideoReceiver::RegisterReceiveCallback(
|
int32_t VideoReceiver::RegisterReceiveCallback(
|
||||||
VCMReceiveCallback* receiveCallback) {
|
VCMReceiveCallback* receiveCallback) {
|
||||||
RTC_DCHECK(construction_thread_.CalledOnValidThread());
|
RTC_DCHECK_RUN_ON(&construction_thread_);
|
||||||
// TODO(tommi): Callback may be null, but only after the decoder thread has
|
RTC_DCHECK(!IsDecoderThreadRunning());
|
||||||
// been stopped. Use the signal we now get that tells us when the decoder
|
// This value is set before the decoder thread starts and unset after
|
||||||
// thread isn't running, to DCHECK that the method is never called while it
|
// the decoder thread has been stopped.
|
||||||
// is. Once we're confident, we can remove the lock.
|
|
||||||
rtc::CritScope cs(&receive_crit_);
|
|
||||||
_decodedFrameCallback.SetUserReceiveCallback(receiveCallback);
|
_decodedFrameCallback.SetUserReceiveCallback(receiveCallback);
|
||||||
return VCM_OK;
|
return VCM_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t VideoReceiver::RegisterReceiveStatisticsCallback(
|
int32_t VideoReceiver::RegisterReceiveStatisticsCallback(
|
||||||
VCMReceiveStatisticsCallback* receiveStats) {
|
VCMReceiveStatisticsCallback* receiveStats) {
|
||||||
RTC_DCHECK(construction_thread_.CalledOnValidThread());
|
RTC_DCHECK_RUN_ON(&construction_thread_);
|
||||||
rtc::CritScope cs(&process_crit_);
|
RTC_DCHECK(!IsDecoderThreadRunning() && !is_attached_to_process_thread_);
|
||||||
|
// |_receiver| is used on both the decoder and module threads.
|
||||||
|
// However, since we make sure that we never do anything on the module thread
|
||||||
|
// when the decoder thread is not running, we don't need a lock for the
|
||||||
|
// |_receiver| or |_receiveStatsCallback| here.
|
||||||
_receiver.RegisterStatsCallback(receiveStats);
|
_receiver.RegisterStatsCallback(receiveStats);
|
||||||
_receiveStatsCallback = receiveStats;
|
_receiveStatsCallback = receiveStats;
|
||||||
return VCM_OK;
|
return VCM_OK;
|
||||||
@ -187,10 +199,8 @@ int32_t VideoReceiver::RegisterReceiveStatisticsCallback(
|
|||||||
// Register an externally defined decoder object.
|
// Register an externally defined decoder object.
|
||||||
void VideoReceiver::RegisterExternalDecoder(VideoDecoder* externalDecoder,
|
void VideoReceiver::RegisterExternalDecoder(VideoDecoder* externalDecoder,
|
||||||
uint8_t payloadType) {
|
uint8_t payloadType) {
|
||||||
RTC_DCHECK(construction_thread_.CalledOnValidThread());
|
RTC_DCHECK_RUN_ON(&construction_thread_);
|
||||||
// TODO(tommi): This method must be called when the decoder thread is not
|
RTC_DCHECK(!IsDecoderThreadRunning());
|
||||||
// running. Do we need a lock in that case?
|
|
||||||
rtc::CritScope cs(&receive_crit_);
|
|
||||||
if (externalDecoder == nullptr) {
|
if (externalDecoder == nullptr) {
|
||||||
RTC_CHECK(_codecDataBase.DeregisterExternalDecoder(payloadType));
|
RTC_CHECK(_codecDataBase.DeregisterExternalDecoder(payloadType));
|
||||||
return;
|
return;
|
||||||
@ -201,53 +211,87 @@ void VideoReceiver::RegisterExternalDecoder(VideoDecoder* externalDecoder,
|
|||||||
// Register a frame type request callback.
|
// Register a frame type request callback.
|
||||||
int32_t VideoReceiver::RegisterFrameTypeCallback(
|
int32_t VideoReceiver::RegisterFrameTypeCallback(
|
||||||
VCMFrameTypeCallback* frameTypeCallback) {
|
VCMFrameTypeCallback* frameTypeCallback) {
|
||||||
rtc::CritScope cs(&process_crit_);
|
RTC_DCHECK_RUN_ON(&construction_thread_);
|
||||||
|
RTC_DCHECK(!IsDecoderThreadRunning() && !is_attached_to_process_thread_);
|
||||||
|
// This callback is used on the module thread, but since we don't get
|
||||||
|
// callbacks on the module thread while the decoder thread isn't running
|
||||||
|
// (and this function must not be called when the decoder is running),
|
||||||
|
// we don't need a lock here.
|
||||||
_frameTypeCallback = frameTypeCallback;
|
_frameTypeCallback = frameTypeCallback;
|
||||||
return VCM_OK;
|
return VCM_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t VideoReceiver::RegisterPacketRequestCallback(
|
int32_t VideoReceiver::RegisterPacketRequestCallback(
|
||||||
VCMPacketRequestCallback* callback) {
|
VCMPacketRequestCallback* callback) {
|
||||||
rtc::CritScope cs(&process_crit_);
|
RTC_DCHECK_RUN_ON(&construction_thread_);
|
||||||
|
RTC_DCHECK(!IsDecoderThreadRunning() && !is_attached_to_process_thread_);
|
||||||
|
// This callback is used on the module thread, but since we don't get
|
||||||
|
// callbacks on the module thread while the decoder thread isn't running
|
||||||
|
// (and this function must not be called when the decoder is running),
|
||||||
|
// we don't need a lock here.
|
||||||
_packetRequestCallback = callback;
|
_packetRequestCallback = callback;
|
||||||
return VCM_OK;
|
return VCM_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoReceiver::TriggerDecoderShutdown() {
|
void VideoReceiver::TriggerDecoderShutdown() {
|
||||||
RTC_DCHECK(construction_thread_.CalledOnValidThread());
|
RTC_DCHECK_RUN_ON(&construction_thread_);
|
||||||
|
RTC_DCHECK(IsDecoderThreadRunning());
|
||||||
_receiver.TriggerDecoderShutdown();
|
_receiver.TriggerDecoderShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VideoReceiver::DecoderThreadStarting() {
|
||||||
|
RTC_DCHECK_RUN_ON(&construction_thread_);
|
||||||
|
RTC_DCHECK(!IsDecoderThreadRunning());
|
||||||
|
if (process_thread_ && !is_attached_to_process_thread_) {
|
||||||
|
process_thread_->RegisterModule(this, RTC_FROM_HERE);
|
||||||
|
}
|
||||||
|
#if RTC_DCHECK_IS_ON
|
||||||
|
decoder_thread_is_running_ = true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void VideoReceiver::DecoderThreadStopped() {
|
||||||
|
RTC_DCHECK_RUN_ON(&construction_thread_);
|
||||||
|
RTC_DCHECK(IsDecoderThreadRunning());
|
||||||
|
if (process_thread_ && is_attached_to_process_thread_) {
|
||||||
|
process_thread_->DeRegisterModule(this);
|
||||||
|
}
|
||||||
|
#if RTC_DCHECK_IS_ON
|
||||||
|
decoder_thread_is_running_ = false;
|
||||||
|
decoder_thread_.DetachFromThread();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Decode next frame, blocking.
|
// Decode next frame, blocking.
|
||||||
// Should be called as often as possible to get the most out of the decoder.
|
// Should be called as often as possible to get the most out of the decoder.
|
||||||
int32_t VideoReceiver::Decode(uint16_t maxWaitTimeMs) {
|
int32_t VideoReceiver::Decode(uint16_t maxWaitTimeMs) {
|
||||||
bool prefer_late_decoding = false;
|
RTC_DCHECK_RUN_ON(&decoder_thread_);
|
||||||
{
|
VCMEncodedFrame* frame = _receiver.FrameForDecoding(
|
||||||
// TODO(tommi): Chances are that this lock isn't required.
|
maxWaitTimeMs, _codecDataBase.PrefersLateDecoding());
|
||||||
rtc::CritScope cs(&receive_crit_);
|
|
||||||
prefer_late_decoding = _codecDataBase.PrefersLateDecoding();
|
|
||||||
}
|
|
||||||
|
|
||||||
VCMEncodedFrame* frame =
|
|
||||||
_receiver.FrameForDecoding(maxWaitTimeMs, prefer_late_decoding);
|
|
||||||
|
|
||||||
if (!frame)
|
if (!frame)
|
||||||
return VCM_FRAME_NOT_READY;
|
return VCM_FRAME_NOT_READY;
|
||||||
|
|
||||||
|
bool drop_frame = false;
|
||||||
{
|
{
|
||||||
rtc::CritScope cs(&process_crit_);
|
rtc::CritScope cs(&process_crit_);
|
||||||
if (drop_frames_until_keyframe_) {
|
if (drop_frames_until_keyframe_) {
|
||||||
// Still getting delta frames, schedule another keyframe request as if
|
// Still getting delta frames, schedule another keyframe request as if
|
||||||
// decode failed.
|
// decode failed.
|
||||||
if (frame->FrameType() != kVideoFrameKey) {
|
if (frame->FrameType() != kVideoFrameKey) {
|
||||||
|
drop_frame = true;
|
||||||
_scheduleKeyRequest = true;
|
_scheduleKeyRequest = true;
|
||||||
_receiver.ReleaseFrame(frame);
|
} else {
|
||||||
return VCM_FRAME_NOT_READY;
|
drop_frames_until_keyframe_ = false;
|
||||||
}
|
}
|
||||||
drop_frames_until_keyframe_ = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (drop_frame) {
|
||||||
|
_receiver.ReleaseFrame(frame);
|
||||||
|
return VCM_FRAME_NOT_READY;
|
||||||
|
}
|
||||||
|
|
||||||
if (pre_decode_image_callback_) {
|
if (pre_decode_image_callback_) {
|
||||||
EncodedImage encoded_image(frame->EncodedImage());
|
EncodedImage encoded_image(frame->EncodedImage());
|
||||||
int qp = -1;
|
int qp = -1;
|
||||||
@ -258,7 +302,6 @@ int32_t VideoReceiver::Decode(uint16_t maxWaitTimeMs) {
|
|||||||
frame->CodecSpecific(), nullptr);
|
frame->CodecSpecific(), nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc::CritScope cs(&receive_crit_);
|
|
||||||
// If this frame was too late, we should adjust the delay accordingly
|
// If this frame was too late, we should adjust the delay accordingly
|
||||||
_timing->UpdateCurrentDelay(frame->RenderTimeMs(),
|
_timing->UpdateCurrentDelay(frame->RenderTimeMs(),
|
||||||
clock_->TimeInMilliseconds());
|
clock_->TimeInMilliseconds());
|
||||||
@ -278,7 +321,7 @@ int32_t VideoReceiver::Decode(uint16_t maxWaitTimeMs) {
|
|||||||
// TODO(philipel): Clean up among the Decode functions as we replace
|
// TODO(philipel): Clean up among the Decode functions as we replace
|
||||||
// VCMEncodedFrame with FrameObject.
|
// VCMEncodedFrame with FrameObject.
|
||||||
int32_t VideoReceiver::Decode(const webrtc::VCMEncodedFrame* frame) {
|
int32_t VideoReceiver::Decode(const webrtc::VCMEncodedFrame* frame) {
|
||||||
rtc::CritScope lock(&receive_crit_);
|
RTC_DCHECK_RUN_ON(&decoder_thread_);
|
||||||
if (pre_decode_image_callback_) {
|
if (pre_decode_image_callback_) {
|
||||||
EncodedImage encoded_image(frame->EncodedImage());
|
EncodedImage encoded_image(frame->EncodedImage());
|
||||||
int qp = -1;
|
int qp = -1;
|
||||||
@ -291,19 +334,20 @@ int32_t VideoReceiver::Decode(const webrtc::VCMEncodedFrame* frame) {
|
|||||||
return Decode(*frame);
|
return Decode(*frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoReceiver::DecodingStopped() {
|
|
||||||
// No further calls to Decode() will be made after this point.
|
|
||||||
// TODO(tommi): Make use of this to clarify and check threading model.
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t VideoReceiver::RequestKeyFrame() {
|
int32_t VideoReceiver::RequestKeyFrame() {
|
||||||
|
RTC_DCHECK_RUN_ON(&module_thread_);
|
||||||
|
|
||||||
|
// Since we deregister from the module thread when the decoder thread isn't
|
||||||
|
// running, we should get no calls here if decoding isn't being done.
|
||||||
|
RTC_DCHECK(IsDecoderThreadRunning());
|
||||||
|
|
||||||
TRACE_EVENT0("webrtc", "RequestKeyFrame");
|
TRACE_EVENT0("webrtc", "RequestKeyFrame");
|
||||||
rtc::CritScope cs(&process_crit_);
|
|
||||||
if (_frameTypeCallback != nullptr) {
|
if (_frameTypeCallback != nullptr) {
|
||||||
const int32_t ret = _frameTypeCallback->RequestKeyFrame();
|
const int32_t ret = _frameTypeCallback->RequestKeyFrame();
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
rtc::CritScope cs(&process_crit_);
|
||||||
_scheduleKeyRequest = false;
|
_scheduleKeyRequest = false;
|
||||||
} else {
|
} else {
|
||||||
return VCM_MISSING_CALLBACK;
|
return VCM_MISSING_CALLBACK;
|
||||||
@ -313,6 +357,7 @@ int32_t VideoReceiver::RequestKeyFrame() {
|
|||||||
|
|
||||||
// Must be called from inside the receive side critical section.
|
// Must be called from inside the receive side critical section.
|
||||||
int32_t VideoReceiver::Decode(const VCMEncodedFrame& frame) {
|
int32_t VideoReceiver::Decode(const VCMEncodedFrame& frame) {
|
||||||
|
RTC_DCHECK_RUN_ON(&decoder_thread_);
|
||||||
TRACE_EVENT0("webrtc", "VideoReceiver::Decode");
|
TRACE_EVENT0("webrtc", "VideoReceiver::Decode");
|
||||||
// Change decoder if payload type has changed
|
// Change decoder if payload type has changed
|
||||||
VCMGenericDecoder* decoder =
|
VCMGenericDecoder* decoder =
|
||||||
@ -324,31 +369,41 @@ int32_t VideoReceiver::Decode(const VCMEncodedFrame& frame) {
|
|||||||
int32_t ret = decoder->Decode(frame, clock_->TimeInMilliseconds());
|
int32_t ret = decoder->Decode(frame, clock_->TimeInMilliseconds());
|
||||||
|
|
||||||
// Check for failed decoding, run frame type request callback if needed.
|
// Check for failed decoding, run frame type request callback if needed.
|
||||||
bool request_key_frame = false;
|
bool request_key_frame = (ret < 0);
|
||||||
if (ret < 0) {
|
|
||||||
request_key_frame = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!frame.Complete() || frame.MissingFrame()) {
|
if (!frame.Complete() || frame.MissingFrame()) {
|
||||||
request_key_frame = true;
|
request_key_frame = true;
|
||||||
ret = VCM_OK;
|
ret = VCM_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request_key_frame) {
|
if (request_key_frame) {
|
||||||
rtc::CritScope cs(&process_crit_);
|
rtc::CritScope cs(&process_crit_);
|
||||||
_scheduleKeyRequest = true;
|
if (!_scheduleKeyRequest) {
|
||||||
|
_scheduleKeyRequest = true;
|
||||||
|
// TODO(tommi): Consider if we could instead post a task to the module
|
||||||
|
// thread and call RequestKeyFrame directly. Here we call WakeUp so that
|
||||||
|
// TimeUntilNextProcess() gets called straight away.
|
||||||
|
process_thread_->WakeUp(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(WEBRTC_ANDROID)
|
||||||
|
void VideoReceiver::PollDecodedFrames() {
|
||||||
|
RTC_DCHECK_RUN_ON(&decoder_thread_);
|
||||||
|
auto* current_decoder = _codecDataBase.GetCurrentDecoder();
|
||||||
|
if (current_decoder)
|
||||||
|
current_decoder->PollDecodedFrames();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Register possible receive codecs, can be called multiple times
|
// Register possible receive codecs, can be called multiple times
|
||||||
int32_t VideoReceiver::RegisterReceiveCodec(const VideoCodec* receiveCodec,
|
int32_t VideoReceiver::RegisterReceiveCodec(const VideoCodec* receiveCodec,
|
||||||
int32_t numberOfCores,
|
int32_t numberOfCores,
|
||||||
bool requireKeyFrame) {
|
bool requireKeyFrame) {
|
||||||
RTC_DCHECK(construction_thread_.CalledOnValidThread());
|
RTC_DCHECK_RUN_ON(&construction_thread_);
|
||||||
// TODO(tommi): This method must only be called when the decoder thread
|
RTC_DCHECK(!IsDecoderThreadRunning());
|
||||||
// is not running. Do we need a lock? If not, it looks like we might not need
|
|
||||||
// a lock at all for |_codecDataBase|.
|
|
||||||
rtc::CritScope cs(&receive_crit_);
|
|
||||||
if (receiveCodec == nullptr) {
|
if (receiveCodec == nullptr) {
|
||||||
return VCM_PARAMETER_ERROR;
|
return VCM_PARAMETER_ERROR;
|
||||||
}
|
}
|
||||||
@ -363,6 +418,7 @@ int32_t VideoReceiver::RegisterReceiveCodec(const VideoCodec* receiveCodec,
|
|||||||
int32_t VideoReceiver::IncomingPacket(const uint8_t* incomingPayload,
|
int32_t VideoReceiver::IncomingPacket(const uint8_t* incomingPayload,
|
||||||
size_t payloadLength,
|
size_t payloadLength,
|
||||||
const WebRtcRTPHeader& rtpInfo) {
|
const WebRtcRTPHeader& rtpInfo) {
|
||||||
|
RTC_DCHECK_RUN_ON(&module_thread_);
|
||||||
if (rtpInfo.frameType == kVideoFrameKey) {
|
if (rtpInfo.frameType == kVideoFrameKey) {
|
||||||
TRACE_EVENT1("webrtc", "VCM::PacketKeyFrame", "seqnum",
|
TRACE_EVENT1("webrtc", "VCM::PacketKeyFrame", "seqnum",
|
||||||
rtpInfo.header.sequenceNumber);
|
rtpInfo.header.sequenceNumber);
|
||||||
@ -394,6 +450,7 @@ int32_t VideoReceiver::IncomingPacket(const uint8_t* incomingPayload,
|
|||||||
// to sync with audio. Not included in VideoCodingModule::Delay()
|
// to sync with audio. Not included in VideoCodingModule::Delay()
|
||||||
// Defaults to 0 ms.
|
// Defaults to 0 ms.
|
||||||
int32_t VideoReceiver::SetMinimumPlayoutDelay(uint32_t minPlayoutDelayMs) {
|
int32_t VideoReceiver::SetMinimumPlayoutDelay(uint32_t minPlayoutDelayMs) {
|
||||||
|
RTC_DCHECK_RUN_ON(&module_thread_);
|
||||||
_timing->set_min_playout_delay(minPlayoutDelayMs);
|
_timing->set_min_playout_delay(minPlayoutDelayMs);
|
||||||
return VCM_OK;
|
return VCM_OK;
|
||||||
}
|
}
|
||||||
@ -401,22 +458,24 @@ int32_t VideoReceiver::SetMinimumPlayoutDelay(uint32_t minPlayoutDelayMs) {
|
|||||||
// The estimated delay caused by rendering, defaults to
|
// The estimated delay caused by rendering, defaults to
|
||||||
// kDefaultRenderDelayMs = 10 ms
|
// kDefaultRenderDelayMs = 10 ms
|
||||||
int32_t VideoReceiver::SetRenderDelay(uint32_t timeMS) {
|
int32_t VideoReceiver::SetRenderDelay(uint32_t timeMS) {
|
||||||
|
RTC_DCHECK_RUN_ON(&construction_thread_);
|
||||||
|
RTC_DCHECK(!IsDecoderThreadRunning());
|
||||||
_timing->set_render_delay(timeMS);
|
_timing->set_render_delay(timeMS);
|
||||||
return VCM_OK;
|
return VCM_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Current video delay
|
// Current video delay
|
||||||
int32_t VideoReceiver::Delay() const {
|
int32_t VideoReceiver::Delay() const {
|
||||||
|
RTC_DCHECK_RUN_ON(&module_thread_);
|
||||||
return _timing->TargetVideoDelay();
|
return _timing->TargetVideoDelay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only used by VCMRobustnessTest.
|
||||||
int VideoReceiver::SetReceiverRobustnessMode(
|
int VideoReceiver::SetReceiverRobustnessMode(
|
||||||
VideoCodingModule::ReceiverRobustness robustnessMode,
|
VideoCodingModule::ReceiverRobustness robustnessMode,
|
||||||
VCMDecodeErrorMode decode_error_mode) {
|
VCMDecodeErrorMode decode_error_mode) {
|
||||||
RTC_DCHECK(construction_thread_.CalledOnValidThread());
|
RTC_DCHECK_RUN_ON(&construction_thread_);
|
||||||
// TODO(tommi): This method must only be called when the decoder thread
|
RTC_DCHECK(!IsDecoderThreadRunning());
|
||||||
// is not running and we don't need to hold this lock.
|
|
||||||
rtc::CritScope cs(&receive_crit_);
|
|
||||||
switch (robustnessMode) {
|
switch (robustnessMode) {
|
||||||
case VideoCodingModule::kNone:
|
case VideoCodingModule::kNone:
|
||||||
_receiver.SetNackMode(kNoNack, -1, -1);
|
_receiver.SetNackMode(kNoNack, -1, -1);
|
||||||
@ -434,24 +493,40 @@ int VideoReceiver::SetReceiverRobustnessMode(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void VideoReceiver::SetDecodeErrorMode(VCMDecodeErrorMode decode_error_mode) {
|
void VideoReceiver::SetDecodeErrorMode(VCMDecodeErrorMode decode_error_mode) {
|
||||||
rtc::CritScope cs(&receive_crit_);
|
RTC_DCHECK_RUN_ON(&construction_thread_);
|
||||||
|
RTC_DCHECK(!IsDecoderThreadRunning());
|
||||||
_receiver.SetDecodeErrorMode(decode_error_mode);
|
_receiver.SetDecodeErrorMode(decode_error_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoReceiver::SetNackSettings(size_t max_nack_list_size,
|
void VideoReceiver::SetNackSettings(size_t max_nack_list_size,
|
||||||
int max_packet_age_to_nack,
|
int max_packet_age_to_nack,
|
||||||
int max_incomplete_time_ms) {
|
int max_incomplete_time_ms) {
|
||||||
if (max_nack_list_size != 0) {
|
RTC_DCHECK_RUN_ON(&construction_thread_);
|
||||||
rtc::CritScope cs(&process_crit_);
|
RTC_DCHECK(!IsDecoderThreadRunning());
|
||||||
|
|
||||||
|
if (max_nack_list_size != 0)
|
||||||
max_nack_list_size_ = max_nack_list_size;
|
max_nack_list_size_ = max_nack_list_size;
|
||||||
}
|
|
||||||
_receiver.SetNackSettings(max_nack_list_size, max_packet_age_to_nack,
|
_receiver.SetNackSettings(max_nack_list_size, max_packet_age_to_nack,
|
||||||
max_incomplete_time_ms);
|
max_incomplete_time_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
int VideoReceiver::SetMinReceiverDelay(int desired_delay_ms) {
|
int VideoReceiver::SetMinReceiverDelay(int desired_delay_ms) {
|
||||||
|
RTC_DCHECK_RUN_ON(&construction_thread_);
|
||||||
|
RTC_DCHECK(!IsDecoderThreadRunning());
|
||||||
|
// TODO(tommi): Is the method only used by tests? Maybe could be offered
|
||||||
|
// via a test only subclass?
|
||||||
|
// Info from Stefan: If it is indeed only used by tests I think it's just that
|
||||||
|
// it hasn't been cleaned up when the calling code was cleaned up.
|
||||||
return _receiver.SetMinReceiverDelay(desired_delay_ms);
|
return _receiver.SetMinReceiverDelay(desired_delay_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VideoReceiver::IsDecoderThreadRunning() {
|
||||||
|
#if RTC_DCHECK_IS_ON
|
||||||
|
return decoder_thread_is_running_;
|
||||||
|
#else
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace vcm
|
} // namespace vcm
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
@ -36,6 +36,18 @@
|
|||||||
#include "webrtc/sdk/android/src/jni/surfacetexturehelper_jni.h"
|
#include "webrtc/sdk/android/src/jni/surfacetexturehelper_jni.h"
|
||||||
#include "webrtc/system_wrappers/include/logcat_trace_context.h"
|
#include "webrtc/system_wrappers/include/logcat_trace_context.h"
|
||||||
|
|
||||||
|
// Logging macros.
|
||||||
|
#define TAG_DECODER "MediaCodecVideoDecoder"
|
||||||
|
#ifdef TRACK_BUFFER_TIMING
|
||||||
|
#define ALOGV(...)
|
||||||
|
__android_log_print(ANDROID_LOG_VERBOSE, TAG_DECODER, __VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define ALOGV(...)
|
||||||
|
#endif
|
||||||
|
#define ALOGD LOG_TAG(rtc::LS_INFO, TAG_DECODER)
|
||||||
|
#define ALOGW LOG_TAG(rtc::LS_WARNING, TAG_DECODER)
|
||||||
|
#define ALOGE LOG_TAG(rtc::LS_ERROR, TAG_DECODER)
|
||||||
|
|
||||||
using rtc::Bind;
|
using rtc::Bind;
|
||||||
using rtc::Thread;
|
using rtc::Thread;
|
||||||
using rtc::ThreadManager;
|
using rtc::ThreadManager;
|
||||||
@ -53,22 +65,7 @@ using webrtc::kVideoCodecVP9;
|
|||||||
|
|
||||||
namespace webrtc_jni {
|
namespace webrtc_jni {
|
||||||
|
|
||||||
// Logging macros.
|
class MediaCodecVideoDecoder : public webrtc::VideoDecoder {
|
||||||
#define TAG_DECODER "MediaCodecVideoDecoder"
|
|
||||||
#ifdef TRACK_BUFFER_TIMING
|
|
||||||
#define ALOGV(...)
|
|
||||||
__android_log_print(ANDROID_LOG_VERBOSE, TAG_DECODER, __VA_ARGS__)
|
|
||||||
#else
|
|
||||||
#define ALOGV(...)
|
|
||||||
#endif
|
|
||||||
#define ALOGD LOG_TAG(rtc::LS_INFO, TAG_DECODER)
|
|
||||||
#define ALOGW LOG_TAG(rtc::LS_WARNING, TAG_DECODER)
|
|
||||||
#define ALOGE LOG_TAG(rtc::LS_ERROR, TAG_DECODER)
|
|
||||||
|
|
||||||
enum { kMaxWarningLogFrames = 2 };
|
|
||||||
|
|
||||||
class MediaCodecVideoDecoder : public webrtc::VideoDecoder,
|
|
||||||
public rtc::MessageHandler {
|
|
||||||
public:
|
public:
|
||||||
explicit MediaCodecVideoDecoder(
|
explicit MediaCodecVideoDecoder(
|
||||||
JNIEnv* jni, VideoCodecType codecType, jobject render_egl_context);
|
JNIEnv* jni, VideoCodecType codecType, jobject render_egl_context);
|
||||||
@ -83,6 +80,8 @@ class MediaCodecVideoDecoder : public webrtc::VideoDecoder,
|
|||||||
const CodecSpecificInfo* codecSpecificInfo = NULL,
|
const CodecSpecificInfo* codecSpecificInfo = NULL,
|
||||||
int64_t renderTimeMs = -1) override;
|
int64_t renderTimeMs = -1) override;
|
||||||
|
|
||||||
|
void PollDecodedFrames() override;
|
||||||
|
|
||||||
int32_t RegisterDecodeCompleteCallback(DecodedImageCallback* callback)
|
int32_t RegisterDecodeCompleteCallback(DecodedImageCallback* callback)
|
||||||
override;
|
override;
|
||||||
|
|
||||||
@ -90,22 +89,41 @@ class MediaCodecVideoDecoder : public webrtc::VideoDecoder,
|
|||||||
|
|
||||||
bool PrefersLateDecoding() const override { return true; }
|
bool PrefersLateDecoding() const override { return true; }
|
||||||
|
|
||||||
// rtc::MessageHandler implementation.
|
|
||||||
void OnMessage(rtc::Message* msg) override;
|
|
||||||
|
|
||||||
const char* ImplementationName() const override;
|
const char* ImplementationName() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// CHECK-fail if not running on |codec_thread_|.
|
struct DecodedFrame {
|
||||||
void CheckOnCodecThread();
|
DecodedFrame(VideoFrame frame,
|
||||||
|
int decode_time_ms,
|
||||||
|
int64_t timestamp,
|
||||||
|
int64_t ntp_timestamp,
|
||||||
|
rtc::Optional<uint8_t> qp)
|
||||||
|
: frame(std::move(frame)),
|
||||||
|
decode_time_ms(decode_time_ms),
|
||||||
|
qp(std::move(qp)) {
|
||||||
|
frame.set_timestamp(timestamp);
|
||||||
|
frame.set_ntp_time_ms(ntp_timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
VideoFrame frame;
|
||||||
|
int decode_time_ms;
|
||||||
|
rtc::Optional<uint8_t> qp;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Returns true if running on |codec_thread_|. Used for DCHECKing.
|
||||||
|
bool IsOnCodecThread();
|
||||||
|
|
||||||
int32_t InitDecodeOnCodecThread();
|
int32_t InitDecodeOnCodecThread();
|
||||||
int32_t ResetDecodeOnCodecThread();
|
int32_t ResetDecodeOnCodecThread();
|
||||||
int32_t ReleaseOnCodecThread();
|
int32_t ReleaseOnCodecThread();
|
||||||
int32_t DecodeOnCodecThread(const EncodedImage& inputImage);
|
int32_t DecodeOnCodecThread(const EncodedImage& inputImage,
|
||||||
|
std::vector<DecodedFrame>* frames);
|
||||||
|
void PollDecodedFramesOnCodecThread(std::vector<DecodedFrame>* frames);
|
||||||
// Deliver any outputs pending in the MediaCodec to our |callback_| and return
|
// Deliver any outputs pending in the MediaCodec to our |callback_| and return
|
||||||
// true on success.
|
// true on success.
|
||||||
bool DeliverPendingOutputs(JNIEnv* jni, int dequeue_timeout_us);
|
bool DeliverPendingOutputs(JNIEnv* jni,
|
||||||
|
int dequeue_timeout_us,
|
||||||
|
std::vector<DecodedFrame>* frames);
|
||||||
int32_t ProcessHWErrorOnCodecThread();
|
int32_t ProcessHWErrorOnCodecThread();
|
||||||
void EnableFrameLogOnWarning();
|
void EnableFrameLogOnWarning();
|
||||||
void ResetVariables();
|
void ResetVariables();
|
||||||
@ -179,6 +197,9 @@ class MediaCodecVideoDecoder : public webrtc::VideoDecoder,
|
|||||||
|
|
||||||
// Global references; must be deleted in Release().
|
// Global references; must be deleted in Release().
|
||||||
std::vector<jobject> input_buffers_;
|
std::vector<jobject> input_buffers_;
|
||||||
|
|
||||||
|
// Added to on the codec thread, frames are delivered on the decoder thread.
|
||||||
|
std::vector<DecodedFrame> decoded_frames_;
|
||||||
};
|
};
|
||||||
|
|
||||||
MediaCodecVideoDecoder::MediaCodecVideoDecoder(
|
MediaCodecVideoDecoder::MediaCodecVideoDecoder(
|
||||||
@ -200,7 +221,7 @@ MediaCodecVideoDecoder::MediaCodecVideoDecoder(
|
|||||||
"<init>",
|
"<init>",
|
||||||
"()V"))) {
|
"()V"))) {
|
||||||
codec_thread_->SetName("MediaCodecVideoDecoder", NULL);
|
codec_thread_->SetName("MediaCodecVideoDecoder", NULL);
|
||||||
RTC_CHECK(codec_thread_->Start()) << "Failed to start MediaCodecVideoDecoder";
|
RTC_CHECK(codec_thread_->Start());
|
||||||
|
|
||||||
j_init_decode_method_ = GetMethodID(
|
j_init_decode_method_ = GetMethodID(
|
||||||
jni, *j_media_codec_video_decoder_class_, "initDecode",
|
jni, *j_media_codec_video_decoder_class_, "initDecode",
|
||||||
@ -295,7 +316,7 @@ int32_t MediaCodecVideoDecoder::InitDecode(const VideoCodec* inst,
|
|||||||
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
|
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
|
||||||
}
|
}
|
||||||
// Factory should guard against other codecs being used with us.
|
// Factory should guard against other codecs being used with us.
|
||||||
RTC_CHECK(inst->codecType == codecType_)
|
RTC_DCHECK(inst->codecType == codecType_)
|
||||||
<< "Unsupported codec " << inst->codecType << " for " << codecType_;
|
<< "Unsupported codec " << inst->codecType << " for " << codecType_;
|
||||||
|
|
||||||
if (sw_fallback_required_) {
|
if (sw_fallback_required_) {
|
||||||
@ -316,7 +337,7 @@ int32_t MediaCodecVideoDecoder::InitDecode(const VideoCodec* inst,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MediaCodecVideoDecoder::ResetVariables() {
|
void MediaCodecVideoDecoder::ResetVariables() {
|
||||||
CheckOnCodecThread();
|
RTC_DCHECK(IsOnCodecThread());
|
||||||
|
|
||||||
key_frame_required_ = true;
|
key_frame_required_ = true;
|
||||||
frames_received_ = 0;
|
frames_received_ = 0;
|
||||||
@ -331,7 +352,7 @@ void MediaCodecVideoDecoder::ResetVariables() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t MediaCodecVideoDecoder::InitDecodeOnCodecThread() {
|
int32_t MediaCodecVideoDecoder::InitDecodeOnCodecThread() {
|
||||||
CheckOnCodecThread();
|
RTC_DCHECK(IsOnCodecThread());
|
||||||
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
||||||
ScopedLocalRefFrame local_ref_frame(jni);
|
ScopedLocalRefFrame local_ref_frame(jni);
|
||||||
ALOGD << "InitDecodeOnCodecThread Type: " << (int)codecType_ << ". "
|
ALOGD << "InitDecodeOnCodecThread Type: " << (int)codecType_ << ". "
|
||||||
@ -405,13 +426,11 @@ int32_t MediaCodecVideoDecoder::InitDecodeOnCodecThread() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
codec_thread_->PostDelayed(RTC_FROM_HERE, kMediaCodecPollMs, this);
|
|
||||||
|
|
||||||
return WEBRTC_VIDEO_CODEC_OK;
|
return WEBRTC_VIDEO_CODEC_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t MediaCodecVideoDecoder::ResetDecodeOnCodecThread() {
|
int32_t MediaCodecVideoDecoder::ResetDecodeOnCodecThread() {
|
||||||
CheckOnCodecThread();
|
RTC_DCHECK(IsOnCodecThread());
|
||||||
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
||||||
ScopedLocalRefFrame local_ref_frame(jni);
|
ScopedLocalRefFrame local_ref_frame(jni);
|
||||||
ALOGD << "ResetDecodeOnCodecThread Type: " << (int)codecType_ << ". "
|
ALOGD << "ResetDecodeOnCodecThread Type: " << (int)codecType_ << ". "
|
||||||
@ -420,7 +439,6 @@ int32_t MediaCodecVideoDecoder::ResetDecodeOnCodecThread() {
|
|||||||
". Frames decoded: " << frames_decoded_;
|
". Frames decoded: " << frames_decoded_;
|
||||||
|
|
||||||
inited_ = false;
|
inited_ = false;
|
||||||
rtc::MessageQueueManager::Clear(this);
|
|
||||||
ResetVariables();
|
ResetVariables();
|
||||||
|
|
||||||
jni->CallVoidMethod(
|
jni->CallVoidMethod(
|
||||||
@ -436,8 +454,6 @@ int32_t MediaCodecVideoDecoder::ResetDecodeOnCodecThread() {
|
|||||||
}
|
}
|
||||||
inited_ = true;
|
inited_ = true;
|
||||||
|
|
||||||
codec_thread_->PostDelayed(RTC_FROM_HERE, kMediaCodecPollMs, this);
|
|
||||||
|
|
||||||
return WEBRTC_VIDEO_CODEC_OK;
|
return WEBRTC_VIDEO_CODEC_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,10 +464,10 @@ int32_t MediaCodecVideoDecoder::Release() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t MediaCodecVideoDecoder::ReleaseOnCodecThread() {
|
int32_t MediaCodecVideoDecoder::ReleaseOnCodecThread() {
|
||||||
|
RTC_DCHECK(IsOnCodecThread());
|
||||||
if (!inited_) {
|
if (!inited_) {
|
||||||
return WEBRTC_VIDEO_CODEC_OK;
|
return WEBRTC_VIDEO_CODEC_OK;
|
||||||
}
|
}
|
||||||
CheckOnCodecThread();
|
|
||||||
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
||||||
ALOGD << "DecoderReleaseOnCodecThread: Frames received: " <<
|
ALOGD << "DecoderReleaseOnCodecThread: Frames received: " <<
|
||||||
frames_received_ << ". Frames decoded: " << frames_decoded_;
|
frames_received_ << ". Frames decoded: " << frames_decoded_;
|
||||||
@ -463,7 +479,6 @@ int32_t MediaCodecVideoDecoder::ReleaseOnCodecThread() {
|
|||||||
jni->CallVoidMethod(*j_media_codec_video_decoder_, j_release_method_);
|
jni->CallVoidMethod(*j_media_codec_video_decoder_, j_release_method_);
|
||||||
surface_texture_helper_ = nullptr;
|
surface_texture_helper_ = nullptr;
|
||||||
inited_ = false;
|
inited_ = false;
|
||||||
rtc::MessageQueueManager::Clear(this);
|
|
||||||
if (CheckException(jni)) {
|
if (CheckException(jni)) {
|
||||||
ALOGE << "Decoder release exception";
|
ALOGE << "Decoder release exception";
|
||||||
return WEBRTC_VIDEO_CODEC_ERROR;
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
||||||
@ -472,19 +487,19 @@ int32_t MediaCodecVideoDecoder::ReleaseOnCodecThread() {
|
|||||||
return WEBRTC_VIDEO_CODEC_OK;
|
return WEBRTC_VIDEO_CODEC_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MediaCodecVideoDecoder::CheckOnCodecThread() {
|
bool MediaCodecVideoDecoder::IsOnCodecThread() {
|
||||||
RTC_CHECK(codec_thread_.get() == ThreadManager::Instance()->CurrentThread())
|
return codec_thread_.get() == ThreadManager::Instance()->CurrentThread();
|
||||||
<< "Running on wrong thread!";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MediaCodecVideoDecoder::EnableFrameLogOnWarning() {
|
void MediaCodecVideoDecoder::EnableFrameLogOnWarning() {
|
||||||
// Log next 2 output frames.
|
// Log next 2 output frames.
|
||||||
|
static const int kMaxWarningLogFrames = 2;
|
||||||
frames_decoded_logged_ = std::max(
|
frames_decoded_logged_ = std::max(
|
||||||
frames_decoded_logged_, frames_decoded_ + kMaxWarningLogFrames);
|
frames_decoded_logged_, frames_decoded_ + kMaxWarningLogFrames);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t MediaCodecVideoDecoder::ProcessHWErrorOnCodecThread() {
|
int32_t MediaCodecVideoDecoder::ProcessHWErrorOnCodecThread() {
|
||||||
CheckOnCodecThread();
|
RTC_DCHECK(IsOnCodecThread());
|
||||||
int ret_val = ReleaseOnCodecThread();
|
int ret_val = ReleaseOnCodecThread();
|
||||||
if (ret_val < 0) {
|
if (ret_val < 0) {
|
||||||
ALOGE << "ProcessHWError: Release failure";
|
ALOGE << "ProcessHWError: Release failure";
|
||||||
@ -515,22 +530,17 @@ int32_t MediaCodecVideoDecoder::Decode(
|
|||||||
const RTPFragmentationHeader* fragmentation,
|
const RTPFragmentationHeader* fragmentation,
|
||||||
const CodecSpecificInfo* codecSpecificInfo,
|
const CodecSpecificInfo* codecSpecificInfo,
|
||||||
int64_t renderTimeMs) {
|
int64_t renderTimeMs) {
|
||||||
|
RTC_DCHECK(callback_);
|
||||||
|
RTC_DCHECK(inited_);
|
||||||
|
|
||||||
if (sw_fallback_required_) {
|
if (sw_fallback_required_) {
|
||||||
ALOGE << "Decode() - fallback to SW codec";
|
ALOGE << "Decode() - fallback to SW codec";
|
||||||
return WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE;
|
return WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE;
|
||||||
}
|
}
|
||||||
if (callback_ == NULL) {
|
|
||||||
ALOGE << "Decode() - callback_ is NULL";
|
|
||||||
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
|
|
||||||
}
|
|
||||||
if (inputImage._buffer == NULL && inputImage._length > 0) {
|
if (inputImage._buffer == NULL && inputImage._length > 0) {
|
||||||
ALOGE << "Decode() - inputImage is incorrect";
|
ALOGE << "Decode() - inputImage is incorrect";
|
||||||
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
|
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
|
||||||
}
|
}
|
||||||
if (!inited_) {
|
|
||||||
ALOGE << "Decode() - decoder is not initialized";
|
|
||||||
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if encoded frame dimension has changed.
|
// Check if encoded frame dimension has changed.
|
||||||
if ((inputImage._encodedWidth * inputImage._encodedHeight > 0) &&
|
if ((inputImage._encodedWidth * inputImage._encodedHeight > 0) &&
|
||||||
@ -575,14 +585,32 @@ int32_t MediaCodecVideoDecoder::Decode(
|
|||||||
return WEBRTC_VIDEO_CODEC_ERROR;
|
return WEBRTC_VIDEO_CODEC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return codec_thread_->Invoke<int32_t>(
|
std::vector<DecodedFrame> frames;
|
||||||
|
int32_t ret = codec_thread_->Invoke<int32_t>(
|
||||||
|
RTC_FROM_HERE, Bind(&MediaCodecVideoDecoder::DecodeOnCodecThread, this,
|
||||||
|
inputImage, &frames));
|
||||||
|
for (auto& f : frames)
|
||||||
|
callback_->Decoded(f.frame, rtc::Optional<int32_t>(f.decode_time_ms), f.qp);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MediaCodecVideoDecoder::PollDecodedFrames() {
|
||||||
|
RTC_DCHECK(callback_);
|
||||||
|
|
||||||
|
std::vector<DecodedFrame> frames;
|
||||||
|
codec_thread_->Invoke<void>(
|
||||||
RTC_FROM_HERE,
|
RTC_FROM_HERE,
|
||||||
Bind(&MediaCodecVideoDecoder::DecodeOnCodecThread, this, inputImage));
|
Bind(&MediaCodecVideoDecoder::PollDecodedFramesOnCodecThread, this,
|
||||||
|
&frames));
|
||||||
|
|
||||||
|
for (auto& f : frames)
|
||||||
|
callback_->Decoded(f.frame, rtc::Optional<int32_t>(f.decode_time_ms), f.qp);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t MediaCodecVideoDecoder::DecodeOnCodecThread(
|
int32_t MediaCodecVideoDecoder::DecodeOnCodecThread(
|
||||||
const EncodedImage& inputImage) {
|
const EncodedImage& inputImage,
|
||||||
CheckOnCodecThread();
|
std::vector<DecodedFrame>* frames) {
|
||||||
|
RTC_DCHECK(IsOnCodecThread());
|
||||||
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
||||||
ScopedLocalRefFrame local_ref_frame(jni);
|
ScopedLocalRefFrame local_ref_frame(jni);
|
||||||
|
|
||||||
@ -598,7 +626,7 @@ int32_t MediaCodecVideoDecoder::DecodeOnCodecThread(
|
|||||||
const int64 drain_start = rtc::TimeMillis();
|
const int64 drain_start = rtc::TimeMillis();
|
||||||
while ((frames_received_ > frames_decoded_ + max_pending_frames_) &&
|
while ((frames_received_ > frames_decoded_ + max_pending_frames_) &&
|
||||||
(rtc::TimeMillis() - drain_start) < kMediaCodecTimeoutMs) {
|
(rtc::TimeMillis() - drain_start) < kMediaCodecTimeoutMs) {
|
||||||
if (!DeliverPendingOutputs(jni, kMediaCodecPollMs)) {
|
if (!DeliverPendingOutputs(jni, kMediaCodecPollMs, frames)) {
|
||||||
ALOGE << "DeliverPendingOutputs error. Frames received: " <<
|
ALOGE << "DeliverPendingOutputs error. Frames received: " <<
|
||||||
frames_received_ << ". Frames decoded: " << frames_decoded_;
|
frames_received_ << ". Frames decoded: " << frames_decoded_;
|
||||||
return ProcessHWErrorOnCodecThread();
|
return ProcessHWErrorOnCodecThread();
|
||||||
@ -618,7 +646,7 @@ int32_t MediaCodecVideoDecoder::DecodeOnCodecThread(
|
|||||||
". Retry DeliverPendingOutputs.";
|
". Retry DeliverPendingOutputs.";
|
||||||
EnableFrameLogOnWarning();
|
EnableFrameLogOnWarning();
|
||||||
// Try to drain the decoder.
|
// Try to drain the decoder.
|
||||||
if (!DeliverPendingOutputs(jni, kMediaCodecPollMs)) {
|
if (!DeliverPendingOutputs(jni, kMediaCodecPollMs, frames)) {
|
||||||
ALOGE << "DeliverPendingOutputs error. Frames received: " <<
|
ALOGE << "DeliverPendingOutputs error. Frames received: " <<
|
||||||
frames_received_ << ". Frames decoded: " << frames_decoded_;
|
frames_received_ << ". Frames decoded: " << frames_decoded_;
|
||||||
return ProcessHWErrorOnCodecThread();
|
return ProcessHWErrorOnCodecThread();
|
||||||
@ -636,7 +664,7 @@ int32_t MediaCodecVideoDecoder::DecodeOnCodecThread(
|
|||||||
jobject j_input_buffer = input_buffers_[j_input_buffer_index];
|
jobject j_input_buffer = input_buffers_[j_input_buffer_index];
|
||||||
uint8_t* buffer =
|
uint8_t* buffer =
|
||||||
reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_input_buffer));
|
reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_input_buffer));
|
||||||
RTC_CHECK(buffer) << "Indirect buffer??";
|
RTC_DCHECK(buffer) << "Indirect buffer??";
|
||||||
int64_t buffer_capacity = jni->GetDirectBufferCapacity(j_input_buffer);
|
int64_t buffer_capacity = jni->GetDirectBufferCapacity(j_input_buffer);
|
||||||
if (CheckException(jni) || buffer_capacity < inputImage._length) {
|
if (CheckException(jni) || buffer_capacity < inputImage._length) {
|
||||||
ALOGE << "Input frame size "<< inputImage._length <<
|
ALOGE << "Input frame size "<< inputImage._length <<
|
||||||
@ -689,7 +717,7 @@ int32_t MediaCodecVideoDecoder::DecodeOnCodecThread(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try to drain the decoder
|
// Try to drain the decoder
|
||||||
if (!DeliverPendingOutputs(jni, 0)) {
|
if (!DeliverPendingOutputs(jni, 0, frames)) {
|
||||||
ALOGE << "DeliverPendingOutputs error";
|
ALOGE << "DeliverPendingOutputs error";
|
||||||
return ProcessHWErrorOnCodecThread();
|
return ProcessHWErrorOnCodecThread();
|
||||||
}
|
}
|
||||||
@ -697,9 +725,26 @@ int32_t MediaCodecVideoDecoder::DecodeOnCodecThread(
|
|||||||
return WEBRTC_VIDEO_CODEC_OK;
|
return WEBRTC_VIDEO_CODEC_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MediaCodecVideoDecoder::PollDecodedFramesOnCodecThread(
|
||||||
|
std::vector<DecodedFrame>* frames) {
|
||||||
|
RTC_DCHECK(IsOnCodecThread());
|
||||||
|
|
||||||
|
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
||||||
|
ScopedLocalRefFrame local_ref_frame(jni);
|
||||||
|
|
||||||
|
if (!DeliverPendingOutputs(jni, 0, frames)) {
|
||||||
|
ALOGE << "PollDecodedFramesOnCodecThread: DeliverPendingOutputs error";
|
||||||
|
ProcessHWErrorOnCodecThread();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool MediaCodecVideoDecoder::DeliverPendingOutputs(
|
bool MediaCodecVideoDecoder::DeliverPendingOutputs(
|
||||||
JNIEnv* jni, int dequeue_timeout_ms) {
|
JNIEnv* jni,
|
||||||
CheckOnCodecThread();
|
int dequeue_timeout_ms,
|
||||||
|
std::vector<DecodedFrame>* frames) {
|
||||||
|
RTC_DCHECK(IsOnCodecThread());
|
||||||
|
RTC_DCHECK(frames);
|
||||||
|
|
||||||
if (frames_received_ <= frames_decoded_) {
|
if (frames_received_ <= frames_decoded_) {
|
||||||
// No need to query for output buffers - decoder is drained.
|
// No need to query for output buffers - decoder is drained.
|
||||||
return true;
|
return true;
|
||||||
@ -808,7 +853,7 @@ bool MediaCodecVideoDecoder::DeliverPendingOutputs(
|
|||||||
rtc::scoped_refptr<webrtc::I420Buffer> i420_buffer =
|
rtc::scoped_refptr<webrtc::I420Buffer> i420_buffer =
|
||||||
decoded_frame_pool_.CreateBuffer(width, height);
|
decoded_frame_pool_.CreateBuffer(width, height);
|
||||||
if (color_format == COLOR_FormatYUV420Planar) {
|
if (color_format == COLOR_FormatYUV420Planar) {
|
||||||
RTC_CHECK_EQ(0, stride % 2);
|
RTC_DCHECK_EQ(0, stride % 2);
|
||||||
const int uv_stride = stride / 2;
|
const int uv_stride = stride / 2;
|
||||||
const uint8_t* y_ptr = payload;
|
const uint8_t* y_ptr = payload;
|
||||||
const uint8_t* u_ptr = y_ptr + stride * slice_height;
|
const uint8_t* u_ptr = y_ptr + stride * slice_height;
|
||||||
@ -834,7 +879,7 @@ bool MediaCodecVideoDecoder::DeliverPendingOutputs(
|
|||||||
i420_buffer->MutableDataV(), i420_buffer->StrideV(),
|
i420_buffer->MutableDataV(), i420_buffer->StrideV(),
|
||||||
chroma_width, chroma_height);
|
chroma_width, chroma_height);
|
||||||
if (slice_height % 2 == 1) {
|
if (slice_height % 2 == 1) {
|
||||||
RTC_CHECK_EQ(height, slice_height);
|
RTC_DCHECK_EQ(height, slice_height);
|
||||||
// Duplicate the last chroma rows.
|
// Duplicate the last chroma rows.
|
||||||
uint8_t* u_last_row_ptr = i420_buffer->MutableDataU() +
|
uint8_t* u_last_row_ptr = i420_buffer->MutableDataU() +
|
||||||
chroma_height * i420_buffer->StrideU();
|
chroma_height * i420_buffer->StrideU();
|
||||||
@ -909,9 +954,16 @@ bool MediaCodecVideoDecoder::DeliverPendingOutputs(
|
|||||||
|
|
||||||
rtc::Optional<uint8_t> qp = pending_frame_qps_.front();
|
rtc::Optional<uint8_t> qp = pending_frame_qps_.front();
|
||||||
pending_frame_qps_.pop_front();
|
pending_frame_qps_.pop_front();
|
||||||
callback_->Decoded(decoded_frame, rtc::Optional<int32_t>(decode_time_ms),
|
decoded_frames_.push_back(DecodedFrame(std::move(decoded_frame),
|
||||||
qp);
|
decode_time_ms, output_timestamps_ms,
|
||||||
|
output_ntp_timestamps_ms, qp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
frames->reserve(frames->size() + decoded_frames_.size());
|
||||||
|
std::move(decoded_frames_.begin(), decoded_frames_.end(),
|
||||||
|
std::back_inserter(*frames));
|
||||||
|
decoded_frames_.clear();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -921,26 +973,6 @@ int32_t MediaCodecVideoDecoder::RegisterDecodeCompleteCallback(
|
|||||||
return WEBRTC_VIDEO_CODEC_OK;
|
return WEBRTC_VIDEO_CODEC_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MediaCodecVideoDecoder::OnMessage(rtc::Message* msg) {
|
|
||||||
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
|
||||||
ScopedLocalRefFrame local_ref_frame(jni);
|
|
||||||
if (!inited_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// We only ever send one message to |this| directly (not through a Bind()'d
|
|
||||||
// functor), so expect no ID/data.
|
|
||||||
RTC_CHECK(!msg->message_id) << "Unexpected message!";
|
|
||||||
RTC_CHECK(!msg->pdata) << "Unexpected message!";
|
|
||||||
CheckOnCodecThread();
|
|
||||||
|
|
||||||
if (!DeliverPendingOutputs(jni, 0)) {
|
|
||||||
ALOGE << "OnMessage: DeliverPendingOutputs error";
|
|
||||||
ProcessHWErrorOnCodecThread();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
codec_thread_->PostDelayed(RTC_FROM_HERE, kMediaCodecPollMs, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
MediaCodecVideoDecoderFactory::MediaCodecVideoDecoderFactory()
|
MediaCodecVideoDecoderFactory::MediaCodecVideoDecoderFactory()
|
||||||
: egl_context_(nullptr) {
|
: egl_context_(nullptr) {
|
||||||
ALOGD << "MediaCodecVideoDecoderFactory ctor";
|
ALOGD << "MediaCodecVideoDecoderFactory ctor";
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "webrtc/base/location.h"
|
#include "webrtc/base/location.h"
|
||||||
#include "webrtc/base/logging.h"
|
#include "webrtc/base/logging.h"
|
||||||
#include "webrtc/base/optional.h"
|
#include "webrtc/base/optional.h"
|
||||||
|
#include "webrtc/base/timeutils.h"
|
||||||
#include "webrtc/base/trace_event.h"
|
#include "webrtc/base/trace_event.h"
|
||||||
#include "webrtc/common_types.h"
|
#include "webrtc/common_types.h"
|
||||||
#include "webrtc/common_video/h264/profile_level_id.h"
|
#include "webrtc/common_video/h264/profile_level_id.h"
|
||||||
@ -168,19 +169,21 @@ VideoCodec CreateDecoderVideoCodec(const VideoReceiveStream::Decoder& decoder) {
|
|||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
VideoReceiveStream::VideoReceiveStream(
|
VideoReceiveStream::VideoReceiveStream(int num_cpu_cores,
|
||||||
int num_cpu_cores,
|
PacketRouter* packet_router,
|
||||||
PacketRouter* packet_router,
|
VideoReceiveStream::Config config,
|
||||||
VideoReceiveStream::Config config,
|
ProcessThread* process_thread,
|
||||||
ProcessThread* process_thread,
|
CallStats* call_stats,
|
||||||
CallStats* call_stats,
|
VieRemb* remb)
|
||||||
VieRemb* remb)
|
|
||||||
: transport_adapter_(config.rtcp_send_transport),
|
: transport_adapter_(config.rtcp_send_transport),
|
||||||
config_(std::move(config)),
|
config_(std::move(config)),
|
||||||
num_cpu_cores_(num_cpu_cores),
|
num_cpu_cores_(num_cpu_cores),
|
||||||
process_thread_(process_thread),
|
process_thread_(process_thread),
|
||||||
clock_(Clock::GetRealTimeClock()),
|
clock_(Clock::GetRealTimeClock()),
|
||||||
decode_thread_(DecodeThreadFunction, this, "DecodingThread"),
|
decode_thread_(&DecodeThreadFunction,
|
||||||
|
this,
|
||||||
|
"DecodingThread",
|
||||||
|
rtc::kHighestPriority),
|
||||||
call_stats_(call_stats),
|
call_stats_(call_stats),
|
||||||
timing_(new VCMTiming(clock_)),
|
timing_(new VCMTiming(clock_)),
|
||||||
video_receiver_(clock_, nullptr, this, timing_.get(), this, this),
|
video_receiver_(clock_, nullptr, this, timing_.get(), this, this),
|
||||||
@ -221,7 +224,6 @@ VideoReceiveStream::VideoReceiveStream(
|
|||||||
frame_buffer_.reset(new video_coding::FrameBuffer(
|
frame_buffer_.reset(new video_coding::FrameBuffer(
|
||||||
clock_, jitter_estimator_.get(), timing_.get(), &stats_proxy_));
|
clock_, jitter_estimator_.get(), timing_.get(), &stats_proxy_));
|
||||||
|
|
||||||
process_thread_->RegisterModule(&video_receiver_, RTC_FROM_HERE);
|
|
||||||
process_thread_->RegisterModule(&rtp_stream_sync_, RTC_FROM_HERE);
|
process_thread_->RegisterModule(&rtp_stream_sync_, RTC_FROM_HERE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +233,6 @@ VideoReceiveStream::~VideoReceiveStream() {
|
|||||||
Stop();
|
Stop();
|
||||||
|
|
||||||
process_thread_->DeRegisterModule(&rtp_stream_sync_);
|
process_thread_->DeRegisterModule(&rtp_stream_sync_);
|
||||||
process_thread_->DeRegisterModule(&video_receiver_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoReceiveStream::SignalNetworkState(NetworkState state) {
|
void VideoReceiveStream::SignalNetworkState(NetworkState state) {
|
||||||
@ -239,7 +240,6 @@ void VideoReceiveStream::SignalNetworkState(NetworkState state) {
|
|||||||
rtp_stream_receiver_.SignalNetworkState(state);
|
rtp_stream_receiver_.SignalNetworkState(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool VideoReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) {
|
bool VideoReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) {
|
||||||
return rtp_stream_receiver_.DeliverRtcp(packet, length);
|
return rtp_stream_receiver_.DeliverRtcp(packet, length);
|
||||||
}
|
}
|
||||||
@ -302,25 +302,31 @@ void VideoReceiveStream::Start() {
|
|||||||
&stats_proxy_, renderer));
|
&stats_proxy_, renderer));
|
||||||
// Register the channel to receive stats updates.
|
// Register the channel to receive stats updates.
|
||||||
call_stats_->RegisterStatsObserver(video_stream_decoder_.get());
|
call_stats_->RegisterStatsObserver(video_stream_decoder_.get());
|
||||||
|
|
||||||
|
video_receiver_.DecoderThreadStarting();
|
||||||
|
process_thread_->RegisterModule(&video_receiver_, RTC_FROM_HERE);
|
||||||
|
|
||||||
// Start the decode thread
|
// Start the decode thread
|
||||||
decode_thread_.Start();
|
decode_thread_.Start();
|
||||||
decode_thread_.SetPriority(rtc::kHighestPriority);
|
|
||||||
rtp_stream_receiver_.StartReceive();
|
rtp_stream_receiver_.StartReceive();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoReceiveStream::Stop() {
|
void VideoReceiveStream::Stop() {
|
||||||
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
|
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
|
||||||
rtp_stream_receiver_.StopReceive();
|
rtp_stream_receiver_.StopReceive();
|
||||||
// TriggerDecoderShutdown will release any waiting decoder thread and make it
|
|
||||||
// stop immediately, instead of waiting for a timeout. Needs to be called
|
|
||||||
// before joining the decoder thread thread.
|
|
||||||
video_receiver_.TriggerDecoderShutdown();
|
|
||||||
|
|
||||||
frame_buffer_->Stop();
|
frame_buffer_->Stop();
|
||||||
call_stats_->DeregisterStatsObserver(&rtp_stream_receiver_);
|
call_stats_->DeregisterStatsObserver(&rtp_stream_receiver_);
|
||||||
|
process_thread_->DeRegisterModule(&video_receiver_);
|
||||||
|
|
||||||
if (decode_thread_.IsRunning()) {
|
if (decode_thread_.IsRunning()) {
|
||||||
|
// TriggerDecoderShutdown will release any waiting decoder thread and make
|
||||||
|
// it stop immediately, instead of waiting for a timeout. Needs to be called
|
||||||
|
// before joining the decoder thread thread.
|
||||||
|
video_receiver_.TriggerDecoderShutdown();
|
||||||
|
|
||||||
decode_thread_.Stop();
|
decode_thread_.Stop();
|
||||||
|
video_receiver_.DecoderThreadStopped();
|
||||||
// Deregister external decoders so they are no longer running during
|
// Deregister external decoders so they are no longer running during
|
||||||
// destruction. This effectively stops the VCM since the decoder thread is
|
// destruction. This effectively stops the VCM since the decoder thread is
|
||||||
// stopped, the VCM is deregistered and no asynchronous decoder threads are
|
// stopped, the VCM is deregistered and no asynchronous decoder threads are
|
||||||
@ -464,30 +470,48 @@ void VideoReceiveStream::SetMinimumPlayoutDelay(int delay_ms) {
|
|||||||
video_receiver_.SetMinimumPlayoutDelay(delay_ms);
|
video_receiver_.SetMinimumPlayoutDelay(delay_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VideoReceiveStream::DecodeThreadFunction(void* ptr) {
|
void VideoReceiveStream::DecodeThreadFunction(void* ptr) {
|
||||||
return static_cast<VideoReceiveStream*>(ptr)->Decode();
|
while (static_cast<VideoReceiveStream*>(ptr)->Decode()) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VideoReceiveStream::Decode() {
|
bool VideoReceiveStream::Decode() {
|
||||||
TRACE_EVENT0("webrtc", "VideoReceiveStream::Decode");
|
TRACE_EVENT0("webrtc", "VideoReceiveStream::Decode");
|
||||||
static const int kMaxWaitForFrameMs = 3000;
|
static const int kMaxWaitForFrameMs = 3000;
|
||||||
std::unique_ptr<video_coding::FrameObject> frame;
|
std::unique_ptr<video_coding::FrameObject> frame;
|
||||||
video_coding::FrameBuffer::ReturnReason res =
|
|
||||||
frame_buffer_->NextFrame(kMaxWaitForFrameMs, &frame);
|
|
||||||
|
|
||||||
if (res == video_coding::FrameBuffer::ReturnReason::kStopped) {
|
video_coding::FrameBuffer::ReturnReason res;
|
||||||
video_receiver_.DecodingStopped();
|
#if defined(WEBRTC_ANDROID)
|
||||||
|
// This is a temporary workaround for video capture on Android in order to
|
||||||
|
// deliver asynchronously delivered frames, on the decoder thread.
|
||||||
|
// More details here:
|
||||||
|
// https://bugs.chromium.org/p/webrtc/issues/detail?id=7361
|
||||||
|
static const int kPollIntervalMs = 10;
|
||||||
|
int time_remaining = kMaxWaitForFrameMs;
|
||||||
|
do {
|
||||||
|
res = frame_buffer_->NextFrame(kPollIntervalMs, &frame);
|
||||||
|
if (res != video_coding::FrameBuffer::ReturnReason::kTimeout)
|
||||||
|
break;
|
||||||
|
time_remaining -= kPollIntervalMs;
|
||||||
|
video_receiver_.PollDecodedFrames();
|
||||||
|
} while (time_remaining > 0);
|
||||||
|
#else
|
||||||
|
res = frame_buffer_->NextFrame(kMaxWaitForFrameMs, &frame);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (res == video_coding::FrameBuffer::ReturnReason::kStopped)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if (frame) {
|
if (frame) {
|
||||||
if (video_receiver_.Decode(frame.get()) == VCM_OK)
|
if (video_receiver_.Decode(frame.get()) == VCM_OK)
|
||||||
rtp_stream_receiver_.FrameDecoded(frame->picture_id);
|
rtp_stream_receiver_.FrameDecoded(frame->picture_id);
|
||||||
} else {
|
} else {
|
||||||
|
RTC_DCHECK_EQ(res, video_coding::FrameBuffer::ReturnReason::kTimeout);
|
||||||
LOG(LS_WARNING) << "No decodable frame in " << kMaxWaitForFrameMs
|
LOG(LS_WARNING) << "No decodable frame in " << kMaxWaitForFrameMs
|
||||||
<< " ms, requesting keyframe.";
|
<< " ms, requesting keyframe.";
|
||||||
RequestKeyFrame();
|
RequestKeyFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
@ -109,7 +109,7 @@ class VideoReceiveStream : public webrtc::VideoReceiveStream,
|
|||||||
void SetMinimumPlayoutDelay(int delay_ms) override;
|
void SetMinimumPlayoutDelay(int delay_ms) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool DecodeThreadFunction(void* ptr);
|
static void DecodeThreadFunction(void* ptr);
|
||||||
bool Decode();
|
bool Decode();
|
||||||
|
|
||||||
rtc::ThreadChecker worker_thread_checker_;
|
rtc::ThreadChecker worker_thread_checker_;
|
||||||
|
@ -68,6 +68,13 @@ class VideoDecoder {
|
|||||||
const CodecSpecificInfo* codec_specific_info = NULL,
|
const CodecSpecificInfo* codec_specific_info = NULL,
|
||||||
int64_t render_time_ms = -1) = 0;
|
int64_t render_time_ms = -1) = 0;
|
||||||
|
|
||||||
|
#if defined(WEBRTC_ANDROID)
|
||||||
|
// This is a temporary remedy while the Android capture implementation is
|
||||||
|
// being changed to deliver frames on the decoder thread without polling.
|
||||||
|
// See https://bugs.chromium.org/p/webrtc/issues/detail?id=7361
|
||||||
|
virtual void PollDecodedFrames() {}
|
||||||
|
#endif
|
||||||
|
|
||||||
virtual int32_t RegisterDecodeCompleteCallback(
|
virtual int32_t RegisterDecodeCompleteCallback(
|
||||||
DecodedImageCallback* callback) = 0;
|
DecodedImageCallback* callback) = 0;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user