From ad4beac464f6275bf78ce5b8d6958d9e7f232f36 Mon Sep 17 00:00:00 2001 From: Scott Lamb Date: Sun, 31 Jan 2016 21:16:33 -0800 Subject: [PATCH] clang-format-3.7 --style=Google -i. --- CMakeLists.txt | 3 --- src/CMakeLists.txt | 7 +++--- src/moonfire-db.cc | 54 +++++++++++++++++++++++++++++++++++----------- src/moonfire-db.h | 13 ++++++++++- src/web.cc | 3 +-- 5 files changed, 58 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b9f74d..e6316e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,9 +46,6 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb") # Dependencies. # -# https://cmake.org/cmake/help/v3.0/module/FindProtobuf.html -find_package(Protobuf REQUIRED) - # https://gflags.github.io/gflags/#cmake mentions a cmake module, but at # least on Ubuntu 15.10, libgflags-dev does not include it. There's no # pkgconfig either. Do this by hand. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ccedc8a..6941d97 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,16 +28,15 @@ # along with this program. If not, see . include_directories(${CMAKE_CURRENT_BINARY_DIR}) -PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS config.protodevel) - +find_package(Threads REQUIRED) set(MOONFIRE_DEPS + ${CMAKE_THREAD_LIBS_INIT} ${FFMPEG_LIBRARIES} ${LIBEVENT_LIBRARIES} ${GFLAGS_LIBRARIES} ${GLOG_LIBRARIES} ${OPENSSL_LIBRARIES} ${PROFILER_LIBRARIES} - ${PROTOBUF_LIBRARIES} ${RE2_LIBRARIES} ${SQLITE_LIBRARIES} ${UUID_LIBRARIES}) @@ -60,7 +59,7 @@ set(MOONFIRE_NVR_SRCS uuid.cc web.cc) -add_library(moonfire-nvr-lib ${MOONFIRE_NVR_SRCS} ${PROTO_SRCS} ${PROTO_HDRS}) +add_library(moonfire-nvr-lib ${MOONFIRE_NVR_SRCS}) target_link_libraries(moonfire-nvr-lib ${MOONFIRE_DEPS}) add_executable(moonfire-nvr moonfire-nvr-main.cc) diff --git a/src/moonfire-db.cc b/src/moonfire-db.cc index 7e77a39..83dc04f 100644 --- a/src/moonfire-db.cc +++ b/src/moonfire-db.cc @@ -59,6 +59,11 @@ bool MoonfireDatabase::Init(Database *db, std::string *error_message) { camera.uuid, camera.short_name, camera.description, + camera.host, + camera.username, + camera.password, + camera.main_rtsp_path, + camera.sub_rtsp_path, camera.retain_bytes, min(recording.start_time_90k), max(recording.start_time_90k + recording.duration_90k), @@ -80,21 +85,26 @@ bool MoonfireDatabase::Init(Database *db, std::string *error_message) { Uuid uuid; if (!uuid.ParseBinary(list_cameras_run.ColumnBlob(1))) { *error_message = - StrCat("bad uuid ", ToHex(list_cameras_run.ColumnBlob(2)), + StrCat("bad uuid ", ToHex(list_cameras_run.ColumnBlob(1)), " for camera id ", data.id); return false; } data.short_name = list_cameras_run.ColumnText(2).as_string(); data.description = list_cameras_run.ColumnText(3).as_string(); - data.retain_bytes = list_cameras_run.ColumnInt64(4); - data.min_start_time_90k = list_cameras_run.ColumnType(5) == SQLITE_NULL + data.host = list_cameras_run.ColumnText(4).as_string(); + data.username = list_cameras_run.ColumnText(5).as_string(); + data.password = list_cameras_run.ColumnText(6).as_string(); + data.main_rtsp_path = list_cameras_run.ColumnText(7).as_string(); + data.sub_rtsp_path = list_cameras_run.ColumnText(8).as_string(); + data.retain_bytes = list_cameras_run.ColumnInt64(9); + data.min_start_time_90k = list_cameras_run.ColumnType(10) == SQLITE_NULL ? -1 - : list_cameras_run.ColumnInt64(5); - data.max_end_time_90k = list_cameras_run.ColumnType(6) == SQLITE_NULL + : list_cameras_run.ColumnInt64(10); + data.max_end_time_90k = list_cameras_run.ColumnType(11) == SQLITE_NULL ? -1 - : list_cameras_run.ColumnInt64(6); - data.total_duration_90k = list_cameras_run.ColumnInt64(7); - data.total_sample_file_bytes = list_cameras_run.ColumnInt64(8); + : list_cameras_run.ColumnInt64(11); + data.total_duration_90k = list_cameras_run.ColumnInt64(12); + data.total_sample_file_bytes = list_cameras_run.ColumnInt64(13); auto ret = cameras_by_uuid_.insert(std::make_pair(uuid, data)); if (!ret.second) { @@ -307,9 +317,15 @@ void MoonfireDatabase::ListCameras( DatabaseContext ctx(db_); ListCamerasRow row; for (const auto &entry : cameras_by_uuid_) { + row.id = entry.second.id; row.uuid = entry.first; row.short_name = entry.second.short_name; row.description = entry.second.description; + row.host = entry.second.host; + row.username = entry.second.username; + row.password = entry.second.password; + row.main_rtsp_path = entry.second.main_rtsp_path; + row.sub_rtsp_path = entry.second.sub_rtsp_path; row.retain_bytes = entry.second.retain_bytes; row.min_start_time_90k = entry.second.min_start_time_90k; row.max_end_time_90k = entry.second.max_end_time_90k; @@ -547,11 +563,10 @@ std::vector MoonfireDatabase::ReserveSampleFiles( if (n == 0) { return std::vector(); } - auto *gen = GetRealUuidGenerator(); std::vector uuids; uuids.reserve(n); for (int i = 0; i < n; ++i) { - uuids.push_back(gen->Generate()); + uuids.push_back(GetRealUuidGenerator->Generate()); } DatabaseContext ctx(db_); if (!ctx.BeginTransaction(error_message)) { @@ -601,7 +616,10 @@ bool MoonfireDatabase::InsertVideoSampleEntry(VideoSampleEntry *entry, insert_run.BindInt64(":height", entry->height); insert_run.BindBlob(":data", entry->data); if (insert_run.Step() != SQLITE_DONE) { - *error_message = insert_run.error_message(); + *error_message = + StrCat("insert video sample entry: ", insert_run.error_message(), + ": sha1=", ToHex(entry->sha1), ", dimensions=", entry->width, + "x", entry->height, ", data=", ToHex(entry->data)); return false; } entry->id = ctx.last_insert_rowid(); @@ -660,7 +678,19 @@ bool MoonfireDatabase::InsertRecording(Recording *recording, insert_run.BindBlob(":sample_file_sha1", recording->sample_file_sha1); insert_run.BindBlob(":video_index", recording->video_index); if (insert_run.Step() != SQLITE_DONE) { - LOG(ERROR) << "insert_run failed: " << insert_run.error_message(); + LOG(ERROR) << "insert_run failed: " << insert_run.error_message() + << ", camera_id=" << recording->camera_id + << ", sample_file_bytes=" << recording->sample_file_bytes + << ", start_time_90k=" << recording->start_time_90k + << ", duration_90k=" + << recording->end_time_90k - recording->start_time_90k + << ", video_samples=" << recording->video_samples + << ", video_sync_samples=" << recording->video_sync_samples + << ", video_sample_entry_id=" << recording->video_sample_entry_id + << ", sample_file_uuid=" + << recording->sample_file_uuid.UnparseText() + << ", sample_file_sha1=" << ToHex(recording->sample_file_sha1) + << ", video_index length " << recording->video_index.size(); *error_message = insert_run.error_message(); ctx.RollbackTransaction(); return false; diff --git a/src/moonfire-db.h b/src/moonfire-db.h index 4b020e4..1c8d36c 100644 --- a/src/moonfire-db.h +++ b/src/moonfire-db.h @@ -75,9 +75,15 @@ namespace moonfire_nvr { // For use with MoonfireDatabase::ListCameras. struct ListCamerasRow { + int64_t id = -1; Uuid uuid; std::string short_name; std::string description; + std::string host; + std::string username; + std::string password; + std::string main_rtsp_path; + std::string sub_rtsp_path; int64_t retain_bytes = -1; // Aggregates summarizing completed recordings. @@ -209,6 +215,11 @@ class MoonfireDatabase { int64_t id = -1; std::string short_name; std::string description; + std::string host; + std::string username; + std::string password; + std::string main_rtsp_path; + std::string sub_rtsp_path; int64_t retain_bytes = -1; // Aggregates of all recordings associated with the camera. @@ -226,7 +237,7 @@ class MoonfireDatabase { int64_t *max_end_time_90k, std::string *error_message); - Database *db_ = nullptr; + Environment *env_ = nullptr; Statement list_camera_recordings_stmt_; Statement build_mp4_stmt_; Statement insert_reservation_stmt_; diff --git a/src/web.cc b/src/web.cc index 3c5e9a3..0206430 100644 --- a/src/web.cc +++ b/src/web.cc @@ -137,8 +137,7 @@ void WebInterface::HandleCameraDetail(evhttp_request *req, void *arg) { // Rather than listing each 60-second recording, generate a HTML row for // aggregated .mp4 files of up to kForceSplitDuration90k each, provided // there is no gap or change in video parameters between recordings. - static const int64_t kForceSplitDuration90k = - 60 * 60 * kTimeUnitsPerSecond; + static const int64_t kForceSplitDuration90k = 60 * 60 * kTimeUnitsPerSecond; ListCameraRecordingsRow aggregated; auto maybe_finish_html_row = [&]() { if (aggregated.start_time_90k == -1) {