| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // AudioRendererHost serves audio related requests from AudioRenderer which | 5 // AudioRendererHost serves audio related requests from AudioRenderer which |
| 6 // lives inside the render process and provide access to audio hardware. It maps | 6 // lives inside the render process and provide access to audio hardware. It maps |
| 7 // an internal ID to AudioRendererHost::IPCAudioSource in a map, which is the | 7 // an internal ID to AudioRendererHost::IPCAudioSource in a map, which is the |
| 8 // actual object providing audio packets through IPC. It creates the actual | 8 // actual object providing audio packets through IPC. It creates the actual |
| 9 // AudioOutputStream object when requested by the renderer provided with | 9 // AudioOutputStream object when requested by the renderer provided with |
| 10 // render view id and stream id. | 10 // render view id and stream id. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 #ifndef CHROME_BROWSER_RENDERER_HOST_AUDIO_RENDERER_HOST_H_ | 67 #ifndef CHROME_BROWSER_RENDERER_HOST_AUDIO_RENDERER_HOST_H_ |
| 68 #define CHROME_BROWSER_RENDERER_HOST_AUDIO_RENDERER_HOST_H_ | 68 #define CHROME_BROWSER_RENDERER_HOST_AUDIO_RENDERER_HOST_H_ |
| 69 | 69 |
| 70 #include <map> | 70 #include <map> |
| 71 | 71 |
| 72 #include "base/lock.h" | 72 #include "base/lock.h" |
| 73 #include "base/process.h" | 73 #include "base/process.h" |
| 74 #include "base/ref_counted.h" | 74 #include "base/ref_counted.h" |
| 75 #include "base/shared_memory.h" | 75 #include "base/shared_memory.h" |
| 76 #include "base/waitable_event.h" | 76 #include "base/waitable_event.h" |
| 77 #include "chrome/browser/chrome_thread.h" |
| 77 #include "ipc/ipc_message.h" | 78 #include "ipc/ipc_message.h" |
| 78 #include "media/audio/audio_output.h" | 79 #include "media/audio/audio_output.h" |
| 79 #include "media/audio/simple_sources.h" | 80 #include "media/audio/simple_sources.h" |
| 80 #include "testing/gtest/include/gtest/gtest_prod.h" | 81 #include "testing/gtest/include/gtest/gtest_prod.h" |
| 81 | 82 |
| 82 class AudioManager; | 83 class AudioManager; |
| 83 struct ViewHostMsg_Audio_CreateStream; | 84 struct ViewHostMsg_Audio_CreateStream; |
| 84 | 85 |
| 85 class AudioRendererHost : public base::RefCountedThreadSafe<AudioRendererHost> { | 86 class AudioRendererHost |
| 87 : public base::RefCountedThreadSafe< |
| 88 AudioRendererHost, ChromeThread::DeleteOnIOThread> { |
| 86 private: | 89 private: |
| 87 class IPCAudioSource; | 90 class IPCAudioSource; |
| 88 public: | 91 public: |
| 89 // Called from UI thread from the owner of this object. | 92 // Called from UI thread from the owner of this object. |
| 90 AudioRendererHost(); | 93 AudioRendererHost(); |
| 91 | 94 |
| 92 // Destruction can happen on either UI thread or IO thread, but at destruction | 95 // Destruction always happens on the IO thread (see DeleteOnIOThread above). |
| 93 // all associated sources are destroyed and streams are closed. | |
| 94 virtual ~AudioRendererHost(); | 96 virtual ~AudioRendererHost(); |
| 95 | 97 |
| 96 // Called from UI thread from the owner of this object to kick start | 98 // Called from UI thread from the owner of this object to kick start |
| 97 // destruction of streams in IO thread. | 99 // destruction of streams in IO thread. |
| 98 void Destroy(); | 100 void Destroy(); |
| 99 | 101 |
| 100 //--------------------------------------------------------------------------- | 102 //--------------------------------------------------------------------------- |
| 101 // The following public methods are called from ResourceMessageFilter in the | 103 // The following public methods are called from ResourceMessageFilter in the |
| 102 // IO thread. | 104 // IO thread. |
| 103 | 105 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 void OnGetVolume(const IPC::Message& msg, int stream_id); | 310 void OnGetVolume(const IPC::Message& msg, int stream_id); |
| 309 | 311 |
| 310 // Notify packet has been prepared for stream, delegates to corresponding | 312 // Notify packet has been prepared for stream, delegates to corresponding |
| 311 // IPCAudioSource::NotifyPacketReady(), see the method for more details. | 313 // IPCAudioSource::NotifyPacketReady(), see the method for more details. |
| 312 // ViewMsg_NotifyAudioStreamStateChanged with | 314 // ViewMsg_NotifyAudioStreamStateChanged with |
| 313 // AudioOutputStream::AUDIO_STREAM_ERROR is sent back to renderer if the | 315 // AudioOutputStream::AUDIO_STREAM_ERROR is sent back to renderer if the |
| 314 // required IPCAudioSource is not found. | 316 // required IPCAudioSource is not found. |
| 315 void OnNotifyPacketReady(const IPC::Message& msg, int stream_id, | 317 void OnNotifyPacketReady(const IPC::Message& msg, int stream_id, |
| 316 size_t packet_size); | 318 size_t packet_size); |
| 317 | 319 |
| 318 // Called on IO thread when this object is created and initialized. | |
| 319 void OnInitialized(); | |
| 320 | |
| 321 // Called on IO thread when this object needs to be destroyed and after | 320 // Called on IO thread when this object needs to be destroyed and after |
| 322 // Destroy() is called from owner of this class in UI thread. | 321 // Destroy() is called from owner of this class in UI thread. |
| 323 void OnDestroyed(); | 322 void OnDestroyed(); |
| 324 | 323 |
| 325 // Sends IPC messages using ipc_sender_. | 324 // Sends IPC messages using ipc_sender_. |
| 326 void OnSend(IPC::Message* message); | 325 void OnSend(IPC::Message* message); |
| 327 | 326 |
| 328 // Closes the source, deletes it and removes it from the internal map. | 327 // Closes the source, deletes it and removes it from the internal map. |
| 329 // Destruction of source and associated stream should always be done by this | 328 // Destruction of source and associated stream should always be done by this |
| 330 // method. *DO NOT* call this method from other than IPCAudioSource and from | 329 // method. *DO NOT* call this method from other than IPCAudioSource and from |
| (...skipping 14 matching lines...) Expand all Loading... |
| 345 | 344 |
| 346 // A map of id to audio sources. | 345 // A map of id to audio sources. |
| 347 typedef std::pair<int32, int32> SourceID; | 346 typedef std::pair<int32, int32> SourceID; |
| 348 typedef std::map<SourceID, IPCAudioSource*> SourceMap; | 347 typedef std::map<SourceID, IPCAudioSource*> SourceMap; |
| 349 SourceMap sources_; | 348 SourceMap sources_; |
| 350 | 349 |
| 351 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); | 350 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); |
| 352 }; | 351 }; |
| 353 | 352 |
| 354 #endif // CHROME_BROWSER_RENDERER_HOST_AUDIO_RENDERER_HOST_H_ | 353 #endif // CHROME_BROWSER_RENDERER_HOST_AUDIO_RENDERER_HOST_H_ |
| OLD | NEW |