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

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: Fixed include guards Created 4 years, 5 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. Can be created on any,
19 // thread, but will be initialized/destroyed on |main_tread_task_runner|, and
watk 2016/07/23 03:13:39 typo: main_tread_task_runner Remove comma in "any,
tguilbert 2016/07/26 00:13:51 Done.
20 // will signal the readyness of new frames on |compositor_task_runner_|.
watk 2016/07/23 03:13:40 readiness
tguilbert 2016/07/26 00:13:51 Done.
21 //
22 // A SurfaceTexture is an Android primitive, joining an Android Surface (the
23 // producer side, used by MediaPlayer for example) with a GL Texture (the
24 // consumer side, used by our compositor). Its documentation can be found here:
25 // https://developer.android.com/reference/android/graphics/SurfaceTexture.html
watk 2016/07/23 03:13:40 nit: doesn't feel like the right place to describe
tguilbert 2016/07/26 00:13:52 I'm fine with removing this.
26 //
27 // The StreamTexture is an abstraction allowing Chrome to wrap a SurfaceTexture
28 // living in the GPU process. It allows VideoFrames to be created from the
29 // SurfaceTexture's texture, in the Renderer process.
30 //
31 // The general idea behind our use of StreamTexture is as follows:
32 // - We create a client GL texture in the Renderer process.
33 // - We request the creation of a StreamTexture via the StreamTextureFactory,
34 // passing the client texture ID. The call is sent to the GPU process via the
35 // CommandBuffer. The "platform" GL texture reference associated with the client
36 // texture ID is looked up in the TextureManager. A StreamTexture is then
37 // created, wrapping a SurfaceTexture created from the texture reference. The
38 // SurfaceTexture's OnFrameAvailable() callback is tied to StreamTexture's
39 // OnFrameAvailable(), which fires an IPC accross the GPU channel.
40 // - We create a StreamTextureProxy in the Renderer process which listens for
41 // the IPC fired by the StreamTexture's OnFrameAvailable() callback.
42 // - We bind the StreamTextureProxy's lifetime to the |compositor_task_runner_|.
43 // - We wrap the client texture into a VideoFrame.
44 // - When the SurfaceTexture's OnFrameAvailable() callback is fired (and routed
45 // to the StreamTextureProxy living on the compositor thread), we notify
46 // |client_| that a new frame is available, via the DidReceiveFrame() callback.
47 //
48 // TODO(tguilbert): Register the underlying SurfaceTexture for retrieval in the
49 // browser process. See crbug.com/627658.
50 //
51 class CONTENT_EXPORT StreamTextureWrapperImpl
52 : public media::StreamTextureWrapper {
53 public:
54 StreamTextureWrapperImpl(
55 scoped_refptr<StreamTextureFactory> factory,
56 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner);
57 virtual ~StreamTextureWrapperImpl();
58
59 // StreamTextureWrapper implementation.
watk 2016/07/23 03:13:40 Since you're only implementing one interface now,
tguilbert 2016/07/26 00:13:52 Done.
60
61 // Creates the underlying StreamTexture. Binds |client|'s DidReceiveFrame() to
62 // |compositor_task_runner|.
watk 2016/07/23 03:13:40 Second sentence isn't super clear. It's the proxy
tguilbert 2016/07/26 00:13:52 Done.
63 // Can be called from any thread, but runs on |main_task_runner_|.
64 void Initialize(
65 cc::VideoFrameProvider::Client* client,
66 const gfx::Size& natural_size,
67 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner,
68 const base::Closure& init_cb) override;
69
70 // Called when the Video size changes.
71 // Can be called from any thread, but runs on |main_task_runner_|.
72 void UpdateTextureSize(const gfx::Size& natural_size) override;
73
74 // Returns the latest frame.
75 // N.B: We create a single VideoFrame at initialization time (and update it
76 // in UpdateTextureSize()), and repeatedly return it here. The underlying
77 // texture's changes are signalled via |client_|'s DidReceiveFrame() callback.
78 scoped_refptr<media::VideoFrame> GetCurrentFrame() override;
79
80 // Destroys the StreamTextureWrapper safely on the |main_task_runner_|.
watk 2016/07/23 03:13:40 StreamTextureWrapperImpl. Or even better, |this|.
tguilbert 2016/07/26 00:13:52 Done.
81 void Destroy() override;
82
83 private:
84 void InitializeOnMainThread(const base::Closure& init_cb);
85
86 void ReallocateVideoFrame(const gfx::Size& natural_size);
87
88 void SetCurrentFrameInternal(
89 const scoped_refptr<media::VideoFrame>& video_frame);
90
91 // GL texture ID allocated to the video.
92 unsigned int texture_id_;
93
94 // GL texture mailbox for |texture_id_| to provide in the VideoFrame, and sync
95 // point for when the mailbox was produced.
watk 2016/07/23 03:13:40 There's no sync point here?
tguilbert 2016/07/26 00:13:52 Removed that part from the comment (which came fro
96 gpu::Mailbox texture_mailbox_;
97
98 // Stream texture ID allocated to the video.
99 unsigned int stream_id_;
100
101 // Object for calling back the compositor thread to repaint the video when a
102 // frame available. It should be bound to the compositor thread.
watk 2016/07/23 03:13:39 frame _is_ available
tguilbert 2016/07/26 00:13:51 Done.
103 ScopedStreamTextureProxy stream_texture_proxy_;
104
105 cc::VideoFrameProvider::Client* client_;
watk 2016/07/23 03:13:40 Looks like you don't need this after Initialize().
tguilbert 2016/07/26 00:13:52 Ack. Removed from member variables and added to th
106
107 // Size of the allocated underlying texture.
108 gfx::Size natural_size_;
watk 2016/07/23 03:13:40 This is not used to allocate a texture though. The
tguilbert 2016/07/26 00:13:51 Done.
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