Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file contains implementation the Pepper Video Decoder API tester. Tester | |
| 6 // is simple realization of Chromium's TestCase class that implements a test | |
| 7 // case for Pepper plugin interface. | |
| 8 // | |
| 9 // VideoDecoderClient implements normal decoding flow on top of Pepper Video | |
| 10 // Decoder API. It relies on VideoBitstreamInterface for getting the decodable | |
| 11 // video bitstream units and DisplayInterface for providing picture buffers and | |
| 12 // drawing them onto screen. Subsystem hidden by VideoDecoderClient can be | |
| 13 // reused by applications as long as they provide valid implementations of | |
| 14 // VideoBitstreamInterface and DisplayInterface to the VideoDecoderClient class. | |
| 15 // | |
| 16 // UML diagram below illustrates the structure of the tester. | |
| 17 // LocalVideoBitstreamSource and GLES2Display are examples of implementation of | |
| 18 // interfaces expected by the video decoder client. | |
| 19 // | |
| 20 // +--------------------+ | |
| 21 // | TestVideoDecoder | | |
| 22 // +--------------------+ | |
| 23 // | | |
| 24 // V | |
| 25 // +--------------------+ | |
| 26 // +------ | VideoDecoderClient |-----------------+ | |
| 27 // | +--------------------+ | | |
| 28 // | | | | | |
| 29 // | | O pp::VideoDecoder::Client | |
| 30 // | | ^ | | |
| 31 // | V | | | |
| 32 // | +--------------------+ | | |
| 33 // | | pp::VideoDecoder | | | |
| 34 // | +--------------------+ | | |
| 35 // V V | |
| 36 // O VideoBitstreamInterface DisplayInterface O | |
| 37 // | | | |
| 38 // +---------------------------+ +--------------+ | |
| 39 // | LocalVideoBitstreamSource | | GLES2Display | | |
| 40 // +---------------------------+ +--------------+ | |
| 41 | |
| 5 #ifndef PPAPI_TESTS_TEST_VIDEO_DECODER_H_ | 42 #ifndef PPAPI_TESTS_TEST_VIDEO_DECODER_H_ |
| 6 #define PPAPI_TESTS_TEST_VIDEO_DECODER_H_ | 43 #define PPAPI_TESTS_TEST_VIDEO_DECODER_H_ |
| 7 | 44 |
| 45 #include <map> | |
| 46 #include <string> | |
| 47 #include <vector> | |
| 48 | |
| 8 #include "ppapi/c/pp_stdint.h" | 49 #include "ppapi/c/pp_stdint.h" |
| 50 #include "ppapi/cpp/completion_callback.h" | |
| 51 #include "ppapi/cpp/dev/graphics_3d_client_dev.h" | |
| 52 #include "ppapi/cpp/dev/video_decoder_dev.h" | |
| 9 #include "ppapi/tests/test_case.h" | 53 #include "ppapi/tests/test_case.h" |
| 54 #include "ppapi/tests/testing_instance.h" | |
| 10 | 55 |
| 11 struct PPB_Var; | 56 struct PPB_Var; |
| 12 struct PPB_VideoDecoder_Dev; | 57 struct PPB_VideoDecoder_Dev; |
| 13 | 58 |
| 59 class TestVideoSource; | |
| 60 | |
| 61 namespace pp { | |
| 62 class Context3D_Dev; | |
| 63 class Surface3D_Dev; | |
| 64 } // namespace pp. | |
| 65 | |
| 66 // Main class for video decoder Pepper plugin tester. | |
| 14 class TestVideoDecoder : public TestCase { | 67 class TestVideoDecoder : public TestCase { |
| 15 public: | 68 public: |
| 16 TestVideoDecoder(TestingInstance* instance) : TestCase(instance) {} | 69 explicit TestVideoDecoder(TestingInstance* instance) : TestCase(instance) {} |
| 17 | 70 |
| 18 // TestCase implementation. | 71 // TestCase implementation. |
| 19 virtual bool Init(); | 72 virtual bool Init(); |
| 20 virtual void RunTest(); | 73 virtual void RunTest(); |
| 21 | 74 |
| 22 void QuitMessageLoop(); | 75 void QuitMessageLoop(); |
| 23 | 76 |
| 24 private: | 77 private: |
| 25 std::string TestCreate(); | 78 std::string TestConfigurations(); |
| 26 | 79 std::string TestH264(); |
| 27 // Used by the tests that access the C API directly. | 80 |
| 28 const PPB_VideoDecoder_Dev* video_decoder_interface_; | 81 // Video decoder client delegate |
| 29 const PPB_Var* var_interface_; | 82 pp::VideoDecoder::Client* video_decoder_client_; |
| 83 }; | |
| 84 | |
| 85 // Interface for acquiring video bitstream units from a source. | |
| 86 class VideoBitstreamInterface { | |
| 87 public: | |
| 88 virtual ~VideoBitstreamInterface(); | |
| 89 | |
| 90 // Writes decodable bitstream unit to |target_mem| which has size of | |
|
Ami GONE FROM CHROMIUM
2011/05/24 17:55:07
What's a "unit"?
| |
| 91 // |target_mem_size_in_bytes|. The actual size of the unit will be stored in | |
| 92 // |unit_size_in_bytes|. Returns true on success, otherwise false. | |
| 93 virtual bool GetBitstreamUnit(void* target_mem, | |
| 94 uint32_t target_mem_size_in_bytes, | |
| 95 int32_t* unit_size_in_bytes) = 0; | |
|
Ami GONE FROM CHROMIUM
2011/05/24 17:55:07
Why signed?
| |
| 96 }; | |
| 97 | |
| 98 // Interface for display drawing and buffer management. | |
| 99 class DisplayInterface { | |
| 100 public: | |
| 101 virtual ~DisplayInterface(); | |
| 102 | |
| 103 // Initializes the display with |width| and |height|. | |
| 104 virtual bool Initialize(int32_t width, int32_t height) = 0; | |
| 105 // Provides one GLES2-backed picture buffer pointer into |picture_buffer| that | |
| 106 // fulfills |buffer_properties| that are dictionary values as defined in | |
| 107 // pp_video_dev.h. Returns true if successful, otherwise false. | |
| 108 virtual bool ProvideGLESPictureBuffer( | |
| 109 const std::vector<uint32_t>& buffer_properties, | |
| 110 PP_GLESBuffer_Dev* picture_buffer) = 0; | |
| 111 // Dismisses the picture buffer whose id is |picture_buffer_id|. | |
| 112 virtual bool DismissPictureBuffer(int32_t picture_buffer_id) = 0; | |
| 113 // Draws the picture described in |picture| and once drawing is complete calls | |
| 114 // the |completion_callback|. Return true, if drawing successfully accepted. | |
| 115 // Otherwise returns false and |completion_callback| will NOT be called and | |
| 116 // needs to be freed by the user. | |
| 117 virtual bool DrawPicture(const PP_Picture_Dev& picture, | |
| 118 pp::CompletionCallback completion_callback) = 0; | |
| 119 }; | |
| 120 | |
| 121 // Video bitstream source for local files. | |
| 122 class LocalVideoBitstreamSource : public VideoBitstreamInterface { | |
| 123 public: | |
| 124 // Constructs the object to read the data with the |filename|. | |
| 125 explicit LocalVideoBitstreamSource(std::string filename); | |
| 126 virtual ~LocalVideoBitstreamSource(); | |
| 127 | |
| 128 // VideoBitstreamInterface implementation. | |
| 129 virtual bool GetBitstreamUnit(void* target_mem, | |
| 130 uint32_t target_mem_size_in_bytes, | |
| 131 int32_t* unit_size_in_bytes); | |
| 132 | |
| 133 private: | |
| 134 std::string file_; | |
| 135 TestVideoSource* video_source_; | |
| 136 bool video_source_open_; | |
| 137 }; | |
| 138 | |
| 139 // Abstract base class that implements common functionality that is independent | |
| 140 // of the rendering target for video decoder client interface. | |
| 141 // | |
| 142 // State machine: | |
| 143 // States | |
| 144 // +---------------+-------------+---------------+---------------+ | |
| 145 // Trigger | Created | Initialized | Running | Flushing | | |
| 146 // -------------|---------------|-------------|---------------|---------------+ | |
| 147 // Initialize() |-> Initialized | N/A | N/A | N/A | | |
| 148 // -------------|---------------|-------------|---------------|---------------+ | |
| 149 // Run() | N/A | -> Running | N/A | N/A | | |
| 150 // -------------|---------------|-------------|---------------|---------------+ | |
| 151 // Stop() | N/A | N/A |-> Initialized | N/A | | |
| 152 // -------------|---------------|-------------|---------------|---------------+ | |
| 153 // Flush() | N/A | N/A |-> Flushing | N/A | | |
| 154 // -------------|---------------|-------------|---------------|---------------+ | |
| 155 // Teardown() | N/A | -> Created | N/A | N/A | | |
| 156 // -------------|---------------|-------------|---------------|---------------+ | |
| 157 // NotifyEOS() | N/A | N/A |-> Initialized | N/A | | |
| 158 // -------------|---------------|-------------|---------------|---------------+ | |
| 159 // NotifyError()| N/A | N/A |-> Initialized | N/A | | |
| 160 // -------------+---------------+-------------+---------------+---------------+ | |
| 161 // OnFlushDone()| N/A | N/A | N/A |-> Running | | |
| 162 // -------------+---------------+-------------+---------------+---------------+ | |
| 163 // | |
| 164 class VideoDecoderClient : public pp::VideoDecoder::Client { | |
| 165 public: | |
| 166 // Enumeration for client states. | |
| 167 enum State { | |
| 168 kCreated, | |
| 169 kInitialized, | |
| 170 kRunning, | |
| 171 kFlushing | |
| 172 }; | |
| 173 | |
| 174 // Constructor expects the user of this class to provide concrete | |
| 175 // implementation of VideoBitstreamInterface and DisplayInterface. | |
| 176 VideoDecoderClient(pp::Instance* instance, | |
| 177 VideoBitstreamInterface* video_bitstream_if, | |
| 178 DisplayInterface* display_if) : | |
| 179 cb_factory_(this), | |
| 180 instance_(instance), | |
| 181 video_source_(video_bitstream_if), | |
| 182 display_(display_if), | |
| 183 end_of_stream_(false), | |
| 184 state_(kCreated) {} | |
| 185 ~VideoDecoderClient() {} | |
| 186 | |
| 187 // Functions to control the execution. | |
| 188 bool Initialize(); | |
| 189 bool Run(); | |
| 190 bool Stop(); | |
| 191 bool Flush(); | |
| 192 bool Teardown(); | |
| 193 | |
| 194 // VideoDecoder::Client implementation. | |
| 195 virtual void ProvidePictureBuffers( | |
| 196 uint32_t requested_num_of_buffers, | |
| 197 const std::vector<uint32_t>& buffer_properties); | |
| 198 virtual void DismissPictureBuffer(int32_t picture_buffer_id); | |
| 199 virtual void PictureReady(const PP_Picture_Dev& picture); | |
| 200 virtual void NotifyEndOfStream(); | |
| 201 virtual void NotifyError(PP_VideoDecodeError_Dev error); | |
| 202 | |
| 203 // Generate unique id. | |
| 204 static int32_t GetUniqueId(); | |
| 205 | |
| 206 private: | |
| 207 // Callback implementations for decoder events. | |
| 208 void OnResourcesAcquired(); | |
| 209 void OnBitstreamBufferProcessed(int32_t result, int32_t bitstream_buffer_id); | |
| 210 void OnUserFlushDone(int32_t result, State target_state); | |
| 211 void OnEOSFlushDone(int32_t result); | |
| 212 void OnAbortDone(int32_t result); | |
| 213 // Callback from display subsystem. | |
| 214 void OnDrawPictureDone(int32_t result, int32_t picture_buffer_id); | |
| 215 // Initializes the input bitstream source. | |
| 216 bool InitializeVideoBitstreamInterface(); | |
| 217 // Read an bitstream unit to bitstream buffer with |bitstream_buffer_id|. | |
| 218 // After successful read, dispatch the unit to video decoder. | |
| 219 bool ReadAndDispatchBitstreamUnit(int32_t bitstream_buffer_id); | |
| 220 // Change the state of the Video Decoder client. | |
| 221 void ChangeState(State to_state); | |
| 222 // Pepper buffer interface. | |
| 223 const struct PPB_Buffer_Dev* buffer_if_; | |
| 224 // Callback factory for generating completion callbacks. | |
| 225 pp::CompletionCallbackFactory<VideoDecoderClient> cb_factory_; | |
| 226 // Pointer to the Instance interface of this plugin module. | |
| 227 pp::Instance* instance_; | |
| 228 // Pepper video decoder instance. | |
| 229 pp::VideoDecoder* video_decoder_; | |
| 230 // Source for video bitstream. | |
| 231 VideoBitstreamInterface* video_source_; | |
| 232 // Pointer to the display. | |
| 233 DisplayInterface* display_; | |
| 234 // Map to hold |id| => |bitstream buffer| pairs. | |
| 235 std::map<int32_t, PP_VideoBitstreamBuffer_Dev> bitstream_buffers_; | |
| 236 // Indicator whether end of stream has been encountered. | |
| 237 bool end_of_stream_; | |
| 238 // Configuration used to initialize the decoder. | |
| 239 const std::vector<uint32_t> decoder_config_; | |
| 240 // Variable to hold the state of the client. | |
| 241 State state_; | |
| 242 // Variable to hold the next unique id. | |
| 243 static int32_t next_id_; | |
| 244 }; | |
| 245 | |
| 246 // Class to render decoded video pictures using OpenGL ES 2.0. | |
| 247 class GLES2Display : public pp::Graphics3DClient_Dev, | |
| 248 public DisplayInterface { | |
| 249 public: | |
| 250 // |instance| and |video_decoder| are NOT owned by this object and they must | |
| 251 // outlive this class. | |
| 252 explicit GLES2Display(pp::Instance* instance) : | |
| 253 pp::Graphics3DClient_Dev(instance), | |
| 254 instance_(instance) {} | |
| 255 virtual ~GLES2Display() {} | |
| 256 | |
| 257 // Graphics3DClient_Dev implementation. | |
| 258 virtual void Graphics3DContextLost(); | |
| 259 | |
| 260 // DisplayInterface implementation. | |
| 261 virtual bool Initialize(int32_t width, int32_t height); | |
| 262 virtual bool ProvideGLESPictureBuffer( | |
| 263 const std::vector<uint32_t>& buffer_properties, | |
| 264 PP_GLESBuffer_Dev* picture_buffer); | |
| 265 virtual bool DismissPictureBuffer(int32_t picture_buffer_id); | |
| 266 virtual bool DrawPicture(const PP_Picture_Dev& picture, | |
| 267 pp::CompletionCallback completion_callback); | |
| 268 | |
| 269 private: | |
| 270 void assertNoGLError(); | |
| 271 bool InitGL(int width, int height); | |
| 272 void CreateShader(GLuint program, GLenum type, const char* source, int size); | |
| 273 void LinkProgram(const PPB_OpenGLES2_Dev* gles2_if); | |
| 274 void ProgramShaders(); | |
| 275 | |
| 276 // Pointer to the Instance interface of this plugin module. | |
| 277 pp::Instance* instance_; | |
| 278 // Pepper GLES2 interface. | |
| 279 const struct PPB_OpenGLES2_Dev* gles2_if_; | |
| 280 // Pepper 3D context in which we are rendering. | |
| 281 pp::Context3D_Dev* context_; | |
| 282 // Pepper 3D surface that represents the frame buffer for our plugin. | |
| 283 pp::Surface3D_Dev* surface_; | |
| 284 // Width and height of the surface we are using. | |
| 285 uint32_t width_; | |
| 286 uint32_t height_; | |
| 287 // Map for GLES buffers. | |
| 288 std::map<int32_t, PP_GLESBuffer_Dev> gles_buffers_; | |
| 289 GLuint vertex_; | |
| 290 GLuint fragment_; | |
| 291 GLuint program_; | |
| 30 }; | 292 }; |
| 31 | 293 |
| 32 #endif // PPAPI_TESTS_TEST_VIDEO_DECODER_H_ | 294 #endif // PPAPI_TESTS_TEST_VIDEO_DECODER_H_ |
| OLD | NEW |