MediaManager
MediaManager class for managing media files and transfers.
#include <media_manager.hpp>Classes
class MediaManager
Ground-side singleton that manages capture media: scanning, transfer, export, and deletion.
Call Configure() once at startup before invoking any other method.
static MediaManager& Instance()Returns the singleton instance.
Returns: Reference to the single MediaManager instance.
void Configure(const std::string& media_path, const std::string& host, const std::string& user = "pi", int min_free_space_mb = 500)Configure paths and remote transfer settings. Call once at app startup.
| Parameter | Type | Description |
|---|---|---|
media_path |
const std::string& |
Local directory where all media files are stored. |
host |
const std::string& |
Onboard computer IP address or hostname used for remote transfers. |
user |
const std::string& |
SSH username for remote connections. |
min_free_space_mb |
int |
Minimum free space in MB required before accepting new media. |
std::vector<MediaItem> ScanItems() constScan the media directory and return all discovered items, newest first.
Returns: A vector of discovered media items.
void OnMasterReady(const std::string& remote_path, uint64_t size_bytes, uint32_t duration_secs)Notifies the manager that an onboard master recording is finalized and ready to fetch.
| Parameter | Type | Description |
|---|---|---|
remote_path |
const std::string& |
Absolute path to the master file on the onboard computer. |
size_bytes |
uint64_t |
File size in bytes. |
duration_secs |
uint32_t |
Recording duration in seconds. |
void Fetch(const std::string& uuid)Asynchronously transfers the master file for the given item.
| Parameter | Type | Description |
|---|---|---|
uuid |
const std::string& |
UUID of the media item to fetch. Does nothing if no remote path is known for this UUID. |
void RefreshRemoteList()Refresh the "available to download" list by listing the onboard media directory over SSH and reconciling it against local files.
Any onboard master with no local copy becomes a downloadable 'available' item; masters already downloaded locally are shown as 'ready'; entries no longer present on the onboard device are dropped. Runs asynchronously and fires the on-changed callback when the list updates.
void DeleteItem(const std::string& uuid)Deletes all local files for the given item and clears its cached state.
| Parameter | Type | Description |
|---|---|---|
uuid |
const std::string& |
UUID of the media item to delete. |
std::string ExportFile(const std::string& uuid, bool is_video, const std::string& dest_dir)Copies the best available local file for the given item to a destination directory.
| Parameter | Type | Description |
|---|---|---|
uuid |
const std::string& |
UUID of the media item to export. |
is_video |
bool |
true if the item is a video, false if it is a photo. |
dest_dir |
const std::string& |
Destination directory path. |
Returns: Full path of the exported file, or an empty string on failure.
bool HasEnoughFreeSpace() constReturns true when the media directory's volume has enough free space.
Returns: true if there is enough free space, false otherwise.
void SetOnChanged(std::function<void()> cb)Registers a callback invoked whenever any item's state changes.
The callback may fire on a background thread — do not perform long-running work inside it.
| Parameter | Type | Description |
|---|---|---|
cb |
std::function<void()> |
Callback to invoke on state change. Safe to register from any thread. |
Structs
struct MediaItem
Lightweight descriptor for a single capture event.
All fields are derived at scan time — no persistent state is stored by this struct.
| Field | Type | Description |
|---|---|---|
uuid |
std::string |
Unique identifier for this capture event. |
is_video |
bool |
true if the item is a video, false if it is a photo. |
captured_at_ms |
int64_t |
Unix epoch ms, from PROXY file mtime. |
state |
MediaState |
Current transfer state of this item. |
download_progress |
double |
0.0–1.0, meaningful during downloading. |
proxy_path |
std::string |
Absolute path to PROXY file (may be empty if deleted after sync). |
master_path |
std::string |
Absolute path to final MASTER file (empty unless state == ready). |
Enums
enum MediaState
State of a captured media item, derived entirely from the filesystem.
| Value | Description |
|---|---|
proxy_only |
Only PROXY file exists; no onboard master available yet. |
available |
Onboard master ready (metadata received); not yet fetched. |
downloading |
MASTER.tmp transfer in progress. |
ready |
MASTER file present locally. |