* migrate few annotations to androidx * mission recovery: better error handling (except StreamExtractor.getErrorMessage() method always returns an error) * post-processing: more detailed progress [file specific changes] DownloadMission.java * remove redundant/boilerplate code (again) * make few variables volatile * better file "length" approximation * use "done" variable to count the amount of bytes downloaded (simplify percent calc in UI code) Postprocessing.java * if case of error use "ERROR_POSTPROCESSING" instead of "ERROR_UNKNOWN_EXCEPTION" * simplify source stream init DownloadManager.java * move all "service message sending" code to DownloadMission * remove not implemented method "notifyUserPendingDownloads()" also his unused strings DownloadManagerService.java * use START_STICKY instead of START_NOT_STICKY * simplify addMissionEventListener()/removeMissionEventListener() methods (always are called from the main thread) Deleter.java * better method definition MissionAdapter.java * better method definition * code cleanup * the UI is now refreshed every 750ms * simplify download progress calculation * indicates if the download is actually recovering * smooth download speed measure * show estimated remain time MainFragment.java: * check if viewPager is null (issued by "Apply changes" feature of Android Studio)
44 lines
1.3 KiB
Java
44 lines
1.3 KiB
Java
package us.shandian.giga.postprocessing;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import org.schabi.newpipe.streams.OggFromWebMWriter;
|
|
import org.schabi.newpipe.streams.io.SharpStream;
|
|
|
|
import java.io.IOException;
|
|
import java.nio.ByteBuffer;
|
|
|
|
class OggFromWebmDemuxer extends Postprocessing {
|
|
|
|
OggFromWebmDemuxer() {
|
|
super(true, true, ALGORITHM_OGG_FROM_WEBM_DEMUXER);
|
|
}
|
|
|
|
@Override
|
|
boolean test(SharpStream... sources) throws IOException {
|
|
ByteBuffer buffer = ByteBuffer.allocate(4);
|
|
sources[0].read(buffer.array());
|
|
|
|
// youtube uses WebM as container, but the file extension (format suffix) is "*.opus"
|
|
// check if the file is a webm/mkv file before proceed
|
|
|
|
switch (buffer.getInt()) {
|
|
case 0x1a45dfa3:
|
|
return true;// webm/mkv
|
|
case 0x4F676753:
|
|
return false;// ogg
|
|
}
|
|
|
|
throw new UnsupportedOperationException("file not recognized, failed to demux the audio stream");
|
|
}
|
|
|
|
@Override
|
|
int process(SharpStream out, @NonNull SharpStream... sources) throws IOException {
|
|
OggFromWebMWriter demuxer = new OggFromWebMWriter(sources[0], out);
|
|
demuxer.parseSource();
|
|
demuxer.selectTrack(0);
|
|
demuxer.build();
|
|
|
|
return OK_RESULT;
|
|
}
|
|
}
|