Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Sep 1, 2024
2 parents ed27685 + 5e98908 commit f108424
Show file tree
Hide file tree
Showing 11 changed files with 1,030 additions and 940 deletions.
9 changes: 5 additions & 4 deletions encoder/src/main/java/com/pedro/encoder/BaseEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public abstract class BaseEncoder implements EncoderCallback {
private Handler handler;
private EncoderErrorCallback encoderErrorCallback;
protected String type;
protected CodecUtil.CodecTypeError typeError;

public void setEncoderErrorCallback(EncoderErrorCallback encoderErrorCallback) {
this.encoderErrorCallback = encoderErrorCallback;
Expand Down Expand Up @@ -112,7 +113,7 @@ private void initCodec() {
running = true;
}

public abstract void reset();
public abstract boolean reset();

public abstract void start(boolean resetTs);

Expand All @@ -130,10 +131,10 @@ private void reloadCodec(IllegalStateException e) {
//Sometimes encoder crash, we will try recover it. Reset encoder a time if crash
EncoderErrorCallback callback = encoderErrorCallback;
if (callback != null) {
shouldReset = callback.onEncodeError(TAG, e);
shouldReset = callback.onEncodeError(typeError, e);
}
if (shouldReset) {
Log.e(TAG, "Encoder crashed, trying to recover it");
Log.e(typeError.name(), "Encoder crashed, trying to recover it");
reset();
}
}
Expand Down Expand Up @@ -299,7 +300,7 @@ public void onOutputBufferAvailable(@NonNull MediaCodec mediaCodec, int outBuffe
public void onError(@NonNull MediaCodec mediaCodec, @NonNull MediaCodec.CodecException e) {
Log.e(TAG, "Error", e);
EncoderErrorCallback callback = encoderErrorCallback;
if (callback != null) callback.onCodecError(TAG, e);
if (callback != null) callback.onCodecError(typeError, e);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
package com.pedro.encoder

import android.media.MediaCodec
import com.pedro.encoder.utils.CodecUtil.CodecTypeError

/**
* Created by pedro on 18/9/23.
*/
interface EncoderErrorCallback {
fun onCodecError(type: String, e: MediaCodec.CodecException)
fun onCodecError(type: CodecTypeError, e: MediaCodec.CodecException)

/**
* @return indicate if should try reset encoder
*/
fun onEncodeError(type: String, e: IllegalStateException): Boolean = true
fun onEncodeError(type: CodecTypeError, e: IllegalStateException): Boolean = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class AudioEncoder extends BaseEncoder implements GetMicrophoneData {

public AudioEncoder(GetAudioData getAudioData) {
this.getAudioData = getAudioData;
typeError = CodecUtil.CodecTypeError.AUDIO_CODEC;
type = CodecUtil.AAC_MIME;
TAG = "AudioEncoder";
}
Expand Down Expand Up @@ -129,10 +130,12 @@ protected void stopImp() {
}

@Override
public void reset() {
public boolean reset() {
stop(false);
prepareAudioEncoder(bitRate, sampleRate, isStereo, maxInputSize);
boolean result = prepareAudioEncoder(bitRate, sampleRate, isStereo, maxInputSize);
if (!result) return false;
restart();
return true;
}

@Override
Expand Down
4 changes: 4 additions & 0 deletions encoder/src/main/java/com/pedro/encoder/utils/CodecUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public enum CodecType {
FIRST_COMPATIBLE_FOUND, SOFTWARE, HARDWARE
}

public enum CodecTypeError {
VIDEO_CODEC, AUDIO_CODEC
}

public static List<String> showAllCodecsInfo() {
List<MediaCodecInfo> mediaCodecInfoList = getAllCodecs(false);
List<String> infos = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class VideoEncoder extends BaseEncoder implements GetCameraData {

public VideoEncoder(GetVideoData getVideoData) {
this.getVideoData = getVideoData;
typeError = CodecUtil.CodecTypeError.VIDEO_CODEC;
type = CodecUtil.H264_MIME;
TAG = "VideoEncoder";
}
Expand Down Expand Up @@ -196,11 +197,13 @@ protected void stopImp() {
}

@Override
public void reset() {
public boolean reset() {
stop(false);
prepareVideoEncoder(width, height, fps, bitRate, rotation, iFrameInterval, formatVideoEncoder,
boolean result = prepareVideoEncoder(width, height, fps, bitRate, rotation, iFrameInterval, formatVideoEncoder,
profile, level);
if (!result) return false;
restart();
return true;
}

private FormatVideoEncoder chooseColorDynamically(MediaCodecInfo mediaCodecInfo) {
Expand Down
16 changes: 16 additions & 0 deletions library/src/main/java/com/pedro/library/base/Camera1Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,22 @@ public boolean isAutoFocusEnabled() {
return cameraManager.isAutoFocusEnabled();
}

public boolean resetVideoEncoder() {
if (glInterface != null) {
glInterface.removeMediaCodecSurface();
boolean result = videoEncoder.reset();
if (!result) return false;
glInterface.addMediaCodecSurface(videoEncoder.getInputSurface());
return true;
} else {
return videoEncoder.reset();
}
}

public boolean resetAudioEncoder() {
return audioEncoder.reset();
}

/**
* Call this method before use @startStream. If not you will do a stream without video. NOTE:
* Rotation with encoder is silence ignored in some devices.
Expand Down
Loading

0 comments on commit f108424

Please sign in to comment.