Implement getMediaDevices.
[chromium-blink-merge.git] / content / renderer / media / video_frame_compositor.cc
blob3fa8042f1f23c2c06301cccd7a290ae9692c28b2
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"
9 namespace content {
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:
20 return true;
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:
27 break;
29 return false;
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),
37 client_(NULL) {
40 VideoFrameCompositor::~VideoFrameCompositor() {
41 if (client_)
42 client_->StopUsingProvider();
45 void VideoFrameCompositor::SetVideoFrameProviderClient(
46 cc::VideoFrameProvider::Client* client) {
47 if (client_)
48 client_->StopUsingProvider();
49 client_ = client;
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) {
62 if (current_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;
73 if (client_)
74 client_->DidReceiveFrame();
77 } // namespace content