Add ICU message format support
[chromium-blink-merge.git] / content / common / gpu / client / gpu_video_encode_accelerator_host.h
bloba4b441e5525e9e7166b56598199c3c1584d9826a
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_ENCODE_ACCELERATOR_HOST_H_
6 #define CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_ENCODE_ACCELERATOR_HOST_H_
8 #include <vector>
10 #include "base/containers/hash_tables.h"
11 #include "base/memory/ref_counted.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"
15 #include "gpu/config/gpu_info.h"
16 #include "ipc/ipc_listener.h"
17 #include "media/video/video_encode_accelerator.h"
19 namespace gfx {
20 class Size;
21 } // namespace gfx
23 namespace media {
24 class VideoFrame;
25 } // namespace media
27 namespace content {
28 class GpuChannelHost;
30 // This class is the renderer-side host for the VideoEncodeAccelerator in the
31 // GPU process, coordinated over IPC.
32 class GpuVideoEncodeAcceleratorHost
33 : public IPC::Listener,
34 public media::VideoEncodeAccelerator,
35 public CommandBufferProxyImpl::DeletionObserver,
36 public base::NonThreadSafe {
37 public:
38 // |this| is guaranteed not to outlive |channel| and |impl|. (See comments
39 // for |channel_| and |impl_|.)
40 GpuVideoEncodeAcceleratorHost(GpuChannelHost* channel,
41 CommandBufferProxyImpl* impl);
43 // IPC::Listener implementation.
44 bool OnMessageReceived(const IPC::Message& message) override;
45 void OnChannelError() override;
47 // media::VideoEncodeAccelerator implementation.
48 SupportedProfiles GetSupportedProfiles() override;
49 bool Initialize(media::VideoPixelFormat input_format,
50 const gfx::Size& input_visible_size,
51 media::VideoCodecProfile output_profile,
52 uint32 initial_bitrate,
53 Client* client) override;
54 void Encode(const scoped_refptr<media::VideoFrame>& frame,
55 bool force_keyframe) override;
56 void UseOutputBitstreamBuffer(const media::BitstreamBuffer& buffer) override;
57 void RequestEncodingParametersChange(uint32 bitrate,
58 uint32 framerate_num) override;
59 void Destroy() override;
61 // CommandBufferProxyImpl::DeletionObserver implementation.
62 void OnWillDeleteImpl() override;
64 private:
65 // Only Destroy() should be deleting |this|.
66 ~GpuVideoEncodeAcceleratorHost() override;
68 // Notify |client_| of an error. Posts a task to avoid re-entrancy.
69 void PostNotifyError(Error);
71 void Send(IPC::Message* message);
73 // IPC handlers, proxying media::VideoEncodeAccelerator::Client for the GPU
74 // process. Should not be called directly.
75 void OnRequireBitstreamBuffers(uint32 input_count,
76 const gfx::Size& input_coded_size,
77 uint32 output_buffer_size);
78 void OnNotifyInputDone(int32 frame_id);
79 void OnBitstreamBufferReady(int32 bitstream_buffer_id,
80 uint32 payload_size,
81 bool key_frame);
82 void OnNotifyError(Error error);
84 // Unowned reference to the GpuChannelHost to send IPC messages to the GPU
85 // process. |channel_| outlives |impl_|, so the reference is always valid as
86 // long as it is not NULL.
87 GpuChannelHost* channel_;
89 // Route ID for the associated encoder in the GPU process.
90 int32 encoder_route_id_;
92 // The client that will receive callbacks from the encoder.
93 Client* client_;
95 // Unowned reference to the CommandBufferProxyImpl that created us. |this|
96 // registers as a DeletionObserver of |impl_|, so the reference is always
97 // valid as long as it is not NULL.
98 CommandBufferProxyImpl* impl_;
100 // media::VideoFrames sent to the encoder.
101 // base::IDMap not used here, since that takes pointers, not scoped_refptr.
102 typedef base::hash_map<int32, scoped_refptr<media::VideoFrame> > FrameMap;
103 FrameMap frame_map_;
105 // ID serial number for the next frame to send to the GPU process.
106 int32 next_frame_id_;
108 // WeakPtr factory for posting tasks back to itself.
109 base::WeakPtrFactory<GpuVideoEncodeAcceleratorHost> weak_this_factory_;
111 DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAcceleratorHost);
114 } // namespace content
116 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_ENCODE_ACCELERATOR_HOST_H_