blob: d74799460cc4e6608b6a291ff251059500bdc08a [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:251/*
pwestin@webrtc.org52fd98d2012-02-13 09:03:532 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:253 *
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 04:47:3111#ifndef MODULES_VIDEO_CODING_VIDEO_CODING_IMPL_H_
12#define MODULES_VIDEO_CODING_VIDEO_CODING_IMPL_H_
niklase@google.com470e71d2011-07-07 08:21:2513
kwiberg3f55dea2016-02-29 13:51:5914#include <memory>
perkj376b1922016-05-02 18:35:2415#include <string>
stefan@webrtc.orgc5300432012-10-08 07:06:5316#include <vector>
17
Erik Språngeee39202018-11-15 16:52:4318#include "absl/types/optional.h"
Artem Titovd15a5752021-02-10 13:31:2419#include "api/sequence_checker.h"
Niels Möllerf9063782018-02-20 15:09:4820#include "modules/video_coding/decoder_database.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3121#include "modules/video_coding/frame_buffer.h"
22#include "modules/video_coding/generic_decoder.h"
Jonas Olssona4d87372019-07-05 17:08:3323#include "modules/video_coding/include/video_coding.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3124#include "modules/video_coding/jitter_buffer.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3125#include "modules/video_coding/receiver.h"
26#include "modules/video_coding/timing.h"
Steve Anton10542f22019-01-11 17:11:0027#include "rtc_base/one_time_event.h"
Markus Handell6deec382020-07-07 10:17:1228#include "rtc_base/synchronization/mutex.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3129#include "rtc_base/thread_annotations.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3130#include "system_wrappers/include/clock.h"
niklase@google.com470e71d2011-07-07 08:21:2531
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2832namespace webrtc {
sprang@webrtc.org40709352013-11-26 11:41:5933
Erik Språng08127a92016-11-16 15:41:3034class VideoBitrateAllocator;
sprang1a646ee2016-12-01 14:34:1135class VideoBitrateAllocationObserver;
Erik Språng08127a92016-11-16 15:41:3036
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2837namespace vcm {
niklase@google.com470e71d2011-07-07 08:21:2538
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2839class VCMProcessTimer {
40 public:
sprang40217c32016-11-21 13:41:5241 static const int64_t kDefaultProcessIntervalMs = 1000;
42
pkasting@chromium.org0b1534c2014-12-15 22:09:4043 VCMProcessTimer(int64_t periodMs, Clock* clock)
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2844 : _clock(clock),
45 _periodMs(periodMs),
46 _latestMs(_clock->TimeInMilliseconds()) {}
pkasting@chromium.org0b1534c2014-12-15 22:09:4047 int64_t Period() const;
48 int64_t TimeUntilProcess() const;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2849 void Processed();
niklase@google.com470e71d2011-07-07 08:21:2550
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2851 private:
52 Clock* _clock;
pkasting@chromium.org0b1534c2014-12-15 22:09:4053 int64_t _periodMs;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2854 int64_t _latestMs;
niklase@google.com470e71d2011-07-07 08:21:2555};
56
Peter Boström0b250722016-04-22 16:23:1557class VideoReceiver : public Module {
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2858 public:
Niels Möllerdb64d992019-03-29 13:30:5359 VideoReceiver(Clock* clock, VCMTiming* timing);
Tommifbf3bce2018-02-21 14:56:0560 ~VideoReceiver() override;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2861
Niels Möller582102c2020-08-07 14:19:5662 int32_t RegisterReceiveCodec(uint8_t payload_type,
63 const VideoCodec* receiveCodec,
Niels Möller18c83d32020-08-07 12:14:4964 int32_t numberOfCores);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2865
Peter Boström795dbe42015-11-27 13:09:0766 void RegisterExternalDecoder(VideoDecoder* externalDecoder,
perkj796cfaf2015-12-10 17:27:3867 uint8_t payloadType);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2868 int32_t RegisterReceiveCallback(VCMReceiveCallback* receiveCallback);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2869 int32_t RegisterFrameTypeCallback(VCMFrameTypeCallback* frameTypeCallback);
70 int32_t RegisterPacketRequestCallback(VCMPacketRequestCallback* callback);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2871
72 int32_t Decode(uint16_t maxWaitTimeMs);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2873
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2874 int32_t IncomingPacket(const uint8_t* incomingPayload,
pkasting@chromium.org4591fbd2014-11-20 22:28:1475 size_t payloadLength,
Niels Möllerbe7a0ec2019-04-25 08:02:5276 const RTPHeader& rtp_header,
77 const RTPVideoHeader& video_header);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2878
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2879 void SetNackSettings(size_t max_nack_list_size,
80 int max_packet_age_to_nack,
81 int max_incomplete_time_ms);
82
Peter Boström0b250722016-04-22 16:23:1583 int64_t TimeUntilNextProcess() override;
84 void Process() override;
Tommifbf3bce2018-02-21 14:56:0585 void ProcessThreadAttached(ProcessThread* process_thread) override;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2886
87 protected:
Tommifbf3bce2018-02-21 14:56:0588 int32_t Decode(const webrtc::VCMEncodedFrame& frame);
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2889 int32_t RequestKeyFrame();
andresp@webrtc.orgf7eb75b2013-09-14 00:25:2890
91 private:
Tommifbf3bce2018-02-21 14:56:0592 // Used for DCHECKing thread correctness.
93 // In build where DCHECKs are enabled, will return false before
94 // DecoderThreadStarting is called, then true until DecoderThreadStopped
95 // is called.
96 // In builds where DCHECKs aren't enabled, it will return true.
97 bool IsDecoderThreadRunning();
98
Artem Titovc8421c42021-02-02 09:57:1999 SequenceChecker construction_thread_checker_;
100 SequenceChecker decoder_thread_checker_;
101 SequenceChecker module_thread_checker_;
pbos@webrtc.org20c1f562014-07-04 10:58:12102 Clock* const clock_;
Markus Handell6deec382020-07-07 10:17:12103 Mutex process_mutex_;
philipel721d4022016-12-15 15:10:57104 VCMTiming* _timing;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28105 VCMReceiver _receiver;
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28106 VCMDecodedFrameCallback _decodedFrameCallback;
niklase@google.com470e71d2011-07-07 08:21:25107
Tommifbf3bce2018-02-21 14:56:05108 // These callbacks are set on the construction thread before being attached
109 // to the module thread or decoding started, so a lock is not required.
110 VCMFrameTypeCallback* _frameTypeCallback;
Tommifbf3bce2018-02-21 14:56:05111 VCMPacketRequestCallback* _packetRequestCallback;
112
113 // Used on both the module and decoder thread.
Markus Handell6deec382020-07-07 10:17:12114 bool _scheduleKeyRequest RTC_GUARDED_BY(process_mutex_);
115 bool drop_frames_until_keyframe_ RTC_GUARDED_BY(process_mutex_);
sprang3911c262016-04-15 08:24:14116
Tommifbf3bce2018-02-21 14:56:05117 // Modified on the construction thread while not attached to the process
118 // thread. Once attached to the process thread, its value is only read
119 // so a lock is not required.
120 size_t max_nack_list_size_;
Peter Boströmed3277b2016-02-02 14:40:04121
Tommifbf3bce2018-02-21 14:56:05122 // Callbacks are set before the decoder thread starts.
123 // Once the decoder thread has been started, usage of |_codecDataBase| moves
124 // over to the decoder thread.
125 VCMDecoderDataBase _codecDataBase;
Tommifbf3bce2018-02-21 14:56:05126
Tommifbf3bce2018-02-21 14:56:05127 VCMProcessTimer _retransmissionTimer RTC_GUARDED_BY(module_thread_checker_);
128 VCMProcessTimer _keyRequestTimer RTC_GUARDED_BY(module_thread_checker_);
Tommifbf3bce2018-02-21 14:56:05129 ThreadUnsafeOneTimeEvent first_frame_received_
130 RTC_GUARDED_BY(decoder_thread_checker_);
131 // Modified on the construction thread. Can be read without a lock and assumed
132 // to be non-null on the module and decoder threads.
133 ProcessThread* process_thread_ = nullptr;
134 bool is_attached_to_process_thread_
135 RTC_GUARDED_BY(construction_thread_checker_) = false;
niklase@google.com470e71d2011-07-07 08:21:25136};
andresp@webrtc.orgf7eb75b2013-09-14 00:25:28137
138} // namespace vcm
pbos@webrtc.orgd900e8b2013-07-03 15:12:26139} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 04:47:31140#endif // MODULES_VIDEO_CODING_VIDEO_CODING_IMPL_H_