X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=mp.c;h=b5fa9cacaa6dcf9f3e2ef6f99fd025757f12097c;hb=2bad70d84e763b4d866d7b97dbc1cdc8e030bd45;hp=bade05bcf866103b5bd794af4ae1ae6ce8cb5b72;hpb=e2167286448ce2ed9a01a548e7e9832563035088;p=paraslash.git diff --git a/mp.c b/mp.c index bade05bc..b5fa9cac 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. * @@ -491,10 +512,10 @@ int mp_init(const char *definition, int nbytes, struct mp_context **result, struct mp_context *ctx; struct yy_buffer_state *buffer_state; + *result = NULL; if (!definition || nbytes == 0) { /* dummy mood */ if (errmsg) *errmsg = NULL; - *result = NULL; return 0; } ctx = para_calloc(sizeof(*ctx)); @@ -541,6 +562,8 @@ bool mp_eval_row(const struct osl_row *aft_row, struct mp_context *ctx) { if (!ctx) /* dummy mood */ return true; + if (!ctx->ast) /* empty mood */ + return true; assert(aft_row); ctx->aft_row = aft_row; ctx->have_afsi = false;