OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_COMMON_GPU_MEDIA_VP8_DECODER_H_ | |
6 #define CONTENT_COMMON_GPU_MEDIA_VP8_DECODER_H_ | |
7 | |
8 #include "base/memory/ref_counted.h" | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "content/common/gpu/media/accelerated_video_decoder.h" | |
11 #include "content/common/gpu/media/vp8_picture.h" | |
12 #include "media/filters/vp8_parser.h" | |
13 | |
14 namespace content { | |
15 | |
16 // Clients of this class are expected to pass raw VP8 stream and are expected | |
17 // to provide an implementation of VP8Accelerator for offloading final steps | |
18 // of the decoding process. | |
19 // | |
20 // This class must be created, called and destroyed on a single thread, and | |
21 // does nothing internally on any other thread. | |
22 class CONTENT_EXPORT VP8Decoder : public AcceleratedVideoDecoder { | |
23 public: | |
24 class CONTENT_EXPORT VP8Accelerator { | |
25 public: | |
26 VP8Accelerator(); | |
27 virtual ~VP8Accelerator(); | |
28 | |
29 // Create a new VP8Picture that the decoder client can use for decoding | |
30 // and pass back to this accelerator for decoding or reference. | |
31 // When the picture is no longer needed by decoder, it will just drop | |
32 // its reference to it, and it may do so at any time. | |
33 // Note that this may return nullptr if accelerator is not able to provide | |
34 // any new pictures at given time. The decoder is expected to handle | |
35 // this situation as normal and return from Decode() with kRanOutOfSurfaces. | |
36 virtual scoped_refptr<VP8Picture> CreateVP8Picture() = 0; | |
37 | |
38 // Submit decode for |pic|, taking as arguments |frame_hdr| with parsed | |
39 // VP8 frame header information for current frame, and using |last_frame|, | |
40 // |golden_frame| and |alt_frame| as references, as per VP8 specification. | |
41 // Note that this runs the decode in hardware. | |
42 // Return true if successful. | |
43 virtual bool SubmitDecode(const scoped_refptr<VP8Picture>& pic, | |
44 const media::Vp8FrameHeader* frame_hdr, | |
45 const scoped_refptr<VP8Picture>& last_frame, | |
46 const scoped_refptr<VP8Picture>& golden_frame, | |
47 const scoped_refptr<VP8Picture>& alt_frame) = 0; | |
48 | |
49 // Schedule output (display) of |pic|. Note that returning from this | |
50 // method does not mean that |pic| has already been outputted (displayed), | |
51 // but guarantees that all pictures will be outputted in the same order | |
52 // as this method was called for them. Decoder may drop its reference | |
53 // to |pic| after calling this method. | |
54 // Return true if successful. | |
55 virtual bool OutputPicture(const scoped_refptr<VP8Picture>& pic) = 0; | |
56 | |
57 private: | |
58 DISALLOW_COPY_AND_ASSIGN(VP8Accelerator); | |
59 }; | |
60 | |
61 VP8Decoder(VP8Accelerator* accelerator); | |
62 ~VP8Decoder() override; | |
63 | |
64 // content::AcceleratedVideoDecoder implementation. | |
65 bool Flush() override WARN_UNUSED_RESULT; | |
66 void Reset() override; | |
67 void SetStream(const uint8_t* ptr, size_t size) override; | |
68 DecodeResult Decode() override WARN_UNUSED_RESULT; | |
69 gfx::Size GetPicSize() const override { return pic_size_; } | |
70 size_t GetRequiredNumOfPictures() const override; | |
71 | |
72 private: | |
73 bool DecodeAndOutputCurrentFrame(); | |
74 void RefreshReferenceFrames(); | |
75 | |
76 enum State { | |
77 kNeedStreamMetadata, // After initialization, need a keyframe. | |
78 kDecoding, // Ready to decode from any point. | |
79 kAfterReset, // After Reset(), need a resume point. | |
80 kError, // Error in decode, can't continue. | |
81 }; | |
82 | |
83 State state_; | |
84 | |
85 media::Vp8Parser parser_; | |
86 | |
87 scoped_ptr<media::Vp8FrameHeader> curr_frame_hdr_; | |
88 scoped_refptr<VP8Picture> curr_pic_; | |
89 scoped_refptr<VP8Picture> last_frame_; | |
90 scoped_refptr<VP8Picture> golden_frame_; | |
91 scoped_refptr<VP8Picture> alt_frame_; | |
92 | |
93 const uint8_t* curr_frame_start_; | |
94 size_t frame_size_; | |
95 | |
96 gfx::Size pic_size_; | |
97 int horizontal_scale_; | |
98 int vertical_scale_; | |
99 | |
100 VP8Accelerator* accelerator_; | |
101 | |
102 DISALLOW_COPY_AND_ASSIGN(VP8Decoder); | |
103 }; | |
104 | |
105 } // namespace content | |
106 | |
107 #endif // CONTENT_COMMON_GPU_MEDIA_VP8_DECODER_H_ | |
OLD | NEW |