Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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_PEPPER_PEPPER_AUDIO_ENCODER_HOST_H_ | |
| 6 #define CONTENT_RENDERER_PEPPER_PEPPER_AUDIO_ENCODER_HOST_H_ | |
| 7 | |
| 8 #include <deque> | |
| 9 | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/memory/scoped_vector.h" | |
| 13 #include "content/common/content_export.h" | |
| 14 #include "content/renderer/pepper/audio_encoder_shim.h" | |
| 15 #include "ppapi/c/pp_codecs.h" | |
| 16 #include "ppapi/host/host_message_context.h" | |
| 17 #include "ppapi/host/resource_host.h" | |
| 18 #include "ppapi/proxy/resource_message_params.h" | |
| 19 #include "ppapi/proxy/serialized_structs.h" | |
| 20 #include "ppapi/shared_impl/media_stream_buffer_manager.h" | |
| 21 | |
| 22 namespace content { | |
| 23 | |
| 24 class RendererPpapiHost; | |
| 25 | |
| 26 class CONTENT_EXPORT PepperAudioEncoderHost : public ppapi::host::ResourceHost { | |
| 27 public: | |
| 28 PepperAudioEncoderHost(RendererPpapiHost* host, | |
| 29 PP_Instance instance, | |
| 30 PP_Resource resource); | |
| 31 ~PepperAudioEncoderHost() override; | |
| 32 | |
| 33 private: | |
| 34 class AudioData; | |
| 35 class BufferManager; | |
| 36 class BitstreamBufferManager; | |
| 37 class PcmBufferManager; | |
| 38 | |
| 39 // ResourceHost implementation. | |
| 40 int32_t OnResourceMessageReceived( | |
| 41 const IPC::Message& msg, | |
| 42 ppapi::host::HostMessageContext* context) override; | |
| 43 | |
| 44 int32_t OnHostMsgGetSupportedProfiles( | |
| 45 ppapi::host::HostMessageContext* context); | |
| 46 int32_t OnHostMsgInitialize( | |
| 47 ppapi::host::HostMessageContext* context, | |
| 48 const ppapi::proxy::PPB_AudioEncodeParameters& parameters); | |
| 49 int32_t OnHostMsgGetAudioFrames(ppapi::host::HostMessageContext* context); | |
| 50 int32_t OnHostMsgEncode(ppapi::host::HostMessageContext* context, | |
| 51 uint32_t buffer_id); | |
| 52 int32_t OnHostMsgRecycleBitstreamBuffer( | |
| 53 ppapi::host::HostMessageContext* context, | |
| 54 uint32_t buffer_id); | |
| 55 int32_t OnHostMsgRequestBitrateChange( | |
| 56 ppapi::host::HostMessageContext* context, | |
| 57 uint32_t bitrate); | |
| 58 int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context); | |
| 59 | |
| 60 void GetSupportedProfiles(std::vector<PP_AudioProfileDescription>* profiles); | |
| 61 bool IsInitializationValid( | |
| 62 const ppapi::proxy::PPB_AudioEncodeParameters& parameters); | |
| 63 bool AllocateAudioFrames(uint32_t number_of_samples); | |
| 64 bool AllocateBitstreamBuffers(size_t buffer_size); | |
| 65 scoped_refptr<AudioData> GetAudioData( | |
| 66 const scoped_refptr<BufferManager>& buffer_manager); | |
| 67 void DoEncode(); | |
| 68 void BitstreamBufferReady( | |
| 69 uint32_t audio_buffer_id, | |
| 70 const scoped_refptr<AudioEncoderShim::AudioData>& output, | |
| 71 size_t size); | |
| 72 void NotifyPepperError(int32_t error); | |
| 73 void Close(); | |
| 74 | |
| 75 // Non-owning pointer. | |
| 76 RendererPpapiHost* renderer_ppapi_host_; | |
| 77 | |
| 78 scoped_ptr<AudioEncoderShim> encoder_; | |
| 79 | |
| 80 // Whether the encoder has been successfully initialized. | |
| 81 bool initialized_; | |
| 82 | |
| 83 // Last error reported by the encoder. | |
| 84 // This represents the current error state of the encoder, i.e. PP_OK | |
| 85 // normally, or a Pepper error code if the encoder is uninitialized, | |
| 86 // has been notified of an encoder error, has encountered some | |
| 87 // other unrecoverable error, or has been closed by the plugin. | |
|
Tom Sepez
2015/10/05 16:54:16
nit: extra space between "by" and "the"
llandwerlin-old
2015/10/05 17:16:31
Done.
| |
| 88 // This field is checked in most message handlers to decide whether | |
| 89 // operations should proceed or fail. | |
| 90 int32_t encoder_last_error_; | |
| 91 | |
| 92 // Encoder's parameters, only valid if |initialized_| is true. | |
| 93 ppapi::proxy::PPB_AudioEncodeParameters encode_parameters_; | |
| 94 | |
| 95 // Buffer manager for the audio buffers handed by the plugin. | |
| 96 scoped_refptr<BufferManager> audio_buffer_manager_; | |
| 97 | |
| 98 // Buffer manager for bitstream buffers handed to the plugin. | |
| 99 scoped_refptr<BufferManager> bitstream_buffer_manager_; | |
| 100 | |
| 101 // Saved context to answer an Initialize message from the plugin. | |
| 102 ppapi::host::ReplyMessageContext initialize_reply_context_; | |
| 103 | |
| 104 // Saved context to answer a GetAudioFrames message from the plugin. | |
| 105 ppapi::host::ReplyMessageContext get_audio_frames_reply_context_; | |
| 106 | |
| 107 base::WeakPtrFactory<PepperAudioEncoderHost> weak_ptr_factory_; | |
| 108 | |
| 109 DISALLOW_COPY_AND_ASSIGN(PepperAudioEncoderHost); | |
| 110 }; | |
| 111 | |
| 112 } // namespace content | |
| 113 | |
| 114 #endif // CONTENT_RENDERER_PEPPER_PEPPER_AUDIO_ENCODER_HOST_H_ | |
| OLD | NEW |