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-03-02 18:33:32 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c1086f8a9d51bbd04828b2cb997400804fa1e9a6
c1086f8a
1 parent
efa09102
srs-librtmp: finish the simple publish and play sample.
隐藏空白字符变更
内嵌
并排对比
正在显示
6 个修改的文件
包含
110 行增加
和
10 行删除
trunk/research/librtmp/srs_play.c
trunk/research/librtmp/srs_publish.c
trunk/src/app/srs_core_source.cpp
trunk/src/libs/srs_librtmp.cpp
trunk/src/rtmp/srs_protocol_rtmp_stack.cpp
trunk/src/rtmp/srs_protocol_rtmp_stack.hpp
trunk/research/librtmp/srs_play.c
查看文件 @
c1086f8
...
...
@@ -25,6 +25,8 @@ gcc srs_play.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_play
*/
#include <stdio.h>
#include <stdlib.h>
#include "../../objs/include/srs_librtmp.h"
int
main
(
int
argc
,
char
**
argv
)
...
...
@@ -33,14 +35,14 @@ int main(int argc, char** argv)
// packet data
int
type
,
size
;
u_int32_t
timestamp
;
u_int32_t
timestamp
=
0
;
char
*
data
;
printf
(
"suck rtmp stream like rtmpdump
\n
"
);
printf
(
"srs(simple-rtmp-server) client librtmp library.
\n
"
);
printf
(
"version: %d.%d.%d
\n
"
,
srs_version_major
(),
srs_version_minor
(),
srs_version_revision
());
rtmp
=
srs_rtmp_create
(
"rtmp://127.0.0.1:1935/live
?vhost=__defaultVhost__
/livestream"
);
rtmp
=
srs_rtmp_create
(
"rtmp://127.0.0.1:1935/live/livestream"
);
if
(
srs_simple_handshake
(
rtmp
)
!=
0
)
{
printf
(
"simple handshake failed.
\n
"
);
...
...
trunk/research/librtmp/srs_publish.c
查看文件 @
c1086f8
...
...
@@ -25,12 +25,20 @@ gcc srs_publish.c ../../objs/lib/srs_librtmp.a -g -O0 -lstdc++ -o srs_publish
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "../../objs/include/srs_librtmp.h"
int
main
(
int
argc
,
char
**
argv
)
{
srs_rtmp_t
rtmp
;
// packet data
int
type
,
size
;
u_int32_t
timestamp
=
0
;
char
*
data
;
printf
(
"publish rtmp stream to server like FMLE/FFMPEG/Encoder
\n
"
);
printf
(
"srs(simple-rtmp-server) client librtmp library.
\n
"
);
printf
(
"version: %d.%d.%d
\n
"
,
srs_version_major
(),
srs_version_minor
(),
srs_version_revision
());
...
...
@@ -55,6 +63,20 @@ int main(int argc, char** argv)
}
printf
(
"publish stream success
\n
"
);
for
(;;)
{
type
=
SRS_RTMP_TYPE_VIDEO
;
timestamp
+=
40
;
size
=
4096
;
data
=
(
char
*
)
malloc
(
4096
);
if
(
srs_write_packet
(
rtmp
,
type
,
timestamp
,
data
,
size
)
!=
0
)
{
goto
rtmp_destroy
;
}
printf
(
"sent packet: type=%s, time=%d, size=%d
\n
"
,
srs_type2string
(
type
),
timestamp
,
size
);
usleep
(
40
*
1000
);
}
rtmp_destroy:
srs_rtmp_destroy
(
rtmp
);
...
...
trunk/src/app/srs_core_source.cpp
查看文件 @
c1086f8
...
...
@@ -677,7 +677,7 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata
cache_metadata
=
new
SrsSharedPtrMessage
();
// dump message to shared ptr message.
if
((
ret
=
cache_metadata
->
initialize
(
msg
,
payload
,
size
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
cache_metadata
->
initialize
(
&
msg
->
header
,
payload
,
size
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"initialize the cache metadata failed. ret=%d"
,
ret
);
return
ret
;
}
...
...
trunk/src/libs/srs_librtmp.cpp
查看文件 @
c1086f8
...
...
@@ -328,6 +328,51 @@ int srs_read_packet(srs_rtmp_t rtmp, int* type, u_int32_t* timestamp, char** dat
int
srs_write_packet
(
srs_rtmp_t
rtmp
,
int
type
,
u_int32_t
timestamp
,
char
*
data
,
int
size
)
{
int
ret
=
ERROR_SUCCESS
;
srs_assert
(
rtmp
!=
NULL
);
Context
*
context
=
(
Context
*
)
rtmp
;
SrsSharedPtrMessage
*
msg
=
NULL
;
if
(
type
==
SRS_RTMP_TYPE_AUDIO
)
{
SrsMessageHeader
header
;
header
.
initialize_audio
(
size
,
timestamp
,
context
->
stream_id
);
msg
=
new
SrsSharedPtrMessage
();
if
((
ret
=
msg
->
initialize
(
&
header
,
data
,
size
))
!=
ERROR_SUCCESS
)
{
srs_freepa
(
data
);
return
ret
;
}
}
else
if
(
type
==
SRS_RTMP_TYPE_VIDEO
)
{
SrsMessageHeader
header
;
header
.
initialize_video
(
size
,
timestamp
,
context
->
stream_id
);
msg
=
new
SrsSharedPtrMessage
();
if
((
ret
=
msg
->
initialize
(
&
header
,
data
,
size
))
!=
ERROR_SUCCESS
)
{
srs_freepa
(
data
);
return
ret
;
}
}
else
if
(
type
==
SRS_RTMP_TYPE_SCRIPT
)
{
SrsMessageHeader
header
;
header
.
initialize_amf0_script
(
size
,
context
->
stream_id
);
msg
=
new
SrsSharedPtrMessage
();
if
((
ret
=
msg
->
initialize
(
&
header
,
data
,
size
))
!=
ERROR_SUCCESS
)
{
srs_freepa
(
data
);
return
ret
;
}
}
if
(
msg
)
{
// send out encoded msg.
if
((
ret
=
context
->
rtmp
->
send_message
(
msg
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
}
else
{
// directly free data if not sent out.
srs_freepa
(
data
);
}
return
ret
;
}
...
...
trunk/src/rtmp/srs_protocol_rtmp_stack.cpp
查看文件 @
c1086f8
...
...
@@ -1193,6 +1193,33 @@ bool SrsMessageHeader::is_user_control_message()
return
message_type
==
RTMP_MSG_UserControlMessage
;
}
void
SrsMessageHeader
::
initialize_amf0_script
(
int
size
,
int
stream
)
{
message_type
=
RTMP_MSG_AMF0DataMessage
;
payload_length
=
(
int32_t
)
size
;
timestamp_delta
=
(
int32_t
)
0
;
timestamp
=
(
int64_t
)
0
;
stream_id
=
(
int32_t
)
stream
;
}
void
SrsMessageHeader
::
initialize_audio
(
int
size
,
u_int32_t
time
,
int
stream
)
{
message_type
=
RTMP_MSG_AudioMessage
;
payload_length
=
(
int32_t
)
size
;
timestamp_delta
=
(
int32_t
)
time
;
timestamp
=
(
int64_t
)
time
;
stream_id
=
(
int32_t
)
stream
;
}
void
SrsMessageHeader
::
initialize_video
(
int
size
,
u_int32_t
time
,
int
stream
)
{
message_type
=
RTMP_MSG_VideoMessage
;
payload_length
=
(
int32_t
)
size
;
timestamp_delta
=
(
int32_t
)
time
;
timestamp
=
(
int64_t
)
time
;
stream_id
=
(
int32_t
)
stream
;
}
SrsChunkStream
::
SrsChunkStream
(
int
_cid
)
{
fmt
=
0
;
...
...
@@ -1516,7 +1543,7 @@ int SrsSharedPtrMessage::initialize(SrsCommonMessage* source)
{
int
ret
=
ERROR_SUCCESS
;
if
((
ret
=
initialize
(
source
,
(
char
*
)
source
->
payload
,
source
->
size
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
initialize
(
&
source
->
header
,
(
char
*
)
source
->
payload
,
source
->
size
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
@@ -1527,7 +1554,7 @@ int SrsSharedPtrMessage::initialize(SrsCommonMessage* source)
return
ret
;
}
int
SrsSharedPtrMessage
::
initialize
(
Srs
CommonMessage
*
source
,
char
*
payload
,
int
size
)
int
SrsSharedPtrMessage
::
initialize
(
Srs
MessageHeader
*
source
,
char
*
payload
,
int
size
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -1540,7 +1567,7 @@ int SrsSharedPtrMessage::initialize(SrsCommonMessage* source, char* payload, int
return
ret
;
}
header
=
source
->
header
;
header
=
*
source
;
header
.
payload_length
=
size
;
ptr
=
new
SrsSharedPtr
();
...
...
@@ -1549,9 +1576,9 @@ int SrsSharedPtrMessage::initialize(SrsCommonMessage* source, char* payload, int
ptr
->
payload
=
payload
;
ptr
->
size
=
size
;
if
(
source
->
header
.
is_video
())
{
if
(
source
->
is_video
())
{
ptr
->
perfer_cid
=
RTMP_CID_Video
;
}
else
if
(
source
->
header
.
is_audio
())
{
}
else
if
(
source
->
is_audio
())
{
ptr
->
perfer_cid
=
RTMP_CID_Audio
;
}
else
{
ptr
->
perfer_cid
=
RTMP_CID_OverConnection2
;
...
...
trunk/src/rtmp/srs_protocol_rtmp_stack.hpp
查看文件 @
c1086f8
...
...
@@ -262,6 +262,10 @@ struct SrsMessageHeader
bool
is_window_ackledgement_size
();
bool
is_set_chunk_size
();
bool
is_user_control_message
();
void
initialize_amf0_script
(
int
size
,
int
stream
);
void
initialize_audio
(
int
size
,
u_int32_t
time
,
int
stream
);
void
initialize_video
(
int
size
,
u_int32_t
time
,
int
stream
);
};
/**
...
...
@@ -434,9 +438,9 @@ public:
virtual
int
initialize
(
SrsCommonMessage
*
source
);
/**
* set the shared payload.
*
we will use the payload, donot use the payload of source
.
*
use source header, and specified param payload
.
*/
virtual
int
initialize
(
Srs
CommonMessage
*
source
,
char
*
payload
,
int
size
);
virtual
int
initialize
(
Srs
MessageHeader
*
source
,
char
*
payload
,
int
size
);
virtual
SrsSharedPtrMessage
*
copy
();
public
:
/**
...
...
请
注册
或
登录
后发表评论