decoder/ffmpeg: optimized the stream_tag() method

Don't use the function ffmpeg_helper(), don't initialize the codec.
This commit is contained in:
Max Kellermann 2010-01-18 10:57:57 +01:00
parent acd3f8cd91
commit 5477c31160

View File

@ -51,7 +51,6 @@ struct ffmpeg_context {
AVCodecContext *codec_context; AVCodecContext *codec_context;
struct decoder *decoder; struct decoder *decoder;
struct input_stream *input; struct input_stream *input;
struct tag *tag;
}; };
struct ffmpeg_stream { struct ffmpeg_stream {
@ -405,14 +404,33 @@ ffmpeg_copy_metadata(struct tag *tag, AVMetadata *m,
} }
#endif #endif
static bool ffmpeg_tag_internal(struct ffmpeg_context *ctx) //no tag reading in ffmpeg, check if playable
static struct tag *
ffmpeg_stream_tag(struct input_stream *is)
{ {
struct tag *tag = (struct tag *) ctx->tag; struct ffmpeg_stream stream = {
AVFormatContext *f = ctx->format_context; .url = "mpd://X", /* only the mpd:// prefix matters */
.decoder = NULL,
.input = is,
};
tag->time = 0; if (is->uri != NULL)
if (f->duration != (int64_t)AV_NOPTS_VALUE) append_uri_suffix(&stream, is->uri);
tag->time = f->duration / AV_TIME_BASE;
AVFormatContext *f;
if (av_open_input_file(&f, stream.url, NULL, 0, NULL) != 0)
return NULL;
if (av_find_stream_info(f) < 0) {
av_close_input_file(f);
return NULL;
}
struct tag *tag = tag_new();
tag->time = f->duration != (int64_t)AV_NOPTS_VALUE
? f->duration / AV_TIME_BASE
: 0;
#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(31<<8)+0) #if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(31<<8)+0)
av_metadata_conv(f, NULL, f->iformat->metadata_conv); av_metadata_conv(f, NULL, f->iformat->metadata_conv);
@ -449,26 +467,10 @@ static bool ffmpeg_tag_internal(struct ffmpeg_context *ctx)
} }
#endif #endif
return true;
}
//no tag reading in ffmpeg, check if playable av_close_input_file(f);
static struct tag *
ffmpeg_stream_tag(struct input_stream *is)
{
struct ffmpeg_context ctx;
bool ret;
ctx.decoder = NULL; return tag;
ctx.tag = tag_new();
ret = ffmpeg_helper(is, ffmpeg_tag_internal, &ctx);
if (!ret) {
tag_free(ctx.tag);
ctx.tag = NULL;
}
return ctx.tag;
} }
/** /**