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

Side by Side Diff: media/mojo/services/video_overlay_factory.cc

Issue 1873513003: Add video-rendering to mojo media pipeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor cleanup Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "chromecast/renderer/media/hole_frame_factory.h" 5 #include "media/mojo/services/video_overlay_factory.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "gpu/GLES2/gl2extchromium.h" 9 #include "gpu/GLES2/gl2extchromium.h"
10 #include "gpu/command_buffer/client/gles2_interface.h" 10 #include "gpu/command_buffer/client/gles2_interface.h"
11 #include "media/base/video_frame.h" 11 #include "media/base/video_frame.h"
12 #include "media/renderers/gpu_video_accelerator_factories.h" 12 #include "media/renderers/gpu_video_accelerator_factories.h"
13 13
14 namespace chromecast {
15 namespace media { 14 namespace media {
16 15
17 HoleFrameFactory::HoleFrameFactory( 16 VideoOverlayFactory::VideoOverlayFactory(
xhwang 2016/04/12 19:40:37 Newbie question. Does this class work in all proce
alokp 2016/04/19 00:16:07 So far it has only been used in the renderer proce
18 ::media::GpuVideoAcceleratorFactories* gpu_factories) 17 ::media::GpuVideoAcceleratorFactories* gpu_factories)
19 : gpu_factories_(gpu_factories), texture_(0), image_id_(0) { 18 : gpu_factories_(gpu_factories), texture_(0), image_id_(0) {
20 if (gpu_factories_) { 19 if (gpu_factories_) {
21 std::unique_ptr<::media::GpuVideoAcceleratorFactories::ScopedGLContextLock> 20 scoped_ptr<::media::GpuVideoAcceleratorFactories::ScopedGLContextLock> lock(
xhwang 2016/04/12 19:40:37 We should keep using unique_ptr
alokp 2016/04/19 00:16:07 Done.
22 lock(gpu_factories_->GetGLContextLock()); 21 gpu_factories_->GetGLContextLock());
23 CHECK(lock); 22 CHECK(lock);
24 gpu::gles2::GLES2Interface* gl = lock->ContextGL(); 23 gpu::gles2::GLES2Interface* gl = lock->ContextGL();
25 24
26 gl->GenTextures(1, &texture_); 25 gl->GenTextures(1, &texture_);
27 gl->BindTexture(GL_TEXTURE_2D, texture_); 26 gl->BindTexture(GL_TEXTURE_2D, texture_);
28 image_id_ = gl->CreateGpuMemoryBufferImageCHROMIUM(1, 1, GL_RGBA, 27 image_id_ = gl->CreateGpuMemoryBufferImageCHROMIUM(1, 1, GL_RGBA,
29 GL_READ_WRITE_CHROMIUM); 28 GL_READ_WRITE_CHROMIUM);
30 CHECK(image_id_); 29 CHECK(image_id_);
31 gl->BindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id_); 30 gl->BindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id_);
32 31
33 gl->GenMailboxCHROMIUM(mailbox_.name); 32 gl->GenMailboxCHROMIUM(mailbox_.name);
34 gl->ProduceTextureDirectCHROMIUM(texture_, GL_TEXTURE_2D, mailbox_.name); 33 gl->ProduceTextureDirectCHROMIUM(texture_, GL_TEXTURE_2D, mailbox_.name);
35 34
36 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM(); 35 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM();
37 gl->ShallowFlushCHROMIUM(); 36 gl->ShallowFlushCHROMIUM();
38 gl->GenSyncTokenCHROMIUM(fence_sync, sync_token_.GetData()); 37 gl->GenSyncTokenCHROMIUM(fence_sync, sync_token_.GetData());
39 } 38 }
40 } 39 }
41 40
42 HoleFrameFactory::~HoleFrameFactory() { 41 VideoOverlayFactory::~VideoOverlayFactory() {
43 if (texture_) { 42 if (texture_) {
44 std::unique_ptr<::media::GpuVideoAcceleratorFactories::ScopedGLContextLock> 43 scoped_ptr<::media::GpuVideoAcceleratorFactories::ScopedGLContextLock> lock(
45 lock(gpu_factories_->GetGLContextLock()); 44 gpu_factories_->GetGLContextLock());
46 CHECK(lock); 45 CHECK(lock);
47 gpu::gles2::GLES2Interface* gl = lock->ContextGL(); 46 gpu::gles2::GLES2Interface* gl = lock->ContextGL();
48 gl->BindTexture(GL_TEXTURE_2D, texture_); 47 gl->BindTexture(GL_TEXTURE_2D, texture_);
49 gl->ReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id_); 48 gl->ReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id_);
50 gl->DeleteTextures(1, &texture_); 49 gl->DeleteTextures(1, &texture_);
51 gl->DestroyImageCHROMIUM(image_id_); 50 gl->DestroyImageCHROMIUM(image_id_);
52 } 51 }
53 } 52 }
54 53
55 scoped_refptr<::media::VideoFrame> HoleFrameFactory::CreateHoleFrame( 54 scoped_refptr<::media::VideoFrame> VideoOverlayFactory::CreateFrame(
56 const gfx::Size& size) { 55 const gfx::Size& size) {
57 // No texture => audio device. size empty => video has one dimension = 0. 56 // No texture => audio device. size empty => video has one dimension = 0.
58 // Dimension 0 case triggers a DCHECK later on in TextureMailbox if we push 57 // Dimension 0 case triggers a DCHECK later on in TextureMailbox if we push
59 // through the overlay path. 58 // through the overlay path.
60 if (!texture_ || size.IsEmpty()) { 59 if (!texture_ || size.IsEmpty()) {
61 LOG(INFO) << "Create black frame " << size.width() << "x" << size.height(); 60 DVLOG(1) << "Create black frame " << size.width() << "x" << size.height();
62 return ::media::VideoFrame::CreateBlackFrame(gfx::Size(1, 1)); 61 return ::media::VideoFrame::CreateBlackFrame(gfx::Size(1, 1));
63 } 62 }
64 63
65 LOG(INFO) << "Create hole frame " << size.width() << "x" << size.height(); 64 DVLOG(1) << "Create overlay frame " << size.width() << "x" << size.height();
66 scoped_refptr<::media::VideoFrame> frame = 65 scoped_refptr<::media::VideoFrame> frame =
67 ::media::VideoFrame::WrapNativeTexture( 66 ::media::VideoFrame::WrapNativeTexture(
68 ::media::PIXEL_FORMAT_XRGB, 67 ::media::PIXEL_FORMAT_XRGB,
69 gpu::MailboxHolder(mailbox_, sync_token_, GL_TEXTURE_2D), 68 gpu::MailboxHolder(mailbox_, sync_token_, GL_TEXTURE_2D),
70 ::media::VideoFrame::ReleaseMailboxCB(), 69 ::media::VideoFrame::ReleaseMailboxCB(),
71 size, // coded_size 70 size, // coded_size
72 gfx::Rect(size), // visible rect 71 gfx::Rect(size), // visible rect
73 size, // natural size 72 size, // natural size
74 base::TimeDelta()); // timestamp 73 base::TimeDelta()); // timestamp
75 CHECK(frame); 74 CHECK(frame);
76 frame->metadata()->SetBoolean(::media::VideoFrameMetadata::ALLOW_OVERLAY, 75 frame->metadata()->SetBoolean(::media::VideoFrameMetadata::ALLOW_OVERLAY,
77 true); 76 true);
78 return frame; 77 return frame;
79 } 78 }
80 79
81 } // namespace media 80 } // namespace media
82 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698