diff --git a/bundles/io/org.eclipse.smarthome.io.audio/.classpath b/bundles/io/org.eclipse.smarthome.io.audio/.classpath new file mode 100644 index 00000000000..a95e0906ca0 --- /dev/null +++ b/bundles/io/org.eclipse.smarthome.io.audio/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/bundles/io/org.eclipse.smarthome.io.audio/.project b/bundles/io/org.eclipse.smarthome.io.audio/.project new file mode 100644 index 00000000000..dd152151c00 --- /dev/null +++ b/bundles/io/org.eclipse.smarthome.io.audio/.project @@ -0,0 +1,33 @@ + + + org.eclipse.smarthome.io.audio + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.ds.core.builder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/bundles/io/org.eclipse.smarthome.io.audio/META-INF/MANIFEST.MF b/bundles/io/org.eclipse.smarthome.io.audio/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..a9a78a48b8d --- /dev/null +++ b/bundles/io/org.eclipse.smarthome.io.audio/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Eclipse SmartHome Audio I/O Bundle +Bundle-SymbolicName: org.eclipse.smarthome.io.audio +Bundle-Vendor: Eclipse.org/SmartHome +Bundle-Version: 0.8.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Bundle-ClassPath: . +Import-Package: org.slf4j +Service-Component: OSGI-INF/*.xml, +Export-Package: org.eclipse.smarthome.io.audio +Bundle-ActivationPolicy: lazy + diff --git a/bundles/io/org.eclipse.smarthome.io.audio/build.properties b/bundles/io/org.eclipse.smarthome.io.audio/build.properties new file mode 100644 index 00000000000..af1b5eea591 --- /dev/null +++ b/bundles/io/org.eclipse.smarthome.io.audio/build.properties @@ -0,0 +1,6 @@ +output.. = target/classes +bin.includes = META-INF/,\ + .,\ + OSGI-INF/,\ + ESH-INF/ +source.. = src/main/java/ \ No newline at end of file diff --git a/bundles/io/org.eclipse.smarthome.io.audio/pom.xml b/bundles/io/org.eclipse.smarthome.io.audio/pom.xml new file mode 100644 index 00000000000..c1c366c6f53 --- /dev/null +++ b/bundles/io/org.eclipse.smarthome.io.audio/pom.xml @@ -0,0 +1,23 @@ + + + + + org.eclipse.smarthome.bundles + io + 0.8.0-SNAPSHOT + + + + org.eclipse.smarthome.io.audio + org.eclipse.smarthome.io.audio + + + 4.0.0 + org.eclipse.smarthome.io + org.eclipse.smarthome.io.audio + + Eclipse SmartHome Audio I/O + + eclipse-plugin + + diff --git a/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/AudioCodec.java b/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/AudioCodec.java new file mode 100644 index 00000000000..8c432f4f7c9 --- /dev/null +++ b/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/AudioCodec.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.smarthome.io.audio; + +/** + * A collection of constants for commonly used audio codecs + * + * @author Harald Kuhn - Initial API + * @author Kelly Davis - Modified to match discussion in #584 + */ +public class AudioCodec { + /** + * PCM Signed + * + * @see PCM Types + */ + public static final String PCM_SIGNED = "PCM_SIGNED"; + + /** + * PCM Unsigned + * + * @see PCM Types + */ + public static final String PCM_UNSIGNED = "PCM_UNSIGNED"; + + /** + * MP3 Codec + * + * @see MP3 Codec + */ + public static final String MP3 = "MP3"; + + /** + * Vorbis Codec + * + * @see Vorbis + */ + public static final String VORBIS = "VORBIS"; +} diff --git a/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/AudioContainer.java b/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/AudioContainer.java new file mode 100644 index 00000000000..a631e5ad97b --- /dev/null +++ b/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/AudioContainer.java @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.smarthome.io.audio; + +/** + * A collection of constants for container formats + * + * @author Harald Kuhn - Initial API + * @author Kelly Davis - Modified to match discussion in #584 + */ +public class AudioContainer { + /** + * {@link AudioCodec} encoded data without any container header or footer, + * e.g. MP3 is a non-container format + */ + public static final String NONE = "NONE"; + + /** + * Microsofts wave container format + * + * @see WAV Format + * @see Supported codecs + * @see RIFF container format + */ + public static final String WAVE = "WAVE"; + + + /** + * OGG container format + * + * @see OGG + */ + public static final String OGG = "OGG"; +} diff --git a/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/AudioException.java b/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/AudioException.java new file mode 100644 index 00000000000..ee47e6e97e8 --- /dev/null +++ b/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/AudioException.java @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.smarthome.io.audio; + +/** + * General purpose audio exception + * + * @author Harald Kuhn - Initial API + * @author Kelly Davis - Modified to match discussion in #584 + */ +public class AudioException extends Exception { + + private static final long serialVersionUID = 1L; + + /** + * Constructs a new exception with null as its detail message. + */ + public AudioException() { + super(); + } + + /** + * Constructs a new exception with the specified detail message and cause. + * + * @param message Detail message + * @param cause The cause + */ + public AudioException(String message, Throwable cause) { + super(message, cause); + } + + /** + * Constructs a new exception with the specified detail message. + * + * @param message Detail message + */ + public AudioException(String message) { + super(message); + } + + /** + * Constructs a new exception with the specified cause. + * + * @param cause The cause + */ + public AudioException(Throwable cause) { + super(cause); + } +} diff --git a/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/AudioFormat.java b/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/AudioFormat.java new file mode 100644 index 00000000000..a1bb060e85b --- /dev/null +++ b/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/AudioFormat.java @@ -0,0 +1,195 @@ +/** + * Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.smarthome.io.audio; + +/** + * An audio format definition + * + * @author Harald Kuhn - Initial API + * @author Kelly Davis - Modified to match discussion in #584 + */ +public class AudioFormat { + + /** + * Codec + */ + private final String codec; + + /** + * Container + */ + private final String container; + + /** + * Big endian or little endian + */ + private final Boolean bigEndian; + + /** + * Bit depth + * + * @see Bit Depth + */ + private final Integer bitDepth; + + /** + * Bit rate + * + * @see Bit Rate + */ + private final Integer bitRate; + + /** + * Sample frequency + */ + private final Long frequency; + + /** + * Constructs an instance with the specified peoperties. + * + * Note that any properties that are null indicate that + * the corresponding AudioFormat allows any value for + * the property. + * + * Concretely this implies that if, for example, one + * passed null for the value of frequency, this would + * mean the created AudioFormat allowed for any valid + * frequency. + * + * @param container The container for the audio + * @param codec The audio codec + * @param bigEndian If the audo data is big endian + * @param bitDepth The bit depth of the audo data + * @param bitRate The bit rate of the audio + * @param frequency The frequency at which the audio was sampled + */ + public AudioFormat(String container, String codec, Boolean bigEndian, + Integer bitDepth, Integer bitRate, Long frequency) { + super(); + this.container = container; + this.codec = codec; + this.bigEndian = bigEndian; + this.bitDepth = bitDepth; + this.bitRate = bitRate; + this.frequency = frequency; + } + + /** + * Gets codec + * + * @return The codec + */ + public String getCodec() { + return codec; + } + + /** + * Gets container + * + * @return The container + */ + public String getContainer() { + return container; + } + + /** + * Is big endian? + * + * @return If format is big endian + */ + public Boolean isBigEndian() { + return bigEndian; + } + + /** + * Gets bit depth + * + * @see Bit Depth + * @return Bit depth + */ + public Integer getBitDepth() { + return bitDepth; + } + + /** + * Gets bit rate + * + * @see Bit Rate + * @return Bit rate + */ + public Integer getBitRate() { + return bitRate; + } + + /** + * Gets frequency + * + * @return The frequency + */ + public Long getFrequency() { + return frequency; + } + + /** + * Determines if the passed AudioFormat is compatable with this AudioFormat. + * + * This AudioFormat is compatible with the passed AudioFormat if both have + * the same value for all non-null members of this instance. + */ + boolean isCompatible(AudioFormat audioFormat) { + if(audioFormat == null) { + return false; + } + if ((null != getContainer()) && (getContainer() != audioFormat.getContainer())) { + return false; + } + if ((null != getCodec()) && (getCodec() != audioFormat.getCodec())) { + return false; + } + if ((null != isBigEndian()) && (isBigEndian() != audioFormat.isBigEndian())) { + return false; + } + if ((null != getBitDepth()) && (getBitDepth() != audioFormat.getBitDepth())) { + return false; + } + if ((null != getBitRate()) && (getBitRate() != audioFormat.getBitRate())) { + return false; + } + if ((null != getFrequency()) && (getFrequency() != audioFormat.getFrequency())) { + return false; + } + return true; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof AudioFormat) { + AudioFormat format = (AudioFormat) obj; + if (format.getCodec() != getCodec()) { + return false; + } + if (format.getContainer() != getContainer()) { + return false; + } + if (format.isBigEndian() != isBigEndian()) { + return false; + } + if (format.getBitDepth() != getBitDepth()) { + return false; + } + if (format.getBitRate() != getBitRate()) { + return false; + } + if (format.getFrequency() != getFrequency()) { + return false; + } + return true; + } + return super.equals(obj); + } +} diff --git a/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/AudioSink.java b/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/AudioSink.java new file mode 100644 index 00000000000..5ead42bf020 --- /dev/null +++ b/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/AudioSink.java @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.smarthome.io.audio; + +import java.util.Set; + +/** + * Definition of an audio output like headphones, a speaker or for writing to + * a file / clip. Also used by TTS service. + * + * @author Harald Kuhn - Initial API + * @author Kelly Davis - Modified to match discussion in #584 + */ +public interface AudioSink { + /** + * Processes the passed {@link AudioSource} + * + * If the passed {@link AudioSource} has a {@link AudioFormat} not supported by this instance, + * an {@link UnsupportedAudioFormatException} is thrown. + * + * @throws UnsupportedAudioFormatException If audioSource format is not supported + */ + void process(AudioSource audioSource) throws UnsupportedAudioFormatException; + + /** + * Gets a set containing all supported audio formats + * + * @return A Set containing all supported audio formats + */ + public Set getSupportedFormats(); +} diff --git a/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/AudioSource.java b/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/AudioSource.java new file mode 100644 index 00000000000..231066046a4 --- /dev/null +++ b/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/AudioSource.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.smarthome.io.audio; + +import java.io.InputStream; + +/** + * Wrapper for a source of audio data + * + * @author Harald Kuhn - Initial API + * @author Kelly Davis - Modified to match discussion in #584 + */ +public interface AudioSource { + /** + * Gets the supported audio format + * + * @return The supported audio format + */ + public AudioFormat getFormat(); + + /** + * Gets InputStream to reading audio data in supported audio format + * + * @return InputStream for reading audio data + * @throws AudioException If problem occurs obtaining InputStream + */ + public InputStream getInputStream() throws AudioException; + +} diff --git a/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/UnsupportedAudioFormatException.java b/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/UnsupportedAudioFormatException.java new file mode 100644 index 00000000000..9c047fefc22 --- /dev/null +++ b/bundles/io/org.eclipse.smarthome.io.audio/src/main/java/org/eclipse/smarthome/io/audio/UnsupportedAudioFormatException.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.smarthome.io.audio; + +/** + * Thrown when a requested format is not supported by an {@link AudioSource} + * or {@link AudioSink} implementation + * + * @author Harald Kuhn - Initial API + * @author Kelly Davis - Modified to match discussion in #584 + */ +public class UnsupportedAudioFormatException extends AudioException { + + private static final long serialVersionUID = 1L; + + /** + * Unsupported {@link AudioFormat} + */ + private AudioFormat unsupportedFormat; + + /** + * Constructs a new exception with the specified detail message, unsupported format, and cause. + * + * @param message Detail message + * @param unsupportedFormat Unsupported format + * @param cause The cause + */ + public UnsupportedAudioFormatException(String message, AudioFormat unsupportedFormat, Throwable cause) { + super(message, cause); + this.unsupportedFormat = unsupportedFormat; + } + + /** + * Constructs a new exception with the specified detail message and unsupported format. + * + * @param message Detail message + * @param unsupportedFormat Unsupported format + */ + public UnsupportedAudioFormatException(String message, AudioFormat unsupportedFormat) { + this(message, unsupportedFormat, null); + } + + /** + * Gets the unsupported format + * + * @return The unsupported format + */ + public AudioFormat getUnsupportedFormat() { + return unsupportedFormat; + } +} diff --git a/bundles/io/pom.xml b/bundles/io/pom.xml index 3039484a7d0..1b690f7ce43 100644 --- a/bundles/io/pom.xml +++ b/bundles/io/pom.xml @@ -16,6 +16,7 @@ pom + org.eclipse.smarthome.io.audio org.eclipse.smarthome.io.console org.eclipse.smarthome.io.console.eclipse org.eclipse.smarthome.io.console.rfc147 @@ -37,4 +38,4 @@ org.eclipse.smarthome.io.voice - + \ No newline at end of file diff --git a/features/karaf/src/main/feature/feature.xml b/features/karaf/src/main/feature/feature.xml index 266b6638f76..f6da014411c 100644 --- a/features/karaf/src/main/feature/feature.xml +++ b/features/karaf/src/main/feature/feature.xml @@ -27,6 +27,7 @@ mvn:org.eclipse.smarthome.io/org.eclipse.smarthome.io.console/${project.version} mvn:org.eclipse.smarthome.io/org.eclipse.smarthome.io.monitor/${project.version} mvn:org.eclipse.smarthome.io/org.eclipse.smarthome.io.voice/${project.version} + mvn:org.eclipse.smarthome.io/org.eclipse.smarthome.io.audio/${project.version} mvn:org.eclipse.smarthome.io/org.eclipse.smarthome.io.net/${project.version} mvn:org.eclipse.smarthome.io/org.eclipse.smarthome.io.rest/${project.version} mvn:org.eclipse.smarthome.io/org.eclipse.smarthome.io.rest.core/${project.version} diff --git a/features/org.eclipse.smarthome.feature.runtime.core/feature.xml b/features/org.eclipse.smarthome.feature.runtime.core/feature.xml index e4b3ac8272b..e40895b0c2d 100644 --- a/features/org.eclipse.smarthome.feature.runtime.core/feature.xml +++ b/features/org.eclipse.smarthome.feature.runtime.core/feature.xml @@ -229,6 +229,13 @@ version="0.0.0" unpack="false"/> + +