Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some growing file improvements #90

Merged
merged 4 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/bmxtranswrap/bmxtranswrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4586,7 +4586,7 @@ int main(int argc, const char** argv)

// realtime transwrapping

uint32_t rt_start = 0;
uint64_t rt_start = 0;
if (realtime)
rt_start = get_tick_count();

Expand All @@ -4596,7 +4596,7 @@ int main(int argc, const char** argv)
unsigned int gf_retry_count = 0;
bool gf_read_failure = false;
int64_t gf_failure_num_read = 0;
uint32_t gf_failure_start = 0;
uint64_t gf_failure_start = 0;


// create clip file(s) and write samples
Expand Down
4 changes: 2 additions & 2 deletions apps/mxf2raw/mxf2raw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2892,15 +2892,15 @@ int main(int argc, const char** argv)
max_samples_per_read = 1920;

// realtime reading
uint32_t rt_start = 0;
uint64_t rt_start = 0;
if (realtime)
rt_start = get_tick_count();

// growing file
unsigned int gf_retry_count = 0;
bool gf_read_failure = false;
int64_t gf_failure_num_read = 0;
uint32_t gf_failure_start = 0;
uint64_t gf_failure_start = 0;

// read data
bmx::ByteArray sound_buffer;
Expand Down
2 changes: 1 addition & 1 deletion apps/raw2bmx/raw2bmx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6135,7 +6135,7 @@ int main(int argc, const char** argv)

// realtime wrapping

uint32_t rt_start = 0;
uint64_t rt_start = 0;
if (realtime)
rt_start = get_tick_count();

Expand Down
8 changes: 8 additions & 0 deletions include/bmx/BMXException.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@
BMX_EXCEPTION(("'%s' check failed", #cond)); \
} while (0)

#define BMX_CHECK_NOLOG(cond) \
do { \
if (!(cond)) { \
throw BMXException( \
"'%s' check failed near %s:%d", #cond, __FILENAME__, __LINE__); \
} \
} while (0)

#define BMX_CHECK_M(cond, err) \
do { \
if (!(cond)) \
Expand Down
6 changes: 3 additions & 3 deletions include/bmx/apps/AppUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ void init_progress(float *next_update);
void print_progress(int64_t count, int64_t duration, float *next_update);

void sleep_msec(uint32_t msec);
uint32_t get_tick_count();
uint32_t delta_tick_count(uint32_t from, uint32_t to);
void rt_sleep(float rt_factor, uint32_t start_tick, Rational sample_rate, int64_t num_samples);
uint64_t get_tick_count();
uint64_t delta_tick_count(uint64_t from, uint64_t to);
void rt_sleep(float rt_factor, uint64_t start_tick, Rational sample_rate, int64_t num_samples);



Expand Down
26 changes: 14 additions & 12 deletions src/apps/AppUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ void bmx::sleep_msec(uint32_t msec)
#endif
}

uint32_t bmx::get_tick_count()
uint64_t bmx::get_tick_count()
{
#if HAVE_CLOCK_GETTIME
struct timespec now;
Expand All @@ -1536,31 +1536,33 @@ uint32_t bmx::get_tick_count()
if (clock_gettime(CLOCK_MONOTONIC, &now) != 0)
#endif
return 0;
return (uint32_t)(now.tv_sec * 1000LL + now.tv_nsec / 1000000L);
return (uint64_t)(now.tv_sec * 1000LL + now.tv_nsec / 1000000L);

#elif defined(_WIN32)
return GetTickCount();
return GetTickCount64();

#else
struct timeval now;
if (gettimeofday(&now, 0) != 0)
return 0;
return (uint32_t)(now.tv_sec * 1000LL + now.tv_usec / 1000);
return (uint64_t)(now.tv_sec * 1000LL + now.tv_usec / 1000);
#endif
}

uint32_t bmx::delta_tick_count(uint32_t from, uint32_t to)
uint64_t bmx::delta_tick_count(uint64_t from, uint64_t to)
{
return (uint32_t)((int64_t)to - from + UINT32_MAX);
if (from >= to)
return 0;
return to - from;
}

void bmx::rt_sleep(float rt_factor, uint32_t start_tick, Rational sample_rate, int64_t num_samples)
void bmx::rt_sleep(float rt_factor, uint64_t start_tick, Rational sample_rate, int64_t num_samples)
{
uint32_t tick = get_tick_count();
uint32_t target_tick = (uint32_t)(start_tick + 1000 * num_samples *
sample_rate.denominator / (rt_factor * sample_rate.numerator));
uint32_t delta_tick = delta_tick_count(tick, target_tick);
if (delta_tick < 10000) // don't sleep if target_tick < tick or there are bogus tick values
uint64_t tick = get_tick_count();
uint64_t target_tick = start_tick + (uint64_t)(1000 * num_samples *
sample_rate.denominator / (rt_factor * sample_rate.numerator));
uint64_t delta_tick = delta_tick_count(tick, target_tick);
if (delta_tick)
sleep_msec(delta_tick);
}

6 changes: 3 additions & 3 deletions src/mxf_reader/EssenceReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool EssenceReaderBuffer::PopOrPrepareRead(int64_t position, uint32_t num_sample
{
size_t offset = GetFrameBufferOffset(position);
if (offset < GetBufferSize()) {
if (mRequestSampleCounts[offset] == num_samples) {
if (mRequestSampleCounts[offset] == num_samples && mReadSampleCounts[offset] == num_samples) {
if (!mBufferFrames) {
ClearBeforeFrames(offset);
offset = 0;
Expand Down Expand Up @@ -529,7 +529,7 @@ uint32_t EssenceReader::ReadClipWrappedSamples(uint32_t num_samples)
frame->Grow((uint32_t)size);
uint32_t num_read = mFile->read(frame->GetBytesAvailable(), (uint32_t)size);
current_file_position += num_read;
BMX_CHECK(num_read == size);
BMX_CHECK_NOLOG(num_read == size);

size -= mImageEndOffset;
if (mImageStartOffset > 0) {
Expand Down Expand Up @@ -638,7 +638,7 @@ uint32_t EssenceReader::ReadFrameWrappedSamples(uint32_t num_samples)
if (!mParseOnly)
{
uint32_t num_read = mFile->read(frame->GetBytesAvailable(), (uint32_t)len);
BMX_CHECK(num_read == len);
BMX_CHECK_NOLOG(num_read == len);
} else {
mFile->skip(len);
}
Expand Down
2 changes: 1 addition & 1 deletion test/growing_file/growing_file.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2c0703daa26c571738c6f313cfd2b054
aa99fd8e8e058b07af7db303dc58653c
Loading