本文整理汇总了C#中DirectShow.AMMediaType类的典型用法代码示例。如果您正苦于以下问题:C# AMMediaType类的具体用法?C# AMMediaType怎么用?C# AMMediaType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AMMediaType类属于DirectShow命名空间,在下文中一共展示了AMMediaType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckMediaType
public int CheckMediaType(AMMediaType pmt)
{
if (pmt == null) return E_POINTER;
if (pmt.formatPtr == IntPtr.Zero) return VFW_E_INVALIDMEDIATYPE;
if (pmt.majorType != MediaType.Video)
{
return VFW_E_INVALIDMEDIATYPE;
}
if (
pmt.subType != MediaSubType.RGB24
&& pmt.subType != MediaSubType.RGB32
&& pmt.subType != MediaSubType.ARGB32
)
{
return VFW_E_INVALIDMEDIATYPE;
}
BitmapInfoHeader _bmi = pmt;
if (_bmi == null)
{
return E_UNEXPECTED;
}
if (_bmi.Compression != BI_RGB)
{
return VFW_E_TYPE_NOT_ACCEPTED;
}
if (_bmi.BitCount != 24 && _bmi.BitCount != 32)
{
return VFW_E_TYPE_NOT_ACCEPTED;
}
VideoStreamConfigCaps _caps;
GetDefaultCaps(0, out _caps);
if (
_bmi.Width < _caps.MinOutputSize.Width
|| _bmi.Width > _caps.MaxOutputSize.Width
)
{
return VFW_E_INVALIDMEDIATYPE;
}
long _rate = 0;
{
VideoInfoHeader _pvi = pmt;
if (_pvi != null)
{
_rate = _pvi.AvgTimePerFrame;
}
}
{
VideoInfoHeader2 _pvi = pmt;
if (_pvi != null)
{
_rate = _pvi.AvgTimePerFrame;
}
}
if (_rate < _caps.MinFrameInterval || _rate > _caps.MaxFrameInterval)
{
return VFW_E_INVALIDMEDIATYPE;
}
return NOERROR;
}
示例2: Load
public int Load(string pszFileName, AMMediaType pmt)
{
if (_sourceStream != null)
return E_UNEXPECTED;
_fileName = pszFileName;
_sourceStream = new FileStream(pszFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
_streamCreated = true;
return NOERROR;
}
示例3: TryGetType
/// <summary>
/// Tries to create a matching <see cref="AMMediaType"/> for the given <paramref name="streamInfo"/>.
/// </summary>
/// <param name="streamInfo">stream</param>
/// <param name="mediaType">media type</param>
/// <returns><c>true</c> if successful</returns>
public static bool TryGetType(InputstreamInfo streamInfo, out AMMediaType mediaType)
{
Func<InputstreamInfo, AMMediaType> mediaTypeFn;
if (TYPE_MAPPINGS.TryGetValue(streamInfo.CodecInternalName, out mediaTypeFn) || TYPE_MAPPINGS.TryGetValue(streamInfo.CodecName, out mediaTypeFn))
{
mediaType = mediaTypeFn(streamInfo);
return true;
}
mediaType = null;
return false;
}
示例4: CheckMediaType
public int CheckMediaType(AMMediaType pmt)
{
if (pmt == null) return E_POINTER;
if (pmt.formatPtr == IntPtr.Zero) return VFW_E_INVALIDMEDIATYPE;
if (pmt.majorType != MediaType.Video)
{
return VFW_E_INVALIDMEDIATYPE;
}
if (
pmt.subType != MediaSubType.RGB24
&& pmt.subType != MediaSubType.RGB32
&& pmt.subType != MediaSubType.ARGB32
)
{
return VFW_E_INVALIDMEDIATYPE;
}
BitmapInfoHeader bmi = pmt;
if (bmi.Compression != BI_RGB)
{
return VFW_E_TYPE_NOT_ACCEPTED;
}
if (bmi.BitCount != 24 && bmi.BitCount != 32)
{
return VFW_E_TYPE_NOT_ACCEPTED;
}
VideoStreamConfigCaps caps;
GetDefaultCaps(0, out caps);
if (
bmi.Width < caps.MinOutputSize.Width
|| bmi.Width > caps.MaxOutputSize.Width
)
{
return VFW_E_INVALIDMEDIATYPE;
}
var rate = 0L;
VideoInfoHeader pvi = pmt;
if (pvi != null)
{
rate = pvi.AvgTimePerFrame;
}
VideoInfoHeader2 pvi2 = pmt;
if (pvi2 != null)
{
rate = pvi2.AvgTimePerFrame;
}
if (rate < caps.MinFrameInterval || rate > caps.MaxFrameInterval)
{
return VFW_E_INVALIDMEDIATYPE;
}
return NOERROR;
}
示例5: H264_AnnexB
/// <summary>
/// AnnexB formatted h264 bitstream
/// </summary>
/// <param name="streamInfo"></param>
/// <returns></returns>
public static AMMediaType H264_AnnexB(InputstreamInfo streamInfo)
{
int width = (int)streamInfo.Width;
int height = (int)streamInfo.Height;
if (streamInfo.ExtraData.Length > 0)
{
var codecData = new H264CodecData(streamInfo.ExtraData);
SPSUnit spsUnit = new SPSUnit(codecData.SPS);
width = spsUnit.Width();
height = spsUnit.Height();
}
VideoInfoHeader2 vi = new VideoInfoHeader2();
vi.SrcRect.right = width;
vi.SrcRect.bottom = height;
vi.TargetRect.right = width;
vi.TargetRect.bottom = height;
int hcf = HCF(width, height);
vi.PictAspectRatioX = width / hcf;
vi.PictAspectRatioY = height / hcf;
vi.BmiHeader.Width = width;
vi.BmiHeader.Height = height;
vi.BmiHeader.Planes = 1;
vi.BmiHeader.Compression = FOURCC_H264;
AMMediaType amt = new AMMediaType();
amt.majorType = MediaType.Video;
amt.subType = MediaSubType.H264;
amt.temporalCompression = true;
amt.fixedSizeSamples = false;
amt.sampleSize = 1;
amt.SetFormat(vi);
return amt;
}
示例6: ImageOverFilter
public ImageOverFilter()
: base("CSharp Image Overlay Filter")
{
vid.DSplugin = true;
AllocConsole();
IntPtr stdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
SafeFileHandle safeFileHandle = new SafeFileHandle(stdHandle, true);
FileStream fileStream = new FileStream(safeFileHandle, FileAccess.Write);
Encoding encoding = System.Text.Encoding.GetEncoding(MY_CODE_PAGE);
StreamWriter standardOutput = new StreamWriter(fileStream, encoding);
standardOutput.AutoFlush = true;
Console.SetOut(standardOutput);
Console.WriteLine("This text you can see in console window.");
AMMediaType pmt = new AMMediaType() { majorType = MediaType.Video, subType = MediaSubType.YUY2, formatType = MediaType.Video, formatPtr = IntPtr.Zero };
SetMediaType(PinDirection.Input, pmt);
pmt.Free();
pmt = new AMMediaType() { majorType = MediaType.Video, subType = MediaSubType.RGB24, formatType = MediaType.Video, formatPtr = IntPtr.Zero };
SetMediaType(PinDirection.Output, pmt);
pmt.Free();
}
示例7: SetFormat
public static void SetFormat(ref AMMediaType mt, IntPtr pFormat, int nSize)
{
AllocFormat(ref mt, nSize);
if (mt != null && pFormat != IntPtr.Zero)
{
COMHelper.API.CopyMemory(mt.formatPtr, pFormat, mt.formatSize);
}
}
示例8: Free
public static void Free(ref AMMediaType mt)
{
if (mt != null)
{
FreeFormat(ref mt);
if (mt.unkPtr != IntPtr.Zero)
{
Marshal.Release(mt.unkPtr);
mt.unkPtr = IntPtr.Zero;
}
}
}
示例9: AllocFormat
public static void AllocFormat(ref AMMediaType mt, int nSize)
{
FreeFormat(ref mt);
if (mt != null && nSize > 0)
{
mt.formatPtr = Marshal.AllocCoTaskMem(nSize);
mt.formatSize = nSize;
}
}
示例10: CheckMediaType
public override int CheckMediaType(AMMediaType pmt)
{
lock (m_Lock)
{
// The given mediatype as acceptable when the major type is Stream, no subtype and no specific format
if (pmt.majorType == MediaType.Stream && pmt.subType == MediaSubType.Null && pmt.formatType == FormatType.None)
return NOERROR;
return E_FAIL;
}
}
示例11: Copy
public static void Copy(AMMediaType mt, ref AMMediaType _dest)
{
if (((object)_dest) == null)
{
_dest = new AMMediaType();
}
else
{
Free(ref _dest);
}
_dest.majorType = mt.majorType;
_dest.subType = mt.subType;
_dest.fixedSizeSamples = mt.fixedSizeSamples;
_dest.temporalCompression = mt.temporalCompression;
_dest.sampleSize = mt.sampleSize;
_dest.formatType = mt.formatType;
_dest.unkPtr = mt.unkPtr;
_dest.formatPtr = IntPtr.Zero;
_dest.formatSize = mt.formatSize;
if (_dest.unkPtr != IntPtr.Zero)
{
Marshal.AddRef(_dest.unkPtr);
}
if (_dest.formatSize > 0)
{
_dest.formatPtr = Marshal.AllocCoTaskMem(_dest.formatSize);
COMHelper.API.CopyMemory(_dest.formatPtr, mt.formatPtr, _dest.formatSize);
}
}
示例12: SetMediaType
public int SetMediaType(AMMediaType pMediaType)
{
if (m_pUnknown == IntPtr.Zero) return E_NOINTERFACE;
SetMediaTypeProc _Proc = GetProcDelegate<SetMediaTypeProc>(14);
if (_Proc == null) return E_UNEXPECTED;
return (HRESULT)_Proc(
m_pUnknown,
pMediaType
);
}
示例13: ConnectionMediaType
public int ConnectionMediaType(AMMediaType pmt)
{
if (m_pUnknown == IntPtr.Zero) return E_NOINTERFACE;
ConnectionMediaTypeProc _Proc = GetProcDelegate<ConnectionMediaTypeProc>(7);
if (_Proc == null) return E_UNEXPECTED;
return (HRESULT)_Proc(
m_pUnknown,
pmt
);
}
示例14: FreeFormat
public static void FreeFormat(ref AMMediaType mt)
{
if (mt != null)
{
if (mt.formatPtr != IntPtr.Zero)
{
Marshal.FreeCoTaskMem(mt.formatPtr);
mt.formatPtr = IntPtr.Zero;
}
mt.formatSize = 0;
}
}
示例15: AreEquals
public static bool AreEquals(AMMediaType _src, AMMediaType _dst)
{
if ((_dst.majorType != _src.majorType))
{
return false;
}
if (_src.subType != _dst.subType)
{
return false;
}
if (_src.formatType != _dst.formatType)
{
return false;
}
if (_src.formatSize != _dst.formatSize)
{
return false;
}
if (_src.formatSize > 0)
{
byte[] _source = new byte[_src.formatSize];
byte[] _dest = new byte[_src.formatSize];
Marshal.Copy(_src.formatPtr, _source, 0, _source.Length);
Marshal.Copy(_dst.formatPtr, _dest, 0, _dest.Length);
for (int i = 0; i < _source.Length; i++)
{
if (_dest[i] != _source[i]) return false;
}
}
return true;
}