Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
5e486964
Commit
5e486964
authored
Nov 04, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ffmpeg: no CamelCase
Renamed variables.
parent
e26bff9b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
102 deletions
+103
-102
ffmpeg_plugin.c
src/decoder/ffmpeg_plugin.c
+101
-100
decoder_list.c
src/decoder_list.c
+2
-2
No files found.
src/decoder/ffmpeg_plugin.c
View file @
5e486964
...
...
@@ -40,166 +40,167 @@
#include <libavformat/avio.h>
#endif
typedef
struc
t
{
int
audio
S
tream
;
AVFormatContext
*
pFormatCtx
;
AVCodecContext
*
aCodecCtx
;
AVCodec
*
aC
odec
;
struct
ffmpeg_contex
t
{
int
audio
_s
tream
;
AVFormatContext
*
format_context
;
AVCodecContext
*
codec_context
;
AVCodec
*
c
odec
;
struct
decoder
*
decoder
;
struct
input_stream
*
input
;
struct
tag
*
tag
;
}
BasePtrs
;
};
typedef
struct
{
/** hack - see url_to_
base
() */
struct
ffmpeg_stream
{
/** hack - see url_to_
struct
() */
char
url
[
8
];
struct
decoder
*
decoder
;
struct
input_stream
*
input
;
}
FopsHelper
;
};
/**
* Convert a faked mpd:// URL to a
FopsHelper
structure. This is a
* Convert a faked mpd:// URL to a
ffmpeg_stream
structure. This is a
* hack because ffmpeg does not provide a nice API for passing a
* user-defined pointer to mpdurl_open().
*/
static
FopsHelper
*
url_to_base
(
const
char
*
url
)
static
struct
ffmpeg_stream
*
url_to_struct
(
const
char
*
url
)
{
union
{
const
char
*
in
;
FopsHelper
*
out
;
struct
ffmpeg_stream
*
out
;
}
u
=
{
.
in
=
url
};
return
u
.
out
;
}
static
int
mpd
url
_open
(
URLContext
*
h
,
const
char
*
filename
,
static
int
mpd
_ffmpeg
_open
(
URLContext
*
h
,
const
char
*
filename
,
mpd_unused
int
flags
)
{
FopsHelper
*
base
=
url_to_base
(
filename
);
h
->
priv_data
=
base
;
h
->
is_streamed
=
(
base
->
input
->
seekable
?
0
:
1
)
;
struct
ffmpeg_stream
*
stream
=
url_to_struct
(
filename
);
h
->
priv_data
=
stream
;
h
->
is_streamed
=
stream
->
input
->
seekable
?
0
:
1
;
return
0
;
}
static
int
mpd
url
_read
(
URLContext
*
h
,
unsigned
char
*
buf
,
int
size
)
static
int
mpd
_ffmpeg
_read
(
URLContext
*
h
,
unsigned
char
*
buf
,
int
size
)
{
FopsHelper
*
base
=
(
FopsHelper
*
)
h
->
priv_data
;
struct
ffmpeg_stream
*
stream
=
(
struct
ffmpeg_stream
*
)
h
->
priv_data
;
while
(
true
)
{
size_t
ret
=
decoder_read
(
base
->
decoder
,
base
->
input
,
size_t
ret
=
decoder_read
(
stream
->
decoder
,
stream
->
input
,
(
void
*
)
buf
,
size
);
if
(
ret
>
0
)
return
ret
;
if
(
input_stream_eof
(
base
->
input
)
||
(
base
->
decoder
&&
decoder_get_command
(
base
->
decoder
)
!=
DECODE_COMMAND_NONE
))
if
(
input_stream_eof
(
stream
->
input
)
||
(
stream
->
decoder
&&
decoder_get_command
(
stream
->
decoder
)
!=
DECODE_COMMAND_NONE
))
return
0
;
my_usleep
(
10000
);
}
}
static
int64_t
mpd
url
_seek
(
URLContext
*
h
,
int64_t
pos
,
int
whence
)
static
int64_t
mpd
_ffmpeg
_seek
(
URLContext
*
h
,
int64_t
pos
,
int
whence
)
{
FopsHelper
*
base
=
(
FopsHelper
*
)
h
->
priv_data
;
struct
ffmpeg_stream
*
stream
=
(
struct
ffmpeg_stream
*
)
h
->
priv_data
;
if
(
whence
!=
AVSEEK_SIZE
)
{
//only ftell
(
void
)
input_stream_seek
(
base
->
input
,
pos
,
whence
);
(
void
)
input_stream_seek
(
stream
->
input
,
pos
,
whence
);
}
return
base
->
input
->
offset
;
return
stream
->
input
->
offset
;
}
static
int
mpd
url
_close
(
URLContext
*
h
)
static
int
mpd
_ffmpeg
_close
(
URLContext
*
h
)
{
h
->
priv_data
=
0
;
return
0
;
}
static
URLProtocol
mpd
url
_fileops
=
{
static
URLProtocol
mpd
_ffmpeg
_fileops
=
{
.
name
=
"mpd"
,
.
url_open
=
mpd
url
_open
,
.
url_read
=
mpd
url
_read
,
.
url_seek
=
mpd
url
_seek
,
.
url_close
=
mpd
url
_close
,
.
url_open
=
mpd
_ffmpeg
_open
,
.
url_read
=
mpd
_ffmpeg
_read
,
.
url_seek
=
mpd
_ffmpeg
_seek
,
.
url_close
=
mpd
_ffmpeg
_close
,
};
static
bool
ffmpeg_init
(
void
)
{
av_register_all
();
register_protocol
(
&
mpd
url
_fileops
);
register_protocol
(
&
mpd
_ffmpeg
_fileops
);
return
true
;
}
static
bool
ffmpeg_helper
(
struct
input_stream
*
input
,
bool
(
*
callback
)(
BasePtrs
*
ptrs
),
BasePtrs
*
ptrs
)
ffmpeg_helper
(
struct
input_stream
*
input
,
bool
(
*
callback
)(
struct
ffmpeg_context
*
ctx
),
struct
ffmpeg_context
*
ctx
)
{
AVFormatContext
*
pFormatCtx
;
AVCodecContext
*
aCodecCtx
;
AVCodec
*
aC
odec
;
int
audio
S
tream
;
AVFormatContext
*
format_context
;
AVCodecContext
*
codec_context
;
AVCodec
*
c
odec
;
int
audio
_s
tream
;
unsigned
i
;
FopsHelper
fopshelp
=
{
struct
ffmpeg_stream
stream
=
{
.
url
=
"mpd://X"
,
/* only the mpd:// prefix matters */
};
bool
ret
;
fopshelp
.
input
=
input
;
if
(
ptrs
&&
ptrs
->
decoder
)
{
fopshelp
.
decoder
=
ptrs
->
decoder
;
//are we in decoding loop ?
stream
.
input
=
input
;
if
(
ctx
&&
ctx
->
decoder
)
{
stream
.
decoder
=
ctx
->
decoder
;
//are we in decoding loop ?
}
else
{
fopshelp
.
decoder
=
NULL
;
stream
.
decoder
=
NULL
;
}
//ffmpeg works with ours "fileops" helper
if
(
av_open_input_file
(
&
pFormatCtx
,
fopshelp
.
url
,
NULL
,
0
,
NULL
)
!=
0
)
{
if
(
av_open_input_file
(
&
format_context
,
stream
.
url
,
NULL
,
0
,
NULL
)
!=
0
)
{
ERROR
(
"Open failed!
\n
"
);
return
false
;
}
if
(
av_find_stream_info
(
pFormatCtx
)
<
0
)
{
if
(
av_find_stream_info
(
format_context
)
<
0
)
{
ERROR
(
"Couldn't find stream info!
\n
"
);
return
false
;
}
audio
S
tream
=
-
1
;
for
(
i
=
0
;
i
<
pFormatCtx
->
nb_streams
;
i
++
)
{
if
(
pFormatCtx
->
streams
[
i
]
->
codec
->
codec_type
==
CODEC_TYPE_AUDIO
&&
audio
S
tream
<
0
)
{
audio
S
tream
=
i
;
audio
_s
tream
=
-
1
;
for
(
i
=
0
;
i
<
format_context
->
nb_streams
;
i
++
)
{
if
(
format_context
->
streams
[
i
]
->
codec
->
codec_type
==
CODEC_TYPE_AUDIO
&&
audio
_s
tream
<
0
)
{
audio
_s
tream
=
i
;
}
}
if
(
audioStream
==
-
1
)
{
if
(
audio_stream
==
-
1
)
{
ERROR
(
"No audio stream inside!
\n
"
);
return
false
;
}
aCodecCtx
=
pFormatCtx
->
streams
[
audioS
tream
]
->
codec
;
aCodec
=
avcodec_find_decoder
(
aCodecCtx
->
codec_id
);
codec_context
=
format_context
->
streams
[
audio_s
tream
]
->
codec
;
codec
=
avcodec_find_decoder
(
codec_context
->
codec_id
);
if
(
!
aC
odec
)
{
if
(
!
c
odec
)
{
ERROR
(
"Unsupported audio codec!
\n
"
);
return
false
;
}
if
(
avcodec_open
(
aCodecCtx
,
aC
odec
)
<
0
)
{
if
(
avcodec_open
(
codec_context
,
c
odec
)
<
0
)
{
ERROR
(
"Could not open codec!
\n
"
);
return
false
;
}
if
(
callback
)
{
ptrs
->
audioStream
=
audioS
tream
;
ptrs
->
pFormatCtx
=
pFormatCtx
;
ptrs
->
aCodecCtx
=
aCodecCtx
;
ptrs
->
aCodec
=
aC
odec
;
ctx
->
audio_stream
=
audio_s
tream
;
ctx
->
format_context
=
format_context
;
ctx
->
codec_context
=
codec_context
;
ctx
->
codec
=
c
odec
;
ret
=
(
*
callback
)(
ptrs
);
ret
=
callback
(
ctx
);
}
else
ret
=
true
;
avcodec_close
(
aCodecCtx
);
av_close_input_file
(
pFormatCtx
);
avcodec_close
(
codec_context
);
av_close_input_file
(
format_context
);
return
ret
;
}
...
...
@@ -243,11 +244,11 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
}
static
bool
ffmpeg_decode_internal
(
BasePtrs
*
base
)
ffmpeg_decode_internal
(
struct
ffmpeg_context
*
ctx
)
{
struct
decoder
*
decoder
=
base
->
decoder
;
AVCodecContext
*
aCodecCtx
=
base
->
aCodecCtx
;
AVFormatContext
*
pFormatCtx
=
base
->
pFormatCtx
;
struct
decoder
*
decoder
=
ctx
->
decoder
;
AVCodecContext
*
codec_context
=
ctx
->
codec_context
;
AVFormatContext
*
format_context
=
ctx
->
format_context
;
AVPacket
packet
;
struct
audio_format
audio_format
;
enum
decoder_command
cmd
;
...
...
@@ -255,31 +256,31 @@ ffmpeg_decode_internal(BasePtrs *base)
total_time
=
0
;
if
(
aCodecCtx
->
channels
>
2
)
{
aCodecCtx
->
channels
=
2
;
if
(
codec_context
->
channels
>
2
)
{
codec_context
->
channels
=
2
;
}
audio_format
.
bits
=
(
uint8_t
)
16
;
audio_format
.
sample_rate
=
(
unsigned
int
)
aCodecCtx
->
sample_rate
;
audio_format
.
channels
=
aCodecCtx
->
channels
;
audio_format
.
sample_rate
=
(
unsigned
int
)
codec_context
->
sample_rate
;
audio_format
.
channels
=
codec_context
->
channels
;
//there is some problem with this on some demux (mp3 at least)
if
(
pFormatCtx
->
duration
!=
(
int
)
AV_NOPTS_VALUE
)
{
total_time
=
pFormatCtx
->
duration
/
AV_TIME_BASE
;
if
(
format_context
->
duration
!=
(
int
)
AV_NOPTS_VALUE
)
{
total_time
=
format_context
->
duration
/
AV_TIME_BASE
;
}
decoder_initialized
(
decoder
,
&
audio_format
,
base
->
input
->
seekable
,
total_time
);
ctx
->
input
->
seekable
,
total_time
);
do
{
if
(
av_read_frame
(
pFormatCtx
,
&
packet
)
<
0
)
if
(
av_read_frame
(
format_context
,
&
packet
)
<
0
)
/* end of file */
break
;
if
(
packet
.
stream_index
==
base
->
audioS
tream
)
cmd
=
ffmpeg_send_packet
(
decoder
,
base
->
input
,
&
packet
,
aCodecCtx
,
&
pFormatCtx
->
streams
[
base
->
audioS
tream
]
->
time_base
);
if
(
packet
.
stream_index
==
ctx
->
audio_s
tream
)
cmd
=
ffmpeg_send_packet
(
decoder
,
ctx
->
input
,
&
packet
,
codec_context
,
&
format_context
->
streams
[
ctx
->
audio_s
tream
]
->
time_base
);
else
cmd
=
decoder_get_command
(
decoder
);
...
...
@@ -288,7 +289,7 @@ ffmpeg_decode_internal(BasePtrs *base)
if
(
cmd
==
DECODE_COMMAND_SEEK
)
{
current
=
decoder_seek_where
(
decoder
)
*
AV_TIME_BASE
;
if
(
av_seek_frame
(
pFormatCtx
,
-
1
,
current
,
0
)
<
0
)
if
(
av_seek_frame
(
format_context
,
-
1
,
current
,
0
)
<
0
)
decoder_seek_error
(
decoder
);
else
decoder_command_finished
(
decoder
);
...
...
@@ -301,20 +302,20 @@ ffmpeg_decode_internal(BasePtrs *base)
static
bool
ffmpeg_decode
(
struct
decoder
*
decoder
,
struct
input_stream
*
input
)
{
BasePtrs
base
;
struct
ffmpeg_context
ctx
;
base
.
input
=
input
;
base
.
decoder
=
decoder
;
ctx
.
input
=
input
;
ctx
.
decoder
=
decoder
;
return
ffmpeg_helper
(
input
,
ffmpeg_decode_internal
,
&
base
);
return
ffmpeg_helper
(
input
,
ffmpeg_decode_internal
,
&
ctx
);
}
static
bool
ffmpeg_tag_internal
(
BasePtrs
*
base
)
static
bool
ffmpeg_tag_internal
(
struct
ffmpeg_context
*
ctx
)
{
struct
tag
*
tag
=
(
struct
tag
*
)
base
->
tag
;
struct
tag
*
tag
=
(
struct
tag
*
)
ctx
->
tag
;
if
(
base
->
pFormatCtx
->
duration
!=
(
int
)
AV_NOPTS_VALUE
)
{
tag
->
time
=
base
->
pFormatCtx
->
duration
/
AV_TIME_BASE
;
if
(
ctx
->
format_context
->
duration
!=
(
int
)
AV_NOPTS_VALUE
)
{
tag
->
time
=
ctx
->
format_context
->
duration
/
AV_TIME_BASE
;
}
else
{
tag
->
time
=
0
;
}
...
...
@@ -326,7 +327,7 @@ static bool ffmpeg_tag_internal(BasePtrs *base)
static
struct
tag
*
ffmpeg_tag
(
const
char
*
file
)
{
struct
input_stream
input
;
BasePtrs
base
;
struct
ffmpeg_context
ctx
;
bool
ret
;
if
(
!
input_stream_open
(
&
input
,
file
))
{
...
...
@@ -334,18 +335,18 @@ static struct tag *ffmpeg_tag(const char *file)
return
NULL
;
}
base
.
decoder
=
NULL
;
base
.
tag
=
tag_new
();
ctx
.
decoder
=
NULL
;
ctx
.
tag
=
tag_new
();
ret
=
ffmpeg_helper
(
&
input
,
ffmpeg_tag_internal
,
&
base
);
ret
=
ffmpeg_helper
(
&
input
,
ffmpeg_tag_internal
,
&
ctx
);
if
(
!
ret
)
{
tag_free
(
base
.
tag
);
base
.
tag
=
NULL
;
tag_free
(
ctx
.
tag
);
ctx
.
tag
=
NULL
;
}
input_stream_close
(
&
input
);
return
base
.
tag
;
return
ctx
.
tag
;
}
/**
...
...
@@ -357,14 +358,14 @@ static struct tag *ffmpeg_tag(const char *file)
* only that files
*/
static
const
char
*
const
ffmpeg_
S
uffixes
[]
=
{
static
const
char
*
const
ffmpeg_
s
uffixes
[]
=
{
"wma"
,
"asf"
,
"wmv"
,
"mpeg"
,
"mpg"
,
"avi"
,
"vob"
,
"mov"
,
"qt"
,
"swf"
,
"rm"
,
"swf"
,
"mp1"
,
"mp2"
,
"mp3"
,
"mp4"
,
"m4a"
,
"flac"
,
"ogg"
,
"wav"
,
"au"
,
"aiff"
,
"aif"
,
"ac3"
,
"aac"
,
"mpc"
,
NULL
};
//not sure if this is correct...
static
const
char
*
const
ffmpeg_
Mime
types
[]
=
{
static
const
char
*
const
ffmpeg_
mime_
types
[]
=
{
"video/x-ms-asf"
,
"audio/x-ms-wma"
,
"audio/x-ms-wax"
,
...
...
@@ -378,13 +379,13 @@ static const char *const ffmpeg_Mimetypes[] = {
NULL
};
const
struct
decoder_plugin
ffmpeg
P
lugin
=
{
const
struct
decoder_plugin
ffmpeg
_p
lugin
=
{
.
name
=
"ffmpeg"
,
.
init
=
ffmpeg_init
,
.
try_decode
=
ffmpeg_try_decode
,
.
stream_decode
=
ffmpeg_decode
,
.
tag_dup
=
ffmpeg_tag
,
.
stream_types
=
INPUT_PLUGIN_STREAM_URL
|
INPUT_PLUGIN_STREAM_FILE
,
.
suffixes
=
ffmpeg_
S
uffixes
,
.
mime_types
=
ffmpeg_
Mime
types
.
suffixes
=
ffmpeg_
s
uffixes
,
.
mime_types
=
ffmpeg_
mime_
types
};
src/decoder_list.c
View file @
5e486964
...
...
@@ -31,7 +31,7 @@ extern const struct decoder_plugin aacPlugin;
extern
const
struct
decoder_plugin
mpcPlugin
;
extern
const
struct
decoder_plugin
wavpackPlugin
;
extern
const
struct
decoder_plugin
modPlugin
;
extern
const
struct
decoder_plugin
ffmpeg
P
lugin
;
extern
const
struct
decoder_plugin
ffmpeg
_p
lugin
;
static
const
struct
decoder_plugin
*
const
decoder_plugins
[]
=
{
#ifdef HAVE_MAD
...
...
@@ -65,7 +65,7 @@ static const struct decoder_plugin *const decoder_plugins[] = {
&
modPlugin
,
#endif
#ifdef HAVE_FFMPEG
&
ffmpeg
P
lugin
,
&
ffmpeg
_p
lugin
,
#endif
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment