Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: media/gpu/vp9_decoder.cc

Issue 2229353002: V4L2SVDA: Add a VP9Accelerator implementation utilizing the V4L2 VP9 frame API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: compilation fixes Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/gpu/vp9_decoder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/gpu/vp9_decoder.h" 5 #include "media/gpu/vp9_decoder.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "media/base/limits.h" 11 #include "media/base/limits.h"
11 #include "media/gpu/vp9_decoder.h" 12 #include "media/gpu/vp9_decoder.h"
12 13
13 namespace media { 14 namespace media {
14 15
15 VP9Decoder::VP9Accelerator::VP9Accelerator() {} 16 VP9Decoder::VP9Accelerator::VP9Accelerator() {}
16 17
17 VP9Decoder::VP9Accelerator::~VP9Accelerator() {} 18 VP9Decoder::VP9Accelerator::~VP9Accelerator() {}
18 19
19 VP9Decoder::VP9Decoder(VP9Accelerator* accelerator) 20 VP9Decoder::VP9Decoder(VP9Accelerator* accelerator)
20 : state_(kNeedStreamMetadata), parser_(false), accelerator_(accelerator) { 21 : state_(kNeedStreamMetadata),
21 DCHECK(accelerator_); 22 accelerator_(accelerator),
23 parser_(accelerator->IsFrameContextRequired()) {
22 ref_frames_.resize(kVp9NumRefFrames); 24 ref_frames_.resize(kVp9NumRefFrames);
23 } 25 }
24 26
25 VP9Decoder::~VP9Decoder() {} 27 VP9Decoder::~VP9Decoder() {}
26 28
27 void VP9Decoder::SetStream(const uint8_t* ptr, size_t size) { 29 void VP9Decoder::SetStream(const uint8_t* ptr, size_t size) {
28 DCHECK(ptr); 30 DCHECK(ptr);
29 DCHECK(size); 31 DCHECK(size);
30 32
31 DVLOG(4) << "New input stream at: " << (void*)ptr << " size: " << size; 33 DVLOG(4) << "New input stream at: " << (void*)ptr << " size: " << size;
(...skipping 15 matching lines...) Expand all
47 49
48 if (state_ == kDecoding) 50 if (state_ == kDecoding)
49 state_ = kAfterReset; 51 state_ = kAfterReset;
50 } 52 }
51 53
52 VP9Decoder::DecodeResult VP9Decoder::Decode() { 54 VP9Decoder::DecodeResult VP9Decoder::Decode() {
53 while (1) { 55 while (1) {
54 // Read a new frame header if one is not awaiting decoding already. 56 // Read a new frame header if one is not awaiting decoding already.
55 if (!curr_frame_hdr_) { 57 if (!curr_frame_hdr_) {
56 std::unique_ptr<Vp9FrameHeader> hdr(new Vp9FrameHeader()); 58 std::unique_ptr<Vp9FrameHeader> hdr(new Vp9FrameHeader());
57 Vp9Parser::Result res = parser_.ParseNextFrame(hdr.get(), nullptr); 59 Vp9Parser::Result res = parser_.ParseNextFrame(hdr.get());
58 switch (res) { 60 switch (res) {
59 case Vp9Parser::kOk: 61 case Vp9Parser::kOk:
60 curr_frame_hdr_.reset(hdr.release()); 62 curr_frame_hdr_.reset(hdr.release());
61 break; 63 break;
62 64
63 case Vp9Parser::kEOStream: 65 case Vp9Parser::kEOStream:
64 return kRanOutOfStreamData; 66 return kRanOutOfStreamData;
65 67
66 case Vp9Parser::kInvalidStream: 68 case Vp9Parser::kInvalidStream:
67 DVLOG(1) << "Error parsing stream"; 69 DVLOG(1) << "Error parsing stream";
68 SetError(); 70 SetError();
69 return kDecodeError; 71 return kDecodeError;
70 72
71 case Vp9Parser::kAwaitingRefresh: 73 case Vp9Parser::kAwaitingRefresh:
72 NOTREACHED(); 74 DVLOG(4) << "Awaiting context update";
75 return kNeedContextUpdate;
73 } 76 }
74 } 77 }
75 78
76 if (state_ != kDecoding) { 79 if (state_ != kDecoding) {
77 // Not kDecoding, so we need a resume point (a keyframe), as we are after 80 // Not kDecoding, so we need a resume point (a keyframe), as we are after
78 // reset or at the beginning of the stream. Drop anything that is not 81 // reset or at the beginning of the stream. Drop anything that is not
79 // a keyframe in such case, and continue looking for a keyframe. 82 // a keyframe in such case, and continue looking for a keyframe.
80 if (curr_frame_hdr_->IsKeyframe()) { 83 if (curr_frame_hdr_->IsKeyframe()) {
81 state_ = kDecoding; 84 state_ = kDecoding;
82 } else { 85 } else {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 } 148 }
146 149
147 void VP9Decoder::RefreshReferenceFrames(const scoped_refptr<VP9Picture>& pic) { 150 void VP9Decoder::RefreshReferenceFrames(const scoped_refptr<VP9Picture>& pic) {
148 for (size_t i = 0; i < kVp9NumRefFrames; ++i) { 151 for (size_t i = 0; i < kVp9NumRefFrames; ++i) {
149 DCHECK(!pic->frame_hdr->IsKeyframe() || pic->frame_hdr->RefreshFlag(i)); 152 DCHECK(!pic->frame_hdr->IsKeyframe() || pic->frame_hdr->RefreshFlag(i));
150 if (pic->frame_hdr->RefreshFlag(i)) 153 if (pic->frame_hdr->RefreshFlag(i))
151 ref_frames_[i] = pic; 154 ref_frames_[i] = pic;
152 } 155 }
153 } 156 }
154 157
158 void VP9Decoder::UpdateFrameContext(
159 const scoped_refptr<VP9Picture>& pic,
160 const base::Callback<void(const Vp9FrameContext&)>& context_refresh_cb) {
161 DCHECK(!context_refresh_cb.is_null());
162 Vp9FrameContext frame_ctx;
163 memset(&frame_ctx, 0, sizeof(frame_ctx));
164
165 if (!accelerator_->GetFrameContext(pic, &frame_ctx)) {
166 SetError();
167 return;
168 }
169
170 context_refresh_cb.Run(frame_ctx);
171 }
172
155 bool VP9Decoder::DecodeAndOutputPicture(scoped_refptr<VP9Picture> pic) { 173 bool VP9Decoder::DecodeAndOutputPicture(scoped_refptr<VP9Picture> pic) {
156 DCHECK(!pic_size_.IsEmpty()); 174 DCHECK(!pic_size_.IsEmpty());
157 DCHECK(pic->frame_hdr); 175 DCHECK(pic->frame_hdr);
158 176
159 if (!accelerator_->SubmitDecode(pic, parser_.GetSegmentation(), 177 base::Closure done_cb;
160 parser_.GetLoopFilter(), ref_frames_)) 178 const auto& context_refresh_cb =
179 parser_.GetContextRefreshCb(pic->frame_hdr->frame_context_idx);
180 if (!context_refresh_cb.is_null())
181 done_cb = base::Bind(&VP9Decoder::UpdateFrameContext,
182 base::Unretained(this), pic, context_refresh_cb);
183
184 const Vp9Parser::Context& context = parser_.context();
185 if (!accelerator_->SubmitDecode(pic, context.segmentation(),
186 context.loop_filter(), ref_frames_, done_cb))
161 return false; 187 return false;
162 188
163 if (pic->frame_hdr->show_frame) { 189 if (pic->frame_hdr->show_frame) {
164 if (!accelerator_->OutputPicture(pic)) 190 if (!accelerator_->OutputPicture(pic))
165 return false; 191 return false;
166 } 192 }
167 193
168 RefreshReferenceFrames(pic); 194 RefreshReferenceFrames(pic);
169 return true; 195 return true;
170 } 196 }
171 197
172 void VP9Decoder::SetError() { 198 void VP9Decoder::SetError() {
173 Reset(); 199 Reset();
174 state_ = kError; 200 state_ = kError;
175 } 201 }
176 202
177 gfx::Size VP9Decoder::GetPicSize() const { 203 gfx::Size VP9Decoder::GetPicSize() const {
178 return pic_size_; 204 return pic_size_;
179 } 205 }
180 206
181 size_t VP9Decoder::GetRequiredNumOfPictures() const { 207 size_t VP9Decoder::GetRequiredNumOfPictures() const {
182 // kMaxVideoFrames to keep higher level media pipeline populated, +2 for the 208 // kMaxVideoFrames to keep higher level media pipeline populated, +2 for the
183 // pictures being parsed and decoded currently. 209 // pictures being parsed and decoded currently.
184 return limits::kMaxVideoFrames + kVp9NumRefFrames + 2; 210 return limits::kMaxVideoFrames + kVp9NumRefFrames + 2;
185 } 211 }
186 212
187 } // namespace media 213 } // namespace media
OLDNEW
« no previous file with comments | « media/gpu/vp9_decoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698