This is a mirror of official site: http://jasper-net.blogspot.com/

C# .NET RTP MJPEG Player

| Sunday, June 6, 2010
Introduction

This is an implemention of RTP/MJPEG protocol in C#. I wrote this code back in 2005
Background

This code was used for Elphel network cameras, multicasting RTP/MJPEG but it should be compatible with almost all RTP/MJPEG technologies. This code was written from reading the related RFCs.


Using the code

A brief description of how to use the article or code. The class names, the methods and properties, any tricks or tips.  

Blocks of code should be set as style "Formatted" like this:

RtpPacket.cs

Collapse
using System;
using System.Collections.Generic;
using System.Text;

namespace RTPLib
{
   public class RtpPacket
   {
       public static readonly int rtp_version = 2; /* the version of RTP supported */
       public static readonly int rtp_length = 12; /* fixed RTP packet header size */
       public int version; /* the version of RTP should be 2 */
       public byte padding; /* the padding flag **/
       public byte extension; /* the extension flag - if any extra headers for higher protocol */
       public int csrc_count; /* the source count */
       public bool marker; /* the marker status */
       public int payload_type;    /* the type of payload  */
       public ushort sequence_no;  /* the sequence number of the RTP packet */
       public uint timestamp;  /* the timestamp of the RTP packet */
       public uint source_id;  /* the source id  of the RTP packet */


       public RtpPacket(byte[] _data)
       {
           decode(_data);
       }

       public void decode(byte[] data)
       {
           /*byte[] data = new byte[12];
           Array.Copy(_data, data, 12);*/ /* there should be no need to copy the header */
           version = data[0] >> 6;
           padding = (byte)(0x1 & (data[0] >> 5));
           extension = (byte)(0x1 & (data[0] >> 4));
           csrc_count = 0x1F & (data[0]);
           marker = ((data[1] >> 7) == 1);
           payload_type = data[1] & 0x7f; /* we will assume it's 26 -> RTP/MJPEG */
           sequence_no = Utils.HostToNetworkOrderShort(System.BitConverter.ToUInt16(data, 2));
           timestamp = Utils.SwapUnsignedInt(System.BitConverter.ToUInt32(data, 4));
           source_id = Utils.SwapUnsignedInt(System.BitConverter.ToUInt32(data, 8));
       }
   }
}

Read more: Codeproject

Posted via email from jasper22's posterous

0 comments: