2016-05-19 12:19:35 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2016 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_VIDEO_CODING_FRAME_BUFFER2_H_
|
|
|
|
|
#define MODULES_VIDEO_CODING_FRAME_BUFFER2_H_
|
2016-05-19 12:19:35 +02:00
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
2018-02-22 14:35:06 +01:00
|
|
|
#include "api/video/encoded_frame.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/video_coding/include/video_coding_defines.h"
|
|
|
|
|
#include "modules/video_coding/inter_frame_delay.h"
|
|
|
|
|
#include "rtc_base/constructormagic.h"
|
|
|
|
|
#include "rtc_base/criticalsection.h"
|
|
|
|
|
#include "rtc_base/event.h"
|
2018-08-27 10:08:58 -05:00
|
|
|
#include "rtc_base/experiments/rtt_mult_experiment.h"
|
2017-10-25 13:07:09 +02:00
|
|
|
#include "rtc_base/numerics/sequence_number_util.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/thread_annotations.h"
|
2016-05-19 12:19:35 +02:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
class Clock;
|
2017-02-22 05:30:39 -08:00
|
|
|
class VCMReceiveStatisticsCallback;
|
2016-05-19 12:19:35 +02:00
|
|
|
class VCMJitterEstimator;
|
|
|
|
|
class VCMTiming;
|
|
|
|
|
|
|
|
|
|
namespace video_coding {
|
|
|
|
|
|
|
|
|
|
class FrameBuffer {
|
|
|
|
|
public:
|
2016-09-05 10:57:41 +02:00
|
|
|
enum ReturnReason { kFrameFound, kTimeout, kStopped };
|
|
|
|
|
|
2016-05-19 12:19:35 +02:00
|
|
|
FrameBuffer(Clock* clock,
|
|
|
|
|
VCMJitterEstimator* jitter_estimator,
|
2017-02-22 05:30:39 -08:00
|
|
|
VCMTiming* timing,
|
|
|
|
|
VCMReceiveStatisticsCallback* stats_proxy);
|
2016-05-19 12:19:35 +02:00
|
|
|
|
2016-11-28 08:49:07 -08:00
|
|
|
virtual ~FrameBuffer();
|
|
|
|
|
|
2016-09-28 10:23:49 +02:00
|
|
|
// Insert a frame into the frame buffer. Returns the picture id
|
|
|
|
|
// of the last continuous frame or -1 if there is no continuous frame.
|
2018-03-23 10:43:21 +01:00
|
|
|
// TODO(philipel): Return a VideoLayerFrameId and not only the picture id.
|
2018-02-22 14:35:06 +01:00
|
|
|
int64_t InsertFrame(std::unique_ptr<EncodedFrame> frame);
|
2016-05-19 12:19:35 +02:00
|
|
|
|
|
|
|
|
// Get the next frame for decoding. Will return at latest after
|
2016-09-05 10:57:41 +02:00
|
|
|
// |max_wait_time_ms|.
|
2016-09-28 10:23:49 +02:00
|
|
|
// - If a frame is available within |max_wait_time_ms| it will return
|
2016-09-05 10:57:41 +02:00
|
|
|
// kFrameFound and set |frame_out| to the resulting frame.
|
|
|
|
|
// - If no frame is available after |max_wait_time_ms| it will return
|
|
|
|
|
// kTimeout.
|
|
|
|
|
// - If the FrameBuffer is stopped then it will return kStopped.
|
|
|
|
|
ReturnReason NextFrame(int64_t max_wait_time_ms,
|
2018-02-22 14:35:06 +01:00
|
|
|
std::unique_ptr<EncodedFrame>* frame_out,
|
Reland of quest keyframes more frequently on stream start/decoding error. (patchset #1 id:1 of https://codereview.chromium.org/2995153002/ )
Reason for revert:
iOS workaround.
Original issue's description:
> Revert of quest keyframes more frequently on stream start/decoding error. (patchset #2 id:170001 of https://codereview.webrtc.org/2996823002/ )
>
> Reason for revert:
> Causes iOS H264 calls received in the background to have increased delay before being able to decode stream from sender due to not having a keyframe.
>
> Original issue's description:
> > Reland of quest keyframes more frequently on stream start/decoding error. (patchset #1 id:1 of https://codereview.chromium.org/2994043002/ )
> >
> > Reason for revert:
> > Create fix CL.
> >
> > Original issue's description:
> > > Revert of Request keyframes more frequently on stream start/decoding error. (patchset #1 id:1 of https://codereview.webrtc.org/2993793002/ )
> > >
> > > Reason for revert:
> > > Broke downstream test that was waiting for 5 keyframes to be received within 10 seconds. Maybe the issue is that "stats_callback_->OnCompleteFrame(frame->num_references == 0, ..." was changed to "frame->is_keyframe()"?
> > >
> > > Original issue's description:
> > > > Request keyframes more frequently on stream start/decoding error.
> > > >
> > > > In this CL:
> > > > - Added FrameObject::is_keyframe() convinience function.
> > > > - Moved logic to request keyframes on decoding error from VideoReceived to
> > > > VideoReceiveStream.
> > > > - Added keyframe_required as a parameter to FrameBuffer::NextFrame.
> > > >
> > > > BUG=webrtc:8074
> > > >
> > > > Review-Url: https://codereview.webrtc.org/2993793002
> > > > Cr-Commit-Position: refs/heads/master@{#19280}
> > > > Committed: https://chromium.googlesource.com/external/webrtc/+/26b48043581735eed6e36b95fae6f5b1bcf8cfb5
> > >
> > > TBR=terelius@webrtc.org,stefan@webrtc.org,noahric@chromium.org,philipel@webrtc.org
> > > # Skipping CQ checks because original CL landed less than 1 days ago.
> > > NOPRESUBMIT=true
> > > NOTREECHECKS=true
> > > NOTRY=true
> > > BUG=webrtc:8074
> > >
> > > Review-Url: https://codereview.webrtc.org/2994043002
> > > Cr-Commit-Position: refs/heads/master@{#19295}
> > > Committed: https://chromium.googlesource.com/external/webrtc/+/77a983185f57628cd5955bd2c0a1bf71c30439bb
> >
> > TBR=terelius@webrtc.org,stefan@webrtc.org,noahric@chromium.org,deadbeef@webrtc.org
> > # Skipping CQ checks because original CL landed less than 1 days ago.
> > BUG=webrtc:8074
> >
> > Review-Url: https://codereview.webrtc.org/2996823002
> > Cr-Commit-Position: refs/heads/master@{#19324}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/628ac5964e32e66083a6ab14dceac6cb2cabe345
>
> TBR=terelius@webrtc.org,stefan@webrtc.org,noahric@chromium.org,deadbeef@webrtc.org,philipel@webrtc.org
> # Not skipping CQ checks because original CL landed more than 1 days ago.
> BUG=webrtc:8074
>
> Review-Url: https://codereview.webrtc.org/2995153002
> Cr-Commit-Position: refs/heads/master@{#19392}
> Committed: https://chromium.googlesource.com/external/webrtc/+/53959fcc2ba580e7c87231708e5b4af7906f6836
TBR=terelius@webrtc.org,stefan@webrtc.org,noahric@chromium.org,deadbeef@webrtc.org,tkchin@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
BUG=webrtc:8074
Review-Url: https://codereview.webrtc.org/2996153003
Cr-Commit-Position: refs/heads/master@{#19410}
2017-08-18 04:55:02 -07:00
|
|
|
bool keyframe_required = false);
|
2016-05-19 12:19:35 +02:00
|
|
|
|
2016-08-03 10:59:32 +02:00
|
|
|
// Tells the FrameBuffer which protection mode that is in use. Affects
|
|
|
|
|
// the frame timing.
|
|
|
|
|
// TODO(philipel): Remove this when new timing calculations has been
|
|
|
|
|
// implemented.
|
|
|
|
|
void SetProtectionMode(VCMVideoProtection mode);
|
|
|
|
|
|
2016-06-30 17:33:02 +02:00
|
|
|
// Start the frame buffer, has no effect if the frame buffer is started.
|
|
|
|
|
// The frame buffer is started upon construction.
|
|
|
|
|
void Start();
|
|
|
|
|
|
|
|
|
|
// Stop the frame buffer, causing any sleeping thread in NextFrame to
|
|
|
|
|
// return immediately.
|
|
|
|
|
void Stop();
|
|
|
|
|
|
2017-09-25 06:37:12 -07:00
|
|
|
// Updates the RTT for jitter buffer estimation.
|
|
|
|
|
void UpdateRtt(int64_t rtt_ms);
|
|
|
|
|
|
2018-11-07 14:32:28 +01:00
|
|
|
// Clears the FrameBuffer, removing all the buffered frames.
|
|
|
|
|
void Clear();
|
|
|
|
|
|
2016-05-19 12:19:35 +02:00
|
|
|
private:
|
2016-09-28 10:23:49 +02:00
|
|
|
struct FrameInfo {
|
2018-03-27 08:31:45 +02:00
|
|
|
FrameInfo();
|
|
|
|
|
FrameInfo(FrameInfo&&);
|
|
|
|
|
~FrameInfo();
|
|
|
|
|
|
2016-09-28 10:23:49 +02:00
|
|
|
// The maximum number of frames that can depend on this frame.
|
|
|
|
|
static constexpr size_t kMaxNumDependentFrames = 8;
|
|
|
|
|
|
|
|
|
|
// Which other frames that have direct unfulfilled dependencies
|
|
|
|
|
// on this frame.
|
2017-06-15 09:06:21 -07:00
|
|
|
// TODO(philipel): Add simple modify/access functions to prevent adding too
|
|
|
|
|
// many |dependent_frames|.
|
2018-03-19 15:34:53 +01:00
|
|
|
VideoLayerFrameId dependent_frames[kMaxNumDependentFrames];
|
2016-09-28 10:23:49 +02:00
|
|
|
size_t num_dependent_frames = 0;
|
|
|
|
|
|
|
|
|
|
// A frame is continiuous if it has all its referenced/indirectly
|
|
|
|
|
// referenced frames.
|
|
|
|
|
//
|
|
|
|
|
// How many unfulfilled frames this frame have until it becomes continuous.
|
|
|
|
|
size_t num_missing_continuous = 0;
|
2016-05-19 12:19:35 +02:00
|
|
|
|
2016-09-28 10:23:49 +02:00
|
|
|
// A frame is decodable if all its referenced frames have been decoded.
|
|
|
|
|
//
|
|
|
|
|
// How many unfulfilled frames this frame have until it becomes decodable.
|
|
|
|
|
size_t num_missing_decodable = 0;
|
|
|
|
|
|
|
|
|
|
// If this frame is continuous or not.
|
|
|
|
|
bool continuous = false;
|
|
|
|
|
|
2018-02-22 14:35:06 +01:00
|
|
|
// The actual EncodedFrame.
|
|
|
|
|
std::unique_ptr<EncodedFrame> frame;
|
2016-05-19 12:19:35 +02:00
|
|
|
};
|
|
|
|
|
|
2018-03-19 15:34:53 +01:00
|
|
|
using FrameMap = std::map<VideoLayerFrameId, FrameInfo>;
|
2016-09-28 10:23:49 +02:00
|
|
|
|
2017-06-15 09:06:21 -07:00
|
|
|
// Check that the references of |frame| are valid.
|
2018-02-22 14:35:06 +01:00
|
|
|
bool ValidReferences(const EncodedFrame& frame) const;
|
2017-06-15 09:06:21 -07:00
|
|
|
|
2017-05-10 09:21:33 -07:00
|
|
|
// Updates the minimal and maximal playout delays
|
|
|
|
|
// depending on the frame.
|
2018-02-22 14:35:06 +01:00
|
|
|
void UpdatePlayoutDelays(const EncodedFrame& frame)
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
2017-05-10 09:21:33 -07:00
|
|
|
|
2016-09-28 10:23:49 +02:00
|
|
|
// Update all directly dependent and indirectly dependent frames and mark
|
|
|
|
|
// them as continuous if all their references has been fulfilled.
|
|
|
|
|
void PropagateContinuity(FrameMap::iterator start)
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
2016-09-28 10:23:49 +02:00
|
|
|
|
|
|
|
|
// Marks the frame as decoded and updates all directly dependent frames.
|
|
|
|
|
void PropagateDecodability(const FrameInfo& info)
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
2016-09-28 10:23:49 +02:00
|
|
|
|
|
|
|
|
// Advances |last_decoded_frame_it_| to |decoded| and removes old
|
|
|
|
|
// frame info.
|
|
|
|
|
void AdvanceLastDecodedFrame(FrameMap::iterator decoded)
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
2016-05-19 12:19:35 +02:00
|
|
|
|
2016-09-28 10:23:49 +02:00
|
|
|
// Update the corresponding FrameInfo of |frame| and all FrameInfos that
|
|
|
|
|
// |frame| references.
|
|
|
|
|
// Return false if |frame| will never be decodable, true otherwise.
|
2018-02-22 14:35:06 +01:00
|
|
|
bool UpdateFrameInfoWithIncomingFrame(const EncodedFrame& frame,
|
2016-09-28 10:23:49 +02:00
|
|
|
FrameMap::iterator info)
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
2016-05-19 12:19:35 +02:00
|
|
|
|
2017-09-07 07:53:45 -07:00
|
|
|
void UpdateJitterDelay() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
2016-11-30 01:31:40 -08:00
|
|
|
|
2017-09-07 07:53:45 -07:00
|
|
|
void UpdateTimingFrameInfo() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
2017-07-06 03:06:50 -07:00
|
|
|
|
2017-09-07 07:53:45 -07:00
|
|
|
void ClearFramesAndHistory() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
2017-01-18 05:35:20 -08:00
|
|
|
|
2018-02-22 14:35:06 +01:00
|
|
|
bool HasBadRenderTiming(const EncodedFrame& frame, int64_t now_ms)
|
2017-09-07 07:53:45 -07:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
2017-05-23 09:52:18 -07:00
|
|
|
|
2017-09-07 07:53:45 -07:00
|
|
|
FrameMap frames_ RTC_GUARDED_BY(crit_);
|
2016-05-19 12:19:35 +02:00
|
|
|
|
|
|
|
|
rtc::CriticalSection crit_;
|
|
|
|
|
Clock* const clock_;
|
2017-03-14 06:23:57 -07:00
|
|
|
rtc::Event new_continuous_frame_event_;
|
2017-09-07 07:53:45 -07:00
|
|
|
VCMJitterEstimator* const jitter_estimator_ RTC_GUARDED_BY(crit_);
|
|
|
|
|
VCMTiming* const timing_ RTC_GUARDED_BY(crit_);
|
|
|
|
|
VCMInterFrameDelay inter_frame_delay_ RTC_GUARDED_BY(crit_);
|
2018-10-22 14:36:45 +02:00
|
|
|
absl::optional<uint32_t> last_decoded_frame_timestamp_ RTC_GUARDED_BY(crit_);
|
2017-09-07 07:53:45 -07:00
|
|
|
FrameMap::iterator last_decoded_frame_it_ RTC_GUARDED_BY(crit_);
|
|
|
|
|
FrameMap::iterator last_continuous_frame_it_ RTC_GUARDED_BY(crit_);
|
|
|
|
|
FrameMap::iterator next_frame_it_ RTC_GUARDED_BY(crit_);
|
|
|
|
|
int num_frames_history_ RTC_GUARDED_BY(crit_);
|
|
|
|
|
int num_frames_buffered_ RTC_GUARDED_BY(crit_);
|
|
|
|
|
bool stopped_ RTC_GUARDED_BY(crit_);
|
|
|
|
|
VCMVideoProtection protection_mode_ RTC_GUARDED_BY(crit_);
|
2017-02-22 05:30:39 -08:00
|
|
|
VCMReceiveStatisticsCallback* const stats_callback_;
|
2017-09-07 07:53:45 -07:00
|
|
|
int64_t last_log_non_decoded_ms_ RTC_GUARDED_BY(crit_);
|
2016-05-19 12:19:35 +02:00
|
|
|
|
|
|
|
|
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(FrameBuffer);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace video_coding
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_VIDEO_CODING_FRAME_BUFFER2_H_
|