本文整理汇总了C#中IMediaSample.GetPointer方法的典型用法代码示例。如果您正苦于以下问题:C# IMediaSample.GetPointer方法的具体用法?C# IMediaSample.GetPointer怎么用?C# IMediaSample.GetPointer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMediaSample
的用法示例。
在下文中一共展示了IMediaSample.GetPointer方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: SampleCallback
/// <summary>
/// The callback from the GSSF to populate the sample. This class isn't intended
/// to be overridden. Child classes should instead implement PopulateSample,
/// which this method calls.
/// </summary>
/// <param name="pSample">The sample to populate</param>
/// <returns>HRESULT</returns>
public int SampleCallback(IMediaSample pSample)
{
int hr;
IntPtr pData;
try
{
// Get the buffer into which we will copy the data
hr = pSample.GetPointer(out pData);
if (hr >= 0)
{
// Find out the amount of space in the buffer
int cbData = pSample.GetSize();
lock (this)
{
hr = SetTimeStamps(pSample);
if (hr >= 0)
{
int iRead;
// Populate the sample
hr = PopulateSample(pData, cbData, out iRead);
if (hr >= 0)
{
if (hr == S_Ok) // 1 == End of stream
{
// increment the frame number for next time
m_iFrameNumber++;
}
else
{
m_iFrameNumber = 0;
}
pSample.SetActualDataLength(iRead);
}
}
}
}
}
finally
{
// Release our pointer the the media sample. THIS IS ESSENTIAL! If
// you don't do this, the graph will stop after about 2 samples.
Marshal.ReleaseComObject(pSample);
}
return hr;
}
示例5: 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);
}
示例6: 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();
}
}
示例7: SampleCallback
/// <summary>
/// Called by the GenericSampleSourceFilter. This routine populates the MediaSample.
/// </summary>
/// <param name="pSample">Pointer to a sample</param>
/// <returns>0 = success, 1 = end of stream, negative values for errors</returns>
public virtual int SampleCallback(IMediaSample pSample)
{
int hr;
IntPtr pData;
try
{
// Get the buffer into which we will copy the data
hr = pSample.GetPointer(out pData);
if (hr >= 0)
{
// Set TRUE on every sample for uncompressed frames
hr = pSample.SetSyncPoint(true);
if (hr >= 0)
{
// Find out the amount of space in the buffer
int cbData = pSample.GetSize();
hr = SetTimeStamps(pSample);
if (hr >= 0)
{
int iRead;
// Get copy the data into the sample
hr = GetImage(m_iFrameNumber, pData, cbData, out iRead);
if (hr == 0) // 1 == End of stream
{
pSample.SetActualDataLength(iRead);
// increment the frame number for next time
m_iFrameNumber++;
}
}
}
}
}
finally
{
// Release our pointer the the media sample. THIS IS ESSENTIAL! If
// you don't do this, the graph will stop after about 2 samples.
Marshal.ReleaseComObject(pSample);
}
return hr;
}
示例8: 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;
}
示例9: SyncReadAligned
public int SyncReadAligned(IMediaSample pSample)
{
Monitor.Enter(this);
long start, end;
long mediaStart, mediaEnd;
int size;
int offset;
int hr;
int ans = S_OK;
IntPtr ptr = new IntPtr();
hr = pSample.GetPointer(out ptr);
hr = pSample.GetTime(out start, out end);
hr = pSample.GetMediaTime(out mediaStart, out mediaEnd);
size = pSample.GetSize();
int rescale = DS_RESCALE_FACTOR; // (int)((end - start) / size);
//start += startTime;
offset = (int)(start / rescale);
if ((offset + size) > reader.BufferSize)
{
Memory.Set(ptr, offset, size);
log.InfoFormat("SyncReadAligned went off the end ({0}, {1}, {2})", offset, (offset + size), reader.BufferSize);
size = (int)(reader.BufferSize - offset);
ans = S_FALSE;
}
if ((offset + size) > reader.BufferEnd)
{
log.InfoFormat("SyncReadAligned wait for buffer ({0}, {1}, {2})", offset, (offset + size), reader.BufferEnd);
BufferData(offset + size);
}
log.InfoFormat("SyncReadAligned ({0} / {1} ({2}), {3} / {4}) - {5}, {6}", start, mediaStart, offset, end, mediaEnd, size, rescale);
byte[] buffer = reader.GetBuffer();
Marshal.Copy(buffer, offset, ptr, size);
reader.ReleaseBuffer();
Monitor.Exit(this);
return ans;
}
示例10: Exception
int ISampleGrabberCB.SampleCB(double SampleTime, IMediaSample pSample)
{
if (!gotOne)
{
gotOne = true;
IntPtr pBuffer;
pSample.GetPointer(out pBuffer);
pSample.GetSize();
if (pSample.GetSize() > Stride*Height)
throw new Exception("Buffer is wrong size");
Kernel32.CopyMemory(handle, pBuffer, Stride * Height);
pictureReady.Set();
}
Marshal.ReleaseComObject(pSample);
return 0;
}
示例11: Exception
int ISampleGrabberCB.SampleCB(double sampleTime, IMediaSample sample)
{
if (!_gotPicture)
{
// Set bGotOne to prevent further calls until we
// request a new bitmap.
_gotPicture = true;
IntPtr pBuffer;
sample.GetPointer(out pBuffer);
if (sample.GetSize() > _stride * _height)
{
throw new Exception("Buffer is wrong size");
}
CopyMemory(_handle, pBuffer, _stride * _height);
_pictureReadyResetEvent.Set();
}
Marshal.ReleaseComObject(sample);
return 0;
}
示例12: MediaSampleCB
/// <summary>
/// This routine populates the MediaSample.
/// </summary>
/// <param name="pSample">Pointer to a sample</param>
/// <returns>0 = success, 1 = end of stream, negative values for errors</returns>
public int MediaSampleCB(IMediaSample pSample)
{
int hr;
try
{
IntPtr pData;
hr = pSample.GetPointer(out pData);
if (hr >= 0)
{
hr = pSample.SetSyncPoint(true);
if (hr >= 0)
{
var len = Source.Read(pData, Constants.DShowNumberOfPacketsTS);
if (len != 0)
{
hr = 0;
pSample.SetActualDataLength(len);
}
else
{
//hr = 1;
hr = 0;
}
}
}
}
catch(Exception ex)
{
Log.ErrorException("Error in Sample handler.", ex);
hr = -1;
}
finally
{
Marshal.ReleaseComObject(pSample);
}
return hr;
}