webrtc_m130/webrtc/video/vie_encoder.h
perkj 71ee44cc6d This cl:
1. It moves calculation of the needed padding to VideoSendStream instead of ViEEncoder and only does it once per send Stream instead of every time the network estimate changes.

2. The maximum amount of padding sent was prior to this cl calculated and updated based on network estimate changes. However, it can only change based on encoder configuration changes and if send streams are added or removed. This cl change the VideoSendStream/VieEncoder to notify the BitrateAllocator of changes to the needed padding bitrate and for BitrateAllocator to notify Call of these changes.

3. Fixed an issue in the SendPacer where it could send a padding packet before sending a real packet. This caused the test EndToEndTest.RestartingSendStreamPreservesRtpStatesWithRtx to fail with these refactorings since the pacer suddenly could send a padding packet before the encoder had produced its first frame.

BUG=webrtc:5687

Review-Url: https://codereview.webrtc.org/1993113003
Cr-Commit-Position: refs/heads/master@{#13149}
2016-06-15 07:47:58 +00:00

153 lines
5.3 KiB
C++

/*
* 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 WEBRTC_VIDEO_VIE_ENCODER_H_
#define WEBRTC_VIDEO_VIE_ENCODER_H_
#include <memory>
#include <string>
#include <vector>
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/scoped_ref_ptr.h"
#include "webrtc/base/thread_annotations.h"
#include "webrtc/common_types.h"
#include "webrtc/video_encoder.h"
#include "webrtc/media/base/videosinkinterface.h"
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "webrtc/modules/video_coding/include/video_coding_defines.h"
#include "webrtc/modules/video_coding/video_coding_impl.h"
#include "webrtc/modules/video_processing/include/video_processing.h"
#include "webrtc/typedefs.h"
namespace webrtc {
class Config;
class EncodedImageCallback;
class OveruseFrameDetector;
class PacedSender;
class ProcessThread;
class SendStatisticsProxy;
class ViEBitrateObserver;
class ViEEffectFilter;
class VideoEncoder;
// VieEncoder represent a video encoder that accepts raw video frames as input
// and produces an encoded bit stream.
// Usage:
// 1. Instantiate
// 2. Call Init
// 3. Call RegisterExternalEncoder if available.
// 4. Call SetEncoder with the codec settings and the object that shall receive
// the encoded bit stream.
// 5. Call Start.
// 6. For each available raw video frame call EncodeVideoFrame.
class ViEEncoder : public VideoEncoderRateObserver,
public EncodedImageCallback,
public VCMSendStatisticsCallback {
public:
friend class ViEBitrateObserver;
ViEEncoder(uint32_t number_of_cores,
ProcessThread* module_process_thread,
SendStatisticsProxy* stats_proxy,
OveruseFrameDetector* overuse_detector,
EncodedImageCallback* sink);
~ViEEncoder();
vcm::VideoSender* video_sender();
// Returns the id of the owning channel.
int Owner() const;
void Start();
// Drops incoming packets before they get to the encoder.
void Pause();
// Codec settings.
int32_t RegisterExternalEncoder(VideoEncoder* encoder,
uint8_t pl_type,
bool internal_source);
int32_t DeRegisterExternalEncoder(uint8_t pl_type);
void SetEncoder(const VideoCodec& video_codec,
size_t max_data_payload_length);
void EncodeVideoFrame(const VideoFrame& video_frame);
void SendKeyFrame();
// Returns the time when the encoder last received an input frame or produced
// an encoded frame.
int64_t time_of_last_frame_activity_ms();
// Implements VideoEncoderRateObserver.
// TODO(perkj): Refactor VideoEncoderRateObserver. This is only used for
// stats. The stats should be set in VideoSendStream instead.
// |bitrate_bps| is the target bitrate and |framerate| is the input frame
// rate so it has nothing to do with the actual encoder.
void OnSetRates(uint32_t bitrate_bps, int framerate) override;
// Implements EncodedImageCallback.
int32_t Encoded(const EncodedImage& encoded_image,
const CodecSpecificInfo* codec_specific_info,
const RTPFragmentationHeader* fragmentation) override;
// Implements VideoSendStatisticsCallback.
void SendStatistics(uint32_t bit_rate,
uint32_t frame_rate,
const std::string& encoder_name) override;
// virtual to test EncoderStateFeedback with mocks.
virtual void OnReceivedIntraFrameRequest(size_t stream_index);
virtual void OnReceivedSLI(uint8_t picture_id);
virtual void OnReceivedRPSI(uint64_t picture_id);
void OnBitrateUpdated(uint32_t bitrate_bps,
uint8_t fraction_lost,
int64_t round_trip_time_ms);
private:
bool EncoderPaused() const EXCLUSIVE_LOCKS_REQUIRED(data_cs_);
void TraceFrameDropStart() EXCLUSIVE_LOCKS_REQUIRED(data_cs_);
void TraceFrameDropEnd() EXCLUSIVE_LOCKS_REQUIRED(data_cs_);
const uint32_t number_of_cores_;
EncodedImageCallback* const sink_;
const std::unique_ptr<VideoProcessing> vp_;
vcm::VideoSender video_sender_;
rtc::CriticalSection data_cs_;
SendStatisticsProxy* const stats_proxy_;
OveruseFrameDetector* const overuse_detector_;
// The time we last received an input frame or encoded frame. This is used to
// track when video is stopped long enough that we also want to stop sending
// padding.
int64_t time_of_last_frame_activity_ms_ GUARDED_BY(data_cs_);
VideoCodec encoder_config_ GUARDED_BY(data_cs_);
uint32_t last_observed_bitrate_bps_ GUARDED_BY(data_cs_);
bool encoder_paused_ GUARDED_BY(data_cs_);
bool encoder_paused_and_dropped_frame_ GUARDED_BY(data_cs_);
ProcessThread* module_process_thread_;
bool has_received_sli_ GUARDED_BY(data_cs_);
uint8_t picture_id_sli_ GUARDED_BY(data_cs_);
bool has_received_rpsi_ GUARDED_BY(data_cs_);
uint64_t picture_id_rpsi_ GUARDED_BY(data_cs_);
bool video_suspended_ GUARDED_BY(data_cs_);
};
} // namespace webrtc
#endif // WEBRTC_VIDEO_VIE_ENCODER_H_