blob: d36e663f4b8e4e6b7017b7651baf83b2fb5e641d [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
mflodman@webrtc.orgc80d9d92012-02-06 10:11:25 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/video_coding/video_coding_impl.h"
philipel5908c712015-12-21 08:23:20 -080012
13#include <algorithm>
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <memory>
philipel5908c712015-12-21 08:23:20 -080015
Yves Gerey3e707812018-11-28 16:47:49 +010016#include "api/video/encoded_image.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/video_coding/include/video_codec_interface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/video_coding/timing.h"
Steve Anton10542f22019-01-11 09:11:00 -080019#include "rtc_base/critical_section.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "rtc_base/thread_checker.h"
21#include "system_wrappers/include/clock.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000022
agalusza@google.coma7e360e2013-08-01 03:15:08 +000023namespace webrtc {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000024namespace vcm {
niklase@google.com470e71d2011-07-07 08:21:25 +000025
philipel5908c712015-12-21 08:23:20 -080026int64_t VCMProcessTimer::Period() const {
27 return _periodMs;
niklase@google.com470e71d2011-07-07 08:21:25 +000028}
29
philipel5908c712015-12-21 08:23:20 -080030int64_t VCMProcessTimer::TimeUntilProcess() const {
31 const int64_t time_since_process = _clock->TimeInMilliseconds() - _latestMs;
32 const int64_t time_until_process = _periodMs - time_since_process;
33 return std::max<int64_t>(time_until_process, 0);
niklase@google.com470e71d2011-07-07 08:21:25 +000034}
35
philipel5908c712015-12-21 08:23:20 -080036void VCMProcessTimer::Processed() {
37 _latestMs = _clock->TimeInMilliseconds();
niklase@google.com470e71d2011-07-07 08:21:25 +000038}
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000039} // namespace vcm
niklase@google.com470e71d2011-07-07 08:21:25 +000040
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000041namespace {
andresp@webrtc.org1df9dc32014-01-09 08:01:57 +000042
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000043class VideoCodingModuleImpl : public VideoCodingModule {
44 public:
stefan@webrtc.org34c5da62014-04-11 14:08:35 +000045 VideoCodingModuleImpl(Clock* clock,
philipel83f831a2016-03-12 03:30:23 -080046 NackSender* nack_sender,
Niels Möller9eb44ac2018-10-02 12:47:47 +020047 KeyFrameRequestSender* keyframe_request_sender)
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000048 : VideoCodingModule(),
philipel721d4022016-12-15 07:10:57 -080049 timing_(new VCMTiming(clock)),
Niels Möller689983f2018-11-07 16:36:22 +010050 receiver_(clock, timing_.get(), nack_sender, keyframe_request_sender) {}
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000051
Mirko Bonadeife055c12019-01-29 22:53:28 +010052 ~VideoCodingModuleImpl() override {}
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000053
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000054 int64_t TimeUntilNextProcess() override {
pbos0fa9b222015-11-13 05:59:57 -080055 int64_t receiver_time = receiver_.TimeUntilNextProcess();
tommid0a71ba2017-03-14 04:16:20 -070056 RTC_DCHECK_GE(receiver_time, 0);
Niels Möllera0565992017-10-24 11:37:08 +020057 return receiver_time;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000058 }
59
Yves Gerey665174f2018-06-19 15:03:05 +020060 void Process() override { receiver_.Process(); }
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000061
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000062 int32_t RegisterReceiveCodec(const VideoCodec* receiveCodec,
63 int32_t numberOfCores,
64 bool requireKeyFrame) override {
pbos0fa9b222015-11-13 05:59:57 -080065 return receiver_.RegisterReceiveCodec(receiveCodec, numberOfCores,
66 requireKeyFrame);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000067 }
68
Anders Carlsson7eb8e9f2018-05-18 10:33:04 +020069 void RegisterExternalDecoder(VideoDecoder* externalDecoder,
70 uint8_t payloadType) override {
71 receiver_.RegisterExternalDecoder(externalDecoder, payloadType);
72 }
73
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000074 int32_t RegisterReceiveCallback(
75 VCMReceiveCallback* receiveCallback) override {
tommid0a71ba2017-03-14 04:16:20 -070076 RTC_DCHECK(construction_thread_.CalledOnValidThread());
pbos0fa9b222015-11-13 05:59:57 -080077 return receiver_.RegisterReceiveCallback(receiveCallback);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000078 }
79
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000080 int32_t RegisterFrameTypeCallback(
81 VCMFrameTypeCallback* frameTypeCallback) override {
pbos0fa9b222015-11-13 05:59:57 -080082 return receiver_.RegisterFrameTypeCallback(frameTypeCallback);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000083 }
84
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000085 int32_t RegisterPacketRequestCallback(
86 VCMPacketRequestCallback* callback) override {
tommid0a71ba2017-03-14 04:16:20 -070087 RTC_DCHECK(construction_thread_.CalledOnValidThread());
pbos0fa9b222015-11-13 05:59:57 -080088 return receiver_.RegisterPacketRequestCallback(callback);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000089 }
90
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000091 int32_t Decode(uint16_t maxWaitTimeMs) override {
pbos0fa9b222015-11-13 05:59:57 -080092 return receiver_.Decode(maxWaitTimeMs);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000093 }
94
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000095 int32_t IncomingPacket(const uint8_t* incomingPayload,
96 size_t payloadLength,
97 const WebRtcRTPHeader& rtpInfo) override {
pbos0fa9b222015-11-13 05:59:57 -080098 return receiver_.IncomingPacket(incomingPayload, payloadLength, rtpInfo);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +000099 }
100
Niels Möller375b3462019-01-10 15:35:56 +0100101 int SetReceiverRobustnessMode(ReceiverRobustness robustnessMode) override {
102 return receiver_.SetReceiverRobustnessMode(robustnessMode);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000103 }
104
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000105 void SetNackSettings(size_t max_nack_list_size,
106 int max_packet_age_to_nack,
107 int max_incomplete_time_ms) override {
pbos0fa9b222015-11-13 05:59:57 -0800108 return receiver_.SetNackSettings(max_nack_list_size, max_packet_age_to_nack,
109 max_incomplete_time_ms);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000110 }
111
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000112 private:
tommid0a71ba2017-03-14 04:16:20 -0700113 rtc::ThreadChecker construction_thread_;
Jiawei Ouc2ebe212018-11-08 10:02:56 -0800114 const std::unique_ptr<VCMTiming> timing_;
pbos0fa9b222015-11-13 05:59:57 -0800115 vcm::VideoReceiver receiver_;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28 +0000116};
117} // namespace
118
tommia5c18d72017-03-20 10:43:23 -0700119// DEPRECATED. Create method for current interface, will be removed when the
philipel83f831a2016-03-12 03:30:23 -0800120// new jitter buffer is in place.
Niels Möller689983f2018-11-07 16:36:22 +0100121VideoCodingModule* VideoCodingModule::Create(Clock* clock) {
tommid0a71ba2017-03-14 04:16:20 -0700122 RTC_DCHECK(clock);
Niels Möllerc4e98252018-11-08 13:08:26 +0100123 return new VideoCodingModuleImpl(clock, nullptr, nullptr);
niklase@google.com470e71d2011-07-07 08:21:25 +0000124}
125
stefan@webrtc.org791eec72011-10-11 07:53:43 +0000126} // namespace webrtc