Skip to content

Commit

Permalink
Use a struct for clock input parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
dukesook committed Nov 7, 2023
1 parent 985b6ca commit ca3d7b7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 49 deletions.
51 changes: 18 additions & 33 deletions libheif/heif_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,7 @@ void heif_property_user_description_release(struct heif_property_user_descriptio

struct heif_error heif_property_set_clock_info(const struct heif_context* context,
heif_item_id itemId,
uint64_t time_uncertainty,
int64_t correction_offset,
float clock_drift_rate,
uint8_t clock_source,
heif_tai_clock_info clock,
heif_property_id* out_propertyId)
{
if (!context) {
Expand All @@ -316,10 +313,10 @@ struct heif_error heif_property_set_clock_info(const struct heif_context* contex
// TODO - if the property already exists, we should update it instead of creating a new one.
auto taic = std::make_shared<Box_taic>();

taic->set_time_uncertainty(time_uncertainty);
taic->set_correction_offset(correction_offset);
taic->set_clock_drift_rate(clock_drift_rate);
taic->set_clock_source(clock_source);
taic->set_time_uncertainty(clock.time_uncertainty);
taic->set_correction_offset(clock.correction_offset);
taic->set_clock_drift_rate(clock.clock_drift_rate);
taic->set_clock_source(clock.clock_source);

bool essential = false;
heif_property_id id = context->context->add_property(itemId, taic, essential);
Expand All @@ -333,40 +330,28 @@ struct heif_error heif_property_set_clock_info(const struct heif_context* contex

struct heif_error heif_property_get_clock_info(const struct heif_context* context,
heif_item_id itemId,
uint64_t* out_time_uncertainty,
int64_t* out_correction_offset,
float* out_clock_drift_rate,
uint8_t* out_clock_source)
heif_tai_clock_info* out_clock)
{
if (!context) {
return {heif_error_Usage_error, heif_suberror_Invalid_parameter_value, "NULL passed"};
return {heif_error_Usage_error, heif_suberror_Invalid_parameter_value, "NULL heif_context passed in"};
}
if (!out_clock) {
return {heif_error_Usage_error, heif_suberror_Invalid_parameter_value, "NULL heif_tai_clock_info passed in"};
}

auto file = context->context->get_heif_file();

// TODO - use a function to get the taic instead of duplicating code.
auto ipco = file->get_ipco_box();
auto impa = file->get_ipma_box();
auto prop = ipco->get_property_for_item_ID(itemId, impa, fourcc("taic"));
auto taic = std::dynamic_pointer_cast<Box_taic>(prop);
// Only create a new taic if one doesn't exist for the itemId.
auto taic = context->context->get_heif_file()->get_property<Box_taic>(itemId);
if (!taic) {
return {heif_error_Usage_error, heif_suberror_Invalid_property, "Clock info property not found"};
taic = std::make_shared<Box_taic>();
context->context->add_property(itemId, taic, essential); // Should we output taic property id?
}

// TODO - if the value is unknown, return a nullptr.
if (out_time_uncertainty) {
*out_time_uncertainty = taic->get_time_uncertainty();
}
if (out_correction_offset) {
*out_correction_offset = taic->get_correction_offset();
}
if (out_clock_drift_rate) {
*out_clock_drift_rate = taic->get_clock_drift_rate();
}
if (out_clock_source) {
*out_clock_source = taic->get_clock_source();
}

clock->time_uncertainty = taic->get_time_uncertainty();
clock->correction_offset = taic->get_correction_offset();
clock->clock_drift_rate = taic->get_clock_drift_rate();
clock->clock_source = taic->get_clock_source();

return heif_error_success;

Expand Down
33 changes: 17 additions & 16 deletions libheif/heif_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,30 +135,31 @@ void heif_item_get_property_transform_crop_borders(const struct heif_context* co


// ========================= Timestamps =========================
/**
* Creates a clock info property if it doesn't already exist.
*
* @param time_uncertainty if unknown: 0xFFFFFFFFFFFFFFFF
* @param correction_offset if unknown: 0x7FFFFFFFFFFFFFFF
* @param clock_drift_rate if unknown: NaN
* @param clock_source if unknown: 0
*/
const uint64_t heif_tai_clock_time_uncertainty = 0x0;
const int64_t heif_tai_clock_correction_offset = 0x0;
const float heif_tai_clock_clock_drift_rate = 0x0;
const uint8_t heif_tai_clock_clock_source = 0x0;
struct heif_tai_clock_info
{
uint8_t version;

uint64_t time_uncertainty,
int64_t correction_offset,
float clock_drift_rate,
uint8_t clock_source,
}

//Creates a clock info property if it doesn't already exist.
LIBHEIF_API
struct heif_error heif_property_set_clock_info(const struct heif_context* ctx,
heif_item_id itemId,
uint64_t time_uncertainty,
int64_t correction_offset,
float clock_drift_rate,
uint8_t clock_source,
heif_tai_clock_info clock,
heif_property_id out_propertyId);

LIBHEIF_API
struct heif_error heif_property_get_clock_info(const struct heif_context* ctx,
heif_item_id itemId,
uint64_t* out_time_uncertainty,
int64_t* out_correction_offset,
float* out_clock_drift_rate,
uint8_t* out_clock_source);
heif_tai_clock_info* out_clock);

/**
* Creates a TAI timestamp property. If one already exists, then update it
Expand Down

0 comments on commit ca3d7b7

Please sign in to comment.