1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/media/video_frame_compositor.h"
7 #include "media/base/video_frame.h"
11 static bool IsOpaque(const scoped_refptr
<media::VideoFrame
>& frame
) {
12 switch (frame
->format()) {
13 case media::VideoFrame::UNKNOWN
:
14 case media::VideoFrame::YV12
:
15 case media::VideoFrame::YV12J
:
16 case media::VideoFrame::YV16
:
17 case media::VideoFrame::I420
:
18 case media::VideoFrame::YV24
:
19 case media::VideoFrame::NV12
:
22 case media::VideoFrame::YV12A
:
23 #if defined(VIDEO_HOLE)
24 case media::VideoFrame::HOLE
:
25 #endif // defined(VIDEO_HOLE)
26 case media::VideoFrame::NATIVE_TEXTURE
:
32 VideoFrameCompositor::VideoFrameCompositor(
33 const base::Callback
<void(gfx::Size
)>& natural_size_changed_cb
,
34 const base::Callback
<void(bool)>& opacity_changed_cb
)
35 : natural_size_changed_cb_(natural_size_changed_cb
),
36 opacity_changed_cb_(opacity_changed_cb
),
40 VideoFrameCompositor::~VideoFrameCompositor() {
42 client_
->StopUsingProvider();
45 void VideoFrameCompositor::SetVideoFrameProviderClient(
46 cc::VideoFrameProvider::Client
* client
) {
48 client_
->StopUsingProvider();
52 scoped_refptr
<media::VideoFrame
> VideoFrameCompositor::GetCurrentFrame() {
53 return current_frame_
;
56 void VideoFrameCompositor::PutCurrentFrame(
57 const scoped_refptr
<media::VideoFrame
>& frame
) {
60 void VideoFrameCompositor::UpdateCurrentFrame(
61 const scoped_refptr
<media::VideoFrame
>& frame
) {
63 current_frame_
->natural_size() != frame
->natural_size()) {
64 natural_size_changed_cb_
.Run(frame
->natural_size());
67 if (!current_frame_
|| IsOpaque(current_frame_
) != IsOpaque(frame
)) {
68 opacity_changed_cb_
.Run(IsOpaque(frame
));
71 current_frame_
= frame
;
74 client_
->DidReceiveFrame();
77 } // namespace content