Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / media / video / video_decode_accelerator.h
blob63553a9ca2f4a6a75b2dae13d0021412c918aaad
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_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/memory/weak_ptr.h"
12 #include "media/base/bitstream_buffer.h"
13 #include "media/base/video_decoder_config.h"
14 #include "media/video/picture.h"
15 #include "ui/gfx/size.h"
17 namespace media {
19 // Video decoder interface.
20 // This interface is extended by the various components that ultimately
21 // implement the backend of PPB_VideoDecode_Dev.
22 class MEDIA_EXPORT VideoDecodeAccelerator
23 : public base::SupportsWeakPtr<VideoDecodeAccelerator> {
24 public:
25 virtual ~VideoDecodeAccelerator();
27 // Enumeration of potential errors generated by the API.
28 // Note: Keep these in sync with PP_VideoDecodeError_Dev.
29 enum Error {
30 // An operation was attempted during an incompatible decoder state.
31 ILLEGAL_STATE = 1,
32 // Invalid argument was passed to an API method.
33 INVALID_ARGUMENT,
34 // Encoded input is unreadable.
35 UNREADABLE_INPUT,
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.
39 PLATFORM_FAILURE,
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
46 // implements.
47 class MEDIA_EXPORT Client {
48 public:
49 // Callback to notify client that decoder has been initialized.
50 virtual void NotifyInitializeDone() = 0;
52 // Callback to tell client how many and what size of buffers to provide.
53 virtual void ProvidePictureBuffers(uint32 requested_num_of_buffers,
54 const gfx::Size& dimensions,
55 uint32 texture_target) = 0;
57 // Callback to dismiss picture buffer that was assigned earlier.
58 virtual void DismissPictureBuffer(int32 picture_buffer_id) = 0;
60 // Callback to deliver decoded pictures ready to be displayed.
61 virtual void PictureReady(const Picture& picture) = 0;
63 // Callback to notify that decoded has decoded the end of the current
64 // bitstream buffer.
65 virtual void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id) = 0;
67 // Flush completion callback.
68 virtual void NotifyFlushDone() = 0;
70 // Reset completion callback.
71 virtual void NotifyResetDone() = 0;
73 // Callback to notify about decoding errors.
74 virtual void NotifyError(Error error) = 0;
76 protected:
77 virtual ~Client() {}
80 // Video decoder functions.
82 // Initializes the video decoder with specific configuration.
83 // Parameters:
84 // |profile| is the video stream's format profile.
86 // Returns true when command successfully accepted. Otherwise false.
87 virtual bool Initialize(VideoCodecProfile profile) = 0;
89 // Decodes given bitstream buffer. Once decoder is done with processing
90 // |bitstream_buffer| it will call NotifyEndOfBitstreamBuffer() with the
91 // bitstream buffer id.
92 // Parameters:
93 // |bitstream_buffer| is the input bitstream that is sent for decoding.
94 virtual void Decode(const BitstreamBuffer& bitstream_buffer) = 0;
96 // Assigns a set of texture-backed picture buffers to the video decoder.
98 // Ownership of each picture buffer remains with the client, but the client
99 // is not allowed to deallocate the buffer before the DismissPictureBuffer
100 // callback has been initiated for a given buffer.
102 // Parameters:
103 // |buffers| contains the allocated picture buffers for the output.
104 virtual void AssignPictureBuffers(
105 const std::vector<PictureBuffer>& buffers) = 0;
107 // Sends picture buffers to be reused by the decoder. This needs to be called
108 // for each buffer that has been processed so that decoder may know onto which
109 // picture buffers it can write the output to.
111 // Parameters:
112 // |picture_buffer_id| id of the picture buffer that is to be reused.
113 virtual void ReusePictureBuffer(int32 picture_buffer_id) = 0;
115 // Flushes the decoder: all pending inputs will be decoded and pictures handed
116 // back to the client, followed by NotifyFlushDone() being called on the
117 // client. Can be used to implement "end of stream" notification.
118 virtual void Flush() = 0;
120 // Resets the decoder: all pending inputs are dropped immediately and the
121 // decoder returned to a state ready for further Decode()s, followed by
122 // NotifyResetDone() being called on the client. Can be used to implement
123 // "seek".
124 virtual void Reset() = 0;
126 // Destroys the decoder: all pending inputs are dropped immediately and the
127 // component is freed. This call may asynchornously free system resources,
128 // but its client-visible effects are synchronous. After this method returns
129 // no more callbacks will be made on the client. Deletes |this|
130 // unconditionally, so make sure to drop all pointers to it!
131 virtual void Destroy() = 0;
134 } // namespace media
136 #endif // MEDIA_VIDEO_VIDEO_DECODE_ACCELERATOR_H_