annotate ffmpeg/libavutil/timestamp.h @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * This file is part of FFmpeg.
yading@11 3 *
yading@11 4 * FFmpeg is free software; you can redistribute it and/or
yading@11 5 * modify it under the terms of the GNU Lesser General Public
yading@11 6 * License as published by the Free Software Foundation; either
yading@11 7 * version 2.1 of the License, or (at your option) any later version.
yading@11 8 *
yading@11 9 * FFmpeg is distributed in the hope that it will be useful,
yading@11 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 12 * Lesser General Public License for more details.
yading@11 13 *
yading@11 14 * You should have received a copy of the GNU Lesser General Public
yading@11 15 * License along with FFmpeg; if not, write to the Free Software
yading@11 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 17 */
yading@11 18
yading@11 19 /**
yading@11 20 * @file
yading@11 21 * timestamp utils, mostly useful for debugging/logging purposes
yading@11 22 */
yading@11 23
yading@11 24 #ifndef AVUTIL_TIMESTAMP_H
yading@11 25 #define AVUTIL_TIMESTAMP_H
yading@11 26
yading@11 27 #include "common.h"
yading@11 28
yading@11 29 #define AV_TS_MAX_STRING_SIZE 32
yading@11 30
yading@11 31 /**
yading@11 32 * Fill the provided buffer with a string containing a timestamp
yading@11 33 * representation.
yading@11 34 *
yading@11 35 * @param buf a buffer with size in bytes of at least AV_TS_MAX_STRING_SIZE
yading@11 36 * @param ts the timestamp to represent
yading@11 37 * @return the buffer in input
yading@11 38 */
yading@11 39 static inline char *av_ts_make_string(char *buf, int64_t ts)
yading@11 40 {
yading@11 41 if (ts == AV_NOPTS_VALUE) snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS");
yading@11 42 else snprintf(buf, AV_TS_MAX_STRING_SIZE, "%"PRId64"", ts);
yading@11 43 return buf;
yading@11 44 }
yading@11 45
yading@11 46 /**
yading@11 47 * Convenience macro, the return value should be used only directly in
yading@11 48 * function arguments but never stand-alone.
yading@11 49 */
yading@11 50 #define av_ts2str(ts) av_ts_make_string((char[AV_TS_MAX_STRING_SIZE]){0}, ts)
yading@11 51
yading@11 52 /**
yading@11 53 * Fill the provided buffer with a string containing a timestamp time
yading@11 54 * representation.
yading@11 55 *
yading@11 56 * @param buf a buffer with size in bytes of at least AV_TS_MAX_STRING_SIZE
yading@11 57 * @param ts the timestamp to represent
yading@11 58 * @param tb the timebase of the timestamp
yading@11 59 * @return the buffer in input
yading@11 60 */
yading@11 61 static inline char *av_ts_make_time_string(char *buf, int64_t ts, AVRational *tb)
yading@11 62 {
yading@11 63 if (ts == AV_NOPTS_VALUE) snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS");
yading@11 64 else snprintf(buf, AV_TS_MAX_STRING_SIZE, "%.6g", av_q2d(*tb) * ts);
yading@11 65 return buf;
yading@11 66 }
yading@11 67
yading@11 68 /**
yading@11 69 * Convenience macro, the return value should be used only directly in
yading@11 70 * function arguments but never stand-alone.
yading@11 71 */
yading@11 72 #define av_ts2timestr(ts, tb) av_ts_make_time_string((char[AV_TS_MAX_STRING_SIZE]){0}, ts, tb)
yading@11 73
yading@11 74 #endif /* AVUTIL_TIMESTAMP_H */