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

Side by Side Diff: media/audio/alsa/alsa_util.cc

Issue 2883313004: Fix off-by-one in ALSA control name determination. (Closed)
Patch Set: Created 3 years, 7 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
« 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/alsa/alsa_util.h" 5 #include "media/audio/alsa/alsa_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "media/audio/alsa/alsa_wrapper.h" 10 #include "media/audio/alsa/alsa_wrapper.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 const char kMixerPrefix[] = "hw"; 47 const char kMixerPrefix[] = "hw";
48 std::string control_name; 48 std::string control_name;
49 size_t pos1 = device_name.find(':'); 49 size_t pos1 = device_name.find(':');
50 if (pos1 == std::string::npos) { 50 if (pos1 == std::string::npos) {
51 control_name = device_name; 51 control_name = device_name;
52 } else { 52 } else {
53 // Examples: 53 // Examples:
54 // deviceName: "front:CARD=Intel,DEV=0", controlName: "hw:CARD=Intel". 54 // deviceName: "front:CARD=Intel,DEV=0", controlName: "hw:CARD=Intel".
55 // deviceName: "default:CARD=Intel", controlName: "CARD=Intel". 55 // deviceName: "default:CARD=Intel", controlName: "CARD=Intel".
56 size_t pos2 = device_name.find(','); 56 size_t pos2 = device_name.find(',');
57 control_name = (pos2 == std::string::npos) ? 57 control_name = (pos2 == std::string::npos)
58 device_name.substr(pos1) : 58 ? device_name.substr(pos1 + 1)
59 kMixerPrefix + device_name.substr(pos1, pos2 - pos1); 59 : kMixerPrefix + device_name.substr(pos1, pos2 - pos1);
60 } 60 }
61 61
62 return control_name; 62 return control_name;
63 } 63 }
64 64
65 snd_pcm_format_t BitsToFormat(int bits_per_sample) { 65 snd_pcm_format_t BitsToFormat(int bits_per_sample) {
66 switch (bits_per_sample) { 66 switch (bits_per_sample) {
67 case 8: 67 case 8:
68 return SND_PCM_FORMAT_U8; 68 return SND_PCM_FORMAT_U8;
69 69
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 else if (strcmp(elem_name, kMicElemName) == 0) 191 else if (strcmp(elem_name, kMicElemName) == 0)
192 mic_elem = elem; 192 mic_elem = elem;
193 } 193 }
194 } 194 }
195 195
196 // Did not find any Capture handle, use the Mic handle. 196 // Did not find any Capture handle, use the Mic handle.
197 return mic_elem; 197 return mic_elem;
198 } 198 }
199 199
200 } // namespace alsa_util 200 } // namespace alsa_util
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