| 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_VP9_DECODER_H_ | |
| 6 #define CONTENT_COMMON_GPU_MEDIA_VP9_DECODER_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 | |
| 11 #include <memory> | |
| 12 #include <vector> | |
| 13 | |
| 14 #include "base/macros.h" | |
| 15 #include "base/memory/ref_counted.h" | |
| 16 #include "content/common/gpu/media/accelerated_video_decoder.h" | |
| 17 #include "content/common/gpu/media/vp9_picture.h" | |
| 18 #include "media/filters/vp9_parser.h" | |
| 19 | |
| 20 namespace content { | |
| 21 | |
| 22 // This class implements an AcceleratedVideoDecoder for VP9 decoding. | |
| 23 // Clients of this class are expected to pass raw VP9 stream and are expected | |
| 24 // to provide an implementation of VP9Accelerator for offloading final steps | |
| 25 // of the decoding process. | |
| 26 // | |
| 27 // This class must be created, called and destroyed on a single thread, and | |
| 28 // does nothing internally on any other thread. | |
| 29 class CONTENT_EXPORT VP9Decoder : public AcceleratedVideoDecoder { | |
| 30 public: | |
| 31 class CONTENT_EXPORT VP9Accelerator { | |
| 32 public: | |
| 33 VP9Accelerator(); | |
| 34 virtual ~VP9Accelerator(); | |
| 35 | |
| 36 // Create a new VP9Picture that the decoder client can use for initial | |
| 37 // stages of the decoding process and pass back to this accelerator for | |
| 38 // final, accelerated stages of it, or for reference when decoding other | |
| 39 // pictures. | |
| 40 // | |
| 41 // When a picture is no longer needed by the decoder, it will just drop | |
| 42 // its reference to it, and it may do so at any time. | |
| 43 // | |
| 44 // Note that this may return nullptr if the accelerator is not able to | |
| 45 // provide any new pictures at the given time. The decoder must handle this | |
| 46 // case and treat it as normal, returning kRanOutOfSurfaces from Decode(). | |
| 47 virtual scoped_refptr<VP9Picture> CreateVP9Picture() = 0; | |
| 48 | |
| 49 // Submit decode for |pic| to be run in accelerator, taking as arguments | |
| 50 // information contained in it, as well as current segmentation and loop | |
| 51 // filter state in |seg| and |lf|, respectively, and using pictures in | |
| 52 // |ref_pictures| for reference. | |
| 53 // | |
| 54 // Note that returning from this method does not mean that the decode | |
| 55 // process is finished, but the caller may drop its references to |pic| | |
| 56 // and |ref_pictures| immediately, and the data in |seg| and |lf| does not | |
| 57 // need to remain valid after this method returns. | |
| 58 // | |
| 59 // Return true when successful, false otherwise. | |
| 60 virtual bool SubmitDecode( | |
| 61 const scoped_refptr<VP9Picture>& pic, | |
| 62 const media::Vp9Segmentation& seg, | |
| 63 const media::Vp9LoopFilter& lf, | |
| 64 const std::vector<scoped_refptr<VP9Picture>>& ref_pictures) = 0; | |
| 65 | |
| 66 // Schedule output (display) of |pic|. | |
| 67 // | |
| 68 // Note that returning from this method does not mean that |pic| has already | |
| 69 // been outputted (displayed), but guarantees that all pictures will be | |
| 70 // outputted in the same order as this method was called for them, and that | |
| 71 // they are decoded before outputting (assuming SubmitDecode() has been | |
| 72 // called for them beforehand). Decoder may drop its references to |pic| | |
| 73 // immediately after calling this method. | |
| 74 // | |
| 75 // Return true when successful, false otherwise. | |
| 76 virtual bool OutputPicture(const scoped_refptr<VP9Picture>& pic) = 0; | |
| 77 | |
| 78 private: | |
| 79 DISALLOW_COPY_AND_ASSIGN(VP9Accelerator); | |
| 80 }; | |
| 81 | |
| 82 VP9Decoder(VP9Accelerator* accelerator); | |
| 83 ~VP9Decoder() override; | |
| 84 | |
| 85 // content::AcceleratedVideoDecoder implementation. | |
| 86 void SetStream(const uint8_t* ptr, size_t size) override; | |
| 87 bool Flush() override WARN_UNUSED_RESULT; | |
| 88 void Reset() override; | |
| 89 DecodeResult Decode() override WARN_UNUSED_RESULT; | |
| 90 gfx::Size GetPicSize() const override; | |
| 91 size_t GetRequiredNumOfPictures() const override; | |
| 92 | |
| 93 private: | |
| 94 // Update ref_frames_ based on the information in current frame header. | |
| 95 void RefreshReferenceFrames(const scoped_refptr<VP9Picture>& pic); | |
| 96 | |
| 97 // Decode and possibly output |pic| (if the picture is to be shown). | |
| 98 // Return true on success, false otherwise. | |
| 99 bool DecodeAndOutputPicture(scoped_refptr<VP9Picture> pic); | |
| 100 | |
| 101 // Called on error, when decoding cannot continue. Sets state_ to kError and | |
| 102 // releases current state. | |
| 103 void SetError(); | |
| 104 | |
| 105 enum State { | |
| 106 kNeedStreamMetadata, // After initialization, need a keyframe. | |
| 107 kDecoding, // Ready to decode from any point. | |
| 108 kAfterReset, // After Reset(), need a resume point. | |
| 109 kError, // Error in decode, can't continue. | |
| 110 }; | |
| 111 | |
| 112 // Current decoder state. | |
| 113 State state_; | |
| 114 | |
| 115 // Current frame header to be used in decoding the next picture. | |
| 116 std::unique_ptr<media::Vp9FrameHeader> curr_frame_hdr_; | |
| 117 | |
| 118 // Reference frames currently in use. | |
| 119 std::vector<scoped_refptr<VP9Picture>> ref_frames_; | |
| 120 | |
| 121 // Current coded resolution. | |
| 122 gfx::Size pic_size_; | |
| 123 | |
| 124 media::Vp9Parser parser_; | |
| 125 | |
| 126 // VP9Accelerator instance owned by the client. | |
| 127 VP9Accelerator* accelerator_; | |
| 128 | |
| 129 DISALLOW_COPY_AND_ASSIGN(VP9Decoder); | |
| 130 }; | |
| 131 | |
| 132 } // namespace content | |
| 133 | |
| 134 #endif // CONTENT_COMMON_GPU_MEDIA_VP9_DECODER_H_ | |
| OLD | NEW |