/* ----------- Global Functions ---------------------------------- */ int mpeg_isvalid(char *path) { int rv = 0; int fd = 0; struct mpg123_frameinfo finfo; fd = mpeg_open(path); if(fd != -1) { if(handle && (mpg123_info(handle->mh, &finfo) == MPG123_OK)) { rv = 1; } mpeg_close(fd); } return rv; }
void mpeg_rd(Data_Obj *dp,Image_File *ifp,index_t x_offset, index_t y_offset,index_t t_offset) { static char *data_ptr; char *pixels; int i; #ifdef BPP_3 int actual_fr_size; #endif /* BPP_3 */ #ifdef QUIP_DEBUG printf("mpeg_rd: IN\n"); #endif /* QUIP_DEBUG */ /* make sure that the sizes match */ if( ! dp_same_dim(dp,ifp->if_dp,0) ) return; /* same # components? */ if( ! dp_same_dim(dp,ifp->if_dp,1) ) return; /* same # columns? */ if( ! dp_same_dim(dp,ifp->if_dp,2) ) return; /* same # rows? */ #ifdef FOOBAR #ifdef BPP_3 /* we don't need to alloate mem for the unused byte, hence 0.75 */ actual_fr_size = ifp->hdr->idp->Size * 0.75 * sizeof(char); data_ptr = dp->dt_data = (char *)malloc(actual_fr_size); #else data_ptr = dp->dt_data = (char *)malloc(ifp->hdr->idp->Size); #endif /* BPP_3 */ #endif /* FOOBAR */ /* Saad must have written that code resetting dp->dt_data!? */ /* note that it was never free'd */ data_ptr = (char *)dp->dt_data; /* mem for decoded image */ pixels = (char *)malloc(ifp->hdr->idp->Size * sizeof(char)); /* Get a single MPEG frame */ GetMPEGFrame(pixels); /* Copy frame to the data object */ for(i=0; i<ifp->hdr->idp->Size; i+=4) { /* For full colour dithering, there are four bytes per pixel: * red, green, blue, and unused. */ *(data_ptr) = *(pixels+i+2); *(data_ptr+1) = *(pixels+i+1); *(data_ptr+2) = *(pixels+i+0); #ifdef BPP_3 data_ptr+=3; #else data_ptr+=4; #endif /* BPP_3 */ } #ifdef QUIP_DEBUG_USING_SDL #ifdef BPP_3 screen->pixels = (char *)memcpy(screen->pixels, dp->dt_data, actual_fr_size); #else screen->pixels = (char *)memcpy(screen->pixels, dp->dt_data, ifp->hdr->idp->Size); #endif /* BPP_3 */ SDL_UpdateRect(screen, 0, 0, 0, 0); #endif /* QUIP_DEBUG_USING_SDL */ // dp->dt_data = (char *)memcpy(dp->dt_data, pixels, ifp->hdr->idp->Size); free(pixels); ifp->if_nfrms ++; if( FILE_FINISHED(ifp) ){ /* BUG? if autoclose is set to no, do we make sure we don't read past eof? */ if( verbose ){ sprintf(error_string, "closing file \"%s\" after reading %ld frames", ifp->if_name,ifp->if_nfrms); advise(error_string); } mpeg_close(ifp); } #ifdef QUIP_DEBUG printf("mpeg_rd: OUT\n"); #endif /* QUIP_DEBUG */ }
int main(int argc, char *argv[]) { /* * step 1: declare the basic data structure used by MPEGlib */ int num = 0, i = 0; mpeg_t *MPEG = NULL; mpeg_file_t *MFILE = NULL; const mpeg_stream_t *mps = NULL; if(argc != 2) { fprintf(stderr, "mpegprobe prints some informations about a given" "mpeg file using MPEGlib detection routines\n"); fprintf(stderr, "usage: %s mpegfile\n", PROGNAME); exit(EXIT_SUCCESS); } /* * step 2: open data source. * mpeg_file_open is the default FILE wrapper used by MPEGlib and will * be always avalaible. It acts just like a plain old fopen() and support * only local files */ MFILE = mpeg_file_open(argv[1], "r"); if(!MFILE) { fprintf(stderr, "unable to open: %s\n", argv[1]); exit(1); } /* * step 3: create a new MPEG descriptor. We need basically a pointer * to a FILE wrapper (mpeg_file_t) and a flag which indicates the kind * of MPEG file to be open. */ MPEG = mpeg_open(MPEG_TYPE_ANY, MFILE, MPEG_DEFAULT_FLAGS, NULL); if(!MPEG) { mpeg_file_close(MFILE); fprintf(stderr, "mpeg_open() failed\n"); exit(1); } /* * step 4a: now we print what we have found. How many streams we have? */ num = mpeg_get_stream_number(MPEG); printf("(%s) found %i A/V streams\n", __FILE__, num); for(i = 0; i < num; i++) { /* * step 4b: get a descriptor for stream #i. This is obviously a constant * reference. We do not free() them. */ mps = mpeg_get_stream_info(MPEG, i); if(mps != NULL) { printf("(%s) stream #%02i:\n", __FILE__, i); /* * step 4c: MPEGlib provides a support function to print main * stream informations on a standard FILE. a value of '0' for * a fields means 'not detected' */ mpeg_print_stream_info(mps, stdout); } else { printf("(%s) WARNING: can't get stream information for stream #%02i\n", __FILE__, i); } } /* * step 5: finalize the MPEG descriptor. Weird things can happen if we do not * follow the REVERSE order of finalization strictly. */ mpeg_close(MPEG); /* * step 5: closing the FILE wrapper */ mpeg_file_close(MFILE); /** * all done! :) */ return 0; }