/// <summary> /// Loads AudioSampleEntry atom from the input bitstream. /// </summary> /// <param name="bitstream">The input bitstream.</param> /// <returns>The number of bytes loaded.</returns> public long create_audio_sample_entry_atom(Mp4DataStream bitstream) { //qtff page 117 #if !SILVERLIGHT log.Debug("Audio sample entry"); #endif bitstream.SkipBytes(6); int dataReferenceIndex = (int)bitstream.ReadBytes(2); bitstream.SkipBytes(8); channelCount = (int)bitstream.ReadBytes(2); #if !SILVERLIGHT log.Debug(string.Format("Channels: {0}", channelCount)); #endif sampleSize = (int)bitstream.ReadBytes(2); #if !SILVERLIGHT log.Debug(string.Format("Sample size (bits): {0}", sampleSize)); #endif bitstream.SkipBytes(4); timeScale = (int)bitstream.ReadBytes(2); #if !SILVERLIGHT log.Debug(string.Format("Time scale: {0}", timeScale)); #endif bitstream.SkipBytes(2); _bytesRead += 28; Mp4Atom child = Mp4Atom.CreateAtom(bitstream); _children.Add(child); _bytesRead += child.Size; return(_bytesRead); }
/// <summary> /// Loads the composite atom from the input bitstream. /// </summary> /// <param name="bitstream">The input bitstream.</param> /// <returns>The number of bytes loaded.</returns> public long create_composite_atom(Mp4DataStream bitstream) { while (_bytesRead < _size) { Mp4Atom child = Mp4Atom.CreateAtom(bitstream); _children.Add(child); _bytesRead += child.Size; } return(_bytesRead); }
/// <summary> /// Loads MP4VideoSampleEntryAtom atom from the input bitstream. /// </summary> /// <param name="bitstream">The input bitstream.</param> /// <returns>The number of bytes loaded.</returns> public long create_video_sample_entry_atom(Mp4DataStream bitstream) { #if !SILVERLIGHT log.Debug("Video entry atom contains wxh"); #endif bitstream.SkipBytes(6); int dataReferenceIndex = (int)bitstream.ReadBytes(2); bitstream.SkipBytes(2); bitstream.SkipBytes(2); bitstream.SkipBytes(12); width = (int)bitstream.ReadBytes(2); #if !SILVERLIGHT log.Debug(string.Format("Width: {0}", width)); #endif height = (int)bitstream.ReadBytes(2); #if !SILVERLIGHT log.Debug(string.Format("Height: {0}", height)); #endif int horizontalRez = (int)bitstream.ReadBytes(4) >> 16; #if !SILVERLIGHT log.Debug(string.Format("H Resolution: {0}", horizontalRez)); #endif int verticalRez = (int)bitstream.ReadBytes(4) >> 16; #if !SILVERLIGHT log.Debug(string.Format("V Resolution: {0}", verticalRez)); #endif bitstream.SkipBytes(4); int frameCount = (int)bitstream.ReadBytes(2); #if !SILVERLIGHT log.Debug(string.Format("Frame to sample count: {0}", frameCount)); #endif int stringLen = (int)bitstream.ReadBytes(1); #if !SILVERLIGHT log.Debug(string.Format("String length (cpname): {0}", stringLen)); #endif String compressorName = bitstream.ReadString(31); #if !SILVERLIGHT log.Debug(string.Format("Compressor name: {0}", compressorName.Trim())); #endif int depth = (int)bitstream.ReadBytes(2); #if !SILVERLIGHT log.Debug(string.Format("Depth: {0}", depth)); #endif bitstream.SkipBytes(2); _bytesRead += 78; #if !SILVERLIGHT log.Debug(string.Format("Bytes read: {0}", _bytesRead)); #endif Mp4Atom child = Mp4Atom.CreateAtom(bitstream); _children.Add(child); _bytesRead += child.Size; return(_bytesRead); }
/// <summary> /// Loads SampleDescription atom from the input bitstream. /// </summary> /// <param name="bitstream">The input bitstream.</param> /// <returns>The number of bytes loaded.</returns> public long create_sample_description_atom(Mp4DataStream bitstream) { create_full_atom(bitstream); entryCount = (int)bitstream.ReadBytes(4); #if !SILVERLIGHT log.Debug(string.Format("stsd entry count: {0}", entryCount)); #endif _bytesRead += 4; for (int i = 0; i < entryCount; i++) { Mp4Atom child = Mp4Atom.CreateAtom(bitstream); _children.Add(child); _bytesRead += child.Size; } return(_bytesRead); }
/// <summary> /// Creates the PASP atom or Pixel Aspect Ratio. It is created by Quicktime /// when exporting an MP4 file. The atom is required for ipod's and acts as /// a container for the avcC atom in these cases. /// </summary> /// <param name="bitstream">The input bitstream.</param> /// <returns>The number of bytes loaded.</returns> public long create_pasp_atom(Mp4DataStream bitstream) { #if !SILVERLIGHT log.Debug("Pixel aspect ratio"); #endif int hSpacing = (int)bitstream.ReadBytes(4); int vSpacing = (int)bitstream.ReadBytes(4); #if !SILVERLIGHT log.Debug(string.Format("hSpacing: {0} vSpacing: {1}", hSpacing, vSpacing)); #endif _bytesRead += 8; Mp4Atom child = Mp4Atom.CreateAtom(bitstream); _children.Add(child); _bytesRead += child.Size; return(_bytesRead); }
/// <summary> /// Looks up a child atom with the specified type, skips the <code>number</code> children with the same type before finding a result. /// </summary> /// <param name="type">The type of the atom.</param> /// <param name="number">The number of atoms to skip.</param> /// <returns>The atom if found othwerwise null.</returns> public Mp4Atom Lookup(long type, int number) { int position = 0; for (int i = 0; i < _children.Count; i++) { Mp4Atom atom = _children[i]; if (atom.Type == type) { if (position >= number) { return(atom); } position++; } } return(null); }
/// <summary> /// Loads MP4VisualSampleEntryAtom atom from the input bitstream. /// </summary> /// <param name="bitstream">The input bitstream.</param> /// <returns>The number of bytes loaded.</returns> public long create_visual_sample_entry_atom(Mp4DataStream bitstream) { #if !SILVERLIGHT log.Debug("Visual entry atom contains wxh"); #endif bitstream.SkipBytes(24); width = (int)bitstream.ReadBytes(2); #if !SILVERLIGHT log.Debug(string.Format("Width: {0}", width)); #endif height = (int)bitstream.ReadBytes(2); #if !SILVERLIGHT log.Debug(string.Format("Height: {0}", height)); #endif bitstream.SkipBytes(50); _bytesRead += 78; Mp4Atom child = Mp4Atom.CreateAtom(bitstream); _children.Add(child); _bytesRead += child.Size; return(_bytesRead); }
/// <summary> /// Constructs an Atom object from the data in the bitstream. /// </summary> /// <param name="bitstream">The input bitstream.</param> /// <returns>The constructed atom.</returns> public static Mp4Atom CreateAtom(Mp4DataStream bitstream) { String uuid = null; long size = bitstream.ReadBytes(4); if (size == 0) { throw new IOException("Invalid size"); } int type = (int)bitstream.ReadBytes(4); long bytesRead = 8; if (type == MP4ExtendedAtomType) { uuid = bitstream.ReadString(16); bytesRead += 16; } // large size if (size == 1) { size = bitstream.ReadBytes(8); bytesRead += 8; } Mp4Atom atom = new Mp4Atom(size, type, uuid, bytesRead); if ((type == MP4MediaAtomType) || (type == MP4DataInformationAtomType) || (type == MP4MovieAtomType) || (type == MP4MediaInformationAtomType) || (type == MP4SampleTableAtomType) || (type == MP4TrackAtomType)) { bytesRead = atom.create_composite_atom(bitstream); } else if (type == MP4AudioSampleEntryAtomType) { bytesRead = atom.create_audio_sample_entry_atom(bitstream); } else if (type == MP4ChunkLargeOffsetAtomType) { bytesRead = atom.create_chunk_large_offset_atom(bitstream); } else if (type == MP4ChunkOffsetAtomType) { bytesRead = atom.create_chunk_offset_atom(bitstream); } else if (type == MP4HandlerAtomType) { bytesRead = atom.create_handler_atom(bitstream); } else if (type == MP4MediaHeaderAtomType) { bytesRead = atom.create_media_header_atom(bitstream); } else if (type == MP4MovieHeaderAtomType) { bytesRead = atom.create_movie_header_atom(bitstream); } else if (type == MP4SampleDescriptionAtomType) { bytesRead = atom.create_sample_description_atom(bitstream); } else if (type == MP4SampleSizeAtomType) { bytesRead = atom.create_sample_size_atom(bitstream); } else if (type == MP4CompactSampleSizeAtomType) { bytesRead = atom.create_compact_sample_size_atom(bitstream); } else if (type == MP4SampleToChunkAtomType) { bytesRead = atom.create_sample_to_chunk_atom(bitstream); } else if (type == MP4SyncSampleAtomType) { bytesRead = atom.create_sync_sample_atom(bitstream); } else if (type == MP4TimeToSampleAtomType) { bytesRead = atom.create_time_to_sample_atom(bitstream); } else if (type == MP4SoundMediaHeaderAtomType) { bytesRead = atom.create_sound_media_header_atom(bitstream); } else if (type == MP4TrackHeaderAtomType) { bytesRead = atom.create_track_header_atom(bitstream); } else if (type == MP4VideoMediaHeaderAtomType) { bytesRead = atom.create_video_media_header_atom(bitstream); } else if (type == MP4VisualSampleEntryAtomType) { bytesRead = atom.create_visual_sample_entry_atom(bitstream); } else if (type == MP4VideoSampleEntryAtomType) { bytesRead = atom.create_video_sample_entry_atom(bitstream); } else if (type == MP4ESDAtomType) { bytesRead = atom.create_esd_atom(bitstream); } else if (type == MP4AVCAtomType) { bytesRead = atom.create_avc_config_atom(bitstream); } else if (type == MP4PixelAspectAtomType) { bytesRead = atom.create_pasp_atom(bitstream); } #if !SILVERLIGHT log.Debug(string.Format("Atom: type = {0} size = {1}", IntToType(type), size)); #endif bitstream.SkipBytes(size - bytesRead); return atom; }
/// <summary> /// Constructs an Atom object from the data in the bitstream. /// </summary> /// <param name="bitstream">The input bitstream.</param> /// <returns>The constructed atom.</returns> public static Mp4Atom CreateAtom(Mp4DataStream bitstream) { String uuid = null; long size = bitstream.ReadBytes(4); if (size == 0) { throw new IOException("Invalid size"); } int type = (int)bitstream.ReadBytes(4); long bytesRead = 8; if (type == MP4ExtendedAtomType) { uuid = bitstream.ReadString(16); bytesRead += 16; } // large size if (size == 1) { size = bitstream.ReadBytes(8); bytesRead += 8; } Mp4Atom atom = new Mp4Atom(size, type, uuid, bytesRead); if ((type == MP4MediaAtomType) || (type == MP4DataInformationAtomType) || (type == MP4MovieAtomType) || (type == MP4MediaInformationAtomType) || (type == MP4SampleTableAtomType) || (type == MP4TrackAtomType)) { bytesRead = atom.create_composite_atom(bitstream); } else if (type == MP4AudioSampleEntryAtomType) { bytesRead = atom.create_audio_sample_entry_atom(bitstream); } else if (type == MP4ChunkLargeOffsetAtomType) { bytesRead = atom.create_chunk_large_offset_atom(bitstream); } else if (type == MP4ChunkOffsetAtomType) { bytesRead = atom.create_chunk_offset_atom(bitstream); } else if (type == MP4HandlerAtomType) { bytesRead = atom.create_handler_atom(bitstream); } else if (type == MP4MediaHeaderAtomType) { bytesRead = atom.create_media_header_atom(bitstream); } else if (type == MP4MovieHeaderAtomType) { bytesRead = atom.create_movie_header_atom(bitstream); } else if (type == MP4SampleDescriptionAtomType) { bytesRead = atom.create_sample_description_atom(bitstream); } else if (type == MP4SampleSizeAtomType) { bytesRead = atom.create_sample_size_atom(bitstream); } else if (type == MP4CompactSampleSizeAtomType) { bytesRead = atom.create_compact_sample_size_atom(bitstream); } else if (type == MP4SampleToChunkAtomType) { bytesRead = atom.create_sample_to_chunk_atom(bitstream); } else if (type == MP4SyncSampleAtomType) { bytesRead = atom.create_sync_sample_atom(bitstream); } else if (type == MP4TimeToSampleAtomType) { bytesRead = atom.create_time_to_sample_atom(bitstream); } else if (type == MP4SoundMediaHeaderAtomType) { bytesRead = atom.create_sound_media_header_atom(bitstream); } else if (type == MP4TrackHeaderAtomType) { bytesRead = atom.create_track_header_atom(bitstream); } else if (type == MP4VideoMediaHeaderAtomType) { bytesRead = atom.create_video_media_header_atom(bitstream); } else if (type == MP4VisualSampleEntryAtomType) { bytesRead = atom.create_visual_sample_entry_atom(bitstream); } else if (type == MP4VideoSampleEntryAtomType) { bytesRead = atom.create_video_sample_entry_atom(bitstream); } else if (type == MP4ESDAtomType) { bytesRead = atom.create_esd_atom(bitstream); } else if (type == MP4AVCAtomType) { bytesRead = atom.create_avc_config_atom(bitstream); } else if (type == MP4PixelAspectAtomType) { bytesRead = atom.create_pasp_atom(bitstream); } #if !SILVERLIGHT log.Debug(string.Format("Atom: type = {0} size = {1}", IntToType(type), size)); #endif bitstream.SkipBytes(size - bytesRead); return(atom); }