Merge ~kissiel/plainbox-provider-snappy:set-volume-in-alsa-test into plainbox-provider-snappy:master

Proposed by Maciej Kisielewski
Status: Merged
Approved by: Chris Wayne
Approved revision: 8ce5f92c38edb6916ac89a8b074a7d6050fc9742
Merged at revision: 030106d2b0984ed7792dca2a042e00b80c765ad9
Proposed branch: ~kissiel/plainbox-provider-snappy:set-volume-in-alsa-test
Merge into: plainbox-provider-snappy:master
Diff against target: 69 lines (+51/-0)
1 file modified
src/alsa_test.cpp (+51/-0)
Reviewer Review Type Date Requested Status
Chris Wayne (community) Needs Fixing
Sylvain Pineau (community) Approve
Review via email: mp+369412@code.launchpad.net

Description of the change

alsa_test: set playback and capture volumes when starting the test

This should improve the fails on some device that default to muted or low gain capture.

If any of the mixer shenanigans fails the test plows on, so this should be "backwards compatible".

To post a comment you must log in.
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

LGTM

review: Approve
Revision history for this message
Chris Wayne (cwayne) wrote :

Doesnt fix the issue on Dawson-j

review: Needs Fixing
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

> Doesnt fix the issue on Dawson-j

This patch is a general improvement, that did not fix the problem on that particular device, while it fixes a problem where the mixer state would prevent the testing.

Also from what I can tell it doesn't break anything, so I would like to land it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/alsa_test.cpp b/src/alsa_test.cpp
index e536f82..b5f4bd6 100644
--- a/src/alsa_test.cpp
+++ b/src/alsa_test.cpp
@@ -266,6 +266,46 @@ template<>
266snd_pcm_format_t Alsa::Pcm<uint8_t>::get_alsa_format() {266snd_pcm_format_t Alsa::Pcm<uint8_t>::get_alsa_format() {
267 return SND_PCM_FORMAT_U8;267 return SND_PCM_FORMAT_U8;
268}268}
269
270struct Mixer {
271 Mixer(string card_name, string mixer_name) {
272 int res;
273 res = snd_mixer_open(&mixer_handle, 0);
274 if (res < 0) throw AlsaError("Failed to open an empty Mixer");
275 res = snd_mixer_attach(mixer_handle, card_name.c_str());
276 if (res < 0) throw AlsaError("Failed to attach HCTL to a Mixer");
277 res = snd_mixer_selem_register(mixer_handle, NULL, NULL);
278 if (res < 0) throw AlsaError("Failed to register a Mixer");
279 res = snd_mixer_load(mixer_handle);
280 if (res < 0) throw AlsaError("Failed to load a Mixer");
281 snd_mixer_selem_id_alloca(&sid);
282 snd_mixer_selem_id_set_index(sid, 0);
283 snd_mixer_selem_id_set_name(sid, mixer_name.c_str());
284 elem = snd_mixer_find_selem(mixer_handle, sid);
285 if (!elem) throw AlsaError(mixer_name + " mixer not found.");
286 }
287 ~Mixer() {
288 snd_mixer_close(mixer_handle);
289 }
290 void set_all_playback_volume(float volume) {
291 long min, max;
292 snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
293 int new_vol = int(float(max) * volume);
294 snd_mixer_selem_set_playback_switch_all(elem, 1);
295 snd_mixer_selem_set_playback_volume_all(elem, new_vol);
296 }
297 void set_all_capture_volume(float volume) {
298 long min, max;
299 snd_mixer_selem_get_capture_volume_range(elem, &min, &max);
300 int new_vol = int(float(max) * volume);
301 snd_mixer_selem_set_capture_switch_all(elem, 1);
302 snd_mixer_selem_set_capture_volume_all(elem, new_vol);
303 }
304private:
305 snd_mixer_t *mixer_handle;
306 snd_mixer_selem_id_t *sid;
307 snd_mixer_elem_t* elem;
308};
269}; //namespace Alsa309}; //namespace Alsa
270310
271template<class storage_type>311template<class storage_type>
@@ -359,6 +399,17 @@ int main(int argc, char *argv[]) {
359 if (std::find(args.begin(), args.end(), std::string("-v")) != args.end()) {399 if (std::find(args.begin(), args.end(), std::string("-v")) != args.end()) {
360 logger.set_level(Logger::Level::info);400 logger.set_level(Logger::Level::info);
361 }401 }
402 try {
403 auto playback_mixer = Alsa::Mixer("default", "Master");
404 auto capture_mixer = Alsa::Mixer("default", "Capture");
405 playback_mixer.set_all_playback_volume(0.75f);
406 capture_mixer.set_all_capture_volume(0.75f);
407 } catch(Alsa::AlsaError err) {
408 logger.normal() << "Failed to change volume: " << err.what() << std::endl;
409 // not being able to change the volume is not critical to the test
410 // and for some devices "Master" and "Caputre" mixers may not exist
411 // so let's just print warning if that's the case
412 }
362 auto format = std::string("int16_48000");413 auto format = std::string("int16_48000");
363 auto format_it = std::find(args.begin(), args.end(), std::string("--format"));414 auto format_it = std::find(args.begin(), args.end(), std::string("--format"));
364 if (format_it != args.end()) { // not doing && because of sequence points415 if (format_it != args.end()) { // not doing && because of sequence points

Subscribers

People subscribed via source and target branches