2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-02-13 09:03:53 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* 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_VIDEO_CODING_IMPL_H_
|
|
|
|
|
#define WEBRTC_MODULES_VIDEO_CODING_VIDEO_CODING_IMPL_H_
|
|
|
|
|
|
2015-11-18 22:00:21 +01:00
|
|
|
#include "webrtc/modules/video_coding/include/video_coding.h"
|
2012-10-08 07:06:53 +00:00
|
|
|
|
2016-02-29 05:51:59 -08:00
|
|
|
#include <memory>
|
2016-05-02 11:35:24 -07:00
|
|
|
#include <string>
|
2012-10-08 07:06:53 +00:00
|
|
|
#include <vector>
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-04-07 15:36:45 -07:00
|
|
|
#include "webrtc/base/onetimeevent.h"
|
2016-07-14 23:35:55 -07:00
|
|
|
#include "webrtc/base/sequenced_task_checker.h"
|
2017-03-14 04:16:20 -07:00
|
|
|
#include "webrtc/base/thread_annotations.h"
|
|
|
|
|
#include "webrtc/base/thread_checker.h"
|
2016-04-18 21:12:48 -07:00
|
|
|
#include "webrtc/common_video/include/frame_callback.h"
|
2015-11-18 22:00:21 +01:00
|
|
|
#include "webrtc/modules/video_coding/codec_database.h"
|
|
|
|
|
#include "webrtc/modules/video_coding/frame_buffer.h"
|
|
|
|
|
#include "webrtc/modules/video_coding/generic_decoder.h"
|
|
|
|
|
#include "webrtc/modules/video_coding/generic_encoder.h"
|
|
|
|
|
#include "webrtc/modules/video_coding/jitter_buffer.h"
|
|
|
|
|
#include "webrtc/modules/video_coding/media_optimization.h"
|
2017-03-08 05:42:26 -08:00
|
|
|
#include "webrtc/modules/video_coding/qp_parser.h"
|
2015-11-18 22:00:21 +01:00
|
|
|
#include "webrtc/modules/video_coding/receiver.h"
|
|
|
|
|
#include "webrtc/modules/video_coding/timing.h"
|
2015-10-28 18:17:40 +01:00
|
|
|
#include "webrtc/system_wrappers/include/clock.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-09-14 00:25:28 +00:00
|
|
|
namespace webrtc {
|
2013-11-26 11:41:59 +00:00
|
|
|
|
2017-04-04 03:53:02 -07:00
|
|
|
class ProcessThread;
|
2016-11-16 16:41:30 +01:00
|
|
|
class VideoBitrateAllocator;
|
2016-12-01 06:34:11 -08:00
|
|
|
class VideoBitrateAllocationObserver;
|
2016-11-16 16:41:30 +01:00
|
|
|
|
2013-09-14 00:25:28 +00:00
|
|
|
namespace vcm {
|
|
|
|
|
|
|
|
|
|
class VCMProcessTimer {
|
|
|
|
|
public:
|
2016-11-21 05:41:52 -08:00
|
|
|
static const int64_t kDefaultProcessIntervalMs = 1000;
|
|
|
|
|
|
2014-12-15 22:09:40 +00:00
|
|
|
VCMProcessTimer(int64_t periodMs, Clock* clock)
|
2013-09-14 00:25:28 +00:00
|
|
|
: _clock(clock),
|
|
|
|
|
_periodMs(periodMs),
|
|
|
|
|
_latestMs(_clock->TimeInMilliseconds()) {}
|
2014-12-15 22:09:40 +00:00
|
|
|
int64_t Period() const;
|
|
|
|
|
int64_t TimeUntilProcess() const;
|
2013-09-14 00:25:28 +00:00
|
|
|
void Processed();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Clock* _clock;
|
2014-12-15 22:09:40 +00:00
|
|
|
int64_t _periodMs;
|
2013-09-14 00:25:28 +00:00
|
|
|
int64_t _latestMs;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
|
|
|
|
|
2016-04-21 16:48:08 +02:00
|
|
|
class VideoSender : public Module {
|
2013-09-14 00:25:28 +00:00
|
|
|
public:
|
|
|
|
|
typedef VideoCodingModule::SenderNackMode SenderNackMode;
|
|
|
|
|
|
2015-02-26 13:15:22 +00:00
|
|
|
VideoSender(Clock* clock,
|
|
|
|
|
EncodedImageCallback* post_encode_callback,
|
2016-05-02 11:35:24 -07:00
|
|
|
VCMSendStatisticsCallback* send_stats_callback);
|
2014-01-09 08:01:57 +00:00
|
|
|
|
2013-09-14 00:25:28 +00:00
|
|
|
~VideoSender();
|
|
|
|
|
|
|
|
|
|
// Register the send codec to be used.
|
2015-02-19 17:43:25 +00:00
|
|
|
// This method must be called on the construction thread.
|
2013-09-14 00:25:28 +00:00
|
|
|
int32_t RegisterSendCodec(const VideoCodec* sendCodec,
|
|
|
|
|
uint32_t numberOfCores,
|
|
|
|
|
uint32_t maxPayloadSize);
|
|
|
|
|
|
2015-11-27 14:09:07 +01:00
|
|
|
void RegisterExternalEncoder(VideoEncoder* externalEncoder,
|
|
|
|
|
uint8_t payloadType,
|
|
|
|
|
bool internalSource);
|
2013-09-14 00:25:28 +00:00
|
|
|
|
|
|
|
|
int Bitrate(unsigned int* bitrate) const;
|
|
|
|
|
int FrameRate(unsigned int* framerate) const;
|
|
|
|
|
|
2016-12-01 06:34:11 -08:00
|
|
|
// Update the channel parameters based on new rates and rtt. This will also
|
|
|
|
|
// cause an immediate call to VideoEncoder::SetRateAllocation().
|
|
|
|
|
int32_t SetChannelParameters(
|
|
|
|
|
uint32_t target_bitrate_bps,
|
|
|
|
|
uint8_t loss_rate,
|
|
|
|
|
int64_t rtt,
|
|
|
|
|
VideoBitrateAllocator* bitrate_allocator,
|
|
|
|
|
VideoBitrateAllocationObserver* bitrate_updated_callback);
|
|
|
|
|
|
|
|
|
|
// Updates the channel parameters with a new bitrate allocation, but using the
|
|
|
|
|
// current targit_bitrate, loss rate and rtt. That is, the distribution or
|
|
|
|
|
// caps may be updated to a change to a new VideoCodec or allocation mode.
|
|
|
|
|
// The new parameters will be stored as pending EncoderParameters, and the
|
|
|
|
|
// encoder will only be updated on the next frame.
|
|
|
|
|
void UpdateChannelParemeters(
|
|
|
|
|
VideoBitrateAllocator* bitrate_allocator,
|
|
|
|
|
VideoBitrateAllocationObserver* bitrate_updated_callback);
|
2016-11-16 16:41:30 +01:00
|
|
|
|
2016-06-02 15:45:42 +02:00
|
|
|
// Deprecated:
|
|
|
|
|
// TODO(perkj): Remove once no projects use it.
|
2013-09-14 00:25:28 +00:00
|
|
|
int32_t RegisterProtectionCallback(VCMProtectionCallback* protection);
|
|
|
|
|
|
2015-05-29 17:21:40 -07:00
|
|
|
int32_t AddVideoFrame(const VideoFrame& videoFrame,
|
2013-09-14 00:25:28 +00:00
|
|
|
const CodecSpecificInfo* codecSpecificInfo);
|
|
|
|
|
|
2016-05-04 11:26:51 -07:00
|
|
|
int32_t IntraFrameRequest(size_t stream_index);
|
2013-09-14 00:25:28 +00:00
|
|
|
int32_t EnableFrameDropper(bool enable);
|
|
|
|
|
|
2016-04-21 16:48:08 +02:00
|
|
|
int64_t TimeUntilNextProcess() override;
|
|
|
|
|
void Process() override;
|
2013-09-14 00:25:28 +00:00
|
|
|
|
|
|
|
|
private:
|
2016-11-16 16:41:30 +01:00
|
|
|
EncoderParameters UpdateEncoderParameters(
|
|
|
|
|
const EncoderParameters& params,
|
|
|
|
|
VideoBitrateAllocator* bitrate_allocator,
|
|
|
|
|
uint32_t target_bitrate_bps);
|
2016-06-17 07:27:16 -07:00
|
|
|
void SetEncoderParameters(EncoderParameters params, bool has_internal_source)
|
2016-01-18 20:23:40 +01:00
|
|
|
EXCLUSIVE_LOCKS_REQUIRED(encoder_crit_);
|
2015-09-15 14:43:47 +02:00
|
|
|
|
|
|
|
|
Clock* const clock_;
|
2013-09-14 00:25:28 +00:00
|
|
|
|
2016-01-25 03:52:44 -08:00
|
|
|
rtc::CriticalSection encoder_crit_;
|
2013-09-14 00:25:28 +00:00
|
|
|
VCMGenericEncoder* _encoder;
|
2013-09-23 19:54:25 +00:00
|
|
|
media_optimization::MediaOptimization _mediaOpt;
|
2016-05-02 11:35:24 -07:00
|
|
|
VCMEncodedFrameCallback _encodedFrameCallback GUARDED_BY(encoder_crit_);
|
2016-11-29 01:44:11 -08:00
|
|
|
EncodedImageCallback* const post_encode_callback_;
|
2016-05-02 11:35:24 -07:00
|
|
|
VCMSendStatisticsCallback* const send_stats_callback_;
|
2016-01-18 20:23:40 +01:00
|
|
|
VCMCodecDataBase _codecDataBase GUARDED_BY(encoder_crit_);
|
|
|
|
|
bool frame_dropper_enabled_ GUARDED_BY(encoder_crit_);
|
2013-09-14 00:25:28 +00:00
|
|
|
VCMProcessTimer _sendStatsTimer;
|
2013-12-19 10:59:48 +00:00
|
|
|
|
2015-02-19 17:43:25 +00:00
|
|
|
// Must be accessed on the construction thread of VideoSender.
|
|
|
|
|
VideoCodec current_codec_;
|
2016-07-14 23:35:55 -07:00
|
|
|
rtc::SequencedTaskChecker sequenced_checker_;
|
2015-06-11 14:20:07 +02:00
|
|
|
|
2016-01-18 20:23:40 +01:00
|
|
|
rtc::CriticalSection params_crit_;
|
|
|
|
|
EncoderParameters encoder_params_ GUARDED_BY(params_crit_);
|
|
|
|
|
bool encoder_has_internal_source_ GUARDED_BY(params_crit_);
|
|
|
|
|
std::vector<FrameType> next_frame_types_ GUARDED_BY(params_crit_);
|
2013-09-14 00:25:28 +00:00
|
|
|
};
|
|
|
|
|
|
2016-04-22 18:23:15 +02:00
|
|
|
class VideoReceiver : public Module {
|
2013-09-14 00:25:28 +00:00
|
|
|
public:
|
2016-03-12 03:30:23 -08:00
|
|
|
VideoReceiver(Clock* clock,
|
|
|
|
|
EventFactory* event_factory,
|
2016-04-15 01:24:14 -07:00
|
|
|
EncodedImageCallback* pre_decode_image_callback,
|
2016-12-15 07:10:57 -08:00
|
|
|
VCMTiming* timing,
|
2016-03-12 03:30:23 -08:00
|
|
|
NackSender* nack_sender = nullptr,
|
|
|
|
|
KeyFrameRequestSender* keyframe_request_sender = nullptr);
|
2017-04-04 03:53:02 -07:00
|
|
|
~VideoReceiver() override;
|
2013-09-14 00:25:28 +00:00
|
|
|
|
|
|
|
|
int32_t RegisterReceiveCodec(const VideoCodec* receiveCodec,
|
|
|
|
|
int32_t numberOfCores,
|
|
|
|
|
bool requireKeyFrame);
|
|
|
|
|
|
2015-11-27 14:09:07 +01:00
|
|
|
void RegisterExternalDecoder(VideoDecoder* externalDecoder,
|
2015-12-10 09:27:38 -08:00
|
|
|
uint8_t payloadType);
|
2013-09-14 00:25:28 +00:00
|
|
|
int32_t RegisterReceiveCallback(VCMReceiveCallback* receiveCallback);
|
|
|
|
|
int32_t RegisterReceiveStatisticsCallback(
|
|
|
|
|
VCMReceiveStatisticsCallback* receiveStats);
|
|
|
|
|
int32_t RegisterFrameTypeCallback(VCMFrameTypeCallback* frameTypeCallback);
|
|
|
|
|
int32_t RegisterPacketRequestCallback(VCMPacketRequestCallback* callback);
|
|
|
|
|
|
|
|
|
|
int32_t Decode(uint16_t maxWaitTimeMs);
|
|
|
|
|
|
2016-11-15 00:57:57 -08:00
|
|
|
int32_t Decode(const webrtc::VCMEncodedFrame* frame);
|
|
|
|
|
|
2017-04-04 03:53:02 -07:00
|
|
|
#if defined(WEBRTC_ANDROID)
|
|
|
|
|
// See https://bugs.chromium.org/p/webrtc/issues/detail?id=7361
|
|
|
|
|
void PollDecodedFrames();
|
|
|
|
|
#endif
|
2017-03-14 04:16:20 -07:00
|
|
|
|
2013-09-14 00:25:28 +00:00
|
|
|
int32_t IncomingPacket(const uint8_t* incomingPayload,
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t payloadLength,
|
2013-09-14 00:25:28 +00:00
|
|
|
const WebRtcRTPHeader& rtpInfo);
|
|
|
|
|
int32_t SetMinimumPlayoutDelay(uint32_t minPlayoutDelayMs);
|
|
|
|
|
int32_t SetRenderDelay(uint32_t timeMS);
|
|
|
|
|
int32_t Delay() const;
|
|
|
|
|
|
2017-03-20 10:43:23 -07:00
|
|
|
// DEPRECATED.
|
|
|
|
|
int SetReceiverRobustnessMode(
|
|
|
|
|
VideoCodingModule::ReceiverRobustness robustnessMode,
|
|
|
|
|
VCMDecodeErrorMode errorMode);
|
|
|
|
|
|
2013-09-14 00:25:28 +00:00
|
|
|
void SetNackSettings(size_t max_nack_list_size,
|
|
|
|
|
int max_packet_age_to_nack,
|
|
|
|
|
int max_incomplete_time_ms);
|
|
|
|
|
|
|
|
|
|
void SetDecodeErrorMode(VCMDecodeErrorMode decode_error_mode);
|
|
|
|
|
int SetMinReceiverDelay(int desired_delay_ms);
|
|
|
|
|
|
2015-01-12 21:51:21 +00:00
|
|
|
int32_t SetReceiveChannelParameters(int64_t rtt);
|
2013-09-14 00:25:28 +00:00
|
|
|
int32_t SetVideoProtection(VCMVideoProtection videoProtection, bool enable);
|
|
|
|
|
|
2016-04-22 18:23:15 +02:00
|
|
|
int64_t TimeUntilNextProcess() override;
|
|
|
|
|
void Process() override;
|
2017-04-04 03:53:02 -07:00
|
|
|
void ProcessThreadAttached(ProcessThread* process_thread) override;
|
2013-09-14 00:25:28 +00:00
|
|
|
|
2015-02-17 13:22:43 +00:00
|
|
|
void TriggerDecoderShutdown();
|
2017-04-04 03:53:02 -07:00
|
|
|
void DecoderThreadStarting();
|
|
|
|
|
void DecoderThreadStopped();
|
2013-11-26 11:41:59 +00:00
|
|
|
|
2013-09-14 00:25:28 +00:00
|
|
|
protected:
|
2017-04-04 03:53:02 -07:00
|
|
|
int32_t Decode(const webrtc::VCMEncodedFrame& frame);
|
2013-09-14 00:25:28 +00:00
|
|
|
int32_t RequestKeyFrame();
|
|
|
|
|
|
|
|
|
|
private:
|
2017-04-04 03:53:02 -07: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();
|
|
|
|
|
|
2017-03-14 04:16:20 -07:00
|
|
|
rtc::ThreadChecker construction_thread_;
|
2017-04-04 03:53:02 -07:00
|
|
|
rtc::ThreadChecker decoder_thread_;
|
|
|
|
|
rtc::ThreadChecker module_thread_;
|
2014-07-04 10:58:12 +00:00
|
|
|
Clock* const clock_;
|
2016-04-15 01:24:14 -07:00
|
|
|
rtc::CriticalSection process_crit_;
|
2016-12-15 07:10:57 -08:00
|
|
|
VCMTiming* _timing;
|
2013-09-14 00:25:28 +00:00
|
|
|
VCMReceiver _receiver;
|
|
|
|
|
VCMDecodedFrameCallback _decodedFrameCallback;
|
2016-04-15 01:24:14 -07:00
|
|
|
|
2017-04-04 03:53:02 -07: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;
|
|
|
|
|
VCMReceiveStatisticsCallback* _receiveStatsCallback;
|
|
|
|
|
VCMPacketRequestCallback* _packetRequestCallback;
|
|
|
|
|
|
|
|
|
|
// Used on both the module and decoder thread.
|
2016-04-15 01:24:14 -07:00
|
|
|
bool _scheduleKeyRequest GUARDED_BY(process_crit_);
|
|
|
|
|
bool drop_frames_until_keyframe_ GUARDED_BY(process_crit_);
|
2016-02-02 15:40:04 +01:00
|
|
|
|
2017-04-04 03:53:02 -07: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.
|
|
|
|
|
VCMCodecDataBase _codecDataBase;
|
|
|
|
|
EncodedImageCallback* const pre_decode_image_callback_;
|
|
|
|
|
|
|
|
|
|
VCMProcessTimer _receiveStatsTimer ACCESS_ON(module_thread_);
|
|
|
|
|
VCMProcessTimer _retransmissionTimer ACCESS_ON(module_thread_);
|
|
|
|
|
VCMProcessTimer _keyRequestTimer ACCESS_ON(module_thread_);
|
|
|
|
|
QpParser qp_parser_ ACCESS_ON(decoder_thread_);
|
|
|
|
|
ThreadUnsafeOneTimeEvent first_frame_received_ ACCESS_ON(decoder_thread_);
|
|
|
|
|
// Modified on the construction thread. Can be read without a lock and assumed
|
|
|
|
|
// to be non-null on the module and decoder threads.
|
|
|
|
|
ProcessThread* process_thread_ = nullptr;
|
|
|
|
|
bool is_attached_to_process_thread_ ACCESS_ON(construction_thread_) = false;
|
|
|
|
|
#if RTC_DCHECK_IS_ON
|
|
|
|
|
bool decoder_thread_is_running_ = false;
|
|
|
|
|
#endif
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
2013-09-14 00:25:28 +00:00
|
|
|
|
|
|
|
|
} // namespace vcm
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace webrtc
|
2013-09-14 00:25:28 +00:00
|
|
|
#endif // WEBRTC_MODULES_VIDEO_CODING_VIDEO_CODING_IMPL_H_
|