2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef MODULES_VIDEO_CODING_GENERIC_DECODER_H_
12 #define MODULES_VIDEO_CODING_GENERIC_DECODER_H_
19 #include "api/field_trials_view.h"
20 #include "api/sequence_checker.h"
21 #include "api/video/encoded_frame.h"
22 #include "api/video_codecs/video_decoder.h"
23 #include "modules/video_coding/encoded_frame.h"
24 #include "modules/video_coding/timing/timing.h"
25 #include "rtc_base/synchronization/mutex.h"
29 class VCMReceiveCallback
;
32 FrameInfo() = default;
33 FrameInfo(const FrameInfo
&) = delete;
34 FrameInfo
& operator=(const FrameInfo
&) = delete;
35 FrameInfo(FrameInfo
&&) = default;
36 FrameInfo
& operator=(FrameInfo
&&) = default;
38 uint32_t rtp_timestamp
;
39 // This is likely not optional, but some inputs seem to sometimes be negative.
40 // TODO(bugs.webrtc.org/13756): See if this can be replaced with Timestamp
41 // once all inputs to this field use Timestamp instead of an integer.
42 absl::optional
<Timestamp
> render_time
;
43 absl::optional
<Timestamp
> decode_start
;
44 VideoRotation rotation
;
45 VideoContentType content_type
;
46 EncodedImage::Timing timing
;
48 RtpPacketInfos packet_infos
;
49 // ColorSpace is not stored here, as it might be modified by decoders.
50 VideoFrameType frame_type
;
53 class VCMDecodedFrameCallback
: public DecodedImageCallback
{
55 VCMDecodedFrameCallback(VCMTiming
* timing
,
57 const FieldTrialsView
& field_trials
);
58 ~VCMDecodedFrameCallback() override
;
59 void SetUserReceiveCallback(VCMReceiveCallback
* receiveCallback
);
60 VCMReceiveCallback
* UserReceiveCallback();
62 int32_t Decoded(VideoFrame
& decodedImage
) override
;
63 int32_t Decoded(VideoFrame
& decodedImage
, int64_t decode_time_ms
) override
;
64 void Decoded(VideoFrame
& decodedImage
,
65 absl::optional
<int32_t> decode_time_ms
,
66 absl::optional
<uint8_t> qp
) override
;
68 void OnDecoderInfoChanged(const VideoDecoder::DecoderInfo
& decoder_info
);
70 void Map(FrameInfo frameInfo
);
71 void ClearTimestampMap();
74 std::pair
<absl::optional
<FrameInfo
>, size_t> FindFrameInfo(
75 uint32_t rtp_timestamp
) RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_
);
77 SequenceChecker construction_thread_
;
79 // This callback must be set before the decoder thread starts running
80 // and must only be unset when external threads (e.g decoder thread)
81 // have been stopped. Due to that, the variable should regarded as const
82 // while there are more than one threads involved, it must be set
83 // from the same thread, and therfore a lock is not required to access it.
84 VCMReceiveCallback
* _receiveCallback
= nullptr;
87 std::deque
<FrameInfo
> frame_infos_
RTC_GUARDED_BY(lock_
);
91 class VCMGenericDecoder
{
93 explicit VCMGenericDecoder(VideoDecoder
* decoder
);
97 * Initialize the decoder with the information from the `settings`
99 bool Configure(const VideoDecoder::Settings
& settings
);
102 * Decode to a raw I420 frame,
104 * inputVideoBuffer reference to encoded video frame
106 // TODO(https://bugs.webrtc.org/9378): Remove VCMEncodedFrame variant
107 // once the usage from code in deprecated/ is gone.
108 int32_t Decode(const VCMEncodedFrame
& inputFrame
, Timestamp now
);
109 int32_t Decode(const EncodedFrame
& inputFrame
, Timestamp now
);
112 * Set decode callback. Deregistering while decoding is illegal.
114 int32_t RegisterDecodeCompleteCallback(VCMDecodedFrameCallback
* callback
);
116 bool IsSameDecoder(VideoDecoder
* decoder
) const {
117 return decoder_
== decoder
;
121 int32_t Decode(const EncodedImage
& frame
,
123 int64_t render_time_ms
);
124 VCMDecodedFrameCallback
* _callback
= nullptr;
125 VideoDecoder
* const decoder_
;
126 VideoContentType _last_keyframe_content_type
;
127 VideoDecoder::DecoderInfo decoder_info_
;
130 } // namespace webrtc
132 #endif // MODULES_VIDEO_CODING_GENERIC_DECODER_H_