| Index: ppapi/examples/video_decode/video_decode.cc
|
| diff --git a/ppapi/examples/video_decode/video_decode.cc b/ppapi/examples/video_decode/video_decode.cc
|
| index de9bb8df2c0c417ecb1c1a45cf5a4e2a58ec10e0..62d665657cb21c37a352d62dd6a715d6d4db261b 100644
|
| --- a/ppapi/examples/video_decode/video_decode.cc
|
| +++ b/ppapi/examples/video_decode/video_decode.cc
|
| @@ -20,7 +20,12 @@
|
| #include "ppapi/cpp/rect.h"
|
| #include "ppapi/cpp/var.h"
|
| #include "ppapi/cpp/video_decoder.h"
|
| +
|
| +// One of these should be defined.
|
| +//#define TEST_H264
|
| +#define TEST_VP8
|
| #include "ppapi/examples/video_decode/testdata.h"
|
| +
|
| #include "ppapi/lib/gl/include/GLES2/gl2.h"
|
| #include "ppapi/lib/gl/include/GLES2/gl2ext.h"
|
| #include "ppapi/utility/completion_callback_factory.h"
|
| @@ -56,6 +61,7 @@ class MyInstance : public pp::Instance, public pp::Graphics3DClient {
|
| // pp::Instance implementation.
|
| virtual void DidChangeView(const pp::Rect& position,
|
| const pp::Rect& clip_ignored);
|
| + virtual bool HandleInputEvent(const pp::InputEvent& event);
|
|
|
| // pp::Graphics3DClient implementation.
|
| virtual void Graphics3DContextLost() {
|
| @@ -164,21 +170,33 @@ class Decoder {
|
| bool resetting_;
|
| };
|
|
|
| +#if defined(TEST_H264)
|
| // Returns true if the current position is at the start of a NAL unit.
|
| static bool LookingAtNAL(const unsigned char* encoded, size_t pos) {
|
| // H264 frames start with 0, 0, 0, 1 in our test data.
|
| return pos + 3 < kDataLen && encoded[pos] == 0 && encoded[pos + 1] == 0 &&
|
| encoded[pos + 2] == 0 && encoded[pos + 3] == 1;
|
| }
|
| +#endif
|
|
|
| // Find the start and end of the next frame.
|
| static void GetNextFrame(size_t* start_pos, size_t* end_pos) {
|
| +#if defined(TEST_H264)
|
| assert(LookingAtNAL(kData, *start_pos));
|
| *end_pos = *start_pos;
|
| *end_pos += 4;
|
| while (*end_pos < kDataLen && !LookingAtNAL(kData, *end_pos)) {
|
| ++*end_pos;
|
| }
|
| +#elif defined(TEST_VP8)
|
| + // VP8 is stored in an IVF container.
|
| + // Helpful description: http://wiki.multimedia.cx/index.php?title=IVF
|
| + if (*start_pos == 0)
|
| + *start_pos = 32; // Skip IVF header.
|
| + uint32_t frame_size = *reinterpret_cast<const uint32_t*>(&kData[*start_pos]);
|
| + *start_pos += 12; // Skip frame header.
|
| + *end_pos = *start_pos + frame_size;
|
| +#endif
|
| }
|
|
|
| Decoder::Decoder(MyInstance* instance,
|
| @@ -194,10 +212,15 @@ Decoder::Decoder(MyInstance* instance,
|
| flushing_(false),
|
| resetting_(false) {
|
| assert(!decoder_->is_null());
|
| - const PP_VideoProfile profile = PP_VIDEOPROFILE_H264MAIN;
|
| + const PP_VideoProfile profile =
|
| +#if defined(TEST_H264)
|
| + PP_VIDEOPROFILE_H264MAIN;
|
| +#elif defined(TEST_VP8)
|
| + PP_VIDEOPROFILE_VP8MAIN;
|
| +#endif
|
| decoder_->Initialize(graphics_3d,
|
| profile,
|
| - PP_FALSE /* allow_software_fallback */,
|
| + PP_TRUE /* allow_software_fallback */,
|
| callback_factory_.NewCallback(&Decoder::InitializeDone));
|
| }
|
|
|
| @@ -218,9 +241,12 @@ void Decoder::Start(int frame) {
|
| // Skip to |frame|.
|
| size_t start_pos = 0;
|
| size_t end_pos = 0;
|
| - for (int i = 0; i < frame; i++)
|
| + for (int i = 0; i < frame; i++) {
|
| GetNextFrame(&start_pos, &end_pos);
|
| + start_pos = end_pos;
|
| + }
|
| encoded_data_next_pos_to_decode_ = end_pos;
|
| + printf("encoded_data_next_pos_to_decode_=%i\n", (int)encoded_data_next_pos_to_decode_);
|
|
|
| // Register callback to get the first picture. We call GetPicture again in
|
| // PictureReady to continuously receive pictures as they're decoded.
|
| @@ -290,15 +316,19 @@ void Decoder::PictureReady(int32_t result, PP_VideoPicture picture) {
|
| }
|
|
|
| void Decoder::FlushDone(int32_t result) {
|
| + printf("FlushDone:result=%i\n", result);
|
| assert(decoder_);
|
| assert(result == PP_OK || result == PP_ERROR_ABORTED);
|
| flushing_ = false;
|
| }
|
|
|
| void Decoder::ResetDone(int32_t result) {
|
| + printf("ResetDone:result=%i\n", result);
|
| assert(decoder_);
|
| assert(result == PP_OK);
|
| resetting_ = false;
|
| +
|
| + Start(seek_frame_);
|
| }
|
|
|
| MyInstance::MyInstance(PP_Instance instance, pp::Module* module)
|
| @@ -353,6 +383,30 @@ void MyInstance::DidChangeView(const pp::Rect& position,
|
| InitializeDecoders();
|
| }
|
|
|
| +bool MyInstance::HandleInputEvent(const pp::InputEvent& event) {
|
| + switch (event.GetType()) {
|
| + case PP_INPUTEVENT_TYPE_MOUSEDOWN: {
|
| + pp::MouseInputEvent mouse_event(event);
|
| + // Reset all decoders and restart video at a point proportional to the
|
| + // mouse's horiziontal offset from the left edge of the plugin area.
|
| + if (mouse_event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_LEFT) {
|
| + pp::Point mouse_position = mouse_event.GetPosition();
|
| + const int num_frames = 300; // TODO figure out real number of frames.
|
| + int frame =
|
| + (float)mouse_position.x() / plugin_size_.width() * num_frames;
|
| + for (size_t i = 0; i < video_decoders_.size(); i++) {
|
| + video_decoders_[i]->Seek(frame);
|
| + }
|
| + printf("Seeking:frame=%i\n", frame);
|
| + }
|
| + return true;
|
| + }
|
| +
|
| + default:
|
| + return false;
|
| + }
|
| +}
|
| +
|
| void MyInstance::InitializeDecoders() {
|
| assert(video_decoders_.empty());
|
| // Create two decoders with ids 0 and 1.
|
|
|