X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=mp.c;h=df030ead1998935f3553d7beca065bbe535ee1d1;hb=2391dbc88e15dd54207f289bb4fdbaf0e801b1ca;hp=56c16e31d7baf64fbf7c415b015b3de2967b6a38;hpb=91dab140da62ea364af1a82b2b5e67e69205b35f;p=paraslash.git diff --git a/mp.c b/mp.c index 56c16e31..df030ead 100644 --- a/mp.c +++ b/mp.c @@ -90,7 +90,7 @@ unsigned parse_quoted_string(const char *src, const char quote_chars[2], assert(len >= 2); assert(src[0] == quote_chars[0]); - p = dst = para_malloc(len - 1); + p = dst = alloc(len - 1); backslash = false; for (n = 1;; n++) { char 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. * @@ -497,7 +518,7 @@ int mp_init(const char *definition, int nbytes, struct mp_context **result, *errmsg = NULL; return 0; } - ctx = para_calloc(sizeof(*ctx)); + ctx = zalloc(sizeof(*ctx)); ctx->errmsg = NULL; ctx->ast = NULL; @@ -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 @@ -535,12 +557,14 @@ int mp_init(const char *definition, int nbytes, struct mp_context **result, * function returns true (without looking at the audio file metadata) to * indicate that the given audio file should be considered admissible. * - * \sa \ref change_current_mood(), \ref mp_eval_ast(). + * \sa \ref mood_switch(), \ref mp_eval_ast(). */ 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;