[go: nahoru, domu]

blob: 60328eef573f5d7e174e812db7381c0c83f99a0d [file] [log] [blame]
posciakd94b2b082015-09-18 04:03:401// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
markdittmer6e70beb82016-05-02 05:40:475#include "media/gpu/vp9_decoder.h"
mostynb6682b1c42016-04-19 10:17:306
7#include <memory>
8
posciak77118c92016-08-28 13:18:399#include "base/bind.h"
Hirokazu Honda10df95d2019-07-19 19:31:4310#include "base/feature_list.h"
mostynb6682b1c42016-04-19 10:17:3011#include "base/logging.h"
Hirokazu Honda967b9192019-08-27 00:59:4212#include "build/build_config.h"
Yuta Hijikata29f67812020-10-24 01:15:4413#include "build/chromeos_buildflags.h"
posciakd94b2b082015-09-18 04:03:4014#include "media/base/limits.h"
Hirokazu Honda10df95d2019-07-19 19:31:4315#include "media/base/media_switches.h"
markdittmer6e70beb82016-05-02 05:40:4716#include "media/gpu/vp9_decoder.h"
posciakd94b2b082015-09-18 04:03:4017
markdittmer6e70beb82016-05-02 05:40:4718namespace media {
posciakd94b2b082015-09-18 04:03:4019
Hirokazu Honda10df95d2019-07-19 19:31:4320namespace {
Hirokazu Hondafb2681c2021-10-29 03:53:5921bool GetSpatialLayerFrameSize(const DecoderBuffer& decoder_buffer,
22 std::vector<uint32_t>& frame_sizes) {
23 frame_sizes.clear();
24
Hirokazu Honda10df95d2019-07-19 19:31:4325 const uint32_t* cue_data =
26 reinterpret_cast<const uint32_t*>(decoder_buffer.side_data());
Hirokazu Hondafb2681c2021-10-29 03:53:5927 if (!cue_data)
28 return true;
29
Hirokazu Hondabbf7f402022-04-04 08:13:4930 bool enable_vp9_ksvc =
Shuhai Pengfe10fd02021-11-11 03:20:5931// On windows, currently only d3d11 supports decoding VP9 kSVC stream, we
32// shouldn't combine the switch kD3D11Vp9kSVCHWDecoding to kVp9kSVCHWDecoding
33// due to we want keep returning false to MediaCapability.
Xiaohan Wangd4983e82022-01-15 06:19:3734#if BUILDFLAG(IS_WIN)
Hirokazu Hondabbf7f402022-04-04 08:13:4935 base::FeatureList::IsEnabled(media::kD3D11Vp9kSVCHWDecoding);
Xiaohan Wangc33487932022-04-22 23:37:2136#elif BUILDFLAG(IS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
Hirokazu Hondabbf7f402022-04-04 08:13:4937 // V4L2 stateless API decoder is not capable of decoding VP9 k-SVC stream.
38 false;
Shuhai Pengfe10fd02021-11-11 03:20:5939#else
Hirokazu Hondabbf7f402022-04-04 08:13:4940 base::FeatureList::IsEnabled(media::kVp9kSVCHWDecoding);
41#endif
42
43 if (!enable_vp9_ksvc) {
Hirokazu Hondafb2681c2021-10-29 03:53:5944 DLOG(ERROR) << "Vp9 k-SVC hardware decoding is disabled";
45 return false;
Hirokazu Honda10df95d2019-07-19 19:31:4346 }
47
48 size_t num_of_layers = decoder_buffer.side_data_size() / sizeof(uint32_t);
49 if (num_of_layers > 3u) {
50 DLOG(WARNING) << "The maximum number of spatial layers in VP9 is three";
Hirokazu Hondafb2681c2021-10-29 03:53:5951 return false;
Hirokazu Honda10df95d2019-07-19 19:31:4352 }
Hirokazu Hondafb2681c2021-10-29 03:53:5953
54 frame_sizes = std::vector<uint32_t>(cue_data, cue_data + num_of_layers);
55 return true;
Hirokazu Honda10df95d2019-07-19 19:31:4356}
Hirokazu Honda7ec32652019-11-22 09:40:2157
58VideoCodecProfile VP9ProfileToVideoCodecProfile(uint8_t profile) {
59 switch (profile) {
60 case 0:
61 return VP9PROFILE_PROFILE0;
62 case 1:
63 return VP9PROFILE_PROFILE1;
64 case 2:
65 return VP9PROFILE_PROFILE2;
66 case 3:
67 return VP9PROFILE_PROFILE3;
68 default:
69 return VIDEO_CODEC_PROFILE_UNKNOWN;
70 }
71}
72
Hirokazu Honda963303782020-12-03 05:57:0473bool IsValidBitDepth(uint8_t bit_depth, VideoCodecProfile profile) {
74 // Spec 7.2.
75 switch (profile) {
76 case VP9PROFILE_PROFILE0:
77 case VP9PROFILE_PROFILE1:
78 return bit_depth == 8u;
79 case VP9PROFILE_PROFILE2:
80 case VP9PROFILE_PROFILE3:
81 return bit_depth == 10u || bit_depth == 12u;
82 default:
83 NOTREACHED();
84 return false;
85 }
86}
Hirokazu Honda790d98e2020-12-04 03:41:4887
88bool IsYUV420Sequence(const Vp9FrameHeader& frame_header) {
89 // Spec 7.2.2
90 return frame_header.subsampling_x == 1u && frame_header.subsampling_y == 1u;
91}
Hirokazu Honda10df95d2019-07-19 19:31:4392} // namespace
93
posciakd94b2b082015-09-18 04:03:4094VP9Decoder::VP9Accelerator::VP9Accelerator() {}
95
96VP9Decoder::VP9Accelerator::~VP9Accelerator() {}
97
Miguel Casas71b9dc42022-03-05 02:45:4198bool VP9Decoder::VP9Accelerator::SupportsContextProbabilityReadback() const {
99 return false;
100}
101
Fredrik Hubinette3cebc622018-10-27 01:01:12102VP9Decoder::VP9Decoder(std::unique_ptr<VP9Accelerator> accelerator,
Hirokazu Honda7ec32652019-11-22 09:40:21103 VideoCodecProfile profile,
Fredrik Hubinette3cebc622018-10-27 01:01:12104 const VideoColorSpace& container_color_space)
posciak77118c92016-08-28 13:18:39105 : state_(kNeedStreamMetadata),
Fredrik Hubinette3cebc622018-10-27 01:01:12106 container_color_space_(container_color_space),
Hirokazu Honda7ec32652019-11-22 09:40:21107 // TODO(hiroh): Set profile to UNKNOWN.
108 profile_(profile),
Miguel Casas2d5ecad82018-02-22 19:03:05109 accelerator_(std::move(accelerator)),
Miguel Casas4eab0212022-03-13 17:32:52110 parser_(accelerator_->NeedsCompressedHeaderParsed(),
Miguel Casas71b9dc42022-03-05 02:45:41111 accelerator_->SupportsContextProbabilityReadback()) {}
posciakd94b2b082015-09-18 04:03:40112
Miguel Casas2d5ecad82018-02-22 19:03:05113VP9Decoder::~VP9Decoder() = default;
posciakd94b2b082015-09-18 04:03:40114
Hirokazu Honda23132c32019-07-09 14:31:20115void VP9Decoder::SetStream(int32_t id, const DecoderBuffer& decoder_buffer) {
116 const uint8_t* ptr = decoder_buffer.data();
117 const size_t size = decoder_buffer.data_size();
118 const DecryptConfig* decrypt_config = decoder_buffer.decrypt_config();
119
posciakd94b2b082015-09-18 04:03:40120 DCHECK(ptr);
121 DCHECK(size);
Pawel Osciakec6e21b2018-03-19 09:13:06122 DVLOG(4) << "New input stream id: " << id << " at: " << (void*)ptr
123 << " size: " << size;
124 stream_id_ = id;
Hirokazu Hondafb2681c2021-10-29 03:53:59125 std::vector<uint32_t> frame_sizes;
126 if (!GetSpatialLayerFrameSize(decoder_buffer, frame_sizes)) {
127 SetError();
128 return;
Ted Meyer0b35c5fd2018-11-27 22:29:29129 }
Hirokazu Hondafb2681c2021-10-29 03:53:59130
131 parser_.SetStream(ptr, size, frame_sizes,
132 decrypt_config ? decrypt_config->Clone() : nullptr);
posciakd94b2b082015-09-18 04:03:40133}
134
135bool VP9Decoder::Flush() {
136 DVLOG(2) << "Decoder flush";
137 Reset();
138 return true;
139}
140
141void VP9Decoder::Reset() {
142 curr_frame_hdr_ = nullptr;
Jeffrey Kardatzke48ebdb692021-01-11 22:05:02143 decrypt_config_.reset();
Jeffrey Kardatzke5e36baf2020-11-20 22:17:13144 pending_pic_.reset();
Sreerenj Balachandran1beb5482019-04-03 03:40:05145
146 ref_frames_.Clear();
posciakd94b2b082015-09-18 04:03:40147
148 parser_.Reset();
149
Jose Lopes24d1cda82020-02-21 13:22:36150 if (state_ == kDecoding) {
posciakd94b2b082015-09-18 04:03:40151 state_ = kAfterReset;
Jose Lopes24d1cda82020-02-21 13:22:36152 }
posciakd94b2b082015-09-18 04:03:40153}
154
155VP9Decoder::DecodeResult VP9Decoder::Decode() {
Jeffrey Kardatzke5e36baf2020-11-20 22:17:13156 while (true) {
Hirokazu Hondafb2681c2021-10-29 03:53:59157 if (state_ == kError)
158 return kDecodeError;
159
Jeffrey Kardatzke5e36baf2020-11-20 22:17:13160 // If we have a pending picture to decode, try that first.
161 if (pending_pic_) {
Jeffrey Kardatzke4ed4e332020-12-05 00:32:15162 VP9Accelerator::Status status =
163 DecodeAndOutputPicture(std::move(pending_pic_));
Jeffrey Kardatzke5e36baf2020-11-20 22:17:13164 if (status == VP9Accelerator::Status::kFail) {
Jeffrey Kardatzke5e36baf2020-11-20 22:17:13165 SetError();
166 return kDecodeError;
167 }
168 if (status == VP9Accelerator::Status::kTryAgain)
169 return kTryAgain;
Jeffrey Kardatzke5e36baf2020-11-20 22:17:13170 }
171
posciakd94b2b082015-09-18 04:03:40172 // Read a new frame header if one is not awaiting decoding already.
173 if (!curr_frame_hdr_) {
Hirokazu Honda10df95d2019-07-19 19:31:43174 gfx::Size allocate_size;
xhwang60f96672016-06-14 21:47:53175 std::unique_ptr<Vp9FrameHeader> hdr(new Vp9FrameHeader());
Ted Meyer0b35c5fd2018-11-27 22:29:29176 Vp9Parser::Result res =
Jeffrey Kardatzke48ebdb692021-01-11 22:05:02177 parser_.ParseNextFrame(hdr.get(), &allocate_size, &decrypt_config_);
posciakd94b2b082015-09-18 04:03:40178 switch (res) {
xhwang60f96672016-06-14 21:47:53179 case Vp9Parser::kOk:
brusi_roy8e7155962016-09-14 18:22:58180 curr_frame_hdr_ = std::move(hdr);
Hirokazu Honda10df95d2019-07-19 19:31:43181 curr_frame_size_ = allocate_size;
posciakd94b2b082015-09-18 04:03:40182 break;
183
xhwang60f96672016-06-14 21:47:53184 case Vp9Parser::kEOStream:
posciakd94b2b082015-09-18 04:03:40185 return kRanOutOfStreamData;
186
xhwang60f96672016-06-14 21:47:53187 case Vp9Parser::kInvalidStream:
posciakd94b2b082015-09-18 04:03:40188 DVLOG(1) << "Error parsing stream";
189 SetError();
190 return kDecodeError;
kcwue5a9a6292016-08-17 03:40:02191
192 case Vp9Parser::kAwaitingRefresh:
posciak77118c92016-08-28 13:18:39193 DVLOG(4) << "Awaiting context update";
194 return kNeedContextUpdate;
posciakd94b2b082015-09-18 04:03:40195 }
196 }
197
198 if (state_ != kDecoding) {
199 // Not kDecoding, so we need a resume point (a keyframe), as we are after
200 // reset or at the beginning of the stream. Drop anything that is not
201 // a keyframe in such case, and continue looking for a keyframe.
Sreerenj Balachandran57163302018-11-28 02:45:57202 // Only exception is when the stream/sequence starts with an Intra only
203 // frame.
204 if (curr_frame_hdr_->IsKeyframe() ||
205 (curr_frame_hdr_->IsIntra() && pic_size_.IsEmpty())) {
posciakd94b2b082015-09-18 04:03:40206 state_ = kDecoding;
207 } else {
208 curr_frame_hdr_.reset();
Jeffrey Kardatzke48ebdb692021-01-11 22:05:02209 decrypt_config_.reset();
posciakd94b2b082015-09-18 04:03:40210 continue;
211 }
212 }
213
214 if (curr_frame_hdr_->show_existing_frame) {
215 // This frame header only instructs us to display one of the
216 // previously-decoded frames, but has no frame data otherwise. Display
217 // and continue decoding subsequent frames.
kcwue5a9a6292016-08-17 03:40:02218 size_t frame_to_show = curr_frame_hdr_->frame_to_show_map_idx;
Sreerenj Balachandran1beb5482019-04-03 03:40:05219 if (frame_to_show >= kVp9NumRefFrames ||
220 !ref_frames_.GetFrame(frame_to_show)) {
posciakd94b2b082015-09-18 04:03:40221 DVLOG(1) << "Request to show an invalid frame";
222 SetError();
223 return kDecodeError;
224 }
225
Chih-Yu Huangcd5181e2018-10-23 06:33:06226 // Duplicate the VP9Picture and set the current bitstream id to keep the
227 // correct timestamp.
Sreerenj Balachandran1beb5482019-04-03 03:40:05228 scoped_refptr<VP9Picture> pic =
229 ref_frames_.GetFrame(frame_to_show)->Duplicate();
Chih-Yu Huangcd5181e2018-10-23 06:33:06230 if (pic == nullptr) {
231 DVLOG(1) << "Failed to duplicate the VP9Picture.";
232 SetError();
233 return kDecodeError;
234 }
235 pic->set_bitstream_id(stream_id_);
236 if (!accelerator_->OutputPicture(std::move(pic))) {
posciakd94b2b082015-09-18 04:03:40237 SetError();
238 return kDecodeError;
239 }
240
241 curr_frame_hdr_.reset();
Jeffrey Kardatzke48ebdb692021-01-11 22:05:02242 decrypt_config_.reset();
posciakd94b2b082015-09-18 04:03:40243 continue;
244 }
245
Hirokazu Honda10df95d2019-07-19 19:31:43246 gfx::Size new_pic_size = curr_frame_size_;
Hirokazu Honda436cf27b2019-05-21 10:44:39247 gfx::Rect new_render_rect(curr_frame_hdr_->render_width,
248 curr_frame_hdr_->render_height);
Hirokazu Hondacffd0ef2020-02-28 03:32:31249 // For safety, check the validity of render size or leave it as pic size.
Hirokazu Honda436cf27b2019-05-21 10:44:39250 if (!gfx::Rect(new_pic_size).Contains(new_render_rect)) {
251 DVLOG(1) << "Render size exceeds picture size. render size: "
252 << new_render_rect.ToString()
253 << ", picture size: " << new_pic_size.ToString();
Hirokazu Hondacffd0ef2020-02-28 03:32:31254 new_render_rect = gfx::Rect(new_pic_size);
Hirokazu Honda436cf27b2019-05-21 10:44:39255 }
Hirokazu Honda7ec32652019-11-22 09:40:21256 VideoCodecProfile new_profile =
257 VP9ProfileToVideoCodecProfile(curr_frame_hdr_->profile);
258 if (new_profile == VIDEO_CODEC_PROFILE_UNKNOWN) {
259 VLOG(1) << "Invalid profile: " << curr_frame_hdr_->profile;
260 return kDecodeError;
261 }
Hirokazu Honda963303782020-12-03 05:57:04262 if (!IsValidBitDepth(curr_frame_hdr_->bit_depth, new_profile)) {
263 DVLOG(1) << "Invalid bit depth="
264 << base::strict_cast<int>(curr_frame_hdr_->bit_depth)
265 << ", profile=" << GetProfileName(new_profile);
266 return kDecodeError;
267 }
Hirokazu Honda790d98e2020-12-04 03:41:48268 if (!IsYUV420Sequence(*curr_frame_hdr_)) {
269 DVLOG(1) << "Only YUV 4:2:0 is supported";
270 return kDecodeError;
271 }
posciakd94b2b082015-09-18 04:03:40272
Hirokazu Honda436cf27b2019-05-21 10:44:39273 DCHECK(!new_pic_size.IsEmpty());
Hirokazu Honda963303782020-12-03 05:57:04274 if (new_pic_size != pic_size_ || new_profile != profile_ ||
275 curr_frame_hdr_->bit_depth != bit_depth_) {
Hirokazu Honda7ec32652019-11-22 09:40:21276 DVLOG(1) << "New profile: " << GetProfileName(new_profile)
Hirokazu Honda963303782020-12-03 05:57:04277 << ", New resolution: " << new_pic_size.ToString()
278 << ", New bit depth: "
279 << base::strict_cast<int>(curr_frame_hdr_->bit_depth);
posciakd94b2b082015-09-18 04:03:40280
Sreerenj Balachandran57163302018-11-28 02:45:57281 if (!curr_frame_hdr_->IsKeyframe() &&
Hirokazu Honda7ec32652019-11-22 09:40:21282 !(curr_frame_hdr_->IsIntra() && pic_size_.IsEmpty())) {
posciakd94b2b082015-09-18 04:03:40283 // TODO(posciak): This is doable, but requires a few modifications to
284 // VDA implementations to allow multiple picture buffer sets in flight.
Dongseong Hwang4f20ebb2018-06-07 00:28:20285 // http://crbug.com/832264
Sreerenj Balachandran57163302018-11-28 02:45:57286 DVLOG(1) << "Resolution change currently supported for keyframes and "
287 "sequence begins with Intra only when there is no prior "
288 "frames in the context";
Dongseong Hwang4f20ebb2018-06-07 00:28:20289 if (++size_change_failure_counter_ > kVPxMaxNumOfSizeChangeFailures) {
290 SetError();
291 return kDecodeError;
292 }
293
294 curr_frame_hdr_.reset();
Jeffrey Kardatzke48ebdb692021-01-11 22:05:02295 decrypt_config_.reset();
Dongseong Hwang4f20ebb2018-06-07 00:28:20296 return kRanOutOfStreamData;
posciakd94b2b082015-09-18 04:03:40297 }
298
299 // TODO(posciak): This requires us to be on a keyframe (see above) and is
300 // required, because VDA clients expect all surfaces to be returned before
Hirokazu Honda7ec32652019-11-22 09:40:21301 // they can cycle surface sets after receiving kConfigChange.
posciakd94b2b082015-09-18 04:03:40302 // This is only an implementation detail of VDAs and can be improved.
Sreerenj Balachandran1beb5482019-04-03 03:40:05303 ref_frames_.Clear();
posciakd94b2b082015-09-18 04:03:40304
305 pic_size_ = new_pic_size;
Hirokazu Honda436cf27b2019-05-21 10:44:39306 visible_rect_ = new_render_rect;
Hirokazu Honda7ec32652019-11-22 09:40:21307 profile_ = new_profile;
Hirokazu Honda963303782020-12-03 05:57:04308 bit_depth_ = curr_frame_hdr_->bit_depth;
Dongseong Hwang4f20ebb2018-06-07 00:28:20309 size_change_failure_counter_ = 0;
Hirokazu Honda7ec32652019-11-22 09:40:21310 return kConfigChange;
posciakd94b2b082015-09-18 04:03:40311 }
312
Jeffrey Kardatzke4ed4e332020-12-05 00:32:15313 scoped_refptr<VP9Picture> pic = accelerator_->CreateVP9Picture();
314 if (!pic) {
posciakd94b2b082015-09-18 04:03:40315 return kRanOutOfSurfaces;
Jose Lopes24d1cda82020-02-21 13:22:36316 }
johnylin74410872017-06-19 13:05:30317 DVLOG(2) << "Render resolution: " << new_render_rect.ToString();
318
Jeffrey Kardatzke4ed4e332020-12-05 00:32:15319 pic->set_visible_rect(new_render_rect);
320 pic->set_bitstream_id(stream_id_);
Fredrik Hubinette3cebc622018-10-27 01:01:12321
Jeffrey Kardatzke48ebdb692021-01-11 22:05:02322 pic->set_decrypt_config(std::move(decrypt_config_));
Ted Meyer0b35c5fd2018-11-27 22:29:29323
Fredrik Hubinette3cebc622018-10-27 01:01:12324 // For VP9, container color spaces override video stream color spaces.
Jeffrey Kardatzke5e36baf2020-11-20 22:17:13325 if (container_color_space_.IsSpecified())
Jeffrey Kardatzke4ed4e332020-12-05 00:32:15326 pic->set_colorspace(container_color_space_);
Jeffrey Kardatzke5e36baf2020-11-20 22:17:13327 else if (curr_frame_hdr_)
Jeffrey Kardatzke4ed4e332020-12-05 00:32:15328 pic->set_colorspace(curr_frame_hdr_->GetColorSpace());
posciakd94b2b082015-09-18 04:03:40329
Jeffrey Kardatzke4ed4e332020-12-05 00:32:15330 pic->frame_hdr = std::move(curr_frame_hdr_);
Jeffrey Kardatzke5e36baf2020-11-20 22:17:13331
Jeffrey Kardatzke4ed4e332020-12-05 00:32:15332 VP9Accelerator::Status status = DecodeAndOutputPicture(std::move(pic));
Jeffrey Kardatzke5e36baf2020-11-20 22:17:13333 if (status == VP9Accelerator::Status::kFail) {
posciakd94b2b082015-09-18 04:03:40334 SetError();
335 return kDecodeError;
336 }
Jeffrey Kardatzke5e36baf2020-11-20 22:17:13337 if (status == VP9Accelerator::Status::kTryAgain)
338 return kTryAgain;
posciakd94b2b082015-09-18 04:03:40339 }
340}
341
posciak77118c92016-08-28 13:18:39342void VP9Decoder::UpdateFrameContext(
Ted Meyer4fac4f62019-05-08 22:57:15343 scoped_refptr<VP9Picture> pic,
Jose Lopes24d1cda82020-02-21 13:22:36344 Vp9Parser::ContextRefreshCallback context_refresh_cb) {
Dale Curtise25163812018-09-21 22:13:39345 DCHECK(context_refresh_cb);
posciak77118c92016-08-28 13:18:39346 Vp9FrameContext frame_ctx;
347 memset(&frame_ctx, 0, sizeof(frame_ctx));
348
Ted Meyer4fac4f62019-05-08 22:57:15349 if (!accelerator_->GetFrameContext(std::move(pic), &frame_ctx)) {
posciak77118c92016-08-28 13:18:39350 SetError();
351 return;
352 }
353
Jose Lopes24d1cda82020-02-21 13:22:36354 std::move(context_refresh_cb).Run(frame_ctx);
posciak77118c92016-08-28 13:18:39355}
356
Jeffrey Kardatzke5e36baf2020-11-20 22:17:13357VP9Decoder::VP9Accelerator::Status VP9Decoder::DecodeAndOutputPicture(
358 scoped_refptr<VP9Picture> pic) {
posciakd94b2b082015-09-18 04:03:40359 DCHECK(!pic_size_.IsEmpty());
360 DCHECK(pic->frame_hdr);
361
Chih-Yu Huangcc6b1b92019-12-19 08:57:16362 base::OnceClosure done_cb;
Jose Lopes24d1cda82020-02-21 13:22:36363 Vp9Parser::ContextRefreshCallback context_refresh_cb =
posciak77118c92016-08-28 13:18:39364 parser_.GetContextRefreshCb(pic->frame_hdr->frame_context_idx);
Jose Lopes24d1cda82020-02-21 13:22:36365 if (context_refresh_cb) {
366 done_cb =
367 base::BindOnce(&VP9Decoder::UpdateFrameContext, base::Unretained(this),
368 pic, std::move(context_refresh_cb));
369 }
posciak77118c92016-08-28 13:18:39370
371 const Vp9Parser::Context& context = parser_.context();
Jeffrey Kardatzke5e36baf2020-11-20 22:17:13372 VP9Accelerator::Status status = accelerator_->SubmitDecode(
373 pic, context.segmentation(), context.loop_filter(), ref_frames_,
374 std::move(done_cb));
Jeffrey Kardatzke4ed4e332020-12-05 00:32:15375 if (status != VP9Accelerator::Status::kOk) {
376 if (status == VP9Accelerator::Status::kTryAgain)
377 pending_pic_ = std::move(pic);
Jeffrey Kardatzke5e36baf2020-11-20 22:17:13378 return status;
Jeffrey Kardatzke4ed4e332020-12-05 00:32:15379 }
posciakd94b2b082015-09-18 04:03:40380
381 if (pic->frame_hdr->show_frame) {
Jeffrey Kardatzke5e36baf2020-11-20 22:17:13382 if (!accelerator_->OutputPicture(pic))
383 return VP9Accelerator::Status::kFail;
posciakd94b2b082015-09-18 04:03:40384 }
385
Ted Meyer4fac4f62019-05-08 22:57:15386 ref_frames_.Refresh(std::move(pic));
Jeffrey Kardatzke5e36baf2020-11-20 22:17:13387 return status;
posciakd94b2b082015-09-18 04:03:40388}
389
390void VP9Decoder::SetError() {
391 Reset();
392 state_ = kError;
393}
394
395gfx::Size VP9Decoder::GetPicSize() const {
396 return pic_size_;
397}
398
Hirokazu Honda436cf27b2019-05-21 10:44:39399gfx::Rect VP9Decoder::GetVisibleRect() const {
400 return visible_rect_;
401}
402
Hirokazu Honda7ec32652019-11-22 09:40:21403VideoCodecProfile VP9Decoder::GetProfile() const {
404 return profile_;
405}
406
Hirokazu Honda963303782020-12-03 05:57:04407uint8_t VP9Decoder::GetBitDepth() const {
408 return bit_depth_;
409}
410
Qiu Jianlina790b3d2022-07-29 03:09:44411VideoChromaSampling VP9Decoder::GetChromaSampling() const {
412 // VP9 decoder currently does not rely on chroma sampling format for
413 // creating/reconfiguring decoder, so return an unknown format.
414 return VideoChromaSampling::kUnknown;
415}
416
posciakd94b2b082015-09-18 04:03:40417size_t VP9Decoder::GetRequiredNumOfPictures() const {
Miguel Casas477a7062019-01-04 19:13:45418 constexpr size_t kPicsInPipeline = limits::kMaxVideoFrames + 1;
419 return kPicsInPipeline + GetNumReferenceFrames();
420}
421
422size_t VP9Decoder::GetNumReferenceFrames() const {
Miguel Casas3dd7e562019-02-14 17:38:46423 // Maximum number of reference frames
424 return kVp9NumRefFrames;
posciakd94b2b082015-09-18 04:03:40425}
426
markdittmer6e70beb82016-05-02 05:40:47427} // namespace media