Skip to content
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
52a21e4
implement webm to ogg demuxer
kapodamy Sep 24, 2019
0cdfa6e
rewrite OggFromWebMWriter
kapodamy Sep 25, 2019
c891f2f
long-term downloads resume
kapodamy Sep 28, 2019
429ee7e
Mp4FromDashWriter fixes
kapodamy Sep 29, 2019
160a33e
misc changes
kapodamy Oct 1, 2019
d092e39
fallback for pending downloads directory
kapodamy Oct 1, 2019
9339fc8
update DownloadManager.java
kapodamy Oct 1, 2019
94e2314
update WebMWriter.java
kapodamy Oct 1, 2019
844f80a
update DownloadDialog.java
kapodamy Oct 2, 2019
f62a791
code cleanup
kapodamy Oct 10, 2019
ea1be11
Merge branch 'dev' into dl-last-features
kapodamy Nov 24, 2019
14de2f2
Merge branch 'dev' into dl-last-features
kapodamy Nov 26, 2019
773aa1e
implement webm to ogg demuxer
kapodamy Sep 24, 2019
dab5345
rewrite OggFromWebMWriter
kapodamy Sep 25, 2019
86dafdd
long-term downloads resume
kapodamy Sep 28, 2019
5707381
Mp4FromDashWriter fixes
kapodamy Sep 29, 2019
4292ca9
misc changes
kapodamy Oct 1, 2019
60d4c8a
fallback for pending downloads directory
kapodamy Oct 1, 2019
da052df
update DownloadManager.java
kapodamy Oct 1, 2019
8a992d4
update WebMWriter.java
kapodamy Oct 1, 2019
763995d
update DownloadDialog.java
kapodamy Oct 2, 2019
e6d9d8e
code cleanup
kapodamy Oct 10, 2019
3ca4614
Merge branch 'dev' into dl-last-features
kapodamy Nov 24, 2019
0033843
Merge branch 'dl-last-features' of https://github.com/kapodamy/NewPip…
kapodamy Nov 26, 2019
84ec320
commit
kapodamy Nov 26, 2019
aae8865
remove unused imports
kapodamy Dec 5, 2019
5a2cd93
remove netbeans editor-fold comments
kapodamy Dec 6, 2019
0393955
add missing change after updating NPE
kapodamy Dec 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ dependencies {
exclude module: 'support-annotations'
})

implementation 'com.github.TeamNewPipe:NewPipeExtractor:5c420340ceb39'
implementation 'com.github.TeamNewPipe:NewPipeExtractor:b6d3252'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.23.0'

Expand Down
36 changes: 26 additions & 10 deletions app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import icepick.Icepick;
import icepick.State;
import io.reactivex.disposables.CompositeDisposable;
import us.shandian.giga.get.MissionRecoveryInfo;
import us.shandian.giga.io.StoredDirectoryHelper;
import us.shandian.giga.io.StoredFileHelper;
import us.shandian.giga.postprocessing.Postprocessing;
Expand Down Expand Up @@ -762,12 +763,13 @@ private void continueSelectedDownload(@NonNull StoredFileHelper storage) {
}

Stream selectedStream;
Stream secondaryStream = null;
char kind;
int threads = threadsSeekBar.getProgress() + 1;
String[] urls;
MissionRecoveryInfo[] recoveryInfo;
String psName = null;
String[] psArgs = null;
String secondaryStreamUrl = null;
long nearLength = 0;

