uint8_t tsHeader::getFrame(uint32_t frame,ADMCompressedImage *img) { if(frame>=ListOfFrames.size()) return 0; dmxFrame *pk=ListOfFrames[frame]; // next frame if(frame==(lastFrame+1) && pk->type!=1) { lastFrame++; bool r=tsPacket->read(pk->len,img->data); img->dataLength=pk->len; img->demuxerFrameNo=frame; img->demuxerDts=pk->dts; img->demuxerPts=pk->pts; //printf("[>>>] %d:%02x %02x %02x %02x\n",frame,img->data[0],img->data[1],img->data[2],img->data[3]); getFlags(frame,&(img->flags)); UNESCAPE(); return r; } // Intra ? if(pk->type==1 || pk->type==4) { if(!tsPacket->seek(pk->startAt,pk->index)) return false; bool r=tsPacket->read(pk->len,img->data); img->dataLength=pk->len; img->demuxerFrameNo=frame; img->demuxerDts=pk->dts; img->demuxerPts=pk->pts; getFlags(frame,&(img->flags)); //printf("[>>>] %d:%02x %02x %02x %02x\n",frame,img->data[0],img->data[1],img->data[2],img->data[3]); lastFrame=frame; UNESCAPE(); return r; } // Random frame // Need to rewind, then forward int startPoint=frame; while(startPoint && !ListOfFrames[startPoint]->startAt) startPoint--; printf("[tsDemux] Wanted frame %"PRIu32", going back to frame %"PRIu32", last frame was %"PRIu32",\n",frame,startPoint,lastFrame); pk=ListOfFrames[startPoint]; if(!tsPacket->seek(pk->startAt,pk->index)) { printf("[tsDemux] Failed to rewind to frame %"PRIu32"\n",startPoint); return false; } // Now forward while(startPoint<frame) { pk=ListOfFrames[startPoint]; if(!tsPacket->read(pk->len,img->data)) { printf("[tsDemux] Read fail for frame %"PRIu32"\n",startPoint); lastFrame=0xffffffff; return false; } startPoint++; lastFrame=startPoint; } pk=ListOfFrames[frame]; lastFrame++; bool r=tsPacket->read(pk->len,img->data); img->dataLength=pk->len; img->demuxerFrameNo=frame; img->demuxerDts=pk->dts; img->demuxerPts=pk->pts; //printf("[>>>] %d:%02x %02x %02x %02x\n",frame,img->data[0],img->data[1],img->data[2],img->data[3]); getFlags(frame,&(img->flags)); UNESCAPE(); return r; }
static int fnmatch_helper( const char **pcur, /* pattern */ const char **scur, /* string */ int flags) { const int period = !(flags & FNM_DOTMATCH); const int pathname = flags & FNM_PATHNAME; const int escape = !(flags & FNM_NOESCAPE); const int nocase = flags & FNM_CASEFOLD; const char *ptmp = 0; const char *stmp = 0; const char *p = *pcur; const char *s = *scur; if (period && *s == '.' && *UNESCAPE(p) != '.') /* leading period */ RETURN(FNM_NOMATCH); while (1) { switch (*p) { case '*': do { p++; } while (*p == '*'); if (ISEND(UNESCAPE(p))) { p = UNESCAPE(p); RETURN(0); } if (ISEND(s)) RETURN(FNM_NOMATCH); ptmp = p; stmp = s; continue; case '?': if (ISEND(s)) RETURN(FNM_NOMATCH); p++; Inc(s); continue; case '[': { const char *t; if (ISEND(s)) RETURN(FNM_NOMATCH); if ((t = bracket(p + 1, s, flags)) != 0) { p = t; Inc(s); continue; } goto failed; } } /* ordinary */ p = UNESCAPE(p); if (ISEND(s)) RETURN(ISEND(p) ? 0 : FNM_NOMATCH); if (ISEND(p)) goto failed; if (Compare(p, s) != 0) goto failed; Inc(p); Inc(s); continue; failed: /* try next '*' position */ if (ptmp && stmp) { p = ptmp; Inc(stmp); /* !ISEND(*stmp) */ s = stmp; continue; } RETURN(FNM_NOMATCH); } }