Skip to content

Commit

Permalink
Fix occasional NullPointerException in QueuedMuxer
Browse files Browse the repository at this point in the history
  • Loading branch information
ypresto committed May 29, 2015
1 parent 5b5bfa2 commit 4358037
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class QueuedMuxer {
private int mVideoTrackIndex;
private int mAudioTrackIndex;
private ByteBuffer mByteBuffer;
private List<SampleInfo> mSampleInfoList;
private final List<SampleInfo> mSampleInfoList;
private boolean mStarted;

public QueuedMuxer(MediaMuxer muxer, Listener listener) {
Expand Down Expand Up @@ -69,18 +69,22 @@ private void onSetOutputFormat() {
mAudioTrackIndex = mMuxer.addTrack(mAudioFormat);
Log.v(TAG, "Added track #" + mAudioTrackIndex + " with " + mAudioFormat.getString(MediaFormat.KEY_MIME) + " to muxer");
mMuxer.start();
mStarted = true;

if (mByteBuffer == null) {
mByteBuffer = ByteBuffer.allocate(0);
}
mByteBuffer.flip();
Log.v(TAG, "Output format determined, writing " + mSampleInfoList.size() +
" samples / " + mByteBuffer.limit() + " bytes to muxer.");
mStarted = true;
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
int offset = 0;
for (SampleInfo sampleInfo : mSampleInfoList) {
sampleInfo.writeToBufferInfo(bufferInfo, offset);
mMuxer.writeSampleData(getTrackIndexForSampleType(sampleInfo.mSampleType), mByteBuffer, bufferInfo);
offset += sampleInfo.mSize;
}
mSampleInfoList = null;
mSampleInfoList.clear();
mByteBuffer = null;
}

Expand Down

0 comments on commit 4358037

Please sign in to comment.