X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=mp.c;h=c537e72998d2ae46e0e9dbaa55175eaebf14f07f;hb=d440a71683940a58747de6dc32643db452d9cf54;hp=416b4f92065ef79716e7f966c3102e995071a112;hpb=5950bc81d20b5b6f9ddf1b34df3141cd542d2c6a;p=paraslash.git diff --git a/mp.c b/mp.c index 416b4f92..c537e729 100644 --- a/mp.c +++ b/mp.c @@ -389,6 +389,27 @@ MP_AFHI(frequency) MP_AFHI(channels) /** \endcond */ +/** + * Return the duration of the audio file from the afh info structure. + * + * \param ctx See \ref mp_path(). + * + * The duration is computed by multiplying the number of chunks and the + * duration of one chunk. + * + * \return The approximate number of milliseconds. + */ +int64_t mp_duration(struct mp_context *ctx) +{ + struct timeval tmp; + int ret = get_afhi(ctx); + + if (ret < 0) + return 0; + tv_scale(ctx->afhi.chunks_total, &ctx->afhi.chunk_tv, &tmp); + return tv2ms(&tmp); +} + /** * Define a function which extracts and returns the value of a meta tag. * @@ -510,6 +531,7 @@ int mp_init(const char *definition, int nbytes, struct mp_context **result, mp_yy_delete_buffer(buffer_state, scanner); mp_yylex_destroy(scanner); if (ctx->errmsg) { /* parse error */ + mp_free_ast(ctx->ast); if (errmsg) *errmsg = ctx->errmsg; else