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

Side by Side Diff: content/browser/renderer_host/media/audio_input_renderer_host.h

Issue 7157001: Implements AudioMessageFilter as member in RenderThread (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Fixed nits in AudioRenderImpl unit test Created 9 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // AudioInputRendererHost serves audio related requests from audio capturer 5 // AudioInputRendererHost serves audio related requests from audio capturer
6 // which lives inside the render process and provide access to audio hardware. 6 // which lives inside the render process and provide access to audio hardware.
7 // 7 //
8 // This class is owned by BrowserRenderProcessHost and instantiated on UI 8 // This class is owned by BrowserRenderProcessHost and instantiated on UI
9 // thread. All other operations and method calls happen on IO thread, so we 9 // thread. All other operations and method calls happen on IO thread, so we
10 // need to be extra careful about the lifetime of this object. AudioManager is a 10 // need to be extra careful about the lifetime of this object. AudioManager is a
(...skipping 20 matching lines...) Expand all
31 #include "media/audio/audio_input_controller.h" 31 #include "media/audio/audio_input_controller.h"
32 #include "media/audio/audio_io.h" 32 #include "media/audio/audio_io.h"
33 #include "media/audio/simple_sources.h" 33 #include "media/audio/simple_sources.h"
34 34
35 class AudioManager; 35 class AudioManager;
36 struct AudioParameters; 36 struct AudioParameters;
37 37
38 class AudioInputRendererHost : public BrowserMessageFilter, 38 class AudioInputRendererHost : public BrowserMessageFilter,
39 public media::AudioInputController::EventHandler { 39 public media::AudioInputController::EventHandler {
40 public: 40 public:
41 typedef std::pair<int32, int> AudioEntryId;
42
43 struct AudioEntry { 41 struct AudioEntry {
44 AudioEntry(); 42 AudioEntry();
45 ~AudioEntry(); 43 ~AudioEntry();
46 44
47 // The AudioInputController that manages the audio input stream. 45 // The AudioInputController that manages the audio input stream.
48 scoped_refptr<media::AudioInputController> controller; 46 scoped_refptr<media::AudioInputController> controller;
49 47
50 // Render view ID that requested the audio input stream.
51 int32 render_view_id;
52
53 // The audio input stream ID in the render view. 48 // The audio input stream ID in the render view.
54 int stream_id; 49 int stream_id;
55 50
56 // Shared memory for transmission of the audio data. 51 // Shared memory for transmission of the audio data.
57 base::SharedMemory shared_memory; 52 base::SharedMemory shared_memory;
58 53
59 // The synchronous writer to be used by the controller. We have the 54 // The synchronous writer to be used by the controller. We have the
60 // ownership of the writer. 55 // ownership of the writer.
61 scoped_ptr<media::AudioInputController::SyncWriter> writer; 56 scoped_ptr<media::AudioInputController::SyncWriter> writer;
62 57
63 // Set to true after we called Close() for the controller. 58 // Set to true after we called Close() for the controller.
64 bool pending_close; 59 bool pending_close;
65 }; 60 };
66 61
67 typedef std::map<AudioEntryId, AudioEntry*> AudioEntryMap; 62 typedef std::map<int, AudioEntry*> AudioEntryMap;
68 63
69 // Called from UI thread from the owner of this object. 64 // Called from UI thread from the owner of this object.
70 AudioInputRendererHost(); 65 AudioInputRendererHost();
71 66
72 // BrowserMessageFilter implementation. 67 // BrowserMessageFilter implementation.
73 virtual void OnChannelClosing(); 68 virtual void OnChannelClosing();
74 virtual void OnDestruct() const; 69 virtual void OnDestruct() const;
75 virtual bool OnMessageReceived(const IPC::Message& message, 70 virtual bool OnMessageReceived(const IPC::Message& message,
76 bool* message_was_ok); 71 bool* message_was_ok);
77 72
78 // AudioInputController::EventHandler implementation. 73 // AudioInputController::EventHandler implementation.
79 virtual void OnCreated(media::AudioInputController* controller); 74 virtual void OnCreated(media::AudioInputController* controller);
80 virtual void OnRecording(media::AudioInputController* controller); 75 virtual void OnRecording(media::AudioInputController* controller);
81 virtual void OnError(media::AudioInputController* controller, 76 virtual void OnError(media::AudioInputController* controller,
82 int error_code); 77 int error_code);
83 virtual void OnData(media::AudioInputController* controller, 78 virtual void OnData(media::AudioInputController* controller,
84 const uint8* data, 79 const uint8* data,
85 uint32 size); 80 uint32 size);
86 81
87 private: 82 private:
88 // TODO(henrika): extend test suite (compare AudioRenderHost) 83 // TODO(henrika): extend test suite (compare AudioRenderHost)
89 friend class BrowserThread; 84 friend class BrowserThread;
90 friend class DeleteTask<AudioInputRendererHost>; 85 friend class DeleteTask<AudioInputRendererHost>;
91 86
92 virtual ~AudioInputRendererHost(); 87 virtual ~AudioInputRendererHost();
93 88
94 // Methods called on IO thread. 89 // Methods called on IO thread ----------------------------------------------
95 // Returns true if the message is an audio input related message and should
96 // be handled by this class.
97 bool IsAudioRendererHostMessage(const IPC::Message& message);
98 90
99 // Audio related IPC message handlers. 91 // Audio related IPC message handlers.
100 // Creates an audio input stream with the specified format. If this call is 92 // Creates an audio input stream with the specified format. If this call is
101 // successful this object would keep an internal entry of the stream for the 93 // successful this object would keep an internal entry of the stream for the
102 // required properties. 94 // required properties.
103 void OnCreateStream(const IPC::Message& msg, int stream_id, 95 void OnCreateStream(int stream_id,
104 const AudioParameters& params, 96 const AudioParameters& params,
105 bool low_latency); 97 bool low_latency);
106 98
107 // Record the audio input stream referenced by |stream_id|. 99 // Record the audio input stream referenced by |stream_id|.
108 void OnRecordStream(const IPC::Message& msg, int stream_id); 100 void OnRecordStream(int stream_id);
109 101
110 // Close the audio stream referenced by |stream_id|. 102 // Close the audio stream referenced by |stream_id|.
111 void OnCloseStream(const IPC::Message& msg, int stream_id); 103 void OnCloseStream(int stream_id);
112 104
113 // Set the volume of the audio stream referenced by |stream_id|. 105 // Set the volume of the audio stream referenced by |stream_id|.
114 void OnSetVolume(const IPC::Message& msg, int stream_id, double volume); 106 void OnSetVolume(int stream_id, double volume);
115 107
116 // Get the volume of the audio stream referenced by |stream_id|. 108 // Get the volume of the audio stream referenced by |stream_id|.
117 void OnGetVolume(const IPC::Message& msg, int stream_id); 109 void OnGetVolume(int stream_id);
118 110
119 // Complete the process of creating an audio input stream. This will set up 111 // Complete the process of creating an audio input stream. This will set up
120 // the shared memory or shared socket in low latency mode. 112 // the shared memory or shared socket in low latency mode.
121 void DoCompleteCreation(media::AudioInputController* controller); 113 void DoCompleteCreation(media::AudioInputController* controller);
122 114
123 // Send a state change message to the renderer. 115 // Send a state change message to the renderer.
124 void DoSendRecordingMessage(media::AudioInputController* controller); 116 void DoSendRecordingMessage(media::AudioInputController* controller);
125 void DoSendPausedMessage(media::AudioInputController* controller); 117 void DoSendPausedMessage(media::AudioInputController* controller);
126 118
127 // Handle error coming from audio stream. 119 // Handle error coming from audio stream.
128 void DoHandleError(media::AudioInputController* controller, int error_code); 120 void DoHandleError(media::AudioInputController* controller, int error_code);
129 121
130 // Send an error message to the renderer. 122 // Send an error message to the renderer.
131 void SendErrorMessage(int32 render_view_id, int32 stream_id); 123 void SendErrorMessage(int stream_id);
132 124
133 // Delete all audio entry and all audio streams 125 // Delete all audio entry and all audio streams
134 void DeleteEntries(); 126 void DeleteEntries();
135 127
136 // Closes the stream. The stream is then deleted in DeleteEntry() after it 128 // Closes the stream. The stream is then deleted in DeleteEntry() after it
137 // is closed. 129 // is closed.
138 void CloseAndDeleteStream(AudioEntry* entry); 130 void CloseAndDeleteStream(AudioEntry* entry);
139 131
140 // Called on the audio thread after the audio input stream is closed. 132 // Called on the audio thread after the audio input stream is closed.
141 void OnStreamClosed(AudioEntry* entry); 133 void OnStreamClosed(AudioEntry* entry);
142 134
143 // Delete an audio entry and close the related audio stream. 135 // Delete an audio entry and close the related audio stream.
144 void DeleteEntry(AudioEntry* entry); 136 void DeleteEntry(AudioEntry* entry);
145 137
146 // Delete audio entry and close the related audio input stream. 138 // Delete audio entry and close the related audio input stream.
147 void DeleteEntryOnError(AudioEntry* entry); 139 void DeleteEntryOnError(AudioEntry* entry);
148 140
149 // A helper method to look up a AudioEntry with a tuple of render view 141 // A helper method to look up a AudioEntry identified by |stream_id|.
150 // id and stream id. Returns NULL if not found. 142 // Returns NULL if not found.
151 AudioEntry* LookupById(int render_view_id, int stream_id); 143 AudioEntry* LookupById(int stream_id);
152 144
153 // Search for a AudioEntry having the reference to |controller|. 145 // Search for a AudioEntry having the reference to |controller|.
154 // This method is used to look up an AudioEntry after a controller 146 // This method is used to look up an AudioEntry after a controller
155 // event is received. 147 // event is received.
156 AudioEntry* LookupByController(media::AudioInputController* controller); 148 AudioEntry* LookupByController(media::AudioInputController* controller);
157 149
158 // A map of id to audio sources. 150 // A map of stream IDs to audio sources.
159 AudioEntryMap audio_entries_; 151 AudioEntryMap audio_entries_;
160 152
161 DISALLOW_COPY_AND_ASSIGN(AudioInputRendererHost); 153 DISALLOW_COPY_AND_ASSIGN(AudioInputRendererHost);
162 }; 154 };
163 155
164 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_RENDERER_HOST_H_ 156 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_RENDERER_HOST_H_
OLDNEW
« no previous file with comments | « chrome/browser/media/media_internals.cc ('k') | content/browser/renderer_host/media/audio_input_renderer_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698