Fixes for USB sound cards

- Ability to change device used for Volume control (PCM/Speaker/Master) only on Pi.
- Ability to change Audio device used for OMX player (local/hdmi/both/ALSA:HW:0,0/ALSA:HW:1,0)
This commit is contained in:
hex007 2017-06-02 08:58:44 -07:00
parent 0772c1f84f
commit 2d38605a08
4 changed files with 58 additions and 2 deletions

View file

@ -1,4 +1,5 @@
#include "VolumeControl.h"
#include "Settings.h"
#include "Log.h"
@ -73,6 +74,10 @@ void VolumeControl::init()
//try to open mixer device
if (mixerHandle == nullptr)
{
#ifdef _RPI_
mixerName = Settings::getInstance()->getString("AudioDevice").c_str();
#endif
snd_mixer_selem_id_alloca(&mixerSelemId);
//sets simple-mixer index and name
snd_mixer_selem_id_set_index(mixerSelemId, mixerIndex);

View file

@ -69,6 +69,23 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
[this] {
auto s = new GuiSettings(mWindow, "SOUND SETTINGS");
#ifdef _RPI_
// volume control device
auto vol_dev = std::make_shared< OptionListComponent<std::string> >(mWindow, "AUDIO DEVICE", false);
std::vector<std::string> transitions;
transitions.push_back("PCM");
transitions.push_back("Speaker");
transitions.push_back("Master");
for(auto it = transitions.begin(); it != transitions.end(); it++)
vol_dev->add(*it, *it, Settings::getInstance()->getString("AudioDevice") == *it);
s->addWithLabel("AUDIO DEVICE", vol_dev);
s->addSaveFunc([vol_dev] {
Settings::getInstance()->setString("AudioDevice", vol_dev->getSelected());
VolumeControl::getInstance()->deinit();
VolumeControl::getInstance()->init();
});
#endif
// volume
auto volume = std::make_shared<SliderComponent>(mWindow, 0.f, 100.f, 1.f, "%");
volume->setValue((float)VolumeControl::getInstance()->getVolume());
@ -204,6 +221,23 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
if(needReload)
ViewController::get()->reloadAll();
});
// OMX player Audio Device
auto omx_audio_dev = std::make_shared< OptionListComponent<std::string> >(mWindow, "OMX PLAYER AUDIO DEVICE", false);
std::vector<std::string> devices;
devices.push_back("local");
devices.push_back("hdmi");
devices.push_back("both");
// USB audio
devices.push_back("alsa:hw:0,0");
devices.push_back("alsa:hw:1,0");
for (auto it = devices.begin(); it != devices.end(); it++)
omx_audio_dev->add(*it, *it, Settings::getInstance()->getString("OMXAudioDev") == *it);
s->addWithLabel("OMX PLAYER AUDIO DEVICE", omx_audio_dev);
s->addSaveFunc([omx_audio_dev] {
if (Settings::getInstance()->getString("OMXAudioDev") != omx_audio_dev->getSelected())
Settings::getInstance()->setString("OMXAudioDev", omx_audio_dev->getSelected());
});
#endif
auto video_audio = std::make_shared<SwitchComponent>(mWindow);
video_audio->setState(Settings::getInstance()->getBool("VideoAudio"));

View file

@ -81,6 +81,15 @@ void Settings::setDefaults()
// we don't get a warning if we encounter it on a different platform
mBoolMap["VideoOmxPlayer"] = false;
mBoolMap["VideoAudio"] = true;
// Audio out device for Video playback using OMX player.
mStringMap["OMXAudioDev"] = "both";
// Audio out device for volume control
#ifdef _RPI_
mStringMap["AudioDevice"] = "PCM";
#else
mStringMap["AudioDevice"] = "Master";
#endif
}

View file

@ -1,5 +1,6 @@
#ifdef _RPI_
#include "components/VideoPlayerComponent.h"
#include "AudioManager.h"
#include "Renderer.h"
#include "ThemeData.h"
#include "Settings.h"
@ -57,6 +58,9 @@ void VideoPlayerComponent::startVideo()
// Set the video that we are going to be playing so we don't attempt to restart it
mPlayingVideoPath = mVideoPath;
// Disable AudioManager so video can play
AudioManager::getInstance()->deinit();
// Start the player process
pid_t pid = fork();
if (pid == -1)
@ -84,7 +88,7 @@ void VideoPlayerComponent::startVideo()
// We need to specify the layer of 10000 or above to ensure the video is displayed on top
// of our SDL display
const char* argv[] = { "", "--layer", "10010", "--loop", "--no-osd", "--aspect-mode", "letterbox", "--vol", "0", "--win", buf, "-b", "", "", "", "", NULL };
const char* argv[] = { "", "--layer", "10010", "--loop", "--no-osd", "--aspect-mode", "letterbox", "--vol", "0", "-o", "both","--win", buf, "-b", "", "", "", "", NULL };
// check if we want to mute the audio
if (!Settings::getInstance()->getBool("VideoAudio"))
@ -98,7 +102,9 @@ void VideoPlayerComponent::startVideo()
argv[6] = "stretch";
}
argv[11] = mPlayingVideoPath.c_str();
argv[10] = Settings::getInstance()->getString("OMXAudioDev").c_str();
argv[13] = mPlayingVideoPath.c_str();
const char* env[] = { "LD_LIBRARY_PATH=/opt/vc/libs:/usr/lib/omxplayer", NULL };
@ -134,6 +140,8 @@ void VideoPlayerComponent::stopVideo()
int status;
kill(mPlayerPid, SIGKILL);
waitpid(mPlayerPid, &status, WNOHANG);
// Restart AudioManager
AudioManager::getInstance()->init();
mPlayerPid = -1;
}
}