当前位置: 首页>>代码示例>>C#>>正文


C# IMediaSample类代码示例

本文整理汇总了C#中IMediaSample的典型用法代码示例。如果您正苦于以下问题:C# IMediaSample类的具体用法?C# IMediaSample怎么用?C# IMediaSample使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IMediaSample类属于命名空间,在下文中一共展示了IMediaSample类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Analyze

        /// <summary>
        /// Implementation of ISampleGrabberCB.
        /// </summary>
        int ISampleGrabberCB.SampleCB(double sampleTime, IMediaSample pSample)
        {
            IntPtr pBuffer;
            int hr = pSample.GetPointer(out pBuffer);
            DsError.ThrowExceptionForHR(hr);

            Analyze(sampleTime, pBuffer, pSample.GetSize());

            Marshal.ReleaseComObject(pSample);
            return 0;
        }
开发者ID:nuukcillo,项目名称:PerrySub,代码行数:14,代码来源:SceneDetector.cs

示例2: SampleCB

 public int SampleCB(double SampleTime, IMediaSample pSample)
 {
     //  Console.WriteLine("**********************55555555555555555555555**********************");
     if (pSample == null) return -1;
     int len = pSample.GetActualDataLength();
     IntPtr pbuf;
     if (pSample.GetPointer(out pbuf) == 0 && len > 0)
     {
         byte[] buf = new byte[len];
         Marshal.Copy(pbuf, buf, 0, len);
         for (int i = 0; i < len; i += 2)
             buf[i] = (byte)(255 - buf[i]);
         Marshal.Copy(buf, 0, pbuf, len);
     }
     return 0;
 }
开发者ID:RajibTheKing,项目名称:DesktopClient,代码行数:16,代码来源:SampleGrabberCallback.cs

示例3: CopySample

        public static void CopySample(IMediaSample src, IMediaSample dest, bool copySamples)
        {
            var sourceSize = src.GetActualDataLength();

            if (copySamples)
            {
                IntPtr sourceBuffer;
                src.GetPointer(out sourceBuffer);

                IntPtr destBuffer;
                dest.GetPointer(out destBuffer);

                CopyMemory(destBuffer, sourceBuffer, sourceSize);
            }

            // Copy the sample times
            long start, end;

            if (src.GetTime(out start, out end) == S_OK)
            {
                dest.SetTime(start, end);
            }

            if (src.GetMediaTime(out start, out end) == S_OK)
            {
                dest.SetMediaTime(start, end);
            }

            // Copy the media type
            AMMediaType mediaType;
            src.GetMediaType(out mediaType);
            dest.SetMediaType(mediaType);
            DsUtils.FreeAMMediaType(mediaType);

            dest.SetSyncPoint(src.IsSyncPoint() == S_OK);
            dest.SetPreroll(src.IsPreroll() == S_OK);
            dest.SetDiscontinuity(src.IsDiscontinuity() == S_OK);

            // Copy the actual data length
            dest.SetActualDataLength(sourceSize);
        }
开发者ID:Xuno,项目名称:MPDN_Extensions,代码行数:41,代码来源:AudioHelpers.cs

示例4: SetTimeStamps

        /// <summary>
        /// Calculate and populate the timestamps
        /// </summary>
        /// <param name="pSample">The IMediaSample to set the timestamps on</param>
        /// <returns>HRESULT</returns>
        public override int SetTimeStamps(IMediaSample pSample)
        {
            // Time per frame
            int tpf = (UNIT / m_Fps);

            DsLong rtStart = new DsLong(m_rtSampleTime);
            m_rtSampleTime += tpf;

            DsLong rtStop = new DsLong(m_rtSampleTime);

            // Set the times into the sample
            int hr = pSample.SetTime(rtStart, rtStop);

            // Set TRUE on every sample for uncompressed frames
            if (hr >= 0)
            {
                hr = pSample.SetSyncPoint(true);
            }

            return hr;
        }
开发者ID:OmerMor,项目名称:DirectShowLib-FORK,代码行数:26,代码来源:Overlay.cs

示例5: Transcode


