use of org.jaudiotagger.audio.asf.data.MetadataContainer in project MusicDNA by harjot-oberai.
the class AsfFileWriter method writeTag.
/**
* {@inheritDoc}
*/
@Override
protected void writeTag(final Tag tag, final RandomAccessFile raf, final RandomAccessFile rafTemp) throws CannotWriteException, IOException {
/*
* Since this implementation should not change the structure of the ASF
* file (locations of content description chunks), we need to read the
* content description chunk and the extended content description chunk
* from the source file. In the second step we need to determine which
* modifier (asf header or asf extended header) gets the appropriate
* modifiers. The following policies are applied: if the source does not
* contain any descriptor, the necessary descriptors are appended to the
* header object.
*
* if the source contains only one descriptor in the header extension
* object, and the other type is needed as well, the other one will be
* put into the header extension object.
*
* for each descriptor type, if an object is found, an updater will be
* configured.
*/
final AsfHeader sourceHeader = AsfHeaderReader.readTagHeader(raf);
// Reset for the streamer
raf.seek(0);
/*
* Now createField modifiers for metadata descriptor and extended content
* descriptor as implied by the given Tag.
*/
// TODO not convinced that we need to copy fields here
final AsfTag copy = new AsfTag(tag, true);
final MetadataContainer[] distribution = TagConverter.distributeMetadata(copy);
final boolean[] existHeader = searchExistence(sourceHeader, distribution);
final boolean[] existExtHeader = searchExistence(sourceHeader.getExtendedHeader(), distribution);
// Modifiers for the asf header object
final List<ChunkModifier> headerModifier = new ArrayList<ChunkModifier>();
// Modifiers for the asf header extension object
final List<ChunkModifier> extHeaderModifier = new ArrayList<ChunkModifier>();
for (int i = 0; i < distribution.length; i++) {
final WriteableChunkModifer modifier = new WriteableChunkModifer(distribution[i]);
if (existHeader[i]) {
// Will remove or modify chunks in ASF header
headerModifier.add(modifier);
} else if (existExtHeader[i]) {
// Will remove or modify chunks in extended header
extHeaderModifier.add(modifier);
} else {
// Objects (chunks) will be added here.
if (i == 0 || i == 2 || i == 1) {
// Add content description and extended content description
// at header for maximum compatibility
headerModifier.add(modifier);
} else {
// For now, the rest should be created at extended header
// since other positions aren'timer known.
extHeaderModifier.add(modifier);
}
}
}
// change (performance)
if (!extHeaderModifier.isEmpty()) {
headerModifier.add(new AsfExtHeaderModifier(extHeaderModifier));
}
new AsfStreamer().createModifiedCopy(new RandomAccessFileInputstream(raf), new RandomAccessFileOutputStream(rafTemp), headerModifier);
}
use of org.jaudiotagger.audio.asf.data.MetadataContainer in project MusicDNA by harjot-oberai.
the class AsfFileReader method determineVariableBitrate.
/**
* Determines if the "isVbr" field is set in the extended content
* description.<br>
*
* @param header
* the header to look up.
* @return <code>true</code> if "isVbr" is present with a
* <code>true</code> value.
*/
private boolean determineVariableBitrate(final AsfHeader header) {
assert header != null;
boolean result = false;
final MetadataContainer extDesc = header.findExtendedContentDescription();
if (extDesc != null) {
final List<MetadataDescriptor> descriptors = extDesc.getDescriptorsByName("IsVBR");
if (descriptors != null && !descriptors.isEmpty()) {
result = Boolean.TRUE.toString().equals(descriptors.get(0).getString());
}
}
return result;
}
Aggregations