Skip to content

Commit 901a956

Browse files
Work on creating a new data source structure
1 parent e45a168 commit 901a956

20 files changed

+1731
-1299
lines changed

YUViewLib/YUViewLib.pro

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ HEADERS += $$files(src/*.h, true)
1212
FORMS += $$files(ui/*.ui, false)
1313

1414
INCLUDEPATH += src/
15+
INCLUDEPATH += $$top_srcdir/submodules
1516

1617
RESOURCES += \
1718
images/images.qrc \

YUViewLib/src/common/FileInfo.h renamed to YUViewLib/src/common/InfoItemAndData.h

+5-17
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,14 @@
3737
#include <QString>
3838

3939
/*
40-
* An info item has a name, a text and an optional toolTip. These are used to show them in the
41-
* fileInfoWidget. For example: ["File Name", "file.yuv"] or ["Number Frames", "123"] Another option
42-
* is to show a button. If the user clicks on it, the callback function infoListButtonPressed() for
43-
* the corresponding playlist item is called.
40+
* An info item has a name, a text and an optional description. These are used to show them in the
41+
* fileInfoWidget. For example: ["File Name", "file.yuv"] or ["Number Frames", "123"].
4442
*/
4543
struct InfoItem
4644
{
47-
InfoItem(const QString &name,
48-
const QString &text,
49-
const QString &toolTip = QString(),
50-
bool button = false,
51-
int buttonID = -1)
52-
: name(name), text(text), button(button), buttonID(buttonID), toolTip(toolTip)
53-
{
54-
}
55-
QString name{};
56-
QString text{};
57-
bool button{};
58-
int buttonID{};
59-
QString toolTip{};
45+
std::string name{};
46+
std::string text{};
47+
std::string description{};
6048
};
6149

6250
struct InfoData
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/* This file is part of YUView - The YUV player with advanced analytics toolset
2+
* <https://github.com/IENT/YUView>
3+
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* In addition, as a special exception, the copyright holders give
11+
* permission to link the code of portions of this program with the
12+
* OpenSSL library under certain conditions as described in each
13+
* individual source file, and distribute linked combinations including
14+
* the two.
15+
*
16+
* You must obey the GNU General Public License in all respects for all
17+
* of the code used other than OpenSSL. If you modify file(s) with this
18+
* exception, you may extend this exception to your version of the
19+
* file(s), but you are not obligated to do so. If you do not wish to do
20+
* so, delete this exception statement from your version. If you delete
21+
* this exception statement from all source files in the program, then
22+
* also delete it here.
23+
*
24+
* This program is distributed in the hope that it will be useful,
25+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
* GNU General Public License for more details.
28+
*
29+
* You should have received a copy of the GNU General Public License
30+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
31+
*/
32+
33+
#include "DataSourceLocalFile.h"
34+
35+
DataSourceLocalFile::DataSourceLocalFile(const std::filesystem::path &filePath)
36+
{
37+
this->file.open(filePath.string(), std::ios_base::in | std::ios_base::binary);
38+
}
39+
40+
std::vector<InfoItem> DataSourceLocalFile::getInfoList() const
41+
{
42+
if (!this->isReady())
43+
return {};
44+
45+
std::vector<InfoItem> infoList;
46+
infoList.push_back(
47+
InfoItem({"File path", this->filePath.string(), "The absolute path of the local file"}));
48+
if (const auto size = this->fileSize())
49+
infoList.push_back(InfoItem({"File Size", std::to_string(*size)}));
50+
51+
return infoList;
52+
}
53+
54+
bool DataSourceLocalFile::atEnd() const
55+
{
56+
return this->file.eof();
57+
}
58+
59+
bool DataSourceLocalFile::isReady() const
60+
{
61+
return !this->file.fail();
62+
}
63+
64+
std::int64_t DataSourceLocalFile::position() const
65+
{
66+
return this->filePosition;
67+
}
68+
69+
std::optional<std::int64_t> DataSourceLocalFile::fileSize() const
70+
{
71+
if (!this->isFileOpened)
72+
return {};
73+
74+
const auto size = std::filesystem::file_size(this->filePath);
75+
return static_cast<std::int64_t>(size);
76+
}
77+
78+
bool DataSourceLocalFile::seek(const std::int64_t pos)
79+
{
80+
if (!this->isReady())
81+
return false;
82+
83+
this->file.seekg(static_cast<std::streampos>(pos));
84+
return this->isReady();
85+
}
86+
87+
std::int64_t DataSourceLocalFile::read(ByteVector &buffer, const std::int64_t nrBytes)
88+
{
89+
if (!this->isReady())
90+
return 0;
91+
92+
const auto usize = static_cast<size_t>(nrBytes);
93+
if (buffer.size() < nrBytes)
94+
buffer.resize(usize);
95+
96+
this->file.read(reinterpret_cast<char *>(buffer.data()), usize);
97+
98+
const auto bytesRead = this->file.gcount();
99+
100+
this->filePosition += bytesRead;
101+
return static_cast<std::int64_t>(bytesRead);
102+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* This file is part of YUView - The YUV player with advanced analytics toolset
2+
* <https://github.com/IENT/YUView>
3+
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* In addition, as a special exception, the copyright holders give
11+
* permission to link the code of portions of this program with the
12+
* OpenSSL library under certain conditions as described in each
13+
* individual source file, and distribute linked combinations including
14+
* the two.
15+
*
16+
* You must obey the GNU General Public License in all respects for all
17+
* of the code used other than OpenSSL. If you modify file(s) with this
18+
* exception, you may extend this exception to your version of the
19+
* file(s), but you are not obligated to do so. If you do not wish to do
20+
* so, delete this exception statement from your version. If you delete
21+
* this exception statement from all source files in the program, then
22+
* also delete it here.
23+
*
24+
* This program is distributed in the hope that it will be useful,
25+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
* GNU General Public License for more details.
28+
*
29+
* You should have received a copy of the GNU General Public License
30+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
31+
*/
32+
33+
#pragma once
34+
35+
#include "IDataSource.h"
36+
37+
#include <filesystem>
38+
#include <fstream>
39+
40+
class DataSourceLocalFile : public IDataSource
41+
{
42+
public:
43+
DataSourceLocalFile(const std::filesystem::path &filePath);
44+
45+
virtual [[nodiscard]] std::vector<InfoItem> getInfoList() const override;
46+
virtual [[nodiscard]] bool atEnd() const override;
47+
virtual [[nodiscard]] bool isReady() const override;
48+
virtual [[nodiscard]] std::int64_t position() const override;
49+
virtual [[nodiscard]] std::optional<std::int64_t> fileSize() const;
50+
51+
virtual [[nodiscard]] bool seek(const std::int64_t pos) override;
52+
virtual [[nodiscard]] std::int64_t read(ByteVector &buffer, const std::int64_t nrBytes) override;
53+
54+
protected:
55+
std::filesystem::path filePath{};
56+
bool isFileOpened{};
57+
58+
std::ifstream file{};
59+
std::int64_t filePosition{};
60+
};

0 commit comments

Comments
 (0)