Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2014-06-29 17:05:26 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1a7735182f84b60dc33eba620f4d3afd1ec0bdcc
1a773518
1 parent
ed3f9f0a
refine the file stream, to file reader and writer. 0.9.142
隐藏空白字符变更
内嵌
并排对比
正在显示
13 个修改的文件
包含
165 行增加
和
119 行删除
trunk/research/librtmp/srs_flv_injecter.c
trunk/research/librtmp/srs_flv_parser.c
trunk/research/librtmp/srs_ingest_flv.c
trunk/src/app/srs_app_dvr.cpp
trunk/src/app/srs_app_dvr.hpp
trunk/src/app/srs_app_http_conn.cpp
trunk/src/core/srs_core.hpp
trunk/src/kernel/srs_kernel_flv.cpp
trunk/src/kernel/srs_kernel_flv.hpp
trunk/src/libs/srs_librtmp.cpp
trunk/src/libs/srs_librtmp.hpp
trunk/src/utest/srs_utest_kernel.cpp
trunk/src/utest/srs_utest_kernel.hpp
trunk/research/librtmp/srs_flv_injecter.c
查看文件 @
1a77351
...
...
@@ -121,14 +121,14 @@ int process(const char* in_flv_file, const char* out_flv_file, srs_flv_t* pic, s
srs_amf0_t
amf0_data
=
NULL
;
srs_amf0_t
filepositions
=
NULL
;
if
((
ic
=
srs_flv_open
_read
(
in_flv_file
))
==
NULL
)
{
if
((
ic
=
srs_flv_open
(
in_flv_file
))
==
NULL
)
{
ret
=
2
;
trace
(
"open input flv file failed. ret=%d"
,
ret
);
return
ret
;
}
*
pic
=
ic
;
if
((
oc
=
srs_flv_open
_write
(
out_flv_file
))
==
NULL
)
{
if
((
oc
=
srs_flv_open
(
out_flv_file
))
==
NULL
)
{
ret
=
2
;
trace
(
"open output flv file failed. ret=%d"
,
ret
);
return
ret
;
...
...
trunk/research/librtmp/srs_flv_parser.c
查看文件 @
1a77351
...
...
@@ -64,7 +64,7 @@ int main(int argc, char** argv)
trace
(
"version: %d.%d.%d"
,
srs_version_major
(),
srs_version_minor
(),
srs_version_revision
());
trace
(
"input: %s"
,
in_flv_file
);
if
((
flv
=
srs_flv_open
_read
(
in_flv_file
))
==
NULL
)
{
if
((
flv
=
srs_flv_open
(
in_flv_file
))
==
NULL
)
{
ret
=
2
;
trace
(
"open flv file failed. ret=%d"
,
ret
);
return
ret
;
...
...
trunk/research/librtmp/srs_ingest_flv.c
查看文件 @
1a77351
...
...
@@ -93,7 +93,7 @@ int main(int argc, char** argv)
trace
(
"input: %s"
,
in_flv_file
);
trace
(
"output: %s"
,
out_rtmp_url
);
if
((
flv
=
srs_flv_open
_read
(
in_flv_file
))
==
NULL
)
{
if
((
flv
=
srs_flv_open
(
in_flv_file
))
==
NULL
)
{
ret
=
2
;
trace
(
"open flv file failed. ret=%d"
,
ret
);
return
ret
;
...
...
trunk/src/app/srs_app_dvr.cpp
查看文件 @
1a77351
...
...
@@ -71,7 +71,7 @@ SrsDvrPlan::SrsDvrPlan()
_req
=
NULL
;
jitter
=
NULL
;
dvr_enabled
=
false
;
fs
=
new
SrsFile
Stream
();
fs
=
new
SrsFile
Writer
();
enc
=
new
SrsFlvEncoder
();
segment
=
new
SrsFlvSegment
();
jitter_algorithm
=
SrsRtmpJitterAlgorithmOFF
;
...
...
@@ -283,7 +283,7 @@ int SrsDvrPlan::flv_open(string stream, string path)
segment
->
reset
();
std
::
string
tmp_file
=
path
+
".tmp"
;
if
((
ret
=
fs
->
open
_write
(
tmp_file
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
fs
->
open
(
tmp_file
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"open file stream for file %s failed. ret=%d"
,
path
.
c_str
(),
ret
);
return
ret
;
}
...
...
@@ -569,8 +569,8 @@ int SrsDvrHssPlan::on_meta_data(SrsOnMetaDataPacket* metadata)
<<
"/"
<<
req
->
app
<<
"/"
<<
req
->
stream
<<
".header.flv"
;
SrsFileStream
fs
;
if
((
ret
=
fs
.
open_write
(
path
.
str
().
c_str
()))
!=
ERROR_SUCCESS
)
{
SrsFileWriter
fs
;
if
((
ret
=
fs
.
open
(
path
.
str
().
c_str
()))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
trunk/src/app/srs_app_dvr.hpp
查看文件 @
1a77351
...
...
@@ -39,7 +39,7 @@ class SrsStream;
class
SrsRtmpJitter
;
class
SrsOnMetaDataPacket
;
class
SrsSharedPtrMessage
;
class
SrsFile
Stream
;
class
SrsFile
Writer
;
class
SrsFlvEncoder
;
#include <srs_app_source.hpp>
...
...
@@ -114,7 +114,7 @@ protected:
SrsFlvSegment
*
segment
;
SrsRequest
*
_req
;
bool
dvr_enabled
;
SrsFile
Stream
*
fs
;
SrsFile
Writer
*
fs
;
public
:
SrsDvrPlan
();
virtual
~
SrsDvrPlan
();
...
...
trunk/src/app/srs_app_http_conn.cpp
查看文件 @
1a77351
...
...
@@ -300,10 +300,10 @@ int SrsHttpVhost::response_flv_file2(SrsSocket* skt, SrsHttpMessage* req, string
{
int
ret
=
ERROR_SUCCESS
;
SrsFile
Stream
fs
;
SrsFile
Reader
fs
;
// open flv file
if
((
ret
=
fs
.
open
_read
(
fullpath
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
fs
.
open
(
fullpath
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
trunk/src/core/srs_core.hpp
查看文件 @
1a77351
...
...
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR "0"
#define VERSION_MINOR "9"
#define VERSION_REVISION "14
1
"
#define VERSION_REVISION "14
2
"
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
// server info.
#define RTMP_SIG_SRS_KEY "SRS"
...
...
trunk/src/kernel/srs_kernel_flv.cpp
查看文件 @
1a77351
...
...
@@ -37,17 +37,16 @@ using namespace std;
#define SRS_FLV_TAG_HEADER_SIZE 11
#define SRS_FLV_PREVIOUS_TAG_SIZE 4
SrsFile
Stream
::
SrsFileStream
()
SrsFile
Writer
::
SrsFileWriter
()
{
fd
=
-
1
;
}
SrsFile
Stream
::~
SrsFileStream
()
SrsFile
Writer
::~
SrsFileWriter
()
{
close
();
}
int
SrsFile
Stream
::
open_write
(
string
file
)
int
SrsFile
Writer
::
open
(
string
file
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -71,7 +70,63 @@ int SrsFileStream::open_write(string file)
return
ret
;
}
int
SrsFileStream
::
open_read
(
string
file
)
void
SrsFileWriter
::
close
()
{
int
ret
=
ERROR_SUCCESS
;
if
(
fd
<
0
)
{
return
;
}
if
(
::
close
(
fd
)
<
0
)
{
ret
=
ERROR_SYSTEM_FILE_CLOSE
;
srs_error
(
"close file %s failed. ret=%d"
,
_file
.
c_str
(),
ret
);
return
;
}
fd
=
-
1
;
return
;
}
bool
SrsFileWriter
::
is_open
()
{
return
fd
>
0
;
}
int64_t
SrsFileWriter
::
tellg
()
{
return
(
int64_t
)
::
lseek
(
fd
,
0
,
SEEK_CUR
);
}
int
SrsFileWriter
::
write
(
void
*
buf
,
size_t
count
,
ssize_t
*
pnwrite
)
{
int
ret
=
ERROR_SUCCESS
;
ssize_t
nwrite
;
if
((
nwrite
=
::
write
(
fd
,
buf
,
count
))
<
0
)
{
ret
=
ERROR_SYSTEM_FILE_WRITE
;
srs_error
(
"write to file %s failed. ret=%d"
,
_file
.
c_str
(),
ret
);
return
ret
;
}
if
(
pnwrite
!=
NULL
)
{
*
pnwrite
=
nwrite
;
}
return
ret
;
}
SrsFileReader
::
SrsFileReader
()
{
fd
=
-
1
;
}
SrsFileReader
::~
SrsFileReader
()
{
close
();
}
int
SrsFileReader
::
open
(
string
file
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -92,7 +147,7 @@ int SrsFileStream::open_read(string file)
return
ret
;
}
void
SrsFile
Stream
::
close
()
void
SrsFile
Reader
::
close
()
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -110,12 +165,30 @@ void SrsFileStream::close()
return
;
}
bool
SrsFileStream
::
is_open
()
int64_t
SrsFileReader
::
tellg
()
{
return
fd
>
0
;
return
(
int64_t
)
::
lseek
(
fd
,
0
,
SEEK_CUR
);
}
void
SrsFileReader
::
skip
(
int64_t
size
)
{
::
lseek
(
fd
,
size
,
SEEK_CUR
);
}
int64_t
SrsFileReader
::
lseek
(
int64_t
offset
)
{
return
(
int64_t
)
::
lseek
(
fd
,
offset
,
SEEK_SET
);
}
int64_t
SrsFileReader
::
filesize
()
{
int64_t
cur
=
tellg
();
int64_t
size
=
(
int64_t
)
::
lseek
(
fd
,
0
,
SEEK_END
);
::
lseek
(
fd
,
cur
,
SEEK_SET
);
return
size
;
}
int
SrsFile
Stream
::
read
(
void
*
buf
,
size_t
count
,
ssize_t
*
pnread
)
int
SrsFile
Reader
::
read
(
void
*
buf
,
size_t
count
,
ssize_t
*
pnread
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -138,47 +211,6 @@ int SrsFileStream::read(void* buf, size_t count, ssize_t* pnread)
return
ret
;
}
int
SrsFileStream
::
write
(
void
*
buf
,
size_t
count
,
ssize_t
*
pnwrite
)
{
int
ret
=
ERROR_SUCCESS
;
ssize_t
nwrite
;
if
((
nwrite
=
::
write
(
fd
,
buf
,
count
))
<
0
)
{
ret
=
ERROR_SYSTEM_FILE_WRITE
;
srs_error
(
"write to file %s failed. ret=%d"
,
_file
.
c_str
(),
ret
);
return
ret
;
}
if
(
pnwrite
!=
NULL
)
{
*
pnwrite
=
nwrite
;
}
return
ret
;
}
int64_t
SrsFileStream
::
tellg
()
{
return
(
int64_t
)
::
lseek
(
fd
,
0
,
SEEK_CUR
);
}
int64_t
SrsFileStream
::
lseek
(
int64_t
offset
)
{
return
(
int64_t
)
::
lseek
(
fd
,
offset
,
SEEK_SET
);
}
int64_t
SrsFileStream
::
filesize
()
{
int64_t
cur
=
tellg
();
int64_t
size
=
(
int64_t
)
::
lseek
(
fd
,
0
,
SEEK_END
);
::
lseek
(
fd
,
cur
,
SEEK_SET
);
return
size
;
}
void
SrsFileStream
::
skip
(
int64_t
size
)
{
::
lseek
(
fd
,
size
,
SEEK_CUR
);
}
SrsFlvEncoder
::
SrsFlvEncoder
()
{
_fs
=
NULL
;
...
...
@@ -190,7 +222,7 @@ SrsFlvEncoder::~SrsFlvEncoder()
srs_freep
(
tag_stream
);
}
int
SrsFlvEncoder
::
initialize
(
SrsFile
Stream
*
fs
)
int
SrsFlvEncoder
::
initialize
(
SrsFile
Writer
*
fs
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -377,7 +409,7 @@ SrsFlvFastDecoder::~SrsFlvFastDecoder()
srs_freep
(
tag_stream
);
}
int
SrsFlvFastDecoder
::
initialize
(
SrsFile
Stream
*
fs
)
int
SrsFlvFastDecoder
::
initialize
(
SrsFile
Reader
*
fs
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -538,7 +570,7 @@ SrsFlvDecoder::~SrsFlvDecoder()
srs_freep
(
tag_stream
);
}
int
SrsFlvDecoder
::
initialize
(
SrsFile
Stream
*
fs
)
int
SrsFlvDecoder
::
initialize
(
SrsFile
Reader
*
fs
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
trunk/src/kernel/srs_kernel_flv.hpp
查看文件 @
1a77351
...
...
@@ -34,37 +34,47 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class
SrsStream
;
/**
* file
stream to read/write
file.
* file
writer, to write to
file.
*/
class
SrsFile
Stream
class
SrsFile
Writer
{
private
:
std
::
string
_file
;
int
fd
;
public
:
SrsFileStream
();
virtual
~
SrsFileStream
();
SrsFileWriter
();
virtual
~
SrsFileWriter
();
public
:
virtual
int
open_write
(
std
::
string
file
);
virtual
int
open_read
(
std
::
string
file
);
virtual
int
open
(
std
::
string
file
);
virtual
void
close
();
public
:
virtual
bool
is_open
();
virtual
int64_t
tellg
();
public
:
/**
* @param pnread, return the read size. NULL to ignore.
*/
virtual
int
read
(
void
*
buf
,
size_t
count
,
ssize_t
*
pnread
);
/**
* @param pnwrite, return the write size. NULL to ignore.
*/
virtual
int
write
(
void
*
buf
,
size_t
count
,
ssize_t
*
pnwrite
);
/**
* tell current offset of stream.
*/
};
/**
* file reader, to read from file.
*/
class
SrsFileReader
{
private
:
std
::
string
_file
;
int
fd
;
public
:
SrsFileReader
();
virtual
~
SrsFileReader
();
public
:
virtual
int
open
(
std
::
string
file
);
virtual
void
close
();
public
:
virtual
int64_t
tellg
();
virtual
void
skip
(
int64_t
size
);
virtual
int64_t
lseek
(
int64_t
offset
);
virtual
int64_t
filesize
();
virtual
void
skip
(
int64_t
size
);
public
:
virtual
int
read
(
void
*
buf
,
size_t
count
,
ssize_t
*
pnread
);
};
/**
...
...
@@ -73,7 +83,7 @@ public:
class
SrsFlvEncoder
{
private
:
SrsFile
Stream
*
_fs
;
SrsFile
Writer
*
_fs
;
private
:
SrsStream
*
tag_stream
;
public
:
...
...
@@ -84,7 +94,7 @@ public:
* initialize the underlayer file stream,
* user can initialize multiple times to encode multiple flv files.
*/
virtual
int
initialize
(
SrsFile
Stream
*
fs
);
virtual
int
initialize
(
SrsFile
Writer
*
fs
);
public
:
/**
* write flv header.
...
...
@@ -122,7 +132,7 @@ private:
class
SrsFlvFastDecoder
{
private
:
SrsFile
Stream
*
_fs
;
SrsFile
Reader
*
_fs
;
private
:
SrsStream
*
tag_stream
;
public
:
...
...
@@ -133,7 +143,7 @@ public:
* initialize the underlayer file stream,
* user can initialize multiple times to encode multiple flv files.
*/
virtual
int
initialize
(
SrsFile
Stream
*
fs
);
virtual
int
initialize
(
SrsFile
Reader
*
fs
);
public
:
/**
* read the flv header and size.
...
...
@@ -156,7 +166,7 @@ public:
class
SrsFlvDecoder
{
private
:
SrsFile
Stream
*
_fs
;
SrsFile
Reader
*
_fs
;
private
:
SrsStream
*
tag_stream
;
public
:
...
...
@@ -167,7 +177,7 @@ public:
* initialize the underlayer file stream,
* user can initialize multiple times to decode multiple flv files.
*/
virtual
int
initialize
(
SrsFile
Stream
*
fs
);
virtual
int
initialize
(
SrsFile
Reader
*
fs
);
public
:
virtual
int
read_header
(
char
header
[
9
]);
virtual
int
read_tag_header
(
char
*
ptype
,
int32_t
*
pdata_size
,
u_int32_t
*
ptime
);
...
...
trunk/src/libs/srs_librtmp.cpp
查看文件 @
1a77351
...
...
@@ -461,52 +461,34 @@ int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp)
struct
FlvContext
{
SrsFileStream
fs
;
SrsFileReader
reader
;
SrsFileWriter
writer
;
SrsFlvEncoder
enc
;
SrsFlvDecoder
dec
;
};
srs_flv_t
srs_flv_open
_read
(
const
char
*
file
)
srs_flv_t
srs_flv_open
(
const
char
*
file
)
{
int
ret
=
ERROR_SUCCESS
;
FlvContext
*
flv
=
new
FlvContext
();
if
((
ret
=
flv
->
fs
.
open_read
(
file
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
flv
->
reader
.
open
(
file
))
!=
ERROR_SUCCESS
)
{
srs_freep
(
flv
);
return
NULL
;
}
if
((
ret
=
flv
->
enc
.
initialize
(
&
flv
->
fs
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
flv
->
dec
.
initialize
(
&
flv
->
reader
))
!=
ERROR_SUCCESS
)
{
srs_freep
(
flv
);
return
NULL
;
}
if
((
ret
=
flv
->
dec
.
initialize
(
&
flv
->
fs
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
flv
->
writer
.
open
(
file
))
!=
ERROR_SUCCESS
)
{
srs_freep
(
flv
);
return
NULL
;
}
return
flv
;
}
srs_flv_t
srs_flv_open_write
(
const
char
*
file
)
{
int
ret
=
ERROR_SUCCESS
;
FlvContext
*
flv
=
new
FlvContext
();
if
((
ret
=
flv
->
fs
.
open_write
(
file
))
!=
ERROR_SUCCESS
)
{
srs_freep
(
flv
);
return
NULL
;
}
if
((
ret
=
flv
->
enc
.
initialize
(
&
flv
->
fs
))
!=
ERROR_SUCCESS
)
{
srs_freep
(
flv
);
return
NULL
;
}
if
((
ret
=
flv
->
dec
.
initialize
(
&
flv
->
fs
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
flv
->
enc
.
initialize
(
&
flv
->
writer
))
!=
ERROR_SUCCESS
)
{
srs_freep
(
flv
);
return
NULL
;
}
...
...
@@ -602,13 +584,13 @@ int srs_flv_size_tag(int data_size)
int64_t
srs_flv_tellg
(
srs_flv_t
flv
)
{
FlvContext
*
context
=
(
FlvContext
*
)
flv
;
return
context
->
fs
.
tellg
();
return
context
->
reader
.
tellg
();
}
void
srs_flv_lseek
(
srs_flv_t
flv
,
int64_t
offset
)
{
FlvContext
*
context
=
(
FlvContext
*
)
flv
;
context
->
fs
.
lseek
(
offset
);
context
->
reader
.
lseek
(
offset
);
}
flv_bool
srs_flv_is_eof
(
int
error_code
)
...
...
trunk/src/libs/srs_librtmp.hpp
查看文件 @
1a77351
...
...
@@ -165,8 +165,7 @@ int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp);
*/
typedef
void
*
srs_flv_t
;
typedef
int
flv_bool
;
srs_flv_t
srs_flv_open_read
(
const
char
*
file
);
srs_flv_t
srs_flv_open_write
(
const
char
*
file
);
srs_flv_t
srs_flv_open
(
const
char
*
file
);
void
srs_flv_close
(
srs_flv_t
flv
);
/* read the flv header. 9bytes header. drop the 4bytes zero previous tag size */
int
srs_flv_read_header
(
srs_flv_t
flv
,
char
header
[
9
]);
...
...
trunk/src/utest/srs_utest_kernel.cpp
查看文件 @
1a77351
...
...
@@ -25,6 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using
namespace
std
;
#include <srs_kernel_error.hpp>
#include <srs_kernel_codec.hpp>
VOID
TEST
(
KernelCodecTest
,
IsKeyFrame
)
{
...
...
trunk/src/utest/srs_utest_kernel.hpp
查看文件 @
1a77351
...
...
@@ -30,6 +30,28 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_utest.hpp>
#include <string>
#include <srs_kernel_codec.hpp>
#include <srs_kernel_flv.hpp>
/*
class MockSrsFileStream : public SrsFileStream
{
public:
MockSrsFileStream();
virtual ~MockSrsFileStream();
public:
public:
virtual int open_write(std::string file);
virtual int open_read(std::string file);
virtual void close();
virtual bool is_open();
public:
virtual int read(void* buf, size_t count, ssize_t* pnread);
virtual int write(void* buf, size_t count, ssize_t* pnwrite);
virtual int64_t tellg();
virtual int64_t lseek(int64_t offset);
virtual int64_t filesize();
virtual void skip(int64_t size);
};
*/
#endif
...
...
请
注册
或
登录
后发表评论