aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--src/lib/ffmpeg-1.0/avcodec.pas51
-rw-r--r--src/media/UAudioDecoder_FFmpeg.pas12
-rw-r--r--src/media/UMediaCore_FFmpeg.pas80
-rw-r--r--src/media/UVideo.pas12
4 files changed, 117 insertions, 38 deletions
diff --git a/src/lib/ffmpeg-1.0/avcodec.pas b/src/lib/ffmpeg-1.0/avcodec.pas
index 1254b997..57cf6164 100644
--- a/src/lib/ffmpeg-1.0/avcodec.pas
+++ b/src/lib/ffmpeg-1.0/avcodec.pas
@@ -110,52 +110,51 @@ const
* dropped at a future version bump. The defines themselves are not part of
* the public API and may change, break or disappear at any time.
*)
-const
{$ifndef FF_API_REQUEST_CHANNELS}
- FF_API_REQUEST_CHANNELS = (LIBAVCODEC_VERSION_MAJOR < 55);
+{$define FF_API_REQUEST_CHANNELS} // = (LIBAVCODEC_VERSION_MAJOR < 55);
{$endif}
{$ifndef FF_API_ALLOC_CONTEXT}
- FF_API_ALLOC_CONTEXT = (LIBAVCODEC_VERSION_MAJOR < 55);
+{$define FF_API_ALLOC_CONTEXT} // = (LIBAVCODEC_VERSION_MAJOR < 55);
{$endif}
{$ifndef FF_API_AVCODEC_OPEN}
- FF_API_AVCODEC_OPEN = (LIBAVCODEC_VERSION_MAJOR < 55);
+{$define FF_API_AVCODEC_OPEN} // = (LIBAVCODEC_VERSION_MAJOR < 55);
{$endif}
{$ifndef FF_API_OLD_DECODE_AUDIO}
- FF_API_OLD_DECODE_AUDIO = (LIBAVCODEC_VERSION_MAJOR < 55);
+{$define FF_API_OLD_DECODE_AUDIO} // = (LIBAVCODEC_VERSION_MAJOR < 55);
{$endif}
{$ifndef FF_API_OLD_TIMECODE}
- FF_API_OLD_TIMECODE = (LIBAVCODEC_VERSION_MAJOR < 55);
+{$define FF_API_OLD_TIMECODE} // = (LIBAVCODEC_VERSION_MAJOR < 55);
{$endif}
{$ifndef FF_API_OLD_ENCODE_AUDIO}
- FF_API_OLD_ENCODE_AUDIO = (LIBAVCODEC_VERSION_MAJOR < 55);
+{$define FF_API_OLD_ENCODE_AUDIO} // = (LIBAVCODEC_VERSION_MAJOR < 55);
{$endif}
{$ifndef FF_API_OLD_ENCODE_VIDEO}
- FF_API_OLD_ENCODE_VIDEO = (LIBAVCODEC_VERSION_MAJOR < 55);
+{$define FF_API_OLD_ENCODE_VIDEO} // = (LIBAVCODEC_VERSION_MAJOR < 55);
{$endif}
{$ifndef FF_API_MPV_GLOBAL_OPTS}
- FF_API_MPV_GLOBAL_OPTS = (LIBAVCODEC_VERSION_MAJOR < 55);
+{$define FF_API_MPV_GLOBAL_OPTS} // = (LIBAVCODEC_VERSION_MAJOR < 55);
{$endif}
{$ifndef FF_API_COLOR_TABLE_ID}
- FF_API_COLOR_TABLE_ID = (LIBAVCODEC_VERSION_MAJOR < 55);
+{$define FF_API_COLOR_TABLE_ID} // = (LIBAVCODEC_VERSION_MAJOR < 55);
{$endif}
{$ifndef FF_API_INTER_THRESHOLD}
- FF_API_INTER_THRESHOLD = (LIBAVCODEC_VERSION_MAJOR < 55);
+{$define FF_API_INTER_THRESHOLD} // = (LIBAVCODEC_VERSION_MAJOR < 55);
{$endif}
{$ifndef FF_API_SUB_ID}
- FF_API_SUB_ID = (LIBAVCODEC_VERSION_MAJOR < 55);
+{$define FF_API_SUB_ID} // = (LIBAVCODEC_VERSION_MAJOR < 55);
{$endif}
{$ifndef FF_API_DSP_MASK}
- FF_API_DSP_MASK = (LIBAVCODEC_VERSION_MAJOR < 55);
+{$define FF_API_DSP_MASK} // = (LIBAVCODEC_VERSION_MAJOR < 55);
{$endif}
{$ifndef FF_API_FIND_BEST_PIX_FMT}
- FF_API_FIND_BEST_PIX_FMT = (LIBAVCODEC_VERSION_MAJOR < 55);
+{$define FF_API_FIND_BEST_PIX_FMT} // = (LIBAVCODEC_VERSION_MAJOR < 55);
{$endif}
{$ifndef FF_API_CODEC_ID}
- FF_API_CODEC_ID = (LIBAVCODEC_VERSION_MAJOR < 55);
+{$define FF_API_CODEC_ID} // = (LIBAVCODEC_VERSION_MAJOR < 55);
{$endif}
{$ifndef FF_API_VDA_ASYNC}
- FF_API_VDA_ASYNC = (LIBAVCODEC_VERSION_MAJOR < 55);
+{$define FF_API_VDA_ASYNC} // = (LIBAVCODEC_VERSION_MAJOR < 55);
{$endif}
{$IFNDEF FPC}
@@ -670,7 +669,7 @@ const
*)
AV_CODEC_PROP_LOSSLESS = 1 << 2;
-{$IF FF_API_OLD_DECODE_AUDIO}
+{$IFDEF FF_API_OLD_DECODE_AUDIO}
(* in bytes *)
AVCODEC_MAX_AUDIO_FRAME_SIZE = 192000; // 1 second of 48khz 32bit audio
{$IFEND}
@@ -1882,7 +1881,7 @@ type
*)
stream_codec_tag: cuint;
-{$IF FF_API_SUB_ID}
+{$IFDEF FF_API_SUB_ID}
(**
* @deprecated this field is unused
*)
@@ -2615,7 +2614,7 @@ type
*)
cutoff: cint;
-{$IF FF_API_REQUEST_CHANNELS}
+{$IFDEF FF_API_REQUEST_CHANNELS}
(**
* Decoder should decode to this many channels if it can (0 for default)
* - encoding: unused
@@ -3062,7 +3061,7 @@ type
*)
idct_algo: cint;
-{$IF FF_API_DSP_MASK}
+{$IFDEF FF_API_DSP_MASK}
(**
* Unused.
* @deprecated use av_set_cpu_flags_mask() instead.
@@ -3256,7 +3255,7 @@ type
* - encoding unused.
* - decodimg set by user
*)
- pkt_timebase: PAVRational;
+ pkt_timebase: TAVRational;
(**
* AVCodecDescriptor
@@ -3644,7 +3643,7 @@ procedure avcodec_register(codec: PAVCodec);
procedure avcodec_register_all();
cdecl; external av__codec;
-{$IF FF_API_ALLOC_CONTEXT}
+{$IFDEF FF_API_ALLOC_CONTEXT}
(**
* Allocate an AVCodecContext and sets it fields to default values. The
* resulting struct can be deallocated by simply calling av_free().
@@ -3776,7 +3775,7 @@ procedure avcodec_get_frame_defaults(frame: PAVFrame);
procedure avcodec_free_frame(frame: PPAVFrame);
cdecl; external av__codec;
-{$IF FF_API_AVCODEC_OPEN}
+{$IFDEF FF_API_AVCODEC_OPEN}
(**
* Initialize the AVCodecContext to use the given AVCodec. Prior to using this
* function the context has to be allocated.
@@ -4049,7 +4048,7 @@ procedure avcodec_align_dimensions2(s: PAVCodecContext; width: PCint; height: PC
linesize_align: PAVNDPArray);
cdecl; external av__codec;
-{$IF FF_API_OLD_DECODE_AUDIO}
+{$IFDEF FF_API_OLD_DECODE_AUDIO}
(**
* Wrapper function which calls avcodec_decode_audio4.
*
@@ -4445,7 +4444,7 @@ function avcodec_find_encoder(id: TAVCodecID): PAVCodec;
function avcodec_find_encoder_by_name(name: PAnsiChar): PAVCodec;
cdecl; external av__codec;
-{$IF FF_API_OLD_ENCODE_AUDIO}
+{$IFDEF FF_API_OLD_ENCODE_AUDIO}
(**
* Encode an audio frame from samples into buf.
*
@@ -4518,7 +4517,7 @@ function avcodec_encode_audio2(avctx: PAVCodecContext; avpkt: PAVPacket;
frame: {const} PAVFrame; got_packet_ptr: Pcint): cint;
cdecl; external av__codec;
-{$IF FF_API_OLD_ENCODE_AUDIO}
+{$IFDEF FF_API_OLD_ENCODE_AUDIO}
(**
* @deprecated use avcodec_encode_video2() instead.
*
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;