blob: 1ace401441faec0bff55226b875064876ae94216 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_
#define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_
#include "base/memory/scoped_vector.h"
#include "base/process/process.h"
#include "base/sync_socket.h"
#include "base/time/time.h"
#include "media/audio/audio_input_controller.h"
#include "media/audio/audio_parameters.h"
#include "media/base/audio_bus.h"
#if defined(OS_POSIX)
#include "base/file_descriptor_posix.h"
#endif
namespace base {
class SharedMemory;
}
namespace content {
// A AudioInputController::SyncWriter implementation using SyncSocket. This
// is used by AudioInputController to provide a low latency data source for
// transmitting audio packets between the browser process and the renderer
// process.
class AudioInputSyncWriter : public media::AudioInputController::SyncWriter {
public:
explicit AudioInputSyncWriter(base::SharedMemory* shared_memory,
int shared_memory_segment_count,
const media::AudioParameters& params);
~AudioInputSyncWriter() override;
// media::AudioInputController::SyncWriter implementation.
void UpdateRecordedBytes(uint32 bytes) override;
void Write(const media::AudioBus* data,
double volume,
bool key_pressed) override;
void Close() override;
bool Init();
bool PrepareForeignSocket(base::ProcessHandle process_handle,
base::SyncSocket::TransitDescriptor* descriptor);
private:
base::SharedMemory* shared_memory_;
uint32 shared_memory_segment_size_;
uint32 shared_memory_segment_count_;
uint32 current_segment_id_;
// Socket for transmitting audio data.
scoped_ptr<base::CancelableSyncSocket> socket_;
// Socket to be used by the renderer. The reference is released after
// PrepareForeignSocketHandle() is called and ran successfully.
scoped_ptr<base::CancelableSyncSocket> foreign_socket_;
// The time of the creation of this object.
base::Time creation_time_;
// The time of the last Write call.
base::Time last_write_time_;
// Size in bytes of each audio bus.
const int audio_bus_memory_size_;
// Vector of audio buses allocated during construction and deleted in the
// destructor.
ScopedVector<media::AudioBus> audio_buses_;
DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputSyncWriter);
};
} // namespace content
#endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_SYNC_WRITER_H_
|