1 // Copyright (c) 2012 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 MEDIA_VIDEO_VIDEO_DECODE_ACCELERATOR_H_
6 #define MEDIA_VIDEO_VIDEO_DECODE_ACCELERATOR_H_
10 #include "base/basictypes.h"
11 #include "media/base/bitstream_buffer.h"
12 #include "media/base/video_decoder_config.h"
13 #include "media/video/picture.h"
14 #include "ui/gfx/size.h"
18 // Video decoder interface.
19 // This interface is extended by the various components that ultimately
20 // implement the backend of PPB_VideoDecode_Dev.
22 // No thread-safety guarantees are implied by the use of RefCountedThreadSafe
24 class MEDIA_EXPORT VideoDecodeAccelerator
25 : public base::RefCountedThreadSafe
<VideoDecodeAccelerator
> {
27 // Enumeration of potential errors generated by the API.
28 // Note: Keep these in sync with PP_VideoDecodeError_Dev.
30 // An operation was attempted during an incompatible decoder state.
32 // Invalid argument was passed to an API method.
34 // Encoded input is unreadable.
36 // A failure occurred at the browser layer or one of its dependencies.
37 // Examples of such failures include GPU hardware failures, GPU driver
38 // failures, GPU library failures, browser programming errors, and so on.
42 // Interface for collaborating with picture interface to provide memory for
43 // output picture and blitting them.
44 // This interface is extended by the various layers that relay messages back
45 // to the plugin, through the PPP_VideoDecode_Dev interface the plugin
47 class MEDIA_EXPORT Client
{
51 // Callback to notify client that decoder has been initialized.
52 virtual void NotifyInitializeDone() = 0;
54 // Callback to tell client how many and what size of buffers to provide.
55 virtual void ProvidePictureBuffers(
56 uint32 requested_num_of_buffers
, const gfx::Size
& dimensions
) = 0;
58 // Callback to dismiss picture buffer that was assigned earlier.
59 virtual void DismissPictureBuffer(int32 picture_buffer_id
) = 0;
61 // Callback to deliver decoded pictures ready to be displayed.
62 virtual void PictureReady(const Picture
& picture
) = 0;
64 // Callback to notify that decoded has decoded the end of the current
66 virtual void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id
) = 0;
68 // Flush completion callback.
69 virtual void NotifyFlushDone() = 0;
71 // Reset completion callback.
72 virtual void NotifyResetDone() = 0;
74 // Callback to notify about decoding errors.
75 virtual void NotifyError(Error error
) = 0;
78 // Video decoder functions.
80 // Initializes the video decoder with specific configuration.
82 // |profile| is the video stream's format profile.
84 // Returns true when command successfully accepted. Otherwise false.
85 virtual bool Initialize(VideoCodecProfile profile
) = 0;
87 // Decodes given bitstream buffer. Once decoder is done with processing
88 // |bitstream_buffer| it will call NotifyEndOfBitstreamBuffer() with the
89 // bitstream buffer id.
91 // |bitstream_buffer| is the input bitstream that is sent for decoding.
92 virtual void Decode(const BitstreamBuffer
& bitstream_buffer
) = 0;
94 // Assigns a set of texture-backed picture buffers to the video decoder.
96 // Ownership of each picture buffer remains with the client, but the client
97 // is not allowed to deallocate the buffer before the DismissPictureBuffer
98 // callback has been initiated for a given buffer.
101 // |buffers| contains the allocated picture buffers for the output.
102 virtual void AssignPictureBuffers(
103 const std::vector
<PictureBuffer
>& buffers
) = 0;
105 // Sends picture buffers to be reused by the decoder. This needs to be called
106 // for each buffer that has been processed so that decoder may know onto which
107 // picture buffers it can write the output to.
110 // |picture_buffer_id| id of the picture buffer that is to be reused.
111 virtual void ReusePictureBuffer(int32 picture_buffer_id
) = 0;
113 // Flushes the decoder: all pending inputs will be decoded and pictures handed
114 // back to the client, followed by NotifyFlushDone() being called on the
115 // client. Can be used to implement "end of stream" notification.
116 virtual void Flush() = 0;
118 // Resets the decoder: all pending inputs are dropped immediately and the
119 // decoder returned to a state ready for further Decode()s, followed by
120 // NotifyResetDone() being called on the client. Can be used to implement
122 virtual void Reset() = 0;
124 // Destroys the decoder: all pending inputs are dropped immediately and the
125 // component is freed. This call may asynchornously free system resources,
126 // but its client-visible effects are synchronous. After this method returns
127 // no more callbacks will be made on the client.
128 virtual void Destroy() = 0;
131 friend class base::RefCountedThreadSafe
<VideoDecodeAccelerator
>;
132 virtual ~VideoDecodeAccelerator();
137 #endif // MEDIA_VIDEO_VIDEO_DECODE_ACCELERATOR_H_