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

Side by Side Diff: content/common/gpu/client/gpu_video_encode_accelerator_host.h

Issue 185403020: Make VEA client of command buffer; move sync. IPC to VDA/VEA::Initialize() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 7da5b6ec Rebase. Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_ENCODE_ACCELERATOR_HOST_H_ 5 #ifndef CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_ENCODE_ACCELERATOR_HOST_H_
6 #define CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_ENCODE_ACCELERATOR_HOST_H_ 6 #define CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_ENCODE_ACCELERATOR_HOST_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/threading/non_thread_safe.h"
14 #include "content/common/gpu/client/command_buffer_proxy_impl.h"
13 #include "ipc/ipc_listener.h" 15 #include "ipc/ipc_listener.h"
14 #include "media/video/video_encode_accelerator.h" 16 #include "media/video/video_encode_accelerator.h"
15 17
16 namespace gfx { 18 namespace gfx {
17 19
18 class Size; 20 class Size;
19 21
20 } // namespace gfx 22 } // namespace gfx
21 23
22 namespace media { 24 namespace media {
23 25
24 class VideoFrame; 26 class VideoFrame;
25 27
26 } // namespace media 28 } // namespace media
27 29
28 namespace content { 30 namespace content {
29 31
30 class GpuChannelHost; 32 class GpuChannelHost;
31 33
32 // This class is the renderer-side host for the VideoEncodeAccelerator in the 34 // This class is the renderer-side host for the VideoEncodeAccelerator in the
33 // GPU process, coordinated over IPC. 35 // GPU process, coordinated over IPC.
34 class GpuVideoEncodeAcceleratorHost 36 class GpuVideoEncodeAcceleratorHost
35 : public IPC::Listener, 37 : public IPC::Listener,
36 public media::VideoEncodeAccelerator, 38 public media::VideoEncodeAccelerator,
37 public base::SupportsWeakPtr<GpuVideoEncodeAcceleratorHost> { 39 public CommandBufferProxyImpl::DeletionObserver,
40 public base::NonThreadSafe {
38 public: 41 public:
39 // Since the GpuChannelHost does _not_ own this object, a reference to 42 // |this| is guaranteed not to outlive |channel| and |impl|. (See comments
40 // |gpu_channel_host| is taken. 43 // for |channel_| and |impl_|.)
41 GpuVideoEncodeAcceleratorHost( 44 GpuVideoEncodeAcceleratorHost(GpuChannelHost* channel,
42 const scoped_refptr<GpuChannelHost>& gpu_channel_host, 45 CommandBufferProxyImpl* impl);
43 int32 route_id);
44 virtual ~GpuVideoEncodeAcceleratorHost();
45 46
46 // Static query for the supported profiles. This query proxies to 47 // Static query for the supported profiles. This query proxies to
47 // GpuVideoEncodeAccelerator::GetSupportedProfiles(). 48 // GpuVideoEncodeAccelerator::GetSupportedProfiles().
48 static std::vector<SupportedProfile> GetSupportedProfiles(); 49 static std::vector<SupportedProfile> GetSupportedProfiles();
49 50
50 // IPC::Listener implementation. 51 // IPC::Listener implementation.
51 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 52 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
52 virtual void OnChannelError() OVERRIDE; 53 virtual void OnChannelError() OVERRIDE;
53 54
54 // media::VideoEncodeAccelerator implementation. 55 // media::VideoEncodeAccelerator implementation.
55 virtual void Initialize(media::VideoFrame::Format format, 56 virtual bool Initialize(media::VideoFrame::Format input_format,
56 const gfx::Size& input_visible_size, 57 const gfx::Size& input_visible_size,
57 media::VideoCodecProfile output_profile, 58 media::VideoCodecProfile output_profile,
58 uint32 initial_bitrate, 59 uint32 initial_bitrate,
59 Client* client) OVERRIDE; 60 Client* client) OVERRIDE;
60 virtual void Encode(const scoped_refptr<media::VideoFrame>& frame, 61 virtual void Encode(const scoped_refptr<media::VideoFrame>& frame,
61 bool force_keyframe) OVERRIDE; 62 bool force_keyframe) OVERRIDE;
62 virtual void UseOutputBitstreamBuffer( 63 virtual void UseOutputBitstreamBuffer(
63 const media::BitstreamBuffer& buffer) OVERRIDE; 64 const media::BitstreamBuffer& buffer) OVERRIDE;
64 virtual void RequestEncodingParametersChange(uint32 bitrate, 65 virtual void RequestEncodingParametersChange(uint32 bitrate,
65 uint32 framerate_num) OVERRIDE; 66 uint32 framerate_num) OVERRIDE;
66 virtual void Destroy() OVERRIDE; 67 virtual void Destroy() OVERRIDE;
67 68
69 // CommandBufferProxyImpl::DeletionObserver implemetnation.
70 virtual void OnWillDeleteImpl() OVERRIDE;
71
68 private: 72 private:
69 // Notify |client_| when an error has occured. Used when notifying from 73 // Only Destroy() should be deleting |this|.
70 // within a media::VideoEncodeAccelerator entry point, to avoid re-entrancy. 74 virtual ~GpuVideoEncodeAcceleratorHost();
71 void NotifyError(Error error); 75
76 // Notify |client_| of an error. Posts a task to avoid re-entrancy.
77 void PostNotifyError(Error);
78
79 void Send(IPC::Message* message);
72 80
73 // IPC handlers, proxying media::VideoEncodeAccelerator::Client for the GPU 81 // IPC handlers, proxying media::VideoEncodeAccelerator::Client for the GPU
74 // process. 82 // process. Should not be called directly.
75 void OnNotifyInitializeDone();
76 void OnRequireBitstreamBuffers(uint32 input_count, 83 void OnRequireBitstreamBuffers(uint32 input_count,
77 const gfx::Size& input_coded_size, 84 const gfx::Size& input_coded_size,
78 uint32 output_buffer_size); 85 uint32 output_buffer_size);
79 void OnNotifyInputDone(int32 frame_id); 86 void OnNotifyInputDone(int32 frame_id);
80 void OnBitstreamBufferReady(int32 bitstream_buffer_id, 87 void OnBitstreamBufferReady(int32 bitstream_buffer_id,
81 uint32 payload_size, 88 uint32 payload_size,
82 bool key_frame); 89 bool key_frame);
83 void OnNotifyError(Error error); 90 void OnNotifyError(Error error);
84 91
85 void Send(IPC::Message* message); 92 // Unowned reference to the GpuChannelHost to send IPC messages to the GPU
93 // process. |channel_| outlives |impl_|, so the reference is always valid as
94 // long as it is not NULL.
95 GpuChannelHost* channel_;
86 96
87 // Pointer for client callbacks on the media::VideoEncodeAccelerator::Client 97 // Route ID for the associated encoder in the GPU process.
88 // interface. 98 int32 encoder_route_id_;
99
100 // The client that will receive callbacks from the encoder.
89 Client* client_; 101 Client* client_;
90 // |client_ptr_factory_| is used for callbacks that need to be done through
91 // a PostTask() to avoid re-entrancy on the client.
92 scoped_ptr<base::WeakPtrFactory<Client> > client_ptr_factory_;
93 102
94 // IPC channel and route ID. 103 // Unowned reference to the CommandBufferProxyImpl that created us. |this|
95 scoped_refptr<GpuChannelHost> channel_; 104 // registers as a DeletionObserver of |impl_|, so the reference is always
96 const int32 route_id_; 105 // valid as long as it is not NULL.
106 CommandBufferProxyImpl* impl_;
97 107
98 // media::VideoFrames sent to the encoder. 108 // media::VideoFrames sent to the encoder.
99 // base::IDMap not used here, since that takes pointers, not scoped_refptr. 109 // base::IDMap not used here, since that takes pointers, not scoped_refptr.
100 typedef base::hash_map<int32, scoped_refptr<media::VideoFrame> > FrameMap; 110 typedef base::hash_map<int32, scoped_refptr<media::VideoFrame> > FrameMap;
101 FrameMap frame_map_; 111 FrameMap frame_map_;
102 112
103 // ID serial number for the next frame to send to the GPU process. 113 // ID serial number for the next frame to send to the GPU process.
104 int32 next_frame_id_; 114 int32 next_frame_id_;
105 115
116 // WeakPtr factory for posting tasks back to itself.
117 base::WeakPtrFactory<GpuVideoEncodeAcceleratorHost> weak_this_factory_;
118
106 DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAcceleratorHost); 119 DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAcceleratorHost);
107 }; 120 };
108 121
109 } // namespace content 122 } // namespace content
110 123
111 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_ENCODE_ACCELERATOR_HOST_H_ 124 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_ENCODE_ACCELERATOR_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698