Sergey Silkin | 0e42cf7 | 2021-03-15 09:12:57 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 | |
| 11 | #ifndef MODULES_VIDEO_CODING_UTILITY_QP_PARSER_H_ |
| 12 | #define MODULES_VIDEO_CODING_UTILITY_QP_PARSER_H_ |
| 13 | |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 14 | #include <optional> |
| 15 | |
Sergey Silkin | 0e42cf7 | 2021-03-15 09:12:57 | [diff] [blame] | 16 | #include "api/video/video_codec_constants.h" |
| 17 | #include "api/video/video_codec_type.h" |
| 18 | #include "common_video/h264/h264_bitstream_parser.h" |
Qiu Jianlin | ddf6084 | 2023-12-11 08:21:03 | [diff] [blame] | 19 | #ifdef RTC_ENABLE_H265 |
| 20 | #include "common_video/h265/h265_bitstream_parser.h" |
| 21 | #endif |
Sergey Silkin | 0e42cf7 | 2021-03-15 09:12:57 | [diff] [blame] | 22 | #include "rtc_base/synchronization/mutex.h" |
| 23 | |
| 24 | namespace webrtc { |
| 25 | class QpParser { |
| 26 | public: |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 27 | std::optional<uint32_t> Parse(VideoCodecType codec_type, |
| 28 | size_t spatial_idx, |
| 29 | const uint8_t* frame_data, |
| 30 | size_t frame_size); |
Sergey Silkin | 0e42cf7 | 2021-03-15 09:12:57 | [diff] [blame] | 31 | |
| 32 | private: |
| 33 | // A thread safe wrapper for H264 bitstream parser. |
| 34 | class H264QpParser { |
| 35 | public: |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 36 | std::optional<uint32_t> Parse(const uint8_t* frame_data, size_t frame_size); |
Sergey Silkin | 0e42cf7 | 2021-03-15 09:12:57 | [diff] [blame] | 37 | |
| 38 | private: |
| 39 | Mutex mutex_; |
| 40 | H264BitstreamParser bitstream_parser_ RTC_GUARDED_BY(mutex_); |
| 41 | }; |
| 42 | |
| 43 | H264QpParser h264_parsers_[kMaxSimulcastStreams]; |
Qiu Jianlin | ddf6084 | 2023-12-11 08:21:03 | [diff] [blame] | 44 | |
| 45 | #ifdef RTC_ENABLE_H265 |
| 46 | // A thread safe wrapper for H.265 bitstream parser. |
| 47 | class H265QpParser { |
| 48 | public: |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 49 | std::optional<uint32_t> Parse(const uint8_t* frame_data, size_t frame_size); |
Qiu Jianlin | ddf6084 | 2023-12-11 08:21:03 | [diff] [blame] | 50 | |
| 51 | private: |
| 52 | Mutex mutex_; |
| 53 | H265BitstreamParser bitstream_parser_ RTC_GUARDED_BY(mutex_); |
| 54 | }; |
| 55 | |
| 56 | H265QpParser h265_parsers_[kMaxSimulcastStreams]; |
| 57 | #endif |
Sergey Silkin | 0e42cf7 | 2021-03-15 09:12:57 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | } // namespace webrtc |
| 61 | |
| 62 | #endif // MODULES_VIDEO_CODING_UTILITY_QP_PARSER_H_ |