OLD | NEW |
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), accelerator_(accelerator) { |
21 DCHECK(accelerator_); | 21 DCHECK(accelerator_); |
22 ref_frames_.resize(media::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 |
31 DVLOG(4) << "New input stream at: " << (void*)ptr << " size: " << size; | 31 DVLOG(4) << "New input stream at: " << (void*)ptr << " size: " << size; |
32 parser_.SetStream(ptr, size); | 32 parser_.SetStream(ptr, size); |
(...skipping 13 matching lines...) Expand all Loading... |
46 parser_.Reset(); | 46 parser_.Reset(); |
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<media::Vp9FrameHeader> hdr(new media::Vp9FrameHeader()); | 56 std::unique_ptr<Vp9FrameHeader> hdr(new Vp9FrameHeader()); |
57 media::Vp9Parser::Result res = parser_.ParseNextFrame(hdr.get()); | 57 Vp9Parser::Result res = parser_.ParseNextFrame(hdr.get()); |
58 switch (res) { | 58 switch (res) { |
59 case media::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 media::Vp9Parser::kEOStream: | 63 case Vp9Parser::kEOStream: |
64 return kRanOutOfStreamData; | 64 return kRanOutOfStreamData; |
65 | 65 |
66 case media::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 } | 70 } |
71 } | 71 } |
72 | 72 |
73 if (state_ != kDecoding) { | 73 if (state_ != kDecoding) { |
74 // Not kDecoding, so we need a resume point (a keyframe), as we are after | 74 // 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 | 75 // 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. | 76 // a keyframe in such case, and continue looking for a keyframe. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 pic->frame_hdr.reset(curr_frame_hdr_.release()); | 134 pic->frame_hdr.reset(curr_frame_hdr_.release()); |
135 | 135 |
136 if (!DecodeAndOutputPicture(pic)) { | 136 if (!DecodeAndOutputPicture(pic)) { |
137 SetError(); | 137 SetError(); |
138 return kDecodeError; | 138 return kDecodeError; |
139 } | 139 } |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 void VP9Decoder::RefreshReferenceFrames(const scoped_refptr<VP9Picture>& pic) { | 143 void VP9Decoder::RefreshReferenceFrames(const scoped_refptr<VP9Picture>& pic) { |
144 for (size_t i = 0; i < media::kVp9NumRefFrames; ++i) { | 144 for (size_t i = 0; i < kVp9NumRefFrames; ++i) { |
145 DCHECK(!pic->frame_hdr->IsKeyframe() || pic->frame_hdr->RefreshFlag(i)); | 145 DCHECK(!pic->frame_hdr->IsKeyframe() || pic->frame_hdr->RefreshFlag(i)); |
146 if (pic->frame_hdr->RefreshFlag(i)) | 146 if (pic->frame_hdr->RefreshFlag(i)) |
147 ref_frames_[i] = pic; | 147 ref_frames_[i] = pic; |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 bool VP9Decoder::DecodeAndOutputPicture(scoped_refptr<VP9Picture> pic) { | 151 bool VP9Decoder::DecodeAndOutputPicture(scoped_refptr<VP9Picture> pic) { |
152 DCHECK(!pic_size_.IsEmpty()); | 152 DCHECK(!pic_size_.IsEmpty()); |
153 DCHECK(pic->frame_hdr); | 153 DCHECK(pic->frame_hdr); |
154 | 154 |
(...skipping 15 matching lines...) Expand all Loading... |
170 state_ = kError; | 170 state_ = kError; |
171 } | 171 } |
172 | 172 |
173 gfx::Size VP9Decoder::GetPicSize() const { | 173 gfx::Size VP9Decoder::GetPicSize() const { |
174 return pic_size_; | 174 return pic_size_; |
175 } | 175 } |
176 | 176 |
177 size_t VP9Decoder::GetRequiredNumOfPictures() const { | 177 size_t VP9Decoder::GetRequiredNumOfPictures() const { |
178 // kMaxVideoFrames to keep higher level media pipeline populated, +2 for the | 178 // kMaxVideoFrames to keep higher level media pipeline populated, +2 for the |
179 // pictures being parsed and decoded currently. | 179 // pictures being parsed and decoded currently. |
180 return media::limits::kMaxVideoFrames + media::kVp9NumRefFrames + 2; | 180 return limits::kMaxVideoFrames + kVp9NumRefFrames + 2; |
181 } | 181 } |
182 | 182 |
183 } // namespace media | 183 } // namespace media |
OLD | NEW |