aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Classes/UVideo.pas
diff options
context:
space:
mode:
authorjaybinks <jaybinks@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-10-27 06:31:04 +0000
committerjaybinks <jaybinks@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-10-27 06:31:04 +0000
commit8cca9e3e6f591c35d35d132a9d3f93ffc7cdfee8 (patch)
tree985dac320ed9d8456a682c952c1b0ab0f502859b /Game/Code/Classes/UVideo.pas
parent64f2c9b369185575d397dccbbcacc7f818874952 (diff)
downloadusdx-8cca9e3e6f591c35d35d132a9d3f93ffc7cdfee8.tar.gz
usdx-8cca9e3e6f591c35d35d132a9d3f93ffc7cdfee8.tar.xz
usdx-8cca9e3e6f591c35d35d132a9d3f93ffc7cdfee8.zip
made some major progress with ffmpeg audio playback !!!
YAY !!! still a little choppy, so I suspect incorrect buffer sizes or something like that. also made some mods to support Unicode song file iteration on windows, this is no worse than what we had before, but is not complete.. oh this code only supports win 2000 and up .. no Win 98... git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@533 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to '')
-rw-r--r--Game/Code/Classes/UVideo.pas85
1 files changed, 60 insertions, 25 deletions
diff --git a/Game/Code/Classes/UVideo.pas b/Game/Code/Classes/UVideo.pas
index 4c27867d..154cd04c 100644
--- a/Game/Code/Classes/UVideo.pas
+++ b/Game/Code/Classes/UVideo.pas
@@ -10,9 +10,11 @@ unit UVideo;
# #
############################################################################## }
-{$define DebugDisplay} // uncomment if u want to see the debug stuff
+//{$define DebugDisplay} // uncomment if u want to see the debug stuff
//{$define DebugFrames}
//{$define Info}
+
+//{$define FFMpegAudio}
{}
@@ -45,6 +47,9 @@ uses SDL,
dialogs,
{$endif}
{$ENDIF}
+ {$ifdef FFMpegAudio}
+ UAudio_FFMpeg,
+ {$endif}
UIni,
UMusic;
@@ -108,7 +113,9 @@ type
end;
-
+ const
+ SDL_AUDIO_BUFFER_SIZE = 1024;
+
{$ifdef DebugDisplay}
//{$ifNdef win32}
@@ -262,19 +269,23 @@ 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
- while (FrameFinished=0) and (av_read_frame(VideoFormatContext, AVPacket)>=0) do // JB-ffmpeg
+ while ( FrameFinished = 0 ) and
+ ( av_read_frame(VideoFormatContext, AVPacket) >= 0 ) do // JB-ffmpeg
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);
+ begin
errnum := avcodec_decode_video(VideoCodecContext, AVFrame, frameFinished , AVPacket.data, AVPacket.size); // JB-ffmpeg
-
-
- // release internal packet structure created by av_read_frame
-// av_free_packet(PAVPacket(@AVPacket));
+ {$ifdef FFMpegAudio}
+ end
+ else
+ if (AVPacket.stream_index = AudioStreamIndex ) then
+ begin
+ UAudio_FFMpeg.packet_queue_put(UAudio_FFMpeg.audioq, AVPacket);
+ {$endif}
+ end;
try
if AVPacket.data <> nil then
@@ -427,6 +438,10 @@ var
errnum, i, x,y: Integer;
lStreamsCount : Integer;
+ wanted_spec ,
+ spec : TSDL_AudioSpec;
+ aCodec : pAVCodec;
+
begin
fVideoOpened := False;
fVideoPaused := False;
@@ -471,27 +486,47 @@ begin
end;
aCodecCtx := VideoFormatContext.streams[ AudioStreamIndex ].codec;
+ {$ifdef FFMpegAudio}
+ // This is the audio ffmpeg audio support Jay is working on.
if aCodecCtx <> nil then
begin
+ wanted_spec.freq := aCodecCtx.sample_rate;
+ wanted_spec.format := AUDIO_S16SYS;
+ wanted_spec.channels := aCodecCtx.channels;
+ wanted_spec.silence := 0;
+ wanted_spec.samples := SDL_AUDIO_BUFFER_SIZE;
+ wanted_spec.callback := UAudio_FFMpeg.audio_callback;
+ wanted_spec.userdata := aCodecCtx;
-// WantedAudioCodecContext.freq := aCodecCtx^.sample_rate;
-// WantedAudioCodecContext.format := AUDIO_S16SYS;
-// WantedAudioCodecContext.channels := aCodecCtx^.channels;
-(* WantedAudioCodecContext.silence := 0;
- WantedAudioCodecContext.samples := 1024;//SDL_AUDIO_BUFFER_SIZE;
-// WantedAudioCodecContext.callback := audio_callback;
- WantedAudioCodecContext.userdata := aCodecCtx;
-*)
+
+ if (SDL_OpenAudio(@wanted_spec, @spec) < 0) then
+ begin
+ writeln('SDL_OpenAudio: '+SDL_GetError());
+ exit;
+ end;
+
+ writeln( 'SDL opened audio device' );
+
+ aCodec := avcodec_find_decoder(aCodecCtx.codec_id);
+ if (aCodec = nil) then
+ begin
+ writeln('Unsupported codec!');
+ exit;
+ end;
+
+ avcodec_open(aCodecCtx, aCodec);
+
+ writeln( 'Opened the codec' );
+
+ packet_queue_init( audioq );
+ SDL_PauseAudio(0);
+
+ writeln( 'SDL_PauseAudio' );
+
end;
-(*
- if(SDL_OpenAudio(WantedAudioCodecContext, AudioCodecContext) < 0) then
- begin
- writeln( 'Could not do SDL_OpenAudio' );
- exit;
- end;
-*)
-
+ {$endif}
+
if(VideoStreamIndex >= 0) then
begin
VideoCodecContext:=VideoFormatContext^.streams[VideoStreamIndex]^.codec;