From a70f9450862516eb26d153fc4e8c65e9f54317aa Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Fri, 16 Dec 2011 14:40:05 +0000 Subject: [PATCH] Inject TickTimeInterface into VCM and tests The purpose of this change is to introduce dependency injection of the timer into the video coding module. Review URL: http://webrtc-codereview.appspot.com/332003 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1220 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../main/interface/video_coding.h | 4 ++ .../main/source/content_metrics_processing.cc | 1 - .../main/source/generic_decoder.cc | 13 +++-- .../main/source/generic_decoder.h | 5 +- .../main/source/inter_frame_delay.cc | 16 ++---- .../main/source/inter_frame_delay.h | 6 +- .../video_coding/main/source/jitter_buffer.cc | 24 ++++---- .../video_coding/main/source/jitter_buffer.h | 5 +- .../main/source/jitter_estimator.cc | 2 +- .../main/source/media_opt_util.cc | 41 +++++++------- .../video_coding/main/source/media_opt_util.h | 13 ++--- .../main/source/media_optimization.cc | 36 +++++++----- .../main/source/media_optimization.h | 5 +- .../video_coding/main/source/receiver.cc | 28 +++++----- .../video_coding/main/source/receiver.h | 3 + .../video_coding/main/source/tick_time.h | 55 ------------------- .../main/source/timestamp_extrapolator.cc | 11 ++-- .../main/source/timestamp_extrapolator.h | 7 ++- .../video_coding/main/source/timing.cc | 8 ++- src/modules/video_coding/main/source/timing.h | 5 +- .../main/source/video_coding.gypi | 1 - .../main/source/video_coding_impl.cc | 55 +++++++++++++------ .../main/source/video_coding_impl.h | 14 ++++- .../main/test/decode_from_storage_test.cc | 22 ++++---- .../main/test/generic_codec_test.cc | 30 +++++----- .../main/test/generic_codec_test.h | 6 +- .../main/test/jitter_buffer_test.cc | 11 ++-- .../main/test/jitter_estimate_test.cc | 1 - .../video_coding/main/test/media_opt_test.cc | 11 ++-- .../video_coding/main/test/media_opt_test.h | 4 +- .../video_coding/main/test/mt_rx_tx_test.cc | 6 +- .../video_coding/main/test/mt_test_common.cc | 10 +++- .../video_coding/main/test/mt_test_common.h | 16 +++--- .../video_coding/main/test/normal_test.cc | 28 +++++----- .../video_coding/main/test/normal_test.h | 4 +- .../main/test/quality_modes_test.cc | 15 +++-- .../main/test/quality_modes_test.h | 3 +- .../main/test/receiver_timing_tests.cc | 8 +-- .../video_coding/main/test/rtp_player.cc | 27 +++++---- .../video_coding/main/test/rtp_player.h | 12 +++- .../video_coding/main/test/test_callbacks.cc | 5 +- .../video_coding/main/test/test_callbacks.h | 4 +- .../video_coding/main/test/tester_main.cc | 10 +--- .../video_coding/main/test/video_rtp_play.cc | 19 ++++--- .../main/test/video_rtp_play_mt.cc | 14 ++--- 45 files changed, 329 insertions(+), 295 deletions(-) delete mode 100644 src/modules/video_coding/main/source/tick_time.h diff --git a/src/modules/video_coding/main/interface/video_coding.h b/src/modules/video_coding/main/interface/video_coding.h index 3afa12b66..bafe2057c 100644 --- a/src/modules/video_coding/main/interface/video_coding.h +++ b/src/modules/video_coding/main/interface/video_coding.h @@ -18,6 +18,7 @@ namespace webrtc { +class TickTimeInterface; class VideoEncoder; class VideoDecoder; struct CodecSpecificInfo; @@ -27,6 +28,9 @@ class VideoCodingModule : public Module public: static VideoCodingModule* Create(const WebRtc_Word32 id); + static VideoCodingModule* Create(const WebRtc_Word32 id, + TickTimeInterface* clock); + static void Destroy(VideoCodingModule* module); // Get number of supported codecs diff --git a/src/modules/video_coding/main/source/content_metrics_processing.cc b/src/modules/video_coding/main/source/content_metrics_processing.cc index 5206da00c..0805178c5 100644 --- a/src/modules/video_coding/main/source/content_metrics_processing.cc +++ b/src/modules/video_coding/main/source/content_metrics_processing.cc @@ -9,7 +9,6 @@ */ #include "content_metrics_processing.h" -#include "tick_time.h" #include "module_common_types.h" #include "video_coding_defines.h" diff --git a/src/modules/video_coding/main/source/generic_decoder.cc b/src/modules/video_coding/main/source/generic_decoder.cc index a0b0d1b79..78838cb3d 100644 --- a/src/modules/video_coding/main/source/generic_decoder.cc +++ b/src/modules/video_coding/main/source/generic_decoder.cc @@ -12,13 +12,15 @@ #include "trace.h" #include "generic_decoder.h" #include "internal_defines.h" -#include "tick_time.h" +#include "tick_time_interface.h" namespace webrtc { -VCMDecodedFrameCallback::VCMDecodedFrameCallback(VCMTiming& timing) +VCMDecodedFrameCallback::VCMDecodedFrameCallback(VCMTiming& timing, + TickTimeInterface* clock) : _critSect(CriticalSectionWrapper::CreateCriticalSection()), +_clock(clock), _receiveCallback(NULL), _timing(timing), _timestampMap(kDecoderFrameMemoryLength) @@ -53,7 +55,7 @@ WebRtc_Word32 VCMDecodedFrameCallback::Decoded(RawImage& decodedImage) _timing.StopDecodeTimer( decodedImage._timeStamp, frameInfo->decodeStartTimeMs, - VCMTickTime::MillisecondTimestamp()); + _clock->MillisecondTimestamp()); if (_receiveCallback != NULL) { @@ -146,7 +148,8 @@ WebRtc_Word32 VCMGenericDecoder::InitDecode(const VideoCodec* settings, return _decoder.InitDecode(settings, numberOfCores); } -WebRtc_Word32 VCMGenericDecoder::Decode(const VCMEncodedFrame& frame) +WebRtc_Word32 VCMGenericDecoder::Decode(const VCMEncodedFrame& frame, + int64_t nowMs) { if (_requireKeyFrame && !_keyFrameDecoded && @@ -157,7 +160,7 @@ WebRtc_Word32 VCMGenericDecoder::Decode(const VCMEncodedFrame& frame) // before we can decode delta frames. return VCM_CODEC_ERROR; } - _frameInfos[_nextFrameInfoIdx].decodeStartTimeMs = VCMTickTime::MillisecondTimestamp(); + _frameInfos[_nextFrameInfoIdx].decodeStartTimeMs = nowMs; _frameInfos[_nextFrameInfoIdx].renderTimeMs = frame.RenderTimeMs(); _callback->Map(frame.TimeStamp(), &_frameInfos[_nextFrameInfoIdx]); diff --git a/src/modules/video_coding/main/source/generic_decoder.h b/src/modules/video_coding/main/source/generic_decoder.h index 9dcd3246a..78cc59219 100644 --- a/src/modules/video_coding/main/source/generic_decoder.h +++ b/src/modules/video_coding/main/source/generic_decoder.h @@ -34,7 +34,7 @@ struct VCMFrameInformation class VCMDecodedFrameCallback : public DecodedImageCallback { public: - VCMDecodedFrameCallback(VCMTiming& timing); + VCMDecodedFrameCallback(VCMTiming& timing, TickTimeInterface* clock); virtual ~VCMDecodedFrameCallback(); void SetUserReceiveCallback(VCMReceiveCallback* receiveCallback); @@ -49,6 +49,7 @@ public: private: CriticalSectionWrapper* _critSect; + TickTimeInterface* _clock; VideoFrame _frame; VCMReceiveCallback* _receiveCallback; VCMTiming& _timing; @@ -76,7 +77,7 @@ public: * * inputVideoBuffer reference to encoded video frame */ - WebRtc_Word32 Decode(const VCMEncodedFrame& inputFrame); + WebRtc_Word32 Decode(const VCMEncodedFrame& inputFrame, int64_t nowMs); /** * Free the decoder memory diff --git a/src/modules/video_coding/main/source/inter_frame_delay.cc b/src/modules/video_coding/main/source/inter_frame_delay.cc index f3bc0134b..3b520b371 100644 --- a/src/modules/video_coding/main/source/inter_frame_delay.cc +++ b/src/modules/video_coding/main/source/inter_frame_delay.cc @@ -9,20 +9,19 @@ */ #include "inter_frame_delay.h" -#include "tick_time.h" namespace webrtc { -VCMInterFrameDelay::VCMInterFrameDelay() +VCMInterFrameDelay::VCMInterFrameDelay(int64_t currentWallClock) { - Reset(); + Reset(currentWallClock); } // Resets the delay estimate void -VCMInterFrameDelay::Reset() +VCMInterFrameDelay::Reset(int64_t currentWallClock) { - _zeroWallClock = VCMTickTime::MillisecondTimestamp(); + _zeroWallClock = currentWallClock; _wrapArounds = 0; _prevWallClock = 0; _prevTimestamp = 0; @@ -34,13 +33,8 @@ VCMInterFrameDelay::Reset() bool VCMInterFrameDelay::CalculateDelay(WebRtc_UWord32 timestamp, WebRtc_Word64 *delay, - WebRtc_Word64 currentWallClock /* = -1 */) + int64_t currentWallClock) { - if (currentWallClock <= -1) - { - currentWallClock = VCMTickTime::MillisecondTimestamp(); - } - if (_prevWallClock == 0) { // First set of data, initialization, wait for next frame diff --git a/src/modules/video_coding/main/source/inter_frame_delay.h b/src/modules/video_coding/main/source/inter_frame_delay.h index 7a976a4f0..807c64b2c 100644 --- a/src/modules/video_coding/main/source/inter_frame_delay.h +++ b/src/modules/video_coding/main/source/inter_frame_delay.h @@ -19,10 +19,10 @@ namespace webrtc class VCMInterFrameDelay { public: - VCMInterFrameDelay(); + VCMInterFrameDelay(int64_t currentWallClock); // Resets the estimate. Zeros are given as parameters. - void Reset(); + void Reset(int64_t currentWallClock); // Calculates the delay of a frame with the given timestamp. // This method is called when the frame is complete. @@ -35,7 +35,7 @@ public: // Return value : true if OK, false when reordered timestamps bool CalculateDelay(WebRtc_UWord32 timestamp, WebRtc_Word64 *delay, - WebRtc_Word64 currentWallClock = -1); + int64_t currentWallClock); // Returns the current difference between incoming timestamps // diff --git a/src/modules/video_coding/main/source/jitter_buffer.cc b/src/modules/video_coding/main/source/jitter_buffer.cc index 8878bb7d8..6bdbc5201 100644 --- a/src/modules/video_coding/main/source/jitter_buffer.cc +++ b/src/modules/video_coding/main/source/jitter_buffer.cc @@ -20,7 +20,7 @@ #include "event.h" #include "trace.h" -#include "tick_time.h" +#include "modules/video_coding/main/source/tick_time_interface.h" #include "list_wrapper.h" #include @@ -57,10 +57,13 @@ VCMJitterBuffer::CompleteDecodableKeyFrameCriteria(VCMFrameBuffer* frame, } // Constructor -VCMJitterBuffer::VCMJitterBuffer(WebRtc_Word32 vcmId, WebRtc_Word32 receiverId, +VCMJitterBuffer::VCMJitterBuffer(TickTimeInterface* clock, + WebRtc_Word32 vcmId, + WebRtc_Word32 receiverId, bool master) : _vcmId(vcmId), _receiverId(receiverId), + _clock(clock), _running(false), _critSect(CriticalSectionWrapper::CreateCriticalSection()), _master(master), @@ -81,6 +84,7 @@ VCMJitterBuffer::VCMJitterBuffer(WebRtc_Word32 vcmId, WebRtc_Word32 receiverId, _numConsecutiveOldPackets(0), _discardedPackets(0), _jitterEstimate(vcmId, receiverId), + _delayEstimate(_clock->MillisecondTimestamp()), _rttMs(0), _nackMode(kNoNack), _lowRttNackThresholdMs(-1), @@ -180,7 +184,7 @@ VCMJitterBuffer::Start() _incomingFrameCount = 0; _incomingFrameRate = 0; _incomingBitCount = 0; - _timeLastIncomingFrameCount = VCMTickTime::MillisecondTimestamp(); + _timeLastIncomingFrameCount = _clock->MillisecondTimestamp(); memset(_receiveStatistics, 0, sizeof(_receiveStatistics)); _numConsecutiveOldFrames = 0; @@ -262,7 +266,7 @@ VCMJitterBuffer::FlushInternal() // Also reset the jitter and delay estimates _jitterEstimate.Reset(); - _delayEstimate.Reset(); + _delayEstimate.Reset(_clock->MillisecondTimestamp()); _waitingForCompletion.frameSize = 0; _waitingForCompletion.timestamp = 0; @@ -602,7 +606,7 @@ WebRtc_Word32 VCMJitterBuffer::GetUpdate(WebRtc_UWord32& frameRate, WebRtc_UWord32& bitRate) { CriticalSectionScoped cs(_critSect); - const WebRtc_Word64 now = VCMTickTime::MillisecondTimestamp(); + const WebRtc_Word64 now = _clock->MillisecondTimestamp(); WebRtc_Word64 diff = now - _timeLastIncomingFrameCount; if (diff < 1000 && _incomingFrameRate > 0 && _incomingBitRate > 0) { @@ -657,7 +661,7 @@ VCMJitterBuffer::GetUpdate(WebRtc_UWord32& frameRate, WebRtc_UWord32& bitRate) else { // No frames since last call - _timeLastIncomingFrameCount = VCMTickTime::MillisecondTimestamp(); + _timeLastIncomingFrameCount = _clock->MillisecondTimestamp(); frameRate = 0; bitRate = 0; _incomingBitRate = 0; @@ -698,7 +702,7 @@ VCMJitterBuffer::GetCompleteFrameForDecoding(WebRtc_UWord32 maxWaitTimeMS) _critSect->Leave(); return NULL; } - const WebRtc_Word64 endWaitTimeMs = VCMTickTime::MillisecondTimestamp() + const WebRtc_Word64 endWaitTimeMs = _clock->MillisecondTimestamp() + maxWaitTimeMS; WebRtc_Word64 waitTimeMs = maxWaitTimeMS; while (waitTimeMs > 0) @@ -727,7 +731,7 @@ VCMJitterBuffer::GetCompleteFrameForDecoding(WebRtc_UWord32 maxWaitTimeMS) if (oldestFrame == NULL) { waitTimeMs = endWaitTimeMs - - VCMTickTime::MillisecondTimestamp(); + _clock->MillisecondTimestamp(); } else { @@ -1514,7 +1518,7 @@ VCMFrameBufferEnum VCMJitterBuffer::InsertPacket(VCMEncodedFrame* buffer, const VCMPacket& packet) { CriticalSectionScoped cs(_critSect); - WebRtc_Word64 nowMs = VCMTickTime::MillisecondTimestamp(); + WebRtc_Word64 nowMs = _clock->MillisecondTimestamp(); VCMFrameBufferEnum bufferReturn = kSizeError; VCMFrameBufferEnum ret = kSizeError; VCMFrameBuffer* frame = static_cast(buffer); @@ -1525,7 +1529,7 @@ VCMJitterBuffer::InsertPacket(VCMEncodedFrame* buffer, const VCMPacket& packet) { // Now it's time to start estimating jitter // reset the delay estimate. - _delayEstimate.Reset(); + _delayEstimate.Reset(_clock->MillisecondTimestamp()); _firstPacket = false; } diff --git a/src/modules/video_coding/main/source/jitter_buffer.h b/src/modules/video_coding/main/source/jitter_buffer.h index 0a2d7065f..6646a195e 100644 --- a/src/modules/video_coding/main/source/jitter_buffer.h +++ b/src/modules/video_coding/main/source/jitter_buffer.h @@ -33,6 +33,7 @@ enum VCMNackMode }; // forward declarations +class TickTimeInterface; class VCMFrameBuffer; class VCMPacket; class VCMEncodedFrame; @@ -49,7 +50,8 @@ public: class VCMJitterBuffer { public: - VCMJitterBuffer(WebRtc_Word32 vcmId = -1, + VCMJitterBuffer(TickTimeInterface* clock, + WebRtc_Word32 vcmId = -1, WebRtc_Word32 receiverId = -1, bool master = true); virtual ~VCMJitterBuffer(); @@ -191,6 +193,7 @@ private: WebRtc_Word32 _vcmId; WebRtc_Word32 _receiverId; + TickTimeInterface* _clock; // If we are running (have started) or not bool _running; CriticalSectionWrapper* _critSect; diff --git a/src/modules/video_coding/main/source/jitter_estimator.cc b/src/modules/video_coding/main/source/jitter_estimator.cc index 233fad4cd..93c6ccb8f 100644 --- a/src/modules/video_coding/main/source/jitter_estimator.cc +++ b/src/modules/video_coding/main/source/jitter_estimator.cc @@ -12,8 +12,8 @@ #include "internal_defines.h" #include "jitter_estimator.h" #include "rtt_filter.h" -#include "tick_time.h" +#include #include #include #include diff --git a/src/modules/video_coding/main/source/media_opt_util.cc b/src/modules/video_coding/main/source/media_opt_util.cc index 22d2f9c6e..c83c19979 100644 --- a/src/modules/video_coding/main/source/media_opt_util.cc +++ b/src/modules/video_coding/main/source/media_opt_util.cc @@ -551,7 +551,7 @@ VCMFecMethod::UpdateParameters(const VCMProtectionParameters* parameters) return true; } -VCMLossProtectionLogic::VCMLossProtectionLogic(): +VCMLossProtectionLogic::VCMLossProtectionLogic(int64_t nowMs): _selectedMethod(NULL), _currentParameters(), _rtt(0), @@ -572,7 +572,7 @@ _boostRateKey(2), _codecWidth(0), _codecHeight(0) { - Reset(); + Reset(nowMs); } VCMLossProtectionLogic::~VCMLossProtectionLogic() @@ -661,13 +661,13 @@ VCMLossProtectionLogic::UpdateResidualPacketLoss(float residualPacketLoss) } void -VCMLossProtectionLogic::UpdateLossPr(WebRtc_UWord8 lossPr255) +VCMLossProtectionLogic::UpdateLossPr(WebRtc_UWord8 lossPr255, + int64_t nowMs) { - const WebRtc_Word64 now = VCMTickTime::MillisecondTimestamp(); - UpdateMaxLossHistory(lossPr255, now); - _lossPr255.Apply(static_cast (now - _lastPrUpdateT), + UpdateMaxLossHistory(lossPr255, nowMs); + _lossPr255.Apply(static_cast (nowMs - _lastPrUpdateT), static_cast (lossPr255)); - _lastPrUpdateT = now; + _lastPrUpdateT = nowMs; _lossPr = _lossPr255.Value() / 255.0f; } @@ -741,14 +741,14 @@ VCMLossProtectionLogic::MaxFilteredLossPr(WebRtc_Word64 nowMs) const } WebRtc_UWord8 -VCMLossProtectionLogic::FilteredLoss() const +VCMLossProtectionLogic::FilteredLoss(int64_t nowMs) const { if (_selectedMethod != NULL && (_selectedMethod->Type() == kFec || _selectedMethod->Type() == kNackFec)) { // Take the windowed max of the received loss. - return MaxFilteredLossPr(VCMTickTime::MillisecondTimestamp()); + return MaxFilteredLossPr(nowMs); } else { @@ -770,21 +770,19 @@ VCMLossProtectionLogic::UpdateBitRate(float bitRate) } void -VCMLossProtectionLogic::UpdatePacketsPerFrame(float nPackets) +VCMLossProtectionLogic::UpdatePacketsPerFrame(float nPackets, int64_t nowMs) { - const WebRtc_Word64 now = VCMTickTime::MillisecondTimestamp(); - _packetsPerFrame.Apply(static_cast(now - _lastPacketPerFrameUpdateT), + _packetsPerFrame.Apply(static_cast(nowMs - _lastPacketPerFrameUpdateT), nPackets); - _lastPacketPerFrameUpdateT = now; + _lastPacketPerFrameUpdateT = nowMs; } void -VCMLossProtectionLogic::UpdatePacketsPerFrameKey(float nPackets) +VCMLossProtectionLogic::UpdatePacketsPerFrameKey(float nPackets, int64_t nowMs) { - const WebRtc_Word64 now = VCMTickTime::MillisecondTimestamp(); - _packetsPerFrameKey.Apply(static_cast(now - + _packetsPerFrameKey.Apply(static_cast(nowMs - _lastPacketPerFrameUpdateTKey), nPackets); - _lastPacketPerFrameUpdateTKey = now; + _lastPacketPerFrameUpdateTKey = nowMs; } void @@ -836,12 +834,11 @@ VCMLossProtectionLogic::SelectedType() const } void -VCMLossProtectionLogic::Reset() +VCMLossProtectionLogic::Reset(int64_t nowMs) { - const WebRtc_Word64 now = VCMTickTime::MillisecondTimestamp(); - _lastPrUpdateT = now; - _lastPacketPerFrameUpdateT = now; - _lastPacketPerFrameUpdateTKey = now; + _lastPrUpdateT = nowMs; + _lastPacketPerFrameUpdateT = nowMs; + _lastPacketPerFrameUpdateTKey = nowMs; _lossPr255.Reset(0.9999f); _packetsPerFrame.Reset(0.9999f); _fecRateDelta = _fecRateKey = 0; diff --git a/src/modules/video_coding/main/source/media_opt_util.h b/src/modules/video_coding/main/source/media_opt_util.h index c6566fb6a..33d42df92 100644 --- a/src/modules/video_coding/main/source/media_opt_util.h +++ b/src/modules/video_coding/main/source/media_opt_util.h @@ -15,7 +15,6 @@ #include "trace.h" #include "exp_filter.h" #include "internal_defines.h" -#include "tick_time.h" #include "qm_select.h" #include @@ -212,7 +211,7 @@ private: class VCMLossProtectionLogic { public: - VCMLossProtectionLogic(); + VCMLossProtectionLogic(int64_t nowMs); ~VCMLossProtectionLogic(); // Set the protection method to be used @@ -251,7 +250,7 @@ public: // Input: // - lossPr255 : The packet loss probability [0, 255], // reported by RTCP. - void UpdateLossPr(WebRtc_UWord8 lossPr255); + void UpdateLossPr(WebRtc_UWord8 lossPr255, int64_t nowMs); // Update the filtered packet loss. // @@ -270,13 +269,13 @@ public: // // Input: // - nPackets : Number of packets in the latest sent frame. - void UpdatePacketsPerFrame(float nPackets); + void UpdatePacketsPerFrame(float nPackets, int64_t nowMs); // Update the number of packets per frame estimate, for key frames // // Input: // - nPackets : umber of packets in the latest sent frame. - void UpdatePacketsPerFrameKey(float nPackets); + void UpdatePacketsPerFrameKey(float nPackets, int64_t nowMs); // Update the keyFrameSize estimate // @@ -324,9 +323,9 @@ public: // Returns the filtered loss probability in the interval [0, 255]. // // Return value : The filtered loss probability - WebRtc_UWord8 FilteredLoss() const; + WebRtc_UWord8 FilteredLoss(int64_t nowMs) const; - void Reset(); + void Reset(int64_t nowMs); void Release(); diff --git a/src/modules/video_coding/main/source/media_optimization.cc b/src/modules/video_coding/main/source/media_optimization.cc index b6f172ca9..76d7a354b 100644 --- a/src/modules/video_coding/main/source/media_optimization.cc +++ b/src/modules/video_coding/main/source/media_optimization.cc @@ -12,11 +12,14 @@ #include "content_metrics_processing.h" #include "frame_dropper.h" #include "qm_select.h" +#include "modules/video_coding/main/source/tick_time_interface.h" namespace webrtc { -VCMMediaOptimization::VCMMediaOptimization(WebRtc_Word32 id): +VCMMediaOptimization::VCMMediaOptimization(WebRtc_Word32 id, + TickTimeInterface* clock): _id(id), +_clock(clock), _maxBitRate(0), _sendCodecType(kVideoCodecUnknown), _codecWidth(0), @@ -42,7 +45,7 @@ _lastChangeTime(0) memset(_incomingFrameTimes, -1, sizeof(_incomingFrameTimes)); _frameDropper = new VCMFrameDropper(_id); - _lossProtLogic = new VCMLossProtectionLogic(); + _lossProtLogic = new VCMLossProtectionLogic(_clock->MillisecondTimestamp()); _content = new VCMContentMetricsProcessing(); _qmResolution = new VCMQmResolution(); } @@ -62,12 +65,12 @@ VCMMediaOptimization::Reset() memset(_incomingFrameTimes, -1, sizeof(_incomingFrameTimes)); InputFrameRate(); // Resets _incomingFrameRate _frameDropper->Reset(); - _lossProtLogic->Reset(); + _lossProtLogic->Reset(_clock->MillisecondTimestamp()); _frameDropper->SetRates(0, 0); _content->Reset(); _qmResolution->Reset(); _lossProtLogic->UpdateFrameRate(_incomingFrameRate); - _lossProtLogic->Reset(); + _lossProtLogic->Reset(_clock->MillisecondTimestamp()); _sendStatisticsZeroEncode = 0; _targetBitRate = 0; _codecWidth = 0; @@ -93,7 +96,7 @@ VCMMediaOptimization::SetTargetRates(WebRtc_UWord32 bitRate, { VCMProtectionMethod *selectedMethod = _lossProtLogic->SelectedMethod(); _lossProtLogic->UpdateBitRate(static_cast(bitRate)); - _lossProtLogic->UpdateLossPr(fractionLost); + _lossProtLogic->UpdateLossPr(fractionLost, _clock->MillisecondTimestamp()); _lossProtLogic->UpdateRtt(roundTripTimeMs); _lossProtLogic->UpdateResidualPacketLoss(static_cast(fractionLost)); @@ -116,7 +119,8 @@ VCMMediaOptimization::SetTargetRates(WebRtc_UWord32 bitRate, // average or max filter may be used. // We should think about which filter is appropriate for low/high bit rates, // low/high loss rates, etc. - WebRtc_UWord8 packetLossEnc = _lossProtLogic->FilteredLoss(); + WebRtc_UWord8 packetLossEnc = _lossProtLogic->FilteredLoss( + _clock->MillisecondTimestamp()); // For now use the filtered loss for computing the robustness settings _lossProtLogic->UpdateFilteredLossPr(packetLossEnc); @@ -253,7 +257,7 @@ VCMMediaOptimization::SetEncodingData(VideoCodecType sendCodecType, WebRtc_Word3 // has changed. If native dimension values have changed, then either user // initiated change, or QM initiated change. Will be able to determine only // after the processing of the first frame. - _lastChangeTime = VCMTickTime::MillisecondTimestamp(); + _lastChangeTime = _clock->MillisecondTimestamp(); _content->Reset(); _content->UpdateFrameRate(frameRate); @@ -336,7 +340,7 @@ VCMMediaOptimization::SentFrameRate() float VCMMediaOptimization::SentBitRate() { - UpdateBitRateEstimate(-1, VCMTickTime::MillisecondTimestamp()); + UpdateBitRateEstimate(-1, _clock->MillisecondTimestamp()); return _avgSentBitRateBps / 1000.0f; } @@ -351,7 +355,7 @@ VCMMediaOptimization::UpdateWithEncodedData(WebRtc_Word32 encodedLength, FrameType encodedFrameType) { // look into the ViE version - debug mode - needs also number of layers. - UpdateBitRateEstimate(encodedLength, VCMTickTime::MillisecondTimestamp()); + UpdateBitRateEstimate(encodedLength, _clock->MillisecondTimestamp()); if(encodedLength > 0) { const bool deltaFrame = (encodedFrameType != kVideoFrameKey && @@ -364,11 +368,13 @@ VCMMediaOptimization::UpdateWithEncodedData(WebRtc_Word32 encodedLength, static_cast(_maxPayloadSize); if (deltaFrame) { - _lossProtLogic->UpdatePacketsPerFrame(minPacketsPerFrame); + _lossProtLogic->UpdatePacketsPerFrame( + minPacketsPerFrame, _clock->MillisecondTimestamp()); } else { - _lossProtLogic->UpdatePacketsPerFrameKey(minPacketsPerFrame); + _lossProtLogic->UpdatePacketsPerFrameKey( + minPacketsPerFrame, _clock->MillisecondTimestamp()); } if (_enableQm) @@ -519,7 +525,7 @@ VCMMediaOptimization::SelectQuality() _qmResolution->ResetRates(); // Reset counters - _lastQMUpdateTime = VCMTickTime::MillisecondTimestamp(); + _lastQMUpdateTime = _clock->MillisecondTimestamp(); // Reset content metrics _content->Reset(); @@ -542,7 +548,7 @@ VCMMediaOptimization::checkStatusForQMchange() // (to sample the metrics) from the event lastChangeTime // lastChangeTime is the time where user changed the size/rate/frame rate // (via SetEncodingData) - WebRtc_Word64 now = VCMTickTime::MillisecondTimestamp(); + WebRtc_Word64 now = _clock->MillisecondTimestamp(); if ((now - _lastQMUpdateTime) < kQmMinIntervalMs || (now - _lastChangeTime) < kQmMinIntervalMs) { @@ -612,7 +618,7 @@ VCMMediaOptimization::QMUpdate(VCMResolutionScale* qm) void VCMMediaOptimization::UpdateIncomingFrameRate() { - WebRtc_Word64 now = VCMTickTime::MillisecondTimestamp(); + WebRtc_Word64 now = _clock->MillisecondTimestamp(); if (_incomingFrameTimes[0] == 0) { // first no shift @@ -664,7 +670,7 @@ VCMMediaOptimization::ProcessIncomingFrameRate(WebRtc_Word64 now) WebRtc_UWord32 VCMMediaOptimization::InputFrameRate() { - ProcessIncomingFrameRate(VCMTickTime::MillisecondTimestamp()); + ProcessIncomingFrameRate(_clock->MillisecondTimestamp()); return WebRtc_UWord32 (_incomingFrameRate + 0.5f); } diff --git a/src/modules/video_coding/main/source/media_optimization.h b/src/modules/video_coding/main/source/media_optimization.h index b02a6bb03..0ceb01dac 100644 --- a/src/modules/video_coding/main/source/media_optimization.h +++ b/src/modules/video_coding/main/source/media_optimization.h @@ -24,6 +24,7 @@ namespace webrtc enum { kBitrateMaxFrameSamples = 60 }; enum { kBitrateAverageWinMs = 1000 }; +class TickTimeInterface; class VCMContentMetricsProcessing; class VCMFrameDropper; @@ -38,7 +39,7 @@ struct VCMEncodedFrameSample class VCMMediaOptimization { public: - VCMMediaOptimization(WebRtc_Word32 id); + VCMMediaOptimization(WebRtc_Word32 id, TickTimeInterface* clock); ~VCMMediaOptimization(void); /* * Reset the Media Optimization module @@ -162,7 +163,7 @@ private: enum { kFrameHistoryWinMs = 2000}; WebRtc_Word32 _id; - + TickTimeInterface* _clock; WebRtc_Word32 _maxBitRate; VideoCodecType _sendCodecType; WebRtc_UWord16 _codecWidth; diff --git a/src/modules/video_coding/main/source/receiver.cc b/src/modules/video_coding/main/source/receiver.cc index 11de30835..c503f98df 100644 --- a/src/modules/video_coding/main/source/receiver.cc +++ b/src/modules/video_coding/main/source/receiver.cc @@ -13,7 +13,7 @@ #include "encoded_frame.h" #include "internal_defines.h" #include "media_opt_util.h" -#include "tick_time.h" +#include "tick_time_interface.h" #include "trace.h" #include "video_coding.h" @@ -22,15 +22,17 @@ namespace webrtc { VCMReceiver::VCMReceiver(VCMTiming& timing, + TickTimeInterface* clock, WebRtc_Word32 vcmId, WebRtc_Word32 receiverId, bool master) : _critSect(CriticalSectionWrapper::CreateCriticalSection()), _vcmId(vcmId), +_clock(clock), _receiverId(receiverId), _master(master), -_jitterBuffer(vcmId, receiverId, master), +_jitterBuffer(_clock, vcmId, receiverId, master), _timing(timing), _renderWaitEvent(*new VCMEvent()), _state(kPassive) @@ -118,10 +120,10 @@ VCMReceiver::InsertPacket(const VCMPacket& packet, VCMId(_vcmId, _receiverId), "Packet seqNo %u of frame %u at %u", packet.seqNum, packet.timestamp, - MaskWord64ToUWord32(VCMTickTime::MillisecondTimestamp())); + MaskWord64ToUWord32(_clock->MillisecondTimestamp())); } - const WebRtc_Word64 nowMs = VCMTickTime::MillisecondTimestamp(); + const WebRtc_Word64 nowMs = _clock->MillisecondTimestamp(); WebRtc_Word64 renderTimeMs = _timing.RenderTimeMs(packet.timestamp, nowMs); @@ -130,7 +132,7 @@ VCMReceiver::InsertPacket(const VCMPacket& packet, // Render time error. Assume that this is due to some change in // the incoming video stream and reset the JB and the timing. _jitterBuffer.Flush(); - _timing.Reset(); + _timing.Reset(_clock->MillisecondTimestamp()); return VCM_FLUSH_INDICATOR; } else if (renderTimeMs < nowMs - kMaxVideoDelayMs) @@ -139,7 +141,7 @@ VCMReceiver::InsertPacket(const VCMPacket& packet, "This frame should have been rendered more than %u ms ago." "Flushing jitter buffer and resetting timing.", kMaxVideoDelayMs); _jitterBuffer.Flush(); - _timing.Reset(); + _timing.Reset(_clock->MillisecondTimestamp()); return VCM_FLUSH_INDICATOR; } else if (_timing.TargetVideoDelay() > kMaxVideoDelayMs) @@ -148,14 +150,14 @@ VCMReceiver::InsertPacket(const VCMPacket& packet, "More than %u ms target delay. Flushing jitter buffer and resetting timing.", kMaxVideoDelayMs); _jitterBuffer.Flush(); - _timing.Reset(); + _timing.Reset(_clock->MillisecondTimestamp()); return VCM_FLUSH_INDICATOR; } // First packet received belonging to this frame. if (buffer->Length() == 0) { - const WebRtc_Word64 nowMs = VCMTickTime::MillisecondTimestamp(); + const WebRtc_Word64 nowMs = _clock->MillisecondTimestamp(); if (_master) { // Only trace the primary receiver to make it possible to parse and plot the trace file. @@ -199,7 +201,7 @@ VCMReceiver::FrameForDecoding(WebRtc_UWord16 maxWaitTimeMs, WebRtc_Word64& nextR // is thread-safe. FrameType incomingFrameType = kVideoFrameDelta; nextRenderTimeMs = -1; - const WebRtc_Word64 startTimeMs = VCMTickTime::MillisecondTimestamp(); + const WebRtc_Word64 startTimeMs = _clock->MillisecondTimestamp(); WebRtc_Word64 ret = _jitterBuffer.GetNextTimeStamp(maxWaitTimeMs, incomingFrameType, nextRenderTimeMs); @@ -215,7 +217,7 @@ VCMReceiver::FrameForDecoding(WebRtc_UWord16 maxWaitTimeMs, WebRtc_Word64& nextR _timing.UpdateCurrentDelay(timeStamp); const WebRtc_Word32 tempWaitTime = maxWaitTimeMs - - static_cast(VCMTickTime::MillisecondTimestamp() - startTimeMs); + static_cast(_clock->MillisecondTimestamp() - startTimeMs); WebRtc_UWord16 newMaxWaitTime = static_cast(VCM_MAX(tempWaitTime, 0)); VCMEncodedFrame* frame = NULL; @@ -256,7 +258,7 @@ VCMReceiver::FrameForDecoding(WebRtc_UWord16 maxWaitTimeMs, { // How long can we wait until we must decode the next frame WebRtc_UWord32 waitTimeMs = _timing.MaxWaitingTime(nextRenderTimeMs, - VCMTickTime::MillisecondTimestamp()); + _clock->MillisecondTimestamp()); // Try to get a complete frame from the jitter buffer VCMEncodedFrame* frame = _jitterBuffer.GetCompleteFrameForDecoding(0); @@ -284,7 +286,7 @@ VCMReceiver::FrameForDecoding(WebRtc_UWord16 maxWaitTimeMs, { // Get an incomplete frame if (_timing.MaxWaitingTime(nextRenderTimeMs, - VCMTickTime::MillisecondTimestamp()) > 0) + _clock->MillisecondTimestamp()) > 0) { // Still time to wait for a complete frame return NULL; @@ -316,7 +318,7 @@ VCMReceiver::FrameForRendering(WebRtc_UWord16 maxWaitTimeMs, // as possible before giving the frame to the decoder, which will render the frame as soon // as it has been decoded. WebRtc_UWord32 waitTimeMs = _timing.MaxWaitingTime(nextRenderTimeMs, - VCMTickTime::MillisecondTimestamp()); + _clock->MillisecondTimestamp()); if (maxWaitTimeMs < waitTimeMs) { // If we're not allowed to wait until the frame is supposed to be rendered diff --git a/src/modules/video_coding/main/source/receiver.h b/src/modules/video_coding/main/source/receiver.h index b1f3cbd1a..5c377fd72 100644 --- a/src/modules/video_coding/main/source/receiver.h +++ b/src/modules/video_coding/main/source/receiver.h @@ -13,6 +13,7 @@ #include "critical_section_wrapper.h" #include "jitter_buffer.h" +#include "modules/video_coding/main/source/tick_time_interface.h" #include "timing.h" #include "packet.h" @@ -40,6 +41,7 @@ class VCMReceiver { public: VCMReceiver(VCMTiming& timing, + TickTimeInterface* clock, WebRtc_Word32 vcmId = -1, WebRtc_Word32 receiverId = -1, bool master = true); @@ -83,6 +85,7 @@ private: CriticalSectionWrapper* _critSect; WebRtc_Word32 _vcmId; + TickTimeInterface* _clock; WebRtc_Word32 _receiverId; bool _master; VCMJitterBuffer _jitterBuffer; diff --git a/src/modules/video_coding/main/source/tick_time.h b/src/modules/video_coding/main/source/tick_time.h deleted file mode 100644 index 47ac9f412..000000000 --- a/src/modules/video_coding/main/source/tick_time.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef WEBRTC_MODULES_VIDEO_CODING_TICK_TIME_H_ -#define WEBRTC_MODULES_VIDEO_CODING_TICK_TIME_H_ - -#include "tick_util.h" - -#include - -namespace webrtc -{ - -//#define TICK_TIME_DEBUG - -class VCMTickTime : public TickTime -{ -#ifdef TICK_TIME_DEBUG -public: - /* - * Get current time - */ - static TickTime Now() { assert(false); }; - - /* - * Get time in milli seconds - */ - static WebRtc_Word64 MillisecondTimestamp() { return _timeNowDebug; }; - - /* - * Get time in micro seconds - */ - static WebRtc_Word64 MicrosecondTimestamp() { return _timeNowDebug * 1000LL; }; - - static void IncrementDebugClock() { _timeNowDebug++; }; - -private: - static WebRtc_Word64 _timeNowDebug; - -#else -public: - static void IncrementDebugClock() { assert(false); }; -#endif -}; - -} // namespace webrtc - -#endif // WEBRTC_MODULES_VIDEO_CODING_TICK_TIME_H_ diff --git a/src/modules/video_coding/main/source/timestamp_extrapolator.cc b/src/modules/video_coding/main/source/timestamp_extrapolator.cc index 17a5dbbf8..2ee0775e4 100644 --- a/src/modules/video_coding/main/source/timestamp_extrapolator.cc +++ b/src/modules/video_coding/main/source/timestamp_extrapolator.cc @@ -9,17 +9,20 @@ */ #include "internal_defines.h" +#include "modules/video_coding/main/source/tick_time_interface.h" #include "timestamp_extrapolator.h" -#include "tick_time.h" #include "trace.h" namespace webrtc { -VCMTimestampExtrapolator::VCMTimestampExtrapolator(WebRtc_Word32 vcmId, WebRtc_Word32 id) +VCMTimestampExtrapolator::VCMTimestampExtrapolator(TickTimeInterface* clock, + WebRtc_Word32 vcmId, + WebRtc_Word32 id) : _rwLock(RWLockWrapper::CreateRWLock()), _vcmId(vcmId), _id(id), +_clock(clock), _startMs(0), _firstTimestamp(0), _wrapArounds(0), @@ -35,7 +38,7 @@ _accDrift(6600), // in timestamp ticks, i.e. 15 ms _accMaxError(7000), _P11(1e10) { - Reset(VCMTickTime::MillisecondTimestamp()); + Reset(_clock->MillisecondTimestamp()); } VCMTimestampExtrapolator::~VCMTimestampExtrapolator() @@ -53,7 +56,7 @@ VCMTimestampExtrapolator::Reset(const WebRtc_Word64 nowMs /* = -1 */) } else { - _startMs = VCMTickTime::MillisecondTimestamp(); + _startMs = _clock->MillisecondTimestamp(); } _prevMs = _startMs; _firstTimestamp = 0; diff --git a/src/modules/video_coding/main/source/timestamp_extrapolator.h b/src/modules/video_coding/main/source/timestamp_extrapolator.h index 6c2b3b9be..1377066dd 100644 --- a/src/modules/video_coding/main/source/timestamp_extrapolator.h +++ b/src/modules/video_coding/main/source/timestamp_extrapolator.h @@ -17,10 +17,14 @@ namespace webrtc { +class TickTimeInterface; + class VCMTimestampExtrapolator { public: - VCMTimestampExtrapolator(WebRtc_Word32 vcmId = 0, WebRtc_Word32 receiverId = 0); + VCMTimestampExtrapolator(TickTimeInterface* clock, + WebRtc_Word32 vcmId = 0, + WebRtc_Word32 receiverId = 0); ~VCMTimestampExtrapolator(); void Update(WebRtc_Word64 tMs, WebRtc_UWord32 ts90khz, bool trace = true); WebRtc_UWord32 ExtrapolateTimestamp(WebRtc_Word64 tMs) const; @@ -33,6 +37,7 @@ private: RWLockWrapper* _rwLock; WebRtc_Word32 _vcmId; WebRtc_Word32 _id; + TickTimeInterface* _clock; bool _trace; double _w[2]; double _P[2][2]; diff --git a/src/modules/video_coding/main/source/timing.cc b/src/modules/video_coding/main/source/timing.cc index ca820ba66..0d7c08efa 100644 --- a/src/modules/video_coding/main/source/timing.cc +++ b/src/modules/video_coding/main/source/timing.cc @@ -16,10 +16,14 @@ namespace webrtc { -VCMTiming::VCMTiming(WebRtc_Word32 vcmId, WebRtc_Word32 timingId, VCMTiming* masterTiming) +VCMTiming::VCMTiming(TickTimeInterface* clock, + WebRtc_Word32 vcmId, + WebRtc_Word32 timingId, + VCMTiming* masterTiming) : _critSect(CriticalSectionWrapper::CreateCriticalSection()), _vcmId(vcmId), +_clock(clock), _timingId(timingId), _master(false), _tsExtrapolator(), @@ -33,7 +37,7 @@ _prevFrameTimestamp(0) if (masterTiming == NULL) { _master = true; - _tsExtrapolator = new VCMTimestampExtrapolator(vcmId, timingId); + _tsExtrapolator = new VCMTimestampExtrapolator(_clock, vcmId, timingId); } else { diff --git a/src/modules/video_coding/main/source/timing.h b/src/modules/video_coding/main/source/timing.h index a82deb540..3de5e9beb 100644 --- a/src/modules/video_coding/main/source/timing.h +++ b/src/modules/video_coding/main/source/timing.h @@ -18,6 +18,7 @@ namespace webrtc { +class TickTimeInterface; class VCMTimestampExtrapolator; class VCMTiming @@ -25,7 +26,8 @@ class VCMTiming public: // The primary timing component should be passed // if this is the dual timing component. - VCMTiming(WebRtc_Word32 vcmId = 0, + VCMTiming(TickTimeInterface* clock, + WebRtc_Word32 vcmId = 0, WebRtc_Word32 timingId = 0, VCMTiming* masterTiming = NULL); ~VCMTiming(); @@ -92,6 +94,7 @@ protected: private: CriticalSectionWrapper* _critSect; WebRtc_Word32 _vcmId; + TickTimeInterface* _clock; WebRtc_Word32 _timingId; bool _master; VCMTimestampExtrapolator* _tsExtrapolator; diff --git a/src/modules/video_coding/main/source/video_coding.gypi b/src/modules/video_coding/main/source/video_coding.gypi index 21598965d..f51667d96 100644 --- a/src/modules/video_coding/main/source/video_coding.gypi +++ b/src/modules/video_coding/main/source/video_coding.gypi @@ -63,7 +63,6 @@ 'receiver.h', 'rtt_filter.h', 'session_info.h', - 'tick_time.h', 'tick_time_interface.h', 'timestamp_extrapolator.h', 'timestamp_map.h', diff --git a/src/modules/video_coding/main/source/video_coding_impl.cc b/src/modules/video_coding/main/source/video_coding_impl.cc index 036478ca6..6a9fdea32 100644 --- a/src/modules/video_coding/main/source/video_coding_impl.cc +++ b/src/modules/video_coding/main/source/video_coding_impl.cc @@ -15,6 +15,7 @@ #include "packet.h" #include "trace.h" #include "video_codec_interface.h" +#include "modules/video_coding/main/source/tick_time_interface.h" namespace webrtc { @@ -33,26 +34,30 @@ VCMProcessTimer::TimeUntilProcess() const { return static_cast( VCM_MAX(static_cast(_periodMs) - - (VCMTickTime::MillisecondTimestamp() - _latestMs), 0)); + (_clock->MillisecondTimestamp() - _latestMs), 0)); } void VCMProcessTimer::Processed() { - _latestMs = VCMTickTime::MillisecondTimestamp(); + _latestMs = _clock->MillisecondTimestamp(); } -VideoCodingModuleImpl::VideoCodingModuleImpl(const WebRtc_Word32 id) +VideoCodingModuleImpl::VideoCodingModuleImpl(const WebRtc_Word32 id, + TickTimeInterface* clock, + bool delete_clock_on_destroy) : _id(id), +clock_(clock), +delete_clock_on_destroy_(delete_clock_on_destroy), _receiveCritSect(CriticalSectionWrapper::CreateCriticalSection()), _receiverInited(false), -_timing(id, 1), -_dualTiming(id, 2, &_timing), -_receiver(_timing, id, 1), -_dualReceiver(_dualTiming, id, 2, false), -_decodedFrameCallback(_timing), -_dualDecodedFrameCallback(_dualTiming), +_timing(clock_, id, 1), +_dualTiming(clock_, id, 2, &_timing), +_receiver(_timing, clock_, id, 1), +_dualReceiver(_dualTiming, clock_, id, 2, false), +_decodedFrameCallback(_timing, clock_), +_dualDecodedFrameCallback(_dualTiming, clock_), _frameTypeCallback(NULL), _frameStorageCallback(NULL), _receiveStatsCallback(NULL), @@ -67,17 +72,18 @@ _scheduleKeyRequest(false), _sendCritSect(CriticalSectionWrapper::CreateCriticalSection()), _encoder(), _encodedFrameCallback(), -_mediaOpt(id), +_mediaOpt(id, clock_), _sendCodecType(kVideoCodecUnknown), _sendStatsCallback(NULL), _encoderInputFile(NULL), _codecDataBase(id), -_receiveStatsTimer(1000), -_sendStatsTimer(1000), -_retransmissionTimer(10), -_keyRequestTimer(500) +_receiveStatsTimer(1000, clock_), +_sendStatsTimer(1000, clock_), +_retransmissionTimer(10, clock_), +_keyRequestTimer(500, clock_) { + assert(clock_); for (int i = 0; i < kMaxSimulcastStreams; i++) { _nextFrameType[i] = kVideoFrameDelta; @@ -98,6 +104,7 @@ VideoCodingModuleImpl::~VideoCodingModuleImpl() } delete _receiveCritSect; delete _sendCritSect; + if (delete_clock_on_destroy_) delete clock_; #ifdef DEBUG_DECODER_BIT_STREAM fclose(_bitStreamBeforeDecoder); #endif @@ -113,7 +120,18 @@ VideoCodingModule::Create(const WebRtc_Word32 id) webrtc::kTraceVideoCoding, VCMId(id), "VideoCodingModule::Create()"); - return new VideoCodingModuleImpl(id); + return new VideoCodingModuleImpl(id, new TickTimeInterface(), true); +} + +VideoCodingModule* +VideoCodingModule::Create(const WebRtc_Word32 id, TickTimeInterface* clock) +{ + WEBRTC_TRACE(webrtc::kTraceModuleCall, + webrtc::kTraceVideoCoding, + VCMId(id), + "VideoCodingModule::Create()"); + assert(clock); + return new VideoCodingModuleImpl(id, clock, false); } void @@ -1085,7 +1103,7 @@ VideoCodingModuleImpl::Decode(WebRtc_UWord16 maxWaitTimeMs) // If this frame was too late, we should adjust the delay accordingly _timing.UpdateCurrentDelay(frame->RenderTimeMs(), - VCMTickTime::MillisecondTimestamp()); + clock_->MillisecondTimestamp()); #ifdef DEBUG_DECODER_BIT_STREAM if (_bitStreamBeforeDecoder != NULL) @@ -1202,7 +1220,8 @@ VideoCodingModuleImpl::DecodeDualFrame(WebRtc_UWord16 maxWaitTimeMs) "Decoding frame %u with dual decoder", dualFrame->TimeStamp()); // Decode dualFrame and try to catch up - WebRtc_Word32 ret = _dualDecoder->Decode(*dualFrame); + WebRtc_Word32 ret = _dualDecoder->Decode(*dualFrame, + clock_->MillisecondTimestamp()); if (ret != WEBRTC_VIDEO_CODEC_OK) { WEBRTC_TRACE(webrtc::kTraceWarning, @@ -1250,7 +1269,7 @@ VideoCodingModuleImpl::Decode(const VCMEncodedFrame& frame) return VCM_NO_CODEC_REGISTERED; } // Decode a frame - WebRtc_Word32 ret = _decoder->Decode(frame); + WebRtc_Word32 ret = _decoder->Decode(frame, clock_->MillisecondTimestamp()); // Check for failed decoding, run frame type request callback if needed. if (ret < 0) diff --git a/src/modules/video_coding/main/source/video_coding_impl.h b/src/modules/video_coding/main/source/video_coding_impl.h index a3c3630bb..94832c549 100644 --- a/src/modules/video_coding/main/source/video_coding_impl.h +++ b/src/modules/video_coding/main/source/video_coding_impl.h @@ -21,6 +21,7 @@ #include "generic_decoder.h" #include "generic_encoder.h" #include "media_optimization.h" +#include "modules/video_coding/main/source/tick_time_interface.h" #include @@ -30,13 +31,16 @@ namespace webrtc class VCMProcessTimer { public: - VCMProcessTimer(WebRtc_UWord32 periodMs) : - _periodMs(periodMs), _latestMs(VCMTickTime::MillisecondTimestamp()) {} + VCMProcessTimer(WebRtc_UWord32 periodMs, TickTimeInterface* clock) + : _clock(clock), + _periodMs(periodMs), + _latestMs(_clock->MillisecondTimestamp()) {} WebRtc_UWord32 Period() const; WebRtc_UWord32 TimeUntilProcess() const; void Processed(); private: + TickTimeInterface* _clock; WebRtc_UWord32 _periodMs; WebRtc_Word64 _latestMs; }; @@ -53,7 +57,9 @@ enum VCMKeyRequestMode class VideoCodingModuleImpl : public VideoCodingModule { public: - VideoCodingModuleImpl(const WebRtc_Word32 id); + VideoCodingModuleImpl(const WebRtc_Word32 id, + TickTimeInterface* clock, + bool delete_clock_on_destroy); virtual ~VideoCodingModuleImpl(); @@ -259,6 +265,8 @@ protected: private: WebRtc_Word32 _id; + TickTimeInterface* clock_; + bool delete_clock_on_destroy_; CriticalSectionWrapper* _receiveCritSect; bool _receiverInited; VCMTiming _timing; diff --git a/src/modules/video_coding/main/test/decode_from_storage_test.cc b/src/modules/video_coding/main/test/decode_from_storage_test.cc index b35546d99..66ea87989 100644 --- a/src/modules/video_coding/main/test/decode_from_storage_test.cc +++ b/src/modules/video_coding/main/test/decode_from_storage_test.cc @@ -12,9 +12,9 @@ #include "video_coding.h" #include "rtp_rtcp.h" #include "trace.h" -#include "tick_time.h" #include "../source/event.h" #include "rtp_player.h" +#include "modules/video_coding/main/source/mock/fake_tick_time_interface.h" using namespace webrtc; @@ -35,8 +35,8 @@ private: int DecodeFromStorageTest(CmdArgs& args) { - // Make sure this test isn't executed without simulated clocks -#if !defined(TICK_TIME_DEBUG) || !defined(EVENT_DEBUG) + // Make sure this test isn't executed without simulated events. +#if !defined(EVENT_DEBUG) return -1; #endif // BEGIN Settings @@ -64,8 +64,10 @@ int DecodeFromStorageTest(CmdArgs& args) Trace::SetLevelFilter(webrtc::kTraceAll); - VideoCodingModule* vcm = VideoCodingModule::Create(1); - VideoCodingModule* vcmPlayback = VideoCodingModule::Create(2); + FakeTickTime clock(0); + // TODO(hlundin): This test was not verified after changing to FakeTickTime. + VideoCodingModule* vcm = VideoCodingModule::Create(1, &clock); + VideoCodingModule* vcmPlayback = VideoCodingModule::Create(2, &clock); FrameStorageCallback storageCallback(vcmPlayback); RtpDataCallback dataCallback(vcm); WebRtc_Word32 ret = vcm->InitializeReceiver(); @@ -80,7 +82,7 @@ int DecodeFromStorageTest(CmdArgs& args) } vcm->RegisterFrameStorageCallback(&storageCallback); vcmPlayback->RegisterReceiveCallback(&receiveCallback); - RTPPlayer rtpStream(rtpFilename.c_str(), &dataCallback); + RTPPlayer rtpStream(rtpFilename.c_str(), &dataCallback, &clock); ListWrapper payloadTypes; payloadTypes.PushFront(new PayloadCodecTuple(VCM_VP8_PAYLOAD_TYPE, "VP8", kVideoCodecVP8)); @@ -124,9 +126,9 @@ int DecodeFromStorageTest(CmdArgs& args) ret = 0; // RTP stream main loop - while ((ret = rtpStream.NextPacket(VCMTickTime::MillisecondTimestamp())) == 0) + while ((ret = rtpStream.NextPacket(clock.MillisecondTimestamp())) == 0) { - if (VCMTickTime::MillisecondTimestamp() % 5 == 0) + if (clock.MillisecondTimestamp() % 5 == 0) { ret = vcm->Decode(); if (ret < 0) @@ -138,11 +140,11 @@ int DecodeFromStorageTest(CmdArgs& args) { vcm->Process(); } - if (MAX_RUNTIME_MS > -1 && VCMTickTime::MillisecondTimestamp() >= MAX_RUNTIME_MS) + if (MAX_RUNTIME_MS > -1 && clock.MillisecondTimestamp() >= MAX_RUNTIME_MS) { break; } - VCMTickTime::IncrementDebugClock(); + clock.IncrementDebugClock(1); } switch (ret) diff --git a/src/modules/video_coding/main/test/generic_codec_test.cc b/src/modules/video_coding/main/test/generic_codec_test.cc index 692e5a7ba..42d9e9bd7 100644 --- a/src/modules/video_coding/main/test/generic_codec_test.cc +++ b/src/modules/video_coding/main/test/generic_codec_test.cc @@ -11,11 +11,11 @@ #include "generic_codec_test.h" #include #include -#include "tick_time.h" #include "../source/event.h" #include "rtp_rtcp.h" #include "module_common_types.h" #include "test_macros.h" +#include "modules/video_coding/main/source/mock/fake_tick_time_interface.h" using namespace webrtc; @@ -23,12 +23,13 @@ enum { kMaxWaitEncTimeMs = 100 }; int GenericCodecTest::RunTest(CmdArgs& args) { -#if !defined(TICK_TIME_DEBUG) || !defined(EVENT_DEBUG) - printf("\n\nEnable debug time to run this test!\n\n"); +#if !defined(EVENT_DEBUG) + printf("\n\nEnable debug events to run this test!\n\n"); return -1; #endif - VideoCodingModule* vcm = VideoCodingModule::Create(1); - GenericCodecTest* get = new GenericCodecTest(vcm); + FakeTickTime clock(0); + VideoCodingModule* vcm = VideoCodingModule::Create(1, &clock); + GenericCodecTest* get = new GenericCodecTest(vcm, &clock); Trace::CreateTrace(); Trace::SetTraceFile( (test::OutputPath() + "genericCodecTestTrace.txt").c_str()); @@ -40,7 +41,8 @@ int GenericCodecTest::RunTest(CmdArgs& args) return 0; } -GenericCodecTest::GenericCodecTest(VideoCodingModule* vcm): +GenericCodecTest::GenericCodecTest(VideoCodingModule* vcm, FakeTickTime* clock): +_clock(clock), _vcm(vcm), _width(0), _height(0), @@ -307,7 +309,7 @@ GenericCodecTest::Perform(CmdArgs& args) _vcm->SetChannelParameters((WebRtc_UWord32)_bitRate, 0, 20); _frameCnt = 0; totalBytes = 0; - startTime = VCMTickTime::MicrosecondTimestamp(); + startTime = _clock->MicrosecondTimestamp(); _encodeCompleteCallback->Initialize(); sendStats.SetTargetFrameRate(static_cast(_frameRate)); _vcm->RegisterSendStatisticsCallback(&sendStats); @@ -331,7 +333,7 @@ GenericCodecTest::Perform(CmdArgs& args) //currentTime = VCMTickTime::MillisecondTimestamp();//clock()/(double)CLOCKS_PER_SEC; if (_frameCnt == _frameRate)// @ 1sec { - oneSecTime = VCMTickTime::MicrosecondTimestamp(); + oneSecTime = _clock->MicrosecondTimestamp(); totalBytesOneSec = _encodeCompleteCallback->EncodedBytes();//totalBytes; } TEST(_vcm->TimeUntilNextProcess() >= 0); @@ -341,7 +343,7 @@ GenericCodecTest::Perform(CmdArgs& args) // estimating rates // complete sequence // bit rate assumes input frame rate is as specified - currentTime = VCMTickTime::MicrosecondTimestamp(); + currentTime = _clock->MicrosecondTimestamp(); totalBytes = _encodeCompleteCallback->EncodedBytes(); actualBitrate = (float)(8.0/1000)*(totalBytes / (_frameCnt / _frameRate)); @@ -514,8 +516,8 @@ GenericCodecTest::Print() float GenericCodecTest::WaitForEncodedFrame() const { - WebRtc_Word64 startTime = TickTime::MillisecondTimestamp(); - while (TickTime::MillisecondTimestamp() - startTime < kMaxWaitEncTimeMs*10) + WebRtc_Word64 startTime = _clock->MillisecondTimestamp(); + while (_clock->MillisecondTimestamp() - startTime < kMaxWaitEncTimeMs*10) { if (_encodeCompleteCallback->EncodeComplete()) { @@ -528,11 +530,7 @@ GenericCodecTest::WaitForEncodedFrame() const void GenericCodecTest::IncrementDebugClock(float frameRate) { - for (int t= 0; t < 1000/frameRate; t++) - { - VCMTickTime::IncrementDebugClock(); - } - return; + _clock->IncrementDebugClock(1000/frameRate); } int diff --git a/src/modules/video_coding/main/test/generic_codec_test.h b/src/modules/video_coding/main/test/generic_codec_test.h index f7217007f..c88280f72 100644 --- a/src/modules/video_coding/main/test/generic_codec_test.h +++ b/src/modules/video_coding/main/test/generic_codec_test.h @@ -31,10 +31,13 @@ namespace webrtc { int VCMGenericCodecTest(CmdArgs& args); +class FakeTickTime; + class GenericCodecTest { public: - GenericCodecTest(webrtc::VideoCodingModule* vcm); + GenericCodecTest(webrtc::VideoCodingModule* vcm, + webrtc::FakeTickTime* clock); ~GenericCodecTest(); static int RunTest(CmdArgs& args); WebRtc_Word32 Perform(CmdArgs& args); @@ -46,6 +49,7 @@ private: WebRtc_Word32 TearDown(); void IncrementDebugClock(float frameRate); + webrtc::FakeTickTime* _clock; webrtc::VideoCodingModule* _vcm; webrtc::VideoCodec _sendCodec; webrtc::VideoCodec _receiveCodec; diff --git a/src/modules/video_coding/main/test/jitter_buffer_test.cc b/src/modules/video_coding/main/test/jitter_buffer_test.cc index 49365d46f..27b7e2c32 100644 --- a/src/modules/video_coding/main/test/jitter_buffer_test.cc +++ b/src/modules/video_coding/main/test/jitter_buffer_test.cc @@ -19,10 +19,10 @@ #include "jitter_estimate_test.h" #include "jitter_estimator.h" #include "media_opt_util.h" +#include "modules/video_coding/main/source/tick_time_interface.h" #include "packet.h" #include "test_util.h" #include "test_macros.h" -#include "tick_time.h" using namespace webrtc; @@ -92,10 +92,11 @@ int CheckOutFrame(VCMEncodedFrame* frameOut, unsigned int size, bool startCode) int JitterBufferTest(CmdArgs& args) { - // Don't run these tests with debug time -#if defined(TICK_TIME_DEBUG) || defined(EVENT_DEBUG) + // Don't run these tests with debug event. +#if defined(EVENT_DEBUG) return -1; #endif + TickTimeInterface clock; // Start test WebRtc_UWord16 seqNum = 1234; @@ -114,7 +115,7 @@ int JitterBufferTest(CmdArgs& args) packet.seqNum = seqNum; packet.payloadType = 126; seqNum++; - fb->InsertPacket(packet, VCMTickTime::MillisecondTimestamp(), false, 0); + fb->InsertPacket(packet, clock.MillisecondTimestamp(), false, 0); TEST(frameList.Insert(fb) == 0); } VCMFrameListItem* item = NULL; @@ -135,7 +136,7 @@ int JitterBufferTest(CmdArgs& args) //printf("DONE timestamp ordered frame list\n"); - VCMJitterBuffer jb; + VCMJitterBuffer jb(&clock); seqNum = 1234; timeStamp = 123*90; diff --git a/src/modules/video_coding/main/test/jitter_estimate_test.cc b/src/modules/video_coding/main/test/jitter_estimate_test.cc index 419ca3541..ac74a8a9d 100644 --- a/src/modules/video_coding/main/test/jitter_estimate_test.cc +++ b/src/modules/video_coding/main/test/jitter_estimate_test.cc @@ -11,7 +11,6 @@ #include #include #include "JitterEstimateTest.h" -#include "tick_time.h" using namespace webrtc; diff --git a/src/modules/video_coding/main/test/media_opt_test.cc b/src/modules/video_coding/main/test/media_opt_test.cc index a6e6c8575..569c91691 100644 --- a/src/modules/video_coding/main/test/media_opt_test.cc +++ b/src/modules/video_coding/main/test/media_opt_test.cc @@ -34,8 +34,9 @@ int MediaOptTest::RunTest(int testNum, CmdArgs& args) Trace::CreateTrace(); Trace::SetTraceFile((test::OutputPath() + "mediaOptTestTrace.txt").c_str()); Trace::SetLevelFilter(webrtc::kTraceAll); - VideoCodingModule* vcm = VideoCodingModule::Create(1); - MediaOptTest* mot = new MediaOptTest(vcm); + TickTimeInterface clock; + VideoCodingModule* vcm = VideoCodingModule::Create(1, &clock); + MediaOptTest* mot = new MediaOptTest(vcm, &clock); if (testNum == 0) { // regular mot->Setup(0, args); @@ -66,8 +67,9 @@ int MediaOptTest::RunTest(int testNum, CmdArgs& args) } -MediaOptTest::MediaOptTest(VideoCodingModule* vcm): +MediaOptTest::MediaOptTest(VideoCodingModule* vcm, TickTimeInterface* clock): _vcm(vcm), +_clock(clock), _width(0), _height(0), _lengthSourceFrame(0), @@ -279,7 +281,8 @@ MediaOptTest::Perform() encodeCompleteCallback->SetCodecType(ConvertCodecType(_codecName.c_str())); encodeCompleteCallback->SetFrameDimensions(_width, _height); // frame ready to be sent to network - RTPSendCompleteCallback* outgoingTransport = new RTPSendCompleteCallback(_rtp); + RTPSendCompleteCallback* outgoingTransport = + new RTPSendCompleteCallback(_rtp, _clock); _rtp->RegisterSendTransport(outgoingTransport); //FrameReceiveCallback VCMDecodeCompleteCallback receiveCallback(_decodedFile); diff --git a/src/modules/video_coding/main/test/media_opt_test.h b/src/modules/video_coding/main/test/media_opt_test.h index 6f1981cd0..60ac698de 100644 --- a/src/modules/video_coding/main/test/media_opt_test.h +++ b/src/modules/video_coding/main/test/media_opt_test.h @@ -31,7 +31,8 @@ class MediaOptTest { public: - MediaOptTest(webrtc::VideoCodingModule* vcm); + MediaOptTest(webrtc::VideoCodingModule* vcm, + webrtc::TickTimeInterface* clock); ~MediaOptTest(); static int RunTest(int testNum, CmdArgs& args); @@ -51,6 +52,7 @@ private: webrtc::VideoCodingModule* _vcm; webrtc::RtpRtcp* _rtp; + webrtc::TickTimeInterface* _clock; std::string _inname; std::string _outname; std::string _actualSourcename; diff --git a/src/modules/video_coding/main/test/mt_rx_tx_test.cc b/src/modules/video_coding/main/test/mt_rx_tx_test.cc index c9e066f29..9c72c1807 100644 --- a/src/modules/video_coding/main/test/mt_rx_tx_test.cc +++ b/src/modules/video_coding/main/test/mt_rx_tx_test.cc @@ -170,7 +170,8 @@ int MTRxTxTest(CmdArgs& args) TEST(rtp->SetGenericFECStatus(fecEnabled, VCM_RED_PAYLOAD_TYPE, VCM_ULPFEC_PAYLOAD_TYPE) == 0); //VCM - VideoCodingModule* vcm = VideoCodingModule::Create(1); + TickTimeInterface clock; + VideoCodingModule* vcm = VideoCodingModule::Create(1, &clock); if (vcm->InitializeReceiver() < 0) { return -1; @@ -215,7 +216,8 @@ int MTRxTxTest(CmdArgs& args) encodeCompleteCallback->SetCodecType(ConvertCodecType(args.codecName.c_str())); encodeCompleteCallback->SetFrameDimensions(width, height); // frame ready to be sent to network - RTPSendCompleteCallback* outgoingTransport = new RTPSendCompleteCallback(rtp, "dump.rtp"); + RTPSendCompleteCallback* outgoingTransport = + new RTPSendCompleteCallback(rtp, &clock, "dump.rtp"); rtp->RegisterSendTransport(outgoingTransport); // FrameReceiveCallback VCMDecodeCompleteCallback receiveCallback(decodedFile); diff --git a/src/modules/video_coding/main/test/mt_test_common.cc b/src/modules/video_coding/main/test/mt_test_common.cc index 7addb876b..ca9bb25b1 100644 --- a/src/modules/video_coding/main/test/mt_test_common.cc +++ b/src/modules/video_coding/main/test/mt_test_common.cc @@ -12,13 +12,15 @@ #include +#include "modules/video_coding/main/source/tick_time_interface.h" #include "rtp_dump.h" namespace webrtc { TransportCallback::TransportCallback(webrtc::RtpRtcp* rtp, + TickTimeInterface* clock, const char* filename): -RTPSendCompleteCallback(rtp, filename) +RTPSendCompleteCallback(rtp, clock, filename) { // } @@ -49,7 +51,8 @@ TransportCallback::SendPacket(int channel, const void *data, int len) transmitPacket = PacketLoss(); } - WebRtc_UWord64 now = VCMTickTime::MillisecondTimestamp(); + TickTimeInterface clock; + int64_t now = clock.MillisecondTimestamp(); // Insert outgoing packet into list if (transmitPacket) { @@ -73,7 +76,8 @@ TransportCallback::TransportPackets() { // Are we ready to send packets to the receiver? rtpPacket* packet = NULL; - WebRtc_UWord64 now = VCMTickTime::MillisecondTimestamp(); + TickTimeInterface clock; + int64_t now = clock.MillisecondTimestamp(); while (!_rtpPackets.Empty()) { diff --git a/src/modules/video_coding/main/test/mt_test_common.h b/src/modules/video_coding/main/test/mt_test_common.h index 5863d048c..433efae21 100644 --- a/src/modules/video_coding/main/test/mt_test_common.h +++ b/src/modules/video_coding/main/test/mt_test_common.h @@ -47,15 +47,15 @@ class TransportCallback:public RTPSendCompleteCallback { public: // constructor input: (receive side) rtp module to send encoded data to - TransportCallback(webrtc::RtpRtcp* rtp, + TransportCallback(webrtc::RtpRtcp* rtp, TickTimeInterface* clock, const char* filename = NULL); - virtual ~TransportCallback(); - // Add packets to list - // Incorporate network conditions - delay and packet loss - // Actual transmission will occur on a separate thread - int SendPacket(int channel, const void *data, int len); - // Send to the receiver packets which are ready to be submitted - int TransportPackets(); + virtual ~TransportCallback(); + // Add packets to list + // Incorporate network conditions - delay and packet loss + // Actual transmission will occur on a separate thread + int SendPacket(int channel, const void *data, int len); + // Send to the receiver packets which are ready to be submitted + int TransportPackets(); }; class SharedRTPState diff --git a/src/modules/video_coding/main/test/normal_test.cc b/src/modules/video_coding/main/test/normal_test.cc index e02921732..5e666ad55 100644 --- a/src/modules/video_coding/main/test/normal_test.cc +++ b/src/modules/video_coding/main/test/normal_test.cc @@ -17,10 +17,10 @@ #include "../source/event.h" #include "common_types.h" +#include "modules/video_coding/main/source/mock/fake_tick_time_interface.h" #include "test_callbacks.h" #include "test_macros.h" #include "test_util.h" -#include "tick_time.h" #include "trace.h" #include "testsupport/metrics/video_metrics.h" @@ -28,20 +28,22 @@ using namespace webrtc; int NormalTest::RunTest(CmdArgs& args) { - // Don't run this test with debug time -#if defined(TICK_TIME_DEBUG) || defined(EVENT_DEBUG) +#if defined(EVENT_DEBUG) printf("SIMULATION TIME\n"); + TickTimeInterface* clock = new FakeTickTime(0); #else printf("REAL-TIME\n"); + TickTimeInterface* clock = new TickTimeInterface; #endif Trace::CreateTrace(); Trace::SetTraceFile( (test::OutputPath() + "VCMNormalTestTrace.txt").c_str()); Trace::SetLevelFilter(webrtc::kTraceAll); - VideoCodingModule* vcm = VideoCodingModule::Create(1); - NormalTest VCMNTest(vcm); + VideoCodingModule* vcm = VideoCodingModule::Create(1, clock); + NormalTest VCMNTest(vcm, clock); VCMNTest.Perform(args); VideoCodingModule::Destroy(vcm); + delete clock; Trace::ReturnTrace(); return 0; } @@ -182,8 +184,9 @@ VCMNTDecodeCompleCallback::DecodedBytes() //VCM Normal Test Class implementation -NormalTest::NormalTest(VideoCodingModule* vcm) +NormalTest::NormalTest(VideoCodingModule* vcm, TickTimeInterface* clock) : +_clock(clock), _vcm(vcm), _sumEncBytes(0), _timeStamp(0), @@ -281,8 +284,8 @@ NormalTest::Perform(CmdArgs& args) while (feof(_sourceFile) == 0) { -#if !(defined(TICK_TIME_DEBUG) || defined(EVENT_DEBUG)) - WebRtc_Word64 processStartTime = VCMTickTime::MillisecondTimestamp(); +#if !defined(EVENT_DEBUG) + WebRtc_Word64 processStartTime = _clock->MillisecondTimestamp(); #endif TEST(fread(tmpBuffer, 1, _lengthSourceFrame, _sourceFile) > 0 || feof(_sourceFile)); @@ -314,13 +317,10 @@ NormalTest::Perform(CmdArgs& args) _vcm->Process(); } WebRtc_UWord32 framePeriod = static_cast(1000.0f/static_cast(_sendCodec.maxFramerate) + 0.5f); -#if defined(TICK_TIME_DEBUG) || defined(EVENT_DEBUG) - for (unsigned int i=0; i < framePeriod; i++) - { - VCMTickTime::IncrementDebugClock(); - } +#if defined(EVENT_DEBUG) + static_cast(_clock)->IncrementDebugClock(framePeriod); #else - WebRtc_Word64 timeSpent = VCMTickTime::MillisecondTimestamp() - processStartTime; + WebRtc_Word64 timeSpent = _clock->MillisecondTimestamp() - processStartTime; if (timeSpent < framePeriod) { waitEvent->Wait(framePeriod - timeSpent); diff --git a/src/modules/video_coding/main/test/normal_test.h b/src/modules/video_coding/main/test/normal_test.h index 786023536..31d228c43 100644 --- a/src/modules/video_coding/main/test/normal_test.h +++ b/src/modules/video_coding/main/test/normal_test.h @@ -83,7 +83,8 @@ private: class NormalTest { public: - NormalTest(webrtc::VideoCodingModule* vcm); + NormalTest(webrtc::VideoCodingModule* vcm, + webrtc::TickTimeInterface* clock); ~NormalTest(); static int RunTest(CmdArgs& args); WebRtc_Word32 Perform(CmdArgs& args); @@ -105,6 +106,7 @@ protected: // calculating pipeline delay, and decoding time void FrameDecoded(WebRtc_UWord32 timeStamp); + webrtc::TickTimeInterface* _clock; webrtc::VideoCodingModule* _vcm; webrtc::VideoCodec _sendCodec; webrtc::VideoCodec _receiveCodec; diff --git a/src/modules/video_coding/main/test/quality_modes_test.cc b/src/modules/video_coding/main/test/quality_modes_test.cc index b7ed7ec0a..b7c02cfca 100644 --- a/src/modules/video_coding/main/test/quality_modes_test.cc +++ b/src/modules/video_coding/main/test/quality_modes_test.cc @@ -15,6 +15,7 @@ #include #include "../source/event.h" +#include "modules/video_coding/main/source/tick_time_interface.h" #include "test_callbacks.h" #include "test_macros.h" #include "testsupport/metrics/video_metrics.h" @@ -24,20 +25,22 @@ using namespace webrtc; int qualityModeTest() { - // Don't run this test with debug time -#if defined(TICK_TIME_DEBUG) || defined(EVENT_DEBUG) + // Don't run this test with debug events. +#if defined(EVENT_DEBUG) return -1; #endif - VideoCodingModule* vcm = VideoCodingModule::Create(1); - QualityModesTest QMTest(vcm); + TickTimeInterface clock; + VideoCodingModule* vcm = VideoCodingModule::Create(1, &clock); + QualityModesTest QMTest(vcm, &clock); QMTest.Perform(); VideoCodingModule::Destroy(vcm); return 0; } -QualityModesTest::QualityModesTest(VideoCodingModule *vcm): -NormalTest(vcm), +QualityModesTest::QualityModesTest(VideoCodingModule* vcm, + TickTimeInterface* clock): +NormalTest(vcm, clock), _vpm() { // diff --git a/src/modules/video_coding/main/test/quality_modes_test.h b/src/modules/video_coding/main/test/quality_modes_test.h index c7a965bef..575d41698 100644 --- a/src/modules/video_coding/main/test/quality_modes_test.h +++ b/src/modules/video_coding/main/test/quality_modes_test.h @@ -20,7 +20,8 @@ int qualityModeTest(); class QualityModesTest : public NormalTest { public: - QualityModesTest(webrtc::VideoCodingModule* vcm); + QualityModesTest(webrtc::VideoCodingModule* vcm, + webrtc::TickTimeInterface* clock); virtual ~QualityModesTest(); WebRtc_Word32 Perform(); diff --git a/src/modules/video_coding/main/test/receiver_timing_tests.cc b/src/modules/video_coding/main/test/receiver_timing_tests.cc index b26e73f9f..a2d8edfa0 100644 --- a/src/modules/video_coding/main/test/receiver_timing_tests.cc +++ b/src/modules/video_coding/main/test/receiver_timing_tests.cc @@ -11,7 +11,6 @@ #include "receiver_tests.h" #include "video_coding.h" #include "trace.h" -#include "tick_time.h" #include "../source/event.h" #include "../source/internal_defines.h" #include "timing.h" @@ -49,8 +48,8 @@ public: int ReceiverTimingTests(CmdArgs& args) { - // Make sure this test is never executed with simulated clocks -#if defined(TICK_TIME_DEBUG) || defined(EVENT_DEBUG) + // Make sure this test is never executed with simulated events. +#if defined(EVENT_DEBUG) return -1; #endif @@ -62,7 +61,8 @@ int ReceiverTimingTests(CmdArgs& args) // A static random seed srand(0); - VCMTiming timing; + TickTimeInterface clock; + VCMTiming timing(&clock); float clockInMs = 0.0; WebRtc_UWord32 waitTime = 0; WebRtc_UWord32 jitterDelayMs = 0; diff --git a/src/modules/video_coding/main/test/rtp_player.cc b/src/modules/video_coding/main/test/rtp_player.cc index 3f8a7377b..3d4f3ea4b 100644 --- a/src/modules/video_coding/main/test/rtp_player.cc +++ b/src/modules/video_coding/main/test/rtp_player.cc @@ -20,8 +20,8 @@ #include "../source/internal_defines.h" #include "gtest/gtest.h" +#include "modules/video_coding/main/source/tick_time_interface.h" #include "rtp_rtcp.h" -#include "tick_time.h" using namespace webrtc; @@ -82,7 +82,9 @@ WebRtc_UWord32 LostPackets::AddPacket(WebRtc_UWord8* rtpData, WebRtc_UWord16 rtp return 0; } -WebRtc_UWord32 LostPackets::SetResendTime(WebRtc_UWord16 sequenceNumber, WebRtc_Word64 resendTime) +WebRtc_UWord32 LostPackets::SetResendTime(WebRtc_UWord16 sequenceNumber, + WebRtc_Word64 resendTime, + WebRtc_Word64 nowMs) { CriticalSectionScoped cs(_critSect); ListItem* item = First(); @@ -90,7 +92,6 @@ WebRtc_UWord32 LostPackets::SetResendTime(WebRtc_UWord16 sequenceNumber, WebRtc_ { RawRtpPacket* packet = static_cast(item->GetItem()); const WebRtc_UWord16 seqNo = (packet->rtpData[2] << 8) + packet->rtpData[3]; - const WebRtc_Word64 nowMs = VCMTickTime::MillisecondTimestamp(); if (sequenceNumber == seqNo && packet->resendTimeMs + 10 < nowMs) { if (_debugFile != NULL) @@ -123,18 +124,21 @@ WebRtc_UWord32 LostPackets::NumberOfPacketsToResend() const return count; } -void LostPackets::ResentPacket(WebRtc_UWord16 seqNo) +void LostPackets::ResentPacket(WebRtc_UWord16 seqNo, WebRtc_Word64 nowMs) { CriticalSectionScoped cs(_critSect); if (_debugFile != NULL) { fprintf(_debugFile, "Resent %u at %u\n", seqNo, - MaskWord64ToUWord32(VCMTickTime::MillisecondTimestamp())); + MaskWord64ToUWord32(nowMs)); } } -RTPPlayer::RTPPlayer(const char* filename, RtpData* callback) +RTPPlayer::RTPPlayer(const char* filename, + RtpData* callback, + TickTimeInterface* clock) : +_clock(clock), _rtpModule(*RtpRtcp::CreateRtpRtcp(1, false)), _nextRtpTime(0), _dataCallback(callback), @@ -272,7 +276,7 @@ WebRtc_Word32 RTPPlayer::ReadHeader() WebRtc_UWord32 RTPPlayer::TimeUntilNextPacket() const { - WebRtc_Word64 timeLeft = (_nextRtpTime - _firstPacketRtpTime) - (VCMTickTime::MillisecondTimestamp() - _firstPacketTimeMs); + WebRtc_Word64 timeLeft = (_nextRtpTime - _firstPacketRtpTime) - (_clock->MillisecondTimestamp() - _firstPacketTimeMs); if (timeLeft < 0) { return 0; @@ -305,7 +309,8 @@ WebRtc_Word32 RTPPlayer::NextPacket(const WebRtc_Word64 timeNow) _resendPacketCount++; if (ret > 0) { - _lostPackets.ResentPacket(seqNo); + _lostPackets.ResentPacket(seqNo, + _clock->MillisecondTimestamp()); } else if (ret < 0) { @@ -327,7 +332,7 @@ WebRtc_Word32 RTPPlayer::NextPacket(const WebRtc_Word64 timeNow) if (_firstPacket) { _firstPacketRtpTime = static_cast(_nextRtpTime); - _firstPacketTimeMs = VCMTickTime::MillisecondTimestamp(); + _firstPacketTimeMs = _clock->MillisecondTimestamp(); } if (_reordering && _reorderBuffer == NULL) { @@ -447,7 +452,9 @@ WebRtc_Word32 RTPPlayer::ResendPackets(const WebRtc_UWord16* sequenceNumbers, We } for (int i=0; i < length; i++) { - _lostPackets.SetResendTime(sequenceNumbers[i], VCMTickTime::MillisecondTimestamp() + _rttMs); + _lostPackets.SetResendTime(sequenceNumbers[i], + _clock->MillisecondTimestamp() + _rttMs, + _clock->MillisecondTimestamp()); } return 0; } diff --git a/src/modules/video_coding/main/test/rtp_player.h b/src/modules/video_coding/main/test/rtp_player.h index 8010a621e..cc6829eae 100644 --- a/src/modules/video_coding/main/test/rtp_player.h +++ b/src/modules/video_coding/main/test/rtp_player.h @@ -16,6 +16,7 @@ #include "list_wrapper.h" #include "critical_section_wrapper.h" #include "video_coding_defines.h" +#include "modules/video_coding/main/source/tick_time_interface.h" #include #include @@ -42,10 +43,12 @@ public: ~LostPackets(); WebRtc_UWord32 AddPacket(WebRtc_UWord8* rtpData, WebRtc_UWord16 rtpLen); - WebRtc_UWord32 SetResendTime(WebRtc_UWord16 sequenceNumber, WebRtc_Word64 resendTime); + WebRtc_UWord32 SetResendTime(WebRtc_UWord16 sequenceNumber, + WebRtc_Word64 resendTime, + WebRtc_Word64 nowMs); WebRtc_UWord32 TotalNumberOfLosses() const { return _lossCount; }; WebRtc_UWord32 NumberOfPacketsToResend() const; - void ResentPacket(WebRtc_UWord16 seqNo); + void ResentPacket(WebRtc_UWord16 seqNo, WebRtc_Word64 nowMs); void Lock() {_critSect->Enter();}; void Unlock() {_critSect->Leave();}; private: @@ -66,7 +69,9 @@ struct PayloadCodecTuple class RTPPlayer : public webrtc::VCMPacketRequestCallback { public: - RTPPlayer(const char* filename, webrtc::RtpData* callback); + RTPPlayer(const char* filename, + webrtc::RtpData* callback, + webrtc::TickTimeInterface* clock); virtual ~RTPPlayer(); WebRtc_Word32 Initialize(const webrtc::ListWrapper& payloadList); @@ -81,6 +86,7 @@ private: WebRtc_Word32 SendPacket(WebRtc_UWord8* rtpData, WebRtc_UWord16 rtpLen); WebRtc_Word32 ReadPacket(WebRtc_Word16* rtpdata, WebRtc_UWord32* offset); WebRtc_Word32 ReadHeader(); + webrtc::TickTimeInterface* _clock; FILE* _rtpFile; webrtc::RtpRtcp& _rtpModule; WebRtc_UWord32 _nextRtpTime; diff --git a/src/modules/video_coding/main/test/test_callbacks.cc b/src/modules/video_coding/main/test/test_callbacks.cc index d77c22ebe..4b7a47a94 100644 --- a/src/modules/video_coding/main/test/test_callbacks.cc +++ b/src/modules/video_coding/main/test/test_callbacks.cc @@ -12,6 +12,7 @@ #include +#include "modules/video_coding/main/source/tick_time_interface.h" #include "rtp_dump.h" #include "test_macros.h" @@ -199,7 +200,9 @@ VCMDecodeCompleteCallback::DecodedBytes() } RTPSendCompleteCallback::RTPSendCompleteCallback(RtpRtcp* rtp, + TickTimeInterface* clock, const char* filename): + _clock(clock), _sendCount(0), _rtp(rtp), _lossPct(0), @@ -251,7 +254,7 @@ RTPSendCompleteCallback::SendPacket(int channel, const void *data, int len) bool transmitPacket = true; transmitPacket = PacketLoss(); - WebRtc_UWord64 now = VCMTickTime::MillisecondTimestamp(); + WebRtc_UWord64 now = _clock->MillisecondTimestamp(); // Insert outgoing packet into list if (transmitPacket) { diff --git a/src/modules/video_coding/main/test/test_callbacks.h b/src/modules/video_coding/main/test/test_callbacks.h index e192a793a..8351be24c 100644 --- a/src/modules/video_coding/main/test/test_callbacks.h +++ b/src/modules/video_coding/main/test/test_callbacks.h @@ -24,7 +24,6 @@ #include "module_common_types.h" #include "rtp_rtcp.h" #include "test_util.h" -#include "tick_time.h" #include "trace.h" #include "video_coding.h" @@ -157,7 +156,7 @@ class RTPSendCompleteCallback: public Transport { public: // Constructor input: (receive side) rtp module to send encoded data to - RTPSendCompleteCallback(RtpRtcp* rtp, + RTPSendCompleteCallback(RtpRtcp* rtp, TickTimeInterface* clock, const char* filename = NULL); virtual ~RTPSendCompleteCallback(); // Send Packet to receive side RTP module @@ -184,6 +183,7 @@ protected: // Random uniform loss model bool UnifomLoss(double lossPct); + TickTimeInterface* _clock; WebRtc_UWord32 _sendCount; RtpRtcp* _rtp; double _lossPct; diff --git a/src/modules/video_coding/main/test/tester_main.cc b/src/modules/video_coding/main/test/tester_main.cc index 1aecf0444..ef5c9debe 100644 --- a/src/modules/video_coding/main/test/tester_main.cc +++ b/src/modules/video_coding/main/test/tester_main.cc @@ -27,16 +27,10 @@ using namespace webrtc; /* - * Build with TICK_TIME_DEBUG and EVENT_DEBUG defined - * to build the tests with simulated clock. + * Build with EVENT_DEBUG defined + * to build the tests with simulated events. */ -// TODO(holmer): How do we get debug time into the cmd line interface? -/* Debug time */ -#if defined(TICK_TIME_DEBUG) && defined(EVENT_DEBUG) -WebRtc_Word64 VCMTickTime::_timeNowDebug = 0; // current time in ms -#endif - int vcmMacrosTests = 0; int vcmMacrosErrors = 0; diff --git a/src/modules/video_coding/main/test/video_rtp_play.cc b/src/modules/video_coding/main/test/video_rtp_play.cc index 4fedc1907..5efc3070b 100644 --- a/src/modules/video_coding/main/test/video_rtp_play.cc +++ b/src/modules/video_coding/main/test/video_rtp_play.cc @@ -12,11 +12,11 @@ #include "video_coding.h" #include "rtp_rtcp.h" #include "trace.h" -#include "tick_time.h" #include "../source/event.h" #include "../source/internal_defines.h" #include "test_macros.h" #include "rtp_player.h" +#include "modules/video_coding/main/source/mock/fake_tick_time_interface.h" #include #include @@ -72,8 +72,8 @@ FrameReceiveCallback::FrameToRender(VideoFrame& videoFrame) int RtpPlay(CmdArgs& args) { - // Make sure this test isn't executed without simulated clocks -#if !defined(TICK_TIME_DEBUG) || !defined(EVENT_DEBUG) + // Make sure this test isn't executed without simulated events. +#if !defined(EVENT_DEBUG) return -1; #endif // BEGIN Settings @@ -90,9 +90,10 @@ int RtpPlay(CmdArgs& args) if (outFile == "") outFile = test::OutputPath() + "RtpPlay_decoded.yuv"; FrameReceiveCallback receiveCallback(outFile); - VideoCodingModule* vcm = VideoCodingModule::Create(1); + FakeTickTime clock(0); + VideoCodingModule* vcm = VideoCodingModule::Create(1, &clock); RtpDataCallback dataCallback(vcm); - RTPPlayer rtpStream(args.inputFile.c_str(), &dataCallback); + RTPPlayer rtpStream(args.inputFile.c_str(), &dataCallback, &clock); ListWrapper payloadTypes; @@ -150,9 +151,9 @@ int RtpPlay(CmdArgs& args) ret = 0; // RTP stream main loop - while ((ret = rtpStream.NextPacket(VCMTickTime::MillisecondTimestamp())) == 0) + while ((ret = rtpStream.NextPacket(clock.MillisecondTimestamp())) == 0) { - if (VCMTickTime::MillisecondTimestamp() % 5 == 0) + if (clock.MillisecondTimestamp() % 5 == 0) { ret = vcm->Decode(); if (ret < 0) @@ -165,11 +166,11 @@ int RtpPlay(CmdArgs& args) { vcm->Process(); } - if (MAX_RUNTIME_MS > -1 && VCMTickTime::MillisecondTimestamp() >= MAX_RUNTIME_MS) + if (MAX_RUNTIME_MS > -1 && clock.MillisecondTimestamp() >= MAX_RUNTIME_MS) { break; } - VCMTickTime::IncrementDebugClock(); + clock.IncrementDebugClock(1); } switch (ret) diff --git a/src/modules/video_coding/main/test/video_rtp_play_mt.cc b/src/modules/video_coding/main/test/video_rtp_play_mt.cc index 60a33619b..97ef45060 100644 --- a/src/modules/video_coding/main/test/video_rtp_play_mt.cc +++ b/src/modules/video_coding/main/test/video_rtp_play_mt.cc @@ -14,7 +14,6 @@ #include "trace.h" #include "thread_wrapper.h" #include "../source/event.h" -#include "tick_time.h" #include "test_macros.h" #include "rtp_player.h" @@ -40,8 +39,8 @@ bool RtpReaderThread(void* obj) SharedState* state = static_cast(obj); EventWrapper& waitEvent = *EventWrapper::Create(); // RTP stream main loop - WebRtc_Word64 nowMs = VCMTickTime::MillisecondTimestamp(); - if (state->_rtpPlayer.NextPacket(nowMs) < 0) + TickTimeInterface clock; + if (state->_rtpPlayer.NextPacket(clock.MillisecondTimestamp()) < 0) { return false; } @@ -60,8 +59,8 @@ bool DecodeThread(void* obj) int RtpPlayMT(CmdArgs& args, int releaseTestNo, webrtc::VideoCodecType releaseTestVideoType) { - // Don't run these tests with debug time -#if defined(TICK_TIME_DEBUG) || defined(EVENT_DEBUG) + // Don't run these tests with debug events. +#if defined(EVENT_DEBUG) return -1; #endif @@ -82,8 +81,9 @@ int RtpPlayMT(CmdArgs& args, int releaseTestNo, webrtc::VideoCodecType releaseTe (protection == kProtectionDualDecoder || protection == kProtectionNack || kProtectionNackFEC)); + TickTimeInterface clock; VideoCodingModule* vcm = - VideoCodingModule::Create(1); + VideoCodingModule::Create(1, &clock); RtpDataCallback dataCallback(vcm); std::string rtpFilename; rtpFilename = args.inputFile; @@ -136,7 +136,7 @@ int RtpPlayMT(CmdArgs& args, int releaseTestNo, webrtc::VideoCodecType releaseTe } printf("Watch %s to verify that the output is reasonable\n", outFilename.c_str()); } - RTPPlayer rtpStream(rtpFilename.c_str(), &dataCallback); + RTPPlayer rtpStream(rtpFilename.c_str(), &dataCallback, &clock); ListWrapper payloadTypes; payloadTypes.PushFront(new PayloadCodecTuple(VCM_VP8_PAYLOAD_TYPE, "VP8", kVideoCodecVP8));