// more download logic: select muxer, subtitle converter, etc.
Expand All @@ -778,18 +780,20 @@ private void continueSelectedDownload(@NonNull StoredFileHelper storage) {

if (selectedStream.getFormat() == MediaFormat.M4A) {
psName = Postprocessing.ALGORITHM_M4A_NO_DASH;
} else if (selectedStream.getFormat() == MediaFormat.WEBMA_OPUS) {
psName = Postprocessing.ALGORITHM_OGG_FROM_WEBM_DEMUXER;
}
break;
case R.id.video_button:
kind = 'v';
selectedStream = videoStreamsAdapter.getItem(selectedVideoIndex);

SecondaryStreamHelper<AudioStream> secondaryStream = videoStreamsAdapter
SecondaryStreamHelper<AudioStream> secondary = videoStreamsAdapter
.getAllSecondary()
.get(wrappedVideoStreams.getStreamsList().indexOf(selectedStream));

if (secondaryStream != null) {
secondaryStreamUrl = secondaryStream.getStream().getUrl();
if (secondary != null) {
secondaryStream = secondary.getStream();

if (selectedStream.getFormat() == MediaFormat.MPEG_4)
psName = Postprocessing.ALGORITHM_MP4_FROM_DASH_MUXER;
Expand All @@ -801,8 +805,8 @@ private void continueSelectedDownload(@NonNull StoredFileHelper storage) {

// set nearLength, only, if both sizes are fetched or known. This probably
// does not work on slow networks but is later updated in the downloader
if (secondaryStream.getSizeInBytes() > 0 && videoSize > 0) {
nearLength = secondaryStream.getSizeInBytes() + videoSize;
if (secondary.getSizeInBytes() > 0 && videoSize > 0) {
nearLength = secondary.getSizeInBytes() + videoSize;
}
}
break;
Expand All @@ -824,13 +828,25 @@ private void continueSelectedDownload(@NonNull StoredFileHelper storage) {
return;
}

if (secondaryStreamUrl == null) {
urls = new String[]{selectedStream.getUrl()};
if (secondaryStream == null) {
urls = new String[]{
selectedStream.getUrl()
};
recoveryInfo = new MissionRecoveryInfo[]{
new MissionRecoveryInfo(selectedStream)
};
} else {
urls = new String[]{selectedStream.getUrl(), secondaryStreamUrl};
urls = new String[]{
selectedStream.getUrl(), secondaryStream.getUrl()
};
recoveryInfo = new MissionRecoveryInfo[]{
new MissionRecoveryInfo(selectedStream), new MissionRecoveryInfo(secondaryStream)
};
}

DownloadManagerService.startMission(context, urls, storage, kind, threads, currentInfo.getUrl(), psName, psArgs, nearLength);
DownloadManagerService.startMission(
context, urls, storage, kind, threads, currentInfo.getUrl(), psName, psArgs, nearLength, recoveryInfo
);

dismiss();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

import android.content.Context;
import android.os.Bundle;
import androidx.annotation.NonNull;
Comment thread
kapodamy marked this conversation as resolved.
Outdated
import androidx.annotation.Nullable;
import com.google.android.material.tabs.TabLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
Expand Down
79 changes: 50 additions & 29 deletions app/src/main/java/org/schabi/newpipe/streams/Mp4FromDashWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.schabi.newpipe.streams.Mp4DashReader.Mp4DashSample;
import org.schabi.newpipe.streams.Mp4DashReader.Mp4Track;
import org.schabi.newpipe.streams.Mp4DashReader.TrunEntry;
import org.schabi.newpipe.streams.Mp4DashReader.TrackKind;
import org.schabi.newpipe.streams.io.SharpStream;

import java.io.IOException;
Expand All @@ -22,6 +23,7 @@ public class Mp4FromDashWriter {
private final static byte SAMPLES_PER_CHUNK = 6;// ffmpeg uses 2, basic uses 1 (with 60fps uses 21 or 22). NewPipe will use 6
private final static long THRESHOLD_FOR_CO64 = 0xFFFEFFFFL;// near 3.999 GiB
private final static int THRESHOLD_MOOV_LENGTH = (256 * 1024) + (2048 * 1024); // 2.2 MiB enough for: 1080p 60fps 00h35m00s
private final static short SINGLE_CHUNK_SAMPLE_BUFFER = 256;

private final long time;

Expand Down Expand Up @@ -145,7 +147,7 @@ public void build(SharpStream output) throws IOException {
// not allowed for very short tracks (less than 0.5 seconds)
//
outStream = output;
int read = 8;// mdat box header size
long read = 8;// mdat box header size
long totalSampleSize = 0;
int[] sampleExtra = new int[readers.length];
int[] defaultMediaTime = new int[readers.length];
Expand All @@ -157,6 +159,8 @@ public void build(SharpStream output) throws IOException {
tablesInfo[i] = new TablesInfo();
}

boolean singleChunk = tracks.length == 1 && tracks[0].kind == TrackKind.Audio;

//<editor-fold defaultstate="expanded" desc="calculate stbl sample tables size and required moov values">
for (int i = 0; i < readers.length; i++) {
int samplesSize = 0;
Expand Down Expand Up @@ -210,14 +214,21 @@ public void build(SharpStream output) throws IOException {
tablesInfo[i].stco = (tmp / SAMPLES_PER_CHUNK) + 1;// +1 for samples in first chunk

tmp = tmp % SAMPLES_PER_CHUNK;
if (tmp == 0) {
if (singleChunk) {
// avoid split audio streams in chunks
tablesInfo[i].stsc = 1;
tablesInfo[i].stsc_bEntries = new int[]{
1, tablesInfo[i].stsz, 1
};
tablesInfo[i].stco = 1;
} else if (tmp == 0) {
tablesInfo[i].stsc = 2;// first chunk (init) and succesive chunks
tablesInfo[i].stsc_bEntries = new int[]{
1, SAMPLES_PER_CHUNK_INIT, 1,
2, SAMPLES_PER_CHUNK, 1
};
} else {
tablesInfo[i].stsc = 3;// first chunk (init) and succesive chunks and remain chunk
tablesInfo[i].stsc = 3;// first chunk (init) and successive chunks and remain chunk
tablesInfo[i].stsc_bEntries = new int[]{
1, SAMPLES_PER_CHUNK_INIT, 1,
2, SAMPLES_PER_CHUNK, 1,
Expand Down Expand Up @@ -268,10 +279,10 @@ public void build(SharpStream output) throws IOException {
} else {*/
if (auxSize > 0) {
int length = auxSize;
byte[] buffer = new byte[8 * 1024];// 8 KiB
byte[] buffer = new byte[64 * 1024];// 64 KiB
while (length > 0) {
int count = Math.min(length, buffer.length);
outWrite(buffer, 0, count);
outWrite(buffer, count);
length -= count;
}
}
Expand All @@ -280,7 +291,7 @@ public void build(SharpStream output) throws IOException {
outSeek(ftyp_size);
}

// tablesInfo contais row counts
// tablesInfo contains row counts
// and after returning from make_moov() will contain table offsets
make_moov(defaultMediaTime, tablesInfo, is64);

Expand All @@ -291,7 +302,7 @@ public void build(SharpStream output) throws IOException {
writeEntryArray(tablesInfo[i].stsc, tablesInfo[i].stsc_bEntries.length, tablesInfo[i].stsc_bEntries);
tablesInfo[i].stsc_bEntries = null;
if (tablesInfo[i].ctts > 0) {
sampleCount[i] = 1;// index is not base zero
sampleCount[i] = 1;// the index is not base zero
sampleExtra[i] = -1;
}
}
Expand All @@ -303,8 +314,8 @@ public void build(SharpStream output) throws IOException {
outWrite(make_mdat(totalSampleSize, is64));

int[] sampleIndex = new int[readers.length];
int[] sizes = new int[SAMPLES_PER_CHUNK];
int[] sync = new int[SAMPLES_PER_CHUNK];
int[] sizes = new int[singleChunk ? SINGLE_CHUNK_SAMPLE_BUFFER : SAMPLES_PER_CHUNK];
int[] sync = new int[singleChunk ? SINGLE_CHUNK_SAMPLE_BUFFER : SAMPLES_PER_CHUNK];

int written = readers.length;
while (written > 0) {
Expand All @@ -317,7 +328,12 @@ public void build(SharpStream output) throws IOException {

long chunkOffset = writeOffset;
int syncCount = 0;
int limit = sampleIndex[i] == 0 ? SAMPLES_PER_CHUNK_INIT : SAMPLES_PER_CHUNK;
int limit;
if (singleChunk) {
limit = SINGLE_CHUNK_SAMPLE_BUFFER;
} else {
limit = sampleIndex[i] == 0 ? SAMPLES_PER_CHUNK_INIT : SAMPLES_PER_CHUNK;
}

int j = 0;
for (; j < limit; j++) {
Expand Down Expand Up @@ -354,7 +370,7 @@ public void build(SharpStream output) throws IOException {
sizes[j] = sample.data.length;
}

outWrite(sample.data, 0, sample.data.length);
outWrite(sample.data, sample.data.length);
}

if (j > 0) {
Expand All @@ -368,10 +384,16 @@ public void build(SharpStream output) throws IOException {
tablesInfo[i].stss = writeEntryArray(tablesInfo[i].stss, syncCount, sync);
}

if (is64) {
tablesInfo[i].stco = writeEntry64(tablesInfo[i].stco, chunkOffset);
} else {
tablesInfo[i].stco = writeEntryArray(tablesInfo[i].stco, 1, (int) chunkOffset);
if (tablesInfo[i].stco > 0) {
if (is64) {
tablesInfo[i].stco = writeEntry64(tablesInfo[i].stco, chunkOffset);
} else {
tablesInfo[i].stco = writeEntryArray(tablesInfo[i].stco, 1, (int) chunkOffset);
}

if (singleChunk) {
tablesInfo[i].stco = -1;
}
}

outRestore();
Expand Down Expand Up @@ -451,12 +473,12 @@ private void outRestore() throws IOException {

// <editor-fold defaultstate="expanded" desc="Utils">
private void outWrite(byte[] buffer) throws IOException {
outWrite(buffer, 0, buffer.length);
outWrite(buffer, buffer.length);
}

private void outWrite(byte[] buffer, int offset, int count) throws IOException {
private void outWrite(byte[] buffer, int count) throws IOException {
writeOffset += count;
outStream.write(buffer, offset, count);
outStream.write(buffer, 0, count);
}

private void outSeek(long offset) throws IOException {
Expand Down Expand Up @@ -509,7 +531,6 @@ private int make(int type, int extra, int columns, int rows) throws IOException
);

if (extra >= 0) {
//size += 4;// commented for auxiliar buffer !!!
offset += 4;
auxWrite(extra);
}
Expand All @@ -531,7 +552,7 @@ private void auxWrite(byte[] buffer) throws IOException {
if (moovSimulation) {
writeOffset += buffer.length;
} else if (auxBuffer == null) {
outWrite(buffer, 0, buffer.length);
outWrite(buffer, buffer.length);
} else {
auxBuffer.put(buffer);
}
Expand Down Expand Up @@ -703,7 +724,7 @@ private void make_trak(int index, long duration, int defaultMediaTime, TablesInf
int mediaTime;

if (tracks[index].trak.edst_elst == null) {
// is a audio track ¿is edst/elst opcional for audio tracks?
// is a audio track ¿is edst/elst optional for audio tracks?
mediaTime = 0x00;// ffmpeg set this value as zero, instead of defaultMediaTime
bMediaRate = 0x00010000;
} else {
Expand Down Expand Up @@ -798,13 +819,13 @@ private byte[] make_hdlr(Hdlr hdlr) {

class TablesInfo {

public int stts;
public int stsc;
public int[] stsc_bEntries;
public int ctts;
public int stsz;
public int stsz_default;
public int stss;
public int stco;
int stts;
int stsc;
int[] stsc_bEntries;
int ctts;
int stsz;
int stsz_default;
int stss;
int stco;
}
}
Loading