private string KsDataFormatToString (ByteArrayReader reader) { StringBuilder result = new StringBuilder (); uint formatSize = reader.ReadU32LE (); uint flags = reader.ReadU32LE (); uint sampleSize = reader.ReadU32LE (); uint reserved = reader.ReadU32LE (); Guid majorFormatGuid = reader.ReadGuid (); string majorFormatStr = MajorFormatToString (majorFormatGuid); Guid subFormatGuid = reader.ReadGuid (); string subFormatStr = SubFormatToString (subFormatGuid); Guid specifierGuid = reader.ReadGuid (); string specifierStr = SpecifierToString (specifierGuid); result.Append ("\r\nKSDATAFORMAT:"); result.AppendFormat ("\r\n FormatSize: {0}", formatSize); result.AppendFormat ("\r\n Flags: {0}", flags); result.AppendFormat ("\r\n SampleSize: {0}", sampleSize); result.AppendFormat ("\r\n Reserved: {0}", reserved); result.AppendFormat ("\r\n MajorFormat: {0}", majorFormatStr); result.AppendFormat ("\r\n SubFormat: {0}", subFormatStr); result.AppendFormat ("\r\n Specifier: {0}", specifierStr); if (specifierStr == "KSDATAFORMAT_SPECIFIER_VIDEOINFO") { Rectangle sourceRect = reader.ReadRectLE (); Rectangle targetRect = reader.ReadRectLE (); uint bitRate = reader.ReadU32LE (); uint bitErrorRate = reader.ReadU32LE (); Int64 avgTimePerFrame = reader.ReadI64LE (); double fps = 10000000.0 / avgTimePerFrame; result.Append ("\r\nKS_VIDEOINFO:"); result.AppendFormat ("\r\n rcSource: ({0}, {1}, {2}, {3})", sourceRect.Left, sourceRect.Top, sourceRect.Right, sourceRect.Bottom); result.AppendFormat ("\r\n rcTarget: ({0}, {1}, {2}, {3})", targetRect.Left, targetRect.Top, targetRect.Right, targetRect.Bottom); result.AppendFormat ("\r\n dwBitRate: {0}", bitRate); result.AppendFormat ("\r\n dwBitErrorRate: {0}", bitErrorRate); result.AppendFormat ("\r\n AvgTimePerFrame: {0} ({1:0.##} fps)", avgTimePerFrame, fps); uint size = reader.ReadU32LE (); int width = reader.ReadI32LE (); int height = reader.ReadI32LE (); ushort planes = reader.ReadU16LE (); ushort bitCount = reader.ReadU16LE (); uint compression = reader.ReadU32LE (); uint sizeImage = reader.ReadU32LE (); int xPelsPerMeter = reader.ReadI32LE (); int yPelsPerMeter = reader.ReadI32LE (); uint clrUsed = reader.ReadU32LE (); uint clrImportant = reader.ReadU32LE (); result.Append ("\r\nKS_BITMAPINFOHEADER:"); result.AppendFormat ("\r\n biSize: {0}", size); result.AppendFormat ("\r\n biWidth: {0}", width); result.AppendFormat ("\r\n biHeight: {0}", height); result.AppendFormat ("\r\n biPlanes: {0}", planes); result.AppendFormat ("\r\n biBitCount: {0}", bitCount); result.AppendFormat ("\r\n biCompression: 0x{0:x8}", compression); result.AppendFormat ("\r\n biSizeImage: {0}", sizeImage); result.AppendFormat ("\r\n biXPelsPerMeter: {0}", xPelsPerMeter); result.AppendFormat ("\r\n biYPelsPerMeter: {0}", yPelsPerMeter); result.AppendFormat ("\r\n biClrUsed: {0}", clrUsed); result.AppendFormat ("\r\n biClrImportant: {0}", clrImportant); } return result.ToString (); }
private string KsReadStreamDataToString (XmlNode dataNode, string directionContext) { StringBuilder body = new StringBuilder (); XmlNode streamHdrNode = dataNode.SelectSingleNode ("value[@type='KSSTREAM_HEADER']"); byte[] streamHdrBuf = Convert.FromBase64String (streamHdrNode.InnerText); ByteArrayReader streamHdrReader = new ByteArrayReader (streamHdrBuf); uint size = streamHdrReader.ReadU32LE (); uint typeSpecificFlags = streamHdrReader.ReadU32LE (); long presentationTime = streamHdrReader.ReadI64LE (); uint presentationNumerator = streamHdrReader.ReadU32LE (); uint presentationDenominator = streamHdrReader.ReadU32LE (); long duration = streamHdrReader.ReadI64LE (); uint frameExtent = streamHdrReader.ReadU32LE (); uint dataUsed = streamHdrReader.ReadU32LE (); uint data = streamHdrReader.ReadU32LE (); uint optionsFlags = streamHdrReader.ReadU32LE (); body.AppendFormat ("[lpOutBuffer direction='{0}']\r\nKSSTREAM_HEADER:", directionContext); body.AppendFormat ("\r\n Size: {0}", size); body.AppendFormat ("\r\n TypeSpecificFlags: 0x{0:x8}", typeSpecificFlags); body.AppendFormat ("\r\n PresentationTime: (Time={0}, {1}/{2})", presentationTime, presentationNumerator, presentationDenominator); body.AppendFormat ("\r\n Duration: {0}", duration); body.AppendFormat ("\r\n FrameExtent: {0}", frameExtent); body.AppendFormat ("\r\n DataUsed: {0}", dataUsed); body.AppendFormat ("\r\n Data: 0x{0:x8}", data); body.AppendFormat ("\r\n OptionsFlags: 0x{0:x8}", optionsFlags); string streamHdrRemainder = streamHdrReader.ReadRemainingBytesAsHexDump (); if (streamHdrRemainder != null) body.AppendFormat ("\r\n\r\n[lpOutBuffer direction='{0}']\r\nRemainder:\r\n{1}", directionContext, streamHdrRemainder); XmlNode frameInfoNode = dataNode.SelectSingleNode ("value[@type='KS_FRAME_INFO']"); byte[] frameInfoBuf = Convert.FromBase64String (frameInfoNode.InnerText); ByteArrayReader frameInfoReader = new ByteArrayReader (frameInfoBuf); uint extendedHeaderSize = frameInfoReader.ReadU32LE (); uint frameFlags = frameInfoReader.ReadU32LE (); long pictureNumber = frameInfoReader.ReadI64LE (); long dropCount = frameInfoReader.ReadI64LE (); uint directDraw = frameInfoReader.ReadU32LE (); uint surfaceHandle = frameInfoReader.ReadU32LE (); Rectangle directDrawRect = frameInfoReader.ReadRectLE (); uint reserved1 = frameInfoReader.ReadU32LE (); uint reserved2 = frameInfoReader.ReadU32LE (); uint reserved3 = frameInfoReader.ReadU32LE (); uint reserved4 = frameInfoReader.ReadU32LE (); body.AppendFormat ("\r\nKS_FRAME_INFO:"); body.AppendFormat ("\r\n ExtendedHeaderSize: {0}", extendedHeaderSize); body.AppendFormat ("\r\n dwFrameFlags: 0x{0:x8}", frameFlags); body.AppendFormat ("\r\n PictureNumber: {0}", pictureNumber); body.AppendFormat ("\r\n DropCount: {0}", dropCount); body.AppendFormat ("\r\n hDirectDraw: 0x{0:x8}", directDraw); body.AppendFormat ("\r\n hSurfaceHandle: 0x{0:x8}", surfaceHandle); body.AppendFormat ("\r\n DirectDrawRect: ({0}, {1}, {2}, {3})", directDrawRect.Left, directDrawRect.Top, directDrawRect.Right, directDrawRect.Bottom); body.AppendFormat ("\r\n Reserved1: {0}", reserved1); body.AppendFormat ("\r\n Reserved2: {0}", reserved2); body.AppendFormat ("\r\n Reserved3: {0}", reserved3); body.AppendFormat ("\r\n Reserved4: {0}", reserved4); string frameInfoRemainder = frameInfoReader.ReadRemainingBytesAsHexDump (); if (frameInfoRemainder != null) body.AppendFormat ("\r\n\r\n[lpOutBuffer direction='{0}']\r\nRemainder:\r\n{1}", directionContext, frameInfoRemainder); return body.ToString (); }