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_
10 #include "base/containers/hash_tables.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "ipc/ipc_listener.h"
14 #include "media/video/video_encode_accelerator.h"
32 // This class is the renderer-side host for the VideoEncodeAccelerator in the
33 // GPU process, coordinated over IPC.
34 class GpuVideoEncodeAcceleratorHost
35 : public IPC::Listener,
36 public media::VideoEncodeAccelerator,
37 public base::SupportsWeakPtr<GpuVideoEncodeAcceleratorHost> {
39 // |client| is assumed to outlive this object. Since the GpuChannelHost does
40 // _not_ own this object, a reference to |gpu_channel_host| is taken.
41 GpuVideoEncodeAcceleratorHost(
42 media::VideoEncodeAccelerator::Client* client,
43 const scoped_refptr<GpuChannelHost>& gpu_channel_host,
45 virtual ~GpuVideoEncodeAcceleratorHost();
47 // Static query for the supported profiles. This query proxies to
48 // GpuVideoEncodeAccelerator::GetSupportedProfiles().
49 static std::vector<SupportedProfile> GetSupportedProfiles();
51 // IPC::Listener implementation.
52 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
53 virtual void OnChannelError() OVERRIDE;
55 // media::VideoEncodeAccelerator implementation.
56 virtual void Initialize(media::VideoFrame::Format format,
57 const gfx::Size& input_visible_size,
58 media::VideoCodecProfile output_profile,
59 uint32 initial_bitrate) OVERRIDE;
60 virtual void Encode(const scoped_refptr<media::VideoFrame>& frame,
61 bool force_keyframe) OVERRIDE;
62 virtual void UseOutputBitstreamBuffer(
63 const media::BitstreamBuffer& buffer) OVERRIDE;
64 virtual void RequestEncodingParametersChange(uint32 bitrate,
65 uint32 framerate_num) OVERRIDE;
66 virtual void Destroy() OVERRIDE;
69 // Notify |client_| when an error has occured. Used when notifying from
70 // within a media::VideoEncodeAccelerator entry point, to avoid re-entrancy.
71 void NotifyError(Error error);
73 // IPC handlers, proxying media::VideoEncodeAccelerator::Client for the GPU
75 void OnNotifyInitializeDone();
76 void OnRequireBitstreamBuffers(uint32 input_count,
77 const gfx::Size& input_coded_size,
78 uint32 output_buffer_size);
79 void OnNotifyInputDone(int32 frame_id);
80 void OnBitstreamBufferReady(int32 bitstream_buffer_id,
83 void OnNotifyError(Error error);
85 void Send(IPC::Message* message);
87 // Weak pointer for client callbacks on the
88 // media::VideoEncodeAccelerator::Client interface.
89 media::VideoEncodeAccelerator::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 base::WeakPtrFactory<VideoEncodeAccelerator::Client> client_ptr_factory_;
94 // IPC channel and route ID.
95 scoped_refptr<GpuChannelHost> channel_;
96 const int32 route_id_;
98 // media::VideoFrames sent to the encoder.
99 // base::IDMap not used here, since that takes pointers, not scoped_refptr.
100 typedef base::hash_map<int32, scoped_refptr<media::VideoFrame> > FrameMap;
103 // ID serial number for the next frame to send to the GPU process.
104 int32 next_frame_id_;
106 DISALLOW_COPY_AND_ASSIGN(GpuVideoEncodeAcceleratorHost);
109 } // namespace content
111 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_ENCODE_ACCELERATOR_HOST_H_