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 "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/scoped_vector.h" |
| 12 #include "base/numerics/safe_math.h" |
| 13 #include "content/common/content_export.h" |
| 14 #include "ppapi/c/pp_codecs.h" |
| 15 #include "ppapi/host/host_message_context.h" |
| 16 #include "ppapi/host/resource_host.h" |
| 17 #include "ppapi/proxy/resource_message_params.h" |
| 18 #include "ppapi/proxy/serialized_structs.h" |
| 19 #include "ppapi/shared_impl/media_stream_buffer_manager.h" |
| 20 |
| 21 namespace content { |
| 22 |
| 23 class RendererPpapiHost; |
| 24 |
| 25 class CONTENT_EXPORT PepperAudioEncoderHost |
| 26 : public ppapi::host::ResourceHost, |
| 27 public ppapi::MediaStreamBufferManager::Delegate { |
| 28 public: |
| 29 class AudioEncoderImpl; |
| 30 |
| 31 PepperAudioEncoderHost(RendererPpapiHost* host, |
| 32 PP_Instance instance, |
| 33 PP_Resource resource); |
| 34 ~PepperAudioEncoderHost() override; |
| 35 |
| 36 private: |
| 37 // ResourceHost implementation. |
| 38 int32_t OnResourceMessageReceived( |
| 39 const IPC::Message& msg, |
| 40 ppapi::host::HostMessageContext* context) override; |
| 41 |
| 42 int32_t OnHostMsgGetSupportedProfiles( |
| 43 ppapi::host::HostMessageContext* context); |
| 44 int32_t OnHostMsgInitialize( |
| 45 ppapi::host::HostMessageContext* context, |
| 46 const ppapi::proxy::PPB_AudioEncodeParameters& parameters); |
| 47 int32_t OnHostMsgGetAudioBuffers(ppapi::host::HostMessageContext* context); |
| 48 int32_t OnHostMsgEncode(ppapi::host::HostMessageContext* context, |
| 49 int32_t buffer_id); |
| 50 int32_t OnHostMsgRecycleBitstreamBuffer( |
| 51 ppapi::host::HostMessageContext* context, |
| 52 int32_t buffer_id); |
| 53 int32_t OnHostMsgRequestBitrateChange( |
| 54 ppapi::host::HostMessageContext* context, |
| 55 uint32_t bitrate); |
| 56 int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context); |
| 57 |
| 58 void GetSupportedProfiles(std::vector<PP_AudioProfileDescription>* profiles); |
| 59 bool IsInitializationValid( |
| 60 const ppapi::proxy::PPB_AudioEncodeParameters& parameters); |
| 61 base::CheckedNumeric<size_t> GetAudioBufferSize(); |
| 62 bool AllocateBuffers(); |
| 63 bool AllocateAudioBuffers(const base::CheckedNumeric<size_t>& buffer_size); |
| 64 bool AllocateBitstreamBuffers( |
| 65 const base::CheckedNumeric<size_t>& buffer_size); |
| 66 void DoEncode(); |
| 67 void BitstreamBufferReady(int32_t audio_buffer_id, |
| 68 int32_t bitstream_buffer_id, |
| 69 int32_t size); |
| 70 void NotifyPepperError(int32_t error); |
| 71 void Close(); |
| 72 |
| 73 // Non-owning pointer. |
| 74 RendererPpapiHost* renderer_ppapi_host_; |
| 75 |
| 76 // Whether the encoder has been successfully initialized. |
| 77 bool initialized_; |
| 78 |
| 79 // Last error reported by the encoder. |
| 80 // This represents the current error state of the encoder, i.e. PP_OK |
| 81 // normally, or a Pepper error code if the encoder is uninitialized, |
| 82 // has been notified of an encoder error, has encountered some |
| 83 // other unrecoverable error, or has been closed by the plugin. |
| 84 // This field is checked in most message handlers to decide whether |
| 85 // operations should proceed or fail. |
| 86 int32_t encoder_last_error_; |
| 87 |
| 88 // Encoder's parameters, only valid if |initialized_| is true. |
| 89 ppapi::proxy::PPB_AudioEncodeParameters encode_parameters_; |
| 90 |
| 91 // Manages buffers containing audio samples from the plugin. |
| 92 ppapi::MediaStreamBufferManager audio_buffer_manager_; |
| 93 |
| 94 // Manages buffers containing encoded audio from the browser. |
| 95 ppapi::MediaStreamBufferManager bitstream_buffer_manager_; |
| 96 |
| 97 // The encoder actually doing the work. This needs to be after |
| 98 // |audio_buffer_manager_| and |bitstream_buffer_manager_| so the encoder |
| 99 // is shutdown before the buffers' memory is freed. |
| 100 scoped_ptr<AudioEncoderImpl> encoder_; |
| 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(PepperAudioEncoderHost); |
| 103 }; |
| 104 |
| 105 } // namespace content |
| 106 |
| 107 #endif // CONTENT_RENDERER_PEPPER_PEPPER_AUDIO_ENCODER_HOST_H_ |
OLD | NEW |