示例#1
0
        public void CanGetNextSample()
        {
            IWMSyncReader reader = OpenWmaFile();
            INSSBuffer    buffer;
            long          sampleTime;
            long          duration;
            uint          flags;
            uint          outputNum;
            ushort        streamNum;
            uint          hresult = reader.GetNextSample(0, out buffer, out sampleTime, out duration, out flags, out outputNum, out streamNum);

            Assert.AreEqual(0, hresult);
            //byte[] theBuffer;
            //buffer.GetBuffer(out theBuffer);


            hresult = reader.Close();
            Assert.AreEqual(0, hresult);
            Marshal.ReleaseComObject(reader);

            /*
             * //char[] nameBuffer = new char[256];
             * ushort length = 256;
             * string name = new string(' ', 256);
             * props.GetConnectionName(name, ref length);
             * //string name = new string(nameBuffer, 0, length);
             * Assert.IsFalse(String.IsNullOrEmpty(name));*/
        }
        /// <summary>
        /// Create WmaStream with specific format for for uncompressed audio data.
        /// </summary>
        /// <param name="FileName">Name of asf file</param>
        /// <param name="OutputFormat">WaveFormat that define the desired audio data format</param>
        public WmaStream(string FileName, WaveFormat OutputFormat)

        {
            m_Reader = WM.CreateSyncReader(WMT_RIGHTS.WMT_RIGHT_NO_DRM);

            try

            {
                m_Reader.Open(FileName);

                Init(OutputFormat);
            }

            catch

            {
                try

                {
                    m_Reader.Close();
                }

                catch {}

                m_Reader = null;

                throw;
            }
        }
示例#3
0
        protected override void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    if (_reader != null)
                    {
                        try
                        {
                            _reader.Close();

                            Logger.WriteLogMessage("Disposed IWMSyncReader.");
                        }
                        catch (Exception)
                        {
                            //
                            // eat exception
                            //
                        }

                        _reader = null;
                    }

                    Logger.WriteLogMessage("Completed dispose.");
                }
            }

            base.Dispose(disposing);
        }
示例#4
0
        public void CanOpenWmaFile()
        {
            IWMSyncReader reader = OpenWmaFile();

            reader.Close();
            Marshal.ReleaseComObject(reader);
        }
示例#5
0
    /// <summary>
    /// Create WmaStream with specific format for for uncompressed audio data.
    /// </summary>
    /// <param name="FileName">Name of asf file</param>
    /// <param name="OutputFormat">WaveFormat that define the desired audio data format</param>
    public WmaStream(string FileName, WaveFormat OutputFormat)

    {
      m_Reader = WM.CreateSyncReader(WMT_RIGHTS.WMT_RIGHT_NO_DRM);

      try

      {
        m_Reader.Open(FileName);

        Init(OutputFormat);
      }

      catch

      {
        try

        {
          m_Reader.Close();
        }

        catch {}

        m_Reader = null;

        throw;
      }
    }
示例#6
0
        public void CanOpenWmaFile()
        {
            IWMSyncReader reader  = OpenWmaFile();
            uint          hresult = reader.Close();

            Assert.AreEqual(0, hresult);
            Marshal.ReleaseComObject(reader);
        }
示例#7
0
 public override void Close()
 {
     if (m_Reader != null)
     {
         m_Reader.Close();
         m_Reader = null;
     }
     base.Close();
 }
示例#8
0
 public override void Close()
 {
     if (m_Reader != null)
     {
         m_Reader.Close();
         Marshal.ReleaseComObject(m_Reader);
         m_Reader = null;
     }
     base.Close();
 }
示例#9
0
        public void CanGetOutputFormat()
        {
            IWMSyncReader       reader = OpenWmaFile();
            IWMOutputMediaProps props;

            reader.GetOutputFormat(0, 0, out props);
            Assert.IsNotNull(props);

            reader.Close();
            Marshal.ReleaseComObject(reader);
        }
示例#10
0
        public void CanGetOutputCount()
        {
            IWMSyncReader reader = OpenWmaFile();
            uint          outputs;

            reader.GetOutputCount(out outputs);
            Assert.AreEqual(1, outputs, "Output Count");

            reader.Close();
            Marshal.ReleaseComObject(reader);
        }
