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

Side by Side Diff: media/audio/linux/alsa_wrapper.cc

Issue 11019010: replace snd_pcm_hw_params_set_* with snd_pcm_set_params. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "media/audio/linux/alsa_wrapper.h" 5 #include "media/audio/linux/alsa_wrapper.h"
6 6
7 #include <alsa/asoundlib.h> 7 #include <alsa/asoundlib.h>
8 8
9 namespace media { 9 namespace media {
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 65
66 int AlsaWrapper::PcmRecover(snd_pcm_t* handle, int err, int silent) { 66 int AlsaWrapper::PcmRecover(snd_pcm_t* handle, int err, int silent) {
67 return snd_pcm_recover(handle, err, silent); 67 return snd_pcm_recover(handle, err, silent);
68 } 68 }
69 69
70 const char* AlsaWrapper::PcmName(snd_pcm_t* handle) { 70 const char* AlsaWrapper::PcmName(snd_pcm_t* handle) {
71 return snd_pcm_name(handle); 71 return snd_pcm_name(handle);
72 } 72 }
73 73
74 int AlsaWrapper::ConfigureHwParams(snd_pcm_t* handle,
75 snd_pcm_hw_params_t* hw_params,
76 snd_pcm_format_t format,
77 snd_pcm_access_t access,
78 unsigned int channels,
79 unsigned int rate,
80 int soft_resample,
81 unsigned int latency) {
82 int err = 0;
83 if ((err = snd_pcm_hw_params_any(handle, hw_params)) < 0)
84 return err;
85
86 if ((err = snd_pcm_hw_params_set_rate_resample(handle, hw_params,
87 soft_resample)) < 0) {
88 return err;
89 }
90
91 if ((err = snd_pcm_hw_params_set_format(handle, hw_params, format)) < 0)
92 return err;
93
94 int dir = 0;
95 unsigned new_rate = rate;
96 if ((err = snd_pcm_hw_params_set_rate_near(handle, hw_params,
97 &new_rate, &dir)) < 0) {
98 return err;
99 }
100
101 if ((err = snd_pcm_hw_params_set_access(handle, hw_params, access)) < 0)
102 return err;
103
104 if ((err = snd_pcm_hw_params_set_channels(handle, hw_params, channels)) < 0)
105 return err;
106
107 unsigned buffer_time = latency;
108 if (buffer_time == 0) {
109 if ((err = snd_pcm_hw_params_get_buffer_time_max(hw_params,
110 &buffer_time, 0)) < 0) {
111 return err;
112 }
113 if (buffer_time > 500000)
114 buffer_time = 500000;
115 }
116
117 unsigned period_time = buffer_time / 4;
118 if ((err = snd_pcm_hw_params_set_period_time_near(handle, hw_params,
119 &period_time, 0)) < 0) {
120 return err;
121 }
122
123 err = snd_pcm_hw_params_set_buffer_time_near(handle, hw_params,
124 &buffer_time, 0);
125 return err;
126 }
127
128 int AlsaWrapper::PcmSetParams(snd_pcm_t* handle, snd_pcm_format_t format, 74 int AlsaWrapper::PcmSetParams(snd_pcm_t* handle, snd_pcm_format_t format,
129 snd_pcm_access_t access, unsigned int channels, 75 snd_pcm_access_t access, unsigned int channels,
130 unsigned int rate, int soft_resample, 76 unsigned int rate, int soft_resample,
131 unsigned int latency) { 77 unsigned int latency) {
132 int err = 0; 78 return snd_pcm_set_params(handle, format,
133 snd_pcm_hw_params_t* hw_params; 79 SND_PCM_ACCESS_RW_INTERLEAVED,
DaleCurtis 2012/10/01 18:59:16 What is the difference between SND_PCM_ACCESS_MMAP
no longer working on chromium 2012/10/01 19:51:13 Sorry, it was one of some quick fixes I tried, I s
134 if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0) 80 channels,
135 return err; 81 rate,
136 82 soft_resample,
137 if ((err = ConfigureHwParams(handle, hw_params, format, access, channels, 83 latency);
138 rate, soft_resample, latency)) >= 0) {
139 err = snd_pcm_hw_params(handle, hw_params);
140 }
141
142 snd_pcm_hw_params_free(hw_params);
143 return err;
144 } 84 }
145 85
146 int AlsaWrapper::PcmGetParams(snd_pcm_t* handle, snd_pcm_uframes_t* buffer_size, 86 int AlsaWrapper::PcmGetParams(snd_pcm_t* handle, snd_pcm_uframes_t* buffer_size,
147 snd_pcm_uframes_t* period_size) { 87 snd_pcm_uframes_t* period_size) {
148 return snd_pcm_get_params(handle, buffer_size, period_size); 88 return snd_pcm_get_params(handle, buffer_size, period_size);
149 } 89 }
150 90
151 snd_pcm_sframes_t AlsaWrapper::PcmAvailUpdate(snd_pcm_t* handle) { 91 snd_pcm_sframes_t AlsaWrapper::PcmAvailUpdate(snd_pcm_t* handle) {
152 return snd_pcm_avail_update(handle); 92 return snd_pcm_avail_update(handle);
153 } 93 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 int AlsaWrapper::MixerSelemHasCaptureVolume(snd_mixer_elem_t* elem) { 163 int AlsaWrapper::MixerSelemHasCaptureVolume(snd_mixer_elem_t* elem) {
224 return snd_mixer_selem_has_capture_volume(elem); 164 return snd_mixer_selem_has_capture_volume(elem);
225 } 165 }
226 166
227 int AlsaWrapper::MixerSelemGetCaptureVolumeRange(snd_mixer_elem_t* elem, 167 int AlsaWrapper::MixerSelemGetCaptureVolumeRange(snd_mixer_elem_t* elem,
228 long* min, long* max) { 168 long* min, long* max) {
229 return snd_mixer_selem_get_capture_volume_range(elem, min, max); 169 return snd_mixer_selem_get_capture_volume_range(elem, min, max);
230 } 170 }
231 171
232 } // namespace media 172 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698