Skip to content

Commit

Permalink
fix StreamBase record only audio/video
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Jan 24, 2025
1 parent de6d6f2 commit 7b1a37c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions library/src/main/java/com/pedro/library/base/StreamBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.pedro.encoder.audio.AudioEncoder
import com.pedro.encoder.audio.GetAudioData
import com.pedro.encoder.input.audio.GetMicrophoneData
import com.pedro.encoder.input.sources.audio.AudioSource
import com.pedro.encoder.input.sources.audio.NoAudioSource
import com.pedro.encoder.input.sources.video.NoVideoSource
import com.pedro.encoder.input.sources.video.VideoSource
import com.pedro.encoder.utils.CodecUtil
Expand Down Expand Up @@ -569,7 +570,8 @@ abstract class StreamBase(
}

override fun onAudioFormat(mediaFormat: MediaFormat) {
recordController.setAudioFormat(mediaFormat)
val isOnlyAudio = videoSource is NoVideoSource
recordController.setAudioFormat(mediaFormat, isOnlyAudio)
}
}

Expand All @@ -585,7 +587,10 @@ abstract class StreamBase(
}

override fun onVideoFormat(mediaFormat: MediaFormat) {
if (!differentRecordResolution) recordController.setVideoFormat(mediaFormat)
if (!differentRecordResolution) {
val isOnlyVideo = audioSource is NoAudioSource
recordController.setVideoFormat(mediaFormat, isOnlyVideo)
}
}
}

Expand All @@ -598,7 +603,8 @@ abstract class StreamBase(
}

override fun onVideoFormat(mediaFormat: MediaFormat) {
recordController.setVideoFormat(mediaFormat)
val isOnlyVideo = audioSource is NoAudioSource
recordController.setVideoFormat(mediaFormat, isOnlyVideo)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ private void init() {
}

private void write(int track, ByteBuffer byteBuffer, MediaCodec.BufferInfo info) {
if (track == -1) return;
try {
mediaMuxer.writeSampleData(track, byteBuffer, info);
if (bitrateManager != null) bitrateManager.calculateBitrate(info.size * 8L, ExtensionsKt.getSuspendContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private void init() {
}

private void write(int track, ByteBuffer byteBuffer, MediaCodec.BufferInfo info) {
if (track == -1) return;
try {
mediaMuxer.writeSampleData(track, byteBuffer, info);
if (bitrateManager != null) bitrateManager.calculateBitrate(info.size * 8L, ExtensionsKt.getSuspendContext());
Expand Down

0 comments on commit 7b1a37c

Please sign in to comment.