Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulseaudio parseVolume regex fixes #2297

Merged
merged 1 commit into from
Jun 1, 2017
Merged

Pulseaudio parseVolume regex fixes #2297

merged 1 commit into from
Jun 1, 2017

Conversation

jimduchek
Copy link

Specifically, this patch was created to add '.' to the 'dB' part of the regex. However, I noticed two other problems and fixed those as well -

1> monitor_of points to the sink ID that the monitor is... monitoring. For some reason parseVolume() was being called on this, probably a copy-paste error.
2> parseVolume only supported stereo sinks. While this is a common use-case, it's hardly the only one. Now supports 'n' channels. Combined with an update to a newer version of PulseAudio, this ought to fix the original bug reporters issue.

@mention-bot
Copy link

@jimduchek, thanks for your PR! By analyzing the history of the files in this pull request, we identified @peuter, @kaikreuzer and @martinvw to be potential reviewers.

if (matcher.find()) {
return Math.round((Integer.valueOf(matcher.group(3)) + Integer.valueOf(matcher.group(7))) / 2);
int volumeTotal = 0, nChannels = 0;
for (String channel : vol.split(",")) {
Copy link
Member

@peuter peuter May 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work mith my setup, because the volume string here is:
front-left: 30419 / 46% / -20,00 dB, front-right: 30419 / 46% / -20,00 dB
so splitting by "," is not a good idea.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bah. The ',' in the dB for y'all was precisely why I made this patch in the first place, and then I go and straight up forget about it! :) I will commit a change to ", " instead.

@@ -35,8 +35,7 @@
private static final Logger logger = LoggerFactory.getLogger(Parser.class);

private static final Pattern pattern = Pattern.compile("^\\s+([a-z\\s._]+)[:=]\\s*<?\"?([^>\"]+)\"?>?$");
private static final Pattern volumePattern = Pattern.compile(
"^(0|front-left):( *[0-9]+ \\/)? *([0-9]+)% *\\/? *([0-9\\-, dB]+)?(1|front-right):( *[0-9]+ \\/)? *([0-9]+)% *\\/? *([0-9\\-, dB]+)?$");
private static final Pattern volumePattern = Pattern.compile("^([\\w\\-]+):( *[\\d]+ \\/)? *([\\d]+)% *\\/? *([\\d\\-., dB]+)?$");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the pulseaudio strings that are parsed by this binding are rather diverse regarding spaces, newlines etc. I would prefer a minimalistic change to the regex by just adding \. which was the initial problem that should be solved here, right. It's just a matter of the lessons I have learned during the past years with different pulseaudio versions, that make me a little bit careful when it comes to changes to the regular expressions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. This change should actually be more permissive than just adding . would be though, and my specific use case does involve a 7.1 surround card (although I can live with support for just stereo channels...). Is there any specific reason why the cli interface was chosen, instead of the native tcp interface? It seems to me the cli interface is almost certainly going to get easily broken by upstream.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLI vs. TCP:
Well its just easier to use. At the time I wrote the first version of this binding the CLI interface was much easier to use and did everything I needed (and that doesn't seem to have changed yet). I still don't know or understand if and how I can achieve the same things with the native interface.

I always had the little hope that some time someone with more experiance in pulseaudio, would re-write this binding to "do it right" but that never happened. So if you are the one, feel free to start ;-)

Regex change:
Ok you have convinced me, I havn't thought about the multichannel stuff, so your solution should work in more environments that the old one.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to do a bit more research on how the native interface works -- it passes structs directly, as far as I can tell. I would hardly call myself any sort of pulseaudio expert, and I'm not sure I have the time on my hands for a rewrite, but I do get a little nervous about parsing/using an interface intended for human use when a 'machine' one is available.

Copy link
Member

@peuter peuter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -265,7 +264,7 @@
source.setVolume(Integer.valueOf(parseVolume(properties.get("volume"))));
}
if (properties.containsKey("monitor_of")) {
source.setMonitorOf(client.getSink(Integer.valueOf(parseVolume(properties.get("monitor_of")))));
source.setMonitorOf(client.getSink(Integer.valueOf(properties.get("monitor_of"))));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But is it expected that the method is not called from here anymore?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completely intended change, i see now

Matcher matcher = volumePattern.matcher(vol);
if (matcher.find()) {
return Math.round((Integer.valueOf(matcher.group(3)) + Integer.valueOf(matcher.group(7))) / 2);
int volumeTotal = 0, nChannels = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you given them a seperate line, one statement one line :-)

@martinvw
Copy link
Member

Sorry one final request. Can you squash your commits and change commit message to include a Signed-off-by (to certify that you wrote it or otherwise have the right to pass it on as an open-source), see http://docs.openhab.org/developers/contributing/contributing.html#sign-your-work

For squashing / rebasing see:
http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html

@martinvw martinvw requested a review from kaikreuzer May 29, 2017 16:40
Adds support to fetch volume for 1+ channels instead of assuming stereo
Fixes bug attempting to use parseVolume to parse monitor_by
Signed-off-by: Jim Duchek <jim.duchek@gmail.com> (github: jimduchek)
@jimduchek
Copy link
Author

Ah done on the rebasing and adding the signed-off-by -- I am not sure where to put the DCO, though. Somewhere here in github, I guess?

@martinvw
Copy link
Member

martinvw commented May 29, 2017

By signing off you agree on the global dco, nothing you have to put or upload anywhere.

@kaikreuzer kaikreuzer merged commit 000d4f3 into openhab:master Jun 1, 2017
falkena pushed a commit to falkena/openhab-addons that referenced this pull request Jun 2, 2017
Adds support to fetch volume for 1+ channels instead of assuming stereo
Fixes bug attempting to use parseVolume to parse monitor_by

Signed-off-by: Jim Duchek <jim.duchek@gmail.com> (github: jimduchek)
holmes added a commit to holmes/openhab2-addons that referenced this pull request Jun 8, 2017
* master: (23 commits)
  Fixes for setting brightness and colour temperature for V3 white bulbs. (openhab#2338)
  [RFXCOM] Add new protocols (openhab#2331)
  [RFXCOM] Add support for UV sensors (openhab#2330)
  Removed the unsupported MACROMAN encoding (openhab#2332)
  Create Issue and PR template files (openhab#2285)
  Corrected the discovery of new devices (openhab#2326)
  Fixes ./, decimal point issue in volume (openhab#2297)
  Fix table layout feed binding (openhab#2318)
  When trying to send a message while the bridge was not connected an NPE occurred (openhab#2299)
  D-Link Smart Home device binding (openhab#2035)
  Updated README.md, Changed definition of 'battery_low' channel to sytemwide channel type 'system.low-battery' (openhab#2262)
  Tesla : Move Event Stream to a separate Thread to speed up processing + discard events  that are too old to be relevant + clean-up constants (openhab#2307)
  Fixed NPE if temperature, powermeter or switch model is null (openhab#1887)
  [DSCAlarm] Various Fixes and Enhancements (openhab#2313)
  [globalcache] Implement bi-directional support for serial devices (openhab#2311)
  Keba : Fix kecontact.xml in ESH-INF (openhab#2314)
  Keba : Fixes openhab#2237 openhab#2236 openhab#2234 openhab#2038 (openhab#2270)
  Fixed typo in configuration of channel-type-id (openhab#2310)
  Update native AllJoyn library for linux x86 and x64 (openhab#2308)
  [kodi] Added channels for opening PVR TV or Radio streams (openhab#2084)
  ...
@kaikreuzer kaikreuzer modified the milestone: 2.1 Jun 23, 2017
qvistgaard pushed a commit to qvistgaard/openhab2-addons that referenced this pull request Jun 30, 2017
Adds support to fetch volume for 1+ channels instead of assuming stereo
Fixes bug attempting to use parseVolume to parse monitor_by

Signed-off-by: Jim Duchek <jim.duchek@gmail.com> (github: jimduchek)
reyem pushed a commit to reyem/openhab2-addons that referenced this pull request Jul 1, 2017
Adds support to fetch volume for 1+ channels instead of assuming stereo
Fixes bug attempting to use parseVolume to parse monitor_by

Signed-off-by: Jim Duchek <jim.duchek@gmail.com> (github: jimduchek)
Markinus pushed a commit to Markinus/openhab2-addons that referenced this pull request Jul 2, 2017
Adds support to fetch volume for 1+ channels instead of assuming stereo
Fixes bug attempting to use parseVolume to parse monitor_by

Signed-off-by: Jim Duchek <jim.duchek@gmail.com> (github: jimduchek)
ppieczul pushed a commit to ppieczul/openhab2-addons that referenced this pull request Jul 2, 2017
Adds support to fetch volume for 1+ channels instead of assuming stereo
Fixes bug attempting to use parseVolume to parse monitor_by

Signed-off-by: Jim Duchek <jim.duchek@gmail.com> (github: jimduchek)
aogorek pushed a commit to aogorek/openhab2-addons that referenced this pull request Jul 5, 2017
Adds support to fetch volume for 1+ channels instead of assuming stereo
Fixes bug attempting to use parseVolume to parse monitor_by

Signed-off-by: Jim Duchek <jim.duchek@gmail.com> (github: jimduchek)
Markinus pushed a commit to Markinus/openhab2-addons that referenced this pull request Sep 8, 2017
Adds support to fetch volume for 1+ channels instead of assuming stereo
Fixes bug attempting to use parseVolume to parse monitor_by

Signed-off-by: Jim Duchek <jim.duchek@gmail.com> (github: jimduchek)
Flole998 pushed a commit to Flole998/openhab-addons that referenced this pull request Dec 30, 2021
…enhab#2297)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants