2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-07-31 15:53:44 +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_GENERIC_DECODER_H_
|
|
|
|
|
#define MODULES_VIDEO_CODING_GENERIC_DECODER_H_
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2022-08-08 11:21:26 +00:00
|
|
|
#include <cstdint>
|
|
|
|
|
#include <deque>
|
2024-10-08 09:19:46 +02:00
|
|
|
#include <optional>
|
2020-05-15 12:24:29 +02:00
|
|
|
#include <string>
|
2022-08-08 11:21:26 +00:00
|
|
|
#include <utility>
|
2017-07-05 16:45:57 -07:00
|
|
|
|
2024-10-08 09:19:46 +02:00
|
|
|
#include "absl/types/variant.h"
|
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-08-25 14:53:44 +02:00
|
|
|
#include "api/video/encoded_frame.h"
|
2021-08-13 16:50:37 +02:00
|
|
|
#include "api/video_codecs/video_decoder.h"
|
2024-10-08 09:19:46 +02:00
|
|
|
#include "common_video/frame_instrumentation_data.h"
|
|
|
|
|
#include "common_video/include/corruption_score_calculator.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/video_coding/encoded_frame.h"
|
2022-05-25 12:03:35 +02:00
|
|
|
#include "modules/video_coding/timing/timing.h"
|
2020-07-07 12:17:12 +02:00
|
|
|
#include "rtc_base/synchronization/mutex.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-21 04:12:39 -08:00
|
|
|
namespace webrtc {
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
class VCMReceiveCallback;
|
|
|
|
|
|
2022-08-08 11:21:26 +00:00
|
|
|
struct FrameInfo {
|
|
|
|
|
FrameInfo() = default;
|
|
|
|
|
FrameInfo(const FrameInfo&) = delete;
|
|
|
|
|
FrameInfo& operator=(const FrameInfo&) = delete;
|
|
|
|
|
FrameInfo(FrameInfo&&) = default;
|
|
|
|
|
FrameInfo& operator=(FrameInfo&&) = default;
|
|
|
|
|
|
|
|
|
|
uint32_t rtp_timestamp;
|
|
|
|
|
// This is likely not optional, but some inputs seem to sometimes be negative.
|
|
|
|
|
// TODO(bugs.webrtc.org/13756): See if this can be replaced with Timestamp
|
|
|
|
|
// once all inputs to this field use Timestamp instead of an integer.
|
2024-08-29 13:00:40 +00:00
|
|
|
std::optional<Timestamp> render_time;
|
|
|
|
|
std::optional<Timestamp> decode_start;
|
2022-08-08 11:21:26 +00:00
|
|
|
VideoRotation rotation;
|
|
|
|
|
VideoContentType content_type;
|
|
|
|
|
EncodedImage::Timing timing;
|
|
|
|
|
int64_t ntp_time_ms;
|
|
|
|
|
RtpPacketInfos packet_infos;
|
|
|
|
|
// ColorSpace is not stored here, as it might be modified by decoders.
|
2023-08-15 10:20:50 +02:00
|
|
|
VideoFrameType frame_type;
|
2024-10-08 09:19:46 +02:00
|
|
|
std::optional<
|
|
|
|
|
absl::variant<FrameInstrumentationSyncData, FrameInstrumentationData>>
|
|
|
|
|
frame_instrumentation_data;
|
2022-08-08 11:21:26 +00:00
|
|
|
};
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-21 04:12:39 -08:00
|
|
|
class VCMDecodedFrameCallback : public DecodedImageCallback {
|
|
|
|
|
public:
|
2024-10-08 09:19:46 +02:00
|
|
|
VCMDecodedFrameCallback(
|
|
|
|
|
VCMTiming* timing,
|
|
|
|
|
Clock* clock,
|
|
|
|
|
const FieldTrialsView& field_trials,
|
|
|
|
|
CorruptionScoreCalculator* corruption_score_calculator);
|
2017-03-14 04:16:20 -07:00
|
|
|
~VCMDecodedFrameCallback() override;
|
|
|
|
|
void SetUserReceiveCallback(VCMReceiveCallback* receiveCallback);
|
|
|
|
|
VCMReceiveCallback* UserReceiveCallback();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-03-14 04:16:20 -07:00
|
|
|
int32_t Decoded(VideoFrame& decodedImage) override;
|
|
|
|
|
int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms) override;
|
|
|
|
|
void Decoded(VideoFrame& decodedImage,
|
2024-08-29 13:00:40 +00:00
|
|
|
std::optional<int32_t> decode_time_ms,
|
|
|
|
|
std::optional<uint8_t> qp) override;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2022-10-14 14:38:31 +00:00
|
|
|
void OnDecoderInfoChanged(const VideoDecoder::DecoderInfo& decoder_info);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2022-08-08 11:21:26 +00:00
|
|
|
void Map(FrameInfo frameInfo);
|
2021-04-09 16:03:22 +02:00
|
|
|
void ClearTimestampMap();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-21 04:12:39 -08:00
|
|
|
private:
|
2024-08-29 13:00:40 +00:00
|
|
|
std::pair<std::optional<FrameInfo>, size_t> FindFrameInfo(
|
2022-08-08 11:21:26 +00:00
|
|
|
uint32_t rtp_timestamp) RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_);
|
|
|
|
|
|
2021-02-02 10:57:19 +01:00
|
|
|
SequenceChecker construction_thread_;
|
2017-03-14 04:16:20 -07:00
|
|
|
Clock* const _clock;
|
|
|
|
|
// This callback must be set before the decoder thread starts running
|
|
|
|
|
// and must only be unset when external threads (e.g decoder thread)
|
|
|
|
|
// have been stopped. Due to that, the variable should regarded as const
|
|
|
|
|
// while there are more than one threads involved, it must be set
|
|
|
|
|
// from the same thread, and therfore a lock is not required to access it.
|
|
|
|
|
VCMReceiveCallback* _receiveCallback = nullptr;
|
2018-02-21 19:38:59 +00:00
|
|
|
VCMTiming* _timing;
|
2020-07-07 12:17:12 +02:00
|
|
|
Mutex lock_;
|
2022-08-08 11:21:26 +00:00
|
|
|
std::deque<FrameInfo> frame_infos_ RTC_GUARDED_BY(lock_);
|
2017-06-19 07:18:55 -07:00
|
|
|
int64_t ntp_offset_;
|
2024-10-08 09:19:46 +02:00
|
|
|
CorruptionScoreCalculator* const corruption_score_calculator_;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
|
|
|
|
|
2015-12-21 04:12:39 -08:00
|
|
|
class VCMGenericDecoder {
|
|
|
|
|
public:
|
2021-08-06 12:30:02 +02:00
|
|
|
explicit VCMGenericDecoder(VideoDecoder* decoder);
|
2015-12-21 04:12:39 -08:00
|
|
|
~VCMGenericDecoder();
|
|
|
|
|
|
|
|
|
|
/**
|
2021-08-13 16:50:37 +02:00
|
|
|
* Initialize the decoder with the information from the `settings`
|
2015-12-21 04:12:39 -08:00
|
|
|
*/
|
2021-08-13 16:50:37 +02:00
|
|
|
bool Configure(const VideoDecoder::Settings& settings);
|
2015-12-21 04:12:39 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Decode to a raw I420 frame,
|
|
|
|
|
*
|
|
|
|
|
* inputVideoBuffer reference to encoded video frame
|
|
|
|
|
*/
|
2023-08-25 14:53:44 +02:00
|
|
|
// TODO(https://bugs.webrtc.org/9378): Remove VCMEncodedFrame variant
|
|
|
|
|
// once the usage from code in deprecated/ is gone.
|
2020-01-16 14:09:33 +01:00
|
|
|
int32_t Decode(const VCMEncodedFrame& inputFrame, Timestamp now);
|
2023-08-25 14:53:44 +02:00
|
|
|
int32_t Decode(const EncodedFrame& inputFrame, Timestamp now);
|
2015-12-21 04:12:39 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set decode callback. Deregistering while decoding is illegal.
|
|
|
|
|
*/
|
|
|
|
|
int32_t RegisterDecodeCompleteCallback(VCMDecodedFrameCallback* callback);
|
|
|
|
|
|
2017-07-05 16:45:57 -07:00
|
|
|
bool IsSameDecoder(VideoDecoder* decoder) const {
|
2021-08-06 12:30:02 +02:00
|
|
|
return decoder_ == decoder;
|
2017-07-05 16:45:57 -07:00
|
|
|
}
|
2015-12-21 04:12:39 -08:00
|
|
|
|
|
|
|
|
private:
|
2023-08-25 14:53:44 +02:00
|
|
|
int32_t Decode(const EncodedImage& frame,
|
|
|
|
|
Timestamp now,
|
2024-10-08 09:19:46 +02:00
|
|
|
int64_t render_time_ms,
|
|
|
|
|
const std::optional<absl::variant<FrameInstrumentationSyncData,
|
|
|
|
|
FrameInstrumentationData>>&
|
|
|
|
|
frame_instrumentation_data);
|
2021-08-06 12:30:02 +02:00
|
|
|
VCMDecodedFrameCallback* _callback = nullptr;
|
|
|
|
|
VideoDecoder* const decoder_;
|
2017-04-11 10:34:31 -07:00
|
|
|
VideoContentType _last_keyframe_content_type;
|
2021-01-13 21:49:59 +01:00
|
|
|
VideoDecoder::DecoderInfo decoder_info_;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
|
|
|
|
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace webrtc
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_VIDEO_CODING_GENERIC_DECODER_H_
|