Ejemplo n.º 1
0
        //------------------------------------------------------------------------------
        // Name: CWMVCopy::Process()
        // Desc: Processes the samples from the reader..
        //------------------------------------------------------------------------------
        protected void Process()
        {
            //
            // Begin writing
            //
            m_pWriter.BeginWriting();

            m_hr         = S_Ok;
            m_fEOF       = false;
            m_dwProgress = 0;
            m_hEvent.Reset();

            Console.WriteLine("            0%-------20%-------40%-------60%-------80%-------100%");
            Console.Write("Process:    ");

            //
            // Start the reader
            //
            m_pReader.Start(0, 0, 1.0f, IntPtr.Zero);

            //
            // Wait until the reading is finished
            //
            WaitForCompletion();
            Console.WriteLine("");

            //
            // End writing
            //
            m_pWriter.EndWriting();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create the writer indicating Metadata information
        /// </summary>
        /// <param name="output"><see cref="System.IO.Stream"/> Where resulting WMA string will be written</param>
        /// <param name="format">PCM format of input data received in <see cref="WmaWriter.Write"/> method</param>
        /// <param name="profile">IWMProfile that describe the resulting compressed stream</param>
        /// <param name="MetadataAttributes">Array of <see cref="Yeti.WMFSdk.WM_Attr"/> structures describing the metadata information that will be in the result stream</param>
        public WmaWriter(Stream output, WaveFormat format, IWMProfile profile, WM_Attr[] MetadataAttributes)
            : base(output, format)
        {
            m_Writer = WM.CreateWriter();
            IWMWriterAdvanced wa = (IWMWriterAdvanced)m_Writer;

            wa.AddSink((IWMWriterSink)this);
            m_Writer.SetProfile(profile);
            uint inputs;

            m_Writer.GetInputCount(out inputs);
            if (inputs == 1)
            {
                IWMInputMediaProps InpProps;
                Guid type;
                m_Writer.GetInputProps(0, out InpProps);
                InpProps.GetType(out type);
                if (type == MediaTypes.WMMEDIATYPE_Audio)
                {
                    WM_MEDIA_TYPE mt;
                    mt.majortype            = MediaTypes.WMMEDIATYPE_Audio;
                    mt.subtype              = MediaTypes.WMMEDIASUBTYPE_PCM;
                    mt.bFixedSizeSamples    = true;
                    mt.bTemporalCompression = false;
                    mt.lSampleSize          = (uint)m_InputDataFormat.nBlockAlign;
                    mt.formattype           = MediaTypes.WMFORMAT_WaveFormatEx;
                    mt.pUnk     = IntPtr.Zero;
                    mt.cbFormat = (uint)Marshal.SizeOf(m_InputDataFormat);

                    GCHandle h = GCHandle.Alloc(m_InputDataFormat, GCHandleType.Pinned);
                    try {
                        mt.pbFormat = h.AddrOfPinnedObject();
                        InpProps.SetMediaType(ref mt);
                    }
                    finally {
                        h.Free();
                    }
                    m_Writer.SetInputProps(0, InpProps);
                    if (MetadataAttributes != null)
                    {
                        WMHeaderInfo info = new WMHeaderInfo((IWMHeaderInfo)m_Writer);
                        foreach (WM_Attr attr in MetadataAttributes)
                        {
                            info.SetAttribute(attr);
                        }
                        info = null;
                    }
                    m_Writer.BeginWriting();
                    m_Profile = profile;
                }
                else
                {
                    throw new ArgumentException("Invalid profile", "profile");
                }
            }
            else
            {
                throw new ArgumentException("Invalid profile", "profile");
            }
        }
Ejemplo n.º 3
0
        private void Test()
        {
            WMWriterStatisticsEx w = new WMWriterStatisticsEx();

            m_wa3.SetNonBlocking();
            m_Writer.BeginWriting();
            m_wa3.GetStatisticsEx(0, out w);
        }
        private void Config()
        {
            WMUtils.WMCreateWriter(IntPtr.Zero, out m_pWriter);
            m_pWriter.SetProfileByID(g);
            m_pWriter.BeginWriting();

            m_preproc = m_pWriter as IWMWriterPreprocess;
        }
Ejemplo n.º 5
0
 public void Start()
 {
     // start writing output file
     //
     try
     {
         _writer.BeginWriting();
     }
     catch (Exception)
     {
         // error handle
         throw;
     }
 }
Ejemplo n.º 6
0
 public bool Start()
 {
     try
     {
         writer.BeginWriting();
     }
     catch (Exception e)
     {
         eventLog.WriteEntry("Failed to start writing: " + e.ToString(), EventLogEntryType.Error, 1000);
         Debug.WriteLine("Failed to start writing: " + e.ToString());
         return(false);
     }
     return(true);
 }
Ejemplo n.º 7
0
        private void TestWrite()
        {
            Bitmap b = new Bitmap(@"c:\sga.png");

            Initialize(b);

            m_Writer.SetOutputFilename(sFileName);

            m_Writer.BeginWriting();
            INSSBuffer pSample = WriteOne(b);

            m_Writer.WriteSample(0, 1, SampleFlag.CleanPoint, pSample);
            m_Writer.Flush();
            TestAdvanced(b);
            m_Writer.EndWriting();
        }
Ejemplo n.º 8
0
        private void Test()
        {
            Bitmap b = new Bitmap(@"c:\sga.png");

            Initialize(b);

            m_Writer.SetOutputFilename(sFileName);

            m_Writer.BeginWriting();
            INSSBuffer pSample = WriteOne(b);

            m_Writer.WriteSample(0, 1, SampleFlag.CleanPoint, pSample);
            m_Writer.Flush();
            m_Writer.EndWriting();

            Debug.Assert(m_OnHeader && m_IsRealTime && m_AllocateDataUnit && m_OnDataUnit && m_OnEndWriting);
        }
        private void TestSink()
        {
            IWMWriterAdvanced pWriterA;

            pWriterA = m_Writer as IWMWriterAdvanced;
            pWriterA.AddSink(this);

            Bitmap b = new Bitmap(@"c:\sga.png");

            Initialize(b);

            m_Writer.SetOutputFilename(sFileName);

            m_Writer.BeginWriting();
            INSSBuffer pSample = WriteOne(b);

            m_Writer.WriteSample(0, 1, SampleFlag.CleanPoint, pSample);
            m_Writer.Flush();
            m_Writer.EndWriting();
        }
        private void Config()
        {
            WMUtils.WMCreateWriter(IntPtr.Zero, out writer);
            writer.SetProfileByID(g);

            WMUtils.WMCreateWriterNetworkSink(out sink);
            m_clientConns = (IWMClientConnections)sink;

            IWMWriterAdvanced advWriter = (IWMWriterAdvanced)writer;

            advWriter.AddSink(sink);
            sink.Open(ref port);

            int urlLen = 0;

            sink.GetHostURL(null, ref urlLen);
            sbUrl = new StringBuilder(urlLen);
            sink.GetHostURL(sbUrl, ref urlLen);

            writer.BeginWriting();

            WMUtils.WMCreateReader(IntPtr.Zero, Rights.Playback, out reader);
            reader.Open(sbUrl.ToString(), this, new IntPtr(123));

            lock (m_openLock)
            {
                Monitor.Wait(m_openLock);
            }

            reader.Start(0, 0, 1.0f, new IntPtr(321));

            lock (m_openLock)
            {
                Monitor.Wait(m_openLock);
            }
        }
Ejemplo n.º 11
0
    /// <summary>
    /// Create the writer indicating Metadata information
    /// </summary>
    /// <param name="output"><see cref="System.IO.Stream"/> Where resulting WMA string will be written</param>
    /// <param name="format">PCM format of input data received in <see cref="WmaWriter.Write"/> method</param>
    /// <param name="profile">IWMProfile that describe the resulting compressed stream</param>
    /// <param name="MetadataAttributes">Array of <see cref="Yeti.WMFSdk.WM_Attr"/> structures describing the metadata information that will be in the result stream</param>
    public WmaWriter(Stream output, WaveFormat format, IWMProfile profile, WM_Attr[] MetadataAttributes)
      : base(output, format)
		{
			m_Writer = WM.CreateWriter();
      IWMWriterAdvanced wa = (IWMWriterAdvanced)m_Writer;
      wa.AddSink((IWMWriterSink)this);
      m_Writer.SetProfile(profile);
      uint inputs;
      m_Writer.GetInputCount(out inputs);
      if (inputs == 1)
      {
        IWMInputMediaProps InpProps;
        Guid type;
        m_Writer.GetInputProps(0, out InpProps);
        InpProps.GetType(out type);
        if (type == MediaTypes.WMMEDIATYPE_Audio)
        {
          WM_MEDIA_TYPE mt;
          mt.majortype = MediaTypes.WMMEDIATYPE_Audio;
          mt.subtype = MediaTypes.WMMEDIASUBTYPE_PCM;
          mt.bFixedSizeSamples	= true;
          mt.bTemporalCompression = false;
          mt.lSampleSize	= (uint)m_InputDataFormat.nBlockAlign;
          mt.formattype	= MediaTypes.WMFORMAT_WaveFormatEx;
          mt.pUnk	= IntPtr.Zero;
          mt.cbFormat	= (uint)Marshal.SizeOf(m_InputDataFormat);

          GCHandle h = GCHandle.Alloc(m_InputDataFormat, GCHandleType.Pinned);
          try
          {
            mt.pbFormat	= h.AddrOfPinnedObject();
            InpProps.SetMediaType(ref mt);
          }
          finally
          {
            h.Free();
          }
          m_Writer.SetInputProps(0, InpProps);
          if ( MetadataAttributes != null )
          {
            WMHeaderInfo info = new WMHeaderInfo((IWMHeaderInfo)m_Writer);
            foreach(WM_Attr attr in MetadataAttributes)
            {
              info.SetAttribute(attr);
            }
            info = null;
          }
          m_Writer.BeginWriting();
          m_Profile = profile;
        }
        else
        {
          throw new ArgumentException("Invalid profile", "profile");
        }
      }
      else
      {
        throw new ArgumentException("Invalid profile", "profile");
      }
		}
Ejemplo n.º 12
0
        /// <summary>
        /// Read the properties of the first bitmap to finish initializing the writer.
        /// </summary>
        /// <param name="hBitmap">First bitmap</param>
        private void Initialize(Bitmap hBitmap)
        {
            AMMediaType     mt        = new AMMediaType();
            VideoInfoHeader videoInfo = new VideoInfoHeader();

            // Create the VideoInfoHeader using info from the bitmap
            videoInfo.BmiHeader.Size   = Marshal.SizeOf(typeof(BitmapInfoHeader));
            videoInfo.BmiHeader.Width  = hBitmap.Width;
            videoInfo.BmiHeader.Height = hBitmap.Height;
            videoInfo.BmiHeader.Planes = 1;

            // compression thru clrimportant don't seem to be used. Init them anyway
            videoInfo.BmiHeader.Compression   = 0;
            videoInfo.BmiHeader.ImageSize     = 0;
            videoInfo.BmiHeader.XPelsPerMeter = 0;
            videoInfo.BmiHeader.YPelsPerMeter = 0;
            videoInfo.BmiHeader.ClrUsed       = 0;
            videoInfo.BmiHeader.ClrImportant  = 0;

            switch (hBitmap.PixelFormat)
            {
            case PixelFormat.Format32bppRgb:
                mt.subType = MediaSubType.RGB32;
                videoInfo.BmiHeader.BitCount = 32;
                break;

            case PixelFormat.Format24bppRgb:
                mt.subType = MediaSubType.RGB24;
                videoInfo.BmiHeader.BitCount = 24;
                break;

            case PixelFormat.Format16bppRgb555:
                mt.subType = MediaSubType.RGB555;
                videoInfo.BmiHeader.BitCount = 16;
                break;

            default:
                throw new Exception("Unrecognized Pixelformat in bitmap");
            }

            videoInfo.SrcRect             = new Rectangle(0, 0, hBitmap.Width, hBitmap.Height);
            videoInfo.TargetRect          = videoInfo.SrcRect;
            videoInfo.BmiHeader.ImageSize = hBitmap.Width * hBitmap.Height * (videoInfo.BmiHeader.BitCount / 8);
            videoInfo.BitRate             = videoInfo.BmiHeader.ImageSize * m_iFrameRate;
            videoInfo.BitErrorRate        = 0;
            videoInfo.AvgTimePerFrame     = 10000 * 1000 / m_iFrameRate;

            mt.majorType           = MediaType.Video;
            mt.fixedSizeSamples    = true;
            mt.temporalCompression = false;
            mt.sampleSize          = videoInfo.BmiHeader.ImageSize;
            mt.formatType          = FormatType.VideoInfo;
            mt.unkPtr     = IntPtr.Zero;
            mt.formatSize = Marshal.SizeOf(typeof(VideoInfoHeader));

            // Lock the videoInfo structure, and put the pointer
            // into the mediatype structure
            GCHandle gHan = GCHandle.Alloc(videoInfo, GCHandleType.Pinned);

            try
            {
                // Set the inputprops using the structures
                mt.formatPtr = gHan.AddrOfPinnedObject();

                m_pInputProps.SetMediaType(mt);
            }
            finally
            {
                gHan.Free();
                mt.formatPtr = IntPtr.Zero;
            }

            // Now take the inputprops, and set them on the file writer
            m_pWMWriter.SetInputProps(m_dwVideoInput, m_pInputProps);

            // Done with config, prepare to write
            m_pWMWriter.BeginWriting();

            m_Init = true;
        }
Ejemplo n.º 13
0
        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();
            }
        }