private void TestFormat()
        {
            int i;
            IWMOutputMediaProps iProp;

            m_read.GetOutputFormatCount(1, out i);
            Debug.Assert(i > 0);

            m_read.GetOutputFormat(1, 1, out iProp);
            Debug.Assert(iProp != null);
        }
示例#2
0
        private static int[] GetPCMOutputNumbers(IWMSyncReader Reader, uint OutputNumber)
        {
            var  result      = new List <int>();
            uint FormatCount = 0;

            Reader.GetOutputFormatCount(OutputNumber, out FormatCount);
            int    BufferSize = Marshal.SizeOf(typeof(WM_MEDIA_TYPE)) + Marshal.SizeOf(typeof(WaveFormat));
            IntPtr buffer     = Marshal.AllocCoTaskMem(BufferSize);

            try
            {
                for (int i = 0; i < FormatCount; i++)
                {
                    IWMOutputMediaProps Props = null;
                    int           size        = 0;
                    WM_MEDIA_TYPE mt;
                    Reader.GetOutputFormat(OutputNumber, (uint)i, out Props);
                    Props.GetMediaType(IntPtr.Zero, ref size);
                    if (size > BufferSize)
                    {
                        BufferSize = size;
                        Marshal.FreeCoTaskMem(buffer);
                        buffer = Marshal.AllocCoTaskMem(BufferSize);
                    }
                    Props.GetMediaType(buffer, ref size);
                    mt = (WM_MEDIA_TYPE)Marshal.PtrToStructure(buffer, typeof(WM_MEDIA_TYPE));
                    if ((mt.majortype == MediaTypes.WMMEDIATYPE_Audio) &&
                        (mt.subtype == MediaTypes.WMMEDIASUBTYPE_PCM) &&
                        (mt.formattype == MediaTypes.WMFORMAT_WaveFormatEx) &&
                        (mt.cbFormat >= WAVE_FORMAT_EX_SIZE))
                    {
                        result.Add(i);
                    }
                }
            }
            finally
            {
                Marshal.FreeCoTaskMem(buffer);
            }
            return(result.ToArray());
        }
示例#3
0
 private static int[] GetPCMOutputNumbers(IWMSyncReader Reader, uint OutputNumber)
 {
     var result = new List<int>();
     uint FormatCount = 0;
     Reader.GetOutputFormatCount(OutputNumber, out FormatCount);
     int BufferSize = Marshal.SizeOf(typeof(WM_MEDIA_TYPE)) + Marshal.SizeOf(typeof(WaveFormat));
     IntPtr buffer = Marshal.AllocCoTaskMem(BufferSize);
     try
     {
         for (int i = 0; i < FormatCount; i++)
         {
             IWMOutputMediaProps Props = null;
             int size = 0;
             WM_MEDIA_TYPE mt;
             Reader.GetOutputFormat(OutputNumber, (uint)i, out Props);
             Props.GetMediaType(IntPtr.Zero, ref size);
             if (size > BufferSize)
             {
                 BufferSize = size;
                 Marshal.FreeCoTaskMem(buffer);
                 buffer = Marshal.AllocCoTaskMem(BufferSize);
             }
             Props.GetMediaType(buffer, ref size);
             mt = (WM_MEDIA_TYPE)Marshal.PtrToStructure(buffer, typeof(WM_MEDIA_TYPE));
             if ((mt.majortype == MediaTypes.WMMEDIATYPE_Audio) &&
                  (mt.subtype == MediaTypes.WMMEDIASUBTYPE_PCM) &&
                  (mt.formattype == MediaTypes.WMFORMAT_WaveFormatEx) &&
                  (mt.cbFormat >= WAVE_FORMAT_EX_SIZE))
             {
                 result.Add(i);
             }
         }
     }
     finally
     {
         Marshal.FreeCoTaskMem(buffer);
     }
     return result.ToArray();
 }
示例#4
0
        public void FindVideoOutputFormat(uint outputNum, ref WM_MEDIA_TYPE mediaType, ref Guid subtype, ref VideoInfoHeader outputVideoInfoHeader)
        {
            IWMOutputMediaProps readerOutputProps = null;
            uint bufferSize = (uint)(Marshal.SizeOf(typeof(WM_MEDIA_TYPE)) + Marshal.SizeOf(typeof(VideoInfoHeader)));
            uint formatCount;

            Logger.WriteLogMessage("Finding video output formats for reader, output [" + outputNum + "].");

            _reader.GetOutputFormatCount(outputNum, out formatCount);

            Logger.WriteLogMessage("Reader can produce " + formatCount + " possible video output formats.");

            IntPtr buffer = Marshal.AllocCoTaskMem((int)bufferSize);

            try
            {
                for (uint j = 0; j < formatCount; j++)
                {
                    uint size = 0;

                    _reader.GetOutputFormat(outputNum, j, out readerOutputProps);

                    readerOutputProps.GetMediaType(IntPtr.Zero, ref size);

                    if (size > bufferSize)
                    {
                        bufferSize = size;
                        Marshal.FreeCoTaskMem(buffer);
                        buffer = Marshal.AllocCoTaskMem((int)bufferSize);
                    }

                    readerOutputProps.GetMediaType(buffer, ref size);

                    mediaType = (WM_MEDIA_TYPE)Marshal.PtrToStructure(buffer, typeof(WM_MEDIA_TYPE));

                    if (mediaType.formattype == FormatTypes.WMFORMAT_VideoInfo)
                    {
                        Logger.WriteLogMessage("Walking output format [" + j + "], format type [" + GetFormatTypeName(mediaType.formattype) + "], subtype [" + GetSubTypeName(mediaType.subtype) + "], sample size [" + mediaType.lSampleSize + "].");

                        //
                        // NOTE: only look for RGB subtypes
                        //
                        if ((mediaType.subtype == MediaSubTypes.WMMEDIASUBTYPE_RGB555) ||
                            (mediaType.subtype == MediaSubTypes.WMMEDIASUBTYPE_RGB24) ||
                            (mediaType.subtype == MediaSubTypes.WMMEDIASUBTYPE_RGB32))
                        {
                            Logger.WriteLogMessage("- Found RGB555, RGB24 or RGB32 sub type, grabbing VideoInfoHeader.");

                            subtype = mediaType.subtype;

                            outputVideoInfoHeader = (VideoInfoHeader)Marshal.PtrToStructure(mediaType.pbFormat, typeof(VideoInfoHeader));

                            Logger.WriteLogMessage("- width [" + outputVideoInfoHeader.bmiHeader.biWidth + "], height [" + outputVideoInfoHeader.bmiHeader.biHeight + "], dwBitrate [" + outputVideoInfoHeader.dwBitRate + "], dwBitErrorRate [" + outputVideoInfoHeader.dwBitErrorRate + "].");

                            _reader.SetOutputProps(outputNum, readerOutputProps);
                            break;
                        }
                    }
                }
            }
            finally
            {
                Marshal.FreeCoTaskMem(buffer);
            }

            Marshal.ReleaseComObject(readerOutputProps);
        }