private void TestOnStreamSelection() { IWMReader read; m_StreamSelection = false; m_Opened = false; WMUtils.WMCreateReader(IntPtr.Zero, Rights.Playback, out read); IWMReaderAdvanced ra = read as IWMReaderAdvanced; ra.SetReceiveSelectionCallbacks(true); read.Open(sFileName, this, new IntPtr(123)); while (!m_Opened) { System.Threading.Thread.Sleep(0); } ChangeSelected(ra); while (!m_StreamSelection) { System.Threading.Thread.Sleep(1); } read.Stop(); read.Close(); }
private void TestAllocateForStream() { IWMReader read; m_AllocateForStream = false; m_Opened = false; WMUtils.WMCreateReader(IntPtr.Zero, Rights.Playback, out read); read.Open(sFileName, this, new IntPtr(123)); while (!m_Opened) { System.Threading.Thread.Sleep(0); } IWMReaderAdvanced ra = read as IWMReaderAdvanced; ra.SetAllocateForStream(1, true); ra.SetReceiveStreamSamples(1, true); read.Start(0, 0, 1.0f, IntPtr.Zero); while (!m_AllocateForStream) { System.Threading.Thread.Sleep(0); } read.Stop(); read.Close(); }
private void SetStreams(string sName) { // First find the mapping between the output name and // the stream number IWMProfile pProfile = m_pReader as IWMProfile; int iCount; pProfile.GetStreamCount(out iCount); short[] sss = new short[iCount]; StreamSelection[] ss = new StreamSelection[iCount]; StringBuilder sSName; for (short j = 0; j < iCount; j++) { IWMStreamConfig pConfig; pProfile.GetStream(j, out pConfig); try { pConfig.GetStreamNumber(out sss[j]); short iSName = 0; sSName = null; pConfig.GetConnectionName(sSName, ref iSName); sSName = new StringBuilder(iSName); pConfig.GetConnectionName(sSName, ref iSName); } finally { Marshal.ReleaseComObject(pConfig); } // Turn the stream on or off depending on whether // this is the one that matches the output we're // looking for if (sSName.ToString() == sName) { ss[j] = StreamSelection.On; } else { ss[j] = StreamSelection.Off; } } // Use the array we've built to specify the streams we want IWMReaderAdvanced ra = m_pReader as IWMReaderAdvanced; ra.SetStreamsSelected((short)iCount, sss, ss); // Learn the maximum sample size that will be send to OnSample ra.GetMaxOutputSampleSize(m_dwAudioOutputNum, out m_MaxSampleSize); // Have the Samples allocated using IWMReaderCallbackAdvanced::AllocateForOutput ra.SetAllocateForOutput(m_dwAudioOutputNum, true); }
private void Config() { IWMReader read; WMUtils.WMCreateReader(IntPtr.Zero, 0, out read); m_Opened = false; read.Open(sFileName, this, new IntPtr(123)); m_read = read as IWMReaderAdvanced; while (!m_Opened) { System.Threading.Thread.Sleep(0); } }
private void ChangeSelected(IWMReaderAdvanced ra) { short[] ss = new short[2]; ss[0] = 1; ss[1] = 2; StreamSelection[] sss = new StreamSelection[2]; if (m_loop == 0) { sss[0] = StreamSelection.Off; sss[1] = StreamSelection.On; m_loop = 1; } else { sss[1] = StreamSelection.Off; sss[0] = StreamSelection.On; m_loop = 0; } ra.SetStreamsSelected(2, ss, sss); }
//------------------------------------------------------------------------------ // Name: CWMVCopy::Copy() // Desc: Copies the input file to the output file. The script stream is moved // to the header if fMoveScriptStream is true. //------------------------------------------------------------------------------ public void Copy( string pwszInputFile, string pwszOutputFile, long qwMaxDuration, bool fMoveScriptStream) { // // Initialize the pointers // m_hEvent = null; m_pReader = null; m_pReaderAdvanced = null; m_pReaderHeaderInfo = null; m_pReaderProfile = null; m_pWriter = null; m_pWriterAdvanced = null; m_pWriterHeaderInfo = null; m_dwStreamCount = 0; m_pguidStreamType = null; m_pwStreamNumber = null; if (null == pwszInputFile || null == pwszOutputFile) { throw new COMException("Missing input or output file", E_InvalidArgument); } m_fMoveScriptStream = fMoveScriptStream; m_qwMaxDuration = qwMaxDuration; // // Event for the asynchronous calls // m_hEvent = new AutoResetEvent(false); // // Create the Reader // CreateReader(pwszInputFile); // // Get profile information // GetProfileInfo(); // // Create the Writer // CreateWriter(pwszOutputFile); // // Copy all attributes // CopyAttribute(); // // Copy codec info // CopyCodecInfo(); // // Copy all scripts in the header // CopyScriptInHeader(); // // Process samples: read from the reader, and write to the writer // try { Process(); } catch (Exception e) { int hr = Marshal.GetHRForException(e); // // Output some common error messages. // if (NSResults.E_VIDEO_CODEC_NOT_INSTALLED == hr) { Console.WriteLine("Processing samples failed: Video codec not installed"); } if (NSResults.E_AUDIO_CODEC_NOT_INSTALLED == hr) { Console.WriteLine("Processing samples failed: Audio codec not installed"); } else if (NSResults.E_INVALID_OUTPUT_FORMAT == hr) { Console.WriteLine("Processing samples failed: Invalid output format "); } else if (NSResults.E_VIDEO_CODEC_ERROR == hr) { Console.WriteLine("Processing samples failed: An unexpected error occurred with the video codec "); } else if (NSResults.E_AUDIO_CODEC_ERROR == hr) { Console.WriteLine("Processing samples failed: An unexpected error occurred with the audio codec "); } else { Console.WriteLine(string.Format("Processing samples failed: Error (hr=0x{0:x})", hr)); } throw; } // // Copy all scripts in m_ScriptList // CopyScriptInList(pwszOutputFile); // // Copy marker information // CopyMarker(pwszOutputFile); Console.WriteLine("Copy finished."); // // Note: The output file is indexed automatically. // You can use IWMWriterFileSink3::SetAutoIndexing(false) to disable // auto indexing. // Dispose(); }
//------------------------------------------------------------------------------ // Name: CWMVCopy::CreateReader() // Desc: Creates a reader and opens the source file using this reader. //------------------------------------------------------------------------------ protected void CreateReader(string pwszInputFile) { Console.WriteLine("Creating the Reader..."); // // Create a reader // WMUtils.WMCreateReader(IntPtr.Zero, 0, out m_pReader); // // Get the IWMReaderAdvanced interface // m_pReaderAdvanced = m_pReader as IWMReaderAdvanced; // // Get the IWMHeaderInfo interface of the reader // m_pReaderHeaderInfo = m_pReader as IWMHeaderInfo; // // Open the reader; use "this" as the callback interface. // m_pReader.Open(pwszInputFile, this, IntPtr.Zero); // // Wait until WMT_OPENED status message is received in OnStatus() // WaitForCompletion(); // // Get the duration of the source file // short wStreamNumber = 0; AttrDataType enumType; short cbLength = 8; // sizeof(m_qwDuration); byte[] b = new byte[cbLength]; m_pReaderHeaderInfo.GetAttributeByName(ref wStreamNumber, Constants.g_wszWMDuration, out enumType, b, ref cbLength); m_qwDuration = BitConverter.ToInt64(b, 0); if (m_qwDuration == 0) { throw new COMException("Duration is zero", E_InvalidArgument); } // // Turn on the user clock // m_pReaderAdvanced.SetUserProvidedClock(true); // // Turn on manual stream selection, so we get all streams. // m_pReaderAdvanced.SetManualStreamSelection(true); }