Skip to content

Commit

Permalink
get rid of convertToUint64
Browse files Browse the repository at this point in the history
same as getULongLong

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Feb 26, 2023
1 parent eaee1f7 commit ce86e0c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 39 deletions.
8 changes: 4 additions & 4 deletions include/exiv2/matroskavideo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ class EXIV2API MatroskaVideo : public Image {
@param size Size of \em buf.
*/

void decodeInternalTags(const Internal::MatroskaTag* tag, const byte* buf, size_t size);
void decodeInternalTags(const Internal::MatroskaTag* tag, const byte* buf);
void decodeStringTags(const Internal::MatroskaTag* tag, const byte* buf);
void decodeIntegerTags(const Internal::MatroskaTag* tag, const byte* buf, size_t size);
void decodeBooleanTags(const Internal::MatroskaTag* tag, const byte* buf, size_t size);
void decodeIntegerTags(const Internal::MatroskaTag* tag, const byte* buf);
void decodeBooleanTags(const Internal::MatroskaTag* tag, const byte* buf);
void decodeDateTags(const Internal::MatroskaTag* tag, const byte* buf, size_t size);
void decodeFloatTags(const Internal::MatroskaTag* tag, const byte* buf, size_t size);
void decodeFloatTags(const Internal::MatroskaTag* tag, const byte* buf);

private:
//! Variable to check the end of metadata traversing.
Expand Down
56 changes: 21 additions & 35 deletions src/matroskavideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,21 +595,6 @@ const MatroskaTag streamRate[] = {

return tag;
}

/*!
@brief Function used to convert buffer data into Integeral information,
information stored in BigEndian format
*/
[[nodiscard]] bool convertToUint64(const byte* buf, size_t size, uint64_t& value) {
uint64_t ret = 0;
for (size_t i = 0; i < size; ++i) {
ret |= static_cast<uint64_t>(buf[i]) << ((size - i - 1) * 8);
}

value = ret;
return true;
}

} // namespace Exiv2::Internal

namespace Exiv2 {
Expand Down Expand Up @@ -706,24 +691,24 @@ void MatroskaVideo::decodeBlock() {
io_->read(buf2.data(), size);
switch (tag->_type) {
case InternalField:
decodeInternalTags(tag, buf2.data(), size);
decodeInternalTags(tag, buf2.data());
break;
case String:
case Utf8:
decodeStringTags(tag, buf2.data());
break;
case Integer:
case UInteger:
decodeIntegerTags(tag, buf2.data(), size);
decodeIntegerTags(tag, buf2.data());
break;
case Boolean:
decodeBooleanTags(tag, buf2.data(), size);
decodeBooleanTags(tag, buf2.data());
break;
case Date:
decodeDateTags(tag, buf2.data(), size);
break;
case Float:
decodeFloatTags(tag, buf2.data(), size);
decodeFloatTags(tag, buf2.data());
break;
case Binary:
break;
Expand All @@ -734,10 +719,10 @@ void MatroskaVideo::decodeBlock() {
}
} // MatroskaVideo::decodeBlock

void MatroskaVideo::decodeInternalTags(const MatroskaTag* tag, const byte* buf, size_t size) {
void MatroskaVideo::decodeInternalTags(const MatroskaTag* tag, const byte* buf) {
const MatroskaTag* internalMt = nullptr;
uint64_t key = 0;
if (!convertToUint64(buf, size, key))
uint64_t key = getULongLong(buf, bigEndian);
if (!key)
return;

switch (tag->_id) {
Expand Down Expand Up @@ -805,9 +790,9 @@ void MatroskaVideo::decodeStringTags(const MatroskaTag* tag, const byte* buf) {
}
}

void MatroskaVideo::decodeIntegerTags(const MatroskaTag* tag, const byte* buf, size_t size) {
uint64_t value = 0;
if (!convertToUint64(buf, size, value))
void MatroskaVideo::decodeIntegerTags(const MatroskaTag* tag, const byte* buf) {
uint64_t value = getULongLong(buf, bigEndian);
if (!value)
return;

if (tag->_id == Xmp_video_Width_1 || tag->_id == Xmp_video_Width_2)
Expand All @@ -817,11 +802,11 @@ void MatroskaVideo::decodeIntegerTags(const MatroskaTag* tag, const byte* buf, s
xmpData_[tag->_label] = value;
}

void MatroskaVideo::decodeBooleanTags(const MatroskaTag* tag, const byte* buf, size_t size) {
void MatroskaVideo::decodeBooleanTags(const MatroskaTag* tag, const byte* buf) {
std::string str("No");
const MatroskaTag* internalMt = nullptr;
uint64_t key = 0;
if (!convertToUint64(buf, size, key))
uint64_t key = getULongLong(buf, bigEndian);
if (!key)
return;

switch (tag->_id) {
Expand Down Expand Up @@ -863,7 +848,7 @@ void MatroskaVideo::decodeBooleanTags(const MatroskaTag* tag, const byte* buf, s

void MatroskaVideo::decodeDateTags(const MatroskaTag* tag, const byte* buf, size_t size) {
int64_t duration_in_ms = 0;
uint64_t value = 0;
uint64_t value;
switch (tag->_id) {
case Xmp_video_Duration:
if (size <= 4) {
Expand All @@ -875,15 +860,16 @@ void MatroskaVideo::decodeDateTags(const MatroskaTag* tag, const byte* buf, size
xmpData_[tag->_label] = duration_in_ms;
break;
case Xmp_video_DateUTC:

if (!convertToUint64(buf, size, value))
value = getULongLong(buf, bigEndian);
if (!value)
return;
duration_in_ms = value / 1000000000;
xmpData_[tag->_label] = duration_in_ms;
break;

case TimecodeScale:
if (!convertToUint64(buf, size, value))
value = getULongLong(buf, bigEndian);
if (!value)
return;
time_code_scale_ = static_cast<double>(value) / static_cast<double>(1000000000);
xmpData_[tag->_label] = time_code_scale_;
Expand All @@ -893,7 +879,7 @@ void MatroskaVideo::decodeDateTags(const MatroskaTag* tag, const byte* buf, size
}
}

void MatroskaVideo::decodeFloatTags(const MatroskaTag* tag, const byte* buf, size_t size) {
void MatroskaVideo::decodeFloatTags(const MatroskaTag* tag, const byte* buf) {
xmpData_[tag->_label] = getFloat(buf, bigEndian);

double frame_rate = 0;
Expand All @@ -904,8 +890,8 @@ void MatroskaVideo::decodeFloatTags(const MatroskaTag* tag, const byte* buf, siz
break;
case VideoFrameRate_DefaultDuration:
case Xmp_video_FrameRate: {
uint64_t key = 0;
if (!convertToUint64(buf, size, key))
uint64_t key = getULongLong(buf, bigEndian);
if (!key)
return;
const MatroskaTag* internalMt = Exiv2::find(streamRate, key);
if (internalMt) {
Expand Down

0 comments on commit ce86e0c

Please sign in to comment.