示例#11
0
 public void Close()
 {
     //if (m_streamWrapper != null)
     //    m_streamWrapper.Close();
     if (m_IO != null)
     {
         m_IO.Close();
     }
     if (m_pSample != null)
     {
         Marshal.ReleaseComObject(m_pSample);
     }
     if (m_syncReader != null)
     {
         m_syncReader.Close();
         Marshal.ReleaseComObject(m_syncReader);
     }
     m_IO         = null;
     m_pSample    = null;
     m_syncReader = null;
 }
示例#12
0
 /// <summary>
 /// Create WmaStream with specific format for for uncompressed audio data.
 /// </summary>
 /// <param name="inputStream">Name of asf stream</param>
 /// <param name="OutputFormat">WaveFormat that define the desired audio data format</param>
 public WmaStreamReader(Stream inputStream, WaveFormat OutputFormat)
 {
     m_Reader = WM.CreateSyncReader(WMT_RIGHTS.WMT_RIGHT_NO_DRM);
     try
     {
         m_Reader.OpenStream(new ComStreamWrapper(inputStream));
         Init(OutputFormat);
     }
     catch
     {
         try
         {
             m_Reader.Close();
         }
         finally
         {
             m_Reader = null;
         }
         throw;
     }
 }
示例#13
0
文件: Helpers.cs 项目: tmpkus/openvss
        public static void CopyWmv(string inputFilePath, string outputFilePath, ulong startTime, long duration)
        {
            IWMWriterAdvanced writerAdvanced = null;
            IWMProfile        profile        = null;
            IWMStreamConfig   streamConfig   = null;
            uint streamCount = 0;
            uint inputCount  = 0;

            ushort[] streamNumbers = null;
            WMT_STREAM_SELECTION[] streamSelections = null;
            ulong      sampleTime, sampleDuration;
            uint       flags, outputNum;
            ushort     streamNum;
            INSSBuffer sample = null;

            IWMSyncReader reader = Helpers.CreateSyncReader(WMT_RIGHTS.WMT_RIGHT_NO_DRM);
            IWMWriter     writer = Helpers.CreateWriter();

            try
            {
                reader.Open(inputFilePath);

                Logger.WriteLogMessage("Opened file [" + inputFilePath + "] for reading.");

                profile = (IWMProfile)reader;

                profile.GetStreamCount(out streamCount);

                streamNumbers = new ushort[streamCount];

                streamSelections = new WMT_STREAM_SELECTION[streamCount];

                for (uint i = 0; i < streamCount; i++)
                {
                    profile.GetStream(i, out streamConfig);

                    streamConfig.GetStreamNumber(out streamNumbers[i]);

                    streamSelections[i] = WMT_STREAM_SELECTION.WMT_ON;

                    //
                    // Read compressed samples
                    //
                    reader.SetReadStreamSamples(streamNumbers[i], true);
                }

                //
                // select all streams
                //
                reader.SetStreamsSelected((ushort)streamCount, streamNumbers, streamSelections);

                writer.SetProfile(profile);

                writer.GetInputCount(out inputCount);

                for (uint i = 0; i < inputCount; i++)
                {
                    writer.SetInputProps(i, null);                     // write compressed samples
                }

                writer.SetOutputFilename(outputFilePath);

                Logger.WriteLogMessage("Set output filename [" + outputFilePath + "] for writing.");

                writerAdvanced = (IWMWriterAdvanced)writer;

                // Copy attributes avoided
                // Copy Codec Info avoided
                // Copy all scripts in the header avoided

                writer.BeginWriting();

                //
                // startTime, duration are in 100-nsec ticks
                //
                reader.SetRange(startTime, duration);                 // seek

                Logger.WriteLogMessage("Set range on reader, startTime [" + startTime + "], duration [" + duration + "].");

                for (uint streamsRead = 0; streamsRead < streamCount;)
                {
                    try
                    {
                        streamNum = 0;

                        reader.GetNextSample(0, out sample, out sampleTime, out sampleDuration, out flags, out outputNum, out streamNum);

                        Logger.WriteLogMessage("Grabbed next video sample, sampleTime [" + sampleTime + "], duration [" + sampleDuration + "], flags [" + flags + "], outputNum [" + outputNum + "], streamNum [" + streamNum + "].");

                        writerAdvanced.WriteStreamSample(streamNum, sampleTime, 0, sampleDuration, flags, sample);

                        Logger.WriteLogMessage("Wrote sample, sampleTime [" + sampleTime + "], duration [" + sampleDuration + "], flags [" + flags + "], outputNum [" + outputNum + "], streamNum [" + streamNum + "].");
                    }
                    catch (COMException e)
                    {
                        if (e.ErrorCode == Constants.NS_E_NO_MORE_SAMPLES)
                        {
                            streamsRead++;
                        }
                        else
                        {
                            throw;
                        }
                    }
                }

                writer.EndWriting();
            }
            finally
            {
                reader.Close();
            }
        }
