mirror of
https://github.com/androidx/media.git
synced 2025-05-05 06:30:24 +08:00
Fix Avc Seek
This commit is contained in:
parent
4c76bf1a9d
commit
5ebaafde6e
@ -21,7 +21,7 @@ public class AvcAviTrack extends AviTrack{
|
|||||||
private NalUnitUtil.SpsData spsData;
|
private NalUnitUtil.SpsData spsData;
|
||||||
//The frame as a calculated from the picCount
|
//The frame as a calculated from the picCount
|
||||||
private int picFrame;
|
private int picFrame;
|
||||||
private int lastPicFrame;
|
private int lastPicCount;
|
||||||
//Largest picFrame, used when we hit an I frame
|
//Largest picFrame, used when we hit an I frame
|
||||||
private int maxPicFrame =-1;
|
private int maxPicFrame =-1;
|
||||||
private int maxPicCount;
|
private int maxPicCount;
|
||||||
@ -56,7 +56,7 @@ public class AvcAviTrack extends AviTrack{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void processIdr() {
|
private void processIdr() {
|
||||||
lastPicFrame = 0;
|
lastPicCount = 0;
|
||||||
picFrame = maxPicFrame + 1;
|
picFrame = maxPicFrame + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,6 +97,13 @@ public class AvcAviTrack extends AviTrack{
|
|||||||
return picFrame;
|
return picFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void seekFrame(int frame) {
|
||||||
|
super.seekFrame(frame);
|
||||||
|
this.picFrame = frame;
|
||||||
|
lastPicCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
int getPicOrderCountLsb(byte[] peek) {
|
int getPicOrderCountLsb(byte[] peek) {
|
||||||
if (peek[3] != 1) {
|
if (peek[3] != 1) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -136,15 +143,15 @@ public class AvcAviTrack extends AviTrack{
|
|||||||
case 2:
|
case 2:
|
||||||
case 3:
|
case 3:
|
||||||
case 4: {
|
case 4: {
|
||||||
final int myPicCount = getPicOrderCountLsb(peek);
|
final int picCount = getPicOrderCountLsb(peek);
|
||||||
int delta = myPicCount - lastPicFrame;
|
int delta = picCount - lastPicCount;
|
||||||
if (delta < negHalf) {
|
if (delta < negHalf) {
|
||||||
delta += maxPicCount;
|
delta += maxPicCount;
|
||||||
} else if (delta > posHalf) {
|
} else if (delta > posHalf) {
|
||||||
delta -= maxPicCount;
|
delta -= maxPicCount;
|
||||||
}
|
}
|
||||||
picFrame += delta / 2;
|
picFrame += delta / 2;
|
||||||
lastPicFrame = myPicCount;
|
lastPicCount = picCount;
|
||||||
if (maxPicFrame < picFrame) {
|
if (maxPicFrame < picFrame) {
|
||||||
maxPicFrame = picFrame;
|
maxPicFrame = picFrame;
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ public class AviSeekMap implements SeekMap {
|
|||||||
|
|
||||||
public void setFrames(final long position, final long timeUs, final SparseArray<AviTrack> idTrackMap) {
|
public void setFrames(final long position, final long timeUs, final SparseArray<AviTrack> idTrackMap) {
|
||||||
final int seekFrameIndex = getSeekFrameIndex(timeUs);
|
final int seekFrameIndex = getSeekFrameIndex(timeUs);
|
||||||
videoTrack.frame = seekFrameIndex * seekIndexFactor;
|
videoTrack.seekFrame(seekFrameIndex * seekIndexFactor);
|
||||||
for (int i=0;i<audioIdMap.size();i++) {
|
for (int i=0;i<audioIdMap.size();i++) {
|
||||||
final int audioId = audioIdMap.keyAt(i);
|
final int audioId = audioIdMap.keyAt(i);
|
||||||
final int[] video2AudioFrameMap = audioIdMap.get(audioId);
|
final int[] video2AudioFrameMap = audioIdMap.get(audioId);
|
||||||
|
@ -95,6 +95,10 @@ public class AviTrack {
|
|||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void seekFrame(int frame) {
|
||||||
|
this.frame = frame;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean newChunk(int tag, int size, ExtractorInput input) throws IOException {
|
public boolean newChunk(int tag, int size, ExtractorInput input) throws IOException {
|
||||||
final int remaining = size - trackOutput.sampleData(input, size, false);
|
final int remaining = size - trackOutput.sampleData(input, size, false);
|
||||||
if (remaining == 0) {
|
if (remaining == 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user