Skip to content

Commit

Permalink
Revert of Revert of Implement software fallback for PPB_VideoDecoder. (
Browse files Browse the repository at this point in the history
…https://codereview.chromium.org/337683002/)

Reason for revert:
Revert of revert, which apparently wasn't a full revert.

Original issue's description:
> Revert of Implement software fallback for PPB_VideoDecoder. (https://codereview.chromium.org/311853005/)
> 
> Reason for revert:
> Broke blink Linux tests compile.http://build.chromium.org/p/chromium.webkit/builders/Linux%20Tests/builds/37259
> 
> Original issue's description:
> > Implement software fallback for PPB_VideoDecoder.
> > This modifies the proxy to implement software fallback mode.
> > The main change is to the host, which now can work with
> > media::VideoDecoders.
> > 
> > media::VideoDecoder works differently from media::VideoDecodeAccelerator
> > so an adapter object, content::VideoDecoderShim is defined. It lives on the main thread and drives the actual decoder on the media thread via a child DecoderImpl class, which sends back frames of video. VideoDecoderShim receives those and converts frames to GL textures.
> > 
> > gpu::Mailboxes are used so the host can create textures that are aliased
> > to the plugin's textures.
> > 
> > The test plugin has been changed to include bitstream data for VP8 in order to
> > test the software decoder. The data is in ppapi/examples/video_decode/testdata.h
> > alongside the H264 data. The file diff is too large for this site but is structured
> > something like this:
> > 
> > const unsigned char kData[] = {
> > #if defined USE_VP8_TESTDATA_INSTEAD_OF_H264
> > ...  lots of VP8 data
> > 
> > #else  // !USE_VP8_TESTDATA_INSTEAD_OF_H264
> > ...  lots of H264 data
> > 
> > #endif  // USE_VP8_TESTDATA_INSTEAD_OF_H264
> > };
> > 
> > 
> > There is a TODO to convert the example to load a file. I'm not sure how to go
> > about that but am willing to do the work if someone can point the way.
> > 
> > BUG=281689
> > R=dmichael@chromium.org, fischman@chromium.org, sievers@chromium.org, tsepez@chromium.org
> > 
> > Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=277012
> 
> TBR=dmichael@chromium.org,fischman@chromium.org,igorc@chromium.org,piman@chromium.org,sievers@chromium.org,tsepez@chromium.org,bbudge@chromium.org
> NOTREECHECKS=true
> NOTRY=true
> BUG=281689
> 
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=277015

TBR=dmichael@chromium.org,fischman@chromium.org,igorc@chromium.org,piman@chromium.org,sievers@chromium.org,tsepez@chromium.org,bbudge@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=281689

Review URL: https://codereview.chromium.org/333903002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277020 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
schenney@chromium.org committed Jun 13, 2014
1 parent a9b5cf7 commit 0ff052d
Show file tree
Hide file tree
Showing 17 changed files with 1,011 additions and 76 deletions.
2 changes: 2 additions & 0 deletions chrome/test/ppapi/ppapi_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,8 @@ TEST_PPAPI_NACL(NetworkProxy)

TEST_PPAPI_NACL(TrueTypeFont)

TEST_PPAPI_NACL(VideoDecoder)

// VideoDestination doesn't work in content_browsertests.
TEST_PPAPI_OUT_OF_PROCESS(VideoDestination)
TEST_PPAPI_NACL(VideoDestination)
Expand Down
6 changes: 4 additions & 2 deletions content/content_renderer.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@
'renderer/mouse_lock_dispatcher.cc',
'renderer/mouse_lock_dispatcher.h',
'renderer/net_info_helper.cc',
'renderer/net_info_helper.h',
'renderer/net_info_helper.h',
'renderer/notification_provider.cc',
'renderer/notification_provider.h',
'renderer/push_messaging_dispatcher.cc',
Expand Down Expand Up @@ -566,6 +566,8 @@
'renderer/pepper/usb_key_code_conversion_win.cc',
'renderer/pepper/v8_var_converter.cc',
'renderer/pepper/v8_var_converter.h',
'renderer/pepper/video_decoder_shim.cc',
'renderer/pepper/video_decoder_shim.h',
'renderer/render_widget_fullscreen_pepper.cc',
'renderer/render_widget_fullscreen_pepper.h',
],
Expand Down Expand Up @@ -644,7 +646,7 @@
'renderer/media/webrtc/webrtc_video_track_adapter.cc',
'renderer/media/webrtc/webrtc_video_track_adapter.h',
'renderer/media/webrtc/media_stream_remote_video_source.cc',
'renderer/media/webrtc/media_stream_remote_video_source.h',
'renderer/media/webrtc/media_stream_remote_video_source.h',
'renderer/media/webrtc/media_stream_track_metrics.cc',
'renderer/media/webrtc/media_stream_track_metrics.h',
'renderer/media/webrtc/peer_connection_dependency_factory.cc',
Expand Down
116 changes: 71 additions & 45 deletions content/renderer/pepper/pepper_video_decoder_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
#include "content/public/renderer/render_thread.h"
#include "content/public/renderer/renderer_ppapi_host.h"
#include "content/renderer/pepper/ppb_graphics_3d_impl.h"
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/render_view_impl.h"
#include "media/video/picture.h"
#include "content/renderer/pepper/video_decoder_shim.h"
#include "media/video/video_decode_accelerator.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
Expand Down Expand Up @@ -119,17 +117,18 @@ int32_t PepperVideoDecoderHost::OnHostMsgInitialize(
graphics_context.host_resource(), true);
if (enter_graphics.failed())
return PP_ERROR_FAILED;
graphics3d_ = static_cast<PPB_Graphics3D_Impl*>(enter_graphics.object());
PPB_Graphics3D_Impl* graphics3d =
static_cast<PPB_Graphics3D_Impl*>(enter_graphics.object());

int command_buffer_route_id = graphics3d_->GetCommandBufferRouteId();
int command_buffer_route_id = graphics3d->GetCommandBufferRouteId();
if (!command_buffer_route_id)
return PP_ERROR_FAILED;

media::VideoCodecProfile media_profile = PepperToMediaVideoProfile(profile);

// This is not synchronous, but subsequent IPC messages will be buffered, so
// it is okay to immediately send IPC messages through the returned channel.
GpuChannelHost* channel = graphics3d_->channel();
GpuChannelHost* channel = graphics3d->channel();
DCHECK(channel);
decoder_ = channel->CreateVideoDecoder(command_buffer_route_id);
if (decoder_ && decoder_->Initialize(media_profile, this)) {
Expand All @@ -138,8 +137,14 @@ int32_t PepperVideoDecoderHost::OnHostMsgInitialize(
}
decoder_.reset();

// TODO(bbudge) Implement software fallback.
return PP_ERROR_NOTSUPPORTED;
if (!allow_software_fallback)
return PP_ERROR_NOTSUPPORTED;

decoder_.reset(new VideoDecoderShim(this));
initialize_reply_context_ = context->MakeReplyMessageContext();
decoder_->Initialize(media_profile, this);

return PP_OK_COMPLETIONPENDING;
}

int32_t PepperVideoDecoderHost::OnHostMsgGetShm(
Expand Down Expand Up @@ -176,8 +181,8 @@ int32_t PepperVideoDecoderHost::OnHostMsgGetShm(
shm_buffers_.push_back(shm.release());
shm_buffer_busy_.push_back(false);
} else {
// Fill in the new resized buffer. Delete it manually since ScopedVector
// won't delete the existing element if we just assign it.
// Remove the old buffer. Delete manually since ScopedVector won't delete
// the existing element if we just assign over it.
delete shm_buffers_[shm_id];
shm_buffers_[shm_id] = shm.release();
}
Expand Down Expand Up @@ -262,7 +267,6 @@ int32_t PepperVideoDecoderHost::OnHostMsgRecyclePicture(
return PP_ERROR_FAILED;

decoder_->ReusePictureBuffer(texture_id);

return PP_OK;
}

Expand Down Expand Up @@ -298,33 +302,54 @@ void PepperVideoDecoderHost::ProvidePictureBuffers(
uint32 requested_num_of_buffers,
const gfx::Size& dimensions,
uint32 texture_target) {
DCHECK(RenderThreadImpl::current());
host()->SendUnsolicitedReply(
pp_resource(),
PpapiPluginMsg_VideoDecoder_RequestTextures(
requested_num_of_buffers,
PP_MakeSize(dimensions.width(), dimensions.height()),
texture_target));
RequestTextures(requested_num_of_buffers,
dimensions,
texture_target,
std::vector<gpu::Mailbox>());
}

void PepperVideoDecoderHost::PictureReady(const media::Picture& picture) {
DCHECK(RenderThreadImpl::current());
host()->SendUnsolicitedReply(
pp_resource(),
PpapiPluginMsg_VideoDecoder_PictureReady(picture.bitstream_buffer_id(),
picture.picture_buffer_id()));
}

void PepperVideoDecoderHost::DismissPictureBuffer(int32 picture_buffer_id) {
DCHECK(RenderThreadImpl::current());
host()->SendUnsolicitedReply(
pp_resource(),
PpapiPluginMsg_VideoDecoder_DismissPicture(picture_buffer_id));
}

void PepperVideoDecoderHost::NotifyEndOfBitstreamBuffer(
int32 bitstream_buffer_id) {
PendingDecodeMap::iterator it = pending_decodes_.find(bitstream_buffer_id);
if (it == pending_decodes_.end()) {
NOTREACHED();
return;
}
const PendingDecode& pending_decode = it->second;
host()->SendReply(
pending_decode.reply_context,
PpapiPluginMsg_VideoDecoder_DecodeReply(pending_decode.shm_id));
shm_buffer_busy_[pending_decode.shm_id] = false;
pending_decodes_.erase(it);
}

void PepperVideoDecoderHost::NotifyFlushDone() {
host()->SendReply(flush_reply_context_,
PpapiPluginMsg_VideoDecoder_FlushReply());
flush_reply_context_ = ppapi::host::ReplyMessageContext();
}

void PepperVideoDecoderHost::NotifyResetDone() {
host()->SendReply(reset_reply_context_,
PpapiPluginMsg_VideoDecoder_ResetReply());
reset_reply_context_ = ppapi::host::ReplyMessageContext();
}

void PepperVideoDecoderHost::NotifyError(
media::VideoDecodeAccelerator::Error error) {
DCHECK(RenderThreadImpl::current());
int32_t pp_error = PP_ERROR_FAILED;
switch (error) {
case media::VideoDecodeAccelerator::UNREADABLE_INPUT:
Expand All @@ -342,34 +367,35 @@ void PepperVideoDecoderHost::NotifyError(
pp_resource(), PpapiPluginMsg_VideoDecoder_NotifyError(pp_error));
}

void PepperVideoDecoderHost::NotifyResetDone() {
DCHECK(RenderThreadImpl::current());
host()->SendReply(reset_reply_context_,
PpapiPluginMsg_VideoDecoder_ResetReply());
reset_reply_context_ = ppapi::host::ReplyMessageContext();
void PepperVideoDecoderHost::OnInitializeComplete(int32_t result) {
if (!initialized_) {
if (result == PP_OK)
initialized_ = true;
initialize_reply_context_.params.set_result(result);
host()->SendReply(initialize_reply_context_,
PpapiPluginMsg_VideoDecoder_InitializeReply());
}
}

void PepperVideoDecoderHost::NotifyEndOfBitstreamBuffer(
int32 bitstream_buffer_id) {
DCHECK(RenderThreadImpl::current());
PendingDecodeMap::iterator it = pending_decodes_.find(bitstream_buffer_id);
if (it == pending_decodes_.end()) {
NOTREACHED();
return;
}
const PendingDecode& pending_decode = it->second;
host()->SendReply(
pending_decode.reply_context,
PpapiPluginMsg_VideoDecoder_DecodeReply(pending_decode.shm_id));
shm_buffer_busy_[pending_decode.shm_id] = false;
pending_decodes_.erase(it);
const uint8_t* PepperVideoDecoderHost::DecodeIdToAddress(uint32_t decode_id) {
PendingDecodeMap::const_iterator it = pending_decodes_.find(decode_id);
DCHECK(it != pending_decodes_.end());
uint32_t shm_id = it->second.shm_id;
return static_cast<uint8_t*>(shm_buffers_[shm_id]->memory());
}

void PepperVideoDecoderHost::NotifyFlushDone() {
DCHECK(RenderThreadImpl::current());
host()->SendReply(flush_reply_context_,
PpapiPluginMsg_VideoDecoder_FlushReply());
flush_reply_context_ = ppapi::host::ReplyMessageContext();
void PepperVideoDecoderHost::RequestTextures(
uint32 requested_num_of_buffers,
const gfx::Size& dimensions,
uint32 texture_target,
const std::vector<gpu::Mailbox>& mailboxes) {
host()->SendUnsolicitedReply(
pp_resource(),
PpapiPluginMsg_VideoDecoder_RequestTextures(
requested_num_of_buffers,
PP_MakeSize(dimensions.width(), dimensions.height()),
texture_target,
mailboxes));
}

} // namespace content
21 changes: 16 additions & 5 deletions content/renderer/pepper/pepper_video_decoder_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@

#include "base/basictypes.h"
#include "base/containers/hash_tables.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "content/common/content_export.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "media/video/video_decode_accelerator.h"
#include "ppapi/c/pp_codecs.h"
#include "ppapi/host/host_message_context.h"
Expand All @@ -30,6 +28,7 @@ namespace content {
class PPB_Graphics3D_Impl;
class RendererPpapiHost;
class RenderViewImpl;
class VideoDecoderShim;

class CONTENT_EXPORT PepperVideoDecoderHost
: public ppapi::host::ResourceHost,
Expand All @@ -50,6 +49,8 @@ class CONTENT_EXPORT PepperVideoDecoderHost
const ppapi::host::ReplyMessageContext reply_context;
};

friend class VideoDecoderShim;

// ResourceHost implementation.
virtual int32_t OnResourceMessageReceived(
const IPC::Message& msg,
Expand All @@ -61,10 +62,10 @@ class CONTENT_EXPORT PepperVideoDecoderHost
uint32 texture_target) OVERRIDE;
virtual void DismissPictureBuffer(int32 picture_buffer_id) OVERRIDE;
virtual void PictureReady(const media::Picture& picture) OVERRIDE;
virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE;
virtual void NotifyFlushDone() OVERRIDE;
virtual void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id) OVERRIDE;
virtual void NotifyFlushDone() OVERRIDE;
virtual void NotifyResetDone() OVERRIDE;
virtual void NotifyError(media::VideoDecodeAccelerator::Error error) OVERRIDE;

int32_t OnHostMsgInitialize(ppapi::host::HostMessageContext* context,
const ppapi::HostResource& graphics_context,
Expand All @@ -85,11 +86,19 @@ class CONTENT_EXPORT PepperVideoDecoderHost
int32_t OnHostMsgFlush(ppapi::host::HostMessageContext* context);
int32_t OnHostMsgReset(ppapi::host::HostMessageContext* context);

// These methods are needed by VideoDecodeShim, to look like a
// VideoDecodeAccelerator.
void OnInitializeComplete(int32_t result);
const uint8_t* DecodeIdToAddress(uint32_t decode_id);
void RequestTextures(uint32 requested_num_of_buffers,
const gfx::Size& dimensions,
uint32 texture_target,
const std::vector<gpu::Mailbox>& mailboxes);

// Non-owning pointer.
RendererPpapiHost* renderer_ppapi_host_;

scoped_ptr<media::VideoDecodeAccelerator> decoder_;
scoped_refptr<PPB_Graphics3D_Impl> graphics3d_;

// A vector holding our shm buffers, in sync with a similar vector in the
// resource. We use a buffer's index in these vectors as its id on both sides
Expand All @@ -106,6 +115,8 @@ class CONTENT_EXPORT PepperVideoDecoderHost

ppapi::host::ReplyMessageContext flush_reply_context_;
ppapi::host::ReplyMessageContext reset_reply_context_;
// Only used when in software fallback mode.
ppapi::host::ReplyMessageContext initialize_reply_context_;

bool initialized_;

Expand Down
Loading

0 comments on commit 0ff052d

Please sign in to comment.