aboutsummaryrefslogtreecommitdiffstats
path: root/src/media
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/media/UAudioDecoder_FFmpeg.pas64
-rw-r--r--src/media/UMediaCore_FFmpeg.pas6
-rw-r--r--src/media/UVideo.pas38
3 files changed, 89 insertions, 19 deletions
diff --git a/src/media/UAudioDecoder_FFmpeg.pas b/src/media/UAudioDecoder_FFmpeg.pas
index 6b4f0cba..792655b2 100644
--- a/src/media/UAudioDecoder_FFmpeg.pas
+++ b/src/media/UAudioDecoder_FFmpeg.pas
@@ -80,7 +80,7 @@ const
const
// TODO: The factor 3/2 might not be necessary as we do not need extra
// space for synchronizing as in the tutorial.
- AUDIO_BUFFER_SIZE = (AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) div 2;
+ AUDIO_BUFFER_SIZE = (192000 * 3) div 2;
type
TFFmpegDecodeStream = class(TAudioDecodeStream)
@@ -290,9 +290,14 @@ begin
Self.fFilename := Filename;
// use custom 'ufile' protocol for UTF-8 support
- if (av_open_input_file(fFormatCtx, PAnsiChar('ufile:'+FileName.ToUTF8), nil, 0, nil) <> 0) then
- begin
- Log.LogError('av_open_input_file failed: "' + Filename.ToNative + '"', 'UAudio_FFmpeg');
+ {$IF LIBAVFORMAT_VERSION >= 53001003)}
+ AVResult := avformat_open_input(@fFormatCtx, PAnsiChar('ufile:'+FileName.ToUTF8), nil, nil);
+ {$ELSE}
+ AVResult := av_open_input_file(fFormatContext, PAnsiChar('ufile:'+FileName.ToUTF8), nil, 0, nil);
+ {$IFEND}
+ if (AVResult <> 0) then
+ begin
+ Log.LogError('Failed to open file "' + Filename.ToNative + '" ('+FFmpegCore.GetErrorString(AVResult)+')', 'UAudio_FFmpeg');
Exit;
end;
@@ -300,9 +305,14 @@ begin
fFormatCtx^.flags := fFormatCtx^.flags or AVFMT_FLAG_GENPTS;
// retrieve stream information
- if (av_find_stream_info(fFormatCtx) < 0) then
- begin
- Log.LogError('av_find_stream_info failed: "' + Filename.ToNative + '"', 'UAudio_FFmpeg');
+ {$IF LIBAVFORMAT_VERSION >= 53002000)}
+ AVResult := avformat_find_stream_info(fFormatCtx, nil);
+ {$ELSE}
+ AVResult := av_find_stream_info(fFormatCtx);
+ {$IFEND}
+ if (AVResult < 0) then
+ begin
+ Log.LogError('No stream info found: "' + Filename.ToNative + '"', 'UAudio_FFmpeg');
Close();
Exit;
end;
@@ -335,7 +345,7 @@ begin
{$IF LIBAVFORMAT_VERSION <= 52111000} // <= 52.111.0
fAudioStream := fFormatCtx.streams[fAudioStreamIndex];
{$ELSE}
- fAudioStream := Pointer(fFormatCtx.streams^) + fAudioStreamIndex;
+ fAudioStream := (fFormatCtx.streams + fAudioStreamIndex)^;
{$IFEND}
fAudioStreamPos := 0;
fCodecCtx := fAudioStream^.codec;
@@ -374,7 +384,11 @@ begin
// fail if called concurrently by different threads.
FFmpegCore.LockAVCodec();
try
+ {$IF LIBAVCODEC_VERSION >= 5300500}
+ AVResult := avcodec_open2(fCodecCtx, fCodec, nil);
+ {$ELSE}
AVResult := avcodec_open(fCodecCtx, fCodec);
+ {$IFEND}
finally
FFmpegCore.UnlockAVCodec();
end;
@@ -448,7 +462,11 @@ begin
// Close the video file
if (fFormatCtx <> nil) then
begin
+ {$IF LIBAVFORMAT_VERSION >= 53017003)}
+ avformat_close_input(@fFormatCtx);
+ {$ELSE}
av_close_input_file(fFormatCtx);
+ {$IFEND}
fFormatCtx := nil;
end;
@@ -672,6 +690,8 @@ var
ErrorCode: integer;
StartSilence: double; // duration of silence at start of stream
StartSilencePtr: PDouble; // pointer for the EMPTY status packet
+ fs: integer;
+ ue: integer;
// Note: pthreads wakes threads waiting on a mutex in the order of their
// priority and not in FIFO order. SDL does not provide any option to
@@ -817,7 +837,12 @@ begin
end;
// check for errors
- if (url_ferror(ByteIOCtx) <> 0) then
+ {$IF (LIBAVFORMAT_VERSION >= 52103000)}
+ ue := ByteIOCtx^.error;
+ {$ELSE}
+ ue := url_ferror(ByteIOCtx);
+ {$IFEND}
+ if (ue <> 0) then
begin
// an error occured -> abort and wait for repositioning or termination
fPacketQueue.PutStatus(PKT_STATUS_FLAG_ERROR, nil);
@@ -826,8 +851,12 @@ begin
// url_feof() does not detect an EOF for some files
// so we have to do it this way.
- if ((fFormatCtx^.file_size <> 0) and
- (ByteIOCtx^.pos >= fFormatCtx^.file_size)) then
+ {$IF (LIBAVFORMAT_VERSION >= 53009000)}
+ fs := avio_size(fFormatCtx^.pb);
+ {$ELSE}
+ fs := fFormatCtx^.file_size;
+ {$IFEND}
+ if ((fs <> 0) and (ByteIOCtx^.pos >= fs)) then
begin
fPacketQueue.PutStatus(PKT_STATUS_FLAG_EOF, nil);
Exit;
@@ -887,7 +916,11 @@ begin
FFmpegCore.LockAVCodec();
try
avcodec_close(fCodecCtx);
+ {$IF LIBAVCODEC_VERSION >= 5300500}
+ avcodec_open2(fCodecCtx, fCodec, nil);
+ {$ELSE}
avcodec_open(fCodecCtx, fCodec);
+ {$IFEND}
finally
FFmpegCore.UnlockAVCodec();
end;
@@ -903,6 +936,10 @@ var
{$IFDEF DebugFFmpegDecode}
TmpPos: double;
{$ENDIF}
+ {$IF LIBAVCODEC_VERSION >= 5300500}
+ AVFrame: PAVFrame;
+ got_frame_ptr: integer;
+ {$IFEND}
begin
Result := -1;
@@ -928,6 +965,11 @@ begin
begin
DataSize := BufferSize;
+// {$IF LIBAVCODEC_VERSION >= 53025000} // 53.25.0
+// PaketDecodedSize := avcodec_decode_audio4(fCodecCtx, AVFrame,
+// @got_frame_ptr, @fAudioPaket);
+// DataSize := AVFrame.nb_samples;
+// Buffer := PByteArray(AVFrame.data[0]);
{$IF LIBAVCODEC_VERSION >= 52122000} // 52.122.0
PaketDecodedSize := avcodec_decode_audio3(fCodecCtx, PSmallint(Buffer),
DataSize, @fAudioPaket);
diff --git a/src/media/UMediaCore_FFmpeg.pas b/src/media/UMediaCore_FFmpeg.pas
index 6abfb16d..dd8ddf07 100644
--- a/src/media/UMediaCore_FFmpeg.pas
+++ b/src/media/UMediaCore_FFmpeg.pas
@@ -270,9 +270,9 @@ begin
{$IF LIBAVFORMAT_VERSION <= 52111000} // <= 52.111.0
Stream := FormatCtx.streams[i];
{$ELSE}
- Stream := Pointer(FormatCtx.streams^) + i;
+ Stream := (FormatCtx.streams + i)^;
{$IFEND}
-
+
{$IF LIBAVCODEC_VERSION < 52064000} // < 52.64.0
if (Stream.codec.codec_type = CODEC_TYPE_VIDEO) and
(FirstVideoStream < 0) then
@@ -320,7 +320,7 @@ begin
{$IF LIBAVFORMAT_VERSION <= 52111000} // <= 52.111.0
Stream := FormatCtx^.streams[i];
{$ELSE}
- Stream := Pointer(FormatCtx^.streams^) + i;
+ Stream := (FormatCtx^.streams + i)^;
{$IFEND}
{$IF LIBAVCODEC_VERSION < 52064000} // < 52.64.0
diff --git a/src/media/UVideo.pas b/src/media/UVideo.pas
index fe043504..eaffa9ea 100644
--- a/src/media/UVideo.pas
+++ b/src/media/UVideo.pas
@@ -322,7 +322,11 @@ begin
fPboEnabled := PboSupported;
// use custom 'ufile' protocol for UTF-8 support
+ {$IF LIBAVFORMAT_VERSION >= 53001003)}
+ errnum := avformat_open_input(@fFormatContext, PAnsiChar('ufile:'+FileName.ToUTF8), nil, nil);
+ {$ELSE}
errnum := av_open_input_file(fFormatContext, PAnsiChar('ufile:'+FileName.ToUTF8), nil, 0, nil);
+ {$IFEND}
if (errnum <> 0) then
begin
Log.LogError('Failed to open file "'+ FileName.ToNative +'" ('+FFmpegCore.GetErrorString(errnum)+')');
@@ -330,7 +334,12 @@ begin
end;
// update video info
- if (av_find_stream_info(fFormatContext) < 0) then
+ {$IF LIBAVFORMAT_VERSION >= 53002000)}
+ errnum := avformat_find_stream_info(fFormatContext, nil);
+ {$ELSE}
+ errnum := av_find_stream_info(fFormatContext);
+ {$IFEND}
+ if (errnum < 0) then
begin
Log.LogError('No stream info found', 'TVideoPlayback_ffmpeg.Open');
Close();
@@ -350,7 +359,7 @@ begin
{$IF LIBAVFORMAT_VERSION <= 52111000} // <= 52.111.0
fStream := fFormatContext^.streams[fStreamIndex];
{$ELSE}
- fStream := Pointer(fFormatContext^.streams^) + fStreamIndex;
+ fStream := (fFormatContext^.streams + fStreamIndex)^;
{$IFEND}
fCodecContext := fStream^.codec;
@@ -377,7 +386,11 @@ begin
// fail if called concurrently by different threads.
FFmpegCore.LockAVCodec();
try
+ {$IF LIBAVCODEC_VERSION >= 5300500)}
+ errnum := avcodec_open2(fCodecContext, fCodec, nil);
+ {$ELSE}
errnum := avcodec_open(fCodecContext, fCodec);
+ {$IFEND}
finally
FFmpegCore.UnlockAVCodec();
end;
@@ -570,7 +583,11 @@ begin
end;
if (fFormatContext <> nil) then
+ {$IF LIBAVFORMAT_VERSION >= 53017003)}
+ avformat_close_input(@fFormatContext);
+ {$ELSE}
av_close_input_file(fFormatContext);
+ {$IFEND}
fCodecContext := nil;
fFormatContext := nil;
@@ -616,6 +633,8 @@ var
errnum: integer;
AVPacket: TAVPacket;
pts: double;
+ fs: integer;
+ ue: integer;
begin
Result := false;
FrameFinished := 0;
@@ -645,7 +664,12 @@ begin
end;
// check for errors
- if (url_ferror(pbIOCtx) <> 0) then
+ {$IF (LIBAVFORMAT_VERSION >= 52103000)}
+ ue := pbIOCtx^.error;
+ {$ELSE}
+ ue := url_ferror(pbIOCtx);
+ {$IFEND}
+ if (ue <> 0) then
begin
Log.LogError('Video decoding file error', 'TVideoPlayback_FFmpeg.DecodeFrame');
Exit;
@@ -653,8 +677,12 @@ begin
// url_feof() does not detect an EOF for some mov-files (e.g. deluxe.mov)
// so we have to do it this way.
- if ((fFormatContext^.file_size <> 0) and
- (pbIOCtx^.pos >= fFormatContext^.file_size)) then
+ {$IF (LIBAVFORMAT_VERSION >= 53009000)}
+ fs := avio_size(fFormatContext^.pb);
+ {$ELSE}
+ fs := fFormatContext^.file_size;
+ {$IFEND}
+ if ((fs <> 0) and (pbIOCtx^.pos >= fs)) then
begin
fEOF := true;
Exit;