>From 60125296989ef38b91bb7dffe78e50cddbed8d8e Mon Sep 17 00:00:00 2001
From: Stefano Sabatini <stefasab@gmail.com>
Date: Tue, 17 Jan 2012 17:12:42 +0100
Subject: [PATCH] lavu: add tsutils.h header with convenience timestamp
 utilities

---
 libavutil/Makefile  |    1 +
 libavutil/tsutils.h |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 0 deletions(-)
 create mode 100644 libavutil/tsutils.h

diff --git a/libavutil/Makefile b/libavutil/Makefile
index b6165a1..8fffbb5 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -36,6 +36,7 @@ HEADERS = adler32.h                                                     \
           rational.h                                                    \
           samplefmt.h                                                   \
           sha.h                                                         \
+          tsutils.h                                                     \
 
 BUILT_HEADERS = avconfig.h
 
diff --git a/libavutil/tsutils.h b/libavutil/tsutils.h
new file mode 100644
index 0000000..24d01b7
--- /dev/null
+++ b/libavutil/tsutils.h
@@ -0,0 +1,47 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * timestamp utils, mostly useful for debugging/logging purposes
+ */
+
+#ifndef AVUTIL_TSUTILS_H
+#define AVUTIL_TSUTILS_H
+
+#include "common.h"
+
+static inline char *av_get_ts_string(char *buf, size_t buf_size, int64_t ts)
+{
+    if (ts == AV_NOPTS_VALUE) snprintf(buf, buf_size, "NOPTS");
+    else                      snprintf(buf, buf_size, "%"PRId64"", ts);
+    return buf;
+}
+
+#define av_ts2str(ts) av_get_ts_string((char[42]){ 0 }, 42, ts)
+
+static inline char* av_get_time_string(char *buf, size_t buf_size, int64_t ts, AVRational *tb)
+{
+    if (ts == AV_NOPTS_VALUE) snprintf(buf, buf_size, "NOPTS");
+    else                      snprintf(buf, buf_size, "%f", av_q2d(*tb) * ts);
+    return buf;
+}
+
+#define av_time2str(ts, tb) av_get_time_string((char[42]){ 0 }, 42, ts, tb)
+
+#endif /* AVUTIL_TSUTILS_H */
-- 
1.7.5.4

