ffmpeg: no CamelCase
Renamed variables.
This commit is contained in:
parent
e26bff9b92
commit
5e486964e8
@ -40,166 +40,167 @@
|
|||||||
#include <libavformat/avio.h>
|
#include <libavformat/avio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
struct ffmpeg_context {
|
||||||
int audioStream;
|
int audio_stream;
|
||||||
AVFormatContext *pFormatCtx;
|
AVFormatContext *format_context;
|
||||||
AVCodecContext *aCodecCtx;
|
AVCodecContext *codec_context;
|
||||||
AVCodec *aCodec;
|
AVCodec *codec;
|
||||||
struct decoder *decoder;
|
struct decoder *decoder;
|
||||||
struct input_stream *input;
|
struct input_stream *input;
|
||||||
struct tag *tag;
|
struct tag *tag;
|
||||||
} BasePtrs;
|
};
|
||||||
|
|
||||||
typedef struct {
|
struct ffmpeg_stream {
|
||||||
/** hack - see url_to_base() */
|
/** hack - see url_to_struct() */
|
||||||
char url[8];
|
char url[8];
|
||||||
|
|
||||||
struct decoder *decoder;
|
struct decoder *decoder;
|
||||||
struct input_stream *input;
|
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
|
* hack because ffmpeg does not provide a nice API for passing a
|
||||||
* user-defined pointer to mpdurl_open().
|
* 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 {
|
union {
|
||||||
const char *in;
|
const char *in;
|
||||||
FopsHelper *out;
|
struct ffmpeg_stream *out;
|
||||||
} u = { .in = url };
|
} u = { .in = url };
|
||||||
return u.out;
|
return u.out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mpdurl_open(URLContext *h, const char *filename,
|
static int mpd_ffmpeg_open(URLContext *h, const char *filename,
|
||||||
mpd_unused int flags)
|
mpd_unused int flags)
|
||||||
{
|
{
|
||||||
FopsHelper *base = url_to_base(filename);
|
struct ffmpeg_stream *stream = url_to_struct(filename);
|
||||||
h->priv_data = base;
|
h->priv_data = stream;
|
||||||
h->is_streamed = (base->input->seekable ? 0 : 1);
|
h->is_streamed = stream->input->seekable ? 0 : 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mpdurl_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) {
|
while (true) {
|
||||||
size_t ret = decoder_read(base->decoder, base->input,
|
size_t ret = decoder_read(stream->decoder, stream->input,
|
||||||
(void *)buf, size);
|
(void *)buf, size);
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (input_stream_eof(base->input) ||
|
if (input_stream_eof(stream->input) ||
|
||||||
(base->decoder &&
|
(stream->decoder &&
|
||||||
decoder_get_command(base->decoder) != DECODE_COMMAND_NONE))
|
decoder_get_command(stream->decoder) != DECODE_COMMAND_NONE))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
my_usleep(10000);
|
my_usleep(10000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t mpdurl_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
|
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 mpdurl_close(URLContext *h)
|
static int mpd_ffmpeg_close(URLContext *h)
|
||||||
{
|
{
|
||||||
h->priv_data = 0;
|
h->priv_data = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static URLProtocol mpdurl_fileops = {
|
static URLProtocol mpd_ffmpeg_fileops = {
|
||||||
.name = "mpd",
|
.name = "mpd",
|
||||||
.url_open = mpdurl_open,
|
.url_open = mpd_ffmpeg_open,
|
||||||
.url_read = mpdurl_read,
|
.url_read = mpd_ffmpeg_read,
|
||||||
.url_seek = mpdurl_seek,
|
.url_seek = mpd_ffmpeg_seek,
|
||||||
.url_close = mpdurl_close,
|
.url_close = mpd_ffmpeg_close,
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool ffmpeg_init(void)
|
static bool ffmpeg_init(void)
|
||||||
{
|
{
|
||||||
av_register_all();
|
av_register_all();
|
||||||
register_protocol(&mpdurl_fileops);
|
register_protocol(&mpd_ffmpeg_fileops);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
ffmpeg_helper(struct input_stream *input, bool (*callback)(BasePtrs *ptrs),
|
ffmpeg_helper(struct input_stream *input,
|
||||||
BasePtrs *ptrs)
|
bool (*callback)(struct ffmpeg_context *ctx),
|
||||||
|
struct ffmpeg_context *ctx)
|
||||||
{
|
{
|
||||||
AVFormatContext *pFormatCtx;
|
AVFormatContext *format_context;
|
||||||
AVCodecContext *aCodecCtx;
|
AVCodecContext *codec_context;
|
||||||
AVCodec *aCodec;
|
AVCodec *codec;
|
||||||
int audioStream;
|
int audio_stream;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
FopsHelper fopshelp = {
|
struct ffmpeg_stream stream = {
|
||||||
.url = "mpd://X", /* only the mpd:// prefix matters */
|
.url = "mpd://X", /* only the mpd:// prefix matters */
|
||||||
};
|
};
|
||||||
bool ret;
|
bool ret;
|
||||||
|
|
||||||
fopshelp.input = input;
|
stream.input = input;
|
||||||
if (ptrs && ptrs->decoder) {
|
if (ctx && ctx->decoder) {
|
||||||
fopshelp.decoder = ptrs->decoder; //are we in decoding loop ?
|
stream.decoder = ctx->decoder; //are we in decoding loop ?
|
||||||
} else {
|
} else {
|
||||||
fopshelp.decoder = NULL;
|
stream.decoder = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//ffmpeg works with ours "fileops" helper
|
//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");
|
ERROR("Open failed!\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (av_find_stream_info(pFormatCtx)<0) {
|
if (av_find_stream_info(format_context)<0) {
|
||||||
ERROR("Couldn't find stream info!\n");
|
ERROR("Couldn't find stream info!\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
audioStream = -1;
|
audio_stream = -1;
|
||||||
for(i=0; i<pFormatCtx->nb_streams; i++) {
|
for(i=0; i<format_context->nb_streams; i++) {
|
||||||
if (pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_AUDIO &&
|
if (format_context->streams[i]->codec->codec_type==CODEC_TYPE_AUDIO &&
|
||||||
audioStream < 0) {
|
audio_stream < 0) {
|
||||||
audioStream=i;
|
audio_stream=i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(audioStream==-1) {
|
if (audio_stream == -1) {
|
||||||
ERROR("No audio stream inside!\n");
|
ERROR("No audio stream inside!\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
aCodecCtx = pFormatCtx->streams[audioStream]->codec;
|
codec_context = format_context->streams[audio_stream]->codec;
|
||||||
aCodec = avcodec_find_decoder(aCodecCtx->codec_id);
|
codec = avcodec_find_decoder(codec_context->codec_id);
|
||||||
|
|
||||||
if (!aCodec) {
|
if (!codec) {
|
||||||
ERROR("Unsupported audio codec!\n");
|
ERROR("Unsupported audio codec!\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (avcodec_open(aCodecCtx, aCodec)<0) {
|
if (avcodec_open(codec_context, codec)<0) {
|
||||||
ERROR("Could not open codec!\n");
|
ERROR("Could not open codec!\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
ptrs->audioStream = audioStream;
|
ctx->audio_stream = audio_stream;
|
||||||
ptrs->pFormatCtx = pFormatCtx;
|
ctx->format_context = format_context;
|
||||||
ptrs->aCodecCtx = aCodecCtx;
|
ctx->codec_context = codec_context;
|
||||||
ptrs->aCodec = aCodec;
|
ctx->codec = codec;
|
||||||
|
|
||||||
ret = (*callback)( ptrs );
|
ret = callback(ctx);
|
||||||
} else
|
} else
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
avcodec_close(aCodecCtx);
|
avcodec_close(codec_context);
|
||||||
av_close_input_file(pFormatCtx);
|
av_close_input_file(format_context);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -243,11 +244,11 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
ffmpeg_decode_internal(BasePtrs *base)
|
ffmpeg_decode_internal(struct ffmpeg_context *ctx)
|
||||||
{
|
{
|
||||||
struct decoder *decoder = base->decoder;
|
struct decoder *decoder = ctx->decoder;
|
||||||
AVCodecContext *aCodecCtx = base->aCodecCtx;
|
AVCodecContext *codec_context = ctx->codec_context;
|
||||||
AVFormatContext *pFormatCtx = base->pFormatCtx;
|
AVFormatContext *format_context = ctx->format_context;
|
||||||
AVPacket packet;
|
AVPacket packet;
|
||||||
struct audio_format audio_format;
|
struct audio_format audio_format;
|
||||||
enum decoder_command cmd;
|
enum decoder_command cmd;
|
||||||
@ -255,31 +256,31 @@ ffmpeg_decode_internal(BasePtrs *base)
|
|||||||
|
|
||||||
total_time = 0;
|
total_time = 0;
|
||||||
|
|
||||||
if (aCodecCtx->channels > 2) {
|
if (codec_context->channels > 2) {
|
||||||
aCodecCtx->channels = 2;
|
codec_context->channels = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
audio_format.bits = (uint8_t)16;
|
audio_format.bits = (uint8_t)16;
|
||||||
audio_format.sample_rate = (unsigned int)aCodecCtx->sample_rate;
|
audio_format.sample_rate = (unsigned int)codec_context->sample_rate;
|
||||||
audio_format.channels = aCodecCtx->channels;
|
audio_format.channels = codec_context->channels;
|
||||||
|
|
||||||
//there is some problem with this on some demux (mp3 at least)
|
//there is some problem with this on some demux (mp3 at least)
|
||||||
if (pFormatCtx->duration != (int)AV_NOPTS_VALUE) {
|
if (format_context->duration != (int)AV_NOPTS_VALUE) {
|
||||||
total_time = pFormatCtx->duration / AV_TIME_BASE;
|
total_time = format_context->duration / AV_TIME_BASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
decoder_initialized(decoder, &audio_format,
|
decoder_initialized(decoder, &audio_format,
|
||||||
base->input->seekable, total_time);
|
ctx->input->seekable, total_time);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (av_read_frame(pFormatCtx, &packet) < 0)
|
if (av_read_frame(format_context, &packet) < 0)
|
||||||
/* end of file */
|
/* end of file */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (packet.stream_index == base->audioStream)
|
if (packet.stream_index == ctx->audio_stream)
|
||||||
cmd = ffmpeg_send_packet(decoder, base->input,
|
cmd = ffmpeg_send_packet(decoder, ctx->input,
|
||||||
&packet, aCodecCtx,
|
&packet, codec_context,
|
||||||
&pFormatCtx->streams[base->audioStream]->time_base);
|
&format_context->streams[ctx->audio_stream]->time_base);
|
||||||
else
|
else
|
||||||
cmd = decoder_get_command(decoder);
|
cmd = decoder_get_command(decoder);
|
||||||
|
|
||||||
@ -288,7 +289,7 @@ ffmpeg_decode_internal(BasePtrs *base)
|
|||||||
if (cmd == DECODE_COMMAND_SEEK) {
|
if (cmd == DECODE_COMMAND_SEEK) {
|
||||||
current = decoder_seek_where(decoder) * AV_TIME_BASE;
|
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);
|
decoder_seek_error(decoder);
|
||||||
else
|
else
|
||||||
decoder_command_finished(decoder);
|
decoder_command_finished(decoder);
|
||||||
@ -301,20 +302,20 @@ ffmpeg_decode_internal(BasePtrs *base)
|
|||||||
static bool
|
static bool
|
||||||
ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
|
ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
|
||||||
{
|
{
|
||||||
BasePtrs base;
|
struct ffmpeg_context ctx;
|
||||||
|
|
||||||
base.input = input;
|
ctx.input = input;
|
||||||
base.decoder = decoder;
|
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) {
|
if (ctx->format_context->duration != (int)AV_NOPTS_VALUE) {
|
||||||
tag->time = base->pFormatCtx->duration / AV_TIME_BASE;
|
tag->time = ctx->format_context->duration / AV_TIME_BASE;
|
||||||
} else {
|
} else {
|
||||||
tag->time = 0;
|
tag->time = 0;
|
||||||
}
|
}
|
||||||
@ -326,7 +327,7 @@ static bool ffmpeg_tag_internal(BasePtrs *base)
|
|||||||
static struct tag *ffmpeg_tag(const char *file)
|
static struct tag *ffmpeg_tag(const char *file)
|
||||||
{
|
{
|
||||||
struct input_stream input;
|
struct input_stream input;
|
||||||
BasePtrs base;
|
struct ffmpeg_context ctx;
|
||||||
bool ret;
|
bool ret;
|
||||||
|
|
||||||
if (!input_stream_open(&input, file)) {
|
if (!input_stream_open(&input, file)) {
|
||||||
@ -334,18 +335,18 @@ static struct tag *ffmpeg_tag(const char *file)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
base.decoder = NULL;
|
ctx.decoder = NULL;
|
||||||
base.tag = tag_new();
|
ctx.tag = tag_new();
|
||||||
|
|
||||||
ret = ffmpeg_helper(&input, ffmpeg_tag_internal, &base);
|
ret = ffmpeg_helper(&input, ffmpeg_tag_internal, &ctx);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
tag_free(base.tag);
|
tag_free(ctx.tag);
|
||||||
base.tag = NULL;
|
ctx.tag = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
input_stream_close(&input);
|
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
|
* only that files
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const char *const ffmpeg_Suffixes[] = {
|
static const char *const ffmpeg_suffixes[] = {
|
||||||
"wma", "asf", "wmv", "mpeg", "mpg", "avi", "vob", "mov", "qt", "swf", "rm", "swf",
|
"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",
|
"mp1", "mp2", "mp3", "mp4", "m4a", "flac", "ogg", "wav", "au", "aiff", "aif", "ac3", "aac", "mpc",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
//not sure if this is correct...
|
//not sure if this is correct...
|
||||||
static const char *const ffmpeg_Mimetypes[] = {
|
static const char *const ffmpeg_mime_types[] = {
|
||||||
"video/x-ms-asf",
|
"video/x-ms-asf",
|
||||||
"audio/x-ms-wma",
|
"audio/x-ms-wma",
|
||||||
"audio/x-ms-wax",
|
"audio/x-ms-wax",
|
||||||
@ -378,13 +379,13 @@ static const char *const ffmpeg_Mimetypes[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct decoder_plugin ffmpegPlugin = {
|
const struct decoder_plugin ffmpeg_plugin = {
|
||||||
.name = "ffmpeg",
|
.name = "ffmpeg",
|
||||||
.init = ffmpeg_init,
|
.init = ffmpeg_init,
|
||||||
.try_decode = ffmpeg_try_decode,
|
.try_decode = ffmpeg_try_decode,
|
||||||
.stream_decode = ffmpeg_decode,
|
.stream_decode = ffmpeg_decode,
|
||||||
.tag_dup = ffmpeg_tag,
|
.tag_dup = ffmpeg_tag,
|
||||||
.stream_types = INPUT_PLUGIN_STREAM_URL | INPUT_PLUGIN_STREAM_FILE,
|
.stream_types = INPUT_PLUGIN_STREAM_URL | INPUT_PLUGIN_STREAM_FILE,
|
||||||
.suffixes = ffmpeg_Suffixes,
|
.suffixes = ffmpeg_suffixes,
|
||||||
.mime_types = ffmpeg_Mimetypes
|
.mime_types = ffmpeg_mime_types
|
||||||
};
|
};
|
||||||
|
@ -31,7 +31,7 @@ extern const struct decoder_plugin aacPlugin;
|
|||||||
extern const struct decoder_plugin mpcPlugin;
|
extern const struct decoder_plugin mpcPlugin;
|
||||||
extern const struct decoder_plugin wavpackPlugin;
|
extern const struct decoder_plugin wavpackPlugin;
|
||||||
extern const struct decoder_plugin modPlugin;
|
extern const struct decoder_plugin modPlugin;
|
||||||
extern const struct decoder_plugin ffmpegPlugin;
|
extern const struct decoder_plugin ffmpeg_plugin;
|
||||||
|
|
||||||
static const struct decoder_plugin *const decoder_plugins[] = {
|
static const struct decoder_plugin *const decoder_plugins[] = {
|
||||||
#ifdef HAVE_MAD
|
#ifdef HAVE_MAD
|
||||||
@ -65,7 +65,7 @@ static const struct decoder_plugin *const decoder_plugins[] = {
|
|||||||
&modPlugin,
|
&modPlugin,
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_FFMPEG
|
#ifdef HAVE_FFMPEG
|
||||||
&ffmpegPlugin,
|
&ffmpeg_plugin,
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user