desc:增加健壮性

main
xiaowusky 1 year ago
parent 9a5616ee69
commit 0c23f5bfa0

@ -62,6 +62,10 @@ public class AndroidMuxer {
throw new IllegalStateException();
}
if (mMuxer == null) {
throw new IllegalStateException("mMuxer is null");
}
synchronized (mMuxer) {
int track = mMuxer.addTrack(trackFormat);
mVideoFormat = trackFormat;
@ -79,7 +83,7 @@ public class AndroidMuxer {
}
public void writeSampleData(int trackIndex, ByteBuffer encodedData, MediaCodec.BufferInfo bufferInfo) {
if (mNumReleases != 0) {
if (mNumReleases != 0 || mMuxer == null) {
return;
}
synchronized (mMuxer) {
@ -101,20 +105,24 @@ public class AndroidMuxer {
}
public boolean release() {
synchronized (mMuxer) {
if (++mNumReleases == mNumTracks) {
stopMuxer();
return true;
if (mMuxer != null) {
synchronized (mMuxer) {
if (++mNumReleases == mNumTracks) {
stopMuxer();
return true;
}
}
}
return false;
}
public void stopMuxer() {
mMuxer.stop();
mMuxer.release();
if (mStartRecordTime > 0 && mStartRecordTime < System.currentTimeMillis() && !TextUtils.isEmpty(mCurrentPath)) {
insertToDB(mStartRecordTime, mCurrentPath);
if (mMuxer != null) {
mMuxer.stop();
mMuxer.release();
if (mStartRecordTime > 0 && mStartRecordTime < System.currentTimeMillis() && !TextUtils.isEmpty(mCurrentPath)) {
insertToDB(mStartRecordTime, mCurrentPath);
}
}
}
}

@ -287,8 +287,12 @@ public class MediaCodecManager {
@Override
public void onOutputFormatChanged(@NonNull MediaCodec codec, @NonNull MediaFormat format) {
MediaFormat newFormat = mMediaCodec.getOutputFormat();
mTrackIndex = androidMuxer.addTrack(newFormat);
try {
MediaFormat newFormat = mMediaCodec.getOutputFormat();
mTrackIndex = androidMuxer.addTrack(newFormat);
} catch (Exception e) {
e.printStackTrace();
}
}
}, mHandler);
mMediaCodec.start();

Loading…
Cancel
Save