bool writeResource(VirtualFile* file, ResourceDatabase* resource) const { bool ok = true; for(unsigned i=0; i<resource->count<Image>(); ++i) ok &= saveJPG(resource->get<Image>(i), file, quality()); return ok; }
bool writeResource(const String& path, ResourceDatabase* resource) const { bool ok = true; for(unsigned i=0; i<resource->count<Image>(); ++i) ok &= saveJPG(resource->get<Image>(i), path, quality()); return ok; }
int msasShowAdminLogon(int confd,ltMsgHead *ltMsgPk,lt_shmHead *lt_MMHead){ ltDbHeadPtr dbPtr; unsigned int sid; char sIp[24]; int i; char strsid[12]; int adminipcount; int ipok; char sqlBuf[1024]; ltDbCursor *tempCursor; LT_DBROW tempRow; sid=0; memset(sIp,0,sizeof(sIp)); ltMsgGetSomeNVar(ltMsgPk,1,"clientip", LT_TYPE_STRING, 19, sIp); dbPtr=lt_dbinit(); lt_db_htmlpage(dbPtr,"utf-8"); adminipcount=0; ipok=0; sprintf(sqlBuf,"select count(*) from msasAdminArea "); tempCursor=ltDbOpenCursor(G_DbCon,sqlBuf); if(tempCursor!=NULL){ tempRow= ltDbFetchRow(tempCursor); if(tempRow!=NULL){ adminipcount=atol(tempRow[0]); } ltDbCloseCursor(tempCursor); } if(adminipcount==0){ ipok=1; }else{ unsigned int s_ip,e_ip,my_ip; my_ip=ntohl(inet_addr(sIp)); sprintf(sqlBuf,"select ipstart,ipend from msasAdminArea "); tempCursor=ltDbOpenCursor(G_DbCon,sqlBuf); if(tempCursor!=NULL){ tempRow= ltDbFetchRow(tempCursor); while(tempRow!=NULL){ s_ip=ntohl(inet_addr(tempRow[0])); e_ip=ntohl(inet_addr(tempRow[1])); if( (my_ip >=s_ip) && (my_ip <=e_ip) ){ ipok=1; break; } } ltDbCloseCursor(tempCursor); } } if(ipok==0){ ltMsgPk->msgpktype=1; lt_TcpResponse(confd,ltMsgPk,2,"lthead",LT_TYPE_STRING,"Content-type: text/html; charset=utf-8\n","lthtml",LT_TYPE_STRING,"<html><body bgcolor=\"#cccccc\">Ip Area error!</body></html>"); ltMsgFree(ltMsgPk); return 0; } for(i=0;i<MAX_ADMIN_SESSION;i++){ if(strcmp(_ltPubInfo->admSession[i].lright,"0000000000000000000000000000000000000000000")==0){ if( (time(0)-_ltPubInfo->admSession[i].lasttime) > MAX_ADMIN_TRYTIMEOUT ){ _ltPubInfo->admSession[i].lSip=0; _ltPubInfo->admSession[i].lasttime=0; _ltPubInfo->admSession[i].trytimes=0; _ltPubInfo->admSession[i].lSid=0; sprintf(_ltPubInfo->admSession[i].lright,"%s","0000000000000000000000000000000000000000000"); } }else{ if( (time(0)-_ltPubInfo->admSession[i].lasttime) > MAX_ADMIN_TIMEOUT ){ _ltPubInfo->admSession[i].lSip=0; _ltPubInfo->admSession[i].lasttime=0; _ltPubInfo->admSession[i].trytimes=0; _ltPubInfo->admSession[i].lSid=0; sprintf(_ltPubInfo->admSession[i].lright,"%s","0000000000000000000000000000000000000000000"); } } } for(i=0;i<MAX_ADMIN_SESSION;i++){ if(_ltPubInfo->admSession[i].lSip==ntohl(inet_addr(sIp)) ){ _ltPubInfo->admSession[i].lSip=0; _ltPubInfo->admSession[i].lasttime=0; _ltPubInfo->admSession[i].trytimes=0; _ltPubInfo->admSession[i].lSid=0; sprintf(_ltPubInfo->admSession[i].lright,"%s","0000000000000000000000000000000000000000000"); } } { gdImagePtr im; int white,red; char caTempDir[128]; char caTempFile[128]; void *pJpg; int lSize; sid=time(0)%10000; sprintf(strsid,"%04d",sid); im = gdImageCreate(40,16); red= gdImageColorAllocate(im, 0, 0, 0); white= gdImageColorAllocate(im, 255, 255, 255); gdImageRectangle(im, 0, 0, 40, 16, red); gdImageString(im, gdFontMediumBold, 5, 2, strsid, white); sprintf(caTempDir,"%s/%lu/",_TMPDIR,ltStrGetId()); if(ltFileIsExist(caTempDir)!=1) { if(mkdir(caTempDir,S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)!=0) { return 0; } } sprintf(caTempFile,"%scheck.jpg",caTempDir); pJpg = gdImageJpegPtr( im,&lSize,-1); gdImageDestroy(im); saveJPG(pJpg,lSize, caTempFile); lt_db_setcookie(dbPtr,"strsid", strsid); lt_dbput_rootvars(dbPtr,1,"file1",caTempFile+strlen(_TMPDIR)+1); ltMsgPk->msgpktype=1; lt_dbput_html(confd,ltMsgPk,dbPtr->doc,"/app/msa/msas/htmlplt/index.htm",dbPtr->head,0); } ltMsgFree(ltMsgPk); lt_dbfree(dbPtr); return 0; }
int main(int argc, char *argv[]) { if(argc < 2) printf("usage: %s matroska_filename\n", argv[0]); char* filename = argv[1]; uint8_t* in_frame = calloc(800*600,1); FILE *fp; if ((fp = fopen(filename,"rb"))!=NULL) { // (rb) read in binary mode printf("opening %s\n", filename); } else { printf("couldn't open %s for read\n",filename); free(in_frame); return (-1); } int i = 0; uint64_t timecode_scale = 0; uint64_t cluster_file_pos = 0; uint64_t end_cluster_file_pos = 0; uint64_t cluster_ts = 0; uint64_t block_ts = 0; uint32_t ID = 0x00000000; int next_byte = 0; uint64_t uisize = 0; uint64_t frame_n = 0; uint64_t seg_inf_size = 0; uint64_t seg_inf_pos = 0; uint64_t tracks_size = 0; uint64_t tracks_pos = 0; uint64_t tmp_size = 0; uint64_t tmp_pos = 0; int video_track = 1; //EBML HEADER ID do { next_byte = fgetc(fp); if(next_byte != EOF) { next_byte &= 0x000000ff; ID <<= 8; ID &= 0xffffff00; ID += next_byte; } else { if(ferror(fp)) printf("An error ocurred when reading the file\n"); fclose(fp); free(in_frame); return(-2); } } while(ID != EBML_ID_HEADER); tmp_size = get_size(fp); printf("ebml header size:%llu - skipping\n", tmp_size); //skip ebml header fseeko(fp, tmp_size, SEEK_CUR); //search for timecode scale in segment info //SEGMENT ID do { next_byte = fgetc(fp); if(next_byte != EOF) { next_byte &= 0x000000ff; ID <<= 8; ID &= 0xffffff00; ID += next_byte; } else { if(ferror(fp)) printf("An error ocurred when reading the file\n"); fclose(fp); free(in_frame); return(-2); } } while(ID != MATROSKA_ID_SEGMENT); //SEGMENT INFO ID do { next_byte = fgetc(fp); if(next_byte != EOF) { next_byte &= 0x000000ff; ID <<= 8; ID &= 0xffffff00; ID += next_byte; } else { if(ferror(fp)) printf("An error ocurred when reading the file\n"); fclose(fp); free(in_frame); return(-2); } } while(ID != MATROSKA_ID_INFO); seg_inf_size = get_size(fp); seg_inf_pos = ftello(fp); //TIMECODE SCALE ID do { next_byte = fgetc(fp); if(next_byte != EOF) { next_byte &= 0x000000ff; ID <<= 8; ID &= 0x00ffff00; ID += next_byte; } else { if(ferror(fp)) printf("An error ocurred when reading the file\n"); fclose(fp); free(in_frame); return(-2); } } while((ID != MATROSKA_ID_TIMECODESCALE) && (ftello(fp) < (seg_inf_pos + seg_inf_size))); //get timecode scale int ts_size = get_size(fp); for(i=0; i< ts_size; i++) { next_byte = fgetc(fp); if(next_byte != EOF) { next_byte &= 0x000000ff; timecode_scale <<= 8; timecode_scale &= 0xffffffffffffff00; timecode_scale += next_byte; } else { if(ferror(fp)) printf("An error ocurred when reading the file\n"); fclose(fp); free(in_frame); return(-2); } } printf("timecode scale is %llu\n", timecode_scale); //SEGMENT TRACKS do { next_byte = fgetc(fp); if(next_byte != EOF) { next_byte &= 0x000000ff; ID <<= 8; ID &= 0xffffff00; ID += next_byte; } else { if(ferror(fp)) printf("An error ocurred when reading the file\n"); fclose(fp); free(in_frame); return(-2); } } while(ID != MATROSKA_ID_TRACKS); tracks_size = get_size(fp); tracks_pos = ftello(fp); //printf("tracks info size: %llu - skip to pos %llu\n", tmp_size, tmp_pos+tmp_size); //skip segment tracks header //fseeko(fp, tmp_size, SEEK_CUR); int track_n = 1; int is_video = 0; do { next_byte = fgetc(fp); if(next_byte != EOF) { next_byte &= 0x000000ff; if(next_byte == MATROSKA_ID_TRACKENTRY) { //check track number and type //if its a video track register number and skip rest of tracks header tmp_size = get_size(fp); tmp_pos = ftello(fp); track_n = 0; int skip = 0; do { next_byte = fgetc(fp); if(next_byte != EOF) { next_byte &= 0x000000ff; if(next_byte == MATROSKA_ID_TRACKNUMBER) { int nsize = get_size(fp); track_n = get_ts(fp, nsize); } else if(next_byte == MATROSKA_ID_TRACKTYPE) { int nsize = get_size(fp); if(get_ts(fp, nsize) == 1) is_video = 1; else skip = 1; //skip track - not a video track } else if (next_byte == 0x73) //0x73c5 UID { next_byte = fgetc(fp); if(next_byte != EOF) { next_byte &=0x000000ff; if(next_byte == 0xc5) //track uid { int uid_size = get_size(fp); fseeko(fp, uid_size, SEEK_CUR); //skip uid } } else { if(ferror(fp)) printf("An error ocurred when reading the file\n"); fclose(fp); free(in_frame); return(-2); } } } else { if(ferror(fp)) printf("An error ocurred when reading the file\n"); fclose(fp); free(in_frame); return(-2); } if(is_video && track_n) { video_track = track_n; printf("video track at index %d\n", video_track); break; } } while((ftello(fp) < (tmp_pos + tmp_size)) && !skip); fseeko(fp, tmp_pos + tmp_size, SEEK_SET); } } else { if(ferror(fp)) printf("An error ocurred when reading the file\n"); fclose(fp); free(in_frame); return(-2); } } while((ftello(fp) < (tracks_pos + tracks_size)) && !is_video); //search for clusters while(1) { do { next_byte = fgetc(fp); if(next_byte != EOF) { next_byte &= 0x000000ff; //if(ftello(fp) == 5553) // printf("ID is 0x%08X next is 0x%08X\n", ID, next_byte); ID <<= 8; ID &= 0xffffff00; ID += next_byte; } else { if(ferror(fp)) printf("An error ocurred when reading the file\n"); fclose(fp); free(in_frame); return(-2); } } while(ID != MATROSKA_ID_CLUSTER); cluster_file_pos = ftello(fp); printf("cluster found at position 0x%016X\n", cluster_file_pos-4); //get size end_cluster_file_pos = get_size(fp); end_cluster_file_pos += cluster_file_pos; next_byte = fgetc(fp); if(next_byte != EOF) { next_byte &= 0x000000ff; } else { if(ferror(fp)) printf("An error ocurred when reading the file\n"); fclose(fp); free(in_frame); return(-2); } if(next_byte == MATROSKA_ID_CLUSTERTIMECODE) { //printf("cluster time code found at position 0x%016X\n", ftello(fp)); uisize = get_size(fp); cluster_ts = get_ts(fp, uisize); //printf("cluster timestamp is %llu ms\n", cluster_ts); } else { printf("found 0x%02X instead of 0xE7 - We must have arrived to the Seek Head block - finish\n", next_byte); printf("extracted %llu frames\n", frame_n); fclose(fp); free(in_frame); return (1); } uint64_t bgsize = 0; uint64_t bsize = 0; uint64_t fstart = 0; uint64_t fend = 0; uint64_t f_ts = 0; uint64_t block_start_pos = 0; //get frame time stamp and frame data do { next_byte = fgetc(fp); if(next_byte != EOF) { next_byte &= 0x000000ff; if(next_byte == MATROSKA_ID_BLOCKGROUP) { //printf("found block group at %llu \n", ftello(fp)); bgsize = get_size(fp); next_byte = fgetc(fp); if(next_byte != EOF) { next_byte &= 0x000000ff; if(next_byte == MATROSKA_ID_BLOCK) { block_start_pos = ftello(fp); //printf("found block at %llu \n", block_start_pos); bsize = get_size(fp); //only 1 uint8_t (1-video 2-audio) //video or audio ? if(get_size(fp) == video_track) { printf("found video frame\n"); //timestamp - allways 2 bytes f_ts = cluster_ts; f_ts += get_frame_delta(fp); //empty byte before frame next_byte = fgetc(fp); if(next_byte == EOF) { if(ferror(fp)) printf("An error ocurred when reading the file\n"); fclose(fp); free(in_frame); return(-2); } if(next_byte != 0) printf("frame flags set to 0x%02X\n", next_byte); //frame if( (bsize-4) > 0) { fread(in_frame, 1, bsize-4, fp); char image_file[80]; sprintf( image_file, "frame_%016llu_ts-%016llu.jpg", frame_n, f_ts ); frame_n++; printf("saving %s\n", image_file); saveJPG(image_file, bsize-4, in_frame); } else printf("frame is empty - skip it\n"); } else { printf("found non video frame - skip it\n"); fseeko(fp, bsize-1, SEEK_CUR); } } } else { if(ferror(fp)) printf("An error ocurred when reading the file\n"); fclose(fp); free(in_frame); return(-2); } } else if(next_byte == MATROSKA_ID_SIMPLEBLOCK) { block_start_pos = ftello(fp); printf("found simple block at %llu\n", block_start_pos); bsize = get_size(fp); //video or audio if(get_size(fp) == video_track) { printf("found video frame\n"); //timestamp - allways 2 bytes f_ts = cluster_ts; f_ts += get_frame_delta(fp); //empty byte before frame next_byte = fgetc(fp); if(next_byte == EOF) { if(ferror(fp)) printf("An error ocurred when reading the file\n"); fclose(fp); free(in_frame); return(-2); } if(next_byte != 0) printf("frame flags set to 0x%02X \n", next_byte); //frame if( (bsize-4) > 0) { fread(in_frame, 1, bsize-4, fp); char image_file[80]; sprintf( image_file, "frame_%016llu_ts-%016llu.jpg", frame_n, f_ts ); frame_n++; printf("saving %s\n", image_file); saveJPG(image_file, bsize-4, in_frame); } else printf("frame is empty - skip it\n"); } else printf("not a video frame - skip it\n"); } } else { if(ferror(fp)) printf("An error ocurred when reading the file\n"); fclose(fp); free(in_frame); return(-2); } } while( ftello(fp) < end_cluster_file_pos); } printf("extracted %llu frames\n", frame_n); fclose(fp); free(in_frame); return 0; }