diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-10-02 16:27:59 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-10-02 16:27:59 +0200 |
commit | d9cb6885ab741ba69a966109cb05e26692143ce0 (patch) | |
tree | e4e356c182011bc389bc895665dab1507ecdb767 /include | |
parent | 9e68dfad4449d5c0180e252fada6de56b4f405d1 (diff) |
Matrix: add video/regular file upload
Diffstat (limited to 'include')
-rw-r--r-- | include/FileAnalyzer.hpp | 57 | ||||
-rw-r--r-- | include/Path.hpp | 14 |
2 files changed, 68 insertions, 3 deletions
diff --git a/include/FileAnalyzer.hpp b/include/FileAnalyzer.hpp new file mode 100644 index 0000000..be0cc25 --- /dev/null +++ b/include/FileAnalyzer.hpp @@ -0,0 +1,57 @@ +#pragma once + +#include <stddef.h> +#include <optional> +#include <string> + +namespace QuickMedia { + struct Dimensions { + int width; + int height; + }; + + enum class ContentType { + UNKNOWN, + VIDEO_AVI, + VIDEO_MP4, + VIDEO_WEBM, + AUDIO_BASIC, + AUDIO_AIFF, + AUDIO_MPEG, + AUDIO_MIDI, + AUDIO_WAVE, + AUDIO_FLAC, + AUDIO_OPUS, + IMAGE_JPEG, + IMAGE_PNG, + IMAGE_GIF, + IMAGE_BMP, + IMAGE_WEBP + }; + + bool is_content_type_video(ContentType content_type); + bool is_content_type_audio(ContentType content_type); + bool is_content_type_image(ContentType content_type); + const char* content_type_to_string(ContentType content_type); + + bool video_get_first_frame(const char *filepath, const char *destination_path); + + class FileAnalyzer { + public: + FileAnalyzer(); + bool load_file(const char *filepath); + ContentType get_content_type() const; + size_t get_file_size() const; + std::optional<Dimensions> get_dimensions() const; + std::optional<double> get_duration_seconds() const; + private: + FileAnalyzer(FileAnalyzer&) = delete; + FileAnalyzer& operator=(FileAnalyzer&) = delete; + private: + ContentType content_type; + size_t file_size; + std::optional<Dimensions> dimensions; + std::optional<double> duration_seconds; + bool loaded; + }; +}
\ No newline at end of file diff --git a/include/Path.hpp b/include/Path.hpp index bdc31c1..95a5d23 100644 --- a/include/Path.hpp +++ b/include/Path.hpp @@ -26,12 +26,20 @@ namespace QuickMedia { return *this; } + const char* filename() const { + size_t index = data.rfind('/'); + if(index == std::string::npos) + return "/"; + return data.c_str() + index + 1; + } + // Returns empty string if no extension const char* ext() const { + size_t slash_index = data.rfind('/'); size_t index = data.rfind('.'); - if(index == std::string::npos) - return ""; - return data.c_str() + index; + if(index != std::string::npos && (slash_index == std::string::npos || index > slash_index)) + return data.c_str() + index; + return ""; } std::string data; |