Skip to content

Commit

Permalink
MP4: Handle loci atom
Browse files Browse the repository at this point in the history
  • Loading branch information
cjee21 committed Jan 29, 2025
1 parent d3214da commit 31f23d7
Showing 1 changed file with 66 additions and 2 deletions.
68 changes: 66 additions & 2 deletions Source/MediaInfo/Multiple/File_Mpeg4_Elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9548,8 +9548,72 @@ void File_Mpeg4::moov_udta_loci()
{
NAME_VERSION_FLAG("Location Information"); //3GP

//Parsing
Skip_XX(Element_Size-Element_Offset, "Data");
// Helper functions
// Skip variable-length null-terminated string
auto SkipString = [this](const char* name) -> void {
bool Utf8 = true;
if (Element_Offset + 2 <= Element_Size)
{
int16u Utf16;
Peek_B2(Utf16);
if (Utf16 == 0xFEFF)
Utf8 = false;
}
if (Utf8) {
int8u peek = -1;
int64u size = 0;
while (peek != 0) {
Peek_B1(peek);
++Element_Offset;
++size;
}
Element_Offset -= size;
Skip_UTF8(size, name);
}
else {
int16u peek = -1;
int64u size = 0;
while (peek != 0) {
Peek_B2(peek);
Element_Offset += 2;
size += 2;
}
Element_Offset -= size;
Skip_UTF16B(size, name);
}
};
// Process fixed-point 32-bit signed coordinate numbers
auto ProcFixed32s = [](int32u data) -> double {
double scaledVal = static_cast<double>(*reinterpret_cast<int32s*>(&data)) / 0x10000;
return std::round(scaledVal * 1e5) / 1e5;
};

// Parsing
// 2-bytes language code
Skip_B2("Language");
// Variable-length null-terminated string for 'Location'
SkipString("LocationString");
// 1-byte role where 0:shooting, 1:real, 2:fictional and 3:reserved
Skip_B1("Role");
// 3x 4-byte fixed-point numbers for coordinates
int32u lat, lon, alt;
Get_B4(lon, "Longitude");
Get_B4(lat, "Latitude");
Get_B4(alt, "Altitude");
// Variable-length null-terminated string for 'Body'
SkipString("Body");
// Variable-length null-terminated string for 'Notes'
SkipString("Notes");

// Format coordinates as ISO-6709 string
char ISO6709_buff[50];
snprintf(ISO6709_buff, sizeof(ISO6709_buff), "%+09.5f%+010.5f%+.5f/", ProcFixed32s(lat), ProcFixed32s(lon), ProcFixed32s(alt));
Ztring ISO6709{ ISO6709_buff };

// Filling
FILLING_BEGIN();
Fill(Stream_General, 0, "Recorded_Location", ISO6709);
FILLING_END();
}

//---------------------------------------------------------------------------
Expand Down

0 comments on commit 31f23d7

Please sign in to comment.