Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / content / browser / renderer_host / media / audio_input_sync_writer.h
blob868219b4c660ff5891f2b3527a1c4dfa248d82bb
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/file_descriptor_posix.h"
9 #include "base/process.h"
10 #include "base/sync_socket.h"
11 #include "media/audio/audio_input_controller.h"
13 namespace base {
14 class SharedMemory;
17 namespace content {
18 // A AudioInputController::SyncWriter implementation using SyncSocket. This
19 // is used by AudioInputController to provide a low latency data source for
20 // transmitting audio packets between the browser process and the renderer
21 // process.
22 class AudioInputSyncWriter : public media::AudioInputController::SyncWriter {
23 public:
24 explicit AudioInputSyncWriter(base::SharedMemory* shared_memory,
25 int shared_memory_segment_count);
27 virtual ~AudioInputSyncWriter();
29 // media::AudioOutputController::SyncWriter implementation.
30 virtual void UpdateRecordedBytes(uint32 bytes) OVERRIDE;
31 virtual uint32 Write(const void* data, uint32 size, double volume) OVERRIDE;
32 virtual void Close() OVERRIDE;
34 bool Init();
35 bool PrepareForeignSocketHandle(base::ProcessHandle process_handle,
36 #if defined(OS_WIN)
37 base::SyncSocket::Handle* foreign_handle);
38 #else
39 base::FileDescriptor* foreign_handle);
40 #endif
42 private:
43 base::SharedMemory* shared_memory_;
44 uint32 shared_memory_segment_size_;
45 uint32 shared_memory_segment_count_;
46 uint32 current_segment_id_;
48 // Socket for transmitting audio data.
49 scoped_ptr<base::CancelableSyncSocket> socket_;
51 // Socket to be used by the renderer. The reference is released after
52 // PrepareForeignSocketHandle() is called and ran successfully.
53 scoped_ptr<base::CancelableSyncSocket> foreign_socket_;
55 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputSyncWriter);
58 } // namespace content
60 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_