正在显示
13 个修改的文件
包含
165 行增加
和
119 行删除
@@ -121,14 +121,14 @@ int process(const char* in_flv_file, const char* out_flv_file, srs_flv_t* pic, s | @@ -121,14 +121,14 @@ int process(const char* in_flv_file, const char* out_flv_file, srs_flv_t* pic, s | ||
121 | srs_amf0_t amf0_data = NULL; | 121 | srs_amf0_t amf0_data = NULL; |
122 | srs_amf0_t filepositions = NULL; | 122 | srs_amf0_t filepositions = NULL; |
123 | 123 | ||
124 | - if ((ic = srs_flv_open_read(in_flv_file)) == NULL) { | 124 | + if ((ic = srs_flv_open(in_flv_file)) == NULL) { |
125 | ret = 2; | 125 | ret = 2; |
126 | trace("open input flv file failed. ret=%d", ret); | 126 | trace("open input flv file failed. ret=%d", ret); |
127 | return ret; | 127 | return ret; |
128 | } | 128 | } |
129 | *pic = ic; | 129 | *pic = ic; |
130 | 130 | ||
131 | - if ((oc = srs_flv_open_write(out_flv_file)) == NULL) { | 131 | + if ((oc = srs_flv_open(out_flv_file)) == NULL) { |
132 | ret = 2; | 132 | ret = 2; |
133 | trace("open output flv file failed. ret=%d", ret); | 133 | trace("open output flv file failed. ret=%d", ret); |
134 | return ret; | 134 | return ret; |
@@ -64,7 +64,7 @@ int main(int argc, char** argv) | @@ -64,7 +64,7 @@ int main(int argc, char** argv) | ||
64 | trace("version: %d.%d.%d", srs_version_major(), srs_version_minor(), srs_version_revision()); | 64 | trace("version: %d.%d.%d", srs_version_major(), srs_version_minor(), srs_version_revision()); |
65 | trace("input: %s", in_flv_file); | 65 | trace("input: %s", in_flv_file); |
66 | 66 | ||
67 | - if ((flv = srs_flv_open_read(in_flv_file)) == NULL) { | 67 | + if ((flv = srs_flv_open(in_flv_file)) == NULL) { |
68 | ret = 2; | 68 | ret = 2; |
69 | trace("open flv file failed. ret=%d", ret); | 69 | trace("open flv file failed. ret=%d", ret); |
70 | return ret; | 70 | return ret; |
@@ -93,7 +93,7 @@ int main(int argc, char** argv) | @@ -93,7 +93,7 @@ int main(int argc, char** argv) | ||
93 | trace("input: %s", in_flv_file); | 93 | trace("input: %s", in_flv_file); |
94 | trace("output: %s", out_rtmp_url); | 94 | trace("output: %s", out_rtmp_url); |
95 | 95 | ||
96 | - if ((flv = srs_flv_open_read(in_flv_file)) == NULL) { | 96 | + if ((flv = srs_flv_open(in_flv_file)) == NULL) { |
97 | ret = 2; | 97 | ret = 2; |
98 | trace("open flv file failed. ret=%d", ret); | 98 | trace("open flv file failed. ret=%d", ret); |
99 | return ret; | 99 | return ret; |
@@ -71,7 +71,7 @@ SrsDvrPlan::SrsDvrPlan() | @@ -71,7 +71,7 @@ SrsDvrPlan::SrsDvrPlan() | ||
71 | _req = NULL; | 71 | _req = NULL; |
72 | jitter = NULL; | 72 | jitter = NULL; |
73 | dvr_enabled = false; | 73 | dvr_enabled = false; |
74 | - fs = new SrsFileStream(); | 74 | + fs = new SrsFileWriter(); |
75 | enc = new SrsFlvEncoder(); | 75 | enc = new SrsFlvEncoder(); |
76 | segment = new SrsFlvSegment(); | 76 | segment = new SrsFlvSegment(); |
77 | jitter_algorithm = SrsRtmpJitterAlgorithmOFF; | 77 | jitter_algorithm = SrsRtmpJitterAlgorithmOFF; |
@@ -283,7 +283,7 @@ int SrsDvrPlan::flv_open(string stream, string path) | @@ -283,7 +283,7 @@ int SrsDvrPlan::flv_open(string stream, string path) | ||
283 | segment->reset(); | 283 | segment->reset(); |
284 | 284 | ||
285 | std::string tmp_file = path + ".tmp"; | 285 | std::string tmp_file = path + ".tmp"; |
286 | - if ((ret = fs->open_write(tmp_file)) != ERROR_SUCCESS) { | 286 | + if ((ret = fs->open(tmp_file)) != ERROR_SUCCESS) { |
287 | srs_error("open file stream for file %s failed. ret=%d", path.c_str(), ret); | 287 | srs_error("open file stream for file %s failed. ret=%d", path.c_str(), ret); |
288 | return ret; | 288 | return ret; |
289 | } | 289 | } |
@@ -569,8 +569,8 @@ int SrsDvrHssPlan::on_meta_data(SrsOnMetaDataPacket* metadata) | @@ -569,8 +569,8 @@ int SrsDvrHssPlan::on_meta_data(SrsOnMetaDataPacket* metadata) | ||
569 | << "/" << req->app << "/" | 569 | << "/" << req->app << "/" |
570 | << req->stream << ".header.flv"; | 570 | << req->stream << ".header.flv"; |
571 | 571 | ||
572 | - SrsFileStream fs; | ||
573 | - if ((ret = fs.open_write(path.str().c_str())) != ERROR_SUCCESS) { | 572 | + SrsFileWriter fs; |
573 | + if ((ret = fs.open(path.str().c_str())) != ERROR_SUCCESS) { | ||
574 | return ret; | 574 | return ret; |
575 | } | 575 | } |
576 | 576 |
@@ -39,7 +39,7 @@ class SrsStream; | @@ -39,7 +39,7 @@ class SrsStream; | ||
39 | class SrsRtmpJitter; | 39 | class SrsRtmpJitter; |
40 | class SrsOnMetaDataPacket; | 40 | class SrsOnMetaDataPacket; |
41 | class SrsSharedPtrMessage; | 41 | class SrsSharedPtrMessage; |
42 | -class SrsFileStream; | 42 | +class SrsFileWriter; |
43 | class SrsFlvEncoder; | 43 | class SrsFlvEncoder; |
44 | 44 | ||
45 | #include <srs_app_source.hpp> | 45 | #include <srs_app_source.hpp> |
@@ -114,7 +114,7 @@ protected: | @@ -114,7 +114,7 @@ protected: | ||
114 | SrsFlvSegment* segment; | 114 | SrsFlvSegment* segment; |
115 | SrsRequest* _req; | 115 | SrsRequest* _req; |
116 | bool dvr_enabled; | 116 | bool dvr_enabled; |
117 | - SrsFileStream* fs; | 117 | + SrsFileWriter* fs; |
118 | public: | 118 | public: |
119 | SrsDvrPlan(); | 119 | SrsDvrPlan(); |
120 | virtual ~SrsDvrPlan(); | 120 | virtual ~SrsDvrPlan(); |
@@ -300,10 +300,10 @@ int SrsHttpVhost::response_flv_file2(SrsSocket* skt, SrsHttpMessage* req, string | @@ -300,10 +300,10 @@ int SrsHttpVhost::response_flv_file2(SrsSocket* skt, SrsHttpMessage* req, string | ||
300 | { | 300 | { |
301 | int ret = ERROR_SUCCESS; | 301 | int ret = ERROR_SUCCESS; |
302 | 302 | ||
303 | - SrsFileStream fs; | 303 | + SrsFileReader fs; |
304 | 304 | ||
305 | // open flv file | 305 | // open flv file |
306 | - if ((ret = fs.open_read(fullpath)) != ERROR_SUCCESS) { | 306 | + if ((ret = fs.open(fullpath)) != ERROR_SUCCESS) { |
307 | return ret; | 307 | return ret; |
308 | } | 308 | } |
309 | 309 |
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
31 | // current release version | 31 | // current release version |
32 | #define VERSION_MAJOR "0" | 32 | #define VERSION_MAJOR "0" |
33 | #define VERSION_MINOR "9" | 33 | #define VERSION_MINOR "9" |
34 | -#define VERSION_REVISION "141" | 34 | +#define VERSION_REVISION "142" |
35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION | 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION |
36 | // server info. | 36 | // server info. |
37 | #define RTMP_SIG_SRS_KEY "SRS" | 37 | #define RTMP_SIG_SRS_KEY "SRS" |
@@ -37,17 +37,16 @@ using namespace std; | @@ -37,17 +37,16 @@ using namespace std; | ||
37 | #define SRS_FLV_TAG_HEADER_SIZE 11 | 37 | #define SRS_FLV_TAG_HEADER_SIZE 11 |
38 | #define SRS_FLV_PREVIOUS_TAG_SIZE 4 | 38 | #define SRS_FLV_PREVIOUS_TAG_SIZE 4 |
39 | 39 | ||
40 | -SrsFileStream::SrsFileStream() | 40 | +SrsFileWriter::SrsFileWriter() |
41 | { | 41 | { |
42 | - fd = -1; | ||
43 | } | 42 | } |
44 | 43 | ||
45 | -SrsFileStream::~SrsFileStream() | 44 | +SrsFileWriter::~SrsFileWriter() |
46 | { | 45 | { |
47 | close(); | 46 | close(); |
48 | } | 47 | } |
49 | 48 | ||
50 | -int SrsFileStream::open_write(string file) | 49 | +int SrsFileWriter::open(string file) |
51 | { | 50 | { |
52 | int ret = ERROR_SUCCESS; | 51 | int ret = ERROR_SUCCESS; |
53 | 52 | ||
@@ -71,28 +70,7 @@ int SrsFileStream::open_write(string file) | @@ -71,28 +70,7 @@ int SrsFileStream::open_write(string file) | ||
71 | return ret; | 70 | return ret; |
72 | } | 71 | } |
73 | 72 | ||
74 | -int SrsFileStream::open_read(string file) | ||
75 | -{ | ||
76 | - int ret = ERROR_SUCCESS; | ||
77 | - | ||
78 | - if (fd > 0) { | ||
79 | - ret = ERROR_SYSTEM_FILE_ALREADY_OPENED; | ||
80 | - srs_error("file %s already opened. ret=%d", _file.c_str(), ret); | ||
81 | - return ret; | ||
82 | - } | ||
83 | - | ||
84 | - if ((fd = ::open(file.c_str(), O_RDONLY)) < 0) { | ||
85 | - ret = ERROR_SYSTEM_FILE_OPENE; | ||
86 | - srs_error("open file %s failed. ret=%d", file.c_str(), ret); | ||
87 | - return ret; | ||
88 | - } | ||
89 | - | ||
90 | - _file = file; | ||
91 | - | ||
92 | - return ret; | ||
93 | -} | ||
94 | - | ||
95 | -void SrsFileStream::close() | 73 | +void SrsFileWriter::close() |
96 | { | 74 | { |
97 | int ret = ERROR_SUCCESS; | 75 | int ret = ERROR_SUCCESS; |
98 | 76 | ||
@@ -110,63 +88,99 @@ void SrsFileStream::close() | @@ -110,63 +88,99 @@ void SrsFileStream::close() | ||
110 | return; | 88 | return; |
111 | } | 89 | } |
112 | 90 | ||
113 | -bool SrsFileStream::is_open() | 91 | +bool SrsFileWriter::is_open() |
114 | { | 92 | { |
115 | return fd > 0; | 93 | return fd > 0; |
116 | } | 94 | } |
117 | 95 | ||
118 | -int SrsFileStream::read(void* buf, size_t count, ssize_t* pnread) | 96 | +int64_t SrsFileWriter::tellg() |
97 | +{ | ||
98 | + return (int64_t)::lseek(fd, 0, SEEK_CUR); | ||
99 | +} | ||
100 | + | ||
101 | +int SrsFileWriter::write(void* buf, size_t count, ssize_t* pnwrite) | ||
119 | { | 102 | { |
120 | int ret = ERROR_SUCCESS; | 103 | int ret = ERROR_SUCCESS; |
121 | 104 | ||
122 | - ssize_t nread; | ||
123 | - if ((nread = ::read(fd, buf, count)) < 0) { | ||
124 | - ret = ERROR_SYSTEM_FILE_READ; | ||
125 | - srs_error("read from file %s failed. ret=%d", _file.c_str(), ret); | 105 | + ssize_t nwrite; |
106 | + if ((nwrite = ::write(fd, buf, count)) < 0) { | ||
107 | + ret = ERROR_SYSTEM_FILE_WRITE; | ||
108 | + srs_error("write to file %s failed. ret=%d", _file.c_str(), ret); | ||
126 | return ret; | 109 | return ret; |
127 | } | 110 | } |
128 | 111 | ||
129 | - if (nread == 0) { | ||
130 | - ret = ERROR_SYSTEM_FILE_EOF; | 112 | + if (pnwrite != NULL) { |
113 | + *pnwrite = nwrite; | ||
114 | + } | ||
115 | + | ||
116 | + return ret; | ||
117 | +} | ||
118 | + | ||
119 | +SrsFileReader::SrsFileReader() | ||
120 | +{ | ||
121 | + fd = -1; | ||
122 | +} | ||
123 | + | ||
124 | +SrsFileReader::~SrsFileReader() | ||
125 | +{ | ||
126 | + close(); | ||
127 | +} | ||
128 | + | ||
129 | +int SrsFileReader::open(string file) | ||
130 | +{ | ||
131 | + int ret = ERROR_SUCCESS; | ||
132 | + | ||
133 | + if (fd > 0) { | ||
134 | + ret = ERROR_SYSTEM_FILE_ALREADY_OPENED; | ||
135 | + srs_error("file %s already opened. ret=%d", _file.c_str(), ret); | ||
131 | return ret; | 136 | return ret; |
132 | } | 137 | } |
133 | 138 | ||
134 | - if (pnread != NULL) { | ||
135 | - *pnread = nread; | 139 | + if ((fd = ::open(file.c_str(), O_RDONLY)) < 0) { |
140 | + ret = ERROR_SYSTEM_FILE_OPENE; | ||
141 | + srs_error("open file %s failed. ret=%d", file.c_str(), ret); | ||
142 | + return ret; | ||
136 | } | 143 | } |
137 | 144 | ||
145 | + _file = file; | ||
146 | + | ||
138 | return ret; | 147 | return ret; |
139 | } | 148 | } |
140 | 149 | ||
141 | -int SrsFileStream::write(void* buf, size_t count, ssize_t* pnwrite) | 150 | +void SrsFileReader::close() |
142 | { | 151 | { |
143 | int ret = ERROR_SUCCESS; | 152 | int ret = ERROR_SUCCESS; |
144 | 153 | ||
145 | - ssize_t nwrite; | ||
146 | - if ((nwrite = ::write(fd, buf, count)) < 0) { | ||
147 | - ret = ERROR_SYSTEM_FILE_WRITE; | ||
148 | - srs_error("write to file %s failed. ret=%d", _file.c_str(), ret); | ||
149 | - return ret; | 154 | + if (fd < 0) { |
155 | + return; | ||
150 | } | 156 | } |
151 | 157 | ||
152 | - if (pnwrite != NULL) { | ||
153 | - *pnwrite = nwrite; | 158 | + if (::close(fd) < 0) { |
159 | + ret = ERROR_SYSTEM_FILE_CLOSE; | ||
160 | + srs_error("close file %s failed. ret=%d", _file.c_str(), ret); | ||
161 | + return; | ||
154 | } | 162 | } |
163 | + fd = -1; | ||
155 | 164 | ||
156 | - return ret; | 165 | + return; |
157 | } | 166 | } |
158 | 167 | ||
159 | -int64_t SrsFileStream::tellg() | 168 | +int64_t SrsFileReader::tellg() |
160 | { | 169 | { |
161 | return (int64_t)::lseek(fd, 0, SEEK_CUR); | 170 | return (int64_t)::lseek(fd, 0, SEEK_CUR); |
162 | } | 171 | } |
163 | 172 | ||
164 | -int64_t SrsFileStream::lseek(int64_t offset) | 173 | +void SrsFileReader::skip(int64_t size) |
174 | +{ | ||
175 | + ::lseek(fd, size, SEEK_CUR); | ||
176 | +} | ||
177 | + | ||
178 | +int64_t SrsFileReader::lseek(int64_t offset) | ||
165 | { | 179 | { |
166 | return (int64_t)::lseek(fd, offset, SEEK_SET); | 180 | return (int64_t)::lseek(fd, offset, SEEK_SET); |
167 | } | 181 | } |
168 | 182 | ||
169 | -int64_t SrsFileStream::filesize() | 183 | +int64_t SrsFileReader::filesize() |
170 | { | 184 | { |
171 | int64_t cur = tellg(); | 185 | int64_t cur = tellg(); |
172 | int64_t size = (int64_t)::lseek(fd, 0, SEEK_END); | 186 | int64_t size = (int64_t)::lseek(fd, 0, SEEK_END); |
@@ -174,9 +188,27 @@ int64_t SrsFileStream::filesize() | @@ -174,9 +188,27 @@ int64_t SrsFileStream::filesize() | ||
174 | return size; | 188 | return size; |
175 | } | 189 | } |
176 | 190 | ||
177 | -void SrsFileStream::skip(int64_t size) | 191 | +int SrsFileReader::read(void* buf, size_t count, ssize_t* pnread) |
178 | { | 192 | { |
179 | - ::lseek(fd, size, SEEK_CUR); | 193 | + int ret = ERROR_SUCCESS; |
194 | + | ||
195 | + ssize_t nread; | ||
196 | + if ((nread = ::read(fd, buf, count)) < 0) { | ||
197 | + ret = ERROR_SYSTEM_FILE_READ; | ||
198 | + srs_error("read from file %s failed. ret=%d", _file.c_str(), ret); | ||
199 | + return ret; | ||
200 | + } | ||
201 | + | ||
202 | + if (nread == 0) { | ||
203 | + ret = ERROR_SYSTEM_FILE_EOF; | ||
204 | + return ret; | ||
205 | + } | ||
206 | + | ||
207 | + if (pnread != NULL) { | ||
208 | + *pnread = nread; | ||
209 | + } | ||
210 | + | ||
211 | + return ret; | ||
180 | } | 212 | } |
181 | 213 | ||
182 | SrsFlvEncoder::SrsFlvEncoder() | 214 | SrsFlvEncoder::SrsFlvEncoder() |
@@ -190,7 +222,7 @@ SrsFlvEncoder::~SrsFlvEncoder() | @@ -190,7 +222,7 @@ SrsFlvEncoder::~SrsFlvEncoder() | ||
190 | srs_freep(tag_stream); | 222 | srs_freep(tag_stream); |
191 | } | 223 | } |
192 | 224 | ||
193 | -int SrsFlvEncoder::initialize(SrsFileStream* fs) | 225 | +int SrsFlvEncoder::initialize(SrsFileWriter* fs) |
194 | { | 226 | { |
195 | int ret = ERROR_SUCCESS; | 227 | int ret = ERROR_SUCCESS; |
196 | 228 | ||
@@ -377,7 +409,7 @@ SrsFlvFastDecoder::~SrsFlvFastDecoder() | @@ -377,7 +409,7 @@ SrsFlvFastDecoder::~SrsFlvFastDecoder() | ||
377 | srs_freep(tag_stream); | 409 | srs_freep(tag_stream); |
378 | } | 410 | } |
379 | 411 | ||
380 | -int SrsFlvFastDecoder::initialize(SrsFileStream* fs) | 412 | +int SrsFlvFastDecoder::initialize(SrsFileReader* fs) |
381 | { | 413 | { |
382 | int ret = ERROR_SUCCESS; | 414 | int ret = ERROR_SUCCESS; |
383 | 415 | ||
@@ -538,7 +570,7 @@ SrsFlvDecoder::~SrsFlvDecoder() | @@ -538,7 +570,7 @@ SrsFlvDecoder::~SrsFlvDecoder() | ||
538 | srs_freep(tag_stream); | 570 | srs_freep(tag_stream); |
539 | } | 571 | } |
540 | 572 | ||
541 | -int SrsFlvDecoder::initialize(SrsFileStream* fs) | 573 | +int SrsFlvDecoder::initialize(SrsFileReader* fs) |
542 | { | 574 | { |
543 | int ret = ERROR_SUCCESS; | 575 | int ret = ERROR_SUCCESS; |
544 | 576 |
@@ -34,37 +34,47 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -34,37 +34,47 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
34 | class SrsStream; | 34 | class SrsStream; |
35 | 35 | ||
36 | /** | 36 | /** |
37 | -* file stream to read/write file. | 37 | +* file writer, to write to file. |
38 | */ | 38 | */ |
39 | -class SrsFileStream | 39 | +class SrsFileWriter |
40 | { | 40 | { |
41 | private: | 41 | private: |
42 | std::string _file; | 42 | std::string _file; |
43 | int fd; | 43 | int fd; |
44 | public: | 44 | public: |
45 | - SrsFileStream(); | ||
46 | - virtual ~SrsFileStream(); | 45 | + SrsFileWriter(); |
46 | + virtual ~SrsFileWriter(); | ||
47 | public: | 47 | public: |
48 | - virtual int open_write(std::string file); | ||
49 | - virtual int open_read(std::string file); | 48 | + virtual int open(std::string file); |
50 | virtual void close(); | 49 | virtual void close(); |
50 | +public: | ||
51 | virtual bool is_open(); | 51 | virtual bool is_open(); |
52 | + virtual int64_t tellg(); | ||
52 | public: | 53 | public: |
53 | - /** | ||
54 | - * @param pnread, return the read size. NULL to ignore. | ||
55 | - */ | ||
56 | - virtual int read(void* buf, size_t count, ssize_t* pnread); | ||
57 | - /** | ||
58 | - * @param pnwrite, return the write size. NULL to ignore. | ||
59 | - */ | ||
60 | virtual int write(void* buf, size_t count, ssize_t* pnwrite); | 54 | virtual int write(void* buf, size_t count, ssize_t* pnwrite); |
61 | - /** | ||
62 | - * tell current offset of stream. | ||
63 | - */ | 55 | +}; |
56 | + | ||
57 | +/** | ||
58 | +* file reader, to read from file. | ||
59 | +*/ | ||
60 | +class SrsFileReader | ||
61 | +{ | ||
62 | +private: | ||
63 | + std::string _file; | ||
64 | + int fd; | ||
65 | +public: | ||
66 | + SrsFileReader(); | ||
67 | + virtual ~SrsFileReader(); | ||
68 | +public: | ||
69 | + virtual int open(std::string file); | ||
70 | + virtual void close(); | ||
71 | +public: | ||
64 | virtual int64_t tellg(); | 72 | virtual int64_t tellg(); |
73 | + virtual void skip(int64_t size); | ||
65 | virtual int64_t lseek(int64_t offset); | 74 | virtual int64_t lseek(int64_t offset); |
66 | virtual int64_t filesize(); | 75 | virtual int64_t filesize(); |
67 | - virtual void skip(int64_t size); | 76 | +public: |
77 | + virtual int read(void* buf, size_t count, ssize_t* pnread); | ||
68 | }; | 78 | }; |
69 | 79 | ||
70 | /** | 80 | /** |
@@ -73,7 +83,7 @@ public: | @@ -73,7 +83,7 @@ public: | ||
73 | class SrsFlvEncoder | 83 | class SrsFlvEncoder |
74 | { | 84 | { |
75 | private: | 85 | private: |
76 | - SrsFileStream* _fs; | 86 | + SrsFileWriter* _fs; |
77 | private: | 87 | private: |
78 | SrsStream* tag_stream; | 88 | SrsStream* tag_stream; |
79 | public: | 89 | public: |
@@ -84,7 +94,7 @@ public: | @@ -84,7 +94,7 @@ public: | ||
84 | * initialize the underlayer file stream, | 94 | * initialize the underlayer file stream, |
85 | * user can initialize multiple times to encode multiple flv files. | 95 | * user can initialize multiple times to encode multiple flv files. |
86 | */ | 96 | */ |
87 | - virtual int initialize(SrsFileStream* fs); | 97 | + virtual int initialize(SrsFileWriter* fs); |
88 | public: | 98 | public: |
89 | /** | 99 | /** |
90 | * write flv header. | 100 | * write flv header. |
@@ -122,7 +132,7 @@ private: | @@ -122,7 +132,7 @@ private: | ||
122 | class SrsFlvFastDecoder | 132 | class SrsFlvFastDecoder |
123 | { | 133 | { |
124 | private: | 134 | private: |
125 | - SrsFileStream* _fs; | 135 | + SrsFileReader* _fs; |
126 | private: | 136 | private: |
127 | SrsStream* tag_stream; | 137 | SrsStream* tag_stream; |
128 | public: | 138 | public: |
@@ -133,7 +143,7 @@ public: | @@ -133,7 +143,7 @@ public: | ||
133 | * initialize the underlayer file stream, | 143 | * initialize the underlayer file stream, |
134 | * user can initialize multiple times to encode multiple flv files. | 144 | * user can initialize multiple times to encode multiple flv files. |
135 | */ | 145 | */ |
136 | - virtual int initialize(SrsFileStream* fs); | 146 | + virtual int initialize(SrsFileReader* fs); |
137 | public: | 147 | public: |
138 | /** | 148 | /** |
139 | * read the flv header and size. | 149 | * read the flv header and size. |
@@ -156,7 +166,7 @@ public: | @@ -156,7 +166,7 @@ public: | ||
156 | class SrsFlvDecoder | 166 | class SrsFlvDecoder |
157 | { | 167 | { |
158 | private: | 168 | private: |
159 | - SrsFileStream* _fs; | 169 | + SrsFileReader* _fs; |
160 | private: | 170 | private: |
161 | SrsStream* tag_stream; | 171 | SrsStream* tag_stream; |
162 | public: | 172 | public: |
@@ -167,7 +177,7 @@ public: | @@ -167,7 +177,7 @@ public: | ||
167 | * initialize the underlayer file stream, | 177 | * initialize the underlayer file stream, |
168 | * user can initialize multiple times to decode multiple flv files. | 178 | * user can initialize multiple times to decode multiple flv files. |
169 | */ | 179 | */ |
170 | - virtual int initialize(SrsFileStream* fs); | 180 | + virtual int initialize(SrsFileReader* fs); |
171 | public: | 181 | public: |
172 | virtual int read_header(char header[9]); | 182 | virtual int read_header(char header[9]); |
173 | virtual int read_tag_header(char* ptype, int32_t* pdata_size, u_int32_t* ptime); | 183 | virtual int read_tag_header(char* ptype, int32_t* pdata_size, u_int32_t* ptime); |
@@ -461,52 +461,34 @@ int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp) | @@ -461,52 +461,34 @@ int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp) | ||
461 | 461 | ||
462 | struct FlvContext | 462 | struct FlvContext |
463 | { | 463 | { |
464 | - SrsFileStream fs; | 464 | + SrsFileReader reader; |
465 | + SrsFileWriter writer; | ||
465 | SrsFlvEncoder enc; | 466 | SrsFlvEncoder enc; |
466 | SrsFlvDecoder dec; | 467 | SrsFlvDecoder dec; |
467 | }; | 468 | }; |
468 | 469 | ||
469 | -srs_flv_t srs_flv_open_read(const char* file) | 470 | +srs_flv_t srs_flv_open(const char* file) |
470 | { | 471 | { |
471 | int ret = ERROR_SUCCESS; | 472 | int ret = ERROR_SUCCESS; |
472 | 473 | ||
473 | FlvContext* flv = new FlvContext(); | 474 | FlvContext* flv = new FlvContext(); |
474 | 475 | ||
475 | - if ((ret = flv->fs.open_read(file)) != ERROR_SUCCESS) { | 476 | + if ((ret = flv->reader.open(file)) != ERROR_SUCCESS) { |
476 | srs_freep(flv); | 477 | srs_freep(flv); |
477 | return NULL; | 478 | return NULL; |
478 | } | 479 | } |
479 | 480 | ||
480 | - if ((ret = flv->enc.initialize(&flv->fs)) != ERROR_SUCCESS) { | 481 | + if ((ret = flv->dec.initialize(&flv->reader)) != ERROR_SUCCESS) { |
481 | srs_freep(flv); | 482 | srs_freep(flv); |
482 | return NULL; | 483 | return NULL; |
483 | } | 484 | } |
484 | 485 | ||
485 | - if ((ret = flv->dec.initialize(&flv->fs)) != ERROR_SUCCESS) { | 486 | + if ((ret = flv->writer.open(file)) != ERROR_SUCCESS) { |
486 | srs_freep(flv); | 487 | srs_freep(flv); |
487 | return NULL; | 488 | return NULL; |
488 | } | 489 | } |
489 | 490 | ||
490 | - return flv; | ||
491 | -} | ||
492 | - | ||
493 | -srs_flv_t srs_flv_open_write(const char* file) | ||
494 | -{ | ||
495 | - int ret = ERROR_SUCCESS; | ||
496 | - | ||
497 | - FlvContext* flv = new FlvContext(); | ||
498 | - | ||
499 | - if ((ret = flv->fs.open_write(file)) != ERROR_SUCCESS) { | ||
500 | - srs_freep(flv); | ||
501 | - return NULL; | ||
502 | - } | ||
503 | - | ||
504 | - if ((ret = flv->enc.initialize(&flv->fs)) != ERROR_SUCCESS) { | ||
505 | - srs_freep(flv); | ||
506 | - return NULL; | ||
507 | - } | ||
508 | - | ||
509 | - if ((ret = flv->dec.initialize(&flv->fs)) != ERROR_SUCCESS) { | 491 | + if ((ret = flv->enc.initialize(&flv->writer)) != ERROR_SUCCESS) { |
510 | srs_freep(flv); | 492 | srs_freep(flv); |
511 | return NULL; | 493 | return NULL; |
512 | } | 494 | } |
@@ -602,13 +584,13 @@ int srs_flv_size_tag(int data_size) | @@ -602,13 +584,13 @@ int srs_flv_size_tag(int data_size) | ||
602 | int64_t srs_flv_tellg(srs_flv_t flv) | 584 | int64_t srs_flv_tellg(srs_flv_t flv) |
603 | { | 585 | { |
604 | FlvContext* context = (FlvContext*)flv; | 586 | FlvContext* context = (FlvContext*)flv; |
605 | - return context->fs.tellg(); | 587 | + return context->reader.tellg(); |
606 | } | 588 | } |
607 | 589 | ||
608 | void srs_flv_lseek(srs_flv_t flv, int64_t offset) | 590 | void srs_flv_lseek(srs_flv_t flv, int64_t offset) |
609 | { | 591 | { |
610 | FlvContext* context = (FlvContext*)flv; | 592 | FlvContext* context = (FlvContext*)flv; |
611 | - context->fs.lseek(offset); | 593 | + context->reader.lseek(offset); |
612 | } | 594 | } |
613 | 595 | ||
614 | flv_bool srs_flv_is_eof(int error_code) | 596 | flv_bool srs_flv_is_eof(int error_code) |
@@ -165,8 +165,7 @@ int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp); | @@ -165,8 +165,7 @@ int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp); | ||
165 | */ | 165 | */ |
166 | typedef void* srs_flv_t; | 166 | typedef void* srs_flv_t; |
167 | typedef int flv_bool; | 167 | typedef int flv_bool; |
168 | -srs_flv_t srs_flv_open_read(const char* file); | ||
169 | -srs_flv_t srs_flv_open_write(const char* file); | 168 | +srs_flv_t srs_flv_open(const char* file); |
170 | void srs_flv_close(srs_flv_t flv); | 169 | void srs_flv_close(srs_flv_t flv); |
171 | /* read the flv header. 9bytes header. drop the 4bytes zero previous tag size */ | 170 | /* read the flv header. 9bytes header. drop the 4bytes zero previous tag size */ |
172 | int srs_flv_read_header(srs_flv_t flv, char header[9]); | 171 | int srs_flv_read_header(srs_flv_t flv, char header[9]); |
@@ -25,6 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -25,6 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
25 | using namespace std; | 25 | using namespace std; |
26 | 26 | ||
27 | #include <srs_kernel_error.hpp> | 27 | #include <srs_kernel_error.hpp> |
28 | +#include <srs_kernel_codec.hpp> | ||
28 | 29 | ||
29 | VOID TEST(KernelCodecTest, IsKeyFrame) | 30 | VOID TEST(KernelCodecTest, IsKeyFrame) |
30 | { | 31 | { |
@@ -30,6 +30,28 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -30,6 +30,28 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
30 | #include <srs_utest.hpp> | 30 | #include <srs_utest.hpp> |
31 | 31 | ||
32 | #include <string> | 32 | #include <string> |
33 | -#include <srs_kernel_codec.hpp> | 33 | +#include <srs_kernel_flv.hpp> |
34 | + | ||
35 | +/* | ||
36 | +class MockSrsFileStream : public SrsFileStream | ||
37 | +{ | ||
38 | +public: | ||
39 | + MockSrsFileStream(); | ||
40 | + virtual ~MockSrsFileStream(); | ||
41 | +public: | ||
42 | +public: | ||
43 | + virtual int open_write(std::string file); | ||
44 | + virtual int open_read(std::string file); | ||
45 | + virtual void close(); | ||
46 | + virtual bool is_open(); | ||
47 | +public: | ||
48 | + virtual int read(void* buf, size_t count, ssize_t* pnread); | ||
49 | + virtual int write(void* buf, size_t count, ssize_t* pnwrite); | ||
50 | + virtual int64_t tellg(); | ||
51 | + virtual int64_t lseek(int64_t offset); | ||
52 | + virtual int64_t filesize(); | ||
53 | + virtual void skip(int64_t size); | ||
54 | +}; | ||
55 | +*/ | ||
34 | 56 | ||
35 | #endif | 57 | #endif |
-
请 注册 或 登录 后发表评论