FFmpegfs Fuse Multi Media Filesystem 2.16
vcdinfo.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017-2024 Norbert Schlia (nschlia@oblivion-software.de)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
30#include "ffmpegfs.h"
31#include "vcdinfo.h"
32#include "vcdutils.h"
33
34#include <arpa/inet.h>
35#include <string>
36#include <cstring>
37#include <sys/stat.h>
38
42typedef struct VCDINFO
43{
44#pragma pack(1)
45
51 std::array<char, 8> m_ID;
58 char m_type;
71 std::array<char, 16> m_albumid;
89 std::array<char, 98> m_palflags;
90
91 // reserved1:
92 // restriction:
93 // special info:
94 // user data cc:
95 // start lid #2:
96 // start track #2:
97 // reserved2:
98 // psd size:
99 // first segment addr:
100 // offset multiplier:
101 // maximum lid:
102 // maximum segment number:
103 // SEGMENT[1]: audio: video:
104 // volume start time[0]:
105 // ...
106
108typedef const VCDINFO * LPCVCDINFO;
110static_assert(sizeof(VCDINFO) == 128);
111
113{
114 clear();
115}
116
118{
119 m_disk_path.clear();
120 m_file_date = -1;
121 m_id.clear();
124 m_album_id.clear();
125 m_number_of_cds = 0;
126 m_cd_number = 0;
127}
128
129int VcdInfo::load_file(const std::string & path)
130{
131 std::string fullname;
132 bool is_svcd = false;
133
134 clear();
135
136 if (!VCDUTILS::locate_file(path, "INFO", fullname, is_svcd))
137 {
138 return errno;
139 }
140
142
143 FILE *fpi;
144 VCDINFO vi;
145 bool success = true;
146
147 fpi = fopen(fullname.c_str(), "rb");
148 if (fpi == nullptr)
149 {
150 return errno;
151 }
152
153 struct stat stbuf;
154
155 if (fstat(fileno(fpi), &stbuf) != 0)
156 {
157 return ferror(fpi);
158 }
159
160 m_file_date = stbuf.st_mtime;
161
162 std::memset(&vi, 0, sizeof(vi));
163
164 if (fread(reinterpret_cast<char *>(&vi), 1, sizeof(vi), fpi) == sizeof(vi))
165 {
166 m_id = VCDUTILS::convert_txt2string(vi.m_ID.data(), vi.m_ID.size());
167 m_type = static_cast<VCDTYPE>(vi.m_type);
168 m_profile_tag = static_cast<VCDPROFILETAG>(vi.m_profile_tag);
170 m_number_of_cds = htons(static_cast<uint16_t>(vi.m_numberof_cds));
171 m_cd_number = htons(static_cast<uint16_t>(vi.m_cd_number));
172 }
173 else
174 {
175 success = false;
176 }
177
178 int orgerrno = 0;
179
180 if (success)
181 {
182 orgerrno = ferror(fpi);
183 }
184
185 fclose(fpi);
186
187 return orgerrno;
188}
189
190const time_t &VcdInfo::get_file_date() const
191{
192 return m_file_date;
193}
194
195const std::string & VcdInfo::get_id() const
196{
197 return m_id;
198}
199
201{
202 return m_type;
203}
204
205std::string VcdInfo::get_type_str() const
206{
208}
209
211{
212 return m_profile_tag;
213}
214
216{
218}
219
220const std::string & VcdInfo::get_album_id() const
221{
222 return m_album_id;
223}
224
226{
227 return m_number_of_cds;
228}
229
231{
232 return m_cd_number;
233}
int load_file(const std::string &path)
Load VCD from path.
Definition: vcdinfo.cc:129
VCDPROFILETAG m_profile_tag
System profile tag.
Definition: vcdinfo.h:77
std::string get_type_str() const
Get disk type as string.
Definition: vcdinfo.cc:205
VcdInfo()
Construct VcdInfo object.
Definition: vcdinfo.cc:112
const std::string & get_id() const
Get disk ID.
Definition: vcdinfo.cc:195
int m_number_of_cds
Number of CDs in set.
Definition: vcdinfo.h:80
VCDPROFILETAG get_profile_tag() const
Get disk profile tag.
Definition: vcdinfo.cc:210
VCDTYPE get_type() const
Get disk type.
Definition: vcdinfo.cc:200
std::string m_id
ID of this CD.
Definition: vcdinfo.h:75
std::string m_album_id
Album ID.
Definition: vcdinfo.h:79
int m_cd_number
Number of this CD in set.
Definition: vcdinfo.h:81
void clear()
Reset this object.
Definition: vcdinfo.cc:117
VCDTYPE m_type
Type of CD.
Definition: vcdinfo.h:76
const time_t & get_file_date() const
Date of disk (of INFO.VCD or SVD)
Definition: vcdinfo.cc:190
int get_cd_number() const
Get CD number in set.
Definition: vcdinfo.cc:230
time_t m_file_date
File date.
Definition: vcdinfo.h:74
const std::string & get_album_id() const
Get album ID.
Definition: vcdinfo.cc:220
int get_number_of_cds() const
Get number of CDs in set.
Definition: vcdinfo.cc:225
std::string m_disk_path
Path to disk.
Definition: vcdinfo.h:73
std::string get_profile_tag_str() const
Get disk profile tag as string.
Definition: vcdinfo.cc:215
Main include for FFmpegfs project.
bool locate_file(const std::string &path, const std::string &filename, std::string &fullname, bool &is_vcd)
Check if path is a S/VCD.
Definition: vcdutils.cc:64
std::string convert_txt2string(const char *txt, int size, bool trimmed)
Non-zero terminated text is converted to std::string.
Definition: vcdutils.cc:41
void get_directory(const std::string &fullname, std::string *directory)
Check if fullname is a directory. Remove the filename if necessary.
Definition: vcdutils.cc:151
std::string get_type_str(VCDTYPE type)
Return disk type as a human readable string.
Definition: vcdutils.cc:111
std::string get_profile_tag_str(VCDPROFILETAG tag)
Profile as a human readable string.
Definition: vcdutils.cc:132
VCDINFO structure of INFO.VCD/SVD file.
Definition: vcdinfo.cc:43
std::array< char, 16 > m_albumid
16 Byte: Album ID
Definition: vcdinfo.cc:71
short m_cd_number
2 Byte: Number of this CD
Definition: vcdinfo.cc:83
std::array< char, 98 > m_palflags
98 Byte: PAL Flags
Definition: vcdinfo.cc:89
char m_profile_tag
1 Byte: System profile tag
Definition: vcdinfo.cc:65
char m_type
1 Byte: CD type
Definition: vcdinfo.cc:58
short m_numberof_cds
2 Byte: Number of CDs in set
Definition: vcdinfo.cc:77
std::array< char, 8 > m_ID
8 Byte: ID for this CD
Definition: vcdinfo.cc:51
VCDTYPE
Definition: vcdchapter.h:40
@ UNKNOWN
unknown type
VCDPROFILETAG
Definition: vcdchapter.h:50
@ UNKNOWN
unknown file tag
struct VCDINFO VCDINFO
VCDINFO structure of INFO.VCD/SVD file.
const VCDINFO * LPCVCDINFO
Pointer to const version of VCDINFO.
Definition: vcdinfo.cc:108
struct VCDINFO * LPVCDINFO
Pointer version of VCDINFO.
S/VCD VcdInfo class.
S/VCD utility functions.