Author: andreas Date: 2011-06-09 01:30:40 -0700 (Thu, 09 Jun 2011) New Revision: 2414 Modified: trunk/platforms/Cross/plugins/Mpeg3Plugin/examplesSqueak.txt trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/audio/mpeg3audio.c trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/changesForSqueak.c trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/mpeg3demux.c trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/mpeg3io.c trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/video/getpicture.c trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/video/macroblocks.c Log: Merging support files from cogvm branch. Modified: trunk/platforms/Cross/plugins/Mpeg3Plugin/examplesSqueak.txt =================================================================== --- trunk/platforms/Cross/plugins/Mpeg3Plugin/examplesSqueak.txt 2011-06-09 08:29:00 UTC (rev 2413) +++ trunk/platforms/Cross/plugins/Mpeg3Plugin/examplesSqueak.txt 2011-06-09 08:30:40 UTC (rev 2414) @@ -1,128 +1,128 @@ -"Find a file" - -MPEGFile isFileValidMPEG: 'randomalien.mpg'. - -"Explore the file" - -| foo | -foo _ MPEGFile openFile: 'randomalien.mpg'. -foo hasVideo. -foo hasAudio. -foo endOfVideo: 0. -foo endOfAudio: 0. -foo audioChannels: 0. -foo audioSamples: 0. -foo audioGetSample: 0. -foo audioSampleRate: 0. -foo videoFrameRate: 0. -foo videoGetFrame: 0. -foo audioGetSample: 0. -foo getTimeCode. -foo videoPreviousFrame: 0. -foo videoSetCPUs: 1. -foo videoSetFrame: 44 stream: 0. -foo setMMX: true. -foo audioSetSample: 44 stream: 0. -foo totalAudioStreams. -foo totalVideoStreams. -foo videoFrames: 0. -foo videoFrameHeight: 0. -foo videoFrameWidth: 0. -foo seekPercentage: 0.5. -foo getPercentage. -foo videoSetCPUs: 1. -foo setMMX: true. -foo closeFile. - ------------------------------------ -"Simply get the video start at 700 and run 50 frames then debug" -"Better code is in the player, don't use this code, but it's an example" - -| foo x y counter fum | - -foo _ MPEGFile openFile: 'randomalien.mpg'. -stream _ 0. -counter _ 0. -y _ foo videoFrameHeight: stream. -x _ foo videoFrameWidth: stream. -fum _ Form extent: x@y depth: 32. -frames _ foo videoFrames: stream. -foo videoSetFrame: 700 stream: stream. -[foo endOfVideo: stream] whileFalse: - [foo videoReadNextFrameInto: fum bits - width: fum width height: fum height stream: stream. - fum displayOn: Display. - (counter _ counter + 1) == 50 ifTrue: [self halt]]. -foo closeFile. - ------------------------------------ -"Play the audio" -"There is more than one way to do this" -"This is my first technically correct try" -"DO not use this code, better code is in the player" - -| foo buffer sound soundOther | - -foo _ MPEGFile openFile: 'randomalien.mpg'. -channels _ foo audioChannels: 0. -sampleRate _ foo audioSampleRate: 0. -totalSamples _ foo audioSamples: 0. -buffer _ ByteArray new: 1024*1024*1. -SoundPlayer startPlayerProcessBufferSize: 8192 rate: sampleRate stereo: true. - -result _ foo audioReadBuffer: buffer stream: 0 channel: 0 samples: 1024*1024//2. -sound _ SampledSound samples: - (SampledSound convertBytesTo16BitSamples: buffer mostSignificantByteFirst: true) - samplingRate: sampleRate. - -result _ foo audioReReadBuffer: buffer stream: 0 channel: 1 samples: 1024*1024//2. -soundOther _ SampledSound samples: - (SampledSound convertBytesTo16BitSamples: buffer mostSignificantByteFirst: true) - samplingRate: sampleRate. - -sound _ MixedSound new - add: sound pan: 0; - add: soundOther pan: 1.0. -sound play - ------------------------------------ -"Ok make it simple for Audio" - -| foo | -form _ Form extent: 320@240 depth: 16. -foo _ MPEGPlayer playFile: 'randomAlien.mpg' onForm: form. -foo playAudioStreamWaitTilDone: 0. - ------------------------------------ -"Ok make it simple for Video" -| foo | -form _ Form extent: 320@240 depth: 32. -foo _ MPEGPlayer playFile: 'randomAlien.mpg' onForm: form. -foo playVideoStreamWaitTilDone: 0. - ------------------------------------ -"Play the video in the background" -| foo | -form _ Form extent: 320@240 depth: 16. -foo _ MPEGPlayer playFile: 'randomAlien.mpg' onForm: form. -foo playVideoStream: 0. -foo inspect. - ------------------------------------ -"Play both in the background" -| foo | -form _ Form extent: 320@240 depth: 16. -foo _ MPEGPlayer playFile: 'randomAlien.mpg' onForm: form. -foo playStream: 0. -foo inspect. - -------------------------- -" In Morphic do " -| foo | -form _ Form extent: 320@240 depth: 32. -morph _ SketchMorph withForm: form. -morph openInWorld. -foo _ MPEGPlayer playFile: 'randomAlien.mpg' onMorph: morph. -foo morph: morph. -foo playStream: 0. -foo inspect. +"Find a file" + +MPEGFile isFileValidMPEG: 'randomalien.mpg'. + +"Explore the file" + +| foo | +foo _ MPEGFile openFile: 'randomalien.mpg'. +foo hasVideo. +foo hasAudio. +foo endOfVideo: 0. +foo endOfAudio: 0. +foo audioChannels: 0. +foo audioSamples: 0. +foo audioGetSample: 0. +foo audioSampleRate: 0. +foo videoFrameRate: 0. +foo videoGetFrame: 0. +foo audioGetSample: 0. +foo getTimeCode. +foo videoPreviousFrame: 0. +foo videoSetCPUs: 1. +foo videoSetFrame: 44 stream: 0. +foo setMMX: true. +foo audioSetSample: 44 stream: 0. +foo totalAudioStreams. +foo totalVideoStreams. +foo videoFrames: 0. +foo videoFrameHeight: 0. +foo videoFrameWidth: 0. +foo seekPercentage: 0.5. +foo getPercentage. +foo videoSetCPUs: 1. +foo setMMX: true. +foo closeFile. + +----------------------------------- +"Simply get the video start at 700 and run 50 frames then debug" +"Better code is in the player, don't use this code, but it's an example" + +| foo x y counter fum | + +foo _ MPEGFile openFile: 'randomalien.mpg'. +stream _ 0. +counter _ 0. +y _ foo videoFrameHeight: stream. +x _ foo videoFrameWidth: stream. +fum _ Form extent: x@y depth: 32. +frames _ foo videoFrames: stream. +foo videoSetFrame: 700 stream: stream. +[foo endOfVideo: stream] whileFalse: + [foo videoReadNextFrameInto: fum bits + width: fum width height: fum height stream: stream. + fum displayOn: Display. + (counter _ counter + 1) == 50 ifTrue: [self halt]]. +foo closeFile. + +----------------------------------- +"Play the audio" +"There is more than one way to do this" +"This is my first technically correct try" +"DO not use this code, better code is in the player" + +| foo buffer sound soundOther | + +foo _ MPEGFile openFile: 'randomalien.mpg'. +channels _ foo audioChannels: 0. +sampleRate _ foo audioSampleRate: 0. +totalSamples _ foo audioSamples: 0. +buffer _ ByteArray new: 1024*1024*1. +SoundPlayer startPlayerProcessBufferSize: 8192 rate: sampleRate stereo: true. + +result _ foo audioReadBuffer: buffer stream: 0 channel: 0 samples: 1024*1024//2. +sound _ SampledSound samples: + (SampledSound convertBytesTo16BitSamples: buffer mostSignificantByteFirst: true) + samplingRate: sampleRate. + +result _ foo audioReReadBuffer: buffer stream: 0 channel: 1 samples: 1024*1024//2. +soundOther _ SampledSound samples: + (SampledSound convertBytesTo16BitSamples: buffer mostSignificantByteFirst: true) + samplingRate: sampleRate. + +sound _ MixedSound new + add: sound pan: 0; + add: soundOther pan: 1.0. +sound play + +----------------------------------- +"Ok make it simple for Audio" + +| foo | +form _ Form extent: 320@240 depth: 16. +foo _ MPEGPlayer playFile: 'randomAlien.mpg' onForm: form. +foo playAudioStreamWaitTilDone: 0. + +----------------------------------- +"Ok make it simple for Video" +| foo | +form _ Form extent: 320@240 depth: 32. +foo _ MPEGPlayer playFile: 'randomAlien.mpg' onForm: form. +foo playVideoStreamWaitTilDone: 0. + +----------------------------------- +"Play the video in the background" +| foo | +form _ Form extent: 320@240 depth: 16. +foo _ MPEGPlayer playFile: 'randomAlien.mpg' onForm: form. +foo playVideoStream: 0. +foo inspect. + +----------------------------------- +"Play both in the background" +| foo | +form _ Form extent: 320@240 depth: 16. +foo _ MPEGPlayer playFile: 'randomAlien.mpg' onForm: form. +foo playStream: 0. +foo inspect. + +------------------------- +" In Morphic do " +| foo | +form _ Form extent: 320@240 depth: 32. +morph _ SketchMorph withForm: form. +morph openInWorld. +foo _ MPEGPlayer playFile: 'randomAlien.mpg' onMorph: morph. +foo morph: morph. +foo playStream: 0. +foo inspect. Modified: trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/audio/mpeg3audio.c =================================================================== --- trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/audio/mpeg3audio.c 2011-06-09 08:29:00 UTC (rev 2413) +++ trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/audio/mpeg3audio.c 2011-06-09 08:30:40 UTC (rev 2414) @@ -258,7 +258,7 @@ mpeg3_t *file = (mpeg3_t *) audio->file; mpeg3_atrack_t *track = (mpeg3_atrack_t *) audio->track; long frame_number; - long byte_position; + long byte_position = 0; double time_position; /* Sample seek wasn't requested */ Modified: trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/changesForSqueak.c =================================================================== --- trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/changesForSqueak.c 2011-06-09 08:29:00 UTC (rev 2413) +++ trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/changesForSqueak.c 2011-06-09 08:30:40 UTC (rev 2414) @@ -6,7 +6,7 @@ * AUTHOR: John McIntosh, and others. * ADDRESS: * EMAIL: [hidden email] -* RCSID: $Id: changesForSqueak.c,v 1.7 2003/02/08 18:23:30 johnmci Exp $ +* RCSID: $Id$ * * NOTES: See change log below. * 12/27/2001 JMM added support to build as a OS-X Bundle, a bit werid because its a mixture of unix and mac OS @@ -189,7 +189,7 @@ { int result = 0, done = 0, counter_start, counter; mpeg3_t *file = (mpeg3_t *) demuxer->file; - long next_byte, prev_byte; + long next_byte=0, prev_byte=0; double next_time, prev_time, absolute_time; long i; mpeg3_title_t *title; Modified: trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/mpeg3demux.c =================================================================== --- trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/mpeg3demux.c 2011-06-09 08:29:00 UTC (rev 2413) +++ trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/mpeg3demux.c 2011-06-09 08:30:40 UTC (rev 2414) @@ -711,15 +711,15 @@ demuxer->raw_size = demuxer->packet_size; demuxer->raw_offset = 0; demuxer->data_size = 0; - + /* Search backward for it. */ header = mpeg3io_read_int32(title->fs); result = mpeg3io_eof(title->fs); if(!result) result = mpeg3io_seek_relative(title->fs, -4); -// Search backwards for header - while(header != MPEG3_PACK_START_CODE && !result && count < demuxer->packet_size) + // Search backwards for header + while(header != MPEG3_PACK_START_CODE && !result && count < (demuxer->packet_size)) { result = mpeg3io_seek_relative(title->fs, -1); if(!result) @@ -731,21 +731,21 @@ count++; } - if(result) - { + if ((header != MPEG3_PACK_START_CODE) || (result) ) { // couldn't find MPEG3_PACK_START_CODE return 1; } - + result = mpeg3io_read_data(demuxer->raw_data, demuxer->packet_size, title->fs); - if(result) { perror("mpeg3_read_program"); return 1; } + // fprintf(stderr, "Got data %ld\n", title->fs->current_byte); header = mpeg3packet_read_int32(demuxer); + while(demuxer->raw_offset + 4 < demuxer->raw_size && !result) { if(header == MPEG3_PACK_START_CODE) @@ -887,8 +887,11 @@ /* Read packets until the output buffer is full */ if(!result) { + long p1; // BGF added this protection against infinite-looping here. do { + p1 = title->fs->current_byte; + result = mpeg3_advance_timecode(demuxer, 0); if(!result) @@ -910,8 +913,15 @@ result = mpeg3io_read_data(demuxer->data_buffer, demuxer->packet_size, title->fs); if(!result) demuxer->data_size = demuxer->packet_size; } + + // We can spin out on attempts to read the last packet over and over. + if (p1 >= title->fs->current_byte) { + result = -1; + title->fs->current_byte = title->fs->total_bytes; // So EOF checks start to fire. + fprintf(stderr, "Stopping demux-stream to prevent spin."); + } } - }while(!result && demuxer->data_size == 0 && (demuxer->do_audio || demuxer->do_video)); + } while (!result && demuxer->data_size == 0 && (demuxer->do_audio || demuxer->do_video)); } return result; @@ -1046,7 +1056,7 @@ int dont_store) { mpeg3demux_timecode_t *new_table; - mpeg3demux_timecode_t *new_timecode, *old_timecode; + mpeg3demux_timecode_t *new_timecode = NULL, *old_timecode = NULL; long i; if(!title->timecode_table || @@ -1381,7 +1391,7 @@ { int result = 0, done = 0, counter_start, counter; mpeg3_t *file = (mpeg3_t *) demuxer->file; - long next_byte, prev_byte; + long next_byte=0, prev_byte=0; double next_time, prev_time, absolute_time; long i; mpeg3_title_t *title; Modified: trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/mpeg3io.c =================================================================== --- trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/mpeg3io.c 2011-06-09 08:29:00 UTC (rev 2413) +++ trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/mpeg3io.c 2011-06-09 08:30:40 UTC (rev 2414) @@ -105,20 +105,26 @@ return fs->total_bytes; } + if (! fs->fd) { // bgf error protection for win + return 0; + } + fseek(fs->fd, 0, SEEK_END); fs->total_bytes = ftell(fs->fd) - fs->id3v2_offset; fseek(fs->fd, fs->id3v2_offset, SEEK_SET); + return fs->total_bytes; } int mpeg3io_get_id3v2_size(mpeg3_fs_t *fs) { unsigned long synchsafe_size = 0; - + if (fs->mpeg_is_in_buffer) { fs->mpeg_is_in_buffer_file_position = 6; } else { - fseek(fs->fd, 6, SEEK_SET); + if (! fs->fd) return 0; + fseek(fs->fd, 6, SEEK_SET); } synchsafe_size = mpeg3io_read_int32(fs); @@ -138,8 +144,7 @@ perror("mpeg3io_open_file"); return 1; } - setvbuf(fs->fd,0, _IOFBF, 64*1024); //JMM Feb 26th, 2006 for CD reader performance - + setvbuf(fs->fd,0, _IOFBF, 64*1024); //JMM Feb 26th, 2006 for CD reader performance } bits = mpeg3io_read_int32(fs); @@ -151,14 +156,15 @@ fs->id3v2_offset = 0; } - mpeg3io_seek(fs, 0); - fs->total_bytes = mpeg3io_get_total_bytes(fs); if(!fs->total_bytes) { - if (!fs->mpeg_is_in_buffer) - fclose(fs->fd); + if (!fs->mpeg_is_in_buffer) { + if (fs->fd) fclose(fs->fd); + } + fprintf(stderr, "MP2 - empty file %s\n", fs->path); + fs->fd = NULL; return 1; } fs->current_byte = 0; @@ -174,6 +180,7 @@ memoryFree(fs->mpeg_is_in_buffer); fs->mpeg_is_in_buffer = 0; } + /* fprintf (stderr, "MP2 closing %s\n", fs->path); */ fs->fd = 0; return 0; } @@ -193,7 +200,7 @@ fs->mpeg_is_in_buffer_file_position += normalizedBytes; result = !normalizedBytes; } else { - result = !fread(buffer, 1, bytes, fs->fd); + result = (fs->fd != NULL) && !fread(buffer, 1, bytes, fs->fd); } fs->current_byte += bytes; return (result && bytes); @@ -244,16 +251,28 @@ fs->mpeg_is_in_buffer_file_position = target; return 0; } - return fseek(fs->fd, byte + fs->id3v2_offset, SEEK_SET); + // For Squeak-Teleplace, where we only deal in static mpeg files. + // No seek beyond the EOF. Partly to protect against win32 seek woes. + if (byte < 0) { + return -1; + } else if (fs->total_bytes && (byte > fs->total_bytes)) { + /* fprintf(stderr, "libmpeg3 seek out of range %ld vs %ld\n", byte, fs->total_bytes); */ + return -1; + } else { + if (fs->fd) { + return fseek(fs->fd, (byte + fs->id3v2_offset), SEEK_SET); + } + fprintf(stderr, "MP2: seek no fd\n"); + return -1; + } } int mpeg3io_seek_relative(mpeg3_fs_t *fs, long bytes) { + long old_current_byte = fs->current_byte; fs->current_byte += bytes; if (fs->mpeg_is_in_buffer) { - int target; - - target = fs->current_byte + fs->id3v2_offset; + long target = fs->current_byte + fs->id3v2_offset; if (target > fs->mpeg_buffer_size) return -1; if (target < 0) { @@ -261,7 +280,19 @@ fs->mpeg_is_in_buffer_file_position = target; return 0; } - return fseek(fs->fd, fs->current_byte + fs->id3v2_offset, SEEK_SET); + if (fs->current_byte < 0) { + return -1; + } else if (fs->total_bytes && (fs->current_byte > fs->total_bytes)) { + /* For Squeak-Teleplace, where we only deal in static mpeg files. */ + /* No seek beyond the EOF. Partly to protect against win32 seek woes. */ + return -1; + } + + if (fs->fd) { + return fseek(fs->fd, fs->current_byte + fs->id3v2_offset, SEEK_SET); + } + fprintf(stderr, "MP2: rel seek no fd\n"); + return -1; } int mpeg3io_scanf (mpeg3_fs_t *fs,char *format, void * string1, void * string2) { @@ -270,7 +301,10 @@ return_value = sscanf(fs->mpeg_is_in_buffer+fs->mpeg_is_in_buffer_file_position,format, string1, string2); return return_value; } - + if (! fs->fd) { + fprintf(stderr, "MP2 scan3 - no file\n"); + return -1; + } return_value = fscanf(fs->fd,format, string1, string2); return return_value; } @@ -282,7 +316,10 @@ return_value = sscanf(fs->mpeg_is_in_buffer+fs->mpeg_is_in_buffer_file_position,format, string1, string2, string3, string4, string5); return return_value; } - + if (! fs->fd) { + fprintf(stderr, "MP2 scan5 - no file\n"); + return -1; + } return_value = fscanf(fs->fd,format, string1, string2, string3, string4, string5); return return_value; } @@ -292,7 +329,7 @@ return fs->mpeg_is_in_buffer_file_position == fs->mpeg_buffer_size; } - return feof(fs->fd); + return ( ! fs->fd ) || feof(fs->fd); } inline int mpeg3io_fgetc(mpeg3_fs_t *fs) { @@ -306,6 +343,6 @@ value = (unsigned int) fs->mpeg_is_in_buffer[fs->mpeg_is_in_buffer_file_position-1]; return value; } - return fgetc(fs->fd); + return (fs->fd ? fgetc(fs->fd) : 0); } Modified: trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/video/getpicture.c =================================================================== --- trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/video/getpicture.c 2011-06-09 08:29:00 UTC (rev 2413) +++ trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/video/getpicture.c 2011-06-09 08:30:40 UTC (rev 2414) @@ -159,7 +159,7 @@ int comp, int dc_dct_pred[]) { - int val, i, j, sign; + int val, i, j=0, sign; unsigned int code; mpeg3_DCTtab_t *tab = 0; short *bp = slice->block[comp]; @@ -275,7 +275,7 @@ mpeg3video_t *video, int comp) { - int val, i, j, sign; + int val, i, j=0, sign; unsigned int code; mpeg3_DCTtab_t *tab; short *bp = slice->block[comp]; @@ -374,7 +374,7 @@ int comp, int dc_dct_pred[]) { - int val, i, j, sign, nc; + int val, i, j=0, sign, nc; unsigned int code; mpeg3_DCTtab_t *tab; short *bp; @@ -502,7 +502,7 @@ mpeg3video_t *video, int comp) { - int val, i, j, sign, nc; + int val, i, j=0, sign, nc; unsigned int code; mpeg3_DCTtab_t *tab; short *bp; Modified: trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/video/macroblocks.c =================================================================== --- trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/video/macroblocks.c 2011-06-09 08:29:00 UTC (rev 2413) +++ trunk/platforms/Cross/plugins/Mpeg3Plugin/libmpeg/video/macroblocks.c 2011-06-09 08:30:40 UTC (rev 2414) @@ -82,7 +82,7 @@ static inline int mpeg3video_getsp_imb_type(mpeg3_slice_t *slice) { - mpeg3_slice_buffer_t *slice_buffer = slice_buffer; + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; unsigned int code = mpeg3slice_showbits(slice_buffer, 4); if(!code) { |
Free forum by Nabble | Edit this page |