Skip to content

Commit

Permalink
Merge pull request #1394 from pedroSG94/fix/streambase-release
Browse files Browse the repository at this point in the history
add release method to StreamBase
  • Loading branch information
pedroSG94 authored Feb 14, 2024
2 parents 45b332a + 28e2580 commit b68fc57
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class StreamService: Service(), ConnectChecker {
stopRecord()
stopStream()
stopPreview()
rtmpCamera?.release()
sensorRotationManager?.stop()
prepared = false
observer.postValue(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public AudioEncoder(GetAacData getAacData) {
*/
public boolean prepareAudioEncoder(int bitRate, int sampleRate, boolean isStereo,
int maxInputSize) {
if (prepared) stop();

this.bitRate = bitRate;
this.sampleRate = sampleRate;
this.maxInputSize = maxInputSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public boolean prepareVideoEncoder(int width, int height, int fps, int bitRate,
public boolean prepareVideoEncoder(int width, int height, int fps, int bitRate, int rotation,
int iFrameInterval, FormatVideoEncoder formatVideoEncoder, int profile,
int level) {
if (prepared) stop();

this.width = width;
this.height = height;
this.fps = fps;
Expand Down
8 changes: 8 additions & 0 deletions library/src/main/java/com/pedro/library/base/StreamBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,14 @@ abstract class StreamBase(
if (!isRecording) recordController.resetFormats()
}

fun release() {
if (isStreaming) stopStream()
if (isRecording) stopRecord()
if (isOnPreview) stopPreview()
stopSources()
videoSource.release()
}

private fun prepareEncoders(): Boolean {
return videoEncoder.prepareVideoEncoder() && audioEncoder.prepareAudioEncoder()
}
Expand Down

0 comments on commit b68fc57

Please sign in to comment.