From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../video_coding/include/video_codec_initializer.h | 40 ++++++ .../video_coding/include/video_codec_interface.cc | 20 +++ .../video_coding/include/video_codec_interface.h | 118 ++++++++++++++++ .../modules/video_coding/include/video_coding.h | 150 +++++++++++++++++++++ .../video_coding/include/video_coding_defines.h | 97 +++++++++++++ .../video_coding/include/video_error_codes.h | 31 +++++ 6 files changed, 456 insertions(+) create mode 100644 third_party/libwebrtc/modules/video_coding/include/video_codec_initializer.h create mode 100644 third_party/libwebrtc/modules/video_coding/include/video_codec_interface.cc create mode 100644 third_party/libwebrtc/modules/video_coding/include/video_codec_interface.h create mode 100644 third_party/libwebrtc/modules/video_coding/include/video_coding.h create mode 100644 third_party/libwebrtc/modules/video_coding/include/video_coding_defines.h create mode 100644 third_party/libwebrtc/modules/video_coding/include/video_error_codes.h (limited to 'third_party/libwebrtc/modules/video_coding/include') diff --git a/third_party/libwebrtc/modules/video_coding/include/video_codec_initializer.h b/third_party/libwebrtc/modules/video_coding/include/video_codec_initializer.h new file mode 100644 index 0000000000..2d10ee45a8 --- /dev/null +++ b/third_party/libwebrtc/modules/video_coding/include/video_codec_initializer.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. + * + * 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. + */ + +#ifndef MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODEC_INITIALIZER_H_ +#define MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODEC_INITIALIZER_H_ + +#include +#include +#include + +#include "video/config/video_encoder_config.h" + +namespace webrtc { + +class VideoCodec; + +class VideoCodecInitializer { + public: + // Takes a VideoEncoderConfig and the VideoStream configuration and + // translates them into the old school VideoCodec type. + static bool SetupCodec(const VideoEncoderConfig& config, + const std::vector& streams, + VideoCodec* codec); + + private: + static VideoCodec VideoEncoderConfigToVideoCodec( + const VideoEncoderConfig& config, + const std::vector& streams); +}; + +} // namespace webrtc + +#endif // MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODEC_INITIALIZER_H_ diff --git a/third_party/libwebrtc/modules/video_coding/include/video_codec_interface.cc b/third_party/libwebrtc/modules/video_coding/include/video_codec_interface.cc new file mode 100644 index 0000000000..bd033b6c57 --- /dev/null +++ b/third_party/libwebrtc/modules/video_coding/include/video_codec_interface.cc @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2019 The WebRTC project authors. All Rights Reserved. + * + * 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. + */ +#include "modules/video_coding/include/video_codec_interface.h" + +namespace webrtc { +CodecSpecificInfo::CodecSpecificInfo() : codecType(kVideoCodecGeneric) { + memset(&codecSpecific, 0, sizeof(codecSpecific)); +} + +CodecSpecificInfo::CodecSpecificInfo(const CodecSpecificInfo&) = default; +CodecSpecificInfo::~CodecSpecificInfo() = default; + +} // namespace webrtc diff --git a/third_party/libwebrtc/modules/video_coding/include/video_codec_interface.h b/third_party/libwebrtc/modules/video_coding/include/video_codec_interface.h new file mode 100644 index 0000000000..c6522fcc6b --- /dev/null +++ b/third_party/libwebrtc/modules/video_coding/include/video_codec_interface.h @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. + * + * 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. + */ + +#ifndef MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODEC_INTERFACE_H_ +#define MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODEC_INTERFACE_H_ + +#include + +#include "absl/types/optional.h" +#include "api/video/video_frame.h" +#include "api/video_codecs/scalability_mode.h" +#include "api/video_codecs/video_decoder.h" +#include "api/video_codecs/video_encoder.h" +#include "common_video/generic_frame_descriptor/generic_frame_info.h" +#include "modules/video_coding/codecs/h264/include/h264_globals.h" +#include "modules/video_coding/codecs/vp9/include/vp9_globals.h" +#include "modules/video_coding/include/video_error_codes.h" +#include "rtc_base/system/rtc_export.h" + +namespace webrtc { + +// Note: If any pointers are added to this struct, it must be fitted +// with a copy-constructor. See below. +// Hack alert - the code assumes that thisstruct is memset when constructed. +struct CodecSpecificInfoVP8 { + bool nonReference; + uint8_t temporalIdx; + bool layerSync; + int8_t keyIdx; // Negative value to skip keyIdx. + + // Used to generate the list of dependency frames. + // `referencedBuffers` and `updatedBuffers` contain buffer IDs. + // Note that the buffer IDs here have a one-to-one mapping with the actual + // codec buffers, but the exact mapping (i.e. whether 0 refers to Last, + // to Golden or to Arf) is not pre-determined. + // More references may be specified than are strictly necessary, but not less. + // TODO(bugs.webrtc.org/10242): Remove `useExplicitDependencies` once all + // encoder-wrappers are updated. + bool useExplicitDependencies; + static constexpr size_t kBuffersCount = 3; + size_t referencedBuffers[kBuffersCount]; + size_t referencedBuffersCount; + size_t updatedBuffers[kBuffersCount]; + size_t updatedBuffersCount; +}; +static_assert(std::is_pod::value, ""); + +// Hack alert - the code assumes that thisstruct is memset when constructed. +struct CodecSpecificInfoVP9 { + bool first_frame_in_picture; // First frame, increment picture_id. + bool inter_pic_predicted; // This layer frame is dependent on previously + // coded frame(s). + bool flexible_mode; + bool ss_data_available; + bool non_ref_for_inter_layer_pred; + + uint8_t temporal_idx; + bool temporal_up_switch; + bool inter_layer_predicted; // Frame is dependent on directly lower spatial + // layer frame. + uint8_t gof_idx; + + // SS data. + size_t num_spatial_layers; // Always populated. + size_t first_active_layer; + bool spatial_layer_resolution_present; + uint16_t width[kMaxVp9NumberOfSpatialLayers]; + uint16_t height[kMaxVp9NumberOfSpatialLayers]; + GofInfoVP9 gof; + + // Frame reference data. + uint8_t num_ref_pics; + uint8_t p_diff[kMaxVp9RefPics]; +}; +static_assert(std::is_pod::value, ""); + +// Hack alert - the code assumes that thisstruct is memset when constructed. +struct CodecSpecificInfoH264 { + H264PacketizationMode packetization_mode; + uint8_t temporal_idx; + bool base_layer_sync; + bool idr_frame; +}; +static_assert(std::is_pod::value, ""); + +union CodecSpecificInfoUnion { + CodecSpecificInfoVP8 VP8; + CodecSpecificInfoVP9 VP9; + CodecSpecificInfoH264 H264; +}; +static_assert(std::is_pod::value, ""); + +// Note: if any pointers are added to this struct or its sub-structs, it +// must be fitted with a copy-constructor. This is because it is copied +// in the copy-constructor of VCMEncodedFrame. +struct RTC_EXPORT CodecSpecificInfo { + CodecSpecificInfo(); + CodecSpecificInfo(const CodecSpecificInfo&); + ~CodecSpecificInfo(); + + VideoCodecType codecType; + CodecSpecificInfoUnion codecSpecific; + bool end_of_picture = true; + absl::optional generic_frame_info; + absl::optional template_structure; + absl::optional scalability_mode; +}; + +} // namespace webrtc + +#endif // MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODEC_INTERFACE_H_ diff --git a/third_party/libwebrtc/modules/video_coding/include/video_coding.h b/third_party/libwebrtc/modules/video_coding/include/video_coding.h new file mode 100644 index 0000000000..ee9326d9fc --- /dev/null +++ b/third_party/libwebrtc/modules/video_coding/include/video_coding.h @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. + * + * 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. + */ + +#ifndef MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODING_H_ +#define MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODING_H_ + +#include "api/field_trials_view.h" +#include "api/video/video_frame.h" +#include "api/video_codecs/video_decoder.h" +#include "modules/rtp_rtcp/source/rtp_video_header.h" +#include "modules/video_coding/include/video_coding_defines.h" + +namespace webrtc { + +class Clock; +class EncodedImageCallback; +class VideoDecoder; +class VideoEncoder; +struct CodecSpecificInfo; + +class VideoCodingModule { + public: + // DEPRECATED. + static VideoCodingModule* Create( + Clock* clock, + const FieldTrialsView* field_trials = nullptr); + + virtual ~VideoCodingModule() = default; + + /* + * Receiver + */ + + // Register possible receive codecs, can be called multiple times for + // different codecs. + // The module will automatically switch between registered codecs depending on + // the + // payload type of incoming frames. The actual decoder will be created when + // needed. + // + // Input: + // - payload_type : RTP payload type + // - settings : Settings for the decoder to be registered. + // + virtual void RegisterReceiveCodec(uint8_t payload_type, + const VideoDecoder::Settings& settings) = 0; + + // Register an external decoder object. + // + // Input: + // - externalDecoder : Decoder object to be used for decoding frames. + // - payloadType : The payload type which this decoder is bound to. + virtual void RegisterExternalDecoder(VideoDecoder* externalDecoder, + uint8_t payloadType) = 0; + + // Register a receive callback. Will be called whenever there is a new frame + // ready + // for rendering. + // + // Input: + // - receiveCallback : The callback object to be used by the + // module when a + // frame is ready for rendering. + // De-register with a NULL pointer. + // + // Return value : VCM_OK, on success. + // < 0, on error. + virtual int32_t RegisterReceiveCallback( + VCMReceiveCallback* receiveCallback) = 0; + + // Register a frame type request callback. This callback will be called when + // the + // module needs to request specific frame types from the send side. + // + // Input: + // - frameTypeCallback : The callback object to be used by the + // module when + // requesting a specific type of frame from + // the send side. + // De-register with a NULL pointer. + // + // Return value : VCM_OK, on success. + // < 0, on error. + virtual int32_t RegisterFrameTypeCallback( + VCMFrameTypeCallback* frameTypeCallback) = 0; + + // Registers a callback which is called whenever the receive side of the VCM + // encounters holes in the packet sequence and needs packets to be + // retransmitted. + // + // Input: + // - callback : The callback to be registered in the VCM. + // + // Return value : VCM_OK, on success. + // <0, on error. + virtual int32_t RegisterPacketRequestCallback( + VCMPacketRequestCallback* callback) = 0; + + // Waits for the next frame in the jitter buffer to become complete + // (waits no longer than maxWaitTimeMs), then passes it to the decoder for + // decoding. + // Should be called as often as possible to get the most out of the decoder. + // + // Return value : VCM_OK, on success. + // < 0, on error. + virtual int32_t Decode(uint16_t maxWaitTimeMs = 200) = 0; + + // Insert a parsed packet into the receiver side of the module. Will be placed + // in the + // jitter buffer waiting for the frame to become complete. Returns as soon as + // the packet + // has been placed in the jitter buffer. + // + // Input: + // - incomingPayload : Payload of the packet. + // - payloadLength : Length of the payload. + // - rtp_header : The parsed RTP header. + // - video_header : The relevant extensions and payload header. + // + // Return value : VCM_OK, on success. + // < 0, on error. + virtual int32_t IncomingPacket(const uint8_t* incomingPayload, + size_t payloadLength, + const RTPHeader& rtp_header, + const RTPVideoHeader& video_header) = 0; + + // Sets the maximum number of sequence numbers that we are allowed to NACK + // and the oldest sequence number that we will consider to NACK. If a + // sequence number older than `max_packet_age_to_nack` is missing + // a key frame will be requested. A key frame will also be requested if the + // time of incomplete or non-continuous frames in the jitter buffer is above + // `max_incomplete_time_ms`. + virtual void SetNackSettings(size_t max_nack_list_size, + int max_packet_age_to_nack, + int max_incomplete_time_ms) = 0; + + // Runs delayed tasks. Expected to be called periodically. + virtual void Process() = 0; +}; + +} // namespace webrtc + +#endif // MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODING_H_ diff --git a/third_party/libwebrtc/modules/video_coding/include/video_coding_defines.h b/third_party/libwebrtc/modules/video_coding/include/video_coding_defines.h new file mode 100644 index 0000000000..cbd420732c --- /dev/null +++ b/third_party/libwebrtc/modules/video_coding/include/video_coding_defines.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. + * + * 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. + */ + +#ifndef MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODING_DEFINES_H_ +#define MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODING_DEFINES_H_ + +#include +#include + +#include "absl/types/optional.h" +#include "api/video/video_content_type.h" +#include "api/video/video_frame.h" +#include "api/video/video_timing.h" +#include "api/video_codecs/video_decoder.h" + +namespace webrtc { + +// Error codes +#define VCM_FRAME_NOT_READY 3 +#define VCM_MISSING_CALLBACK 1 +#define VCM_OK 0 +#define VCM_GENERAL_ERROR -1 +#define VCM_PARAMETER_ERROR -4 +#define VCM_NO_CODEC_REGISTERED -8 +#define VCM_JITTER_BUFFER_ERROR -9 + +enum { + // Timing frames settings. Timing frames are sent every + // `kDefaultTimingFramesDelayMs`, or if the frame is at least + // `kDefaultOutlierFrameSizePercent` in size of average frame. + kDefaultTimingFramesDelayMs = 200, + kDefaultOutlierFrameSizePercent = 500, + // Maximum number of frames for what we store encode start timing information. + kMaxEncodeStartTimeListSize = 150, +}; + +enum VCMVideoProtection { + kProtectionNack, + kProtectionNackFEC, +}; + +// Callback class used for passing decoded frames which are ready to be +// rendered. +class VCMReceiveCallback { + public: + virtual int32_t FrameToRender(VideoFrame& videoFrame, // NOLINT + absl::optional qp, + TimeDelta decode_time, + VideoContentType content_type, + VideoFrameType frame_type) = 0; + + virtual void OnDroppedFrames(uint32_t frames_dropped); + + // Called when the current receive codec changes. + virtual void OnIncomingPayloadType(int payload_type); + virtual void OnDecoderInfoChanged( + const VideoDecoder::DecoderInfo& decoder_info); + + protected: + virtual ~VCMReceiveCallback() {} +}; + +// Callback class used for telling the user about what frame type needed to +// continue decoding. +// Typically a key frame when the stream has been corrupted in some way. +class VCMFrameTypeCallback { + public: + virtual int32_t RequestKeyFrame() = 0; + + protected: + virtual ~VCMFrameTypeCallback() {} +}; + +// Callback class used for telling the user about which packet sequence numbers +// are currently +// missing and need to be resent. +// TODO(philipel): Deprecate VCMPacketRequestCallback +// and use NackSender instead. +class VCMPacketRequestCallback { + public: + virtual int32_t ResendPackets(const uint16_t* sequenceNumbers, + uint16_t length) = 0; + + protected: + virtual ~VCMPacketRequestCallback() {} +}; + +} // namespace webrtc + +#endif // MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODING_DEFINES_H_ diff --git a/third_party/libwebrtc/modules/video_coding/include/video_error_codes.h b/third_party/libwebrtc/modules/video_coding/include/video_error_codes.h new file mode 100644 index 0000000000..17146ce205 --- /dev/null +++ b/third_party/libwebrtc/modules/video_coding/include/video_error_codes.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * + * 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. + */ + +#ifndef MODULES_VIDEO_CODING_INCLUDE_VIDEO_ERROR_CODES_H_ +#define MODULES_VIDEO_CODING_INCLUDE_VIDEO_ERROR_CODES_H_ + +// NOTE: in sync with video_coding_module_defines.h + +// Define return values + +#define WEBRTC_VIDEO_CODEC_TARGET_BITRATE_OVERSHOOT 5 +#define WEBRTC_VIDEO_CODEC_OK_REQUEST_KEYFRAME 4 +#define WEBRTC_VIDEO_CODEC_NO_OUTPUT 1 +#define WEBRTC_VIDEO_CODEC_OK 0 +#define WEBRTC_VIDEO_CODEC_ERROR -1 +#define WEBRTC_VIDEO_CODEC_MEMORY -3 +#define WEBRTC_VIDEO_CODEC_ERR_PARAMETER -4 +#define WEBRTC_VIDEO_CODEC_TIMEOUT -6 +#define WEBRTC_VIDEO_CODEC_UNINITIALIZED -7 +#define WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE -13 +#define WEBRTC_VIDEO_CODEC_ERR_SIMULCAST_PARAMETERS_NOT_SUPPORTED -15 +#define WEBRTC_VIDEO_CODEC_ENCODER_FAILURE -16 + +#endif // MODULES_VIDEO_CODING_INCLUDE_VIDEO_ERROR_CODES_H_ -- cgit v1.2.3