static void read_head(struct mpstr *mp) { unsigned long head = 0; int i; while(mp->tail) { head <<= 8; head |= read_buf_byte(mp); head &= 0xffffffff; if(head_check(head)) break; } mp->header = head; }
/* * decode a header and write the information * into the frame structure */ int decode_header(struct frame *fr,unsigned long newhead) { if(head_check(newhead) == FALSE) return (0); if( newhead & (1<<20) ) { fr->lsf = (newhead & (1<<19)) ? 0x0 : 0x1; fr->mpeg25 = 0; } else { fr->lsf = 1; fr->mpeg25 = 1; } fr->lay = 4-((newhead>>17)&3); if(fr->mpeg25) { fr->sampling_frequency = 6 + ((newhead>>10)&0x3); }
/* stream mp3 to the peer */ static void mp3streamout_stream(t_mp3streamout *x) { int count = -1, i; struct frame hframe; /* header needs to be included in each packet */ for( i=0; i<x->x_mp3size; i++ ) { // track valid data if ( head_check( *((unsigned long*)x->x_mp3outbuf+i), 3 ) ) { // post( "valid header emitted @ %d (byte %d)", i, i*sizeof(unsigned long) ); } } count = send(x->x_fd, x->x_mp3outbuf, x->x_mp3size, MSG_NOSIGNAL); if(count < 0) { error("mp3streamout~: could not send encoded data to the peer (%d)", count); lame_close( x->lgfp ); x->x_lame = -1; #ifdef _WIN32 closesocket(x->x_fd); #else close(x->x_fd); #endif x->x_fd = -1; outlet_float(x->x_obj.ob_outlet, 0); } else { x->x_outpackets++; if ( x->x_outpackets%100 == 0 ) { // post( "mp3streamout~ : emitted %d bytes (packets = %d)", count, x->x_outpackets ); } } if((count > 0)&&(count != x->x_mp3size)) { error("mp3streamout~: %d bytes skipped", x->x_mp3size - count); } }
int prefix_check (file_t *A, file_t *B) { if (A->size < B->size) { kprintf ("%s is smaller than %s\n", A->filename, B->filename); return -2; } if (A->size < 20 || B->size < 20) { return -1; } int r = head_check (A, B); if (r < 0) { return r; } if (B->size == STORAGE_LEV_START_SIZE) { local_id = 0; return 0; } struct lev_crc32 C1, C2; int sz = sizeof (C1); long long off = B->size - sz; if (vk_pread (A, &C1, sz, off) < 0) { return -3; } if (vk_pread (B, &C2, sz, off) < 0) { return -4; } crc32_complement = ~C1.crc32; if (C1.type != LEV_CRC32) { kprintf ("didn't find LEV_CRC32 record in %s at offset %lld\n", A->filename, off); return -5; } if (memcmp (&C1, &C2, sz)) { kprintf ("last lev_crc32 record don't matched.\n"); return -6; } vkprintf (3, "Last %d bytes are equal (%s, %s).\n", sz, A->filename, B->filename); crc32_complement = crc32_partial (&C1, sz, crc32_complement); return 0; }