-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfilereader.cpp
63 lines (45 loc) · 1.1 KB
/
filereader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "filereader.h"
#include "flvparser.h"
#include <fstream>
#include <iostream>
#include <thread>
#include <memory>
using namespace std;
thread * file_load_thread = nullptr;
namespace {
const int MAX_BUF_LEN = 4096;
}
void load_file_loop(shared_ptr<ifstream> ifs_ptr)
{
ifstream & ifs = *ifs_ptr;
char c[MAX_BUF_LEN] = { 0 };
// "FLV"
ifs.read(c, 3);
// Version
ifs.read(c, 1);
// TypeFlags
ifs.read(c, 1);
// DataOffset
ifs.read(c, 4);
for (int i = 0; true; i++)
{
bool pasre_ret = parse_body(ifs);
if (!pasre_ret)
{
cout << "all parse over" << endl;
break;
}
}
}
int load_file(const std::string & filename)
{
shared_ptr<ifstream> ifs_ptr(new ifstream(filename, ios_base::in | ios_base::binary));
ifstream & ifs = *ifs_ptr;
if (!ifs.is_open())
{
cerr << " can not open file " << filename << endl;
return -1;
}
file_load_thread = new thread(std::bind(load_file_loop, ifs_ptr));
return 0;
}