Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: ppapi/tests/test_video_decoder.h

Issue 6961018: Pepper Video Decoder API tester plugin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simple lint fixes. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ppapi/tests/test_video_decoder.h
diff --git a/ppapi/tests/test_video_decoder.h b/ppapi/tests/test_video_decoder.h
index 15e0b3917d5ac57624e7b7bf1859a94422cd5e84..67c174dc93c1a2cbc74a6be29e551510d295ea66 100644
--- a/ppapi/tests/test_video_decoder.h
+++ b/ppapi/tests/test_video_decoder.h
@@ -2,18 +2,71 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// This file contains implementation the Pepper Video Decoder API tester. Tester
+// is simple realization of Chromium's TestCase class that implements a test
+// case for Pepper plugin interface.
+//
+// VideoDecoderClient implements normal decoding flow on top of Pepper Video
+// Decoder API. It relies on VideoBitstreamInterface for getting the decodable
+// video bitstream units and DisplayInterface for providing picture buffers and
+// drawing them onto screen. Subsystem hidden by VideoDecoderClient can be
+// reused by applications as long as they provide valid implementations of
+// VideoBitstreamInterface and DisplayInterface to the VideoDecoderClient class.
+//
+// UML diagram below illustrates the structure of the tester.
+// LocalVideoBitstreamSource and GLES2Display are examples of implementation of
+// interfaces expected by the video decoder client.
+//
+// +--------------------+
+// | TestVideoDecoder |
+// +--------------------+
+// |
+// V
+// +--------------------+
+// +------ | VideoDecoderClient |-----------------+
+// | +--------------------+ |
+// | | | |
+// | | O pp::VideoDecoder::Client
+// | | ^ |
+// | V | |
+// | +--------------------+ |
+// | | pp::VideoDecoder | |
+// | +--------------------+ |
+// V V
+// O VideoBitstreamInterface DisplayInterface O
+// | |
+// +---------------------------+ +--------------+
+// | LocalVideoBitstreamSource | | GLES2Display |
+// +---------------------------+ +--------------+
+
#ifndef PPAPI_TESTS_TEST_VIDEO_DECODER_H_
#define PPAPI_TESTS_TEST_VIDEO_DECODER_H_
+#include <map>
+#include <string>
+#include <vector>
+
#include "ppapi/c/pp_stdint.h"
+#include "ppapi/cpp/completion_callback.h"
+#include "ppapi/cpp/dev/graphics_3d_client_dev.h"
+#include "ppapi/cpp/dev/video_decoder_dev.h"
#include "ppapi/tests/test_case.h"
+#include "ppapi/tests/testing_instance.h"
struct PPB_Var;
struct PPB_VideoDecoder_Dev;
+class TestVideoSource;
+
+namespace pp {
+ class Context3D_Dev;
+ class Surface3D_Dev;
+} // namespace pp.
+
+// Main class for video decoder Pepper plugin tester.
class TestVideoDecoder : public TestCase {
public:
- TestVideoDecoder(TestingInstance* instance) : TestCase(instance) {}
+ explicit TestVideoDecoder(TestingInstance* instance) : TestCase(instance) {}
// TestCase implementation.
virtual bool Init();
@@ -22,11 +75,220 @@ class TestVideoDecoder : public TestCase {
void QuitMessageLoop();
private:
- std::string TestCreate();
+ std::string TestConfigurations();
+ std::string TestH264();
+
+ // Video decoder client delegate
+ pp::VideoDecoder::Client* video_decoder_client_;
+};
+
+// Interface for acquiring video bitstream units from a source.
+class VideoBitstreamInterface {
+ public:
+ virtual ~VideoBitstreamInterface();
+
+ // 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"?
+ // |target_mem_size_in_bytes|. The actual size of the unit will be stored in
+ // |unit_size_in_bytes|. Returns true on success, otherwise false.
+ virtual bool GetBitstreamUnit(void* target_mem,
+ uint32_t target_mem_size_in_bytes,
+ int32_t* unit_size_in_bytes) = 0;
Ami GONE FROM CHROMIUM 2011/05/24 17:55:07 Why signed?
+};
+
+// Interface for display drawing and buffer management.
+class DisplayInterface {
+ public:
+ virtual ~DisplayInterface();
+
+ // Initializes the display with |width| and |height|.
+ virtual bool Initialize(int32_t width, int32_t height) = 0;
+ // Provides one GLES2-backed picture buffer pointer into |picture_buffer| that
+ // fulfills |buffer_properties| that are dictionary values as defined in
+ // pp_video_dev.h. Returns true if successful, otherwise false.
+ virtual bool ProvideGLESPictureBuffer(
+ const std::vector<uint32_t>& buffer_properties,
+ PP_GLESBuffer_Dev* picture_buffer) = 0;
+ // Dismisses the picture buffer whose id is |picture_buffer_id|.
+ virtual bool DismissPictureBuffer(int32_t picture_buffer_id) = 0;
+ // Draws the picture described in |picture| and once drawing is complete calls
+ // the |completion_callback|. Return true, if drawing successfully accepted.
+ // Otherwise returns false and |completion_callback| will NOT be called and
+ // needs to be freed by the user.
+ virtual bool DrawPicture(const PP_Picture_Dev& picture,
+ pp::CompletionCallback completion_callback) = 0;
+};
+
+// Video bitstream source for local files.
+class LocalVideoBitstreamSource : public VideoBitstreamInterface {
+ public:
+ // Constructs the object to read the data with the |filename|.
+ explicit LocalVideoBitstreamSource(std::string filename);
+ virtual ~LocalVideoBitstreamSource();
+
+ // VideoBitstreamInterface implementation.
+ virtual bool GetBitstreamUnit(void* target_mem,
+ uint32_t target_mem_size_in_bytes,
+ int32_t* unit_size_in_bytes);
+
+ private:
+ std::string file_;
+ TestVideoSource* video_source_;
+ bool video_source_open_;
+};
+
+// Abstract base class that implements common functionality that is independent
+// of the rendering target for video decoder client interface.
+//
+// State machine:
+// States
+// +---------------+-------------+---------------+---------------+
+// Trigger | Created | Initialized | Running | Flushing |
+// -------------|---------------|-------------|---------------|---------------+
+// Initialize() |-> Initialized | N/A | N/A | N/A |
+// -------------|---------------|-------------|---------------|---------------+
+// Run() | N/A | -> Running | N/A | N/A |
+// -------------|---------------|-------------|---------------|---------------+
+// Stop() | N/A | N/A |-> Initialized | N/A |
+// -------------|---------------|-------------|---------------|---------------+
+// Flush() | N/A | N/A |-> Flushing | N/A |
+// -------------|---------------|-------------|---------------|---------------+
+// Teardown() | N/A | -> Created | N/A | N/A |
+// -------------|---------------|-------------|---------------|---------------+
+// NotifyEOS() | N/A | N/A |-> Initialized | N/A |
+// -------------|---------------|-------------|---------------|---------------+
+// NotifyError()| N/A | N/A |-> Initialized | N/A |
+// -------------+---------------+-------------+---------------+---------------+
+// OnFlushDone()| N/A | N/A | N/A |-> Running |
+// -------------+---------------+-------------+---------------+---------------+
+//
+class VideoDecoderClient : public pp::VideoDecoder::Client {
+ public:
+ // Enumeration for client states.
+ enum State {
+ kCreated,
+ kInitialized,
+ kRunning,
+ kFlushing
+ };
+
+ // Constructor expects the user of this class to provide concrete
+ // implementation of VideoBitstreamInterface and DisplayInterface.
+ VideoDecoderClient(pp::Instance* instance,
+ VideoBitstreamInterface* video_bitstream_if,
+ DisplayInterface* display_if) :
+ cb_factory_(this),
+ instance_(instance),
+ video_source_(video_bitstream_if),
+ display_(display_if),
+ end_of_stream_(false),
+ state_(kCreated) {}
+ ~VideoDecoderClient() {}
+
+ // Functions to control the execution.
+ bool Initialize();
+ bool Run();
+ bool Stop();
+ bool Flush();
+ bool Teardown();
+
+ // VideoDecoder::Client implementation.
+ virtual void ProvidePictureBuffers(
+ uint32_t requested_num_of_buffers,
+ const std::vector<uint32_t>& buffer_properties);
+ virtual void DismissPictureBuffer(int32_t picture_buffer_id);
+ virtual void PictureReady(const PP_Picture_Dev& picture);
+ virtual void NotifyEndOfStream();
+ virtual void NotifyError(PP_VideoDecodeError_Dev error);
+
+ // Generate unique id.
+ static int32_t GetUniqueId();
+
+ private:
+ // Callback implementations for decoder events.
+ void OnResourcesAcquired();
+ void OnBitstreamBufferProcessed(int32_t result, int32_t bitstream_buffer_id);
+ void OnUserFlushDone(int32_t result, State target_state);
+ void OnEOSFlushDone(int32_t result);
+ void OnAbortDone(int32_t result);
+ // Callback from display subsystem.
+ void OnDrawPictureDone(int32_t result, int32_t picture_buffer_id);
+ // Initializes the input bitstream source.
+ bool InitializeVideoBitstreamInterface();
+ // Read an bitstream unit to bitstream buffer with |bitstream_buffer_id|.
+ // After successful read, dispatch the unit to video decoder.
+ bool ReadAndDispatchBitstreamUnit(int32_t bitstream_buffer_id);
+ // Change the state of the Video Decoder client.
+ void ChangeState(State to_state);
+ // Pepper buffer interface.
+ const struct PPB_Buffer_Dev* buffer_if_;
+ // Callback factory for generating completion callbacks.
+ pp::CompletionCallbackFactory<VideoDecoderClient> cb_factory_;
+ // Pointer to the Instance interface of this plugin module.
+ pp::Instance* instance_;
+ // Pepper video decoder instance.
+ pp::VideoDecoder* video_decoder_;
+ // Source for video bitstream.
+ VideoBitstreamInterface* video_source_;
+ // Pointer to the display.
+ DisplayInterface* display_;
+ // Map to hold |id| => |bitstream buffer| pairs.
+ std::map<int32_t, PP_VideoBitstreamBuffer_Dev> bitstream_buffers_;
+ // Indicator whether end of stream has been encountered.
+ bool end_of_stream_;
+ // Configuration used to initialize the decoder.
+ const std::vector<uint32_t> decoder_config_;
+ // Variable to hold the state of the client.
+ State state_;
+ // Variable to hold the next unique id.
+ static int32_t next_id_;
+};
+
+// Class to render decoded video pictures using OpenGL ES 2.0.
+class GLES2Display : public pp::Graphics3DClient_Dev,
+ public DisplayInterface {
+ public:
+ // |instance| and |video_decoder| are NOT owned by this object and they must
+ // outlive this class.
+ explicit GLES2Display(pp::Instance* instance) :
+ pp::Graphics3DClient_Dev(instance),
+ instance_(instance) {}
+ virtual ~GLES2Display() {}
+
+ // Graphics3DClient_Dev implementation.
+ virtual void Graphics3DContextLost();
+
+ // DisplayInterface implementation.
+ virtual bool Initialize(int32_t width, int32_t height);
+ virtual bool ProvideGLESPictureBuffer(
+ const std::vector<uint32_t>& buffer_properties,
+ PP_GLESBuffer_Dev* picture_buffer);
+ virtual bool DismissPictureBuffer(int32_t picture_buffer_id);
+ virtual bool DrawPicture(const PP_Picture_Dev& picture,
+ pp::CompletionCallback completion_callback);
+
+ private:
+ void assertNoGLError();
+ bool InitGL(int width, int height);
+ void CreateShader(GLuint program, GLenum type, const char* source, int size);
+ void LinkProgram(const PPB_OpenGLES2_Dev* gles2_if);
+ void ProgramShaders();
- // Used by the tests that access the C API directly.
- const PPB_VideoDecoder_Dev* video_decoder_interface_;
- const PPB_Var* var_interface_;
+ // Pointer to the Instance interface of this plugin module.
+ pp::Instance* instance_;
+ // Pepper GLES2 interface.
+ const struct PPB_OpenGLES2_Dev* gles2_if_;
+ // Pepper 3D context in which we are rendering.
+ pp::Context3D_Dev* context_;
+ // Pepper 3D surface that represents the frame buffer for our plugin.
+ pp::Surface3D_Dev* surface_;
+ // Width and height of the surface we are using.
+ uint32_t width_;
+ uint32_t height_;
+ // Map for GLES buffers.
+ std::map<int32_t, PP_GLESBuffer_Dev> gles_buffers_;
+ GLuint vertex_;
+ GLuint fragment_;
+ GLuint program_;
};
#endif // PPAPI_TESTS_TEST_VIDEO_DECODER_H_

Powered by Google App Engine
This is Rietveld 408576698