Replacing SoundStreamHeads with MP3

This commit is contained in:
Jindra Petřík
2022-12-27 19:25:01 +01:00
parent cc71ba8cef
commit a940ea1c6f
9 changed files with 333 additions and 17 deletions
@@ -146,7 +146,24 @@ public final class Bitstream implements BitstreamErrors {
closeFrame();
}
//JPEXS
public Bitstream(MarkingBufferedInputStream in) {
if (in == null)
throw new NullPointerException("in");
loadID3v2(in);
in.setFixed(true);
firstframe = true;
source = new MarkingPushbackInputStream(in, BUFFER_INT_SIZE * 4);
closeFrame();
}
//JPEXS
public MarkingPushbackInputStream getSource() {
return (MarkingPushbackInputStream) source;
}
/**
* Return position of the first audio header.
*
@@ -0,0 +1,99 @@
package javazoom.jl.decoder;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
*
* @author JPEXS
*/
public class MarkingBufferedInputStream extends BufferedInputStream {
private BufferedInputStream is;
private long pos = 0;
private long markedPos = -1;
private boolean fixed = false;
public long getPosition() {
return pos;
}
public void setFixed(boolean fixed) {
this.fixed = fixed;
}
public MarkingBufferedInputStream(InputStream in) {
super(in);
this.is = new BufferedInputStream(in);
}
@Override
public synchronized int read() throws IOException {
if (!fixed) pos++;
return is.read();
}
@Override
public int read(byte[] b) throws IOException {
int ret = is.read(b);
if (!fixed) pos += ret;
return ret;
}
@Override
public synchronized int read(byte[] b, int off, int len) throws IOException {
int ret = is.read(b, off, len);
if (!fixed) pos += ret;
return ret;
}
@Override
public synchronized void reset() throws IOException {
if (markedPos > -1) {
if (!fixed) pos = markedPos;
markedPos = -1;
}
is.reset();
}
@Override
public synchronized void mark(int readlimit) {
markedPos = pos;
is.mark(readlimit);
}
@Override
public synchronized int available() throws IOException {
return is.available();
}
@Override
public synchronized long skip(long n) throws IOException {
long ret = is.skip(n);
if (!fixed) pos+=ret;
return ret;
}
@Override
public void skipNBytes(long n) throws IOException {
if (!fixed) pos+=n;
is.skipNBytes(n);
}
@Override
public void close() throws IOException {
is.close();
}
@Override
public boolean markSupported() {
return is.markSupported();
}
}
@@ -0,0 +1,104 @@
package javazoom.jl.decoder;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
/**
*
* @author JPEXS
*/
public class MarkingPushbackInputStream extends PushbackInputStream {
private PushbackInputStream is;
private long pos = 0;
public long getPosition() {
return pos;
}
public MarkingPushbackInputStream(InputStream in, int size) {
super(in, size);
is = new PushbackInputStream(in, size);
}
@Override
public int available() throws IOException {
return is.available();
}
@Override
public synchronized void close() throws IOException {
is.close();
}
@Override
public synchronized void mark(int readlimit) {
is.mark(readlimit);
}
@Override
public boolean markSupported() {
return is.markSupported();
}
@Override
public int read() throws IOException {
pos++;
return is.read();
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
int ret = is.read(b, off, len);
pos += ret;
return ret;
}
@Override
public int read(byte[] b) throws IOException {
int ret = is.read(b);
pos += ret;
return ret;
}
@Override
public synchronized void reset() throws IOException {
is.reset();
}
@Override
public void unread(byte[] b) throws IOException {
pos -= b.length;
is.unread(b);
}
@Override
public void unread(int b) throws IOException {
pos--;
is.unread(b);
}
@Override
public void unread(byte[] b, int off, int len) throws IOException {
pos -= len;
is.unread(b, off, len);
}
@Override
public long skip(long n) throws IOException {
long ret = is.skip(n);
pos += ret;
return ret;
}
@Override
public void skipNBytes(long n) throws IOException {
pos += n;
is.skipNBytes(n);
}
}