webrtc_m130/modules/video_coding/video_coding_impl.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

142 lines
5.0 KiB
C
Raw Normal View History

/*
* Copyright (c) 2012 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 MODULES_VIDEO_CODING_VIDEO_CODING_IMPL_H_
#define MODULES_VIDEO_CODING_VIDEO_CODING_IMPL_H_
#include <memory>
#include <string>
#include <vector>
#include "absl/types/optional.h"
#include "modules/video_coding/decoder_database.h"
#include "modules/video_coding/frame_buffer.h"
#include "modules/video_coding/generic_decoder.h"
#include "modules/video_coding/include/video_coding.h"
#include "modules/video_coding/jitter_buffer.h"
#include "modules/video_coding/receiver.h"
#include "modules/video_coding/timing.h"
#include "rtc_base/one_time_event.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/synchronization/sequence_checker.h"
#include "rtc_base/thread_annotations.h"
#include "rtc_base/thread_checker.h"
#include "system_wrappers/include/clock.h"
namespace webrtc {
Reland #2 of Issue 2434073003: Extract bitrate allocation ... This is yet another reland of https://codereview.webrtc.org/2434073003/ including two fixes: 1. SimulcastRateAllocator did not handle the screenshare settings properly for numSimulcastStreams = 1. Additional test case was added for that. 2. In VideoSender, when rate allocation is updated after setting a new VideoCodec config, only update the state of the EncoderParameters, but don't actually run SetRateAllocation on the encoder itself. This caused some problems upstreams. Please review only the changes after patch set 1. Original description: Extract bitrate allocation of spatial/temporal layers out of codec impl. This CL makes a number of intervowen changes: * Add BitrateAllocation struct, that contains a codec independent view of how the target bitrate is distributed over spatial and temporal layers. * Adds the BitrateAllocator interface, which takes a bitrate and frame rate and produces a BitrateAllocation. * A default (non layered) implementation is added, and SimulcastRateAllocator is extended to fully handle VP8 allocation. This includes capturing TemporalLayer instances created by the encoder. * ViEEncoder now owns both the bitrate allocator and the temporal layer factories for VP8. This allows allocation to happen fully outside of the encoder implementation. This refactoring will make it possible for ViEEncoder to signal the full picture of target bitrates to the RTCP module. BUG=webrtc:6301 R=stefan@webrtc.org Review URL: https://codereview.webrtc.org/2510583002 . Cr-Commit-Position: refs/heads/master@{#15105}
2016-11-16 16:41:30 +01:00
class VideoBitrateAllocator;
class VideoBitrateAllocationObserver;
Reland #2 of Issue 2434073003: Extract bitrate allocation ... This is yet another reland of https://codereview.webrtc.org/2434073003/ including two fixes: 1. SimulcastRateAllocator did not handle the screenshare settings properly for numSimulcastStreams = 1. Additional test case was added for that. 2. In VideoSender, when rate allocation is updated after setting a new VideoCodec config, only update the state of the EncoderParameters, but don't actually run SetRateAllocation on the encoder itself. This caused some problems upstreams. Please review only the changes after patch set 1. Original description: Extract bitrate allocation of spatial/temporal layers out of codec impl. This CL makes a number of intervowen changes: * Add BitrateAllocation struct, that contains a codec independent view of how the target bitrate is distributed over spatial and temporal layers. * Adds the BitrateAllocator interface, which takes a bitrate and frame rate and produces a BitrateAllocation. * A default (non layered) implementation is added, and SimulcastRateAllocator is extended to fully handle VP8 allocation. This includes capturing TemporalLayer instances created by the encoder. * ViEEncoder now owns both the bitrate allocator and the temporal layer factories for VP8. This allows allocation to happen fully outside of the encoder implementation. This refactoring will make it possible for ViEEncoder to signal the full picture of target bitrates to the RTCP module. BUG=webrtc:6301 R=stefan@webrtc.org Review URL: https://codereview.webrtc.org/2510583002 . Cr-Commit-Position: refs/heads/master@{#15105}
2016-11-16 16:41:30 +01:00
namespace vcm {
class VCMProcessTimer {
public:
static const int64_t kDefaultProcessIntervalMs = 1000;
VCMProcessTimer(int64_t periodMs, Clock* clock)
: _clock(clock),
_periodMs(periodMs),
_latestMs(_clock->TimeInMilliseconds()) {}
int64_t Period() const;
int64_t TimeUntilProcess() const;
void Processed();
private:
Clock* _clock;
int64_t _periodMs;
int64_t _latestMs;
};
class VideoReceiver : public Module {
public:
VideoReceiver(Clock* clock, VCMTiming* timing);
Reland "Reduce locking in VideoReceiver and check the threading model." This is a reland of c75f1e45093a8d5cc62937c7708b87aa5c5bf0b0. Original change's description: > Reduce locking in VideoReceiver and check the threading model. > > Note: This is a subset of code that was previously reviewed here: > - https://codereview.webrtc.org/2764573002/ > > * 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/correctness. > * 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. > * Removed |VCMFrameBuffer _frameFromFile| (unused). > * Clean up several of my TODOs > > Bug: webrtc:7361, chromium:695438 > Change-Id: Id0048ee9624f76103c088d02825eb5c0d6c8913c > Reviewed-on: https://webrtc-review.googlesource.com/55000 > Commit-Queue: Tommi <tommi@webrtc.org> > Reviewed-by: Philip Eliasson <philipel@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#22133} Bug: webrtc:7361, chromium:695438 Change-Id: I32e1dc6c62cb30ad96e6366106f39fe415de49f1 Tbr: philipel@webrtc.org Reviewed-on: https://webrtc-review.googlesource.com/56803 Commit-Queue: Tommi <tommi@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22163}
2018-02-21 15:56:05 +01:00
~VideoReceiver() override;
int32_t RegisterReceiveCodec(const VideoCodec* receiveCodec,
int32_t numberOfCores,
bool requireKeyFrame);
void RegisterExternalDecoder(VideoDecoder* externalDecoder,
uint8_t payloadType);
int32_t RegisterReceiveCallback(VCMReceiveCallback* receiveCallback);
int32_t RegisterFrameTypeCallback(VCMFrameTypeCallback* frameTypeCallback);
int32_t RegisterPacketRequestCallback(VCMPacketRequestCallback* callback);
int32_t Decode(uint16_t maxWaitTimeMs);
int32_t IncomingPacket(const uint8_t* incomingPayload,
size_t payloadLength,
const RTPHeader& rtp_header,
const RTPVideoHeader& video_header);
void SetNackSettings(size_t max_nack_list_size,
int max_packet_age_to_nack,
int max_incomplete_time_ms);
int64_t TimeUntilNextProcess() override;
void Process() override;
Reland "Reduce locking in VideoReceiver and check the threading model." This is a reland of c75f1e45093a8d5cc62937c7708b87aa5c5bf0b0. Original change's description: > Reduce locking in VideoReceiver and check the threading model. > > Note: This is a subset of code that was previously reviewed here: > - https://codereview.webrtc.org/2764573002/ > > * 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/correctness. > * 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. > * Removed |VCMFrameBuffer _frameFromFile| (unused). > * Clean up several of my TODOs > > Bug: webrtc:7361, chromium:695438 > Change-Id: Id0048ee9624f76103c088d02825eb5c0d6c8913c > Reviewed-on: https://webrtc-review.googlesource.com/55000 > Commit-Queue: Tommi <tommi@webrtc.org> > Reviewed-by: Philip Eliasson <philipel@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#22133} Bug: webrtc:7361, chromium:695438 Change-Id: I32e1dc6c62cb30ad96e6366106f39fe415de49f1 Tbr: philipel@webrtc.org Reviewed-on: https://webrtc-review.googlesource.com/56803 Commit-Queue: Tommi <tommi@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22163}
2018-02-21 15:56:05 +01:00
void ProcessThreadAttached(ProcessThread* process_thread) override;
protected:
Reland "Reduce locking in VideoReceiver and check the threading model." This is a reland of c75f1e45093a8d5cc62937c7708b87aa5c5bf0b0. Original change's description: > Reduce locking in VideoReceiver and check the threading model. > > Note: This is a subset of code that was previously reviewed here: > - https://codereview.webrtc.org/2764573002/ > > * 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/correctness. > * 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. > * Removed |VCMFrameBuffer _frameFromFile| (unused). > * Clean up several of my TODOs > > Bug: webrtc:7361, chromium:695438 > Change-Id: Id0048ee9624f76103c088d02825eb5c0d6c8913c > Reviewed-on: https://webrtc-review.googlesource.com/55000 > Commit-Queue: Tommi <tommi@webrtc.org> > Reviewed-by: Philip Eliasson <philipel@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#22133} Bug: webrtc:7361, chromium:695438 Change-Id: I32e1dc6c62cb30ad96e6366106f39fe415de49f1 Tbr: philipel@webrtc.org Reviewed-on: https://webrtc-review.googlesource.com/56803 Commit-Queue: Tommi <tommi@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22163}
2018-02-21 15:56:05 +01:00
int32_t Decode(const webrtc::VCMEncodedFrame& frame);
int32_t RequestKeyFrame();
private:
Reland "Reduce locking in VideoReceiver and check the threading model." This is a reland of c75f1e45093a8d5cc62937c7708b87aa5c5bf0b0. Original change's description: > Reduce locking in VideoReceiver and check the threading model. > > Note: This is a subset of code that was previously reviewed here: > - https://codereview.webrtc.org/2764573002/ > > * 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/correctness. > * 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. > * Removed |VCMFrameBuffer _frameFromFile| (unused). > * Clean up several of my TODOs > > Bug: webrtc:7361, chromium:695438 > Change-Id: Id0048ee9624f76103c088d02825eb5c0d6c8913c > Reviewed-on: https://webrtc-review.googlesource.com/55000 > Commit-Queue: Tommi <tommi@webrtc.org> > Reviewed-by: Philip Eliasson <philipel@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#22133} Bug: webrtc:7361, chromium:695438 Change-Id: I32e1dc6c62cb30ad96e6366106f39fe415de49f1 Tbr: philipel@webrtc.org Reviewed-on: https://webrtc-review.googlesource.com/56803 Commit-Queue: Tommi <tommi@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22163}
2018-02-21 15:56:05 +01:00
// 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_checker_;
rtc::ThreadChecker decoder_thread_checker_;
rtc::ThreadChecker module_thread_checker_;
Clock* const clock_;
Mutex process_mutex_;
VCMTiming* _timing;
VCMReceiver _receiver;
VCMDecodedFrameCallback _decodedFrameCallback;
Reland "Reduce locking in VideoReceiver and check the threading model." This is a reland of c75f1e45093a8d5cc62937c7708b87aa5c5bf0b0. Original change's description: > Reduce locking in VideoReceiver and check the threading model. > > Note: This is a subset of code that was previously reviewed here: > - https://codereview.webrtc.org/2764573002/ > > * 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/correctness. > * 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. > * Removed |VCMFrameBuffer _frameFromFile| (unused). > * Clean up several of my TODOs > > Bug: webrtc:7361, chromium:695438 > Change-Id: Id0048ee9624f76103c088d02825eb5c0d6c8913c > Reviewed-on: https://webrtc-review.googlesource.com/55000 > Commit-Queue: Tommi <tommi@webrtc.org> > Reviewed-by: Philip Eliasson <philipel@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#22133} Bug: webrtc:7361, chromium:695438 Change-Id: I32e1dc6c62cb30ad96e6366106f39fe415de49f1 Tbr: philipel@webrtc.org Reviewed-on: https://webrtc-review.googlesource.com/56803 Commit-Queue: Tommi <tommi@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22163}
2018-02-21 15:56:05 +01:00
// 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;
VCMPacketRequestCallback* _packetRequestCallback;
// Used on both the module and decoder thread.
bool _scheduleKeyRequest RTC_GUARDED_BY(process_mutex_);
bool drop_frames_until_keyframe_ RTC_GUARDED_BY(process_mutex_);
Reland "Reduce locking in VideoReceiver and check the threading model." This is a reland of c75f1e45093a8d5cc62937c7708b87aa5c5bf0b0. Original change's description: > Reduce locking in VideoReceiver and check the threading model. > > Note: This is a subset of code that was previously reviewed here: > - https://codereview.webrtc.org/2764573002/ > > * 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/correctness. > * 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. > * Removed |VCMFrameBuffer _frameFromFile| (unused). > * Clean up several of my TODOs > > Bug: webrtc:7361, chromium:695438 > Change-Id: Id0048ee9624f76103c088d02825eb5c0d6c8913c > Reviewed-on: https://webrtc-review.googlesource.com/55000 > Commit-Queue: Tommi <tommi@webrtc.org> > Reviewed-by: Philip Eliasson <philipel@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#22133} Bug: webrtc:7361, chromium:695438 Change-Id: I32e1dc6c62cb30ad96e6366106f39fe415de49f1 Tbr: philipel@webrtc.org Reviewed-on: https://webrtc-review.googlesource.com/56803 Commit-Queue: Tommi <tommi@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22163}
2018-02-21 15:56:05 +01:00
// Modified on the construction thread while not attached to the process
// thread. Once attached to the process thread, its value is only read
// so a lock is not required.
size_t max_nack_list_size_;
// Callbacks are set before the decoder thread starts.
// Once the decoder thread has been started, usage of |_codecDataBase| moves
// over to the decoder thread.
VCMDecoderDataBase _codecDataBase;
VCMProcessTimer _retransmissionTimer RTC_GUARDED_BY(module_thread_checker_);
VCMProcessTimer _keyRequestTimer RTC_GUARDED_BY(module_thread_checker_);
ThreadUnsafeOneTimeEvent first_frame_received_
RTC_GUARDED_BY(decoder_thread_checker_);
// 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_
RTC_GUARDED_BY(construction_thread_checker_) = false;
};
} // namespace vcm
} // namespace webrtc
#endif // MODULES_VIDEO_CODING_VIDEO_CODING_IMPL_H_