示例#14
0
        public Metadata GetMetadata(object target)
        {
            if (target == null || !(target is string))
            {
                return(null);
            }

            string filename = target.ToString();

            IWMMetadataEditor2 metadataEditor = null;

            IWMSyncReader syncReader = null;

            WMMetadata metadata = new WMMetadata();

            try
            {
                WMFSDKFunctions.WMCreateEditor(out metadataEditor);
                metadataEditor.OpenEx(filename, FILE_ACCESS.GENERIC_READ, FILE_SHARE.FILE_SHARE_NONE);

                IWMHeaderInfo3 header = (IWMHeaderInfo3)metadataEditor;

                ushort attributeCount;
                header.GetAttributeCountEx(StreamNumber, out attributeCount);

                for (int i = 0; i < attributeCount; i++)
                {
                    MetadataField metadataField = GetAttributeByIndex(header, i);

                    metadata.AddMetadataField(metadataField);
                }
            }
            catch (COMException ex)
            {
                // TODO: Logging
            }
            finally
            {
                if (metadataEditor != null)
                {
                    metadataEditor.Close();
                    Marshal.FinalReleaseComObject(metadataEditor);
                    metadataEditor = null;
                }
            }

            try
            {
                WMFSDKFunctions.WMCreateSyncReader(IntPtr.Zero, WMT_RIGHTS.WMT_RIGHT_PLAYBACK, out syncReader);
                syncReader.Open(filename);

                int outputCount;
                syncReader.GetOutputCount(out outputCount);

                IWMOutputMediaProps outputMediaProps = null;

                for (uint i = 0; i < outputCount; i++)
                {
                    IWMOutputMediaProps innerOutputMediaProps;
                    syncReader.GetOutputProps(i, out innerOutputMediaProps);

                    Guid type;
                    innerOutputMediaProps.GetType(out type);

                    if (type == WMFSDKFunctions.WMMEDIATYPE_Video)
                    {
                        outputMediaProps = innerOutputMediaProps;
                        break;
                    }
                }

                if (outputMediaProps != null)
                {
                    int pcbType = 0;
                    outputMediaProps.GetMediaType(IntPtr.Zero, ref pcbType);

                    IntPtr mediaTypeBufferPtr = Marshal.AllocHGlobal(pcbType);

                    outputMediaProps.GetMediaType(mediaTypeBufferPtr, ref pcbType);

                    WM_MEDIA_TYPE     mediaType       = new WM_MEDIA_TYPE();
                    WMVIDEOINFOHEADER videoInfoHeader = new WMVIDEOINFOHEADER();
                    Marshal.PtrToStructure(mediaTypeBufferPtr, mediaType);

                    Marshal.FreeHGlobal(mediaTypeBufferPtr);
                    Marshal.PtrToStructure(mediaType.pbFormat, videoInfoHeader);

                    double frameRate = Math.Round((double)10000000 / videoInfoHeader.AvgTimePerFrame, 2);

                    metadata.AddMetadataField(new MetadataField("FrameRate", frameRate));
                }
            }
            catch (COMException ex)
            {
                // TODO: Logging
            }
            finally
            {
                if (syncReader != null)
                {
                    syncReader.Close();
                    Marshal.FinalReleaseComObject(syncReader);
                    syncReader = null;
                }
            }

            return(metadata);
        }
示例#15
0
 /// <summary>
 /// Create WmaStream with specific format for for uncompressed audio data.
 /// </summary>
 /// <param name="inputStream">Name of asf stream</param>
 /// <param name="OutputFormat">WaveFormat that define the desired audio data format</param>
 public WmaStreamReader(Stream inputStream, WaveFormat OutputFormat)
 {
     m_Reader = WM.CreateSyncReader(WMT_RIGHTS.WMT_RIGHT_NO_DRM);
     try
     {
         m_Reader.OpenStream(new ComStreamWrapper(inputStream));
         Init(OutputFormat);
     }
     catch
     {
         try
         {
             m_Reader.Close();
         }
         finally
         {
             m_Reader = null;
         }
         throw;
     }
 }
 private void TestClose()
 {
     m_read.Close();
 }