General parser for Ogg files where we don't know what the specific kind is. We provide a detector which should help specialise the more common kinds of Ogg files, based on their streams, to their appropriate types. This just handles the rest, as best we can.
| 46 | * appropriate types. This just handles the rest, as best we can. |
| 47 | */ |
| 48 | public class OggParser extends AbstractParser { |
| 49 | private static final long serialVersionUID = -5686095376587813226L; |
| 50 | |
| 51 | protected static final MediaType OGG_GENERAL = OggDetector.OGG_GENERAL; |
| 52 | protected static final MediaType OGG_AUDIO = OggDetector.OGG_AUDIO; |
| 53 | protected static final MediaType OGG_VIDEO = OggDetector.OGG_VIDEO; |
| 54 | |
| 55 | protected static final MediaType KATE = |
| 56 | MediaType.parse(OggStreamIdentifier.KATE.mimetype); |
| 57 | |
| 58 | protected static final MediaType DAALA_VIDEO = |
| 59 | MediaType.parse(OggStreamIdentifier.DAALA_VIDEO.mimetype); |
| 60 | protected static final MediaType DIRAC_VIDEO = |
| 61 | MediaType.parse(OggStreamIdentifier.DIRAC_VIDEO.mimetype); |
| 62 | protected static final MediaType OGM_VIDEO = |
| 63 | MediaType.parse(OggStreamIdentifier.OGM_VIDEO.mimetype); |
| 64 | protected static final MediaType OGG_UVS = |
| 65 | MediaType.parse(OggStreamIdentifier.OGG_UVS.mimetype); |
| 66 | protected static final MediaType OGG_YUV = |
| 67 | MediaType.parse(OggStreamIdentifier.OGG_YUV.mimetype); |
| 68 | protected static final MediaType OGG_RGB = |
| 69 | MediaType.parse(OggStreamIdentifier.OGG_RGB.mimetype); |
| 70 | protected static final MediaType OGG_PCM = |
| 71 | MediaType.parse(OggStreamIdentifier.OGG_PCM.mimetype); |
| 72 | |
| 73 | private static List<MediaType> TYPES = Arrays.asList(new MediaType[] { |
| 74 | // General ones, which didn't fit a specific pattern (eg 2*Opus+2*Vorbis, |
| 75 | // Unknown audio codec, unknown video codec etc). We can't do much |
| 76 | // for these |
| 77 | OGG_GENERAL, OGG_AUDIO, OGG_VIDEO, |
| 78 | // Ones we lack a proper parser for, but may be able to support |
| 79 | // better in the future with a dedicated parser |
| 80 | DAALA_VIDEO, DIRAC_VIDEO, OGM_VIDEO, |
| 81 | OGG_UVS, OGG_YUV, OGG_RGB, OGG_PCM, |
| 82 | KATE |
| 83 | }); |
| 84 | |
| 85 | public Set<MediaType> getSupportedTypes(ParseContext context) { |
| 86 | return new HashSet<MediaType>(TYPES); |
| 87 | } |
| 88 | |
| 89 | public void parse( |
| 90 | InputStream stream, ContentHandler handler, |
| 91 | Metadata metadata, ParseContext context) |
| 92 | throws IOException, TikaException, SAXException { |
| 93 | // Process the file straight through once |
| 94 | OggFile ogg = new OggFile(stream); |
| 95 | |
| 96 | // To track the streams we find |
| 97 | Map<OggStreamType, Integer> streams = |
| 98 | new HashMap<OggStreamType, Integer>(); |
| 99 | Map<OggStreamType.Kind, Integer> streamKinds = |
| 100 | new HashMap<OggStreamType.Kind, Integer>(); |
| 101 | List<Integer> sids = new ArrayList<Integer>(); |
| 102 | int totalStreams = 0; |
| 103 | |
| 104 | // Start |
| 105 | XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); |