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.
5 #ifndef CONTENT_COMMON_GPU_MEDIA_VP8_DECODER_H_
6 #define CONTENT_COMMON_GPU_MEDIA_VP8_DECODER_H_
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"
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.
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
{
24 class CONTENT_EXPORT VP8Accelerator
{
27 virtual ~VP8Accelerator();
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;
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;
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;
58 DISALLOW_COPY_AND_ASSIGN(VP8Accelerator
);
61 VP8Decoder(VP8Accelerator
* accelerator
);
62 ~VP8Decoder() override
;
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
;
70 size_t GetRequiredNumOfPictures() const override
;
73 bool DecodeAndOutputCurrentFrame();
74 void RefreshReferenceFrames();
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.
85 media::Vp8Parser parser_
;
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_
;
93 const uint8_t* curr_frame_start_
;
97 int horizontal_scale_
;
100 VP8Accelerator
* accelerator_
;
102 DISALLOW_COPY_AND_ASSIGN(VP8Decoder
);
105 } // namespace content
107 #endif // CONTENT_COMMON_GPU_MEDIA_VP8_DECODER_H_