AJA NTV2 SDK  17.5.0.1492
NTV2 SDK 17.5.0.1492
timecode.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 //---------------------------------------------------------------------------------------------------------------------
9 // Includes
10 //---------------------------------------------------------------------------------------------------------------------
11 #include "ajabase/common/common.h"
13 
14 #include <iomanip>
15 #include <sstream>
16 #include <string>
17 #include <vector>
18 using namespace std;
19 
20 #if defined(AJA_MAC) || defined(AJA_LINUX) || defined(AJA_BAREMETAL)
21 #include <stdlib.h>
22 #include <string.h>
23 #include <wctype.h>
24 #endif
25 
26 //---------------------------------------------------------------------------------------------------------------------
27 // Defines and structures
28 //---------------------------------------------------------------------------------------------------------------------
29 
30 //---------------------------------------------------------------------------------------------------------------------
31 // Utility Functions
32 //---------------------------------------------------------------------------------------------------------------------
33 
34 //---------------------------------------------------------------------------------------------------------------------
35 // Public Functions and Class Methods
36 //---------------------------------------------------------------------------------------------------------------------
37 
38 //---------------------------------------------------------------------------------------------------------------------
39 // Name: AJATimeCode
40 // Notes: http://www.andrewduncan.ws/Timecodes/Timecodes.html
41 // http://en.wikipedia.org/wiki/SMPTE_time_code
42 // Drop frame is lifted from http://www.davidheidelberger.com/blog/?p=29
43 //---------------------------------------------------------------------------------------------------------------------
45  m_frame(0),
46  m_stdTcForHfr(true)
47 {
48 }
49 
50 AJATimeCode::AJATimeCode(uint32_t frame, bool bStdTcForHfr) :
51  m_stdTcForHfr(bStdTcForHfr)
52 {
53  Set(frame);
54 }
55 
56 AJATimeCode::AJATimeCode(const std::string &str, const AJATimeBase& timeBase, bool bDropFrame, bool bStdTcForHfr)
57  : m_stdTcForHfr(bStdTcForHfr)
58 {
59  Set(str.c_str(), timeBase, bDropFrame);
60 }
61 
62 AJATimeCode::AJATimeCode(const std::string &str, const AJATimeBase& timeBase)
63  : m_stdTcForHfr(true)
64 {
65  Set(str.c_str(), timeBase);
66 }
67 
69 {
70  m_frame = other.m_frame;
71  m_stdTcForHfr = other.m_stdTcForHfr;
72 }
73 
74 //---------------------------------------------------------------------------------------------------------------------
75 // Name: ~AJATimeCode
76 //---------------------------------------------------------------------------------------------------------------------
78 {
79 } //end ~AJATimeCode
80 
81 bool AJATimeCode::QueryIsDropFrame(const string &str)
82 {
83  bool bHasSemicolon = str.find(";", 0) != string::npos;
84  return bHasSemicolon;
85 }
86 
88 {
89  return (int)::strlen("00:00:00:00") + 1;
90 }
91 
92 uint32_t AJATimeCode::QueryFrame(void) const
93 {
94  return m_frame;
95 }
96 
97 inline uint32_t AJATimeCodeRound(double f)
98 {
99  return (uint32_t)(f + .5);
100 }
101 
102 inline int64_t AJATimeCodeAbs(int64_t x)
103 {
104  return (((x)>=0)?(x):-(x));
105 }
106 
107 uint32_t AJATimeCode::CalcFrame(uint32_t h, uint32_t m, uint32_t s, uint32_t f, const AJATimeBase& timeBase, bool bDropFrame, bool bStdTcForHfr, uint32_t addFrame)
108 {
109  int64_t frameRate, frameRate2, frameDuration;
110  timeBase.GetFrameRate(frameRate, frameDuration);
111  AJA_FrameRate ajaFrameRate = timeBase.GetAJAFrameRate();
112 
113  frameRate2 = frameRate;
114  if (ajaFrameRate >= AJA_FrameRate_10000 && bStdTcForHfr == true)
115  {
116  frameRate2 /=4;
117  }
118  else if (ajaFrameRate >= AJA_FrameRate_4795 && bStdTcForHfr == true)
119  {
120  frameRate2 /=2;
121  }
122 
123  uint32_t frame;
124  if (frameRate == 0 || frameDuration == 0)
125  {
126  frame = 0;
127  }
128  else if (bDropFrame)
129  {
130  // this is just good for 29.97, 59.94, 23.976
131  double dFrameRate = double(frameRate2) / double(frameDuration);
132  uint32_t dropFrames = AJATimeCodeRound(dFrameRate*.066666); //Number of drop frames is 6% of framerate rounded to nearest integer
133  uint32_t tb = AJATimeCodeRound(dFrameRate); //We don't need the exact framerate anymore, we just need it rounded to nearest integer
134 
135  uint32_t hourFrames = tb*60*60; //Number of frames per hour (non-drop)
136  uint32_t minuteFrames = tb*60; //Number of frames per minute (non-drop)
137  uint32_t totalMinutes = (60*h) + m; //Total number of minutes
138 
139  // if TC does not exist then we need to round up to the next valid frame
140  if ( (s == 0) && ((m % 10) > 0) && ((f & ~1) == 0))
141  f = 2;
142 
143  frame = ((hourFrames * h) + (minuteFrames * m) + (tb * s) + f) - (dropFrames * (totalMinutes - (totalMinutes / 10)));
144  }
145  else
146  {
147  double dFrameRate = double(frameRate2) / double(frameDuration);
148  uint32_t tb = AJATimeCodeRound(dFrameRate); //We don't need the exact framerate anymore, we just need it rounded to nearest integer
149 
150  uint32_t hourFrames = tb*60*60; //Number of frames per hour (non-drop)
151  uint32_t minuteFrames = tb*60; //Number of frames per minute (non-drop)
152  //uint32_t totalMinutes = (60*h) + m; //Total number of minutes
153  frame = ((hourFrames * h) + (minuteFrames * m) + (tb * s) + f);
154  }
155 
156  if (ajaFrameRate >= AJA_FrameRate_10000 && bStdTcForHfr == true)
157  {
158  frame *=4;
159  }
160  else if (ajaFrameRate >= AJA_FrameRate_4795 && bStdTcForHfr == true)
161  {
162  frame *=2;
163  }
164 
165  frame += bStdTcForHfr ? addFrame : 0;
166  return frame;
167 
168 } //end CalcFrame
169 
170 uint32_t AJATimeCode::CalcHmsf(uint32_t &h, uint32_t &m, uint32_t &s, uint32_t &f, uint32_t frame, const AJATimeBase& timeBase, bool bDropFrame, bool bStdTcForHfr=true)
171 {
172  // This code was pulled from the NTV2RP188 class and appears to work correctly.
173  int64_t frameRate,frameDuration;
174  timeBase.GetFrameRate(frameRate,frameDuration);
175  AJA_FrameRate ajaFrameRate = timeBase.GetAJAFrameRate();
176  uint32_t remainder = 0;
177 
178  if (ajaFrameRate >= AJA_FrameRate_10000 && bStdTcForHfr == true)
179  {
180  remainder = frame % 4;
181  frame /= 4;
182  frameRate /= 4;
183  }
184  else if (ajaFrameRate >= AJA_FrameRate_4795 && bStdTcForHfr == true)
185  {
186  remainder = frame % 2;
187  frame /= 2;
188  frameRate /= 2;
189  }
190 
191  if (frameRate == 0 || frameDuration == 0 || frameRate < frameDuration)
192  {
193  h = m = s = f = 0;
194  }
195  else
196  {
197  // this is just good for 29.97, 59.94, 23.976
198  double dFrameRate = double(frameRate) / double(frameDuration);
199 
200  // non-dropframe
201  uint32_t framesPerSec = AJATimeCodeRound(dFrameRate);
202  uint32_t framesPerMin = framesPerSec * 60; // 60 seconds/minute
203  uint32_t framesPerHr = framesPerMin * 60; // 60 minutes/hr.
204  uint32_t framesPerDay = framesPerHr * 24; // 24 hours/day
205 
206  if (! bDropFrame)
207  {
208  // make sure we don't have more than 24 hours worth of frames
209  frame = frame % framesPerDay;
210 
211  // how many hours?
212  h = uint32_t(frame / framesPerHr);
213  frame = frame % framesPerHr;
214 
215  // how many minutes?
216  m = uint32_t(frame / framesPerMin);
217  frame = frame % framesPerMin;
218 
219  // how many seconds?
220  s = uint32_t(frame / framesPerSec);
221 
222  // what's left is the frame count
223  f = uint32_t(frame % framesPerSec);
224  }
225  else
226  {
227  // dropframe
228  uint32_t droppedFrames = AJATimeCodeRound(dFrameRate * .066666); // number of frames dropped in a "drop second"
229  uint32_t dropFramesPerSec = framesPerSec - droppedFrames;
230  uint32_t dropframesPerMin = (59 * framesPerSec) + dropFramesPerSec; // every minute we get 1 drop and 59 regular seconds
231  uint32_t dropframesPerTenMin = (9 * dropframesPerMin) + framesPerMin; // every ten minutes we get 1 regular and 9 drop minutes
232  uint32_t dropframesPerHr = dropframesPerTenMin * 6; // 60 minutes/hr.
233  uint32_t dropframesPerDay = dropframesPerHr * 24; // 24 hours/day
234 
235  // make sure we don't have more than 24 hours worth of frames
236  frame = frame % dropframesPerDay;
237 
238  // how many hours?
239  h = uint32_t(frame / dropframesPerHr);
240  frame = frame % dropframesPerHr;
241 
242  // how many tens of minutes?
243  m = uint32_t(10 * (frame / dropframesPerTenMin));
244  frame = frame % dropframesPerTenMin;
245 
246  // how many units of minutes?
247  if (frame >= framesPerMin)
248  {
249  m += 1; // got at least one minute (the first one is a non-drop minute)
250  frame = frame - framesPerMin;
251 
252  // any remaining minutes are drop-minutes
253  m += uint32_t(frame / dropframesPerMin);
254  frame = frame % dropframesPerMin;
255  }
256 
257  // how many seconds? depends on whether this was a regular or a drop minute...
258  s = 0;
259  if (m % 10 == 0)
260  {
261  // regular minute: all seconds are full length
262  s = uint32_t(frame / framesPerSec);
263  frame = frame % framesPerSec;
264  }
265  else
266  {
267  // drop minute: the first second is a drop second
268  if (frame >= dropFramesPerSec)
269  {
270  s += 1; // got at least one (the first one is a drop second)
271  frame = frame - dropFramesPerSec;
272 
273  // any remaining seconds are full-length
274  s += uint32_t(frame / framesPerSec);
275  frame = frame % framesPerSec;
276  }
277  }
278 
279  // what's left is the frame count
280  f = uint32_t(frame);
281 
282  // if we happened to land on a drop-second, add 2 frames (the 28 frames are numbered 2 - 29, not 0 - 27)
283  if ( (s == 0) && (m % 10 != 0))
284  f += droppedFrames;
285  }
286  }
287  return remainder;
288 
289 } //end CalcHmsf
290 
291 
292 void AJATimeCode::QueryHmsf(uint32_t &h, uint32_t &m, uint32_t &s, uint32_t &f, const AJATimeBase& timeBase, bool bDropFrame) const
293 {
294  // WARNING: Possible loss of frame accuracy for HFR using std TC presentation, should use CalcHmsf directly instead
295  uint32_t remainder = CalcHmsf(h, m, s, f, m_frame, timeBase, bDropFrame, m_stdTcForHfr);
296  AJA_UNUSED(remainder);
297 }
298 
299 void AJATimeCode::QueryString(std::string &str, const AJATimeBase& timeBase, bool bDropFrame, bool bStdTcForHfr, AJATimecodeNotation notation)
300 {
301  uint32_t h = 0,m = 0,s = 0,f = 0;
302  uint32_t r = CalcHmsf(h,m,s,f,m_frame,timeBase,bDropFrame,bStdTcForHfr);
303  AJA_FrameRate frameRate = timeBase.GetAJAFrameRate();
304  char delim = bDropFrame ? ';' : ':';
305  std::ostringstream oss;
306 
307  if (notation == AJA_TIMECODE_STANDARD) // AJA standard notation for delimiters
308  {
309  if (bStdTcForHfr) // using standardize f values, i.e. divided f values for fps > 30
310  {
311  if (frameRate <= AJA_FrameRate_3000)
312  {
313  oss << setfill('0') << setw(2) << h << delim
314  << setfill('0') << setw(2) << m << delim
315  << setfill('0') << setw(2) << s << delim
316  << setfill('0') << setw(2) << f;
317  }
318  else if (frameRate < AJA_FrameRate_10000)
319  {
320  oss << setfill('0') << setw(2) << h << delim
321  << setfill('0') << setw(2) << m << delim
322  << setfill('0') << setw(2) << s << (r == 0 ? delim : '.')
323  << setfill('0') << setw(2) << f;
324  }
325  else
326  {
327  oss << setfill('0') << setw(2) << h << delim
328  << setfill('0') << setw(2) << m << delim
329  << setfill('0') << setw(2) << s << (r <= 1 ? delim : '.')
330  << setfill('0') << setw(2) << f;
331  }
332  }
333  else // using full frame values for f
334  {
335  if (frameRate < AJA_FrameRate_10000) // e.g. 01:02:03#04
336  {
337  oss << setfill('0') << setw(2) << h << delim
338  << setfill('0') << setw(2) << m << delim
339  << setfill('0') << setw(2) << s << '#'
340  << setfill('0') << setw(2) << f;
341  }
342  else // e.g. 01:02:03#004
343  {
344  oss << setfill('0') << setw(2) << h << delim
345  << setfill('0') << setw(2) << m << delim
346  << setfill('0') << setw(2) << s << '#'
347  << setfill('0') << setw(3) << f;
348  }
349  }
350  }
351  else // AJA_TIMECODE_LEGACY legacy notation for delimiters
352  {
353  if (frameRate < AJA_FrameRate_10000) // e.g. 01:02:03:04
354  {
355  oss << setfill('0') << setw(2) << h << ':'
356  << setfill('0') << setw(2) << m << ':'
357  << setfill('0') << setw(2) << s << delim
358  << setfill('0') << setw(2) << f;
359  }
360  else // e.g. 120 fps
361  {
362  if (bStdTcForHfr) // using standardize f values, f values divided by 4 require only 2 digits
363  {
364  oss << setfill('0') << setw(2) << h << ':'
365  << setfill('0') << setw(2) << m << ':'
366  << setfill('0') << setw(2) << s << delim
367  << setfill('0') << setw(2) << f;
368  }
369  else // using standardize f values, show full frame values at 3 digits
370  {
371  oss << setfill('0') << setw(2) << h << ':'
372  << setfill('0') << setw(2) << m << ':'
373  << setfill('0') << setw(2) << s << delim
374  << setfill('0') << setw(3) << f;
375  }
376  }
377  }
378  str.assign(oss.str());
379 }
380 
381 void AJATimeCode::QueryString(std::string &str, const AJATimeBase& timeBase, bool bDropFrame, AJATimecodeNotation notation)
382 {
383  QueryString(str, timeBase, bDropFrame, m_stdTcForHfr, notation);
384 }
385 
386 #if !defined(NTV2_DEPRECATE_17_5)
387  void AJATimeCode::QueryString(char *pString, const AJATimeBase& timeBase, bool bDropFrame, AJATimecodeNotation notation)
388  {
389  string s;
390  QueryString(s, timeBase, bDropFrame, notation);
391  strncpy(pString, s.c_str(), s.length());
392  pString[11] = '\0';
393  }
394 #endif // NTV2_DEPRECATE_17_5
395 
397 {
398  return 4;
399 }
400 
401 void AJATimeCode::QuerySMPTEString(char *pBufr,const AJATimeBase& timeBase,bool bDrop)
402 {
403  uint32_t h=0, m=0, s=0, f=0;
404  uint32_t r = CalcHmsf(h,m,s,f,m_frame,timeBase,bDrop,m_stdTcForHfr);
405  AJA_UNUSED(r);
406 
407  pBufr[0] = ((f/10) << 4) + (f % 10);
408  pBufr[1] = ((s/10) << 4) + (s % 10);
409  pBufr[2] = ((m/10) << 4) + (m % 10);
410  pBufr[3] = ((h/10) << 4) + (h % 10);
411  if (bDrop)
412  pBufr[0] = pBufr[0] | 0x40;
413 }
414 
415 //---------------------------------------------------------------------------------------------------------------------
416 // Name: Set
417 // Notes: If we need to either clamp or roll over the frame number, the uint32_t version of Set() is a good place
418 // to do it.
419 //---------------------------------------------------------------------------------------------------------------------
420 void AJATimeCode::Set(uint32_t frame)
421 {
422  m_frame = frame;
423 }
424 
425 void AJATimeCode::SetHmsf(uint32_t h, uint32_t m, uint32_t s, uint32_t f, const AJATimeBase& timeBase, bool bDropFrame, bool bStdTcForHfr, uint32_t addFrame)
426 {
427  uint32_t frame = CalcFrame(h, m, s, f, timeBase, bDropFrame, bStdTcForHfr, addFrame);
428  Set(frame);
429 }
430 
431 void AJATimeCode::SetHmsf(uint32_t h, uint32_t m, uint32_t s, uint32_t f, const AJATimeBase& timeBase, bool bDropFrame)
432 {
433  // WARNING: may lose a frame in calculation accuracy if HFR and m_stdTcForHfr=true
434  uint32_t frame = CalcFrame(h, m, s, f, timeBase, bDropFrame, m_stdTcForHfr, 0);
435  Set(frame);
436 
437 }
438 
439 void AJATimeCode::Set(const std::string &str, const AJATimeBase& timeBase, bool bDropFrame)
440 {
441  const int valCount = 4;
442  uint32_t val[valCount];
443  ::memset(val,0,sizeof(val));
444 
445  // work from bottom up so that partial time code
446  // (ie. something like 10:02 rather than 00:00:10:02)
447  // is handled
448  size_t len = str.length();
449  int valOffset = 0;
450  int valMult = 1;
451  int addFrame = 0;
452  int stdTcForHfr = m_stdTcForHfr;
453  AJA_FrameRate ajaFrameRate = timeBase.GetAJAFrameRate();
454 
455  for (size_t i = 0; i < len; i++)
456  {
457  char theChar = str[len - i - 1];
458  if (::isdigit(theChar))
459  {
460  val[valOffset] = val[valOffset] + ((theChar - '0') * valMult);
461  valMult *= 10;
462  }
463  else
464  {
465  if (valOffset == 0) // if frame level value
466  {
467  if (theChar == '#') // temp set to non-std
468  stdTcForHfr = false;
469 
470  // if using std timecode, add frame(s) if '.'
471  if (ajaFrameRate >= AJA_FrameRate_10000 && stdTcForHfr && theChar == '.')
472  addFrame = 2; // WARNING: possible loss of frame accuracy due to limitaion of TC presentation
473  else if (ajaFrameRate >= AJA_FrameRate_4795 && stdTcForHfr && theChar == '.')
474  addFrame = 1;
475  }
476 
477  valOffset++;
478  valMult = 1;
479  }
480 
481  if (valOffset >= 4)
482  break;
483  }
484 
485  uint32_t frame = CalcFrame(val[3], val[2], val[1], val[0], timeBase, bDropFrame, stdTcForHfr, addFrame);
486  Set(frame);
487 }
488 
489 void AJATimeCode::Set(const std::string &str, const AJATimeBase& timeBase)
490 {
491  bool bDropFrame = QueryIsDropFrame(str);
492  Set(str, timeBase, bDropFrame);
493 }
494 
495 void AJATimeCode::SetWithCleanup(const std::string &str, const AJATimeBase& timeBase, bool bDrop)
496 {
497  if (str.empty())
498  return;
499 
500  int results[4] = {0, 0, 0, 0}; // Temporary array to store the results
501  char delim[3] = {0, 0, 0}; // Holds TC delimiter chars
502  int index = 3; // Start filling from the last slot in the results array
503  uint32_t addFrame = 0;
504 
505  // Traverse the string from the end
506  for (size_t i = str.length() - 1; i >= 0 && index >= 0; )
507  {
508  // Skip non-digit characters
509  while (i >= 0 && !aja::is_decimal_digit(str[i]))
510  i--;
511 
512  // Find the start of the number
513  if (i >= 0 && aja::is_decimal_digit(str[i]))
514  {
515  size_t start = i;
516  while (start > 0 && aja::is_decimal_digit(str[start - 1]))
517  start--;
518 
519  if (start > 0 && index > 0)
520  delim[index-1] = str[start - 1];
521 
522  // Convert the substring to an integer
523  std::string numberStr = str.substr(start, i - start + 1);
524  results[index--] = std::stoi(numberStr);
525 
526  // update i to continue, start-1 was already identified as a non-digit
527  i = start - 2;
528  }
529  }
530 
531  uint32_t fps = AJATimeCodeRound(timeBase.GetFramesPerSecondDouble());
532  bool stdTcForHfr = m_stdTcForHfr;
533  char lastDelim = delim[2];
534 
535  if (lastDelim == '#')
536  stdTcForHfr = false;
537 
538  // if using std timecode for hfr, add frame(s) if indicated by '.'
539  if (fps >= 100 && stdTcForHfr == true && lastDelim == '.')
540  addFrame = 2;
541  else if (fps >= 48 && stdTcForHfr == true && lastDelim == '.')
542  addFrame = 1;
543 
544  uint32_t frame = CalcFrame(results[0], results[1], results[2], results[3], timeBase, bDrop, stdTcForHfr, addFrame);
545  Set(frame);
546 
547 }
548 
549 void AJATimeCode::SetSMPTEString(const char *pBufr, const AJATimeBase& timeBase)
550 {
551  bool bDrop = false;
552  if (pBufr[0] & 0x40)
553  bDrop = true;
554 
555  uint32_t f = (((pBufr[0] & 0x30) >> 4) * 10) + (pBufr[0] & 0x0f);
556  uint32_t s = (((pBufr[1] & 0x70) >> 4) * 10) + (pBufr[1] & 0x0f);
557  uint32_t m = (((pBufr[2] & 0x70) >> 4) * 10) + (pBufr[2] & 0x0f);
558  uint32_t h = (((pBufr[3] & 0x30) >> 4) * 10) + (pBufr[3] & 0x0f);
559 
560  SetHmsf(h,m,s,f,timeBase,bDrop);
561 }
562 
563 bool AJATimeCode::QueryIsRP188DropFrame (const uint32_t inDBB, const uint32_t inLo, const uint32_t inHi) // STATIC
564 {
565  AJA_UNUSED(inDBB);
566  AJA_UNUSED(inHi);
567  return (inLo >> 10) & 0x01;
568 }
569 
570 void AJATimeCode::SetRP188 (const uint32_t inDBB, const uint32_t inLo, const uint32_t inHi, const AJATimeBase & inTimeBase)
571 {
572  bool bDrop = AJATimeCode::QueryIsRP188DropFrame(inDBB, inLo, inHi);
573 
574  // HRS
575  const uint32_t h0 (((inHi >> 16) & 0xF) );
576  const uint32_t h1 (((inHi >> 24) & 0x3) * 10);
577  // MINS
578  const uint32_t m0 (((inHi ) & 0xF) );
579  const uint32_t m1 (((inHi >> 8) & 0x7) * 10);
580  // SECS
581  const uint32_t s0 (((inLo >> 16) & 0xF) );
582  const uint32_t s1 (((inLo >> 24) & 0x7) * 10);
583  // FRAMES
584  uint32_t f0(0);
585  uint32_t f1(0);
586 
587  AJA_FrameRate frameRate = inTimeBase.GetAJAFrameRate();
588  if (m_stdTcForHfr == false && frameRate >= AJA_FrameRate_4795)
589  {
590  // for frame rates > 39 fps, we need an extra bit for the frame "10s". By convention,
591  // we use the field ID bit to be the LS bit of the three bit number.
592  bool fieldID;
593 
594  // Note: FID is in different words for PAL & NTSC!
595  if(frameRate == AJA_FrameRate_5000 || frameRate == AJA_FrameRate_10000)
596  fieldID = ((inHi & (1u<<27)) != 0);
597  else
598  fieldID = ((inLo & (1u<<27)) != 0);
599 
600  // Double the regular frame count and add fieldID...
601  const uint32_t numFrames = (((((inLo >> 8) & 0x3) * 10) + (inLo & 0xF)) * 2) + uint32_t(fieldID);
602  f0 = numFrames % 10;
603  f1 = (numFrames / 10) * 10;
604  }
605  else
606  {
607  f0 = ((inLo ) & 0xF);
608  f1 = ((inLo >> 8) & 0x3) * 10;
609  }
610 
611  SetHmsf (h0+h1, m0+m1, s0+s1, f0+f1, inTimeBase, bDrop);
612 }
613 
614 #if !defined(NTV2_DEPRECATE_17_5)
615  void AJATimeCode::QueryRP188(uint32_t *pDbb, uint32_t *pLow, uint32_t *pHigh, const AJATimeBase& timeBase, bool bDrop)
616  {
617  uint32_t dbb(0), low(0), high(0);
618  QueryRP188(dbb, low, high, timeBase, bDrop);
619  if (*pDbb) *pDbb = dbb;
620  if (*pLow) *pLow = low;
621  if (*pHigh) *pHigh = high;
622  }
623 #endif // !defined(NTV2_DEPRECATE_17_5)
624 
625 void AJATimeCode::QueryRP188(uint32_t & outDBB, uint32_t & outLo, uint32_t & outHi, const AJATimeBase & timeBase, const bool bDrop)
626 {
627  AJA_UNUSED(timeBase);
628  AJA_UNUSED(bDrop);
629 
630  uint32_t dbb = 0;
631  uint32_t low = 0;
632  uint32_t high = 0;
633  // UNIMPLEMENTED -- FINISH
634  outDBB = dbb;
635  outLo = low;
636  outHi = high;
637 }
638 
639 
640 //---------------------------------------------------------------------------------------------------------------------
641 // Name: = operator
642 //---------------------------------------------------------------------------------------------------------------------
644 {
645  if (this != &val)
646  {
647  m_frame = val.m_frame;
648  m_stdTcForHfr = val.m_stdTcForHfr;
649  }
650  return *this;
651 } //end '='
652 
653 //---------------------------------------------------------------------------------------------------------------------
654 // Name: == operator
655 //---------------------------------------------------------------------------------------------------------------------
656 bool AJATimeCode::operator==(const AJATimeCode &val) const
657 {
658  bool bIsSame = false;
659  if (m_frame == val.m_frame)
660  {
661  bIsSame = true;
662  }
663  return bIsSame;
664 }
665 
666 //---------------------------------------------------------------------------------------------------------------------
667 // Name: < operator
668 //---------------------------------------------------------------------------------------------------------------------
669 bool AJATimeCode::operator<(const AJATimeCode &val) const
670 {
671  bool bIsLess = (m_frame < val.m_frame);
672  return bIsLess;
673 }
674 
675 bool AJATimeCode::operator<(const int32_t val) const
676 {
677  bool bIsLess = (m_frame < (uint32_t)val);
678  return bIsLess;
679 }
680 
681 
682 //---------------------------------------------------------------------------------------------------------------------
683 // Name: > operator
684 //---------------------------------------------------------------------------------------------------------------------
685 bool AJATimeCode::operator>(const AJATimeCode &val) const
686 {
687  bool bIsGreater = (m_frame > val.m_frame);
688  return bIsGreater;
689 }
690 
691 bool AJATimeCode::operator>(const int32_t val) const
692 {
693  bool bIsGreater = (m_frame > (uint32_t)val);
694  return bIsGreater;
695 }
696 
697 
698 //---------------------------------------------------------------------------------------------------------------------
699 // Name: != operator
700 //---------------------------------------------------------------------------------------------------------------------
701 bool AJATimeCode::operator!=(const AJATimeCode &val) const
702 {
703  return !(*this == val);
704 }
705 
706 //---------------------------------------------------------------------------------------------------------------------
707 // Name: += operator
708 //---------------------------------------------------------------------------------------------------------------------
710 {
711  m_frame += val.m_frame;
712  return *this;
713 }
714 
716 {
717  m_frame += val;
718  return *this;
719 }
720 
721 //---------------------------------------------------------------------------------------------------------------------
722 // Name: -= operator
723 //---------------------------------------------------------------------------------------------------------------------
725 {
726  if(val.m_frame > m_frame)
727  m_frame = 0;
728  else
729  m_frame -= val.m_frame;
730 
731  return *this;
732 }
733 
735 {
736  if((uint32_t)val > m_frame)
737  m_frame = 0;
738  else
739  m_frame -= val;
740 
741  return *this;
742 }
743 
744 //---------------------------------------------------------------------------------------------------------------------
745 // Name: + operator
746 //---------------------------------------------------------------------------------------------------------------------
748 {
749  return AJATimeCode(*this) += val;
750 }
751 
752 const AJATimeCode AJATimeCode::operator+(const int32_t val) const
753 {
754  return AJATimeCode(*this) += val;
755 }
756 
757 //---------------------------------------------------------------------------------------------------------------------
758 // Name: - operator
759 //---------------------------------------------------------------------------------------------------------------------
761 {
762  return AJATimeCode(*this) -= val;
763 }
764 
765 const AJATimeCode AJATimeCode::operator-(const int32_t val) const
766 {
767  return AJATimeCode(*this) -= val;
768 }
AJA_FrameRate_3000
@ AJA_FrameRate_3000
Definition: videotypes.h:223
AJATimeCode::~AJATimeCode
virtual ~AJATimeCode()
Definition: timecode.cpp:77
AJATimeCode::SetHmsf
void SetHmsf(uint32_t h, uint32_t m, uint32_t s, uint32_t f, const AJATimeBase &timeBase, bool bDropFrame, bool bStdTcForHfr, uint32_t addFrame)
Definition: timecode.cpp:425
AJATimeCodeRound
uint32_t AJATimeCodeRound(double f)
Definition: timecode.cpp:97
AJATimeCode::QueryIsRP188DropFrame
static bool QueryIsRP188DropFrame(const uint32_t inDBB, const uint32_t inLo, const uint32_t inHi)
Definition: timecode.cpp:563
AJATimeCode::QueryRP188
void QueryRP188(uint32_t &outDBB, uint32_t &outLo, uint32_t &outHi, const AJATimeBase &timeBase, const bool bDrop)
Definition: timecode.cpp:625
AJATimeBase::GetFrameRate
void GetFrameRate(int64_t &frameTimeScale, int64_t &frameDuration) const
Definition: timebase.cpp:133
AJATimeCode::operator<
bool operator<(const AJATimeCode &val) const
Definition: timecode.cpp:669
AJATimeCode::SetWithCleanup
void SetWithCleanup(const std::string &str, const AJATimeBase &timeBase, bool bDrop)
Definition: timecode.cpp:495
AJATimeCode::operator+=
AJATimeCode & operator+=(const AJATimeCode &val)
Definition: timecode.cpp:709
AJATimeCode::Set
void Set(uint32_t frame)
Definition: timecode.cpp:420
AJATimeCode::operator==
bool operator==(const AJATimeCode &val) const
Definition: timecode.cpp:656
AJATimeCode::QueryStringSize
static int QueryStringSize(void)
Definition: timecode.cpp:87
timecode.h
Declares the AJATimeCode class.
aja::stoi
int stoi(const std::string &str, std::size_t *idx, int base)
Definition: common.cpp:122
AJA_UNUSED
#define AJA_UNUSED(_x_)
Definition: types.h:424
AJA_FrameRate
AJA_FrameRate
Definition: videotypes.h:210
AJATimeCode::operator-=
AJATimeCode & operator-=(const AJATimeCode &val)
Definition: timecode.cpp:724
AJA_FrameRate_10000
@ AJA_FrameRate_10000
Definition: videotypes.h:229
AJA_FrameRate_4795
@ AJA_FrameRate_4795
Definition: videotypes.h:224
AJATimeCode::operator-
const AJATimeCode operator-(const AJATimeCode &val) const
Definition: timecode.cpp:760
AJATimeBase
Definition: timebase.h:18
AJA_TIMECODE_STANDARD
@ AJA_TIMECODE_STANDARD
AJA standard notation (e.g. 01;02;03.29 .. 01;02;03;29 .. 01:02:03#58)
Definition: timecode.h:19
AJATimeCode::operator!=
bool operator!=(const AJATimeCode &val) const
Definition: timecode.cpp:701
AJATimeBase::GetAJAFrameRate
AJA_FrameRate GetAJAFrameRate(void) const
Definition: timebase.cpp:427
AJATimeCode::SetRP188
void SetRP188(const uint32_t inDBB, const uint32_t inLo, const uint32_t inHi, const AJATimeBase &inTimeBase)
Definition: timecode.cpp:570
AJATimeBase::GetFramesPerSecondDouble
double GetFramesPerSecondDouble(void) const
Definition: timebase.cpp:215
AJATimeCode::AJATimeCode
AJATimeCode()
Definition: timecode.cpp:44
AJA_FrameRate_5000
@ AJA_FrameRate_5000
Definition: videotypes.h:226
aja::is_decimal_digit
bool is_decimal_digit(const char inChr)
Definition: common.cpp:516
AJATimeCode::QuerySMPTEString
void QuerySMPTEString(char *pString, const AJATimeBase &timeBase, bool bDropFrame)
Definition: timecode.cpp:401
AJATimeCode::SetSMPTEString
void SetSMPTEString(const char *pBufr, const AJATimeBase &timeBase)
Definition: timecode.cpp:549
AJATimeCode::QueryHmsf
void QueryHmsf(uint32_t &h, uint32_t &m, uint32_t &s, uint32_t &f, const AJATimeBase &timeBase, bool bDropFrame) const
Definition: timecode.cpp:292
AJATimeCode::operator=
AJATimeCode & operator=(const AJATimeCode &val)
Definition: timecode.cpp:643
common.h
Private include file for all ajabase sources.
AJATimeCode::CalcFrame
static uint32_t CalcFrame(uint32_t h, uint32_t m, uint32_t s, uint32_t f, const AJATimeBase &timeBase, bool bDropFrame, bool bStdTcForHfr, uint32_t addFrame)
Definition: timecode.cpp:107
AJATimeCode::QuerySMPTEStringSize
static int QuerySMPTEStringSize(void)
Definition: timecode.cpp:396
std
Definition: json.hpp:5362
AJATimeCode::QueryFrame
uint32_t QueryFrame(void) const
Definition: timecode.cpp:92
AJATimeCode::operator>
bool operator>(const AJATimeCode &val) const
Definition: timecode.cpp:685
true
#define true
Definition: ntv2devicefeatures.h:26
AJATimeCode::operator+
const AJATimeCode operator+(const AJATimeCode &val) const
Definition: timecode.cpp:747
AJATimeCode::QueryString
void QueryString(std::string &str, const AJATimeBase &timeBase, bool bDropFrame, bool bStdTcForHfr, AJATimecodeNotation notation=AJA_TIMECODE_LEGACY)
Definition: timecode.cpp:299
AJATimeCodeAbs
int64_t AJATimeCodeAbs(int64_t x)
Definition: timecode.cpp:102
AJATimecodeNotation
AJATimecodeNotation
Identifies the timecode format used in AJATimeCode::QueryString.
Definition: timecode.h:16
AJATimeCode::CalcHmsf
static uint32_t CalcHmsf(uint32_t &h, uint32_t &m, uint32_t &s, uint32_t &f, uint32_t frame, const AJATimeBase &timeBase, bool bDropFrame, bool bStdTcForHfr)
Definition: timecode.cpp:170
AJATimeCode
Utility class for timecodes.
Definition: timecode.h:28
AJATimeCode::QueryIsDropFrame
static bool QueryIsDropFrame(const std::string &str)
Definition: timecode.cpp:81