Skip to content

Commit

Permalink
heif_item_get_property_uuid_size
Browse files Browse the repository at this point in the history
  • Loading branch information
dukesook committed Mar 26, 2024
1 parent 111158d commit 20785dd
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 90 deletions.
41 changes: 5 additions & 36 deletions libheif/box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,11 @@ Error Box::parse(BitstreamRange& range)
}
else {
uint64_t content_size = get_box_size() - get_header_size();
if (range.prepare_read(content_size)) {
if (get_short_type() == fourcc("uuid")) {
m_uuid_data.resize(content_size);
range.read(m_uuid_data.data(), content_size);
}
else if (range.prepare_read(content_size)) {
if (content_size > MAX_BOX_SIZE) {
return Error(heif_error_Invalid_input,
heif_suberror_Invalid_box_size);
Expand Down Expand Up @@ -568,9 +572,6 @@ Error Box::read(BitstreamRange& range, std::shared_ptr<Box>* result)
box = std::make_shared<Box_udes>();
break;

case fourcc("uuid"):
box = std::make_shared<Box_uuid>();
break;

case fourcc("jpgC"):
box = std::make_shared<Box_jpgC>();
Expand Down Expand Up @@ -3092,35 +3093,3 @@ Error Box_udes::write(StreamWriter& writer) const
return Error::Ok;
}


std::string Box_uuid::dump(Indent& indent) const
{
std::ostringstream sstr;
sstr << Box::dump(indent);
sstr << indent << "uuid_type: ";
for (uint8_t byte: m_uuid_type) {
sstr << byte << " ";
}
sstr << "\n";
return sstr.str();
}

Error Box_uuid::write(StreamWriter& writer) const
{
size_t box_start = reserve_box_header_space(writer);
writer.write(m_uuid_data);
prepend_header(writer, box_start);
return Error::Ok;
}

Error Box_uuid::parse(BitstreamRange& range)
{
printf("***********Box_uuid::parse()***************\n");
size_t nBytes = range.get_remaining_bytes();
printf("remaining: %lu\n", nBytes);
m_uuid_data.resize(nBytes);
range.read(m_uuid_data.data(), nBytes);
return Error::Ok;
}


34 changes: 5 additions & 29 deletions libheif/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,14 @@ class BoxHeader

std::string get_type_string() const;

std::vector<uint8_t> get_uuid_data() const { return m_uuid_data; }

void set_short_type(uint32_t type) { m_type = type; }

void set_uuid_type(const std::vector<uint8_t>& uuid_type) { m_uuid_type = uuid_type; }

void set_uuid_data(const std::vector<uint8_t>& uuid_data) { m_uuid_data = uuid_data; }

Error parse_header(BitstreamRange& range);

virtual std::string dump(Indent&) const;
Expand All @@ -144,6 +148,7 @@ class BoxHeader

protected:
std::vector<uint8_t> m_uuid_type;
std::vector<uint8_t> m_uuid_data;
uint32_t m_header_size = 0;
};

Expand Down Expand Up @@ -1059,35 +1064,6 @@ class Box_udes : public FullBox
std::string m_tags;
};

/**
* Universally Unique Identifier.
*
* A box of type "uuid" is used to store user-defined data.
* The uuid_type (aka extended_type) in the BoxHeader is used to identify the uuid_data.
*
* See ISO/IEC 14496-12 Section 4.2.2 and Section 11.1.
*/
class Box_uuid : public Box
{
public:
Box_uuid()
{
set_short_type(fourcc("uuid"));
}

std::string dump(Indent&) const override;

Error write(StreamWriter& writer) const override;

std::vector<uint8_t> get_uuid_data() const { return m_uuid_data; }

void set_uuid_data(const std::vector<uint8_t>& uuid_data) { m_uuid_data = uuid_data; }

protected:
Error parse(BitstreamRange& range) override;

private:
std::vector<uint8_t> m_uuid_data;
};

#endif
57 changes: 35 additions & 22 deletions libheif/heif_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ struct heif_error heif_item_add_property_uuid(const struct heif_context* context
std::vector<uint8_t> data_vector(data, data + size);
std::vector<uint8_t> uuid_type_vector(uuid_type, uuid_type + 16);

auto uuid_box = std::make_shared<Box_uuid>();
auto uuid_box = std::make_shared<Box>();
uuid_box->set_uuid_type(uuid_type_vector);
uuid_box->set_uuid_data(data_vector);

Expand All @@ -327,14 +327,40 @@ struct heif_error heif_item_add_property_uuid(const struct heif_context* context
return heif_error_success;
}

struct heif_error heif_item_get_property_uuid_size(const struct heif_context* context,
heif_item_id itemId,
heif_property_id propertyId,
size_t* size_out)
{
auto file = context->context->get_heif_file(); if (!context || !size_out) {
return {heif_error_Usage_error, heif_suberror_Null_pointer_argument, "NULL argument passed in"};
}

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

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

auto uuid_box = properties[propertyId - 1];
auto data = uuid_box->get_uuid_data();

*size_out = data.size();

return heif_error_success;
}


struct heif_error heif_item_get_property_uuid(const struct heif_context* context,
heif_item_id itemId,
heif_property_id propertyId,
const uint8_t** data_out,
size_t* size_out)
uint8_t* data_out)
{
if (!context || !data_out || !size_out) {
if (!context || !data_out) {
return {heif_error_Usage_error, heif_suberror_Null_pointer_argument, "NULL argument passed in"};
}

Expand All @@ -350,25 +376,12 @@ struct heif_error heif_item_get_property_uuid(const struct heif_context* context
return {heif_error_Usage_error, heif_suberror_Invalid_property, "property index out of range"};
}

printf("heif-item_get_property_uuid: properties.size(): %lu\n", properties.size());
for (size_t i = 0; i < properties.size(); i++) {
auto property = properties[i];
std::string type = property->get_type_string();
printf(" %lu) type: %s\n", i, type.c_str());
}
printf("desired propertyId: %lu\n", (long unsigned) propertyId);
int property_index = propertyId - 1;
auto property = properties[property_index];
Indent indent;
std::string dump = property->dump(indent);
printf("dump: %s\n", dump.c_str());
auto uuid = std::dynamic_pointer_cast<Box_uuid>(property);
if (!uuid) {
return {heif_error_Usage_error, heif_suberror_Invalid_property, "Dynamic cast failed"};
}
auto uuid_box = properties[propertyId - 1];
auto data = uuid_box->get_uuid_data();



*data_out = uuid->get_uuid_data().data();
*size_out = uuid->get_uuid_data().size();
std::copy(data.begin(), data.end(), data_out);

return heif_error_success;
}
Expand Down
19 changes: 16 additions & 3 deletions libheif/heif_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,29 @@ struct heif_error heif_item_add_property_uuid(const struct heif_context* context
uint8_t* data, size_t size,
heif_property_id* out_propertyId);


/**
* Get the size of the specidied UUID property.
*
* @param itemId The item to which the property should be added.
* @param propertyId
* @param size_out The size of the uuid payload is returned here. Does not include the 16 bytes of the UUID type.
*/

LIBHEIF_API
struct heif_error heif_item_get_property_uuid_size(const struct heif_context* context,
heif_item_id itemId,
heif_property_id propertyId,
size_t* size_out);


/**
* @param data_out User-supplied array. The size given by heif_item_get_property_uuid_size().
*/
LIBHEIF_API
struct heif_error heif_item_get_property_uuid(const struct heif_context* context,
heif_item_id itemId,
heif_property_id propertyId,
const uint8_t** data_out,
size_t* size_out);
uint8_t* data_out);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 20785dd

Please sign in to comment.