| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_SYNC_READER_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_SYNC_READER_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_SYNC_READER_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_SYNC_READER_H_ |
| 7 | 7 |
| 8 #include "base/file_descriptor_posix.h" | 8 #include "base/file_descriptor_posix.h" |
| 9 #include "base/process/process.h" | 9 #include "base/process/process.h" |
| 10 #include "base/sync_socket.h" | 10 #include "base/sync_socket.h" |
| 11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "media/audio/audio_output_controller.h" | 13 #include "media/audio/audio_output_controller.h" |
| 14 #include "media/base/audio_bus.h" | 14 #include "media/base/audio_bus.h" |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 class SharedMemory; | 17 class SharedMemory; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 | 21 |
| 22 // A AudioOutputController::SyncReader implementation using SyncSocket. This | 22 // A AudioOutputController::SyncReader implementation using SyncSocket. This |
| 23 // is used by AudioOutputController to provide a low latency data source for | 23 // is used by AudioOutputController to provide a low latency data source for |
| 24 // transmitting audio packets between the browser process and the renderer | 24 // transmitting audio packets between the browser process and the renderer |
| 25 // process. | 25 // process. |
| 26 class AudioSyncReader : public media::AudioOutputController::SyncReader { | 26 class AudioSyncReader : public media::AudioOutputController::SyncReader { |
| 27 public: | 27 public: |
| 28 AudioSyncReader(base::SharedMemory* shared_memory, | 28 AudioSyncReader(base::SharedMemory* shared_memory, |
| 29 const media::AudioParameters& params, | 29 const media::AudioParameters& params); |
| 30 int input_channels); | |
| 31 | 30 |
| 32 virtual ~AudioSyncReader(); | 31 virtual ~AudioSyncReader(); |
| 33 | 32 |
| 34 // media::AudioOutputController::SyncReader implementations. | 33 // media::AudioOutputController::SyncReader implementations. |
| 35 virtual void UpdatePendingBytes(uint32 bytes) OVERRIDE; | 34 virtual void UpdatePendingBytes(uint32 bytes) OVERRIDE; |
| 36 virtual void Read(const media::AudioBus* source, | 35 virtual void Read(const media::AudioBus* source, |
| 37 media::AudioBus* dest) OVERRIDE; | 36 media::AudioBus* dest) OVERRIDE; |
| 38 virtual void Close() OVERRIDE; | 37 virtual void Close() OVERRIDE; |
| 39 | 38 |
| 40 bool Init(); | 39 bool Init(); |
| 41 bool PrepareForeignSocketHandle(base::ProcessHandle process_handle, | 40 bool PrepareForeignSocketHandle(base::ProcessHandle process_handle, |
| 42 #if defined(OS_WIN) | 41 #if defined(OS_WIN) |
| 43 base::SyncSocket::Handle* foreign_handle); | 42 base::SyncSocket::Handle* foreign_handle); |
| 44 #else | 43 #else |
| 45 base::FileDescriptor* foreign_handle); | 44 base::FileDescriptor* foreign_handle); |
| 46 #endif | 45 #endif |
| 47 | 46 |
| 48 private: | 47 private: |
| 49 // Blocks until data is ready for reading or a timeout expires. Returns false | 48 // Blocks until data is ready for reading or a timeout expires. Returns false |
| 50 // if an error or timeout occurs. | 49 // if an error or timeout occurs. |
| 51 bool WaitUntilDataIsReady(); | 50 bool WaitUntilDataIsReady(); |
| 52 | 51 |
| 53 const base::SharedMemory* const shared_memory_; | 52 const base::SharedMemory* const shared_memory_; |
| 54 | 53 |
| 55 // Number of input channels for synchronized I/O. | |
| 56 const int input_channels_; | |
| 57 | |
| 58 // Mutes all incoming samples. This is used to prevent audible sound | 54 // Mutes all incoming samples. This is used to prevent audible sound |
| 59 // during automated testing. | 55 // during automated testing. |
| 60 const bool mute_audio_; | 56 const bool mute_audio_; |
| 61 | 57 |
| 62 // Socket for transmitting audio data. | 58 // Socket for transmitting audio data. |
| 63 scoped_ptr<base::CancelableSyncSocket> socket_; | 59 scoped_ptr<base::CancelableSyncSocket> socket_; |
| 64 | 60 |
| 65 // Socket to be used by the renderer. The reference is released after | 61 // Socket to be used by the renderer. The reference is released after |
| 66 // PrepareForeignSocketHandle() is called and ran successfully. | 62 // PrepareForeignSocketHandle() is called and ran successfully. |
| 67 scoped_ptr<base::CancelableSyncSocket> foreign_socket_; | 63 scoped_ptr<base::CancelableSyncSocket> foreign_socket_; |
| 68 | 64 |
| 69 // Shared memory wrapper used for transferring audio data to Read() callers. | 65 // Shared memory wrapper used for transferring audio data to Read() callers. |
| 70 scoped_ptr<media::AudioBus> output_bus_; | 66 scoped_ptr<media::AudioBus> output_bus_; |
| 71 | 67 |
| 72 // Shared memory wrapper used for transferring audio data from Read() callers. | |
| 73 scoped_ptr<media::AudioBus> input_bus_; | |
| 74 | |
| 75 // Maximum amount of audio data which can be transferred in one Read() call. | 68 // Maximum amount of audio data which can be transferred in one Read() call. |
| 76 const int packet_size_; | 69 const int packet_size_; |
| 77 | 70 |
| 78 // Track the number of times the renderer missed its real-time deadline and | 71 // Track the number of times the renderer missed its real-time deadline and |
| 79 // report a UMA stat during destruction. | 72 // report a UMA stat during destruction. |
| 80 size_t renderer_callback_count_; | 73 size_t renderer_callback_count_; |
| 81 size_t renderer_missed_callback_count_; | 74 size_t renderer_missed_callback_count_; |
| 82 | 75 |
| 83 // The maximum amount of time to wait for data from the renderer. Calculated | 76 // The maximum amount of time to wait for data from the renderer. Calculated |
| 84 // from the parameters given at construction. | 77 // from the parameters given at construction. |
| 85 const base::TimeDelta maximum_wait_time_; | 78 const base::TimeDelta maximum_wait_time_; |
| 86 | 79 |
| 87 // The index of the audio buffer we're expecting to be sent from the renderer; | 80 // The index of the audio buffer we're expecting to be sent from the renderer; |
| 88 // used to block with timeout for audio data. | 81 // used to block with timeout for audio data. |
| 89 uint32 buffer_index_; | 82 uint32 buffer_index_; |
| 90 | 83 |
| 91 DISALLOW_COPY_AND_ASSIGN(AudioSyncReader); | 84 DISALLOW_COPY_AND_ASSIGN(AudioSyncReader); |
| 92 }; | 85 }; |
| 93 | 86 |
| 94 } // namespace content | 87 } // namespace content |
| 95 | 88 |
| 96 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_SYNC_READER_H_ | 89 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_SYNC_READER_H_ |
| OLD | NEW |