//.........这里部分代码省略.........
       Cleanup();
       return false;
     }
     hr = graphBuilder.Connect(pinOut0, pinIn0);
     if (hr != 0)
     {
       Log.Error("TSReader2MP4: FAILED: unable to connect audio pins :0x{0:X}", hr);
       Cleanup();
       return false;
     }
     hr = graphBuilder.Connect(pinOut1, pinIn1);
     if (hr != 0)
     {
       Log.Error("TSReader2MP4: FAILED: unable to connect video pins :0x{0:X}", hr);
       Cleanup();
       return false;
     }
     //add encoders, muxer & filewriter
     if (!AddCodecs(graphBuilder, info)) return false;
     //setup graph controls
     mediaControl = graphBuilder as IMediaControl;
     mediaSeeking = tsreaderSource as IMediaSeeking;
     mediaEvt = graphBuilder as IMediaEventEx;
     mediaPos = graphBuilder as IMediaPosition;
     //get file duration
     Log.Info("TSReader2MP4: Get duration of recording");
     long lTime = 5 * 60 * 60;
     lTime *= 10000000;
     long pStop = 0;
     hr = mediaSeeking.SetPositions(new DsLong(lTime), AMSeekingSeekingFlags.AbsolutePositioning, new DsLong(pStop),
                                    AMSeekingSeekingFlags.NoPositioning);
     if (hr == 0)
     {
       long lStreamPos;
       mediaSeeking.GetCurrentPosition(out lStreamPos); // stream position
       m_dDuration = lStreamPos;
       lTime = 0;
       mediaSeeking.SetPositions(new DsLong(lTime), AMSeekingSeekingFlags.AbsolutePositioning, new DsLong(pStop),
                                 AMSeekingSeekingFlags.NoPositioning);
     }
     double duration = m_dDuration / 10000000d;
     Log.Info("TSReader2MP4: recording duration: {0}", MediaPortal.Util.Utils.SecondsToHMSString((int)duration));
     //run the graph to initialize the filters to be sure
     hr = mediaControl.Run();
     if (hr != 0)
     {
       Log.Error("TSReader2MP4: FAILED: unable to start graph :0x{0:X}", hr);
       Cleanup();
       return false;
     }
     int maxCount = 20;
     while (true)
     {
       long lCurrent;
       mediaSeeking.GetCurrentPosition(out lCurrent);
       double dpos = (double)lCurrent;
       dpos /= 10000000d;
       System.Threading.Thread.Sleep(100);
       if (dpos >= 2.0d) break;
       maxCount--;
       if (maxCount <= 0) break;
     }
     mediaControl.Stop();
     FilterState state;
     mediaControl.GetState(500, out state);
     GC.Collect();
     GC.Collect();
     GC.Collect();
     GC.WaitForPendingFinalizers();
     graphBuilder.RemoveFilter(mp4Muxer);
     graphBuilder.RemoveFilter(h264Encoder);
     graphBuilder.RemoveFilter(aacEncoder);
     graphBuilder.RemoveFilter((IBaseFilter)fileWriterFilter);
     if (!AddCodecs(graphBuilder, info)) return false;
     //Set Encoder quality & Muxer settings
     if (!EncoderSet(graphBuilder, info)) return false;
     //start transcoding - run the graph
     Log.Info("TSReader2MP4: start transcoding");
     //setup flow control
     //need to leverage CBAsePin, CPullPin & IAsyncReader methods.
     IAsyncReader synchVideo = null;
     mediaSample = VideoCodec as IMediaSample;
     hr = synchVideo.SyncReadAligned(mediaSample);
     //So we only parse decoder output whent the encoders are ready.
     hr = mediaControl.Run();
     if (hr != 0)
     {
       Log.Error("TSReader2MP4: FAILED:unable to start graph :0x{0:X}", hr);
       Cleanup();
       return false;
     }
   }
   catch (Exception ex)
   {
     Log.Error("TSReader2MP4: Unable create graph: {0}", ex.Message);
     Cleanup();
     return false;
   }
   return true;
 }
开发者ID:arangas,项目名称:MediaPortal-1,代码行数:101,代码来源:TSReader2MP4.cs

示例6: Exception

        /// <summary> sample callback, NOT USED. </summary>
        int ISampleGrabberCB.SampleCB(double SampleTime, IMediaSample pSample)
        {
            if (!m_bGotOne)
            {
                // Set bGotOne to prevent further calls until we
                // request a new bitmap.
                m_bGotOne = true;
                IntPtr pBuffer;

                pSample.GetPointer(out pBuffer);
                int iBufferLen = pSample.GetSize();

                if (pSample.GetSize() > m_stride*m_videoHeight)
                {
                    throw new Exception("Buffer is wrong size");
                }

                NativeMethods.CopyMemory(m_handle, pBuffer, m_stride*m_videoHeight);

                // Picture is ready.
                m_PictureReady.Set();
            }

            Marshal.ReleaseComObject(pSample);
            return 0;
        }
开发者ID:duyisu,项目名称:MissionPlanner,代码行数:27,代码来源:OSDVideo.cs

示例7: CxSampleGrabberEventArgs

 /// <summary>
 /// �R���X�g���N�^ (�����l�w��)
 /// </summary>
 /// <param name="sample_time">�T���v���^�C��</param>
 /// <param name="sample_data">�T���v���f�[�^</param>
 public CxSampleGrabberEventArgs(double sample_time, IMediaSample sample_data)
 {
     SampleTime = sample_time;
     SampleData = sample_data;
     if (sample_data != null)
     {
         sample_data.GetPointer(ref m_Address);
         m_Length = sample_data.GetSize();
     }
 }
开发者ID:cogorou,项目名称:DSLab,代码行数:15,代码来源:CxSampleGrabberCB.cs

示例8: SampleCB

 /// <summary>
 /// receives a pointer to the media sample.
 /// </summary>
 /// <param name="sampleTime">Starting time of the sample, in seconds.</param>
 /// <param name="pSample">Pointer to the IMediaSample interface of the sample.</param>
 /// <returns></returns>
 public int SampleCB(double sampleTime, IMediaSample pSample)
 {
     return 0;
 }
