00001 #include <math.h>
00002 #include "standard.h"
00003 #include "rcpcc_hg16.h"
00004 #include "uep_rcpcc.h"
00005 #include "Buffer.h"
00006
00007 extern int debug;
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 buf_rcpc *MakeNewVideoPacket(int Rtype, int N, Buffer *VideoBuff, int CRCBytes, int arq_type)
00023 {
00024 int i, j;
00025 buf_rcpc *a1 = (buf_rcpc *)calloc(1, sizeof(buf_rcpc ));
00026 int K;
00027 unsigned char *vid_char;
00028 int *in_bits;
00029
00030
00031
00032
00033 K=rcpcc16_getK(Rtype,N,CRCBytes);
00034
00035 if (debug >= 2)
00036 printf(" K = %d\n", K);
00037
00038 vid_char = (unsigned char *)calloc(K+CRCBytes , sizeof(char));
00039
00040 for(i=0;i<K;i++) {
00041 bread(VideoBuff, &vid_char[i]);
00042 }
00043
00044 if (debug >= 5) {
00045 printf("vid_char at pack before CRC \n");
00046 for (i=0; i< (K)+ CRCBytes; i++)
00047 printf("%c", vid_char[i]);
00048 printf("\n");
00049 }
00050
00051 MakeCRCBytes(vid_char, K, CRCBytes);
00052
00053
00054 if (debug >= 2) {
00055 printf("vid_char at pack after CRC \n");
00056 for (i=0; i< (K)+ CRCBytes; i++)
00057 printf("%c", vid_char[i]);
00058 printf("\n");
00059 }
00060
00061 in_bits = (int *)malloc( ((K + CRCBytes) * 8) * sizeof(int));
00062
00063 if (debug >= 2)
00064 printf("in_bits\n");
00065 for (i=0; i< ((K+CRCBytes)*8); i++) {
00066 in_bits[i] = (vid_char[i/8] >> (7- (i%8) ) ) & 1;
00067 }
00068
00069 if (debug >= 2)
00070 printf(" after making the CRC bits\n");
00071
00072 for (i=0; i< 4; i++) {
00073 a1->block[i] = (unsigned char *)calloc(N, sizeof(unsigned char));
00074 if (debug >= 2)
00075 printf(" %d\n", a1->block[i] );
00076 }
00077
00078 if (debug >= 2)
00079 printf(" before RCPC encoder\n");
00080 rcpcc16_encode(in_bits,(K+CRCBytes)*8, a1, Rtype, N);
00081 if (debug >= 2)
00082 printf(" after RCPC encoder\n");
00083
00084 free(vid_char);
00085 free(in_bits);
00086
00087 return a1;
00088
00089 }