Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Feb 23, 2024
1 parent f1c3765 commit 19ab626
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import com.pedro.common.AudioCodec;
import com.pedro.common.ConnectChecker;
import com.pedro.encoder.input.gl.SpriteGestureController;
import com.pedro.encoder.input.gl.render.filters.AnalogTVFilterRender;
Expand Down Expand Up @@ -136,7 +135,6 @@ protected void onCreate(Bundle savedInstanceState) {
etUrl = findViewById(R.id.et_rtp_url);
etUrl.setHint(R.string.hint_srt);
srtCamera1 = new SrtCamera1(openGlView, this);
srtCamera1.setAudioCodec(AudioCodec.OPUS);
openGlView.getHolder().addCallback(this);
openGlView.setOnTouchListener(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public boolean prepareVideo() {
* doesn't support any configuration seated or your device hasn't a AAC encoder).
*/
public boolean prepareAudio() {
return prepareAudio(64 * 1024, 48000, true, false, false);
return prepareAudio(64 * 1024, 32000, true, false, false);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions srt/src/main/java/com/pedro/srt/mpeg2ts/packets/AacPacket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class AacPacket(
): BasePacket(psiManager, limitSize) {

private val header = ByteArray(7) //ADTS header
var sampleRate = 44100
var isStereo = true
private var sampleRate = 44100
private var isStereo = true

override fun createAndSendPacket(
byteBuffer: ByteBuffer,
Expand Down
15 changes: 1 addition & 14 deletions srt/src/main/java/com/pedro/srt/mpeg2ts/packets/OpusPacket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ class OpusPacket(
psiManager: PsiManager,
): BasePacket(psiManager, limitSize) {

var sampleRate = 48000
var isStereo = true

override fun createAndSendPacket(
byteBuffer: ByteBuffer,
info: MediaCodec.BufferInfo,
Expand Down Expand Up @@ -68,17 +65,7 @@ class OpusPacket(
callback(packets)
}

override fun resetPacket(resetInfo: Boolean) {
if (resetInfo) {
sampleRate = 48000
isStereo = true
}
}

fun sendAudioInfo(sampleRate: Int, stereo: Boolean) {
this.sampleRate = sampleRate
this.isStereo = stereo
}
override fun resetPacket(resetInfo: Boolean) { }

private fun createControlHeader(payloadLength: Int): ByteArray {
val bytes = payloadLength.toByteArray()
Expand Down
1 change: 0 additions & 1 deletion srt/src/main/java/com/pedro/srt/srt/SrtSender.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ class SrtSender(
}
AudioCodec.OPUS -> {
audioPacket = OpusPacket(limitSize, psiManager)
(audioPacket as? OpusPacket)?.sendAudioInfo(sampleRate, isStereo)
}
AudioCodec.G711 -> {
throw IllegalArgumentException("Unsupported codec: ${commandsManager.audioCodec.name}")
Expand Down
1 change: 1 addition & 0 deletions srt/src/main/java/com/pedro/srt/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ fun InputStream.readUntil(byteArray: ByteArray) {
if (result != -1) bytesRead += result
}
}

fun Int.toByteArray(): ByteArray {
val bytes = mutableListOf<Byte>()
var remainingValue = this
Expand Down

0 comments on commit 19ab626

Please sign in to comment.