Niels Möller | be682d4 | 2018-03-27 08:31:45 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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 | #include "api/video_codecs/video_decoder.h" |
| 12 | |
Danil Chapovalov | ecc46ef | 2021-08-09 15:30:47 +0200 | [diff] [blame] | 13 | #include "absl/types/optional.h" |
| 14 | #include "api/video/render_resolution.h" |
| 15 | #include "api/video/video_codec_type.h" |
Danil Chapovalov | ba0a306 | 2021-08-13 18:15:55 +0200 | [diff] [blame^] | 16 | #include "rtc_base/checks.h" |
Erik Språng | c12f625 | 2021-01-13 21:49:59 +0100 | [diff] [blame] | 17 | #include "rtc_base/strings/string_builder.h" |
| 18 | |
Niels Möller | be682d4 | 2018-03-27 08:31:45 +0200 | [diff] [blame] | 19 | namespace webrtc { |
| 20 | |
| 21 | int32_t DecodedImageCallback::Decoded(VideoFrame& decodedImage, |
| 22 | int64_t decode_time_ms) { |
| 23 | // The default implementation ignores custom decode time value. |
| 24 | return Decoded(decodedImage); |
| 25 | } |
| 26 | |
| 27 | void DecodedImageCallback::Decoded(VideoFrame& decodedImage, |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 28 | absl::optional<int32_t> decode_time_ms, |
| 29 | absl::optional<uint8_t> qp) { |
Niels Möller | be682d4 | 2018-03-27 08:31:45 +0200 | [diff] [blame] | 30 | Decoded(decodedImage, decode_time_ms.value_or(-1)); |
| 31 | } |
| 32 | |
Erik Språng | c12f625 | 2021-01-13 21:49:59 +0100 | [diff] [blame] | 33 | VideoDecoder::DecoderInfo VideoDecoder::GetDecoderInfo() const { |
| 34 | DecoderInfo info; |
| 35 | info.implementation_name = ImplementationName(); |
| 36 | return info; |
| 37 | } |
| 38 | |
Niels Möller | be682d4 | 2018-03-27 08:31:45 +0200 | [diff] [blame] | 39 | const char* VideoDecoder::ImplementationName() const { |
| 40 | return "unknown"; |
| 41 | } |
| 42 | |
Erik Språng | c12f625 | 2021-01-13 21:49:59 +0100 | [diff] [blame] | 43 | std::string VideoDecoder::DecoderInfo::ToString() const { |
| 44 | char string_buf[2048]; |
| 45 | rtc::SimpleStringBuilder oss(string_buf); |
| 46 | |
| 47 | oss << "DecoderInfo { " |
| 48 | << "prefers_late_decoding = " |
| 49 | << "implementation_name = '" << implementation_name << "', " |
| 50 | << "is_hardware_accelerated = " |
| 51 | << (is_hardware_accelerated ? "true" : "false") << " }"; |
| 52 | return oss.str(); |
| 53 | } |
| 54 | |
| 55 | bool VideoDecoder::DecoderInfo::operator==(const DecoderInfo& rhs) const { |
| 56 | return is_hardware_accelerated == rhs.is_hardware_accelerated && |
| 57 | implementation_name == rhs.implementation_name; |
| 58 | } |
| 59 | |
Danil Chapovalov | ba0a306 | 2021-08-13 18:15:55 +0200 | [diff] [blame^] | 60 | void VideoDecoder::Settings::set_number_of_cores(int value) { |
| 61 | RTC_DCHECK_GT(value, 0); |
| 62 | number_of_cores_ = value; |
| 63 | } |
| 64 | |
Danil Chapovalov | ecc46ef | 2021-08-09 15:30:47 +0200 | [diff] [blame] | 65 | bool VideoDecoder::Configure(const Settings& settings) { |
| 66 | VideoCodec codec_settings = {}; |
| 67 | codec_settings.buffer_pool_size = settings.buffer_pool_size(); |
| 68 | RenderResolution max_resolution = settings.max_render_resolution(); |
| 69 | if (max_resolution.Valid()) { |
| 70 | codec_settings.width = max_resolution.Width(); |
| 71 | codec_settings.height = max_resolution.Height(); |
| 72 | } |
| 73 | codec_settings.codecType = settings.codec_type(); |
| 74 | return InitDecode(&codec_settings, settings.number_of_cores()) >= 0; |
| 75 | } |
| 76 | |
| 77 | int32_t VideoDecoder::InitDecode(const VideoCodec* codec_settings, |
| 78 | int32_t number_of_cores) { |
| 79 | Settings settings; |
| 80 | if (codec_settings != nullptr) { |
| 81 | settings.set_buffer_pool_size(codec_settings->buffer_pool_size); |
| 82 | settings.set_max_render_resolution( |
| 83 | {codec_settings->width, codec_settings->height}); |
| 84 | settings.set_codec_type(codec_settings->codecType); |
| 85 | } |
| 86 | settings.set_number_of_cores(number_of_cores); |
| 87 | return Configure(settings) ? 0 : -1; |
| 88 | } |
| 89 | |
Niels Möller | be682d4 | 2018-03-27 08:31:45 +0200 | [diff] [blame] | 90 | } // namespace webrtc |