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

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

Issue 2133993002: Parse VP9 compressed header (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reset curr_frame_info_ when Reset Created 4 years, 4 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') | media/media.gyp » ('j') | 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/logging.h" 9 #include "base/logging.h"
10 #include "media/base/limits.h" 10 #include "media/base/limits.h"
11 #include "media/gpu/vp9_decoder.h" 11 #include "media/gpu/vp9_decoder.h"
12 12
13 namespace media { 13 namespace media {
14 14
15 VP9Decoder::VP9Accelerator::VP9Accelerator() {} 15 VP9Decoder::VP9Accelerator::VP9Accelerator() {}
16 16
17 VP9Decoder::VP9Accelerator::~VP9Accelerator() {} 17 VP9Decoder::VP9Accelerator::~VP9Accelerator() {}
18 18
19 VP9Decoder::VP9Decoder(VP9Accelerator* accelerator) 19 VP9Decoder::VP9Decoder(VP9Accelerator* accelerator)
20 : state_(kNeedStreamMetadata), accelerator_(accelerator) { 20 : state_(kNeedStreamMetadata), parser_(false), accelerator_(accelerator) {
21 DCHECK(accelerator_); 21 DCHECK(accelerator_);
22 ref_frames_.resize(kVp9NumRefFrames); 22 ref_frames_.resize(kVp9NumRefFrames);
23 } 23 }
24 24
25 VP9Decoder::~VP9Decoder() {} 25 VP9Decoder::~VP9Decoder() {}
26 26
27 void VP9Decoder::SetStream(const uint8_t* ptr, size_t size) { 27 void VP9Decoder::SetStream(const uint8_t* ptr, size_t size) {
28 DCHECK(ptr); 28 DCHECK(ptr);
29 DCHECK(size); 29 DCHECK(size);
30 30
(...skipping 16 matching lines...) Expand all
47 47
48 if (state_ == kDecoding) 48 if (state_ == kDecoding)
49 state_ = kAfterReset; 49 state_ = kAfterReset;
50 } 50 }
51 51
52 VP9Decoder::DecodeResult VP9Decoder::Decode() { 52 VP9Decoder::DecodeResult VP9Decoder::Decode() {
53 while (1) { 53 while (1) {
54 // Read a new frame header if one is not awaiting decoding already. 54 // Read a new frame header if one is not awaiting decoding already.
55 if (!curr_frame_hdr_) { 55 if (!curr_frame_hdr_) {
56 std::unique_ptr<Vp9FrameHeader> hdr(new Vp9FrameHeader()); 56 std::unique_ptr<Vp9FrameHeader> hdr(new Vp9FrameHeader());
57 Vp9Parser::Result res = parser_.ParseNextFrame(hdr.get()); 57 Vp9Parser::Result res = parser_.ParseNextFrame(hdr.get(), nullptr);
58 switch (res) { 58 switch (res) {
59 case Vp9Parser::kOk: 59 case Vp9Parser::kOk:
60 curr_frame_hdr_.reset(hdr.release()); 60 curr_frame_hdr_.reset(hdr.release());
61 break; 61 break;
62 62
63 case Vp9Parser::kEOStream: 63 case Vp9Parser::kEOStream:
64 return kRanOutOfStreamData; 64 return kRanOutOfStreamData;
65 65
66 case Vp9Parser::kInvalidStream: 66 case Vp9Parser::kInvalidStream:
67 DVLOG(1) << "Error parsing stream"; 67 DVLOG(1) << "Error parsing stream";
68 SetError(); 68 SetError();
69 return kDecodeError; 69 return kDecodeError;
70
71 case Vp9Parser::kAwaitingRefresh:
72 NOTREACHED();
70 } 73 }
71 } 74 }
72 75
73 if (state_ != kDecoding) { 76 if (state_ != kDecoding) {
74 // Not kDecoding, so we need a resume point (a keyframe), as we are after 77 // Not kDecoding, so we need a resume point (a keyframe), as we are after
75 // reset or at the beginning of the stream. Drop anything that is not 78 // reset or at the beginning of the stream. Drop anything that is not
76 // a keyframe in such case, and continue looking for a keyframe. 79 // a keyframe in such case, and continue looking for a keyframe.
77 if (curr_frame_hdr_->IsKeyframe()) { 80 if (curr_frame_hdr_->IsKeyframe()) {
78 state_ = kDecoding; 81 state_ = kDecoding;
79 } else { 82 } else {
80 curr_frame_hdr_.reset(); 83 curr_frame_hdr_.reset();
81 continue; 84 continue;
82 } 85 }
83 } 86 }
84 87
85 if (curr_frame_hdr_->show_existing_frame) { 88 if (curr_frame_hdr_->show_existing_frame) {
86 // This frame header only instructs us to display one of the 89 // This frame header only instructs us to display one of the
87 // previously-decoded frames, but has no frame data otherwise. Display 90 // previously-decoded frames, but has no frame data otherwise. Display
88 // and continue decoding subsequent frames. 91 // and continue decoding subsequent frames.
89 size_t frame_to_show = curr_frame_hdr_->frame_to_show; 92 size_t frame_to_show = curr_frame_hdr_->frame_to_show_map_idx;
90 if (frame_to_show >= ref_frames_.size() || !ref_frames_[frame_to_show]) { 93 if (frame_to_show >= ref_frames_.size() || !ref_frames_[frame_to_show]) {
91 DVLOG(1) << "Request to show an invalid frame"; 94 DVLOG(1) << "Request to show an invalid frame";
92 SetError(); 95 SetError();
93 return kDecodeError; 96 return kDecodeError;
94 } 97 }
95 98
96 if (!accelerator_->OutputPicture(ref_frames_[frame_to_show])) { 99 if (!accelerator_->OutputPicture(ref_frames_[frame_to_show])) {
97 SetError(); 100 SetError();
98 return kDecodeError; 101 return kDecodeError;
99 } 102 }
100 103
101 curr_frame_hdr_.reset(); 104 curr_frame_hdr_.reset();
102 continue; 105 continue;
103 } 106 }
104 107
105 gfx::Size new_pic_size(curr_frame_hdr_->width, curr_frame_hdr_->height); 108 gfx::Size new_pic_size(curr_frame_hdr_->frame_width,
109 curr_frame_hdr_->frame_height);
106 DCHECK(!new_pic_size.IsEmpty()); 110 DCHECK(!new_pic_size.IsEmpty());
107 111
108 if (new_pic_size != pic_size_) { 112 if (new_pic_size != pic_size_) {
109 DVLOG(1) << "New resolution: " << new_pic_size.ToString(); 113 DVLOG(1) << "New resolution: " << new_pic_size.ToString();
110 114
111 if (!curr_frame_hdr_->IsKeyframe()) { 115 if (!curr_frame_hdr_->IsKeyframe()) {
112 // TODO(posciak): This is doable, but requires a few modifications to 116 // TODO(posciak): This is doable, but requires a few modifications to
113 // VDA implementations to allow multiple picture buffer sets in flight. 117 // VDA implementations to allow multiple picture buffer sets in flight.
114 DVLOG(1) << "Resolution change currently supported for keyframes only"; 118 DVLOG(1) << "Resolution change currently supported for keyframes only";
115 SetError(); 119 SetError();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 return pic_size_; 178 return pic_size_;
175 } 179 }
176 180
177 size_t VP9Decoder::GetRequiredNumOfPictures() const { 181 size_t VP9Decoder::GetRequiredNumOfPictures() const {
178 // kMaxVideoFrames to keep higher level media pipeline populated, +2 for the 182 // kMaxVideoFrames to keep higher level media pipeline populated, +2 for the
179 // pictures being parsed and decoded currently. 183 // pictures being parsed and decoded currently.
180 return limits::kMaxVideoFrames + kVp9NumRefFrames + 2; 184 return limits::kMaxVideoFrames + kVp9NumRefFrames + 2;
181 } 185 }
182 186
183 } // namespace media 187 } // namespace media
OLDNEW
« no previous file with comments | « media/gpu/vp9_decoder.h ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698