/// <summary> /// Given a byte[] containing a video frame, return the video MediaType. /// </summary> /// <param name="frame"></param> /// <param name="compressionData"></param> /// <returns></returns> private static MediaTypeVideoInfo VideoMediaTypeFromFrame(byte[] frame, out byte[] compressionData) { if (frame == null) { compressionData = null; return(null); } BufferChunk bc = new BufferChunk(frame); short headerSize = bc.NextInt16(); //first short tells us the header size BufferChunk header = bc.NextBufferChunk(headerSize); //The header contains a custom serialization of AM_SAMPLE2_PROPERTIES followed by // AM_MEDIA_TYPE and an optional format type. //AM_SAMPLE2_PROPERTIES BufferChunk AmSample2Properties = header.NextBufferChunk(48); //AM_MEDIA_TYPE MediaTypeVideoInfo vmt = new MediaTypeVideoInfo(); ReconstituteBaseMediaType((MediaType)vmt, header); compressionData = null; if (vmt.FormatType == FormatType.VideoInfo) { ReconstituteVideoFormat(vmt, header, out compressionData); } return(vmt); }
private void ReadPrivatePropertyFromBuffer(BufferChunk buffer) { byte totalLength = buffer.NextByte(); byte prefixLength = buffer.NextByte(); int dataLength = totalLength - prefixLength - 1; // The cast to byte[] does a copy byte[] prefix = (byte[])buffer.NextBufferChunk(prefixLength); byte[] data = null; if (dataLength > 0) { // The cast to byte[] does a copy data = (byte[])buffer.NextBufferChunk(dataLength); } privs[prefix] = data; }
//public static void Pack(BufferChunk chunk, XFORM aTrans) //{ // chunk += aTrans.eDx; // chunk += aTrans.eDy; // chunk += aTrans.eM11; // chunk += aTrans.eM12; // chunk += aTrans.eM21; // chunk += aTrans.eM22; //} //public static void Pack(BufferChunk chunk, TRIVERTEX[] vertices) //{ // int nVertices = vertices.Length; // // Pack the vertices, starting with the length // chunk += nVertices; // for (int i = 0; i < nVertices; i++) // { // chunk += vertices[i].x; // chunk += vertices[i].y; // chunk += vertices[i].Alpha; // chunk += vertices[i].Blue; // chunk += vertices[i].Green; // chunk += vertices[i].Red; // } //} //public static void Pack(BufferChunk chunk, GRADIENT_RECT[] gRect) //{ // int nRects = gRect.Length; // chunk += nRects; // for (int i = 0; i < nRects; i++) // { // chunk += gRect[i].UpperLeft; // chunk += gRect[i].LowerRight; // } //} //public static void Pack(BufferChunk chunk, GBrush aBrush) //{ // chunk += GDI32.EMR_CREATEBRUSHINDIRECT; // chunk += (int)aBrush.Style; // chunk += (int)aBrush.Hatching; // chunk += aBrush.Color; // Pack(chunk, aBrush.UniqueID); //} //public static void Pack(BufferChunk chunk, GPen aPen) //{ // chunk += GDI32.EMR_CREATEPEN; // chunk += (int)aPen.Style; // chunk += 1; // chunk += aPen.Color; // Pack(chunk, aPen.UniqueID); //} //public static void Pack(BufferChunk chunk, GFont aFont) //{ // chunk += GDI32.EMR_EXTCREATEFONTINDIRECTW; // chunk += aFont.FaceName.Length; // chunk += aFont.FaceName; // chunk += (int)aFont.Height; // chunk += (byte)1; // newFont.fLogFont.lfCharSet; // chunk += (byte)0; // newFont.fLogFont.lfClipPrecision; // chunk += (int)0; // newFont.fLogFont.lfEscapement; // chunk += (byte)0; // newFont.fLogFont.lfItalic; // chunk += (int)0; // newFont.fLogFont.lfOrientation; // chunk += (byte)0; // newFont.fLogFont.lfOutPrecision; // chunk += (byte)0; // newFont.fLogFont.lfPitchAndFamily; // chunk += (byte)0; // newFont.fLogFont.lfQuality; // chunk += (byte)0; // newFont.fLogFont.lfStrikeOut; // chunk += (byte)0; // newFont.fLogFont.lfUnderline; // chunk += (int)0; // newFont.fLogFont.lfWeight; // chunk += (int)0; // newFont.fLogFont.lfWidth; // // Write the GUID // Pack(chunk, aFont.UniqueID); //} #endregion #region Unpacking routines //public static GPen UnpackGPen(BufferChunk chunk) //{ // uint penColor; // PenStyle penStyle; // Guid uniqueID; // int penSize; // penStyle = (PenStyle)chunk.NextInt32(); // penSize = chunk.NextInt32(); // penColor = chunk.NextUInt32(); // uniqueID = UnpackGuid(chunk); // GPen aPen = new GPen(penColor, PenType.Cosmetic, PenStyle.Solid, PenJoinStyle.Round, PenEndCap.Round, penSize, uniqueID); // return aPen; //} public static Guid UnpackGuid(BufferChunk chunk) { int bufferLength = chunk.NextInt32(); // How many bytes did we pack byte[] bytes = (byte[])chunk.NextBufferChunk(bufferLength); Guid aGuid = new Guid(bytes); return(aGuid); }
/// <summary> /// Extract a Guid from the next bytes in a BufferChunk /// </summary> /// <param name="bc"></param> /// <returns></returns> private static Guid NextGuid(BufferChunk bc) { int a = NextInt32(bc); short b = NextInt16(bc); short c = NextInt16(bc); byte[] d = (byte[])bc.NextBufferChunk(8); return(new Guid(a, b, c, d)); }
public void ReadDataFromBuffer(BufferChunk buffer) { SSRC = buffer.NextUInt32(); FractionLost = buffer.NextByte(); PacketsLost = ThreeBytesToInt(buffer.NextBufferChunk(3)); ExtendedHighestSequence = buffer.NextUInt32(); Jitter = buffer.NextUInt32(); LastSenderReport = buffer.NextUInt32(); DelaySinceLastSenderReport = buffer.NextUInt32(); }
private void ReadPropertyFromBuffer(int type, BufferChunk buffer) { int dataLength = buffer.NextByte(); if (dataLength != 0) { data[type] = (byte[])buffer.NextBufferChunk(dataLength); } else // Clear value { data[type] = null; } }
/// <summary> /// Take the DirectShow header off the frame and return the remainder. /// Also indicate whether the keyframe flag is set. /// </summary> /// <param name="frame"></param> /// <returns></returns> public static BufferChunk FrameToSample(BufferChunk frame, out bool keyframe) { short headerSize = frame.NextInt16(); //first short tells us the header size BufferChunk header = null; header = frame.NextBufferChunk(headerSize); AM_SAMPLE2_PROPERTIES amsp = ReconstituteSampleProperties(header); if ((amsp.dwSampleFlags & 1) > 0) { keyframe = true; } else { keyframe = false; } //Debug.WriteLine("FrameToSample returning sample of size=" + frame.Length); return(frame); }
public override void ReadDataFromBuffer(BufferChunk buffer) { SSRC = buffer.NextUInt32(); name = (byte[])buffer.NextBufferChunk(4); if(buffer.Length != 0) { data = (byte[])buffer.NextBufferChunk(buffer.Length); } }
/// <summary> /// Converts buffer into member data /// </summary> /// <param name="packet"></param> public override void ReadDataFromBuffer(BufferChunk buffer) { // Read SSRCs for(int i = 0; i < Header.ItemCount; i++) { ssrcs.Add(buffer.NextUInt32()); } // Determine if there is a reason... // SSRCs are 32 bits each, Length is number of 32 bit words in packet data if(Header.Length > Header.ItemCount) { reason = (byte[])buffer.NextBufferChunk(buffer.NextByte()); } }
/// <summary> /// Constructor which creates a generic RtcpPacket from an existing buffer /// </summary> /// <param name="buffer"></param> public RtcpPacket(BufferChunk buffer) { header = new RtcpHeader(buffer.NextBufferChunk(RtcpHeader.SIZE)); this.buffer = buffer.NextBufferChunk(Header.Length * 4); }
/// <summary> /// Removes padding to make sure buffer ends on a 32 bit boundary /// </summary> /// <param name="cbBuffer">Size of buffer in bytes</param> protected static void RemovePadding(BufferChunk buffer) { int padding = buffer.Length % 4; if(padding > 0) { buffer.NextBufferChunk(padding); } }
private void ReadPrivatePropertyFromBuffer(BufferChunk buffer) { byte totalLength = buffer.NextByte(); byte prefixLength = buffer.NextByte(); int dataLength = totalLength - prefixLength - 1; // The cast to byte[] does a copy byte[] prefix = (byte[])buffer.NextBufferChunk(prefixLength); byte[] data = null; if(dataLength > 0) { // The cast to byte[] does a copy data = (byte[])buffer.NextBufferChunk(dataLength); } privs[prefix] = data; }
private void ReadPropertyFromBuffer(int type, BufferChunk buffer) { int dataLength = buffer.NextByte(); if(dataLength != 0) { data[type] = (byte[])buffer.NextBufferChunk(dataLength); } else // Clear value { data[type] = null; } }
/// <summary> /// Sends the plan to server. /// </summary> /// <param name="spots">The spots.</param> /// <param name="nblocks">The nblocks.</param> /// <returns><c>true</c> if OK, <c>false</c> otherwise.</returns> /// <exception cref="SendPlanException"> /// </exception> public virtual bool Send(List <Spot> spots, uint nblocks = 10) { if (!IsConnected) { if (Globals.Debug) { Console.WriteLine(Resources.Server_is_not_connected); } return(false); } BufferChunk.SetNetworking(); var plan = new BufferChunk(); foreach (var spot in spots) { plan.Add(spot); } var len = Spot.Length * nblocks; if (Globals.Debug) { Console.WriteLine(Resources.Sending_plan_to_server + ": length = " + (plan.Length / 1000.0) + " Kb"); } try { while (plan.Length > len) { var bf = plan.NextBufferChunk((int)len); Send(bf); } try { if (plan.Length >= Spot.Length) { var bf = plan.NextBufferChunk(plan.Length); Send(bf); } } catch { throw new SendPlanException(); } } catch { if (plan.Length >= Spot.Length) // send the last portion of data { try { var bf = plan.NextBufferChunk(plan.Length); Send(bf); } catch { throw new SendPlanException(); } } } if (Globals.Debug) { Console.WriteLine(Resources.Plan_sent_to_server); } SendCommand(EPlanCommand.GETSTATE); return(true); }