2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-02-06 10:11:25 +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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/video_coding/video_coding_impl.h"
|
2015-12-21 08:23:20 -08:00
|
|
|
|
|
|
|
|
#include <algorithm>
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <memory>
|
2015-12-21 08:23:20 -08:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "api/video/encoded_image.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/video_coding/include/video_codec_interface.h"
|
|
|
|
|
#include "modules/video_coding/timing.h"
|
2021-02-02 10:57:19 +01:00
|
|
|
#include "rtc_base/synchronization/sequence_checker.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "system_wrappers/include/clock.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-01 03:15:08 +00:00
|
|
|
namespace webrtc {
|
2013-09-14 00:25:28 +00:00
|
|
|
namespace vcm {
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-21 08:23:20 -08:00
|
|
|
int64_t VCMProcessTimer::Period() const {
|
|
|
|
|
return _periodMs;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-12-21 08:23:20 -08:00
|
|
|
int64_t VCMProcessTimer::TimeUntilProcess() const {
|
|
|
|
|
const int64_t time_since_process = _clock->TimeInMilliseconds() - _latestMs;
|
|
|
|
|
const int64_t time_until_process = _periodMs - time_since_process;
|
|
|
|
|
return std::max<int64_t>(time_until_process, 0);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-12-21 08:23:20 -08:00
|
|
|
void VCMProcessTimer::Processed() {
|
|
|
|
|
_latestMs = _clock->TimeInMilliseconds();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2013-09-14 00:25:28 +00:00
|
|
|
} // namespace vcm
|
|
|
|
|
|
|
|
|
|
namespace {
|
2014-01-09 08:01:57 +00:00
|
|
|
|
2013-09-14 00:25:28 +00:00
|
|
|
class VideoCodingModuleImpl : public VideoCodingModule {
|
|
|
|
|
public:
|
2019-03-29 14:30:53 +01:00
|
|
|
explicit VideoCodingModuleImpl(Clock* clock)
|
2013-09-14 00:25:28 +00:00
|
|
|
: VideoCodingModule(),
|
2016-12-15 07:10:57 -08:00
|
|
|
timing_(new VCMTiming(clock)),
|
2019-03-29 14:30:53 +01:00
|
|
|
receiver_(clock, timing_.get()) {}
|
2013-09-14 00:25:28 +00:00
|
|
|
|
2019-01-29 22:53:28 +01:00
|
|
|
~VideoCodingModuleImpl() override {}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
int64_t TimeUntilNextProcess() override {
|
2015-11-13 05:59:57 -08:00
|
|
|
int64_t receiver_time = receiver_.TimeUntilNextProcess();
|
2017-03-14 04:16:20 -07:00
|
|
|
RTC_DCHECK_GE(receiver_time, 0);
|
2017-10-24 11:37:08 +02:00
|
|
|
return receiver_time;
|
2013-09-14 00:25:28 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2018-06-19 15:03:05 +02:00
|
|
|
void Process() override { receiver_.Process(); }
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2020-08-07 16:19:56 +02:00
|
|
|
int32_t RegisterReceiveCodec(uint8_t payload_type,
|
|
|
|
|
const VideoCodec* receiveCodec,
|
|
|
|
|
int32_t numberOfCores) override {
|
|
|
|
|
return receiver_.RegisterReceiveCodec(payload_type, receiveCodec,
|
|
|
|
|
numberOfCores);
|
2013-09-14 00:25:28 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2018-05-18 10:33:04 +02:00
|
|
|
void RegisterExternalDecoder(VideoDecoder* externalDecoder,
|
|
|
|
|
uint8_t payloadType) override {
|
|
|
|
|
receiver_.RegisterExternalDecoder(externalDecoder, payloadType);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
int32_t RegisterReceiveCallback(
|
|
|
|
|
VCMReceiveCallback* receiveCallback) override {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(construction_thread_.IsCurrent());
|
2015-11-13 05:59:57 -08:00
|
|
|
return receiver_.RegisterReceiveCallback(receiveCallback);
|
2013-09-14 00:25:28 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
int32_t RegisterFrameTypeCallback(
|
|
|
|
|
VCMFrameTypeCallback* frameTypeCallback) override {
|
2015-11-13 05:59:57 -08:00
|
|
|
return receiver_.RegisterFrameTypeCallback(frameTypeCallback);
|
2013-09-14 00:25:28 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
int32_t RegisterPacketRequestCallback(
|
|
|
|
|
VCMPacketRequestCallback* callback) override {
|
2019-04-08 15:20:44 +02:00
|
|
|
RTC_DCHECK(construction_thread_.IsCurrent());
|
2015-11-13 05:59:57 -08:00
|
|
|
return receiver_.RegisterPacketRequestCallback(callback);
|
2013-09-14 00:25:28 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
int32_t Decode(uint16_t maxWaitTimeMs) override {
|
2015-11-13 05:59:57 -08:00
|
|
|
return receiver_.Decode(maxWaitTimeMs);
|
2013-09-14 00:25:28 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2019-04-25 10:02:52 +02:00
|
|
|
int32_t IncomingPacket(const uint8_t* incomingPayload,
|
|
|
|
|
size_t payloadLength,
|
|
|
|
|
const RTPHeader& rtp_header,
|
|
|
|
|
const RTPVideoHeader& video_header) override {
|
|
|
|
|
return receiver_.IncomingPacket(incomingPayload, payloadLength, rtp_header,
|
|
|
|
|
video_header);
|
2013-09-14 00:25:28 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-03-04 12:58:35 +00:00
|
|
|
void SetNackSettings(size_t max_nack_list_size,
|
|
|
|
|
int max_packet_age_to_nack,
|
|
|
|
|
int max_incomplete_time_ms) override {
|
2015-11-13 05:59:57 -08:00
|
|
|
return receiver_.SetNackSettings(max_nack_list_size, max_packet_age_to_nack,
|
|
|
|
|
max_incomplete_time_ms);
|
2013-09-14 00:25:28 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-09-14 00:25:28 +00:00
|
|
|
private:
|
2021-02-02 10:57:19 +01:00
|
|
|
SequenceChecker construction_thread_;
|
2018-11-08 10:02:56 -08:00
|
|
|
const std::unique_ptr<VCMTiming> timing_;
|
2015-11-13 05:59:57 -08:00
|
|
|
vcm::VideoReceiver receiver_;
|
2013-09-14 00:25:28 +00:00
|
|
|
};
|
|
|
|
|
} // namespace
|
2011-12-21 20:38:37 +00:00
|
|
|
|
2017-03-20 10:43:23 -07:00
|
|
|
// DEPRECATED. Create method for current interface, will be removed when the
|
2016-03-12 03:30:23 -08:00
|
|
|
// new jitter buffer is in place.
|
2018-11-07 16:36:22 +01:00
|
|
|
VideoCodingModule* VideoCodingModule::Create(Clock* clock) {
|
2017-03-14 04:16:20 -07:00
|
|
|
RTC_DCHECK(clock);
|
2019-03-29 14:30:53 +01:00
|
|
|
return new VideoCodingModuleImpl(clock);
|
2012-08-28 16:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
2011-10-11 07:53:43 +00:00
|
|
|
} // namespace webrtc
|