diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-08-02 19:52:03 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-08-02 19:54:59 +0100 |
commit | 575f818b0bce3a6dc571e970c546ae4d02660e02 (patch) | |
tree | 3193e2dd302874c61411ca3a5752a3256fe4a469 | |
parent | Tidy and shuffle some bits (diff) | |
download | p2pvr-575f818b0bce3a6dc571e970c546ae4d02660e02.tar.bz2 p2pvr-575f818b0bce3a6dc571e970c546ae4d02660e02.tar.xz p2pvr-575f818b0bce3a6dc571e970c546ae4d02660e02.zip |
Provide more comprehensive video stats, not just size
-rw-r--r-- | p2pvr/daemon/sql/storage/getSize.sql | 3 | ||||
-rw-r--r-- | p2pvr/daemon/sql/storage/getVideoStats.sql | 6 | ||||
-rw-r--r-- | p2pvr/daemon/storage.cpp | 15 | ||||
-rw-r--r-- | p2pvr/daemon/storage.h | 2 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/testStorage.cpp | 16 | ||||
-rw-r--r-- | p2pvr/ice/p2pvr.ice | 8 |
6 files changed, 36 insertions, 14 deletions
diff --git a/p2pvr/daemon/sql/storage/getSize.sql b/p2pvr/daemon/sql/storage/getSize.sql deleted file mode 100644 index 1427d02..0000000 --- a/p2pvr/daemon/sql/storage/getSize.sql +++ /dev/null @@ -1,3 +0,0 @@ -SELECT SUM(LENGTH(videodata)) -FROM recordedvideo -WHERE recordingid = ? diff --git a/p2pvr/daemon/sql/storage/getVideoStats.sql b/p2pvr/daemon/sql/storage/getVideoStats.sql new file mode 100644 index 0000000..e00cc0c --- /dev/null +++ b/p2pvr/daemon/sql/storage/getVideoStats.sql @@ -0,0 +1,6 @@ +SELECT r.recordingId, SUM(LENGTH(rv.videodata)) totalSize, COUNT(rv.recordingid) fragments +FROM recordings r + LEFT OUTER JOIN recordedvideo rv + ON r.recordingId = rv.recordingId +WHERE r.recordingid = ? +GROUP BY r.recordingId diff --git a/p2pvr/daemon/storage.cpp b/p2pvr/daemon/storage.cpp index 844623f..ba5d931 100644 --- a/p2pvr/daemon/storage.cpp +++ b/p2pvr/daemon/storage.cpp @@ -1,7 +1,7 @@ #include "storage.h" #include "muxer.h" #include <logger.h> -#include <sql/storage/getSize.sql.h> +#include <sql/storage/getVideoStats.sql.h> #include <sql/storage/writeBlock.sql.h> namespace po = boost::program_options; @@ -70,13 +70,14 @@ StorageI::Close(const RawDataClientPrx & file, const Ice::Current & ice) } } -Ice::Long -StorageI::GetSize(Ice::Int recordingId, const Ice::Current &) +VideoStats +StorageI::GetVideoStats(Ice::Int recordingId, const Ice::Current &) { - // Handles video not existing - auto size = fetch<IceUtil::Optional<Ice::Long>>(sql::storage::getSize, recordingId); - if (size) return *size; - return 0; + auto stats = fetch<IceUtil::Optional<VideoStats>>(sql::storage::getVideoStats, recordingId); + if (!stats) { + throw NotFound(); + } + return *stats; } } diff --git a/p2pvr/daemon/storage.h b/p2pvr/daemon/storage.h index 48d3b57..305fb68 100644 --- a/p2pvr/daemon/storage.h +++ b/p2pvr/daemon/storage.h @@ -27,7 +27,7 @@ class DLL_PUBLIC StorageI : public Storage, IceTray::AbstractDatabaseClient { RawDataClientPrx OpenForWrite(Ice::Int recordingId, const Ice::Current &) override; void Close(const RawDataClientPrx &, const Ice::Current &) override; - Ice::Long GetSize(Ice::Int recordingId, const Ice::Current &) override; + VideoStats GetVideoStats(Ice::Int recordingId, const Ice::Current &) override; protected: std::map<Ice::Identity, Ice::Identity> muxerStorageLink; diff --git a/p2pvr/daemon/unittests/testStorage.cpp b/p2pvr/daemon/unittests/testStorage.cpp index 5083848..e7eee95 100644 --- a/p2pvr/daemon/unittests/testStorage.cpp +++ b/p2pvr/daemon/unittests/testStorage.cpp @@ -42,6 +42,10 @@ runTest(RecordingsPrx recordings, StoragePrx storage) auto id = recordings->NewRecording(new Recording(0, 8, 2556)); auto rdc = storage->OpenForWrite(id); BOOST_REQUIRE(rdc); + auto stats1 = storage->GetVideoStats(id); + BOOST_REQUIRE_EQUAL(id, stats1.RecordingId); + BOOST_REQUIRE_EQUAL(0, stats1.TotalSize); + BOOST_REQUIRE_EQUAL(0, stats1.Fragments); Data data; data.resize(1024); @@ -50,10 +54,18 @@ runTest(RecordingsPrx recordings, StoragePrx storage) storage->Close(rdc); - BOOST_REQUIRE_EQUAL(1024, storage->GetSize(id)); + auto stats2 = storage->GetVideoStats(id); + BOOST_REQUIRE_EQUAL(id, stats2.RecordingId); + BOOST_REQUIRE_EQUAL(1024, stats2.TotalSize); + BOOST_REQUIRE_EQUAL(1, stats2.Fragments); recordings->DeleteRecording(id); - BOOST_REQUIRE_EQUAL(0, storage->GetSize(id)); + BOOST_REQUIRE_THROW(storage->GetVideoStats(id), NotFound); +} + +BOOST_AUTO_TEST_CASE( not_found ) +{ + BOOST_REQUIRE_THROW(storage->GetVideoStats(1), NotFound); } BOOST_AUTO_TEST_CASE( st_openWriteCloseMuxWithCat ) diff --git a/p2pvr/ice/p2pvr.ice b/p2pvr/ice/p2pvr.ice index ae263a2..566dd3c 100644 --- a/p2pvr/ice/p2pvr.ice +++ b/p2pvr/ice/p2pvr.ice @@ -61,10 +61,16 @@ module P2PVR { idempotent void UpdateEvents(); }; + struct VideoStats { + int RecordingId; + long TotalSize; + int Fragments; + }; + interface Storage { idempotent RawDataClient * OpenForWrite(int recordingId); idempotent void Close(RawDataClient * rdc); - idempotent long GetSize(int recordingId); + idempotent VideoStats GetVideoStats(int recordingId) throws NotFound; }; interface Recordings { |