aboutsummaryrefslogtreecommitdiff
path: root/Src/nsavi/info.cpp
diff options
context:
space:
mode:
authorJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
committerJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
commit20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/nsavi/info.cpp
parent537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff)
downloadwinamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz
Initial community commit
Diffstat (limited to 'Src/nsavi/info.cpp')
-rw-r--r--Src/nsavi/info.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/Src/nsavi/info.cpp b/Src/nsavi/info.cpp
new file mode 100644
index 00000000..17c1c4a2
--- /dev/null
+++ b/Src/nsavi/info.cpp
@@ -0,0 +1,68 @@
+#include "info.h"
+#include "read.h"
+
+nsavi::Info::Info()
+{
+
+}
+
+nsavi::Info::~Info()
+{
+ for (auto itr = this->begin(); itr != this->end(); itr++)
+ {
+ free((void*)itr->second);
+ }
+}
+
+int nsavi::Info::Read(nsavi::avi_reader* reader, uint32_t data_len)
+{
+ while (data_len)
+ {
+ riff_chunk chunk;
+ uint32_t bytes_read = 0;
+ nsavi::read_riff_chunk(reader, &chunk, &bytes_read);
+ data_len -= bytes_read;
+ size_t malloc_size = chunk.size + 1;
+ if (malloc_size == 0)
+ return READ_INVALID_DATA;
+
+ char* str = (char*)calloc(malloc_size, sizeof(char));
+ if (!str)
+ return READ_OUT_OF_MEMORY;
+
+ reader->Read(str, chunk.size, &bytes_read);
+ str[chunk.size] = 0;
+ data_len -= bytes_read;
+
+ Set(chunk.id, str);
+
+ if (chunk.size & 1)
+ {
+ reader->Skip(1);
+ data_len--;
+ }
+ }
+ return 0;
+}
+
+void nsavi::Info::Set(uint32_t chunk_id, const char* data)
+{
+ auto it = this->find(chunk_id);
+ if (this->end() == it)
+ {
+ this->insert({ chunk_id, data });
+ }
+ else
+ {
+ it->second = data;
+ }
+}
+const char* nsavi::Info::GetMetadata(uint32_t id)
+{
+ InfoMap::iterator itr = InfoMap::find(id);
+ if (itr != InfoMap::end())
+ {
+ return itr->second;
+ }
+ return 0;
+} \ No newline at end of file