void TestTitle() { int hr; DvdParentalLevel pulTParentalLevels; int pulNumOfChapters; hr = m_idi2.GetNumberOfChapters(1, out pulNumOfChapters); DsError.ThrowExceptionForHR(hr); Debug.Assert(pulNumOfChapters == 2, "TestTitle"); hr = m_idi2.GetTitleParentalLevels(1, out pulTParentalLevels); DsError.ThrowExceptionForHR(hr); Debug.Assert(pulTParentalLevels == (DvdParentalLevel.Level1 | DvdParentalLevel.Level2 | DvdParentalLevel.Level3 | DvdParentalLevel.Level4 | DvdParentalLevel.Level5 | DvdParentalLevel.Level6 | DvdParentalLevel.Level7 | DvdParentalLevel.Level8), "TestTitle2"); DvdDecoderCaps pCaps = new DvdDecoderCaps(); pCaps.dwSize = Marshal.SizeOf(pCaps); hr = m_idi2.GetDecoderCaps(ref pCaps); DsError.ThrowExceptionForHR(hr); Debug.Assert(pCaps.dwAudioCaps == (DvdAudioCaps.AC3 | DvdAudioCaps.MPEG2 | DvdAudioCaps.DTS | DvdAudioCaps.SDDS), "TestTitle3"); DvdMenuAttributes pMenu = new DvdMenuAttributes(); DvdTitleAttributes pTitle = new DvdTitleAttributes(); hr = m_idi2.GetTitleAttributes(1, out pMenu, pTitle); DsError.ThrowExceptionForHR(hr); Debug.Assert(pMenu.VideoAttributes.sourceResolutionX == 720, "TestDiskInfo4"); Debug.Assert(pTitle.ulNumberOfAudioStreams == 1, "TestTitle5"); }
// Called just after invoking the COM method. The IntPtr is the same one that just got returned // from MarshalManagedToNative. The return value is unused. override public object MarshalNativeToManaged(IntPtr pNativeData) { DvdTitleAttributes dta = m_obj as DvdTitleAttributes; // Copy in the value, and advance the pointer dta.AppMode = (DvdTitleAppMode)Marshal.ReadInt32(pNativeData); pNativeData = (IntPtr)(pNativeData.ToInt64() + Marshal.SizeOf(typeof(int))); // Copy in the value, and advance the pointer dta.VideoAttributes = (DvdVideoAttributes)Marshal.PtrToStructure(pNativeData, typeof(DvdVideoAttributes)); pNativeData = (IntPtr)(pNativeData.ToInt64() + Marshal.SizeOf(typeof(DvdVideoAttributes))); // Copy in the value, and advance the pointer dta.ulNumberOfAudioStreams = Marshal.ReadInt32(pNativeData); pNativeData = (IntPtr)(pNativeData.ToInt64() + Marshal.SizeOf(typeof(int))); // Allocate a large enough array to hold all the returned structs. dta.AudioAttributes = new DvdAudioAttributes[8]; for (int x = 0; x < 8; x++) { // Copy in the value, and advance the pointer dta.AudioAttributes[x] = (DvdAudioAttributes)Marshal.PtrToStructure(pNativeData, typeof(DvdAudioAttributes)); pNativeData = (IntPtr)(pNativeData.ToInt64() + Marshal.SizeOf(typeof(DvdAudioAttributes))); } // Allocate a large enough array to hold all the returned structs. dta.MultichannelAudioAttributes = new DvdMultichannelAudioAttributes[8]; for (int x = 0; x < 8; x++) { // MultichannelAudioAttributes has nested ByValArrays. They need to be individually copied. dta.MultichannelAudioAttributes[x].Info = new DvdMUAMixingInfo[8]; for (int y = 0; y < 8; y++) { // Copy in the value, and advance the pointer dta.MultichannelAudioAttributes[x].Info[y] = (DvdMUAMixingInfo)Marshal.PtrToStructure(pNativeData, typeof(DvdMUAMixingInfo)); pNativeData = (IntPtr)(pNativeData.ToInt64() + Marshal.SizeOf(typeof(DvdMUAMixingInfo))); } dta.MultichannelAudioAttributes[x].Coeff = new DvdMUACoeff[8]; for (int y = 0; y < 8; y++) { // Copy in the value, and advance the pointer dta.MultichannelAudioAttributes[x].Coeff[y] = (DvdMUACoeff)Marshal.PtrToStructure(pNativeData, typeof(DvdMUACoeff)); pNativeData = (IntPtr)(pNativeData.ToInt64() + Marshal.SizeOf(typeof(DvdMUACoeff))); } } // The DvdMultichannelAudioAttributes needs to be 16 byte aligned pNativeData = (IntPtr)(pNativeData.ToInt64() + 4); // Copy in the value, and advance the pointer dta.ulNumberOfSubpictureStreams = Marshal.ReadInt32(pNativeData); pNativeData = (IntPtr)(pNativeData.ToInt64() + Marshal.SizeOf(typeof(int))); // Allocate a large enough array to hold all the returned structs. dta.SubpictureAttributes = new DvdSubpictureAttributes[32]; for (int x = 0; x < 32; x++) { // Copy in the value, and advance the pointer dta.SubpictureAttributes[x] = (DvdSubpictureAttributes)Marshal.PtrToStructure(pNativeData, typeof(DvdSubpictureAttributes)); pNativeData = (IntPtr)(pNativeData.ToInt64() + Marshal.SizeOf(typeof(DvdSubpictureAttributes))); } // Note that 4 bytes (more alignment) are unused at the end return(null); }
private void FetchDVDInformation_DS(string volumePath) { IDvdGraphBuilder dvdGraphBuilder = Activator.CreateInstance(Type.GetTypeFromCLSID(Filters.DvdGraphBuilder, true)) as IDvdGraphBuilder; AMDvdRenderStatus status; dvdGraphBuilder.TryRenderDVD(volumePath, out status); if (status.bDvdVolInvalid) { throw new COMException(ErrDvdVolume, -1); } object comobj = null; dvdGraphBuilder.GetDvdInterface(typeof(IDvdInfo2).GUID, out comobj); IDvdInfo2 dvdInfo = comobj as IDvdInfo2; IDvdControl2 dvdControl = comobj as IDvdControl2; dvdControl.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true); // use new HMSF timecode format dvdControl.SetOption(DvdOptionFlag.ResetOnStop, false); // Try getting the frame rate and the video size dvdInfo.GetVMGAttributes(out _dma); this.FrameRate = new FrameRate(_dma.VideoAttributes.frameRate); this.VideoSize = new VSize(_dma.VideoAttributes.sourceResolutionX, _dma.VideoAttributes.sourceResolutionY); // Try getting the DVD volume name. // Stage 1: Get the number of available languages. int numLangs = 0; dvdInfo.GetDVDTextNumberOfLanguages(out numLangs); if (numLangs > 0) { // Stage 2: Get string count for the first language. int numStrings = 0; int langId = 0; DvdTextCharSet charSet = DvdTextCharSet.CharSet_Unicode; dvdInfo.GetDVDTextLanguageInfo(0, out numStrings, out langId, out charSet); // Stage 3: Iterate through the string collection and identify the volume name for (int i = 0; i < numStrings; i++) { int maxSize = 4096; StringBuilder sb = new StringBuilder(maxSize); int txtSize = 0; DvdTextStringType textType; dvdInfo.GetDVDTextStringAsUnicode(0, i, sb, maxSize, out txtSize, out textType); // Is this the volume name ? if (textType == DvdTextStringType.DVD_General_Name) { // Volume name was found, so exit iteration. _label = sb.ToString(); break; } } } // Try getting the titles, chapters and overall duration info int numVolumes = 0, volumeNumber = 0, numTitles = 0; DvdDiscSide sideInfo; dvdInfo.GetDVDVolumeInfo(out numVolumes, out volumeNumber, out sideInfo, out numTitles); for (int i = 1; i <= numTitles; i++) { int numChapters = 0; try { DvdMenuAttributes menuAttr; DvdTitleAttributes titleAttr = new DvdTitleAttributes(); if (i == 1) { dvdInfo.GetTitleAttributes(i, out menuAttr, titleAttr); for (int j = 0; j < titleAttr.ulNumberOfSubpictureStreams; j++) { _subtitles.Add(titleAttr.SubpictureAttributes[j]); } } dvdInfo.GetNumberOfChapters(i, out numChapters); _chaptersPerTitle.Add(numChapters); } catch { } } }