Skip to content

Commit

Permalink
Video: Plumb media::VideoFrame color space to cc and GpuMemoryBuffer
Browse files Browse the repository at this point in the history
In VideoResourceUpdater, populate the cc::TextureMailbox's color space
to get this through to the cc::GLRenderer, where it will be used in
compositing.

In GpuMemoryBufferVideoFramePool, specify the gfx::GpuMemoryBuffer's
color space for scanout after populating it.

BUG=622133
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_blink_rel

Review-Url: https://codereview.chromium.org/2169913003
Cr-Commit-Position: refs/heads/master@{#407882}
  • Loading branch information
ccameron-chromium authored and Commit bot committed Jul 26, 2016
1 parent f1b52c4 commit f864d5f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
31 changes: 17 additions & 14 deletions cc/resources/video_resource_updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,11 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForSoftwarePlanes(
external_resources.multiplier = 2048.0 / max_input_value;
}

external_resources.mailboxes.push_back(
TextureMailbox(plane_resource.mailbox(), gpu::SyncToken(),
resource_provider_->GetResourceTextureTarget(
plane_resource.resource_id())));
TextureMailbox mailbox(plane_resource.mailbox(), gpu::SyncToken(),
resource_provider_->GetResourceTextureTarget(
plane_resource.resource_id()));
mailbox.set_color_space(video_frame->ColorSpace());
external_resources.mailboxes.push_back(mailbox);
external_resources.release_callbacks.push_back(base::Bind(
&RecycleResource, AsWeakPtr(), plane_resource.resource_id()));
}
Expand Down Expand Up @@ -608,9 +609,10 @@ void VideoResourceUpdater::CopyPlaneTexture(
// Done with the source video frame texture at this point.
video_frame->UpdateReleaseSyncToken(&client);

external_resources->mailboxes.push_back(
TextureMailbox(resource->mailbox(), sync_token, GL_TEXTURE_2D,
video_frame->coded_size(), false, false));
TextureMailbox mailbox(resource->mailbox(), sync_token, GL_TEXTURE_2D,
video_frame->coded_size(), false, false);
mailbox.set_color_space(video_frame->ColorSpace());
external_resources->mailboxes.push_back(mailbox);

external_resources->release_callbacks.push_back(
base::Bind(&RecycleResource, AsWeakPtr(), resource->resource_id()));
Expand Down Expand Up @@ -646,13 +648,14 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes(
media::VideoFrameMetadata::COPY_REQUIRED)) {
CopyPlaneTexture(video_frame.get(), mailbox_holder, &external_resources);
} else {
external_resources.mailboxes.push_back(TextureMailbox(
mailbox_holder.mailbox, mailbox_holder.sync_token,
mailbox_holder.texture_target, video_frame->coded_size(),
video_frame->metadata()->IsTrue(
media::VideoFrameMetadata::ALLOW_OVERLAY),
false));

TextureMailbox mailbox(mailbox_holder.mailbox, mailbox_holder.sync_token,
mailbox_holder.texture_target,
video_frame->coded_size(),
video_frame->metadata()->IsTrue(
media::VideoFrameMetadata::ALLOW_OVERLAY),
false);
mailbox.set_color_space(video_frame->ColorSpace());
external_resources.mailboxes.push_back(mailbox);
external_resources.release_callbacks.push_back(
base::Bind(&ReturnTexture, AsWeakPtr(), video_frame));
}
Expand Down
18 changes: 18 additions & 0 deletions media/base/video_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,24 @@ bool VideoFrame::HasTextures() const {
return !mailbox_holders_[0].mailbox.IsZero();
}

gfx::ColorSpace VideoFrame::ColorSpace() const {
int videoframe_color_space;
if (metadata()->GetInteger(media::VideoFrameMetadata::COLOR_SPACE,
&videoframe_color_space)) {
switch (videoframe_color_space) {
case media::COLOR_SPACE_JPEG:
return gfx::ColorSpace::CreateJpeg();
case media::COLOR_SPACE_HD_REC709:
return gfx::ColorSpace::CreateREC709();
case media::COLOR_SPACE_SD_REC601:
return gfx::ColorSpace::CreateREC601();
default:
break;
}
}
return gfx::ColorSpace();
}

int VideoFrame::stride(size_t plane) const {
DCHECK(IsValidPlane(plane, format_));
return strides_[plane];
Expand Down
4 changes: 4 additions & 0 deletions media/base/video_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "gpu/command_buffer/common/mailbox_holder.h"
#include "media/base/video_frame_metadata.h"
#include "media/base/video_types.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/gpu_memory_buffer.h"
Expand Down Expand Up @@ -322,6 +323,9 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> {
// accessed via data(), visible_data() etc.
bool HasTextures() const;

// Returns the color space of this frame's content.
gfx::ColorSpace ColorSpace() const;

VideoPixelFormat format() const { return format_; }
StorageType storage_type() const { return storage_type_; }

Expand Down
5 changes: 4 additions & 1 deletion media/video/gpu_memory_buffer_video_frame_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,11 @@ void GpuMemoryBufferVideoFramePool::PoolImpl::OnCopiesDone(
FrameResources* frame_resources,
const FrameReadyCB& frame_ready_cb) {
for (const auto& plane_resource : frame_resources->plane_resources) {
if (plane_resource.gpu_memory_buffer)
if (plane_resource.gpu_memory_buffer) {
plane_resource.gpu_memory_buffer->Unmap();
plane_resource.gpu_memory_buffer->SetColorSpaceForScanout(
video_frame->ColorSpace());
}
}

media_task_runner_->PostTask(
Expand Down

0 comments on commit f864d5f

Please sign in to comment.