Skip to content

Commit

Permalink
If the taic is missing, add it
Browse files Browse the repository at this point in the history
  • Loading branch information
dukesook committed Nov 3, 2023
1 parent 4a6e47c commit f3ef516
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libheif/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ class Box_taic : public FullBox
//These default values are used if the true value in unkown.
uint64_t m_time_uncertainty = 0xFFFFFFFFFFFFFFFF;
int64_t m_correction_offset = 0x7FFFFFFFFFFFFFFF;
float m_clock_drift_rate = 0x7FC00000;// IEEE 754 quiet NAN
float m_clock_drift_rate = std::numeric_limits<float>::quiet_NaN();
uint8_t m_clock_source = 0;
};

Expand Down
53 changes: 52 additions & 1 deletion libheif/heif_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,50 @@ struct heif_error heif_property_add_clock_info(const struct heif_context* contex

struct heif_error heif_property_get_clock_info(const struct heif_context* context,
heif_item_id itemId,
heif_property_id propertyId,
uint64_t* out_time_uncertainty,
int64_t* out_correction_offset,
float* out_clock_drift_rate,
uint8_t* out_clock_source)
{
return {heif_error_Unsupported_feature, heif_suberror_Unsupported_data_version, "not yet implemented"};
if (!context) {
return {heif_error_Usage_error, heif_suberror_Invalid_parameter_value, "NULL passed"};
}

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

std::vector<std::shared_ptr<Box>> properties;
Error err = file->get_properties(itemId, properties);
if (err) {
return err.error_struct(context->context.get());
}

uint32_t propertyIndex = propertyId - 1;
if (propertyIndex < 0 || propertyIndex >= properties.size()) {
return {heif_error_Usage_error, heif_suberror_Invalid_property, "property index out of range"};
}

auto taic = std::dynamic_pointer_cast<Box_taic>(properties[propertyIndex]);
if (!taic) {
return {heif_error_Usage_error, heif_suberror_Invalid_property, "wrong property type"};
}

if (out_time_uncertainty == nullptr) {
*out_time_uncertainty = taic->get_time_uncertainty();
}
if (out_correction_offset == nullptr) {
*out_correction_offset = taic->get_correction_offset();
}
if (out_clock_drift_rate == nullptr) {
*out_clock_drift_rate = taic->get_clock_drift_rate();
}
if (out_clock_source == nullptr) {
*out_clock_source = taic->get_clock_source();
}


return heif_error_success;

}

struct heif_error heif_property_add_tai_timestamp(const struct heif_context* context,
Expand All @@ -367,6 +405,19 @@ struct heif_error heif_property_add_tai_timestamp(const struct heif_context* con

bool essential = false;
heif_property_id id = context->context->add_property(itemId, itai, essential);

// A taic box shall be present point to the same item as the itai box.
heif_error err;
auto ipco = context->context->get_heif_file()->get_ipco_box();
auto impa = context->context->get_heif_file()->get_ipma_box();
auto taic = ipco->get_property_for_item_ID(itemId, impa, fourcc("taic"));
if (!taic) {
err = heif_property_add_clock_info(context, itemId, nullptr, nullptr, nullptr, nullptr, nullptr);
if (err.code != heif_error_Ok) {
return err;
}
}


if (out_propertyId) {
*out_propertyId = id;
Expand Down
4 changes: 1 addition & 3 deletions libheif/heif_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ void heif_item_get_property_transform_crop_borders(const struct heif_context* co


// ========================= Timestamps =========================
// The Clock Info Property provides metadata about the source
// clock that used to record the TAI timestamps.
// The 'itai' TAI Timestamp Box indicates the time in nanoseconds since January 1, 1958
// Add required metadata about
LIBHEIF_API
struct heif_error heif_property_add_clock_info(const struct heif_context* context,
heif_item_id itemId,
Expand Down

0 comments on commit f3ef516

Please sign in to comment.