1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
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
11 #include "modules/video_coding/video_coding_impl.h"
12
13 #include <algorithm>
14 #include <memory>
15
16 #include "api/video/encoded_image.h"
17 #include "modules/video_coding/include/video_codec_interface.h"
18 #include "modules/video_coding/timing.h"
19 #include "rtc_base/thread_checker.h"
20 #include "system_wrappers/include/clock.h"
21
22 namespace webrtc {
23 namespace vcm {
24
Period() const25 int64_t VCMProcessTimer::Period() const {
26 return _periodMs;
27 }
28
TimeUntilProcess() const29 int64_t VCMProcessTimer::TimeUntilProcess() const {
30 const int64_t time_since_process = _clock->TimeInMilliseconds() - _latestMs;
31 const int64_t time_until_process = _periodMs - time_since_process;
32 return std::max<int64_t>(time_until_process, 0);
33 }
34
Processed()35 void VCMProcessTimer::Processed() {
36 _latestMs = _clock->TimeInMilliseconds();
37 }
38 } // namespace vcm
39
40 namespace {
41
42 class VideoCodingModuleImpl : public VideoCodingModule {
43 public:
VideoCodingModuleImpl(Clock * clock)44 explicit VideoCodingModuleImpl(Clock* clock)
45 : VideoCodingModule(),
46 timing_(new VCMTiming(clock)),
47 receiver_(clock, timing_.get()) {}
48
~VideoCodingModuleImpl()49 ~VideoCodingModuleImpl() override {}
50
TimeUntilNextProcess()51 int64_t TimeUntilNextProcess() override {
52 int64_t receiver_time = receiver_.TimeUntilNextProcess();
53 RTC_DCHECK_GE(receiver_time, 0);
54 return receiver_time;
55 }
56
Process()57 void Process() override { receiver_.Process(); }
58
RegisterReceiveCodec(const VideoCodec * receiveCodec,int32_t numberOfCores,bool requireKeyFrame)59 int32_t RegisterReceiveCodec(const VideoCodec* receiveCodec,
60 int32_t numberOfCores,
61 bool requireKeyFrame) override {
62 return receiver_.RegisterReceiveCodec(receiveCodec, numberOfCores,
63 requireKeyFrame);
64 }
65
RegisterExternalDecoder(VideoDecoder * externalDecoder,uint8_t payloadType)66 void RegisterExternalDecoder(VideoDecoder* externalDecoder,
67 uint8_t payloadType) override {
68 receiver_.RegisterExternalDecoder(externalDecoder, payloadType);
69 }
70
RegisterReceiveCallback(VCMReceiveCallback * receiveCallback)71 int32_t RegisterReceiveCallback(
72 VCMReceiveCallback* receiveCallback) override {
73 RTC_DCHECK(construction_thread_.IsCurrent());
74 return receiver_.RegisterReceiveCallback(receiveCallback);
75 }
76
RegisterFrameTypeCallback(VCMFrameTypeCallback * frameTypeCallback)77 int32_t RegisterFrameTypeCallback(
78 VCMFrameTypeCallback* frameTypeCallback) override {
79 return receiver_.RegisterFrameTypeCallback(frameTypeCallback);
80 }
81
RegisterPacketRequestCallback(VCMPacketRequestCallback * callback)82 int32_t RegisterPacketRequestCallback(
83 VCMPacketRequestCallback* callback) override {
84 RTC_DCHECK(construction_thread_.IsCurrent());
85 return receiver_.RegisterPacketRequestCallback(callback);
86 }
87
Decode(uint16_t maxWaitTimeMs)88 int32_t Decode(uint16_t maxWaitTimeMs) override {
89 return receiver_.Decode(maxWaitTimeMs);
90 }
91
IncomingPacket(const uint8_t * incomingPayload,size_t payloadLength,const RTPHeader & rtp_header,const RTPVideoHeader & video_header)92 int32_t IncomingPacket(const uint8_t* incomingPayload,
93 size_t payloadLength,
94 const RTPHeader& rtp_header,
95 const RTPVideoHeader& video_header) override {
96 return receiver_.IncomingPacket(incomingPayload, payloadLength, rtp_header,
97 video_header);
98 }
99
SetNackSettings(size_t max_nack_list_size,int max_packet_age_to_nack,int max_incomplete_time_ms)100 void SetNackSettings(size_t max_nack_list_size,
101 int max_packet_age_to_nack,
102 int max_incomplete_time_ms) override {
103 return receiver_.SetNackSettings(max_nack_list_size, max_packet_age_to_nack,
104 max_incomplete_time_ms);
105 }
106
107 private:
108 rtc::ThreadChecker construction_thread_;
109 const std::unique_ptr<VCMTiming> timing_;
110 vcm::VideoReceiver receiver_;
111 };
112 } // namespace
113
114 // DEPRECATED. Create method for current interface, will be removed when the
115 // new jitter buffer is in place.
Create(Clock * clock)116 VideoCodingModule* VideoCodingModule::Create(Clock* clock) {
117 RTC_DCHECK(clock);
118 return new VideoCodingModuleImpl(clock);
119 }
120
121 } // namespace webrtc
122