diff options
Diffstat (limited to 'Game/Code/SMpeg')
-rw-r--r-- | Game/Code/SMpeg/USmpeg.pas | 301 | ||||
-rw-r--r-- | Game/Code/SMpeg/Uffmpeg.pas | 378 |
2 files changed, 0 insertions, 679 deletions
diff --git a/Game/Code/SMpeg/USmpeg.pas b/Game/Code/SMpeg/USmpeg.pas deleted file mode 100644 index 317b04bb..00000000 --- a/Game/Code/SMpeg/USmpeg.pas +++ /dev/null @@ -1,301 +0,0 @@ -unit USmpeg;
-
-interface
-uses SDL, smpeg, OpenGL12, SysUtils, UIni;
-
-procedure OpenSmpeg(FileName: string);
-procedure SkipSmpeg(Time: single);
-procedure PlaySmpeg;
-procedure PauseSmpeg; //PauseMod
-procedure UpdateSmpeg;
-procedure CloseSmpeg;
-function glmovie_init(Width : GLuint; Height : TGLuint ) : TGLenum;
-procedure glmpeg_update(surface: PSDL_Surface; x: Sint32; y: Sint32; w: Uint32; h: Uint32); cdecl;
-procedure DrawSmpeg(frame: PGLubyte);
-procedure glmovie_resize( width : GLuint; height : GLuint );
-procedure glmovie_quit;
-
-var
- mpeg: PSMPEG;
- mpeg_info: TSMPEG_Info;
- surface: PSDL_Surface;
-
-type
- { Some data is redundant at this stage. }
- PGLMovieTexture = ^TGLMovieTexture;
- TGLMovieTexture = record
- id : TGLuint; (* OpenGL texture id. *)
- poly_width : TGLuint; (* Quad width for tile. *)
- poly_height : TGLuint; (* Quad height for tile. *)
- movie_width : TGLuint; (* Width of movie inside tile. *)
- movie_height : TGLuint; (* Height of movie inside tile. *)
- skip_rows : TGLuint; (* Number of rows of movie to skip *)
- skip_pixels : TGLuint; (* Number of columns of movie to skip *)
- row : TGLuint; (* Row number of tile in scheme. *)
- col : TGLuint; (* Column number of tile in scheme. *)
- end;
-
-type
- TGLuintArray = array of TGLuint;
- PGLuintArray = ^TGLuintArray;
- TGLMovieTextureArray = array of TGLMovieTexture;
- PGLMovieTextureArray = ^TGLMovieTextureArray;
-
-var
- (* Our evil maximum texture size. Boo 3Dfxnot *)
- texture_size : TGLuint = 1024;//512;
- texture_ids : TGLuint;
- textures: TGLMovieTexture;
- tiled_width : TGLuint = 0;
- tiled_height : TGLuint = 0;
- movie_width : TGLuint = 0;
- movie_height : TGLuint = 0;
-
-implementation
-
-procedure OpenSmpeg(FileName: string);
-begin
- mpeg := SMPEG_new(PChar(FileName), @mpeg_info, 0); // audio
- if ( mpeg = nil ) then begin
- SDL_Quit;
- Exit;
- end;
-
-// SMPEG_setvolume(mpeg, 50);
- SMPEG_enableaudio(mpeg, 0);
-
- (* Everything needs to be in RGB for GL, but needs to be 32-bit for SMPEG. *)
- surface := SDL_AllocSurface( SDL_SWSURFACE,
- mpeg_info.width,
- mpeg_info.height,
- 32,
- $000000FF,
- $0000FF00,
- $00FF0000,
- $FF000000 );
-
- if ( surface = nil ) then begin
- SDL_Quit;
- Exit;
- end;
-
- (* *Initialize* with mpeg size. *)
- if (glmovie_init( mpeg_info.width, mpeg_info.height ) <> GL_NO_ERROR ) then begin
- SDL_Quit;
- Exit;
- end;
-
- SMPEG_setdisplay(mpeg, surface, nil, @glmpeg_update);
-end;
-
-procedure SkipSmpeg(Time: single);
-begin
- SMPEG_skip(mpeg, Time);
-end;
-
-procedure PlaySmpeg;
-begin
- SMPEG_play(mpeg);
-end;
-
-//Pause Mod
-procedure PauseSmpeg;
-begin
- SMPEG_pause(mpeg);
-end;
-
-procedure UpdateSmpeg;
-begin
-// glmpeg_update(surface,0,0,0,0);
- DrawSmpeg( PGLubyte( surface.pixels ) );
-end;
-
-procedure CloseSmpeg;
-begin
- SMPEG_delete(mpeg);
- //Fixing the Memory Lag in earlyer Versions (X-Mas Mod, all Official Versions)
- glmovie_quit;
-end;
-
-function glmovie_init( Width : GLuint; Height : TGLuint ) : TGLenum;
-type
- PGLubyteArray = ^TGLubyteArray;
- TGLubyteArray = array of TGLubyte;
-var
- (* Initial black texels. *)
- pixels : TGLubyteArray;
- (* Absolute offsets from within tiled frame. *)
- //offset_x: GLuint;
- //offset_y: GLuint;
- skip_rows : GLuint;
- skip_pixels : GLuint;
- i, j, current : GLuint;
-begin
- skip_rows := 0;
- current := 0;
- (* Save original movie dimensions. *)
- movie_width := width;
- movie_height := height;
-
- (* Get the power of 2 dimensions. *)
- tiled_width := 1024{512};
- tiled_height := 1024{512};
-
- texture_size := 1024{512};
-
- (* Time for fun with data type = record *)
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_DITHER);
-
- glGenTextures(1, @texture_ids);
-
- current := 0;
- (* Setup texture. *)
- textures.id := texture_ids;
- textures.poly_width := texture_size;
- textures.poly_height := texture_size;
- textures.movie_width := movie_width - 2;
- textures.movie_height := movie_height - 2;
- textures.row := i;
- textures.col := j;
- textures.skip_pixels := skip_pixels;
- textures.skip_rows := skip_rows;
-
- SetLength( pixels, textures.poly_width * textures.poly_height * 4 );
- if ( pixels = nil ) then
- begin
- glDeleteTextures(1, @texture_ids);
- result := GL_OUT_OF_MEMORY;
- exit;
- end;
- //FillChar( pixels^, textures[ current ].poly_width * textures[ current ].poly_height * 4, 0 );
-
- (* Do all of our useful binding. *)
- glBindTexture(GL_TEXTURE_2D, texture_ids);
-// glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- (* Specify our 256x256 black texture. *)
- glTexImage2D( GL_TEXTURE_2D,
- 0,
- GL_RGB,
- 1024{512},//textures.poly_width,
- 1024{512},//textures.poly_height,
- 0,
- GL_RGBA,
- GL_UNSIGNED_BYTE,
- @pixels[0] );
- SetLength( pixels, 0 );
-
-
- (* Simple state setup at the end. *)
- result := glGetError( );
-end;
-
-procedure glmpeg_update( surface : PSDL_Surface; x : Sint32; y : Sint32; w : Uint32;
- h : Uint32 ); cdecl;
-var
- error : TGLenum;
-begin
- glClear( GL_COLOR_BUFFER_BIT );
- glMatrixMode( GL_MODELVIEW );
- glLoadIdentity;
- DrawSmpeg( PGLubyte( surface.pixels ) );
- error := glGetError( );
- if ( error <> GL_NO_ERROR ) then Exit;
- SDL_GL_SwapBuffers;
-end;
-
-procedure DrawSmpeg(frame: PGLubyte);
-var
- Shift: TGLdouble;
- CropT: real;
- CropB: real;
- TexT: real;
- TexB: real;
- TexL: real;
- TexR: real;
- Wide: boolean;
-begin
- (* full screen mpeg *)
-{ CropT := 0;
- CropB := 600;
- TexT := 0;
- TexB := 1;
- TexL := 0;
- TexW := 1;}
-
- // set movie texture crop
- Wide := false;
- if (textures.movie_width = 720-2) and (textures.movie_height = 344-2) then begin
- TexT := 0;
- TexB := 342/1024;
- Wide := true;
- end;
- if textures.movie_height = 304-2 then begin
- TexT := 0;
- TexB := 304/1024;
- Wide := true;
- end;
- if textures.movie_height = 152-2 then begin
- TexT := 0;
- TexB := 152/1024;
- Wide := true;
- end;
-
- CropT := 110; // (110/800 = 13,75% max crop)
- CropB := 490; // (110/800 = 13,75% max crop)
-
- if (textures.movie_height <> 304-2) and (textures.movie_height <> 152-2) and (textures.movie_height <> 344-2) then begin
- TexT := 110 / 600 * (textures.movie_height / 1024{512});
- TexB := 490 / 600 * (textures.movie_height / 1024{512});
-
- if Ini.MovieSize >= 1 then begin
- // full screen size
- CropT := 0;
- CropB := 600;
- TexT := 0;
- TexB := textures.movie_height / 1024{512};
- end;
- end;
-
- TexL := {10}0/600 * (textures.movie_width / 1024{512});
- TexR := {590}600/600 * (textures.movie_width / 1024{512});
-
- glEnable(GL_TEXTURE_2D);
- glDisable(GL_BLEND);
- glColor3f(1, 1, 1);
- glBindTexture( GL_TEXTURE_2D, texture_ids );
-// glPixelStorei( GL_UNPACK_ROW_LENGTH, movie_width );
- glPixelStorei( GL_UNPACK_SKIP_ROWS, 0);
- glPixelStorei( GL_UNPACK_SKIP_PIXELS, 0);
- glTexSubImage2D( GL_TEXTURE_2D, 0, 0, (* offset_x *) 0, (* offset_y *) textures.movie_width + 2, textures.movie_height + 2, GL_RGBA, GL_UNSIGNED_BYTE, frame );
-
- // draw
- glBegin( GL_QUADS );
- glTexCoord2f(TexL, TexT); glVertex2f(0, CropT);
- glTexCoord2f(TexL, TexB); glVertex2f(0, CropB);
- glTexCoord2f(TexR, TexB); glVertex2f(800, CropB);
- glTexCoord2f(TexR, TexT); glVertex2f(800, CropT);
- glEnd;
- glDisable(GL_TEXTURE_2D);
-end;
-
-procedure glmovie_resize( width : GLuint; height : GLuint );
-begin
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity;
- gluOrtho2D(0, 800, 600, 0);
-end;
-
-procedure glmovie_quit;
-begin
- glDeleteTextures(1, @texture_ids);
- SDL_FreeSurface(surface);
-end;
-
-end.
diff --git a/Game/Code/SMpeg/Uffmpeg.pas b/Game/Code/SMpeg/Uffmpeg.pas deleted file mode 100644 index 6e08ca95..00000000 --- a/Game/Code/SMpeg/Uffmpeg.pas +++ /dev/null @@ -1,378 +0,0 @@ -{############################################################################
-# FFmpeg support for UltraStar deluxe #
-# #
-# Created by b1indy #
-# based on 'An ffmpeg and SDL Tutorial' (http://www.dranger.com/ffmpeg/) #
-#############################################################################}
-
-//{$define DebugDisplay} // uncomment if u want to see the debug stuff
-{$define DebugFrames}
-{$define Info}
-
-
-unit Uffmpeg;
-
-interface
-uses SDL, UGraphicClasses, textgl, avcodec, avformat, avutil, math, OpenGL12, SysUtils, UIni, dialogs;
-
-procedure Init;
-procedure FFmpegOpenFile(FileName: pAnsiChar);
-procedure FFmpegClose;
-procedure FFmpegGetFrame(Time: Extended);
-procedure FFmpegDrawGL(Screen: integer);
-procedure FFmpegTogglePause;
-procedure FFmpegSkip(Time: Single);
-
-var
- VideoOpened, VideoPaused: Boolean;
- VideoFormatContext: PAVFormatContext;
- VideoStreamIndex: Integer;
- VideoCodecContext: PAVCodecContext;
- VideoCodec: PAVCodec;
- AVFrame: PAVFrame;
- AVFrameRGB: PAVFrame;
- myBuffer: pByte;
- VideoTex: glUint;
- TexX, TexY, dataX, dataY: Cardinal;
- TexData: array of Byte;
- ScaledVideoWidth, ScaledVideoHeight: Real;
- VideoAspect: Real;
- VideoTextureU, VideoTextureV: Real;
- VideoTimeBase, VideoTime, LastFrameTime, TimeDifference: Extended;
- VideoSkipTime: Single;
-
-implementation
-
-procedure Init;
-begin
- av_register_all;
- VideoOpened:=False;
- VideoPaused:=False;
- glGenTextures(1, PglUint(@VideoTex));
- SetLength(TexData,0);
-end;
-
-procedure FFmpegOpenFile(FileName: pAnsiChar);
-var errnum, i, x,y: Integer;
-begin
- VideoOpened:=False;
- VideoPaused:=False;
- VideoTimeBase:=0;
- VideoTime:=0;
- LastFrameTime:=0;
- TimeDifference:=0;
- errnum:=av_open_input_file(VideoFormatContext, FileName, Nil, 0, Nil);
- if(errnum <> 0)
- then begin
- case errnum of
- AVERROR_UNKNOWN: showmessage('failed to open file '+Filename+#13#10+'AVERROR_UNKNOWN');
- AVERROR_IO: showmessage('failed to open file '+Filename+#13#10+'AVERROR_IO');
- AVERROR_NUMEXPECTED: showmessage('failed to open file '+Filename+#13#10+'AVERROR_NUMEXPECTED');
- AVERROR_INVALIDDATA: showmessage('failed to open file '+Filename+#13#10+'AVERROR_INVALIDDATA');
- AVERROR_NOMEM: showmessage('failed to open file '+Filename+#13#10+'AVERROR_NOMEM');
- AVERROR_NOFMT: showmessage('failed to open file '+Filename+#13#10+'AVERROR_NOFMT');
- AVERROR_NOTSUPP: showmessage('failed to open file '+Filename+#13#10+'AVERROR_NOTSUPP');
- else showmessage('failed to open file '+Filename+#13#10+'Error number: '+inttostr(Errnum));
- end;
- Exit;
- end
- else begin
- VideoStreamIndex:=-1;
- if(av_find_stream_info(VideoFormatContext)>=0) then
- begin
- for i:=0 to VideoFormatContext^.nb_streams-1 do
- if(VideoFormatContext^.streams[i]^.codec^.codec_type=CODEC_TYPE_VIDEO) then begin
- VideoStreamIndex:=i;
- end else
- end;
- if(VideoStreamIndex >= 0) then
- begin
- VideoCodecContext:=VideoFormatContext^.streams[VideoStreamIndex]^.codec;
- VideoCodec:=avcodec_find_decoder(VideoCodecContext^.codec_id);
- end else begin
- showmessage('found no video stream');
- av_close_input_file(VideoFormatContext);
- Exit;
- end;
- if(VideoCodec<>Nil) then
- begin
- errnum:=avcodec_open(VideoCodecContext, VideoCodec);
- end else begin
- showmessage('no matching codec found');
- avcodec_close(VideoCodecContext);
- av_close_input_file(VideoFormatContext);
- Exit;
- end;
- if(errnum >=0) then
- begin
-{$ifdef DebugDisplay}
- showmessage('Found a matching Codec:'+#13#10#13#10+
- 'Width='+inttostr(VideoCodecContext^.width)+
- ', Height='+inttostr(VideoCodecContext^.height)+#13#10+
- 'Aspect: '+inttostr(VideoCodecContext^.sample_aspect_ratio.num)+'/'+inttostr(VideoCodecContext^.sample_aspect_ratio.den)+#13#10+
- 'Framerate: '+inttostr(VideoCodecContext^.time_base.num)+'/'+inttostr(VideoCodecContext^.time_base.den));
-{$endif}
- // allocate space for decoded frame and rgb frame
- AVFrame:=avcodec_alloc_frame;
- AVFrameRGB:=avcodec_alloc_frame;
- end;
- myBuffer:=Nil;
- if(AVFrame <> Nil) and (AVFrameRGB <> Nil) then
- begin
- myBuffer:=av_malloc(avpicture_get_size(PIX_FMT_RGB24, VideoCodecContext^.width,
- VideoCodecContext^.height));
- end;
- if myBuffer <> Nil then errnum:=avpicture_fill(PAVPicture(AVFrameRGB), myBuffer, PIX_FMT_RGB24,
- VideoCodecContext^.width, VideoCodecContext^.height)
- else begin
- showmessage('failed to allocate video buffer');
- av_free(AVFrameRGB);
- av_free(AVFrame);
- avcodec_close(VideoCodecContext);
- av_close_input_file(VideoFormatContext);
- Exit;
- end;
- if errnum >=0 then
- begin
- VideoOpened:=True;
-
- TexX := VideoCodecContext^.width;
- TexY := VideoCodecContext^.height;
- dataX := Round(Power(2, Ceil(Log2(TexX))));
- dataY := Round(Power(2, Ceil(Log2(TexY))));
- SetLength(TexData,dataX*dataY*3);
- // calculate some information for video display
- VideoAspect:=VideoCodecContext^.sample_aspect_ratio.num/VideoCodecContext^.sample_aspect_ratio.den;
- if (VideoAspect = 0) then
- VideoAspect:=VideoCodecContext^.width/VideoCodecContext^.height
- else
- VideoAspect:=VideoAspect*VideoCodecContext^.width/VideoCodecContext^.height;
- if VideoAspect >= 4/3 then
- begin
- ScaledVideoWidth:=800.0;
- ScaledVideoHeight:=800.0/VideoAspect;
- end else
- begin
- ScaledVideoHeight:=600.0;
- ScaledVideoWidth:=600.0*VideoAspect;
- end;
- VideoTimeBase:=VideoCodecContext^.time_base.num/VideoCodecContext^.time_base.den;
- // hack to get reasonable timebase for divx
-{$ifdef DebugDisplay}
- showmessage('framerate: '+inttostr(floor(1/videotimebase))+'fps');
-{$endif}
- if VideoTimeBase < 0.02 then // 0.02 <-> 50 fps
- begin
- VideoTimeBase:=VideoCodecContext^.time_base.den/VideoCodecContext^.time_base.num;
- while VideoTimeBase > 50 do VideoTimeBase:=VideoTimeBase/10;
- VideoTimeBase:=1/VideoTimeBase;
- end;
-{$ifdef DebugDisplay}
- showmessage('corrected framerate: '+inttostr(floor(1/videotimebase))+'fps');
- if ((VideoAspect*VideoCodecContext^.width*VideoCodecContext^.height)>200000) then
- showmessage('you are trying to play a rather large video'+#13#10+
- 'be prepared to experience some timing problems');
-{$endif}
- end;
- end;
-end;
-
-procedure FFmpegClose;
-begin
- if VideoOpened then begin
- av_free(myBuffer);
- av_free(AVFrameRGB);
- av_free(AVFrame);
- avcodec_close(VideoCodecContext);
- av_close_input_file(VideoFormatContext);
- SetLength(TexData,0);
- VideoOpened:=False;
- end;
-end;
-
-procedure FFmpegTogglePause;
-begin
- if VideoPaused then VideoPaused:=False
- else VideoPaused:=True;
-end;
-
-procedure FFmpegSkip(Time: Single);
-begin
- VideoSkiptime:=Time;
- if VideoSkipTime > 0 then begin
- av_seek_frame(VideoFormatContext,-1,Floor((VideoSkipTime)*1500000),0);
- VideoTime:=VideoSkipTime;
- end;
-end;
-
-procedure FFmpegGetFrame(Time: Extended);
-var
- FrameFinished: Integer;
- AVPacket: TAVPacket;
- errnum, x, y: Integer;
- FrameDataPtr: PByteArray;
- linesize: integer;
- myTime: Extended;
- DropFrame: Boolean;
- droppedFrames: Integer;
-const
- FRAMEDROPCOUNT=3;
-begin
- if not VideoOpened then Exit;
- if VideoPaused then Exit;
- myTime:=Time+VideoSkipTime;
- TimeDifference:=myTime-VideoTime;
- DropFrame:=False;
-{ showmessage('Time: '+inttostr(floor(Time*1000))+#13#10+
- 'VideoTime: '+inttostr(floor(VideoTime*1000))+#13#10+
- 'TimeBase: '+inttostr(floor(VideoTimeBase*1000))+#13#10+
- 'TimeDiff: '+inttostr(floor(TimeDifference*1000)));
-}
- if (VideoTime <> 0) and (TimeDifference <= VideoTimeBase) then begin
-{$ifdef DebugFrames}
- // frame delay debug display
- GoldenRec.Spawn(200,15,1,16,0,-1,ColoredStar,$00ff00);
-{$endif}
-{ showmessage('not getting new frame'+#13#10+
- 'Time: '+inttostr(floor(Time*1000))+#13#10+
- 'VideoTime: '+inttostr(floor(VideoTime*1000))+#13#10+
- 'TimeBase: '+inttostr(floor(VideoTimeBase*1000))+#13#10+
- 'TimeDiff: '+inttostr(floor(TimeDifference*1000)));
-}
- Exit;// we don't need a new frame now
- end;
- VideoTime:=VideoTime+VideoTimeBase;
- TimeDifference:=myTime-VideoTime;
- if TimeDifference >= (FRAMEDROPCOUNT-1)*VideoTimeBase then begin // skip frames
-{$ifdef DebugFrames}
- //frame drop debug display
- GoldenRec.Spawn(200,55,1,16,0,-1,ColoredStar,$ff0000);
-{$endif}
-// showmessage('skipping frames'+#13#10+
-// 'TimeBase: '+inttostr(floor(VideoTimeBase*1000))+#13#10+
-// 'TimeDiff: '+inttostr(floor(TimeDifference*1000))+#13#10+
-// 'Time2Skip: '+inttostr(floor((Time-LastFrameTime)*1000)));
-// av_seek_frame(VideoFormatContext,VideoStreamIndex,Floor(Time*VideoTimeBase),0);
-{ av_seek_frame(VideoFormatContext,-1,Floor((myTime+VideoTimeBase)*1500000),0);
- VideoTime:=floor(myTime/VideoTimeBase)*VideoTimeBase;}
- VideoTime:=VideoTime+FRAMEDROPCOUNT*VideoTimeBase;
- DropFrame:=True;
- end;
-
- av_init_packet(@AVPacket);
- FrameFinished:=0;
- // read packets until we have a finished frame (or there are no more packets)
- while (FrameFinished=0) and (av_read_frame(VideoFormatContext, @AVPacket)>=0) do
- begin
- // if we got a packet from the video stream, then decode it
- if (AVPacket.stream_index=VideoStreamIndex) then
- errnum:=avcodec_decode_video(VideoCodecContext, AVFrame, @frameFinished,
- AVPacket.data, AVPacket.size);
- // release internal packet structure created by av_read_frame
- av_free_packet(PAVPacket(@AVPacket));
- end;
- if DropFrame then
- for droppedFrames:=1 to FRAMEDROPCOUNT do begin
- FrameFinished:=0;
- // read packets until we have a finished frame (or there are no more packets)
- while (FrameFinished=0) and (av_read_frame(VideoFormatContext, @AVPacket)>=0) do
- begin
- // if we got a packet from the video stream, then decode it
- if (AVPacket.stream_index=VideoStreamIndex) then
- errnum:=avcodec_decode_video(VideoCodecContext, AVFrame, @frameFinished,
- AVPacket.data, AVPacket.size);
- // release internal packet structure created by av_read_frame
- av_free_packet(PAVPacket(@AVPacket));
- end;
- end;
-
- // 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);
- Exit;
- end;
- // otherwise we convert the pixeldata from YUV to RGB
- errnum:=img_convert(PAVPicture(AVFrameRGB), PIX_FMT_RGB24,
- PAVPicture(AVFrame), VideoCodecContext^.pix_fmt,
- VideoCodecContext^.width, VideoCodecContext^.height);
-//errnum:=1;
- if errnum >=0 then begin
- // copy RGB pixeldata to our TextureBuffer
- // (line by line)
- FrameDataPtr:=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);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-{$ifdef DebugFrames}
- //frame decode debug display
- GoldenRec.Spawn(200,35,1,16,0,-1,ColoredStar,$ffff00);
-{$endif}
-
- end;
-end;
-
-procedure FFmpegDrawGL(Screen: integer);
-begin
- // have a nice black background to draw on (even if there were errors opening the vid)
- if Screen=1 then begin
- glClearColor(0,0,0,0);
- glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
- end;
- // exit if there's nothing to draw
- if not VideoOpened then Exit;
-
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_BLEND);
- glColor4f(1, 1, 1, 1);
- glBindTexture(GL_TEXTURE_2D, VideoTex);
- glbegin(gl_quads);
- glTexCoord2f( 0, 0); glVertex2f(400-ScaledVideoWidth/2, 300-ScaledVideoHeight/2);
- glTexCoord2f( 0, TexY/dataY); glVertex2f(400-ScaledVideoWidth/2, 300+ScaledVideoHeight/2);
- glTexCoord2f(TexX/dataX, TexY/dataY); glVertex2f(400+ScaledVideoWidth/2, 300+ScaledVideoHeight/2);
- glTexCoord2f(TexX/dataX, 0); glVertex2f(400+ScaledVideoWidth/2, 300-ScaledVideoHeight/2);
- glEnd;
- glDisable(GL_TEXTURE_2D);
- glDisable(GL_BLEND);
-
-{$ifdef Info}
- if VideoSkipTime+VideoTime+VideoTimeBase < 0 then begin
- glColor4f(0.7, 1, 0.3, 1);
- SetFontStyle (1);
- SetFontItalic(False);
- SetFontSize(9);
- SetFontPos (300, 0);
- glPrint('Delay due to negative VideoGap');
- glColor4f(1, 1, 1, 1);
- end;
-{$endif}
-
-{$ifdef DebugFrames}
- glColor4f(0, 0, 0, 0.2);
- glbegin(gl_quads);
- glVertex2f(0, 0);
- glVertex2f(0, 70);
- glVertex2f(250, 70);
- glVertex2f(250, 0);
- glEnd;
-
- glColor4f(1,1,1,1);
- SetFontStyle (1);
- SetFontItalic(False);
- SetFontSize(9);
- SetFontPos (5, 0);
- glPrint('delaying frame');
- SetFontPos (5, 20);
- glPrint('fetching frame');
- SetFontPos (5, 40);
- glPrint('dropping frame');
-{$endif}
-end;
-
-end.
|