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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_VIDEO_CODING_VIDEO_CODING_IMPL_H_
|
|
|
|
|
#define MODULES_VIDEO_CODING_VIDEO_CODING_IMPL_H_
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2022-09-29 14:13:15 +02:00
|
|
|
#include <map>
|
2016-02-29 05:51:59 -08:00
|
|
|
#include <memory>
|
2024-08-29 13:00:40 +00:00
|
|
|
#include <optional>
|
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
|
|
|
|
2022-03-29 11:04:48 +02:00
|
|
|
#include "api/field_trials_view.h"
|
2021-02-10 14:31:24 +01:00
|
|
|
#include "api/sequence_checker.h"
|
2023-03-07 11:20:46 +01:00
|
|
|
#include "modules/video_coding/deprecated/frame_buffer.h"
|
2023-04-17 14:02:49 +02:00
|
|
|
#include "modules/video_coding/deprecated/jitter_buffer.h"
|
2023-05-03 11:08:11 +02:00
|
|
|
#include "modules/video_coding/deprecated/receiver.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/video_coding/generic_decoder.h"
|
|
|
|
|
#include "modules/video_coding/include/video_coding.h"
|
2022-05-25 12:03:35 +02:00
|
|
|
#include "modules/video_coding/timing/timing.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/one_time_event.h"
|
2020-07-07 12:17:12 +02:00
|
|
|
#include "rtc_base/synchronization/mutex.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/thread_annotations.h"
|
|
|
|
|
#include "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;
|
2016-12-01 06:34:11 -08:00
|
|
|
class VideoBitrateAllocationObserver;
|
2016-11-16 16:41:30 +01:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
2022-09-29 14:13:15 +02:00
|
|
|
class DEPRECATED_VCMDecoderDataBase {
|
|
|
|
|
public:
|
|
|
|
|
DEPRECATED_VCMDecoderDataBase();
|
|
|
|
|
DEPRECATED_VCMDecoderDataBase(const DEPRECATED_VCMDecoderDataBase&) = delete;
|
|
|
|
|
DEPRECATED_VCMDecoderDataBase& operator=(
|
|
|
|
|
const DEPRECATED_VCMDecoderDataBase&) = delete;
|
|
|
|
|
~DEPRECATED_VCMDecoderDataBase() = default;
|
|
|
|
|
|
|
|
|
|
// Returns a pointer to the previously registered decoder or nullptr if none
|
|
|
|
|
// was registered for the `payload_type`.
|
|
|
|
|
VideoDecoder* DeregisterExternalDecoder(uint8_t payload_type);
|
|
|
|
|
void RegisterExternalDecoder(uint8_t payload_type,
|
|
|
|
|
VideoDecoder* external_decoder);
|
|
|
|
|
bool IsExternalDecoderRegistered(uint8_t payload_type) const;
|
|
|
|
|
|
|
|
|
|
void RegisterReceiveCodec(uint8_t payload_type,
|
|
|
|
|
const VideoDecoder::Settings& settings);
|
|
|
|
|
bool DeregisterReceiveCodec(uint8_t payload_type);
|
|
|
|
|
|
|
|
|
|
// Returns a decoder specified by frame.PayloadType. The decoded frame
|
|
|
|
|
// callback of the decoder is set to `decoded_frame_callback`. If no such
|
|
|
|
|
// decoder already exists an instance will be created and initialized.
|
|
|
|
|
// nullptr is returned if no decoder with the specified payload type was found
|
|
|
|
|
// and the function failed to create one.
|
|
|
|
|
VCMGenericDecoder* GetDecoder(
|
|
|
|
|
const VCMEncodedFrame& frame,
|
|
|
|
|
VCMDecodedFrameCallback* decoded_frame_callback);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void CreateAndInitDecoder(const VCMEncodedFrame& frame)
|
|
|
|
|
RTC_RUN_ON(decoder_sequence_checker_);
|
|
|
|
|
|
|
|
|
|
SequenceChecker decoder_sequence_checker_;
|
|
|
|
|
|
2024-08-29 13:00:40 +00:00
|
|
|
std::optional<uint8_t> current_payload_type_;
|
|
|
|
|
std::optional<VCMGenericDecoder> current_decoder_
|
2022-09-29 14:13:15 +02:00
|
|
|
RTC_GUARDED_BY(decoder_sequence_checker_);
|
|
|
|
|
// Initialization paramaters for decoders keyed by payload type.
|
|
|
|
|
std::map<uint8_t, VideoDecoder::Settings> decoder_settings_;
|
|
|
|
|
// Decoders keyed by payload type.
|
|
|
|
|
std::map<uint8_t, VideoDecoder*> decoders_
|
|
|
|
|
RTC_GUARDED_BY(decoder_sequence_checker_);
|
|
|
|
|
};
|
|
|
|
|
|
2022-06-22 15:48:36 +02:00
|
|
|
class VideoReceiver {
|
2013-09-14 00:25:28 +00:00
|
|
|
public:
|
2022-03-25 12:43:14 +01:00
|
|
|
VideoReceiver(Clock* clock,
|
|
|
|
|
VCMTiming* timing,
|
2022-03-29 11:04:48 +02:00
|
|
|
const FieldTrialsView& field_trials);
|
2022-06-22 15:48:36 +02:00
|
|
|
~VideoReceiver();
|
2013-09-14 00:25:28 +00:00
|
|
|
|
2021-08-13 18:15:55 +02:00
|
|
|
void RegisterReceiveCodec(uint8_t payload_type,
|
2021-08-13 16:50:37 +02:00
|
|
|
const VideoDecoder::Settings& settings);
|
2013-09-14 00:25:28 +00:00
|
|
|
|
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 RegisterFrameTypeCallback(VCMFrameTypeCallback* frameTypeCallback);
|
|
|
|
|
int32_t RegisterPacketRequestCallback(VCMPacketRequestCallback* callback);
|
|
|
|
|
|
|
|
|
|
int32_t Decode(uint16_t maxWaitTimeMs);
|
|
|
|
|
|
|
|
|
|
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,
|
2019-04-25 10:02:52 +02:00
|
|
|
const RTPHeader& rtp_header,
|
|
|
|
|
const RTPVideoHeader& video_header);
|
2013-09-14 00:25:28 +00:00
|
|
|
|
|
|
|
|
void SetNackSettings(size_t max_nack_list_size,
|
|
|
|
|
int max_packet_age_to_nack,
|
|
|
|
|
int max_incomplete_time_ms);
|
|
|
|
|
|
2022-06-22 15:48:36 +02:00
|
|
|
void Process();
|
2013-09-14 00:25:28 +00:00
|
|
|
|
|
|
|
|
protected:
|
2018-02-21 15:56:05 +01:00
|
|
|
int32_t Decode(const webrtc::VCMEncodedFrame& frame);
|
2013-09-14 00:25:28 +00:00
|
|
|
int32_t RequestKeyFrame();
|
|
|
|
|
|
|
|
|
|
private:
|
2018-02-21 15:56:05 +01:00
|
|
|
// Used for DCHECKing thread correctness.
|
|
|
|
|
// In build where DCHECKs are enabled, will return false before
|
|
|
|
|
// DecoderThreadStarting is called, then true until DecoderThreadStopped
|
|
|
|
|
// is called.
|
|
|
|
|
// In builds where DCHECKs aren't enabled, it will return true.
|
|
|
|
|
bool IsDecoderThreadRunning();
|
|
|
|
|
|
2021-02-02 10:57:19 +01:00
|
|
|
SequenceChecker construction_thread_checker_;
|
|
|
|
|
SequenceChecker decoder_thread_checker_;
|
|
|
|
|
SequenceChecker module_thread_checker_;
|
2014-07-04 10:58:12 +00:00
|
|
|
Clock* const clock_;
|
2020-07-07 12:17:12 +02:00
|
|
|
Mutex process_mutex_;
|
2016-12-15 07:10:57 -08:00
|
|
|
VCMTiming* _timing;
|
2013-09-14 00:25:28 +00:00
|
|
|
VCMReceiver _receiver;
|
|
|
|
|
VCMDecodedFrameCallback _decodedFrameCallback;
|
2016-04-15 01:24:14 -07:00
|
|
|
|
2018-02-21 15:56:05 +01:00
|
|
|
// These callbacks are set on the construction thread before being attached
|
|
|
|
|
// to the module thread or decoding started, so a lock is not required.
|
|
|
|
|
VCMFrameTypeCallback* _frameTypeCallback;
|
|
|
|
|
VCMPacketRequestCallback* _packetRequestCallback;
|
|
|
|
|
|
|
|
|
|
// Used on both the module and decoder thread.
|
2020-07-07 12:17:12 +02:00
|
|
|
bool _scheduleKeyRequest RTC_GUARDED_BY(process_mutex_);
|
|
|
|
|
bool drop_frames_until_keyframe_ RTC_GUARDED_BY(process_mutex_);
|
2016-02-02 15:40:04 +01:00
|
|
|
|
2018-02-21 15:56:05 +01:00
|
|
|
// Modified on the construction thread while not attached to the process
|
|
|
|
|
// thread. Once attached to the process thread, its value is only read
|
|
|
|
|
// so a lock is not required.
|
|
|
|
|
size_t max_nack_list_size_;
|
|
|
|
|
|
|
|
|
|
// Callbacks are set before the decoder thread starts.
|
2021-08-09 13:02:57 +02:00
|
|
|
// Once the decoder thread has been started, usage of `_codecDataBase` moves
|
2018-02-21 15:56:05 +01:00
|
|
|
// over to the decoder thread.
|
2022-09-29 14:13:15 +02:00
|
|
|
DEPRECATED_VCMDecoderDataBase _codecDataBase;
|
2018-02-21 15:56:05 +01:00
|
|
|
|
|
|
|
|
VCMProcessTimer _retransmissionTimer RTC_GUARDED_BY(module_thread_checker_);
|
|
|
|
|
VCMProcessTimer _keyRequestTimer RTC_GUARDED_BY(module_thread_checker_);
|
|
|
|
|
ThreadUnsafeOneTimeEvent first_frame_received_
|
|
|
|
|
RTC_GUARDED_BY(decoder_thread_checker_);
|
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
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_VIDEO_CODING_VIDEO_CODING_IMPL_H_
|