Advertisement
Guest User

Untitled

a guest
Jan 16th, 2012
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.41 KB | None | 0 0
  1. Subject: [PATCH 1/2] [WIP] timecode: use flags in the timecode context
  2.  
  3. ---
  4. libavcodec/timecode.c | 22 +++++++++++++---------
  5. libavcodec/timecode.h | 12 +++++++++---
  6. 2 files changed, 22 insertions(+), 12 deletions(-)
  7.  
  8. diff --git a/libavcodec/timecode.c b/libavcodec/timecode.c
  9. index 2e0f4a4..d8316b1 100644
  10. --- a/libavcodec/timecode.c
  11. +++ b/libavcodec/timecode.c
  12. @@ -37,8 +37,9 @@ int avpriv_framenum_to_drop_timecode(int frame_num)
  13. return frame_num + 18 * d + 2 * ((m - 2) / 1798);
  14. }
  15.  
  16. -uint32_t avpriv_framenum_to_smpte_timecode(unsigned frame, int fps, int drop)
  17. +uint32_t avpriv_framenum_to_smpte_timecode(unsigned frame, int fps, int flags)
  18. {
  19. + int drop = (flags && TIMECODE_DROP_FRAME);
  20. return (0 << 31) | // color frame flag
  21. (drop << 30) | // drop frame flag
  22. ( ((frame % fps) / 10) << 28) | // tens of frames
  23. @@ -55,9 +56,11 @@ uint32_t avpriv_framenum_to_smpte_timecode(unsigned frame, int fps, int drop)
  24. ( (frame / (fps * 3600) % 24)) % 10; // units of hours
  25. }
  26.  
  27. -int avpriv_check_timecode_rate(void *avcl, AVRational rate, int drop)
  28. +int avpriv_check_timecode_rate(void *avcl, const struct ff_timecode *tc)
  29. {
  30. int fps;
  31. + AVRational rate = tc->rate;
  32. + int drop = tc->flags && TIMECODE_DROP_FRAME;
  33.  
  34. if (!rate.num || !rate.den) {
  35. av_log(avcl, AV_LOG_ERROR, "Timecode frame rate must be specified\n");
  36. @@ -85,7 +88,7 @@ char *avpriv_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigne
  37. int fps = (tc->rate.num + tc->rate.den/2) / tc->rate.den;
  38. int hh, mm, ss, ff, neg = 0;
  39.  
  40. - if (tc->drop)
  41. + if (tc->flags && TIMECODE_DROP_FRAME)
  42. frame_num = avpriv_framenum_to_drop_timecode(frame_num);
  43. if (frame_num < 0) {
  44. frame_num = -frame_num;
  45. @@ -97,7 +100,7 @@ char *avpriv_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigne
  46. hh = frame_num / (fps*3600);
  47. snprintf(buf, 16, "%s%02d:%02d:%02d%c%02d",
  48. neg ? "-" : "",
  49. - hh, mm, ss, tc->drop ? ';' : ':', ff);
  50. + hh, mm, ss, (tc->flags && TIMECODE_DROP_FRAME) ? ';' : ':', ff);
  51. return buf;
  52. }
  53.  
  54. @@ -112,16 +115,17 @@ int avpriv_init_smpte_timecode(void *avcl, struct ff_timecode *tc)
  55. return -1;
  56. }
  57.  
  58. - tc->drop = c != ':'; // drop if ';', '.', ...
  59. + if(c != ':') // drop if ';', '.', ...
  60. + tc->flags &= TIMECODE_DROP_FRAME;
  61.  
  62. - ret = avpriv_check_timecode_rate(avcl, tc->rate, tc->drop);
  63. + ret = avpriv_check_timecode_rate(avcl, tc);
  64. if (ret < 0)
  65. return ret;
  66.  
  67. fps = (tc->rate.num + tc->rate.den/2) / tc->rate.den;
  68. tc->start = (hh*3600 + mm*60 + ss) * fps + ff;
  69.  
  70. - if (tc->drop) { /* adjust frame number */
  71. + if (tc->flags && TIMECODE_DROP_FRAME) { /* adjust frame number */
  72. int tmins = 60*hh + mm;
  73. tc->start -= 2 * (tmins - tmins/10);
  74. }
  75. @@ -134,9 +138,9 @@ int ff_framenum_to_drop_timecode(int frame_num)
  76. return avpriv_framenum_to_drop_timecode(frame_num);
  77. }
  78.  
  79. -uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop)
  80. +uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int flags)
  81. {
  82. - return avpriv_framenum_to_smpte_timecode(frame, fps, drop);
  83. + return avpriv_framenum_to_smpte_timecode(frame, fps, flags);
  84. }
  85.  
  86. int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc)
  87. diff --git a/libavcodec/timecode.h b/libavcodec/timecode.h
  88. index bcfb0fa..63a4ae0 100644
  89. --- a/libavcodec/timecode.h
  90. +++ b/libavcodec/timecode.h
  91. @@ -31,6 +31,12 @@
  92. #include "avcodec.h"
  93. #include "libavutil/rational.h"
  94.  
  95. +/* timecode flags */
  96. +#define TIMECODE_DROP_FRAME 0x0001 ///< Drop Frame
  97. +#define TIMECODE_MAX_24H 0x0002 ///< Timecode wraps after 24h
  98. +#define TIMECODE_NEG_TIMES 0x0004 ///< Negative timecode allowed
  99. +#define TIMECODE_COUNTER 0x0008 ///< Time value corresponds to a tape counter value
  100. +
  101. #define TIMECODE_OPT(ctx, flags) \
  102. "timecode", "set timecode value following hh:mm:ss[:;.]ff format, " \
  103. "use ';' or '.' before frame number for drop frame", \
  104. @@ -40,7 +46,7 @@
  105. struct ff_timecode {
  106. char *str; ///< string following the hh:mm:ss[:;.]ff format
  107. int start; ///< timecode frame start
  108. - int drop; ///< drop flag (1 if drop, else 0)
  109. + int flags; ///< TIMECODE_* flags
  110. AVRational rate; ///< Frame rate in rational form
  111. };
  112.  
  113. @@ -79,7 +85,7 @@ char *avpriv_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigne
  114. *
  115. * @return 0 on success, negative value on failure
  116. */
  117. -int avpriv_check_timecode_rate(void *avcl, AVRational rate, int drop);
  118. +int avpriv_check_timecode_rate(void *avcl, const struct ff_timecode *tc);
  119.  
  120. /**
  121. * Parse SMTPE 12M time representation (hh:mm:ss[:;.]ff). str and rate fields
  122. @@ -95,7 +101,7 @@ int avpriv_init_smpte_timecode(void *avcl, struct ff_timecode *tc);
  123.  
  124. #if FF_API_OLD_TIMECODE
  125. attribute_deprecated int ff_framenum_to_drop_timecode(int frame_num);
  126. -attribute_deprecated uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop);
  127. +attribute_deprecated uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int flags);
  128. attribute_deprecated int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc);
  129. #endif
  130.  
  131. --
  132. 1.7.8.3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement