Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static GstFlowReturn
- gst_destool_chain (GstPad * pad, GstBuffer * inbuf)
- {
- GstDesTool *filter;
- GstBuffer *outbuf;
- outbuf=NULL;
- filter = GST_DESTOOL (GST_OBJECT_PARENT (pad));
- nFrame++;
- if( ( filter->ptss[filter->ptsUsed] < inbuf->timestamp/1000 ) )
- {
- filter->ptsUsed++;
- gchar* key = g_strdup (g_value_get_string ( g_value_array_get_nth( filter->keys, filter->ptsUsed ) ));
- printf(" --- TimeStamp: %llu --- key changed: %02x %02x %02x %02x %02x %02x %02x %02x\n", inbuf->timestamp/1000, key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7]);
- }
- gchar* key = g_strdup (g_value_get_string ( g_value_array_get_nth( filter->keys, filter->ptsUsed ) ));
- gchar* iv = g_strdup (g_value_get_string ( g_value_array_get_nth( filter->ivs, filter->ptsUsed ) ));
- if (filter->silent == FALSE)
- {
- //Valore dello START_CODE
- guint8 startCode[3] = { 0x00, 0x00, 0x01 };
- guint8 *start = NULL;
- guint8 *temp = NULL;
- guint offset = 0;
- temp = inbuf->data;
- if(inbuf->size < 3){
- printf(" --- frame piu' corto di 3 byte --- STRANO!!!");
- outbuf = gst_buffer_try_new_and_alloc (inbuf->size);
- GST_BUFFER_TIMESTAMP(outbuf)= GST_BUFFER_TIMESTAMP (inbuf);
- GST_BUFFER_DURATION(outbuf)= GST_BUFFER_DURATION (inbuf);
- gst_buffer_set_caps (outbuf, GST_PAD_CAPS (filter->srcpad));
- memcpy( outbuf->data, inbuf->data, inbuf->size );
- return gst_pad_push (filter->srcpad, outbuf);
- }
- guint ind = 0;
- ind = 0;
- guint sizeBuffer = inbuf->size;
- do{
- temp = (guint8*)memmem( inbuf->data + offset, sizeBuffer, startCode, 3 );
- if(temp != NULL){
- #ifdef PRINT
- printf(" --- --- --- ciclo %u --- --- ---\n",++ind);
- printf(" --- --- startcode trovato: %02x %02x %02x %02x\n",temp[0],temp[1],temp[2],temp[3]);
- #endif
- offset = temp - inbuf->data + 3;
- sizeBuffer = inbuf->size - offset;
- start = temp;
- }
- }
- while (temp != NULL && offset < inbuf->size);
- #ifdef PRINT
- printf(" --- --- --- startcode prima di cifrare: %02x %02x %02x %02x\n",start[0],start[1],start[2],start[3]);
- #endif
- if ( start != NULL )
- {
- offset = start - inbuf->data;
- //CIFRATURA
- if(filter->mode==TRUE)
- {
- if ( inbuf->size <= ( offset + 8 ) ){
- printf("-- Frame troppo corto, NON CIFRO --\n");
- outbuf = gst_buffer_try_new_and_alloc (inbuf->size);
- GST_BUFFER_TIMESTAMP(outbuf)= GST_BUFFER_TIMESTAMP (inbuf);
- GST_BUFFER_DURATION(outbuf)= GST_BUFFER_DURATION (inbuf);
- gst_buffer_set_caps (outbuf, GST_PAD_CAPS (filter->srcpad));
- memcpy( outbuf->data, inbuf->data, inbuf->size );
- return gst_pad_push (filter->srcpad, outbuf);
- }
- offset = offset + 8;
- guint padSize = (8 - (inbuf->size - offset) % 8);
- guint newSize = (inbuf->size) + padSize;
- guint pad;
- //Alloco buffer di output
- outbuf = gst_buffer_try_new_and_alloc (newSize);
- if(outbuf == NULL)
- printf("potrebbe essere qui il problema!!!\n");
- GST_BUFFER_TIMESTAMP(outbuf)= GST_BUFFER_TIMESTAMP (inbuf);
- GST_BUFFER_DURATION(outbuf)= GST_BUFFER_DURATION (inbuf);
- gst_buffer_set_caps (outbuf, GST_PAD_CAPS (filter->srcpad));
- memcpy( outbuf->data, inbuf->data, inbuf->size );
- // effettuo il padding
- for( pad = 0; pad < padSize; pad++)
- {
- outbuf->data[ inbuf->size + pad ] = padSize;
- }
- // prepariamo la chiave
- des_check_key = 1;
- DES_key_schedule schedule;
- int ret = DES_set_key ( (des_cblock*)key, &schedule );
- if(ret != 0 )
- printf(" --- (%d) c'e' qualche problema sulle chiavi!!!\n", ret );
- #ifdef PRINT
- else
- printf( " --- (%d) OK chiavi!!!\n", ret );
- #endif
- /*
- des_cblock *desKey = (des_cblock *) filter->key;
- char strKey[sizeof(des_cblock)];
- memcpy(strKey, desKey, sizeof(des_cblock));
- printf( " --- chiave: " );
- int ind;
- for(ind = 0; ind < sizeof(des_cblock); ind++){
- printf(" %x",strKey[ind]);
- }
- printf( "\n" );
- char *keyB64 = base64((unsigned char *) strKey, sizeof(des_cblock));
- printf(" --- key base64: %s (%d)\n", keyB64, (int)strlen(keyB64));
- des_cblock *desIv = (des_cblock *) filter->iv;
- char strIv[sizeof(des_cblock)];
- memcpy(strIv, desIv, sizeof(des_cblock));
- printf( " --- chiave: " );
- for(ind = 0; ind < sizeof(des_cblock); ind++){
- printf(" %x",strIv[ind]);
- }
- printf( "\n" );
- char *ivB64 = base64((unsigned char *) strIv, sizeof(des_cblock));
- printf(" --- iv base64: %s (%d)\n", ivB64, (int)strlen(ivB64));
- */
- DES_cbc_encrypt( outbuf->data + offset, outbuf->data + offset, newSize - offset, &schedule, (des_cblock*)iv, DES_ENCRYPT );
- }
- }
- else
- {
- printf ("begin of frame is not expected start code, dropping\n");
- }
- }
- /* just push out the incoming buffer without touching it */
- //gst_buffer_unref (inbuf);
- return gst_pad_push (filter->srcpad, outbuf);
- }
Add Comment
Please, Sign In to add comment