blob: 544b8ce4443e390f169535e64b476c1c27e0a99a [file] [log] [blame]
Niels Möllerbe682d42018-03-27 08:31:45 +02001/*
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 Chapovalovecc46ef2021-08-09 15:30:47 +020013#include "absl/types/optional.h"
14#include "api/video/render_resolution.h"
15#include "api/video/video_codec_type.h"
Erik Språngc12f6252021-01-13 21:49:59 +010016#include "rtc_base/strings/string_builder.h"
17
Niels Möllerbe682d42018-03-27 08:31:45 +020018namespace webrtc {
19
20int32_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
26void DecodedImageCallback::Decoded(VideoFrame& decodedImage,
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020027 absl::optional<int32_t> decode_time_ms,
28 absl::optional<uint8_t> qp) {
Niels Möllerbe682d42018-03-27 08:31:45 +020029 Decoded(decodedImage, decode_time_ms.value_or(-1));
30}
31
Erik Språngc12f6252021-01-13 21:49:59 +010032VideoDecoder::DecoderInfo VideoDecoder::GetDecoderInfo() const {
33 DecoderInfo info;
34 info.implementation_name = ImplementationName();
35 return info;
36}
37
Niels Möllerbe682d42018-03-27 08:31:45 +020038const char* VideoDecoder::ImplementationName() const {
39 return "unknown";
40}
41
Erik Språngc12f6252021-01-13 21:49:59 +010042std::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
54bool 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 Chapovalovecc46ef2021-08-09 15:30:47 +020059bool 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
71int32_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öllerbe682d42018-03-27 08:31:45 +020084} // namespace webrtc