Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / media / video / video_decode_accelerator.h
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.
4
5 #ifndef MEDIA_VIDEO_VIDEO_DECODE_ACCELERATOR_H_
6 #define MEDIA_VIDEO_VIDEO_DECODE_ACCELERATOR_H_
7
8 #include <vector>
9
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"
15
16 namespace media {
17
18 // Video decoder interface.
19 // This interface is extended by the various components that ultimately
20 // implement the backend of PPB_VideoDecode_Dev.
21 class MEDIA_EXPORT VideoDecodeAccelerator {
22  public:
23   virtual ~VideoDecodeAccelerator();
24
25   // Enumeration of potential errors generated by the API.
26   // Note: Keep these in sync with PP_VideoDecodeError_Dev. Also do not
27   // rearrange, reuse or remove values as they are used for gathering UMA
28   // statistics.
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,
40     // Largest used enum. This should be adjusted when new errors are added.
41     LARGEST_ERROR_ENUM,
42   };
43
44   // Interface for collaborating with picture interface to provide memory for
45   // output picture and blitting them. These callbacks will not be made unless
46   // Initialize() has returned successfully.
47   // This interface is extended by the various layers that relay messages back
48   // to the plugin, through the PPP_VideoDecode_Dev interface the plugin
49   // implements.
50   class MEDIA_EXPORT Client {
51    public:
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;
56
57     // Callback to dismiss picture buffer that was assigned earlier.
58     virtual void DismissPictureBuffer(int32 picture_buffer_id) = 0;
59
60     // Callback to deliver decoded pictures ready to be displayed.
61     virtual void PictureReady(const Picture& picture) = 0;
62
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;
66
67     // Flush completion callback.
68     virtual void NotifyFlushDone() = 0;
69
70     // Reset completion callback.
71     virtual void NotifyResetDone() = 0;
72
73     // Callback to notify about decoding errors. Note that errors in
74     // Initialize() will not be reported here, but will instead be indicated by
75     // a false return value there.
76     virtual void NotifyError(Error error) = 0;
77
78    protected:
79     virtual ~Client() {}
80   };
81
82   // Video decoder functions.
83
84   // Initializes the video decoder with specific configuration.  Called once per
85   // decoder construction.  This call is synchronous and returns true iff
86   // initialization is successful.
87   // Parameters:
88   //  |profile| is the video stream's format profile.
89   //  |client| is the client of this video decoder.  The provided pointer must
90   //  be valid until Destroy() is called.
91   virtual bool Initialize(VideoCodecProfile profile, Client* client) = 0;
92
93   // Decodes given bitstream buffer that contains at most one frame.  Once
94   // decoder is done with processing |bitstream_buffer| it will call
95   // NotifyEndOfBitstreamBuffer() with the bitstream buffer id.
96   // Parameters:
97   //  |bitstream_buffer| is the input bitstream that is sent for decoding.
98   virtual void Decode(const BitstreamBuffer& bitstream_buffer) = 0;
99
100   // Assigns a set of texture-backed picture buffers to the video decoder.
101   //
102   // Ownership of each picture buffer remains with the client, but the client
103   // is not allowed to deallocate the buffer before the DismissPictureBuffer
104   // callback has been initiated for a given buffer.
105   //
106   // Parameters:
107   //  |buffers| contains the allocated picture buffers for the output.
108   virtual void AssignPictureBuffers(
109       const std::vector<PictureBuffer>& buffers) = 0;
110
111   // Sends picture buffers to be reused by the decoder. This needs to be called
112   // for each buffer that has been processed so that decoder may know onto which
113   // picture buffers it can write the output to.
114   //
115   // Parameters:
116   //  |picture_buffer_id| id of the picture buffer that is to be reused.
117   virtual void ReusePictureBuffer(int32 picture_buffer_id) = 0;
118
119   // Flushes the decoder: all pending inputs will be decoded and pictures handed
120   // back to the client, followed by NotifyFlushDone() being called on the
121   // client.  Can be used to implement "end of stream" notification.
122   virtual void Flush() = 0;
123
124   // Resets the decoder: all pending inputs are dropped immediately and the
125   // decoder returned to a state ready for further Decode()s, followed by
126   // NotifyResetDone() being called on the client.  Can be used to implement
127   // "seek".
128   virtual void Reset() = 0;
129
130   // Destroys the decoder: all pending inputs are dropped immediately and the
131   // component is freed.  This call may asynchornously free system resources,
132   // but its client-visible effects are synchronous.  After this method returns
133   // no more callbacks will be made on the client.  Deletes |this|
134   // unconditionally, so make sure to drop all pointers to it!
135   virtual void Destroy() = 0;
136 };
137
138 }  // namespace media
139
140 #endif  // MEDIA_VIDEO_VIDEO_DECODE_ACCELERATOR_H_