Skip to content

Commit

Permalink
[android] Added mp4 demux progress
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml committed Mar 26, 2016
1 parent a6d73c0 commit 8868d74
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.frostwire.android.R;
import com.frostwire.android.gui.Librarian;
import com.frostwire.android.gui.services.Engine;
import com.frostwire.fmp4.Mp4Demuxer;
import com.frostwire.platform.FileSystem;
import com.frostwire.platform.Platforms;
import com.frostwire.search.youtube.YouTubeCrawledSearchResult;
Expand Down Expand Up @@ -84,6 +85,9 @@ public final class YouTubeDownload implements DownloadTransfer {
private long speedMarkTimestamp;
private long totalReceivedSinceLastSpeedStamp;

private long demuxerReadCount;
private long demuxerWriteCount;

YouTubeDownload(TransferManager manager, YouTubeCrawledSearchResult sr) {
this.manager = manager;
this.sr = sr;
Expand Down Expand Up @@ -166,6 +170,16 @@ public String getStatus() {
}

public int getProgress() {
if (status == STATUS_DEMUXING) {
try {
if (demuxerReadCount > 0) { // in case fmp4 fail
return (int) (demuxerReadCount * 100 / completeFile.length());
}
} catch (Throwable e) {
// ignore, fall back to old logic
}
}

This comment has been minimized.

Copy link
@gubatron

gubatron Mar 27, 2016

Collaborator

hmm, so this will reset the progress bar and start to fill it up again right?
how does it feel when you use it?

What I had in mind was keeping the progress bar at 100% (keeping getProgress() as in download progress) while just changing the transfer status text to be demuxing (55%)

I'll give it a try.

This comment has been minimized.

Copy link
@gubatron

gubatron Mar 27, 2016

Collaborator

Performed some tests and added some logging output but the experience is too coarse for most downloads as the listener seems to be reporting progress towards the end only. This is usually the output:

I/YouTubeDownload(24479): getProgress() -> 91

and then 100%.

I decided to make a test with a larger video file and this is what I obtained

I/YouTubeDownload(24479): getProgress() -> 22
I/YouTubeDownload(24479): getProgress() -> 95
I/YouTubeDownload(24479): getProgress() -> 96
I/YouTubeDownload(24479): getProgress() -> 96
I/YouTubeDownload(24479): getProgress() -> 96
I/YouTubeDownload(24479): getProgress() -> 96
I/YouTubeDownload(24479): getProgress() -> 96

Notice the jump, and then it sort of gets stuck there at 96 most of the time.

This comment has been minimized.

Copy link
@aldenml

aldenml Mar 27, 2016

Author Collaborator

@gubatron I need to say that your test was very helpful, I was aware of the progress behavior but when I saw your log, It was clear to me where the hot code was. Fixed with 3bccfcf

I also changed the progress notification

if (size > 0) {
return isComplete() ? 100 : (int) ((bytesReceived * 100) / size);
} else {
Expand Down Expand Up @@ -478,7 +492,13 @@ public void onComplete(HttpClient client) {
} else if (downloadType == DownloadType.DEMUX) {
try {
status = STATUS_DEMUXING;
new MP4Muxer().demuxAudio(tempAudio.getAbsolutePath(), completeFile.getAbsolutePath(), buildMetadata());
new MP4Muxer().demuxAudio(tempAudio.getAbsolutePath(), completeFile.getAbsolutePath(), buildMetadata(), new Mp4Demuxer.DemuxerListener() {
@Override
public void onCount(long readCount, long writeCount) {
demuxerReadCount = readCount;
demuxerWriteCount = writeCount;
}
});

if (!completeFile.exists()) {
//error(null);
Expand Down
16 changes: 10 additions & 6 deletions common/src/main/java/com/frostwire/util/MP4Muxer.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,16 @@ protected Box createUdta(Movie movie) {

public void demuxAudio(String video, String output, final MP4Metadata mt, Mp4Demuxer.DemuxerListener l) throws IOException {
try {
Mp4Tags tags = new Mp4Tags();
tags.compatibleBrands = new int[]{com.frostwire.fmp4.Box.M4A_, com.frostwire.fmp4.Box.mp42, com.frostwire.fmp4.Box.isom, com.frostwire.fmp4.Box.zero};
tags.title = mt.title;
tags.author = mt.author;
tags.source = mt.source;
tags.jpg = mt.jpg;
Mp4Tags tags = null;

if (mt != null) {
tags = new Mp4Tags();
tags.compatibleBrands = new int[]{com.frostwire.fmp4.Box.M4A_, com.frostwire.fmp4.Box.mp42, com.frostwire.fmp4.Box.isom, com.frostwire.fmp4.Box.zero};
tags.title = mt.title;
tags.author = mt.author;
tags.source = mt.source;
tags.jpg = mt.jpg;
}
Mp4Demuxer.audio(new File(video), new File(output), tags, l);
} catch (Throwable e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public void onComplete(HttpClient client) {
}
} else if (downloadType == DownloadType.DEMUX) {
try {
new MP4Muxer().demuxAudio(tempAudio.getAbsolutePath(), completeFile.getAbsolutePath(), buildMetadata());
new MP4Muxer().demuxAudio(tempAudio.getAbsolutePath(), completeFile.getAbsolutePath(), buildMetadata(), null);

if (!completeFile.exists()) {
state = TransferState.ERROR_MOVING_INCOMPLETE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ private void demuxFiles(final List<File> files) {
String mp4 = file.getAbsolutePath();
String m4a = new File(file.getParentFile(), FilenameUtils.getBaseName(mp4) + ".m4a").getAbsolutePath();
try {
new MP4Muxer().demuxAudio(mp4, m4a, null);
new MP4Muxer().demuxAudio(mp4, m4a, null, null);
demuxedFiles.add(new File(m4a));
updateDemuxingStatus(new File(m4a), files.size(), true);
} catch (Throwable e) {
Expand Down

0 comments on commit 8868d74

Please sign in to comment.