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
2015-05-04 18:28:41 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ba6c3132e37073ee7c0d08b92b73b676bead0d88
ba6c3132
1 parent
ea1e015a
refine code, use decoder to parse flv stream
隐藏空白字符变更
内嵌
并排对比
正在显示
3 个修改的文件
包含
112 行增加
和
0 行删除
trunk/src/app/srs_app_caster_flv.cpp
trunk/src/app/srs_app_caster_flv.hpp
trunk/src/kernel/srs_kernel_error.hpp
trunk/src/app/srs_app_caster_flv.cpp
查看文件 @
ba6c313
...
...
@@ -36,6 +36,7 @@ using namespace std;
#include <srs_app_http.hpp>
#include <srs_app_http_conn.hpp>
#include <srs_core_autofree.hpp>
#include <srs_kernel_flv.hpp>
#define SRS_HTTP_FLV_STREAM_BUFFER 4096
...
...
@@ -92,6 +93,13 @@ int SrsAppCasterFlv::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
SrsAutoFree
(
char
,
buffer
);
ISrsHttpResponseReader
*
rr
=
r
->
body_reader
();
SrsHttpFileReader
reader
(
rr
);
SrsFlvDecoder
dec
;
if
((
ret
=
dec
.
initialize
(
&
reader
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
while
(
!
rr
->
eof
())
{
int
nb_read
=
0
;
if
((
ret
=
rr
->
read
(
buffer
,
SRS_HTTP_FLV_STREAM_BUFFER
,
&
nb_read
))
!=
ERROR_SUCCESS
)
{
...
...
@@ -118,4 +126,68 @@ int SrsDynamicHttpConn::on_got_http_message(SrsHttpMessage* msg)
return
ret
;
}
SrsHttpFileReader
::
SrsHttpFileReader
(
ISrsHttpResponseReader
*
h
)
{
http
=
h
;
}
SrsHttpFileReader
::~
SrsHttpFileReader
()
{
}
int
SrsHttpFileReader
::
open
(
std
::
string
/*file*/
)
{
return
ERROR_SUCCESS
;
}
void
SrsHttpFileReader
::
close
()
{
}
bool
SrsHttpFileReader
::
is_open
()
{
return
false
;
}
int64_t
SrsHttpFileReader
::
tellg
()
{
return
0
;
}
void
SrsHttpFileReader
::
skip
(
int64_t
/*size*/
)
{
}
int64_t
SrsHttpFileReader
::
lseek
(
int64_t
offset
)
{
return
offset
;
}
int64_t
SrsHttpFileReader
::
filesize
()
{
return
0
;
}
int
SrsHttpFileReader
::
read
(
void
*
buf
,
size_t
count
,
ssize_t
*
pnread
)
{
int
ret
=
ERROR_SUCCESS
;
if
(
http
->
eof
())
{
ret
=
ERROR_HTTP_REQUEST_EOF
;
srs_error
(
"flv: encoder EOF. ret=%d"
,
ret
);
return
ret
;
}
int
nread
=
0
;
if
((
ret
=
http
->
read
((
char
*
)
buf
,
(
int
)
count
,
&
nread
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
if
(
pnread
)
{
*
pnread
=
nread
;
}
return
ret
;
}
#endif
...
...
trunk/src/app/srs_app_caster_flv.hpp
查看文件 @
ba6c313
...
...
@@ -44,7 +44,11 @@ class SrsHttpConn;
#include <srs_app_conn.hpp>
#include <srs_app_http.hpp>
#include <srs_app_http_conn.hpp>
#include <srs_kernel_file.hpp>
/**
* the stream caster for flv stream over HTTP POST.
*/
class
SrsAppCasterFlv
:
virtual
public
ISrsTcpHandler
,
virtual
public
IConnectionManager
,
virtual
public
ISrsHttpHandler
{
...
...
@@ -68,6 +72,9 @@ public:
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
/**
* the dynamic http connection, never drop the body.
*/
class
SrsDynamicHttpConn
:
public
SrsHttpConn
{
public
:
...
...
@@ -77,6 +84,38 @@ public:
virtual
int
on_got_http_message
(
SrsHttpMessage
*
msg
);
};
/**
* the http wrapper for file reader,
* to read http post stream like a file.
*/
class
SrsHttpFileReader
:
public
SrsFileReader
{
private
:
ISrsHttpResponseReader
*
http
;
public
:
SrsHttpFileReader
(
ISrsHttpResponseReader
*
h
);
virtual
~
SrsHttpFileReader
();
public
:
/**
* open file reader, can open then close then open...
*/
virtual
int
open
(
std
::
string
file
);
virtual
void
close
();
public
:
// TODO: FIXME: extract interface.
virtual
bool
is_open
();
virtual
int64_t
tellg
();
virtual
void
skip
(
int64_t
size
);
virtual
int64_t
lseek
(
int64_t
offset
);
virtual
int64_t
filesize
();
public
:
/**
* read from file.
* @param pnread the output nb_read, NULL to ignore.
*/
virtual
int
read
(
void
*
buf
,
size_t
count
,
ssize_t
*
pnread
);
};
#endif
#endif
...
...
trunk/src/kernel/srs_kernel_error.hpp
查看文件 @
ba6c313
...
...
@@ -255,6 +255,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define ERROR_HTTP_INVALID_CHUNK_HEADER 4026
#define ERROR_AVC_NALU_UEV 4027
#define ERROR_AAC_BYTES_INVALID 4028
#define ERROR_HTTP_REQUEST_EOF 4029
///////////////////////////////////////////////////////
// user-define error.
...
...
请
注册
或
登录
后发表评论