From 575f818b0bce3a6dc571e970c546ae4d02660e02 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 2 Aug 2017 19:52:03 +0100 Subject: Provide more comprehensive video stats, not just size --- p2pvr/daemon/sql/storage/getSize.sql | 3 --- p2pvr/daemon/sql/storage/getVideoStats.sql | 6 ++++++ p2pvr/daemon/storage.cpp | 15 ++++++++------- p2pvr/daemon/storage.h | 2 +- p2pvr/daemon/unittests/testStorage.cpp | 16 ++++++++++++++-- p2pvr/ice/p2pvr.ice | 8 +++++++- 6 files changed, 36 insertions(+), 14 deletions(-) delete mode 100644 p2pvr/daemon/sql/storage/getSize.sql create mode 100644 p2pvr/daemon/sql/storage/getVideoStats.sql 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 -#include +#include #include 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>(sql::storage::getSize, recordingId); - if (size) return *size; - return 0; + auto stats = fetch>(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 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 { -- cgit v1.2.3