Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

[audio] Added getSupportedStreams() and UnsupportedAudioStreamException #3764

Merged
merged 5 commits into from Jun 30, 2017
Merged

[audio] Added getSupportedStreams() and UnsupportedAudioStreamException #3764

merged 5 commits into from Jun 30, 2017

Conversation

cweitkamp
Copy link
Contributor

Closes #3566

Signed-off-by: Christoph Weitkamp github@christophweitkamp.de

@cweitkamp
Copy link
Contributor Author

CAUTION: This is a change breaking PR for bindings using an AudioSink. It itroduces a new abstract method getSupportedStreams().

I will post (or push) an example implementation later.

@sjsf
Copy link
Contributor

sjsf commented Jun 29, 2017

Could you please also adapt the voice bundle?

[ERROR] Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:1.0.0:compile (default-compile) on project org.eclipse.smarthome.core.voice: Compilation failure: Compilation failure:
[ERROR] /home/travis/build/eclipse/smarthome/bundles/core/org.eclipse.smarthome.core.voice/src/main/java/org/eclipse/smarthome/core/voice/internal/DialogProcessor.java:[190]
[ERROR] sink.process(audioStream);
[ERROR] ^^^^^^^^^^^^^^^^^^^^^^^^^
[ERROR] Unhandled exception type UnsupportedAudioStreamException
[ERROR] /home/travis/build/eclipse/smarthome/bundles/core/org.eclipse.smarthome.core.voice/src/main/java/org/eclipse/smarthome/core/voice/internal/VoiceManagerImpl.java:[169]
[ERROR] sink.process(audioStream);
[ERROR] ^^^^^^^^^^^^^^^^^^^^^^^^^
[ERROR] Unhandled exception type UnsupportedAudioStreamException
[ERROR] 2 problems (2 errors)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
@cweitkamp
Copy link
Contributor Author

@SJKA Done.

I also added potential examples for getSupportedFormats() and getSupportedStreams() to the unit test class AudioSinkFake.

@sjsf
Copy link
Contributor

sjsf commented Jun 29, 2017

Thanks!

Now, as you already predicted above, Travis has got another wish:

public class SonosAudioSink implements AudioSink {
[ERROR] ^^^^^^^^^^^^^^
[ERROR] The type SonosAudioSink must implement the inherited abstract method AudioSink.getSupportedStreams()
[ERROR] 1 problem (1 error)

@cweitkamp
Copy link
Contributor Author

@SJKA Done.

I applied those changes to binding.sonos, io. javasound and io.webaudio to prevent good boy Travis to fail again.

@sjsf
Copy link
Contributor

sjsf commented Jun 30, 2017

Thanks!
(btw, this time I made the build fail - will be fixed in a few minutes and I will trigger it again)

Copy link
Contributor

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

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

Is it by intention that the newly introduced method getSupportedStreams is actually not used anywhere? I thought the idea of it was to allow the framework to check it upfront, instead of having exceptions being thrown at runtime...

* Thrown when a requested {@link AudioStream} is not supported by an {@link AudioSource} or {@link AudioSink}
* implementation
*
* @author Christoph Weitkamp - Added UnsupportedAudioStreamException
Copy link
Contributor

Choose a reason for hiding this comment

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

Put "Initial contribution and API" here.

@@ -184,12 +186,17 @@ protected void say(String text) {
}
}
if (null == voice) {
throw new TTSException("Unable to find a suitable voice");
throw new TTSException("Unable to find a voice");
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you change this? It seems unrelated to this PR and the message is not correct anymore as the system probably was able to find a voice, but not one of the right locale.

@@ -139,20 +141,24 @@ public void say(String text, String voiceId, String sinkId) {
} else if (voiceId.contains(":")) {
// it is a fully qualified unique id
String[] segments = voiceId.split(":");
tts = ttsServices.get(segments[0]);
voice = getVoice(tts.getAvailableVoices(), segments[1]);
tts = getTTS(segments[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you change this? This potentially returns you the default tts instead of the one specified in segments[0], so it unnecessarily complicates things here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it for readability and to prevent NPE (in case of segment[0] contains a not suitable value). Have a look at https://github.com/eclipse/smarthome/pull/3764/files#diff-2bdbf6176fb6bd9b1af9a6cb230b6293R472. The getTTS(String) method returns exaclty the same like before (ttsServices.get(id)).

IOUtils.closeQuietly(audioStream);
throw new UnsupportedAudioStreamException(
"Sonos can only handle FixedLengthAudioStreams and URLAudioStreams.", audioStream.getClass());
// TODO: Instead of throwing an exception, we could ourselves try to wrap it into a
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this todo still relevant? If I understand @maggu2810 right, it should now be rather the framework, which decides to do the conversion to a FixedLengthAudioStream, in case it sees that the sink does not support anything else.

@@ -71,6 +75,11 @@ public void process(AudioStream audioStream) throws UnsupportedAudioFormatExcept
}

@Override
public Set<Class<? extends AudioStream>> getSupportedStreams() {
return Collections.emptySet();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why empty? It supports ALL streams!

@cweitkamp
Copy link
Contributor Author

Is it by intention that the newly introduced method getSupportedStreams is actually not used anywhere? I thought the idea of it was to allow the framework to check it upfront, instead of having exceptions being thrown at runtime...

@kaikreuzer thanks for review. No, of course not. My intention was to change it in a follow-up PR. I can do that in this PR if you preferr.

@kaikreuzer
Copy link
Contributor

Many thanks @cweitkamp! Ok, all fine for me to make use of this feature in an upcoming PR.

@kaikreuzer kaikreuzer merged commit 1bada87 into eclipse-archived:master Jun 30, 2017
@kaikreuzer
Copy link
Contributor

We need to remember that once the next ESH stable is pushed out, quite some bindings in openhab2-addons will break and need to be adapted.

@cweitkamp cweitkamp deleted the feature-3566-audio-stream-exception branch June 30, 2017 12:03
@lolodomo
Copy link
Contributor

lolodomo commented Jul 1, 2017

The timing looks not very good. Such a breaking API will prevent any update of OH2 bindings relying on it for any user running OH 2.1 during around 5 months. We have to pray that no urgent patch is needed for all impacted bindings.
What will happen for users using the online distribution ?

@kaikreuzer
Copy link
Contributor

We are talking about changes on unstable development branches, so there should be no need for praying or anything.

@lolodomo
Copy link
Contributor

lolodomo commented Jul 8, 2017

@cweitkamp: may we ask you to provide a fix for all broken OH2 bindings ?

@cweitkamp
Copy link
Contributor Author

@lolodomo Yes of course. I am working on it.

@cweitkamp
Copy link
Contributor Author

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants