nx_server_plugin_sdk 1.0 Server Plugin SDK

device_archive.h
1 // Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/
2
3 #pragma once
4
5 #include <map>
6 #include <string>
7 #include <chrono>
8
9 #include <nx/sdk/cloud_storage/helpers/data_list.h>
10 #include <nx/sdk/cloud_storage/i_async_operation_handler.h>
11 #include <nx/sdk/helpers/list.h>
12 #include <nx/sdk/helpers/ref_countable.h>
13
14 namespace nx::sdk::cloud_storage {
15
16 enum class ChunkOperation
17 {
18 add,
19 remove,
20 };
21
25 class MediaChunk: public IMediaChunk
26 {
27 public:
28 MediaChunk(int64_t startTimeMs, int64_t durationMs, const char* bucketUrl);
29
30 virtual int64_t startTimeMs() const override;
31 virtual int64_t durationMs() const override;
32 virtual const char* locationUrl() const override;
33
34 std::string toString() const;
35 bool operator<(const MediaChunk& other) const;
36
37 private:
38 int64_t m_startTimeMs = -1;
39 int64_t m_durationMs = -1;
40 const char* m_bucketUrl = nullptr;
41 };
42
43 std::string toString(const std::vector<MediaChunk>& chunks);
44
45 using IndexData = std::map<ChunkOperation, std::vector<MediaChunk>>;
46 using DeviceData = std::map<int /*streamIndex*/, IndexData>;
47 using CloudChunkData = std::map<std::string, DeviceData>;
48
49 class MediaChunkList:
50 public nx::sdk::RefCountable<IMediaChunkList>,
51 public DataList<MediaChunk>
52 {
53 public:
54 MediaChunkList(const std::vector<MediaChunk>& chunks);
55
56 virtual void goToBeginning() const override;
57 virtual void next() const override;
58 virtual bool atEnd() const override;
59 virtual const IMediaChunk* get() const override;
60
61 private:
62 using Base = DataList<MediaChunk>;
63 };
64
65 class IndexArchive: public nx::sdk::RefCountable<IIndexArchive>
66 {
67 public:
68 IndexArchive(int streamIndex, const IndexData& indexData);
69
70 virtual const IMediaChunkList* addedChunks() const override;
71 virtual const IMediaChunkList* removedChunks() const override;
72 virtual int streamIndex() const override;
73
74 private:
75 const int m_streamIndex;
76 Ptr<IMediaChunkList> m_addedChunks;
77 Ptr<IMediaChunkList> m_removedChunks;
78 };
79
80 class DeviceArchive: public nx::sdk::RefCountable<IDeviceArchive>
81 {
82 public:
83 DeviceArchive(
84 IDeviceAgent* deviceAgent,
85 const DeviceData& deviceData);
86
87 virtual IList<IIndexArchive>* indexArchive() override;
88 virtual IDeviceAgent* deviceAgent() const override;
89
90 private:
91 IDeviceAgent* m_deviceAgent;
92 const DeviceData& m_data;
93 List<IIndexArchive> m_indexArchiveList;
94 };
95
96 } // namespace nx::sdk::cloud_storage
nx::sdk::cloud_storage::IMediaChunkList
Definition: i_async_operation_handler.h:28
nx::sdk::cloud_storage::DeviceArchive
Definition: device_archive.h:80
nx::sdk::cloud_storage::MediaChunkList
Definition: device_archive.h:49
nx::sdk::cloud_storage::IndexArchive
Definition: device_archive.h:65
nx::sdk::Ptr
Definition: ptr.h:18
nx::sdk::cloud_storage::IMediaChunk
Definition: i_async_operation_handler.h:16
nx::sdk::cloud_storage::IDeviceAgent
Definition: i_device_agent.h:21
nx::sdk::List
Definition: list.h:15
nx::sdk::cloud_storage::MediaChunk
Definition: device_archive.h:25
nx::sdk::cloud_storage
Definition: algorithm.cpp:9
nx::sdk::cloud_storage::DataList
Definition: data_list.h:10
nx::sdk::IList
Definition: i_list.h:10
nx::sdk::RefCountable
Definition: ref_countable.h:83