/// <summary> /// Loads the MP4ES_Descriptor from the input bitstream. /// </summary> /// <param name="bitstream">The input bitstream.</param> public void CreateESDescriptor(Mp4DataStream bitstream) { int ES_ID = (int)bitstream.ReadBytes(2); int flags = (int)bitstream.ReadBytes(1); bool streamDependenceFlag = (flags & (1 << 7)) != 0; bool urlFlag = (flags & (1 << 6)) != 0; bool ocrFlag = (flags & (1 << 5)) != 0; _bytesRead += 3; if (streamDependenceFlag) { bitstream.SkipBytes(2); _bytesRead += 2; } if (urlFlag) { int str_size = (int)bitstream.ReadBytes(1); bitstream.ReadString(str_size); _bytesRead += str_size + 1; } if (ocrFlag) { bitstream.SkipBytes(2); _bytesRead += 2; } while (_bytesRead < _size) { Mp4Descriptor descriptor = CreateDescriptor(bitstream); _children.Add(descriptor); _bytesRead += descriptor.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 Handler atom from the input bitstream. /// </summary> /// <param name="bitstream">The input bitstream.</param> /// <returns>The number of bytes loaded.</returns> public long create_handler_atom(Mp4DataStream bitstream) { create_full_atom(bitstream); int qt_componentType = (int)bitstream.ReadBytes(4); handlerType = (int)bitstream.ReadBytes(4); int qt_componentManufacturer = (int)bitstream.ReadBytes(4); int qt_componentFlags = (int)bitstream.ReadBytes(4); int qt_componentFlagsMask = (int)bitstream.ReadBytes(4); _bytesRead += 20; int length = (int)(_size - _bytesRead - 1); String trackName = bitstream.ReadString(length); #if !SILVERLIGHT log.Debug(string.Format("Track name: {0}", trackName)); #endif _bytesRead += length; 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 Handler atom from the input bitstream. /// </summary> /// <param name="bitstream">The input bitstream.</param> /// <returns>The number of bytes loaded.</returns> public long create_handler_atom(Mp4DataStream bitstream) { create_full_atom(bitstream); int qt_componentType = (int)bitstream.ReadBytes(4); handlerType = (int)bitstream.ReadBytes(4); int qt_componentManufacturer = (int)bitstream.ReadBytes(4); int qt_componentFlags = (int)bitstream.ReadBytes(4); int qt_componentFlagsMask = (int)bitstream.ReadBytes(4); _bytesRead += 20; int length = (int)(_size - _bytesRead - 1); String trackName = bitstream.ReadString(length); #if !SILVERLIGHT log.Debug(string.Format("Track name: {0}", trackName)); #endif _bytesRead += length; 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); }