summaryrefslogtreecommitdiff
path: root/chromium/media/base/android/stream_texture_wrapper.h
blob: b0a4dd5ef454c26b04decb827132649e497cf86a (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
64
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_BASE_ANDROID_STREAM_TEXTURE_WRAPPER_H_
#define MEDIA_BASE_ANDROID_STREAM_TEXTURE_WRAPPER_H_

#include "base/task/single_thread_task_runner.h"
#include "base/unguessable_token.h"
#include "media/base/video_frame.h"

namespace media {

// StreamTextureWrapper encapsulates a StreamTexture's creation, initialization
// and registration for later retrieval (in the Browser process).
class MEDIA_EXPORT StreamTextureWrapper {
 public:
  using StreamTextureWrapperInitCB = base::OnceCallback<void(bool)>;

  StreamTextureWrapper() {}

  // Initialize the underlying StreamTexture.
  // See StreamTextureWrapperImpl.
  virtual void Initialize(
      const base::RepeatingClosure& received_frame_cb,
      scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner,
      StreamTextureWrapperInitCB init_cb) = 0;

  // Called whenever the video's natural size changes.
  // See StreamTextureWrapperImpl.
  virtual void UpdateTextureSize(const gfx::Size& natural_size) = 0;

  // Returns the latest frame.
  // See StreamTextureWrapperImpl.
  virtual scoped_refptr<VideoFrame> GetCurrentFrame() = 0;

  // Sends the StreamTexture to the browser process, to fulfill the request
  // identified by |request_token|.
  // See StreamTextureWrapperImpl.
  virtual void ForwardStreamTextureForSurfaceRequest(
      const base::UnguessableToken& request_token) = 0;

  // Clears the |received_frame_cb| passed in Initialize().
  // Should be safe to call from any thread.
  virtual void ClearReceivedFrameCBOnAnyThread() = 0;

  struct Deleter {
    inline void operator()(StreamTextureWrapper* ptr) const { ptr->Destroy(); }
  };

 protected:
  virtual ~StreamTextureWrapper() {}

  // Safely destroys the StreamTextureWrapper.
  // See StreamTextureWrapperImpl.
  virtual void Destroy() = 0;
};

typedef std::unique_ptr<StreamTextureWrapper, StreamTextureWrapper::Deleter>
    ScopedStreamTextureWrapper;

}  // namespace media

#endif  // MEDIA_BASE_ANDROID_STREAM_TEXTURE_WRAPPER_H_