place timecode conversion functions into a Timecode class rather than an olive namespace
Code cleanup and improvement.
This commit is contained in:
@@ -25,30 +25,42 @@
|
||||
|
||||
#include "common/rational.h"
|
||||
|
||||
namespace olive {
|
||||
/**
|
||||
* @brief Functions for converting times/timecodes/timestamps
|
||||
*
|
||||
* Olive uses the following terminology through its code:
|
||||
*
|
||||
* `time` - time in seconds presented in a rational form
|
||||
* `timebase` - the base time unit of an audio/video stream in seconds
|
||||
* `timestamp` - an integer representation of a time in timebase units (in many cases is used like a frame number)
|
||||
* `timecode` a user-friendly string representation of a time according to Timecode::Display
|
||||
*/
|
||||
class Timecode {
|
||||
public:
|
||||
enum Display {
|
||||
kTimecodeDropFrame,
|
||||
kTimecodeNonDropFrame,
|
||||
kTimecodeSeconds,
|
||||
kFrames,
|
||||
kMilliseconds
|
||||
};
|
||||
|
||||
static Display CurrentDisplay();
|
||||
|
||||
/**
|
||||
* @brief Convert a timestamp (according to a rational timebase) to a user-friendly string representation
|
||||
*/
|
||||
static QString timestamp_to_timecode(const int64_t ×tamp, const rational& timebase, const Display &display, bool show_plus_if_positive = false);
|
||||
|
||||
static int64_t timecode_to_timestamp(const QString& timecode, const rational& timebase, const Display& display, bool *ok = nullptr);
|
||||
|
||||
static int64_t time_to_timestamp(const rational& time, const rational& timebase);
|
||||
static int64_t time_to_timestamp(const double& time, const rational& timebase);
|
||||
|
||||
static rational timestamp_to_time(const int64_t& timestamp, const rational& timebase);
|
||||
|
||||
static bool TimebaseIsDropFrame(const rational& timebase);
|
||||
|
||||
enum TimecodeDisplay {
|
||||
kTimecodeDropFrame,
|
||||
kTimecodeNonDropFrame,
|
||||
kTimecodeSeconds,
|
||||
kFrames,
|
||||
kMilliseconds
|
||||
};
|
||||
|
||||
TimecodeDisplay CurrentTimecodeDisplay();
|
||||
|
||||
/**
|
||||
* @brief Convert a timestamp (according to a rational timebase) to a user-friendly string representation
|
||||
*/
|
||||
QString timestamp_to_timecode(const int64_t ×tamp, const rational& timebase, const TimecodeDisplay& display, bool show_plus_if_positive = false);
|
||||
|
||||
int64_t timecode_to_timestamp(const QString& timecode, const rational& timebase, const TimecodeDisplay& display, bool *ok = nullptr);
|
||||
|
||||
int64_t time_to_timestamp(const rational& time, const rational& timebase);
|
||||
int64_t time_to_timestamp(const double& time, const rational& timebase);
|
||||
|
||||
rational timestamp_to_time(const int64_t& timestamp, const rational& timebase);
|
||||
|
||||
}
|
||||
|
||||
#endif // TIMECODEFUNCTIONS_H
|
||||
|
||||
Reference in New Issue
Block a user