OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef PPAPI_PROXY_AUDIO_ENCODER_RESOURCE_H_ | 5 #ifndef PPAPI_PROXY_AUDIO_ENCODER_RESOURCE_H_ |
6 #define PPAPI_PROXY_AUDIO_ENCODER_RESOURCE_H_ | 6 #define PPAPI_PROXY_AUDIO_ENCODER_RESOURCE_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "ppapi/proxy/connection.h" | 12 #include "ppapi/proxy/connection.h" |
13 #include "ppapi/proxy/plugin_resource.h" | 13 #include "ppapi/proxy/plugin_resource.h" |
14 #include "ppapi/shared_impl/media_stream_buffer_manager.h" | |
14 #include "ppapi/shared_impl/resource.h" | 15 #include "ppapi/shared_impl/resource.h" |
15 #include "ppapi/thunk/ppb_audio_encoder_api.h" | 16 #include "ppapi/thunk/ppb_audio_encoder_api.h" |
16 | 17 |
17 namespace ppapi { | 18 namespace ppapi { |
18 | 19 |
19 class TrackedCallback; | 20 class TrackedCallback; |
20 | 21 |
21 namespace proxy { | 22 namespace proxy { |
22 | 23 |
23 class SerializedHandle; | 24 class AudioBufferResource; |
24 class VideoFrameResource; | |
25 | 25 |
26 class PPAPI_PROXY_EXPORT AudioEncoderResource | 26 class PPAPI_PROXY_EXPORT AudioEncoderResource |
27 : public PluginResource, | 27 : public PluginResource, |
28 public thunk::PPB_AudioEncoder_API { | 28 public thunk::PPB_AudioEncoder_API, |
29 public ppapi::MediaStreamBufferManager::Delegate { | |
29 public: | 30 public: |
30 AudioEncoderResource(Connection connection, PP_Instance instance); | 31 AudioEncoderResource(Connection connection, PP_Instance instance); |
31 ~AudioEncoderResource() override; | 32 ~AudioEncoderResource() override; |
32 | 33 |
33 thunk::PPB_AudioEncoder_API* AsPPB_AudioEncoder_API() override; | 34 thunk::PPB_AudioEncoder_API* AsPPB_AudioEncoder_API() override; |
34 | 35 |
35 private: | 36 private: |
36 // PPB_AduioEncoder_API implementation. | 37 class BitstreamBufferManager; |
38 | |
39 // MediaStreamBufferManager::Delegate implementation. | |
40 void OnNewBufferEnqueued() override {} | |
41 | |
42 // PPB_AudioEncoder_API implementation. | |
37 int32_t GetSupportedProfiles( | 43 int32_t GetSupportedProfiles( |
38 const PP_ArrayOutput& output, | 44 const PP_ArrayOutput& output, |
39 const scoped_refptr<TrackedCallback>& callback) override; | 45 const scoped_refptr<TrackedCallback>& callback) override; |
40 int32_t Initialize(uint32_t channels, | 46 int32_t Initialize(uint32_t channels, |
41 PP_AudioBuffer_SampleRate input_sample_rate, | 47 PP_AudioBuffer_SampleRate input_sample_rate, |
42 PP_AudioBuffer_SampleSize input_sample_size, | 48 PP_AudioBuffer_SampleSize input_sample_size, |
43 PP_AudioProfile output_profile, | 49 PP_AudioProfile output_profile, |
44 uint32_t initial_bitrate, | 50 uint32_t initial_bitrate, |
45 PP_HardwareAcceleration acceleration, | 51 PP_HardwareAcceleration acceleration, |
46 const scoped_refptr<TrackedCallback>& callback) override; | 52 const scoped_refptr<TrackedCallback>& callback) override; |
47 int32_t GetNumberOfSamples() override; | 53 int32_t GetNumberOfSamples() override; |
48 int32_t GetBuffer(PP_Resource* audio_buffer, | 54 int32_t GetBuffer(PP_Resource* audio_buffer, |
49 const scoped_refptr<TrackedCallback>& callback) override; | 55 const scoped_refptr<TrackedCallback>& callback) override; |
50 int32_t Encode(PP_Resource audio_buffer, | 56 int32_t Encode(PP_Resource audio_buffer, |
51 const scoped_refptr<TrackedCallback>& callback) override; | 57 const scoped_refptr<TrackedCallback>& callback) override; |
52 int32_t GetBitstreamBuffer( | 58 int32_t GetBitstreamBuffer( |
53 PP_AudioBitstreamBuffer* bitstream_buffer, | 59 PP_AudioBitstreamBuffer* bitstream_buffer, |
54 const scoped_refptr<TrackedCallback>& callback) override; | 60 const scoped_refptr<TrackedCallback>& callback) override; |
55 void RecycleBitstreamBuffer( | 61 void RecycleBitstreamBuffer( |
56 const PP_AudioBitstreamBuffer* bitstream_buffer) override; | 62 const PP_AudioBitstreamBuffer* bitstream_buffer) override; |
57 void RequestBitrateChange(uint32_t bitrate) override; | 63 void RequestBitrateChange(uint32_t bitrate) override; |
58 void Close() override; | 64 void Close() override; |
59 | 65 |
66 // PluginResource implementation. | |
67 void OnReplyReceived(const ResourceMessageReplyParams& params, | |
68 const IPC::Message& msg) override; | |
69 | |
70 // Message handlers for the host's messages. | |
71 void OnPluginMsgGetSupportedProfilesReply( | |
72 const PP_ArrayOutput& output, | |
73 const ResourceMessageReplyParams& params, | |
74 const std::vector<PP_AudioProfileDescription>& profiles); | |
75 void OnPluginMsgInitializeReply(const ResourceMessageReplyParams& params, | |
76 int32_t number_of_samples, | |
77 int32_t audio_buffer_count, | |
78 int32_t audio_buffer_size, | |
79 int32_t bitstream_buffer_count, | |
80 int32_t bitstream_buffer_size); | |
81 void OnPluginMsgEncodeReply(const ResourceMessageReplyParams& params, | |
82 int32_t buffer_id); | |
83 void OnPluginMsgBitstreamBufferReady(const ResourceMessageReplyParams& params, | |
84 int32_t buffer_id, | |
85 int32_t buffer_size); | |
86 void OnPluginMsgNotifyError(const ResourceMessageReplyParams& params, | |
87 int32_t error); | |
88 | |
89 // Internal utility functions. | |
90 void NotifyError(int32_t error); | |
91 void TryWriteAudioBuffer(); | |
92 void TryWriteBitstreamBuffer(); | |
93 void ReleaseBuffers(); | |
94 | |
95 int32_t encoder_last_error_; | |
96 | |
97 bool initialized_; | |
98 bool closed_; | |
99 | |
100 uint32_t number_of_samples_; | |
101 | |
102 typedef std::map<PP_Resource, scoped_refptr<AudioBufferResource>> | |
103 AudioBufferMap; | |
bbudge
2015/11/17 00:53:41
nit: using
llandwerlin-old
2015/11/17 15:22:31
Done.
| |
104 AudioBufferMap audio_buffers_; | |
105 | |
106 scoped_refptr<TrackedCallback> get_supported_profiles_callback_; | |
107 scoped_refptr<TrackedCallback> initialize_callback_; | |
108 scoped_refptr<TrackedCallback> get_buffer_callback_; | |
109 PP_Resource* get_buffer_data_; | |
110 | |
111 using EncodeMap = std::map<int32_t, scoped_refptr<TrackedCallback>>; | |
112 EncodeMap encode_callbacks_; | |
113 | |
114 scoped_refptr<TrackedCallback> get_bitstream_buffer_callback_; | |
115 PP_AudioBitstreamBuffer* get_bitstream_buffer_data_; | |
116 | |
117 // Buffer manager for audio frames. | |
bbudge
2015/11/17 00:53:41
I wouldn't complain if you dropped the comments on
llandwerlin-old
2015/11/17 15:22:31
Done.
| |
118 MediaStreamBufferManager audio_buffer_manager_; | |
119 | |
120 // Buffer manager for bitstream buffers. | |
121 MediaStreamBufferManager bitstream_buffer_manager_; | |
122 | |
123 // Queue of sizes of bitstream buffers ready to hand over to the plugin. | |
124 std::deque<int32_t> bitstream_queued_buffer_sizes_; | |
125 | |
126 // Map of bitstream buffer point to buffer ids. | |
bbudge
2015/11/17 00:53:41
s/point/pointers
llandwerlin-old
2015/11/17 15:22:31
Done.
| |
127 using BufferMap = std::map<void*, int32_t>; | |
128 BufferMap bitstream_buffer_map_; | |
129 | |
60 DISALLOW_COPY_AND_ASSIGN(AudioEncoderResource); | 130 DISALLOW_COPY_AND_ASSIGN(AudioEncoderResource); |
61 }; | 131 }; |
62 | 132 |
63 } // namespace proxy | 133 } // namespace proxy |
64 } // namespace ppapi | 134 } // namespace ppapi |
65 | 135 |
66 #endif // PPAPI_PROXY_AUDIO_ENCODER_RESOURCE_H_ | 136 #endif // PPAPI_PROXY_AUDIO_ENCODER_RESOURCE_H_ |
OLD | NEW |