Converting C++ to C# - code to work with MPEG-TS (Transport Stream)
===

*I'M NOT ASKING FOR HELP WITH DEALING WITH PACKETS, JUST PURELY THE CONVERSION*

I need to rewrite some C++ code in C# but am not familiar enough with C# to figure out what to use in place of everything in the original code.

Here's just 1 function from the C++ (it uses a class (BitStream), but I'm not including this here).

I'm not really sure what specific question(s) to ask but any help with this conversion would be greatly appreciated!!

    int ParseTxPkt(BYTE *pTxPkt, BYTE **ppPayload, int &payloadLen, int &pid, int &payload_unit_start_indicator,int &continuity_counter,__int64 &pcr,__int64 &offset,bool peek)
    {
      int transport_error_indicator;
      int transport_priority;
      int transport_scrambling_control;
      int adaptation_field_control;
      int adaptation_field_length;
      int payloadOffset;
      bool pcr_flag;
      int ret=QV_FAILURE;
      BYTE *txPkt;

      BitStream *stream=NULL;  
      payloadOffset=-1;
      payloadLen=0;
      *ppPayload=NULL;
      pcr=-1;
      pcr_flag=false;

      txPkt=pTxPkt;

      stream=new BitStream(txPkt,TX_PKT_SIZE);

      if (stream->GetNextBits(8)!=Sync_Byte) {
        delete stream;
        return QV_FAILURE;
      }

      transport_error_indicator=stream->GetNextBit();
      payload_unit_start_indicator=stream->GetNextBit();
      transport_priority=stream->GetNextBit();
      pid=stream->GetNextBits(13);
      transport_scrambling_control=stream->GetNextBits(2);
      adaptation_field_control=stream->GetNextBits(2);
      continuity_counter=stream->GetNextBits(4);

      switch (adaptation_field_control) {
      case 0:    // reserved
        break;
      case 2:    // no payload
        *ppPayload=NULL;
        payloadLen=0;
        adaptation_field_length=stream->GetNextBits(8);
        if (adaptation_field_length>0 && pcr<0) {
          stream->GetNextBits(3);
          pcr_flag=stream->GetNextBits(1);
          stream->GetNextBits(4);
          if (pcr_flag) {
            pcr=stream->GetNextBits(32);
            pcr=pcr*2+stream->GetNextBits(1);
          }
        }
        ret=QV_SUCCESS;
        break;
      case 1:    // no adaptation field
        payloadOffset=4;
        payloadLen=TX_PKT_SIZE-4;
        *ppPayload=txPkt+payloadOffset;
        ret=QV_SUCCESS;
        break;
      case 3:    // adaptation field and payload
        adaptation_field_length=stream->GetNextBits(8);
        payloadOffset=4+1+adaptation_field_length;
        payloadLen=TX_PKT_SIZE-4-(1+adaptation_field_length);
        *ppPayload=txPkt+payloadOffset;
        if (adaptation_field_length>0) {
          stream->GetNextBits(3);
          pcr_flag=stream->GetNextBits(1);
          stream->GetNextBits(4);
          if (pcr_flag) {
            pcr=stream->GetNextBits(32);      
            pcr=pcr*2+stream->GetNextBits(1);
          }
        }
        ret=QV_SUCCESS;
        break;
      }

      delete stream;
      return ret;
    }