1 #include "library/filesystem.hpp"
2 #include "library/serialization.hpp"
3 #include "library/string.hpp"
6 struct stream_statistics
10 size
= length
= packets
= clusters
= 0;
12 stream_statistics
operator+(const stream_statistics
& s
) const
15 r
.size
= size
+ s
.size
;
16 r
.length
= length
+ s
.length
;
17 r
.packets
= packets
+ s
.packets
;
18 r
.clusters
= clusters
+ s
.clusters
;
21 stream_statistics
& operator+=(const stream_statistics
& s
)
32 stream_statistics
dump_stream(filesystem
& fs
, uint32_t ccluster
, uint32_t dcluster
)
35 uint32_t ctrl_c
= ccluster
;
37 uint32_t data_c
= dcluster
;
41 uint32_t ctrl_uc
= ctrl_c
;
42 uint32_t ctrl_uo
= ctrl_o
;
43 uint32_t data_uc
= data_c
;
44 uint32_t data_uo
= data_o
;
46 size_t r
= fs
.read_data(ctrl_c
, ctrl_o
, buffer
, 4);
49 uint16_t psize
= serialization::u16b(buffer
+ 0);
50 uint16_t plength
= 120 * serialization::u8b(buffer
+ 2);
51 if(!serialization::u8b(buffer
+ 3))
53 r
= fs
.skip_data(data_c
, data_o
, psize
);
55 (stringfmt() << "Unexpected end of data, read " << r
<< " bytes, expected "
64 std::cout
<< "\tPacket: " << psize
<< " bytes@" << data_uc
<< ":" << data_uo
<< "(" << ctrl_uc
65 << ":" << ctrl_uo
<< "), " << plength
<< " samples." << std::endl
;
67 std::cout
<< "\tTotal of " << ss
.size
<< " bytes in " << ss
.packets
<< " packets, " << ss
.length
68 << " samples" << " (" << ss
.clusters
<< " clusters used)" << std::endl
;
72 int main(int argc
, char** argv
)
76 std::cerr
<< "Syntax: lsvsdump <filename>" << std::endl
;
80 uint64_t stream_count
= 0;
82 fs
= new filesystem(argv
[1]);
83 } catch(std::exception
& e
) {
84 std::cerr
<< "Can't load .lsvs file '" << argv
[1] << "': " << e
.what() << std::endl
;
88 uint32_t maindir_c
= 2;
89 uint32_t maindir_o
= 0;
94 maindir_uc
= maindir_c
;
95 maindir_uo
= maindir_o
;
97 size_t r
= fs
->read_data(maindir_c
, maindir_o
, buffer
, 16);
100 uint64_t stream_ts
= serialization::u64b(buffer
);
101 uint32_t stream_c
= serialization::u32b(buffer
+ 8);
102 uint32_t stream_d
= serialization::u32b(buffer
+ 12);
105 std::cout
<< "Found stream (from " << maindir_uc
<< ":" << maindir_uo
<< "): ts=" << stream_ts
106 << ", cluster=" << stream_c
<< "/" << stream_d
<< std::endl
;
107 auto ss2
= dump_stream(*fs
, stream_c
, stream_d
);
110 if(maindir_c
!= maindir_uc
)
113 } catch(std::exception
& e
) {
114 std::cerr
<< "Error reading .lsvs file '" << argv
[1] << "': " << e
.what() << std::endl
;
117 std::cout
<< "Totals: " << ss
.size
<< " bytes in " << ss
.packets
<< " packets in " << stream_count
<<
118 " streams, totalling " << ss
.length
<< " samples. " << ss
.clusters
<< " clusters used." << std::endl
;