Add stream source "Origin"
This commit is contained in:
parent
a4d517aa25
commit
3c86310edf
|
@ -0,0 +1,13 @@
|
||||||
|
package ctbrec;
|
||||||
|
|
||||||
|
public class NotImplementedExcetion extends RuntimeException {
|
||||||
|
|
||||||
|
public NotImplementedExcetion() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotImplementedExcetion(String mesg) {
|
||||||
|
super(mesg);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package ctbrec.recorder.download;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
|
||||||
public class StreamSource implements Comparable<StreamSource> {
|
public class StreamSource implements Comparable<StreamSource> {
|
||||||
|
public static final int ORIGIN = Integer.MAX_VALUE - 1;
|
||||||
public int bandwidth;
|
public int bandwidth;
|
||||||
public int width;
|
public int width;
|
||||||
public int height;
|
public int height;
|
||||||
|
@ -46,6 +47,8 @@ public class StreamSource implements Comparable<StreamSource> {
|
||||||
float mbit = bandwidth / 1024.0f / 1024.0f;
|
float mbit = bandwidth / 1024.0f / 1024.0f;
|
||||||
if (height == Integer.MAX_VALUE) {
|
if (height == Integer.MAX_VALUE) {
|
||||||
return "unknown resolution (" + df.format(mbit) + " Mbit/s)";
|
return "unknown resolution (" + df.format(mbit) + " Mbit/s)";
|
||||||
|
} else if (height == ORIGIN) {
|
||||||
|
return "Origin";
|
||||||
} else {
|
} else {
|
||||||
return height + "p (" + df.format(mbit) + " Mbit/s)";
|
return height + "p (" + df.format(mbit) + " Mbit/s)";
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import com.squareup.moshi.JsonWriter;
|
||||||
|
|
||||||
import ctbrec.AbstractModel;
|
import ctbrec.AbstractModel;
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
|
import ctbrec.NotImplementedExcetion;
|
||||||
import ctbrec.io.HttpException;
|
import ctbrec.io.HttpException;
|
||||||
import ctbrec.recorder.download.StreamSource;
|
import ctbrec.recorder.download.StreamSource;
|
||||||
import okhttp3.MediaType;
|
import okhttp3.MediaType;
|
||||||
|
@ -31,6 +32,8 @@ import okhttp3.Response;
|
||||||
|
|
||||||
public class StreamateModel extends AbstractModel {
|
public class StreamateModel extends AbstractModel {
|
||||||
|
|
||||||
|
private static final String ORIGIN = "origin";
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(StreamateModel.class);
|
private static final Logger LOG = LoggerFactory.getLogger(StreamateModel.class);
|
||||||
|
|
||||||
private boolean online = false;
|
private boolean online = false;
|
||||||
|
@ -107,17 +110,18 @@ public class StreamateModel extends AbstractModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add raw source stream
|
// add raw source stream
|
||||||
if(formats.has("mp4-ws")) {
|
if (hls.has(ORIGIN)) {
|
||||||
JSONObject ws = formats.getJSONObject("mp4-ws");
|
JSONObject origin = hls.getJSONObject(ORIGIN);
|
||||||
JSONObject origin = hls.getJSONObject("origin");
|
|
||||||
StreamSource src = new StreamSource();
|
StreamSource src = new StreamSource();
|
||||||
src.mediaPlaylistUrl = origin.getString("location");
|
src.mediaPlaylistUrl = origin.getString("location");
|
||||||
origin = ws.getJSONObject("origin"); // switch to web socket origin, because it has width, height and bitrates
|
origin = hls.getJSONObject(ORIGIN);
|
||||||
src.width = origin.optInt("videoWidth");
|
src.width = origin.optInt("videoWidth");
|
||||||
src.height = origin.optInt("videoHeight");
|
src.height = origin.optInt("videoHeight");
|
||||||
src.bandwidth = (origin.optInt("videoKbps") + origin.optInt("audioKbps")) * 1024;
|
src.bandwidth = (origin.optInt("videoKbps") + origin.optInt("audioKbps")) * 1024;
|
||||||
|
src.height = StreamSource.ORIGIN;
|
||||||
streamSources.add(src);
|
streamSources.add(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new HttpException(response.code(), response.message());
|
throw new HttpException(response.code(), response.message());
|
||||||
}
|
}
|
||||||
|
@ -159,9 +163,12 @@ public class StreamateModel extends AbstractModel {
|
||||||
if(!isOnline()) {
|
if(!isOnline()) {
|
||||||
return new int[2];
|
return new int[2];
|
||||||
}
|
}
|
||||||
List<StreamSource> streamSources = getStreamSources();
|
List<StreamSource> sources = getStreamSources();
|
||||||
Collections.sort(streamSources);
|
Collections.sort(sources);
|
||||||
StreamSource best = streamSources.get(streamSources.size()-1);
|
StreamSource best = sources.get(sources.size() - 1);
|
||||||
|
if (best.height == StreamSource.ORIGIN) {
|
||||||
|
best = sources.get(sources.size() - 2);
|
||||||
|
}
|
||||||
resolution = new int[] { best.width, best.height };
|
resolution = new int[] { best.width, best.height };
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
LOG.warn("Couldn't determine stream resolution for {} - {}", getName(), e.getMessage());
|
LOG.warn("Couldn't determine stream resolution for {} - {}", getName(), e.getMessage());
|
||||||
|
@ -229,7 +236,6 @@ public class StreamateModel extends AbstractModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readSiteSpecificData(JsonReader reader) throws IOException {
|
public void readSiteSpecificData(JsonReader reader) throws IOException {
|
||||||
|
|
||||||
reader.nextName();
|
reader.nextName();
|
||||||
id = reader.nextLong();
|
id = reader.nextLong();
|
||||||
}
|
}
|
||||||
|
@ -248,7 +254,6 @@ public class StreamateModel extends AbstractModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receiveTip(Double tokens) throws IOException {
|
public void receiveTip(Double tokens) throws IOException {
|
||||||
// TODO Auto-generated method stub
|
throw new NotImplementedExcetion("Tipping is not implemented for Streamate");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue