Change AudioCodecDefines to simple object
This commit is contained in:
@@ -19,16 +19,10 @@ package de.rochefort.childmonitor
|
|||||||
import android.media.AudioFormat
|
import android.media.AudioFormat
|
||||||
import de.rochefort.childmonitor.audio.G711UCodec
|
import de.rochefort.childmonitor.audio.G711UCodec
|
||||||
|
|
||||||
class AudioCodecDefines private constructor() {
|
object AudioCodecDefines {
|
||||||
init {
|
|
||||||
throw IllegalStateException("Do not instantiate!")
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
const val FREQUENCY = 8000
|
const val FREQUENCY = 8000
|
||||||
const val ENCODING = AudioFormat.ENCODING_PCM_16BIT
|
const val ENCODING = AudioFormat.ENCODING_PCM_16BIT
|
||||||
val CODEC = G711UCodec()
|
val CODEC = G711UCodec()
|
||||||
const val CHANNEL_CONFIGURATION_IN = AudioFormat.CHANNEL_IN_MONO
|
const val CHANNEL_CONFIGURATION_IN = AudioFormat.CHANNEL_IN_MONO
|
||||||
const val CHANNEL_CONFIGURATION_OUT = AudioFormat.CHANNEL_OUT_MONO
|
const val CHANNEL_CONFIGURATION_OUT = AudioFormat.CHANNEL_OUT_MONO
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ import java.io.IOException
|
|||||||
import java.net.Socket
|
import java.net.Socket
|
||||||
|
|
||||||
class ListenService : Service() {
|
class ListenService : Service() {
|
||||||
private val frequency: Int = AudioCodecDefines.Companion.FREQUENCY
|
private val frequency: Int = AudioCodecDefines.FREQUENCY
|
||||||
private val channelConfiguration: Int = AudioCodecDefines.Companion.CHANNEL_CONFIGURATION_OUT
|
private val channelConfiguration: Int = AudioCodecDefines.CHANNEL_CONFIGURATION_OUT
|
||||||
private val audioEncoding: Int = AudioCodecDefines.Companion.ENCODING
|
private val audioEncoding: Int = AudioCodecDefines.ENCODING
|
||||||
private val bufferSize = AudioTrack.getMinBufferSize(frequency, channelConfiguration, audioEncoding)
|
private val bufferSize = AudioTrack.getMinBufferSize(frequency, channelConfiguration, audioEncoding)
|
||||||
private val byteBufferSize = bufferSize * 2
|
private val byteBufferSize = bufferSize * 2
|
||||||
private val binder: IBinder = ListenBinder()
|
private val binder: IBinder = ListenBinder()
|
||||||
@@ -175,7 +175,7 @@ class ListenService : Service() {
|
|||||||
val decodedBuffer = ShortArray(byteBufferSize * 2)
|
val decodedBuffer = ShortArray(byteBufferSize * 2)
|
||||||
while (socket.isConnected && read != -1 && !Thread.currentThread().isInterrupted) {
|
while (socket.isConnected && read != -1 && !Thread.currentThread().isInterrupted) {
|
||||||
read = inputStream.read(readBuffer)
|
read = inputStream.read(readBuffer)
|
||||||
val decoded: Int = AudioCodecDefines.Companion.CODEC.decode(decodedBuffer, readBuffer, read, 0)
|
val decoded: Int = AudioCodecDefines.CODEC.decode(decodedBuffer, readBuffer, read, 0)
|
||||||
if (decoded > 0) {
|
if (decoded > 0) {
|
||||||
audioTrack.write(decodedBuffer, 0, decoded)
|
audioTrack.write(decodedBuffer, 0, decoded)
|
||||||
val decodedBytes = ShortArray(decoded)
|
val decodedBytes = ShortArray(decoded)
|
||||||
|
|||||||
@@ -59,9 +59,9 @@ class MonitorService : Service() {
|
|||||||
val statusText = ma.findViewById<TextView>(R.id.textStatus)
|
val statusText = ma.findViewById<TextView>(R.id.textStatus)
|
||||||
statusText.setText(R.string.streaming)
|
statusText.setText(R.string.streaming)
|
||||||
}
|
}
|
||||||
val frequency: Int = AudioCodecDefines.Companion.FREQUENCY
|
val frequency: Int = AudioCodecDefines.FREQUENCY
|
||||||
val channelConfiguration: Int = AudioCodecDefines.Companion.CHANNEL_CONFIGURATION_IN
|
val channelConfiguration: Int = AudioCodecDefines.CHANNEL_CONFIGURATION_IN
|
||||||
val audioEncoding: Int = AudioCodecDefines.Companion.ENCODING
|
val audioEncoding: Int = AudioCodecDefines.ENCODING
|
||||||
val bufferSize = AudioRecord.getMinBufferSize(frequency, channelConfiguration, audioEncoding)
|
val bufferSize = AudioRecord.getMinBufferSize(frequency, channelConfiguration, audioEncoding)
|
||||||
val audioRecord: AudioRecord = try {
|
val audioRecord: AudioRecord = try {
|
||||||
AudioRecord(
|
AudioRecord(
|
||||||
@@ -85,7 +85,7 @@ class MonitorService : Service() {
|
|||||||
Log.d(TAG, "Socket send buffer size: " + socket.sendBufferSize)
|
Log.d(TAG, "Socket send buffer size: " + socket.sendBufferSize)
|
||||||
while (socket.isConnected && (this.currentSocket != null) && !Thread.currentThread().isInterrupted) {
|
while (socket.isConnected && (this.currentSocket != null) && !Thread.currentThread().isInterrupted) {
|
||||||
val read = audioRecord.read(pcmBuffer, 0, bufferSize)
|
val read = audioRecord.read(pcmBuffer, 0, bufferSize)
|
||||||
val encoded: Int = AudioCodecDefines.Companion.CODEC.encode(pcmBuffer, read, ulawBuffer, 0)
|
val encoded: Int = AudioCodecDefines.CODEC.encode(pcmBuffer, read, ulawBuffer, 0)
|
||||||
out.write(ulawBuffer, 0, encoded)
|
out.write(ulawBuffer, 0, encoded)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|||||||
Reference in New Issue
Block a user