Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / content / browser / renderer_host / media / audio_input_sync_writer.h
blob75b2bbf1e2efba4f77b26e0470756ed7b2ad94dd
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_
8 #include "base/process/process.h"
9 #include "base/sync_socket.h"
10 #include "base/time/time.h"
11 #include "media/audio/audio_input_controller.h"
13 #if defined(OS_POSIX)
14 #include "base/file_descriptor_posix.h"
15 #endif
17 namespace base {
18 class SharedMemory;
21 namespace content {
22 // A AudioInputController::SyncWriter implementation using SyncSocket. This
23 // is used by AudioInputController to provide a low latency data source for
24 // transmitting audio packets between the browser process and the renderer
25 // process.
26 class AudioInputSyncWriter : public media::AudioInputController::SyncWriter {
27 public:
28 explicit AudioInputSyncWriter(base::SharedMemory* shared_memory,
29 int shared_memory_segment_count);
31 virtual ~AudioInputSyncWriter();
33 // media::AudioOutputController::SyncWriter implementation.
34 virtual void UpdateRecordedBytes(uint32 bytes) OVERRIDE;
35 virtual uint32 Write(const void* data,
36 uint32 size,
37 double volume,
38 bool key_pressed) OVERRIDE;
39 virtual void Close() OVERRIDE;
41 bool Init();
42 bool PrepareForeignSocketHandle(base::ProcessHandle process_handle,
43 #if defined(OS_WIN)
44 base::SyncSocket::Handle* foreign_handle);
45 #else
46 base::FileDescriptor* foreign_handle);
47 #endif
49 private:
50 base::SharedMemory* shared_memory_;
51 uint32 shared_memory_segment_size_;
52 uint32 shared_memory_segment_count_;
53 uint32 current_segment_id_;
55 // Socket for transmitting audio data.
56 scoped_ptr<base::CancelableSyncSocket> socket_;
58 // Socket to be used by the renderer. The reference is released after
59 // PrepareForeignSocketHandle() is called and ran successfully.
60 scoped_ptr<base::CancelableSyncSocket> foreign_socket_;
62 // The time of the creation of this object.
63 base::Time creation_time_;
65 // The time of the last Write call.
66 base::Time last_write_time_;
68 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputSyncWriter);
71 } // namespace content
73 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_