summaryrefslogtreecommitdiffstats
path: root/cc/video_frame_provider_client_impl.h
blob: a2a9fc7c05d608e41c1e2f1d66e2e317b1b2a29c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_VIDEO_FRAME_PROVIDER_CLIENT_IMPL_H_
#define CC_VIDEO_FRAME_PROVIDER_CLIENT_IMPL_H_

#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "cc/video_frame_provider.h"
#include "ui/gfx/transform.h"

namespace media { class VideoFrame; }

namespace cc {
class VideoLayerImpl;

class VideoFrameProviderClientImpl
    : public VideoFrameProvider::Client,
      public base::RefCounted<VideoFrameProviderClientImpl> {
 public:
  static scoped_refptr<VideoFrameProviderClientImpl> Create(
      VideoFrameProvider* provider);

  void set_active_video_layer(VideoLayerImpl* video_layer) {
    active_video_layer_ = video_layer;
  }

  void Stop();
  bool Stopped() const { return !provider_; }

  media::VideoFrame* AcquireLockAndCurrentFrame();
  void PutCurrentFrame(media::VideoFrame* frame);
  void ReleaseLock();
  const gfx::Transform& stream_texture_matrix() const {
    return stream_texture_matrix_;
  }

  // VideoFrameProvider::Client implementation. These methods are all callable
  // on any thread.
  virtual void StopUsingProvider() OVERRIDE;
  virtual void DidReceiveFrame() OVERRIDE;
  virtual void DidUpdateMatrix(const float* matrix) OVERRIDE;

 private:
  explicit VideoFrameProviderClientImpl(VideoFrameProvider* provider);
  friend class base::RefCounted<VideoFrameProviderClientImpl>;
  virtual ~VideoFrameProviderClientImpl();

  VideoLayerImpl* active_video_layer_;

  // Guards the destruction of provider_ and the frame that it provides
  base::Lock provider_lock_;
  VideoFrameProvider* provider_;

  gfx::Transform stream_texture_matrix_;

  DISALLOW_COPY_AND_ASSIGN(VideoFrameProviderClientImpl);
};

}  // namespace cc

#endif  // CC_VIDEO_FRAME_PROVIDER_CLIENT_IMPL_H_