00001
00017 #include "contributors.h"
00018 #include "global.h"
00019
00034 int RBSPtoSODB(byte *streamBuffer, int last_byte_pos)
00035 {
00036 int ctr_bit, bitoffset;
00037
00038 bitoffset = 0;
00039
00040 ctr_bit = (streamBuffer[last_byte_pos-1] & (0x01<<bitoffset));
00041
00042 while (ctr_bit==0)
00043 {
00044 bitoffset++;
00045 if(bitoffset == 8)
00046 {
00047 if(last_byte_pos == 0)
00048 printf(" Panic: All zero data sequence in RBSP \n");
00049 assert(last_byte_pos != 0);
00050 last_byte_pos -= 1;
00051 bitoffset = 0;
00052 }
00053 ctr_bit= streamBuffer[last_byte_pos-1] & (0x01<<(bitoffset));
00054 }
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 return(last_byte_pos);
00068
00069 }
00070
00071
00085 int EBSPtoRBSP(byte *streamBuffer, int end_bytepos, int begin_bytepos)
00086 {
00087 int i, j, count;
00088 count = 0;
00089
00090 if(end_bytepos < begin_bytepos)
00091 return end_bytepos;
00092
00093 j = begin_bytepos;
00094
00095 for(i = begin_bytepos; i < end_bytepos; i++)
00096 {
00097
00098 if(count == ZEROBYTES_SHORTSTARTCODE && streamBuffer[i] < 0x03)
00099 return -1;
00100 if(count == ZEROBYTES_SHORTSTARTCODE && streamBuffer[i] == 0x03)
00101 {
00102
00103 if((i < end_bytepos-1) && (streamBuffer[i+1] > 0x03))
00104 return -1;
00105
00106 if(i == end_bytepos-1)
00107 return j;
00108
00109 i++;
00110 count = 0;
00111 }
00112 streamBuffer[j] = streamBuffer[i];
00113 if(streamBuffer[i] == 0x00)
00114 count++;
00115 else
00116 count = 0;
00117 j++;
00118 }
00119
00120 return j;
00121 }