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

Side by Side Diff: content/renderer/media/android/stream_texture_wrapper_impl.h

Issue 2136103010: Add StreamTextureWrapper/StreamTextureWrapperImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments Created 4 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_WRAPPER_IMPL_H_
6 #define CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_WRAPPER_IMPL_H_
7
8 #include <memory>
9
10 #include "content/common/content_export.h"
11 #include "content/renderer/media/android/stream_texture_factory.h"
12 #include "gpu/command_buffer/common/mailbox.h"
13 #include "media/base/video_frame.h"
14 #include "media/blink/stream_texture_wrapper.h"
15
16 namespace content {
17
18 // Concrete implementation of StreamTextureWrapper. Any method can be called on
19 // any thread, but additional threading considerations are listed in the
20 // comments of individual methods.
21 //
22 // The StreamTexture is an abstraction allowing Chrome to wrap a SurfaceTexture
23 // living in the GPU process. It allows VideoFrames to be created from the
24 // SurfaceTexture's texture, in the Renderer process.
25 //
26 // The general idea behind our use of StreamTexture is as follows:
27 // - We create a client GL texture in the Renderer process.
28 // - We request the creation of a StreamTexture via the StreamTextureFactory,
29 // passing the client texture ID. The call is sent to the GPU process via the
30 // CommandBuffer. The "platform" GL texture reference associated with the client
31 // texture ID is looked up in the TextureManager. A StreamTexture is then
32 // created, wrapping a SurfaceTexture created from the texture reference. The
33 // SurfaceTexture's OnFrameAvailable() callback is tied to StreamTexture's
34 // OnFrameAvailable(), which fires an IPC accross the GPU channel.
35 // - We create a StreamTextureProxy in the Renderer process which listens for
36 // the IPC fired by the StreamTexture's OnFrameAvailable() callback.
37 // - We bind the StreamTextureProxy's lifetime to the |compositor_task_runner_|.
38 // - We wrap the client texture into a VideoFrame.
39 // - When the SurfaceTexture's OnFrameAvailable() callback is fired (and routed
40 // to the StreamTextureProxy living on the compositor thread), we notify
41 // |client_| that a new frame is available, via the DidReceiveFrame() callback.
42 //
43 // TODO(tguilbert): Register the underlying SurfaceTexture for retrieval in the
44 // browser process. See crbug.com/627658.
45 //
46 // TODO(tguilbert): Change StreamTextureProxy's interface to accept a
47 // base::Closure instead of requiring a VideoFrameProvider::Client, to simplify
48 // the MediaPlayerRendererHost interface. See crbug.com/631178.
49 class CONTENT_EXPORT StreamTextureWrapperImpl
50 : public media::StreamTextureWrapper {
51 public:
52 StreamTextureWrapperImpl(
53 scoped_refptr<StreamTextureFactory> factory,
54 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner);
55 virtual ~StreamTextureWrapperImpl();
56
57 // Creates the underlying StreamTexture, and binds |stream_texture_proxy_| to
58 // |compositor_task_runner|.
59 //
60 // Additional threading considerations:
61 // - Can be called from any thread.
62 // - Initialization will run on |main_task_runner_|.
63 // - |init_cb| will be run on the calling thread.
64 // - New frames will be signaled on |compositor_task_runner| via |client|'s
65 // DidReceiveFrame() method.
66 void Initialize(
67 cc::VideoFrameProvider::Client* client,
68 const gfx::Size& natural_size,
69 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner,
70 const base::Closure& init_cb) override;
71
72 // Should be called when the Video size changes.
73 // Can be called from any thread, but runs on |main_task_runner_|.
74 void UpdateTextureSize(const gfx::Size& natural_size) override;
75
76 // Returns the latest frame.
77 // N.B: We create a single VideoFrame at initialization time (and update it
78 // in UpdateTextureSize()), and repeatedly return it here. The underlying
79 // texture's changes are signalled via |client|'s DidReceiveFrame() callback.
80 scoped_refptr<media::VideoFrame> GetCurrentFrame() override;
81
82 // Destroys |this| safely on |main_task_runner_|.
83 void Destroy() override;
watk 2016/07/26 20:02:32 Destroy should probably not be public. You should
tguilbert 2016/07/26 22:20:20 Changed the logic, and then re-integrated this pat
84
85 private:
86 void InitializeOnMainThread(cc::VideoFrameProvider::Client* client,
87 const base::Closure& init_cb);
88
89 void ReallocateVideoFrame(const gfx::Size& natural_size);
90
91 void SetCurrentFrameInternal(
92 const scoped_refptr<media::VideoFrame>& video_frame);
93
94 // Client GL texture ID allocated to the StreamTexture.
95 unsigned texture_id_;
96
97 // GL texture mailbox for |texture_id_|.
98 gpu::Mailbox texture_mailbox_;
99
100 // Stream texture ID.
101 unsigned stream_id_;
102
103 // Object for calling back the compositor thread to repaint the video when a
104 // frame is available. It should be bound to |compositor_task_runner_|.
105 ScopedStreamTextureProxy stream_texture_proxy_;
106
107 // Size of the video frames.
108 gfx::Size natural_size_;
109
110 scoped_refptr<StreamTextureFactory> factory_;
111
112 base::Lock current_frame_lock_;
113 scoped_refptr<media::VideoFrame> current_frame_;
114
115 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
116 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
117
118 base::WeakPtrFactory<StreamTextureWrapperImpl> weak_factory_;
119
120 DISALLOW_COPY_AND_ASSIGN(StreamTextureWrapperImpl);
121 };
122
123 } // namespace media
124
125 #endif // CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_WRAPPER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698