-
-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tts] Make the LRU media cache generic
Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
- Loading branch information
Showing
17 changed files
with
1,822 additions
and
1,535 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...enhab.core.voice/src/main/java/org/openhab/core/voice/internal/cache/AudioFormatInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Copyright (c) 2010-2023 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.core.voice.internal.cache; | ||
|
||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.core.audio.AudioFormat; | ||
|
||
/** | ||
* Serializable AudioFormat storage class | ||
* We cannot use a record yet (requires Gson v2.10) | ||
* | ||
* @author Gwendal Roulleau - Initial contribution | ||
*/ | ||
public class AudioFormatInfo { | ||
public final @Nullable Boolean bigEndian; | ||
public final @Nullable Integer bitDepth; | ||
public final @Nullable Integer bitRate; | ||
public final @Nullable Long frequency; | ||
public final @Nullable Integer channels; | ||
public final @Nullable String codec; | ||
public final @Nullable String container; | ||
|
||
public AudioFormatInfo(String text, @Nullable Boolean bigEndian, @Nullable Integer bitDepth, | ||
@Nullable Integer bitRate, @Nullable Long frequency, @Nullable Integer channels, @Nullable String codec, | ||
@Nullable String container) { | ||
super(); | ||
this.bigEndian = bigEndian; | ||
this.bitDepth = bitDepth; | ||
this.bitRate = bitRate; | ||
this.frequency = frequency; | ||
this.channels = channels; | ||
this.codec = codec; | ||
this.container = container; | ||
} | ||
|
||
public AudioFormatInfo(AudioFormat audioFormat) { | ||
this.bigEndian = audioFormat.isBigEndian(); | ||
this.bitDepth = audioFormat.getBitDepth(); | ||
this.bitRate = audioFormat.getBitRate(); | ||
this.frequency = audioFormat.getFrequency(); | ||
this.channels = audioFormat.getChannels(); | ||
this.codec = audioFormat.getCodec(); | ||
this.container = audioFormat.getContainer(); | ||
} | ||
|
||
public AudioFormat toAudioFormat() { | ||
return new AudioFormat(container, codec, bigEndian, bitDepth, bitRate, frequency, channels); | ||
} | ||
} |
188 changes: 0 additions & 188 deletions
188
...re.voice/src/main/java/org/openhab/core/voice/internal/cache/AudioStreamCacheWrapper.java
This file was deleted.
Oops, something went wrong.
104 changes: 104 additions & 0 deletions
104
....core.voice/src/main/java/org/openhab/core/voice/internal/cache/AudioStreamFromCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/** | ||
* Copyright (c) 2010-2023 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.core.voice.internal.cache; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.core.audio.AudioException; | ||
import org.openhab.core.audio.AudioFormat; | ||
import org.openhab.core.audio.FixedLengthAudioStream; | ||
import org.openhab.core.cache.lru.InputStreamCacheWrapper; | ||
|
||
/** | ||
* Implements AudioStream methods, with an inner stream extracted from cache | ||
* | ||
* @author Gwendal Roulleau - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class AudioStreamFromCache extends FixedLengthAudioStream { | ||
|
||
private InputStreamCacheWrapper inputStream; | ||
private AudioFormat audioFormat; | ||
|
||
public AudioStreamFromCache(InputStreamCacheWrapper inputStream, AudioFormatInfo audioFormat) { | ||
this.inputStream = inputStream; | ||
this.audioFormat = audioFormat.toAudioFormat(); | ||
} | ||
|
||
@Override | ||
public int read() throws IOException { | ||
return inputStream.read(); | ||
} | ||
|
||
@Override | ||
public int read(byte @Nullable [] b, int off, int len) throws IOException { | ||
return inputStream.read(b, off, len); | ||
} | ||
|
||
@Override | ||
public AudioFormat getFormat() { | ||
return audioFormat; | ||
} | ||
|
||
@Override | ||
public long length() { | ||
return inputStream.length(); | ||
} | ||
|
||
@Override | ||
public InputStream getClonedStream() throws AudioException { | ||
try { | ||
return inputStream.getClonedStream(); | ||
} catch (IOException e) { | ||
throw new AudioException("Cannot get cloned AudioStream", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
inputStream.close(); | ||
} | ||
|
||
@Override | ||
public long skip(long n) throws IOException { | ||
return inputStream.skip(n); | ||
} | ||
|
||
@Override | ||
public void skipNBytes(long n) throws IOException { | ||
inputStream.skipNBytes(n); | ||
} | ||
|
||
@Override | ||
public int available() throws IOException { | ||
return inputStream.available(); | ||
} | ||
|
||
@Override | ||
public synchronized void mark(int readlimit) { | ||
inputStream.mark(readlimit); | ||
} | ||
|
||
@Override | ||
public synchronized void reset() throws IOException { | ||
inputStream.reset(); | ||
} | ||
|
||
@Override | ||
public boolean markSupported() { | ||
return inputStream.markSupported(); | ||
} | ||
} |
Oops, something went wrong.