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