| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
package com.drew.metadata.mp4.media; |
| 22 |
|
| 23 |
import com.drew.lang.SequentialReader; |
| 24 |
import com.drew.lang.annotations.NotNull; |
| 25 |
import com.drew.metadata.Metadata; |
| 26 |
import com.drew.metadata.mp4.Mp4BoxTypes; |
| 27 |
import com.drew.metadata.mp4.Mp4Context; |
| 28 |
import com.drew.metadata.mp4.Mp4Dictionary; |
| 29 |
import com.drew.metadata.mp4.Mp4MediaHandler; |
| 30 |
|
| 31 |
import java.io.IOException; |
| 32 |
|
| 33 |
public class Mp4SoundHandler extends Mp4MediaHandler<Mp4SoundDirectory> |
| 34 |
{ |
| 35 |
public Mp4SoundHandler(Metadata metadata, Mp4Context context) |
| 36 |
{ |
| 37 |
super(metadata, context); |
| 38 |
} |
| 39 |
|
| 40 |
@NotNull |
| 41 |
@Override |
| 42 |
protected Mp4SoundDirectory getDirectory() |
| 43 |
{ |
| 44 |
return new Mp4SoundDirectory(); |
| 45 |
} |
| 46 |
|
| 47 |
@Override |
| 48 |
protected String getMediaInformation() |
| 49 |
{ |
| 50 |
return Mp4BoxTypes.BOX_SOUND_MEDIA_INFO; |
| 51 |
} |
| 52 |
|
| 53 |
@Override |
| 54 |
public void processSampleDescription(@NotNull SequentialReader reader) throws IOException |
| 55 |
{ |
| 56 |
|
| 57 |
|
| 58 |
reader.skip(4); |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
long numberOfEntries = reader.getUInt32(); |
| 63 |
long sampleDescriptionSize = reader.getUInt32(); |
| 64 |
String format = reader.getString(4); |
| 65 |
reader.skip(6); |
| 66 |
int dataReferenceIndex = reader.getUInt16(); |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
reader.skip(8); |
| 71 |
int channelCount = reader.getUInt16(); |
| 72 |
int sampleSize = reader.getInt16(); |
| 73 |
reader.skip(2); |
| 74 |
reader.skip(2); |
| 75 |
long sampleRate = reader.getUInt32(); |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
Mp4Dictionary.setLookup(Mp4SoundDirectory.TAG_AUDIO_FORMAT, format, directory); |
| 82 |
|
| 83 |
directory.setInt(Mp4SoundDirectory.TAG_NUMBER_OF_CHANNELS, channelCount); |
| 84 |
directory.setInt(Mp4SoundDirectory.TAG_AUDIO_SAMPLE_SIZE, sampleSize); |
| 85 |
} |
| 86 |
|
| 87 |
@Override |
| 88 |
public void processMediaInformation(@NotNull SequentialReader reader) throws IOException |
| 89 |
{ |
| 90 |
|
| 91 |
|
| 92 |
reader.skip(4); |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
int balance = reader.getInt16(); |
| 97 |
reader.skip(2); |
| 98 |
|
| 99 |
double integer = balance & 0xFFFF0000; |
| 100 |
double fraction = (balance & 0x0000FFFF) / Math.pow(2, 4); |
| 101 |
directory.setDouble(Mp4SoundDirectory.TAG_SOUND_BALANCE, integer + fraction); |
| 102 |
} |
| 103 |
|
| 104 |
@Override |
| 105 |
protected void processTimeToSample(@NotNull SequentialReader reader, Mp4Context context) throws IOException |
| 106 |
{ |
| 107 |
|
| 108 |
|
| 109 |
reader.skip(4); |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
long entryCount = reader.getUInt32(); |
| 114 |
|
| 115 |
|
| 116 |
reader.skip(entryCount * 8); |
| 117 |
|
| 118 |
if (context.timeScale != null) { |
| 119 |
directory.setDouble(Mp4SoundDirectory.TAG_AUDIO_SAMPLE_RATE, context.timeScale); |
| 120 |
} |
| 121 |
} |
| 122 |
} |