From b1adf70e2659a6414175b5ae66ffa33f90bf573e Mon Sep 17 00:00:00 2001 From: b1indy Date: Sat, 22 Dec 2007 19:37:52 +0000 Subject: incorporated av_free_packet fix fixed #VIDEOGAP problem fixed unexpected #START problem (needs to be fixed in trunk too git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/1.0.1@741 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/Classes/UVideo.pas | 44 ++++++++++++++++++++++++++------------- Game/Code/Screens/UScreenSing.pas | 2 +- Game/Code/lib/ffmpeg/avformat.pas | 2 +- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/Game/Code/Classes/UVideo.pas b/Game/Code/Classes/UVideo.pas index 91a64939..c3aa8073 100644 --- a/Game/Code/Classes/UVideo.pas +++ b/Game/Code/Classes/UVideo.pas @@ -41,7 +41,7 @@ procedure FFmpegClose; procedure FFmpegGetFrame(Time: Extended); procedure FFmpegDrawGL(Screen: integer); procedure FFmpegTogglePause; -procedure FFmpegSkip(Time: Single); +procedure FFmpegSkip(Gap: Single; Start: Single); var VideoOpened, VideoPaused: Boolean; @@ -205,11 +205,25 @@ begin myBuffer:=Nil; if(AVFrame <> Nil) and (AVFrameRGB <> Nil) then begin - myBuffer:=av_malloc(avpicture_get_size(PIX_FMT_RGB24, VideoCodecContext^.width, - VideoCodecContext^.height)); + TexX := VideoCodecContext^.width; + TexY := VideoCodecContext^.height; + dataX := Round(Power(2, Ceil(Log2(TexX)))); + dataY := Round(Power(2, Ceil(Log2(TexY)))); + if (dataX >1024) or (dataY>1024) then + begin +{$ifdef DebugDisplay} + showmessage('video too large'); +{$endif} + av_free(AVFrameRGB); + av_free(AVFrame); + avcodec_close(VideoCodecContext); + av_close_input_file(VideoFormatContext); + Exit; + end; + myBuffer:=av_malloc(avpicture_get_size(PIX_FMT_RGB24, dataX, dataY)); end; if myBuffer <> Nil then errnum:=avpicture_fill(PAVPicture(AVFrameRGB), myBuffer, PIX_FMT_RGB24, - VideoCodecContext^.width, VideoCodecContext^.height) + dataX, dataY) else begin {$ifdef DebugDisplay} showmessage('failed to allocate video buffer'); @@ -292,15 +306,15 @@ begin else VideoPaused:=True; end; -procedure FFmpegSkip(Time: Single); +procedure FFmpegSkip(Gap: Single; Start: Single); var seek_target: uint64; + str: string; begin - VideoSkiptime:=Time; - NegativeSkipTime:=Time; - if VideoSkipTime > 0 then begin -// av_seek_frame(VideoFormatContext,-1,Floor((VideoSkipTime)*1000000),0); - av_seek_frame(VideoFormatContext,VideoStreamIndex,Floor(Time/VideoTimeBase),AVSEEK_FLAG_ANY); - VideoTime:=VideoSkipTime; + VideoSkiptime:=Gap; + NegativeSkipTime:=Start+Gap; + if Start+Gap > 0 then begin + av_seek_frame(VideoFormatContext,VideoStreamIndex,Floor((Gap+Start)/(VideoFormatContext^.streams[VideoStreamIndex]^.time_base.num/VideoFormatContext^.streams[VideoStreamIndex]^.time_base.den)),AVSEEK_FLAG_ANY); + VideoTime:=Gap+Start; end; end; @@ -388,7 +402,7 @@ begin // if we did not get an new frame, there's nothing more to do if Framefinished=0 then begin - GoldenRec.Spawn(220,15,1,16,0,-1,ColoredStar,$0000ff); +// GoldenRec.Spawn(220,15,1,16,0,-1,ColoredStar,$0000ff); Exit; end; // otherwise we convert the pixeldata from YUV to RGB @@ -399,15 +413,15 @@ begin if errnum >=0 then begin // copy RGB pixeldata to our TextureBuffer // (line by line) - FrameDataPtr:=Pointer(AVFrameRGB^.data[0]); +{ FrameDataPtr:=Pointer(AVFrameRGB^.data[0]); linesize:=AVFrameRGB^.linesize[0]; for y:=0 to TexY-1 do begin System.Move(FrameDataPtr[y*linesize],TexData[3*y*dataX],linesize); end; - +} // generate opengl texture out of whatever we got glBindTexture(GL_TEXTURE_2D, VideoTex); - glTexImage2D(GL_TEXTURE_2D, 0, 3, dataX, dataY, 0, GL_RGB, GL_UNSIGNED_BYTE, TexData); + glTexImage2D(GL_TEXTURE_2D, 0, 3, dataX, dataY, 0, GL_RGB, GL_UNSIGNED_BYTE, AVFrameRGB^.data[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); {$ifdef DebugFrames} diff --git a/Game/Code/Screens/UScreenSing.pas b/Game/Code/Screens/UScreenSing.pas index 283c51d0..3cedc0a1 100644 --- a/Game/Code/Screens/UScreenSing.pas +++ b/Game/Code/Screens/UScreenSing.pas @@ -351,7 +351,7 @@ begin // set movie if (AktSong.Video <> '') and FileExists(AktSong.Path + AktSong.Video) then begin FFmpegOpenFile(PAnsiChar(AktSong.Path + AktSong.Video)); - FFmpegSkip(AktSong.VideoGAP + AktSong.Start); + FFmpegSkip(AktSong.VideoGAP, AktSong.Start); if (UVideo.VideoOpened) then AktSong.VideoLoaded := true; end; diff --git a/Game/Code/lib/ffmpeg/avformat.pas b/Game/Code/lib/ffmpeg/avformat.pas index aa74043b..e7584d87 100644 --- a/Game/Code/lib/ffmpeg/avformat.pas +++ b/Game/Code/lib/ffmpeg/avformat.pas @@ -113,7 +113,7 @@ type stream_index: integer; flags: integer; duration: integer; ///< presentation duration in time_base units (0 if not available) - destruct: procedure (p: PAVPacket); (* This cannot be var : TAVPacket. + destruct: procedure (p: PAVPacket);cdecl; (* This cannot be var : TAVPacket. because TAVPacket is not completely defined yet *) priv: pointer; pos: int64 ///< byte position in stream, -1 if unknown -- cgit v1.2.3