timestamp.h 2.7 KB

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