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"
|
2014-09-24 06:05:00 +00:00
|
|
|
#include "webrtc/base/thread_annotations.h"
|
2016-07-14 23:35:55 -07:00
|
|
|
#include "webrtc/base/sequenced_task_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"
|
|
|
|
|
#include "webrtc/modules/video_coding/receiver.h"
|
|
|
|
|
#include "webrtc/modules/video_coding/timing.h"
|
2015-11-18 23:04:10 +01:00
|
|
|
#include "webrtc/modules/video_coding/utility/qp_parser.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
|
|
|
|
2016-11-16 16:41:30 +01:00
|
|
|
class VideoBitrateAllocator;
|
|
|
|
|
|
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-11-16 16:41:30 +01:00
|
|
|
int32_t SetChannelParameters(uint32_t target_bitrate_bps,
|
2013-09-14 00:25:28 +00:00
|
|
|
uint8_t lossRate,
|
2016-11-16 16:41:30 +01:00
|
|
|
int64_t rtt,
|
|
|
|
|
VideoBitrateAllocator* bitrate_allocator);
|
|
|
|
|
// Updates the channel parameters, with a reallocated bitrate based on a
|
|
|
|
|
// presumably updated codec configuration, but does not update the encoder
|
|
|
|
|
// itself (it will be updated on the next frame).
|
|
|
|
|
void UpdateChannelParemeters(VideoBitrateAllocator* bitrate_allocator);
|
|
|
|
|
|
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_);
|
|
|
|
|
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:
|
|
|
|
|
typedef VideoCodingModule::ReceiverRobustness ReceiverRobustness;
|
|
|
|
|
|
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-03-12 03:30:23 -08:00
|
|
|
NackSender* nack_sender = nullptr,
|
|
|
|
|
KeyFrameRequestSender* keyframe_request_sender = nullptr);
|
2013-09-14 00:25:28 +00:00
|
|
|
~VideoReceiver();
|
|
|
|
|
|
|
|
|
|
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);
|
2013-10-23 23:59:45 +00:00
|
|
|
int32_t RegisterDecoderTimingCallback(
|
|
|
|
|
VCMDecoderTimingCallback* decoderTiming);
|
2013-09-14 00:25:28 +00:00
|
|
|
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);
|
|
|
|
|
|
2013-09-14 00:25:28 +00:00
|
|
|
int32_t ReceiveCodec(VideoCodec* currentReceiveCodec) const;
|
|
|
|
|
VideoCodecType ReceiveCodec() const;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
uint32_t DiscardedPackets() const;
|
|
|
|
|
|
|
|
|
|
int SetReceiverRobustnessMode(ReceiverRobustness robustnessMode,
|
|
|
|
|
VCMDecodeErrorMode errorMode);
|
|
|
|
|
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;
|
2013-09-14 00:25:28 +00:00
|
|
|
|
2015-02-17 13:22:43 +00:00
|
|
|
void TriggerDecoderShutdown();
|
2013-11-26 11:41:59 +00:00
|
|
|
|
2013-09-14 00:25:28 +00:00
|
|
|
protected:
|
2014-10-29 15:28:39 +00:00
|
|
|
int32_t Decode(const webrtc::VCMEncodedFrame& frame)
|
2016-04-15 01:24:14 -07:00
|
|
|
EXCLUSIVE_LOCKS_REQUIRED(receive_crit_);
|
2013-09-14 00:25:28 +00:00
|
|
|
int32_t RequestKeyFrame();
|
|
|
|
|
int32_t RequestSliceLossIndication(const uint64_t pictureID) const;
|
|
|
|
|
|
|
|
|
|
private:
|
2014-07-04 10:58:12 +00:00
|
|
|
Clock* const clock_;
|
2016-04-15 01:24:14 -07:00
|
|
|
rtc::CriticalSection process_crit_;
|
|
|
|
|
rtc::CriticalSection receive_crit_;
|
2013-09-14 00:25:28 +00:00
|
|
|
VCMTiming _timing;
|
|
|
|
|
VCMReceiver _receiver;
|
|
|
|
|
VCMDecodedFrameCallback _decodedFrameCallback;
|
2016-04-15 01:24:14 -07:00
|
|
|
VCMFrameTypeCallback* _frameTypeCallback GUARDED_BY(process_crit_);
|
|
|
|
|
VCMReceiveStatisticsCallback* _receiveStatsCallback GUARDED_BY(process_crit_);
|
|
|
|
|
VCMDecoderTimingCallback* _decoderTimingCallback GUARDED_BY(process_crit_);
|
|
|
|
|
VCMPacketRequestCallback* _packetRequestCallback GUARDED_BY(process_crit_);
|
2013-09-14 00:25:28 +00:00
|
|
|
VCMGenericDecoder* _decoder;
|
2016-04-15 01:24:14 -07:00
|
|
|
|
2013-09-14 00:25:28 +00:00
|
|
|
VCMFrameBuffer _frameFromFile;
|
2016-04-15 01:24:14 -07:00
|
|
|
bool _scheduleKeyRequest GUARDED_BY(process_crit_);
|
|
|
|
|
bool drop_frames_until_keyframe_ GUARDED_BY(process_crit_);
|
|
|
|
|
size_t max_nack_list_size_ GUARDED_BY(process_crit_);
|
2013-09-14 00:25:28 +00:00
|
|
|
|
2016-04-15 01:24:14 -07:00
|
|
|
VCMCodecDataBase _codecDataBase GUARDED_BY(receive_crit_);
|
|
|
|
|
EncodedImageCallback* pre_decode_image_callback_;
|
2016-02-02 15:40:04 +01:00
|
|
|
|
2013-09-14 00:25:28 +00:00
|
|
|
VCMProcessTimer _receiveStatsTimer;
|
|
|
|
|
VCMProcessTimer _retransmissionTimer;
|
|
|
|
|
VCMProcessTimer _keyRequestTimer;
|
2015-10-20 23:55:26 -07:00
|
|
|
QpParser qp_parser_;
|
2016-04-07 15:36:45 -07:00
|
|
|
ThreadUnsafeOneTimeEvent first_frame_received_;
|
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_
|