Skip to content

Commit

Permalink
the fix for #34 made the h264 track correctly set the profile compati…
Browse files Browse the repository at this point in the history
…bility flag and therefor the H264TrackImplTest didn't work
  • Loading branch information
sannies committed Dec 21, 2014
1 parent 5636d7c commit e6dca02
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ private void parse(LookAhead la) throws IOException {

AvcConfigurationBox avcConfigurationBox = new AvcConfigurationBox();

avcConfigurationBox.setSequenceParameterSets(new ArrayList<byte[]>(seqParameterRangeMap.values()));
avcConfigurationBox.setPictureParameterSets(new ArrayList<byte[]>(pictureParameterRangeMap.values()));
avcConfigurationBox.setSequenceParameterSets(new ArrayList<byte[]>(spsIdToSpsBytes.values()));
avcConfigurationBox.setPictureParameterSets(new ArrayList<byte[]>(ppsIdToPpsBytes.values()));
avcConfigurationBox.setAvcLevelIndication(firstSeqParameterSet.level_idc);
avcConfigurationBox.setAvcProfileIndication(firstSeqParameterSet.profile_idc);
avcConfigurationBox.setBitDepthLumaMinus8(firstSeqParameterSet.bit_depth_luma_minus8);
Expand Down Expand Up @@ -320,10 +320,6 @@ private ByteBuffer findNextNal(LookAhead la) throws IOException {

}

private enum NALActions {
IGNORE, BUFFER, STORE, END
}

/**
* Builds an MP4 sample from a list of NALs. Each NAL will be preceded by its
* 4 byte (unit32) length.
Expand Down Expand Up @@ -444,7 +440,6 @@ boolean isFirstInNew(FirstVclNalDetector nu) {
int nal_unit_type = type & 0x1f;


NALActions action;

switch (nal_unit_type) {
case 1:
Expand Down Expand Up @@ -476,28 +471,28 @@ boolean isFirstInNew(FirstVclNalDetector nu) {
break;

case 9:
if (buffered.size() > 0) {
System.err.println("Wrapping up cause of AU after vcl marks new sample");
if (fvnd != null) {
//System.err.println("Wrapping up cause of AU after vcl marks new sample");
createSample(buffered);
fvnd = null;
}
buffered.add(nal);
break;
case 7:
if (buffered.size() > 0) {
if (fvnd != null) {
//System.err.println("Wrapping up cause of SPS after vcl marks new sample");
createSample(buffered);
fvnd = null;
}
handleSPS(nal);
handleSPS((ByteBuffer) nal.rewind());
break;
case 8:
if (buffered.size() > 0) {
if (fvnd != null) {
//System.err.println("Wrapping up cause of PPS after vcl marks new sample");
createSample(buffered);
fvnd = null;
}
handlePPS(nal);
handlePPS((ByteBuffer) nal.rewind());
break;
case 10:
case 11:
Expand Down Expand Up @@ -544,9 +539,6 @@ private void createSample(List<ByteBuffer> buffered) throws IOException {
// LOG.fine("Adding sample with size " + bb.capacity() + " and header " + sh);
buffered.clear();

if (IdrPicFlag) { // IDR Picture
stss.add(samples.size());
}
if (seiMessage == null || seiMessage.n_frames == 0) {
frameNrInGop = 0;
}
Expand All @@ -559,7 +551,12 @@ private void createSample(List<ByteBuffer> buffered) throws IOException {
ctts.add(new CompositionTimeToSample.Entry(1, offset * frametick));
sdtp.add(new SampleDependencyTypeBox.Entry(stdpValue));
frameNrInGop++;

samples.add(bb);
if (IdrPicFlag) { // IDR Picture
stss.add(samples.size());
}

}


Expand Down Expand Up @@ -591,18 +588,18 @@ private void handlePPS(ByteBuffer data) throws IOException {
byte[] oldPpsSameId = ppsIdToPpsBytes.get(_pictureParameterSet.pic_parameter_set_id);

String ppsHex = Hex.encodeHex(ppsBytes);
System.err.println(ppsHex);
if (oldPpsSameId != null && !Arrays.equals(oldPpsSameId, ppsBytes)) {
throw new RuntimeException("OMG - I got two SPS with same ID but different settings! (AVC3 is the solution)");
} else {
if (oldPpsSameId == null) {
seqParameterRangeMap.put(samples.size(), ppsBytes);
pictureParameterRangeMap.put(samples.size(), ppsBytes);
}
ppsIdToPpsBytes.put(_pictureParameterSet.pic_parameter_set_id, ppsBytes);
ppsIdToPps.put(_pictureParameterSet.pic_parameter_set_id, _pictureParameterSet);
}


pictureParameterRangeMap.put(samples.size(), toArray((ByteBuffer) data.rewind()));
}

private void handleSPS(ByteBuffer data) throws IOException {
Expand All @@ -616,6 +613,7 @@ private void handleSPS(ByteBuffer data) throws IOException {

byte[] spsBytes = toArray((ByteBuffer) data.rewind());
String spsHex = Hex.encodeHex(spsBytes);
System.err.println(spsHex);
byte[] oldSpsSameId = spsIdToSpsBytes.get(_seqParameterSet.seq_parameter_set_id);
if (oldSpsSameId != null && !Arrays.equals(oldSpsSameId, spsBytes)) {
throw new RuntimeException("OMG - I got two SPS with same ID but different settings!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ public AvcDecoderConfigurationRecord getavcDecoderConfigurationRecord() {
return avcDecoderConfigurationRecord;
}


@Override
public String toString() {
return "AvcConfigurationBox{" +
"avcDecoderConfigurationRecord=" + avcDecoderConfigurationRecord +
'}';
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,23 @@ public List<String> getPictureParameterSetsAsStrings() {
return result;
}

@Override
public String toString() {
return "AvcDecoderConfigurationRecord{" +
"configurationVersion=" + configurationVersion +
", avcProfileIndication=" + avcProfileIndication +
", profileCompatibility=" + profileCompatibility +
", avcLevelIndication=" + avcLevelIndication +
", lengthSizeMinusOne=" + lengthSizeMinusOne +
", hasExts=" + hasExts +
", chromaFormat=" + chromaFormat +
", bitDepthLumaMinus8=" + bitDepthLumaMinus8 +
", bitDepthChromaMinus8=" + bitDepthChromaMinus8 +
", lengthSizeMinusOnePaddingBits=" + lengthSizeMinusOnePaddingBits +
", numberOfSequenceParameterSetsPaddingBits=" + numberOfSequenceParameterSetsPaddingBits +
", chromaFormatPaddingBits=" + chromaFormatPaddingBits +
", bitDepthLumaMinus8PaddingBits=" + bitDepthLumaMinus8PaddingBits +
", bitDepthChromaMinus8PaddingBits=" + bitDepthChromaMinus8PaddingBits +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public void freeze() throws IOException {
DefaultMp4Builder mp4Builder = new DefaultMp4Builder();
Container isoFile = mp4Builder.build(m);

//WritableByteChannel fcOut = new FileOutputStream("h264-sample.mp4").getChannel();
//isoFile.writeContainer(fcOut);
//fcOut.close();
WritableByteChannel fcOut = new FileOutputStream("h264-sample.mp4").getChannel();
isoFile.writeContainer(fcOut);
fcOut.close();


IsoFile isoFileReference = new IsoFile(getClass().getProtectionDomain().getCodeSource().getLocation().getFile() + "com/googlecode/mp4parser/authoring/tracks/h264-sample.mp4");
Expand Down
Binary file not shown.

0 comments on commit e6dca02

Please sign in to comment.