aboutsummaryrefslogtreecommitdiffstats
path: root/src/media
diff options
context:
space:
mode:
authorlotanrm <lotanrm@b956fd51-792f-4845-bead-9b4dfca2ff2c>2013-07-11 08:55:30 +0000
committerlotanrm <lotanrm@b956fd51-792f-4845-bead-9b4dfca2ff2c>2013-07-11 08:55:30 +0000
commitbd2ba8c9437c0c3bd4e84841f322501166145a6a (patch)
treec973560b1e706f87b03425329e54928dd29fdb3d /src/media
parent2596ea5ea76e3a6bb46ce1c7c5da3ea33bcda031 (diff)
downloadusdx-bd2ba8c9437c0c3bd4e84841f322501166145a6a.tar.gz
usdx-bd2ba8c9437c0c3bd4e84841f322501166145a6a.tar.xz
usdx-bd2ba8c9437c0c3bd4e84841f322501166145a6a.zip
In order to make ffmpeg-1.0 work:
Fixed avcodec FF_API flags (similar to r2996). Changed from old avformat_register_protocol2 to using AVIOContext. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2998 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'src/media')
-rw-r--r--src/media/UAudioDecoder_FFmpeg.pas12
-rw-r--r--src/media/UMediaCore_FFmpeg.pas80
-rw-r--r--src/media/UVideo.pas12
3 files changed, 92 insertions, 12 deletions
diff --git a/src/media/UAudioDecoder_FFmpeg.pas b/src/media/UAudioDecoder_FFmpeg.pas
index 21322064..5df42ff7 100644
--- a/src/media/UAudioDecoder_FFmpeg.pas
+++ b/src/media/UAudioDecoder_FFmpeg.pas
@@ -290,10 +290,12 @@ begin
Self.fFilename := Filename;
// use custom 'ufile' protocol for UTF-8 support
- {$IF LIBAVFORMAT_VERSION >= 53001003)}
+ {$IF LIBAVFORMAT_VERSION < 54029104}
AVResult := avformat_open_input(@fFormatCtx, PAnsiChar('ufile:'+FileName.ToUTF8), nil, nil);
- {$ELSE}
+ {$ELSEIF LIBAVFORMAT_VERSION < 53001003}
AVResult := av_open_input_file(fFormatCtx, PAnsiChar('ufile:'+FileName.ToUTF8), nil, 0, nil);
+ {$ELSE}
+ AVResult := FFmpegCore.AVFormatOpenInput(@fFormatCtx, PAnsiChar('ufile:'+FileName.ToUTF8));
{$IFEND}
if (AVResult <> 0) then
begin
@@ -462,10 +464,12 @@ begin
// Close the video file
if (fFormatCtx <> nil) then
begin
- {$IF LIBAVFORMAT_VERSION >= 53024002)}
+ {$IF LIBAVFORMAT_VERSION < 54029104}
avformat_close_input(@fFormatCtx);
- {$ELSE}
+ {$ELSEIF LIBAVFORMAT_VERSION < 53024002}
av_close_input_file(fFormatCtx);
+ {$ELSE}
+ FFmpegCore.AVFormatCloseInput(@fFormatCtx);
{$IFEND}
fFormatCtx := nil;
end;
diff --git a/src/media/UMediaCore_FFmpeg.pas b/src/media/UMediaCore_FFmpeg.pas
index c9e61c4a..d006e0d1 100644
--- a/src/media/UMediaCore_FFmpeg.pas
+++ b/src/media/UMediaCore_FFmpeg.pas
@@ -95,6 +95,8 @@ type
function ConvertFFmpegToAudioFormat(FFmpegFormat: TAVSampleFormat; out Format: TAudioSampleFormat): boolean;
procedure LockAVCodec();
procedure UnlockAVCodec();
+ function AVFormatOpenInput(ps: PPAVFormatContext; filename: {const} PAnsiChar): Integer;
+ procedure AVFormatCloseInput(ps: PPAVFormatContext);
end;
implementation
@@ -103,6 +105,15 @@ uses
SysUtils,
UConfig;
+{$IF LIBAVFORMAT_VERSION >= 54029104}
+{ redeclaration of constants with the same names as deprecated
+ constants in order to reuse old callback definitions }
+const
+ URL_RDONLY = 0; (**< read-only *)
+ URL_WRONLY = 1; (**< write-only *)
+ URL_RDWR = 2; (**< read-write *)
+ BLOCKSIZE = 4 * 1024;
+{$ELSE}
function FFmpegStreamOpen(h: PURLContext; filename: PAnsiChar; flags: cint): cint; cdecl; forward;
function FFmpegStreamRead(h: PURLContext; buf: PByteArray; size: cint): cint; cdecl; forward;
function FFmpegStreamWrite(h: PURLContext; buf: PByteArray; size: cint): cint; cdecl; forward;
@@ -118,6 +129,7 @@ const
url_seek: FFmpegStreamSeek;
url_close: FFmpegStreamClose;
);
+{$ENDIF}
var
Instance: TMediaCore_FFmpeg;
@@ -200,10 +212,10 @@ begin
CheckVersions();
- {$IF LIBAVFORMAT_VERSION <= 52111000} // 52.110.0
- av_register_protocol(@UTF8FileProtocol);
- {$ELSE}
+ {$IF LIBAVFORMAT_VERSION < 54029104}
av_register_protocol2(@UTF8FileProtocol, sizeof(UTF8FileProtocol));
+ {$ELSEIF LIBAVFORMAT_VERSION <= 52111000} // 52.110.0
+ av_register_protocol(@UTF8FileProtocol);
{$IFEND}
AVCodecLock := SDL_CreateMutex();
@@ -359,7 +371,11 @@ end;
* http://www.mail-archive.com/libav-user@mplayerhq.hu/msg02460.html
*}
+{$IF LIBAVFORMAT_VERSION >= 54029104}
+function FFmpegStreamOpen(Out h: Pointer; filename: PAnsiChar; flags: Integer): Integer;
+{$ELSE}
function FFmpegStreamOpen(h: PURLContext; filename: PAnsiChar; flags: cint): cint; cdecl;
+{$ENDIF}
var
Stream: TStream;
Mode: word;
@@ -367,7 +383,7 @@ var
FilePath: IPath;
begin
// check for protocol prefix ('ufile:') and strip it
- ProtPrefix := Format('%s:', [UTF8FileProtocol.name]);
+ ProtPrefix := Format('%s:', ['ufile']);
if (StrLComp(filename, PChar(ProtPrefix), Length(ProtPrefix)) = 0) then
begin
Inc(filename, Length(ProtPrefix));
@@ -386,7 +402,11 @@ begin
try
Stream := TBinaryFileStream.Create(FilePath, Mode);
+ {$IF LIBAVFORMAT_VERSION >= 54029104}
+ h := Stream;
+ {$ELSE}
h.priv_data := Stream;
+ {$ENDIF}
except
{$IF LIBAVUTIL_VERSION < 50043000} // < 50.43.0
Result := AVERROR_NOENT;
@@ -396,11 +416,19 @@ begin
end;
end;
+{$IF LIBAVFORMAT_VERSION >= 54029104}
+function FFmpegStreamRead(h: Pointer; buf: PByteArray; size: cint): cint; cdecl;
+{$ELSE}
function FFmpegStreamRead(h: PURLContext; buf: PByteArray; size: cint): cint; cdecl;
+{$ENDIF}
var
Stream: TStream;
begin
+ {$IF LIBAVFORMAT_VERSION >= 54029104}
+ Stream := TStream(h);
+ {$ELSE}
Stream := TStream(h.priv_data);
+ {$ENDIF}
if (Stream = nil) then
raise EInvalidContainer.Create('FFmpegStreamRead on nil');
try
@@ -410,11 +438,19 @@ begin
end;
end;
+{$IF LIBAVFORMAT_VERSION >= 54029104}
+function FFmpegStreamWrite(h: Pointer; buf: PByteArray; size: cint): cint; cdecl;
+{$ELSE}
function FFmpegStreamWrite(h: PURLContext; buf: PByteArray; size: cint): cint; cdecl;
+{$ENDIF}
var
Stream: TStream;
begin
+ {$IF LIBAVFORMAT_VERSION >= 54029104}
+ Stream := TStream(h);
+ {$ELSE}
Stream := TStream(h.priv_data);
+ {$ENDIF}
if (Stream = nil) then
raise EInvalidContainer.Create('FFmpegStreamWrite on nil');
try
@@ -424,12 +460,20 @@ begin
end;
end;
+{$IF LIBAVFORMAT_VERSION >= 54029104}
+function FFmpegStreamSeek(h: Pointer; pos: cint64; whence: cint): cint64; cdecl;
+{$ELSE}
function FFmpegStreamSeek(h: PURLContext; pos: cint64; whence: cint): cint64; cdecl;
+{$ENDIF}
var
Stream : TStream;
Origin : TSeekOrigin;
begin
+ {$IF LIBAVFORMAT_VERSION >= 54029104}
+ Stream := TStream(h);
+ {$ELSE}
Stream := TStream(h.priv_data);
+ {$ENDIF}
if (Stream = nil) then
raise EInvalidContainer.Create('FFmpegStreamSeek on nil');
case whence of
@@ -446,15 +490,43 @@ begin
Result := Stream.Seek(pos, Origin);
end;
+{$IF LIBAVFORMAT_VERSION >= 54029104}
+function FFmpegStreamClose(h: Pointer): Integer;
+{$ELSE}
function FFmpegStreamClose(h: PURLContext): cint; cdecl;
+{$ENDIF}
var
Stream : TStream;
begin
+ {$IF LIBAVFORMAT_VERSION >= 54029104}
+ Stream := TStream(h);
+ {$ELSE}
Stream := TStream(h.priv_data);
+ {$ENDIF}
Stream.Free;
Result := 0;
end;
+function TMediaCore_FFmpeg.AVFormatOpenInput(ps: PPAVFormatContext; filename: {const} PAnsiChar): Integer;
+var
+ h: Pointer;
+ buffer: Pointer;
+begin
+ ps^ := avformat_alloc_context();
+ buffer := av_malloc(BLOCKSIZE);
+ FFmpegStreamOpen(h, filename, URL_RDONLY);
+ ps^^.pb := avio_alloc_context(buffer, BLOCKSIZE, 0, h, FFmpegStreamRead, FFmpegStreamWrite, FFmpegStreamSeek);
+ Result := avformat_open_input(ps, filename, nil, nil);
+end;
+
+procedure TMediaCore_FFmpeg.AVFormatCloseInput(ps: PPAVFormatContext);
+begin
+ av_free(ps^^.pb.buffer);
+ FFmpegStreamClose(ps^^.pb.opaque);
+ { avformat_close_input frees AVIOContext pb, no avio_close needed }
+ { avformat_close_input frees AVFormatContext, no additional avformat_free_context needed }
+ avformat_close_input(ps);
+end;
{ TPacketQueue }
diff --git a/src/media/UVideo.pas b/src/media/UVideo.pas
index a4b12962..949a66c2 100644
--- a/src/media/UVideo.pas
+++ b/src/media/UVideo.pas
@@ -323,10 +323,12 @@ begin
fPboEnabled := PboSupported;
// use custom 'ufile' protocol for UTF-8 support
- {$IF LIBAVFORMAT_VERSION >= 53001003)}
+ {$IF LIBAVFORMAT_VERSION < 54029104}
errnum := avformat_open_input(@fFormatContext, PAnsiChar('ufile:'+FileName.ToUTF8), nil, nil);
- {$ELSE}
+ {$ELSEIF LIBAVFORMAT_VERSION < 53001003}
errnum := av_open_input_file(fFormatContext, PAnsiChar('ufile:'+FileName.ToUTF8), nil, 0, nil);
+ {$ELSE}
+ errnum := FFmpegCore.AVFormatOpenInput(@fFormatContext, PAnsiChar('ufile:'+FileName.ToUTF8));
{$IFEND}
if (errnum <> 0) then
begin
@@ -584,10 +586,12 @@ begin
end;
if (fFormatContext <> nil) then
- {$IF LIBAVFORMAT_VERSION >= 53024002)}
+ {$IF LIBAVFORMAT_VERSION < 54029104}
avformat_close_input(@fFormatContext);
- {$ELSE}
+ {$ELSEIF LIBAVFORMAT_VERSION < 53024002)}
av_close_input_file(fFormatContext);
+ {$ELSE}
+ FFmpegCore.AVFormatCloseInput(@fFormatContext);
{$IFEND}
fCodecContext := nil;