Skip to content

Commit

Permalink
Do not stop muxer if no frames are written. Seems we can do without t…
Browse files Browse the repository at this point in the history
…he blocking in stop
  • Loading branch information
DavidGillsjo committed Oct 1, 2020
1 parent 0babbdd commit babb87c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,26 +209,11 @@ public void run() {

//Callback from encoder when it is finished and thread is shutting down.
public void onEncodingFinished() {
Log.d(TAG, "Got listener call");
Log.d(TAG, "Got Encoder listener call");
mRecordingEnabled = false;
getActivity().runOnUiThread(() -> updateControls());
}


@Override
public void onStop() {
super.onStop();
// Wait for recording to stop
/*TODO: Not a nice solution, making the Encoder lifecycle aware might be a better move */
while(mRecordingEnabled) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

/**
* onClick handler for "record" button.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,13 @@ public void release() {
mEncoder = null;
}
if (mMuxer != null) {
// TODO: stop() throws an exception if you haven't fed it any data. Keep track
// stop() and release() throws an exception if you haven't fed it any data. Keep track
// of frames submitted, and don't call stop() if we haven't written anything.
mMuxer.stop();
mMuxer.release();
if (mFrameNbr > 0) {
if (VERBOSE) Log.d(TAG, "Stopping Muxer since we have written " + mFrameNbr + " frames");
mMuxer.stop();
mMuxer.release();
}
mMuxer = null;
}

Expand Down Expand Up @@ -191,8 +194,8 @@ public void drainEncoder(boolean endOfStream) {
// adjust the ByteBuffer values to match BufferInfo (not needed?)
encodedData.position(mBufferInfo.offset);
encodedData.limit(mBufferInfo.offset + mBufferInfo.size);
writeMetadata(mFrameNbr++, mBufferInfo.presentationTimeUs);
mMuxer.writeSampleData(mTrackIndex, encodedData, mBufferInfo);
writeMetadata(mFrameNbr++, mBufferInfo.presentationTimeUs);
if (VERBOSE) {
Log.d(TAG, "sent " + mBufferInfo.size + " bytes to muxer, ts=" +
mBufferInfo.presentationTimeUs);
Expand Down

0 comments on commit babb87c

Please sign in to comment.