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

Unified Diff: content/renderer/pepper/pepper_video_encoder_host.h

Issue 905023005: Pepper: PPB_VideoEncoder implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Send bitstream buffers in their own ppapi ipc message Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/pepper/pepper_video_encoder_host.h
diff --git a/content/renderer/pepper/pepper_video_encoder_host.h b/content/renderer/pepper/pepper_video_encoder_host.h
new file mode 100644
index 0000000000000000000000000000000000000000..05ecabced79e204ee93b5ecbf56f0289d31ef2c2
--- /dev/null
+++ b/content/renderer/pepper/pepper_video_encoder_host.h
@@ -0,0 +1,150 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_ENCODER_HOST_H_
+#define CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_ENCODER_HOST_H_
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_vector.h"
+#include "content/common/content_export.h"
+#include "gpu/command_buffer/common/mailbox_holder.h"
bbudge 2015/02/18 22:53:01 This doesn't appear to get used.
llandwerlin-old 2015/02/19 15:55:45 Done.
+#include "media/video/video_encode_accelerator.h"
+#include "ppapi/c/pp_codecs.h"
+#include "ppapi/c/ppb_video_frame.h"
+#include "ppapi/host/host_message_context.h"
+#include "ppapi/host/resource_host.h"
+#include "ppapi/proxy/resource_message_params.h"
+#include "ppapi/shared_impl/media_stream_buffer_manager.h"
+
+namespace media {
+class GpuVideoAcceleratorFactories;
+}
+
+namespace content {
+
+class CommandBufferProxyImpl;
+class GpuChannelHost;
+class RendererPpapiHost;
+class RenderViewImpl;
bbudge 2015/02/18 22:53:01 Not used.
llandwerlin-old 2015/02/19 15:55:45 Done.
+
+class CONTENT_EXPORT PepperVideoEncoderHost
+ : public ppapi::host::ResourceHost,
+ public media::VideoEncodeAccelerator::Client,
+ public ppapi::MediaStreamBufferManager::Delegate {
+ public:
+ PepperVideoEncoderHost(RendererPpapiHost* host,
+ PP_Instance instance,
+ PP_Resource resource);
+ ~PepperVideoEncoderHost() override;
+
+ private:
+ // Shared memory buffers.
+ struct ShmBuffer {
+ ShmBuffer(int32_t id, scoped_ptr<base::SharedMemory> shm);
+ ~ShmBuffer();
+
+ media::BitstreamBuffer ToBitstreamBuffer();
+
bbudge 2015/02/18 22:53:01 I think it would be helpful to repeat the comment
llandwerlin-old 2015/02/19 15:55:45 Done.
+ int32_t id;
+ scoped_ptr<base::SharedMemory> shm;
+ bool in_use;
+ };
+
+ // media::VideoEncodeAccelerator implementation.
+ virtual void RequireBitstreamBuffers(unsigned int input_count,
+ const gfx::Size& input_coded_size,
+ size_t output_buffer_size) override;
+ virtual void BitstreamBufferReady(int32 bitstream_buffer_id,
+ size_t payload_size,
+ bool key_frame) override;
+ virtual void NotifyError(media::VideoEncodeAccelerator::Error error) override;
+
+ // ResourceHost implementation.
+ virtual int32_t OnResourceMessageReceived(
+ const IPC::Message& msg,
+ ppapi::host::HostMessageContext* context) override;
+
+ int32_t OnHostMsgGetSupportedProfiles(
+ ppapi::host::HostMessageContext* context);
+ int32_t OnHostMsgInitialize(ppapi::host::HostMessageContext* context,
+ PP_VideoFrame_Format input_format,
+ const PP_Size& input_visible_size,
+ PP_VideoProfile output_profile,
+ uint32_t initial_bitrate,
+ PP_HardwareAcceleration acceleration);
+ int32_t OnHostMsgGetVideoFrames(ppapi::host::HostMessageContext* context);
+ int32_t OnHostMsgEncode(ppapi::host::HostMessageContext* context,
+ uint32_t frame_id,
+ bool force_keyframe);
+ int32_t OnHostMsgRecycleBitstreamBuffer(
+ ppapi::host::HostMessageContext* context,
+ uint32_t buffer_id);
+ int32_t OnHostMsgRequestEncodingParametersChange(
+ ppapi::host::HostMessageContext* context,
+ uint32_t bitrate,
+ uint32_t framerate);
+ int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context);
+
+ // Internal methods.
+ void GetSupportedProfiles(
+ std::vector<PP_VideoProfileDescription>* pp_profiles);
+ bool IsInitializationValid(const PP_Size& input_size,
+ PP_VideoProfile ouput_profile,
+ PP_HardwareAcceleration acceleration);
+ void AllocateVideoFrames();
+ scoped_refptr<media::VideoFrame> CreateVideoFrame(
+ uint32_t frame_id,
+ const ppapi::host::ReplyMessageContext& reply_context);
+ void FrameReleased(const ppapi::host::ReplyMessageContext& reply_context,
+ uint32_t frame_id);
+ void NotifyPepperError(int32_t error);
+ void Close();
+
+ // Non-owning pointer.
+ RendererPpapiHost* renderer_ppapi_host_;
+
+ ScopedVector<ShmBuffer> shm_buffers_;
+
+ // Buffer manager for shared memory that holds video frames.
+ ppapi::MediaStreamBufferManager buffer_manager_;
+
+ scoped_refptr<GpuChannelHost> channel_;
+ CommandBufferProxyImpl* command_buffer_;
+
+ scoped_ptr<media::VideoEncodeAccelerator> encoder_;
+
+ // Whether the encoder has been successfully initialized.
+ bool initialized_;
+
+ // Saved context to answer a Initialize message from the plugin.
+ ppapi::host::ReplyMessageContext initialize_context_;
bbudge 2015/02/18 22:53:01 nit: s/initialize_context_/initialize_reply_contex
llandwerlin-old 2015/02/19 15:55:45 Done.
+
+ // Saved context to answer a GetVideoFrames message from the plugin.
+ ppapi::host::ReplyMessageContext get_video_frames_context_;
+
+ // Last error encountered by the encoder or failure encountered by
+ // this class or termination triggered by the plugin. This variables
+ // is checked at most ipc entry point to decide whether operations
+ // on the encoder should proceed or fail.
bbudge 2015/02/18 22:53:01 Could we reword this a bit? e.g. // This represen
llandwerlin-old 2015/02/19 15:55:45 Done.
+ int32_t encoder_last_error_;
+
+ // Size of the frames allocated for the encoder (matching hardware
+ // constraints).
+ gfx::Size input_coded_size_;
+
+ // Number of frames the encoder needs.
+ uint32_t frame_count_;
+
+ // Format of the frames to give to the encoder.
+ media::VideoFrame::Format media_input_format_;
+
+ base::WeakPtrFactory<PepperVideoEncoderHost> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(PepperVideoEncoderHost);
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_ENCODER_HOST_H_

Powered by Google App Engine
This is Rietveld 408576698