Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(673)

Side by Side Diff: media/audio/pulse/pulse_util.cc

Issue 10952024: Adding pulseaudio input support to chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased and addressed Dale's final comments. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/audio/pulse/pulse_util.h ('k') | media/media.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "media/audio/pulse/pulse_util.h"
6
7 #include "base/logging.h"
8 #include "base/time.h"
9 #include "media/audio/audio_manager_base.h"
10
11 namespace media {
12
13 namespace pulse {
14
15 namespace {
16
17 pa_channel_position ChromiumToPAChannelPosition(Channels channel) {
18 switch (channel) {
19 // PulseAudio does not differentiate between left/right and
20 // stereo-left/stereo-right, both translate to front-left/front-right.
21 case LEFT:
22 return PA_CHANNEL_POSITION_FRONT_LEFT;
23 case RIGHT:
24 return PA_CHANNEL_POSITION_FRONT_RIGHT;
25 case CENTER:
26 return PA_CHANNEL_POSITION_FRONT_CENTER;
27 case LFE:
28 return PA_CHANNEL_POSITION_LFE;
29 case BACK_LEFT:
30 return PA_CHANNEL_POSITION_REAR_LEFT;
31 case BACK_RIGHT:
32 return PA_CHANNEL_POSITION_REAR_RIGHT;
33 case LEFT_OF_CENTER:
34 return PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER;
35 case RIGHT_OF_CENTER:
36 return PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER;
37 case BACK_CENTER:
38 return PA_CHANNEL_POSITION_REAR_CENTER;
39 case SIDE_LEFT:
40 return PA_CHANNEL_POSITION_SIDE_LEFT;
41 case SIDE_RIGHT:
42 return PA_CHANNEL_POSITION_SIDE_RIGHT;
43 case CHANNELS_MAX:
44 return PA_CHANNEL_POSITION_INVALID;
45 default:
46 NOTREACHED() << "Invalid channel: " << channel;
47 return PA_CHANNEL_POSITION_INVALID;
48 }
49 }
50
51 } // namespace
52
53 // static, pa_stream_success_cb_t
54 void StreamSuccessCallback(pa_stream* s, int error, void* mainloop) {
55 pa_threaded_mainloop* pa_mainloop =
56 static_cast<pa_threaded_mainloop*>(mainloop);
57 pa_threaded_mainloop_signal(pa_mainloop, 0);
58 }
59
60 // |pa_context| and |pa_stream| state changed cb.
61 void ContextStateCallback(pa_context* context, void* mainloop) {
62 pa_threaded_mainloop* pa_mainloop =
63 static_cast<pa_threaded_mainloop*>(mainloop);
64 pa_threaded_mainloop_signal(pa_mainloop, 0);
65 }
66
67 pa_sample_format_t BitsToPASampleFormat(int bits_per_sample) {
68 switch (bits_per_sample) {
69 case 8:
70 return PA_SAMPLE_U8;
71 case 16:
72 return PA_SAMPLE_S16LE;
73 case 24:
74 return PA_SAMPLE_S24LE;
75 case 32:
76 return PA_SAMPLE_S32LE;
77 default:
78 NOTREACHED() << "Invalid bits per sample: " << bits_per_sample;
79 return PA_SAMPLE_INVALID;
80 }
81 }
82
83 pa_channel_map ChannelLayoutToPAChannelMap(ChannelLayout channel_layout) {
84 pa_channel_map channel_map;
85 pa_channel_map_init(&channel_map);
86
87 channel_map.channels = ChannelLayoutToChannelCount(channel_layout);
88 for (Channels ch = LEFT; ch < CHANNELS_MAX;
89 ch = static_cast<Channels>(ch + 1)) {
90 int channel_index = ChannelOrder(channel_layout, ch);
91 if (channel_index < 0)
92 continue;
93
94 channel_map.map[channel_index] = ChromiumToPAChannelPosition(ch);
95 }
96
97 return channel_map;
98 }
99
100 void WaitForOperationCompletion(pa_threaded_mainloop* pa_mainloop,
101 pa_operation* operation) {
102 if (!operation) {
103 DLOG(WARNING) << "Operation is NULL";
104 return;
105 }
106
107 while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING)
108 pa_threaded_mainloop_wait(pa_mainloop);
109
110 pa_operation_unref(operation);
111 }
112
113 int GetHardwareLatencyInBytes(pa_stream* stream,
114 int sample_rate,
115 int bytes_per_frame) {
116 DCHECK(stream);
117 int negative = 0;
118 pa_usec_t latency_micros = 0;
119 if (pa_stream_get_latency(stream, &latency_micros, &negative) != 0)
120 return 0;
121
122 if (negative)
123 return 0;
124
125 return latency_micros * sample_rate * bytes_per_frame /
126 base::Time::kMicrosecondsPerSecond;
127 }
128
129 } // namespace pulse
130
131 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/pulse/pulse_util.h ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698