开发者ID:supertanglang,项目名称:RTSPSource,代码行数:10,代码来源:SampleGrabberCallback.cs

示例9: AMMediaType

        int ISampleGrabberCB.SampleCB(double sampleTime, IMediaSample pSample)
        {
            var mediaType = new AMMediaType();

            /* We query for the media type the sample grabber is using */
            int hr = m_sampleGrabber.GetConnectedMediaType(mediaType);

            var videoInfo = new VideoInfoHeader();

            /* 'Cast' the pointer to our managed struct */
            Marshal.PtrToStructure(mediaType.formatPtr, videoInfo);

            /* The stride is "How many bytes across for each pixel line (0 to width)" */
            int stride = Math.Abs(videoInfo.BmiHeader.Width * (videoInfo.BmiHeader.BitCount / 8 /* eight bits per byte */));
            int width = videoInfo.BmiHeader.Width;
            int height = videoInfo.BmiHeader.Height;

            if (m_videoFrame == null)
                InitializeBitmapFrame(width, height);

            if (m_videoFrame == null)
                return 0;

            BitmapData bmpData = m_videoFrame.LockBits(new Rectangle(0, 0, width, height),
                                                       ImageLockMode.ReadWrite,
                                                       PixelFormat.Format24bppRgb);

            /* Get the pointer to the pixels */
            IntPtr pBmp = bmpData.Scan0;

            IntPtr samplePtr;

            /* Get the native pointer to the sample */
            pSample.GetPointer(out samplePtr);

            int pSize = stride * height;

            /* Copy the memory from the sample pointer to our bitmap pixel pointer */
            CopyMemory(pBmp, samplePtr, pSize);

            m_videoFrame.UnlockBits(bmpData);

            InvokeNewVideoSample(new VideoSampleArgs { VideoFrame = m_videoFrame });

            DsUtils.FreeAMMediaType(mediaType);

            /* Dereference the sample COM object */
            Marshal.ReleaseComObject(pSample);
            return 0;
        }
开发者ID:JayBeavers,项目名称:WPF-MediaKit,代码行数:50,代码来源:VideoCapturePlayer.cs

示例10: SetTimeStamps

        // Calculate the timestamps based on the frame number and the frames per second
        public override int SetTimeStamps(IMediaSample pSample)
        {
            // Calculate the start/end times based on the current frame number
            // and frame rate
            DsLong rtStart = new DsLong(m_iFrameNumber * m_FPS);
            DsLong rtStop  = new DsLong(rtStart + m_FPS);

            // Set the times into the sample
            int hr = pSample.SetTime(rtStart, rtStop);

            return hr;
        }
开发者ID:OmerMor,项目名称:DirectShowLib-FORK,代码行数:13,代码来源:BuildGraph.cs

示例11:

 /// <summary> sample callback, NOT USED. </summary>
 int ISampleGrabberCB.SampleCB( double SampleTime, IMediaSample pSample )
 {
     Trace.WriteLine( "!!CB: ISampleGrabberCB.SampleCB" );
     return 0;
 }
开发者ID:pmontu,项目名称:Experiments,代码行数:6,代码来源:MainForm.cs

示例12: SetTimeStamps

    /// <summary>
    /// Calculate the timestamps based on the frame number and the frames per second.
    /// </summary>
    /// <param name="sample">The <see cref="IMediaSample"/> to be timed.</param>
    /// <returns>0 = success, negative values for errors</returns>
    public override int SetTimeStamps(IMediaSample sample)
    {
      // Calculate the start/end times based on the current frame number
      // and frame rate
      DsLong start = new DsLong(this.FrameNumber * this.framesPerSecond);
      DsLong stop = new DsLong(start + this.framesPerSecond);

      // Set the times into the sample
      int hr = sample.SetTime(start, stop);

      return hr;
    }
开发者ID:DeSciL,项目名称:Ogama,代码行数:17,代码来源:ImageFromVectorGraphics.cs

示例13: NotImplementedException

 int IMemAllocator.ReleaseBuffer(IMediaSample pBuffer)
 {
     throw new NotImplementedException();
 }
开发者ID:sgraf812,项目名称:crystalmpq,代码行数:4,代码来源:ManagedMemAllocator.cs

示例14: SampleCB

 // ISampleGrabberCB methods
 public int SampleCB(double SampleTime, IMediaSample pSample)
 {
     Marshal.ReleaseComObject(pSample);
     return 0;
 }
开发者ID:coolsula,项目名称:vidplaycorder,代码行数:6,代码来源:DESCombine.cs

示例15:

		int ISampleGrabberCB.SampleCB( double SampleTime, IMediaSample pSample )
		{
			Trace.Write ("Sample");
			return 0;
		}
开发者ID:rajeper,项目名称:ikarus-osd,代码行数:5,代码来源:Capture.cs


注:本文中的IMediaSample类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。