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-09 20:37:20 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
387be8fa3b6b73b6e02b13c753214764a2d927a9
387be8fa
1 parent
9521fbfa
change to 0.9.15, finish amf0 utest
隐藏空白字符变更
内嵌
并排对比
正在显示
3 个修改的文件
包含
155 行增加
和
9 行删除
trunk/src/core/srs_core.hpp
trunk/src/rtmp/srs_protocol_amf0.cpp
trunk/src/utest/srs_utest_amf0.cpp
trunk/src/core/srs_core.hpp
查看文件 @
387be8f
...
...
@@ -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 "1
4
"
#define VERSION_REVISION "1
5
"
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
// server info.
#define RTMP_SIG_SRS_KEY "srs"
...
...
trunk/src/rtmp/srs_protocol_amf0.cpp
查看文件 @
387be8f
...
...
@@ -1174,14 +1174,15 @@ int srs_amf0_read_utf8(SrsStream* stream, string& value)
// support utf8-1 only
// 1.3.1 Strings and UTF-8
// UTF8-1 = %x00-7F
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
// TODO: support other utf-8 strings
/*for (int i = 0; i < len; i++) {
char ch = *(str.data() + i);
if ((ch & 0x80) != 0) {
ret = ERROR_RTMP_AMF0_DECODE;
srs_error("ignored. only support utf8-1, 0x00-0x7F, actual is %#x. ret=%d", (int)ch, ret);
ret = ERROR_SUCCESS;
}
}
}
*/
value
=
str
;
srs_verbose
(
"amf0 read string data success. str=%s"
,
str
.
c_str
());
...
...
trunk/src/utest/srs_utest_amf0.cpp
查看文件 @
387be8f
...
...
@@ -22,11 +22,156 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <srs_utest_amf0.hpp>
#include <string>
using
namespace
std
;
#include <srs_core_autofree.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_stream.hpp>
VOID
TEST
(
AMF0Test
,
Size
)
// user scenario: coding and decoding with amf0
VOID
TEST
(
AMF0Test
,
ScenarioMain
)
{
// coded amf0 object
int
nb_bytes
=
0
;
char
*
bytes
=
NULL
;
// coding data to binaries by amf0
// for example, send connect app response to client.
if
(
true
)
{
// props: object
// fmsVer: string
// capabilities: number
// mode: number
// info: object
// level: string
// code: string
// descrption: string
// objectEncoding: number
// data: array
// version: string
// srs_sig: string
SrsAmf0Object
*
props
=
SrsAmf0Any
::
object
();
SrsAutoFree
(
SrsAmf0Object
,
props
,
false
);
props
->
set
(
"fmsVer"
,
SrsAmf0Any
::
str
(
"FMS/3,5,3,888"
));
props
->
set
(
"capabilities"
,
SrsAmf0Any
::
number
(
253
));
props
->
set
(
"mode"
,
SrsAmf0Any
::
number
(
123
));
SrsAmf0Object
*
info
=
SrsAmf0Any
::
object
();
SrsAutoFree
(
SrsAmf0Object
,
info
,
false
);
info
->
set
(
"level"
,
SrsAmf0Any
::
str
(
"info"
));
info
->
set
(
"code"
,
SrsAmf0Any
::
str
(
"NetStream.Connnect.Success"
));
info
->
set
(
"descrption"
,
SrsAmf0Any
::
str
(
"connected"
));
info
->
set
(
"objectEncoding"
,
SrsAmf0Any
::
number
(
3
));
SrsAmf0EcmaArray
*
data
=
SrsAmf0Any
::
ecma_array
();
info
->
set
(
"data"
,
data
);
data
->
set
(
"version"
,
SrsAmf0Any
::
str
(
"FMS/3,5,3,888"
));
data
->
set
(
"srs_sig"
,
SrsAmf0Any
::
str
(
"srs"
));
// buf store the serialized props/info
nb_bytes
=
props
->
total_size
()
+
info
->
total_size
();
ASSERT_GT
(
nb_bytes
,
0
);
bytes
=
new
char
[
nb_bytes
];
// use SrsStream to write props/info to binary buf.
SrsStream
s
;
EXPECT_EQ
(
ERROR_SUCCESS
,
s
.
initialize
(
bytes
,
nb_bytes
));
EXPECT_EQ
(
ERROR_SUCCESS
,
props
->
write
(
&
s
));
EXPECT_EQ
(
ERROR_SUCCESS
,
info
->
write
(
&
s
));
EXPECT_TRUE
(
s
.
empty
());
// now, user can use the buf
EXPECT_EQ
(
0x03
,
bytes
[
0
]);
EXPECT_EQ
(
0x09
,
bytes
[
nb_bytes
-
1
]);
}
SrsAutoFree
(
char
,
bytes
,
true
);
// decoding amf0 object from bytes
// when user know the schema
if
(
true
)
{
ASSERT_TRUE
(
NULL
!=
bytes
);
// use SrsStream to assist amf0 object to read from bytes.
SrsStream
s
;
EXPECT_EQ
(
ERROR_SUCCESS
,
s
.
initialize
(
bytes
,
nb_bytes
));
// decoding
// if user know the schema, for instance, it's an amf0 object,
// user can use specified object to decoding.
SrsAmf0Object
*
props
=
SrsAmf0Any
::
object
();
SrsAutoFree
(
SrsAmf0Object
,
props
,
false
);
EXPECT_EQ
(
ERROR_SUCCESS
,
props
->
read
(
&
s
));
// user can use specified object to decoding.
SrsAmf0Object
*
info
=
SrsAmf0Any
::
object
();
SrsAutoFree
(
SrsAmf0Object
,
info
,
false
);
EXPECT_EQ
(
ERROR_SUCCESS
,
info
->
read
(
&
s
));
// use the decoded data.
SrsAmf0Any
*
prop
=
NULL
;
// if user requires specified property, use ensure of amf0 object
EXPECT_TRUE
(
NULL
!=
(
prop
=
props
->
ensure_property_string
(
"fmsVer"
)));
// the property can assert to string.
ASSERT_TRUE
(
prop
->
is_string
());
// get the prop string value.
EXPECT_STREQ
(
"FMS/3,5,3,888"
,
prop
->
to_str
().
c_str
());
// get other type property value
EXPECT_TRUE
(
NULL
!=
(
prop
=
info
->
get_property
(
"data"
)));
// we cannot assert the property is ecma array
if
(
prop
->
is_ecma_array
())
{
SrsAmf0EcmaArray
*
data
=
prop
->
to_ecma_array
();
// it must be a ecma array.
ASSERT_TRUE
(
NULL
!=
data
);
// get property of array
EXPECT_TRUE
(
NULL
!=
(
prop
=
data
->
ensure_property_string
(
"srs_sig"
)));
ASSERT_TRUE
(
prop
->
is_string
());
EXPECT_STREQ
(
"srs"
,
prop
->
to_str
().
c_str
());
}
// confidence about the schema
EXPECT_TRUE
(
NULL
!=
(
prop
=
info
->
ensure_property_string
(
"level"
)));
ASSERT_TRUE
(
prop
->
is_string
());
EXPECT_STREQ
(
"info"
,
prop
->
to_str
().
c_str
());
}
// use any to decoding it,
// if user donot know the schema
if
(
true
)
{
ASSERT_TRUE
(
NULL
!=
bytes
);
// use SrsStream to assist amf0 object to read from bytes.
SrsStream
s
;
EXPECT_EQ
(
ERROR_SUCCESS
,
s
.
initialize
(
bytes
,
nb_bytes
));
// decoding a amf0 any, for user donot know
SrsAmf0Any
*
any
=
NULL
;
EXPECT_EQ
(
ERROR_SUCCESS
,
srs_amf0_read_any
(
&
s
,
&
any
));
SrsAutoFree
(
SrsAmf0Any
,
any
,
false
);
// for amf0 object
if
(
any
->
is_object
())
{
SrsAmf0Object
*
obj
=
any
->
to_object
();
ASSERT_TRUE
(
NULL
!=
obj
);
// use foreach to process properties
for
(
int
i
=
0
;
i
<
obj
->
count
();
++
i
)
{
string
name
=
obj
->
key_at
(
i
);
SrsAmf0Any
*
value
=
obj
->
value_at
(
i
);
// use the property name
EXPECT_TRUE
(
""
!=
name
);
// use the property value
EXPECT_TRUE
(
NULL
!=
value
);
}
}
}
}
VOID
TEST
(
AMF0Test
,
ApiSize
)
{
// size of elem
EXPECT_EQ
(
2
+
6
,
SrsAmf0Size
::
utf8
(
"winlin"
));
...
...
@@ -282,7 +427,7 @@ VOID TEST(AMF0Test, Size)
}
}
VOID
TEST
(
AMF0Test
,
AnyElem
)
VOID
TEST
(
AMF0Test
,
A
piA
nyElem
)
{
SrsAmf0Any
*
o
=
NULL
;
...
...
@@ -365,7 +510,7 @@ VOID TEST(AMF0Test, AnyElem)
}
}
VOID
TEST
(
AMF0Test
,
AnyIO
)
VOID
TEST
(
AMF0Test
,
A
piA
nyIO
)
{
SrsStream
s
;
SrsAmf0Any
*
o
=
NULL
;
...
...
@@ -675,7 +820,7 @@ VOID TEST(AMF0Test, AnyIO)
}
}
VOID
TEST
(
AMF0Test
,
AnyAssert
)
VOID
TEST
(
AMF0Test
,
A
piA
nyAssert
)
{
SrsStream
s
;
SrsAmf0Any
*
o
=
NULL
;
...
...
@@ -749,7 +894,7 @@ VOID TEST(AMF0Test, AnyAssert)
}
}
VOID
TEST
(
AMF0Test
,
ObjectProps
)
VOID
TEST
(
AMF0Test
,
Api
ObjectProps
)
{
SrsAmf0Object
*
o
=
NULL
;
...
...
@@ -827,7 +972,7 @@ VOID TEST(AMF0Test, ObjectProps)
}
}
VOID
TEST
(
AMF0Test
,
EcmaArrayProps
)
VOID
TEST
(
AMF0Test
,
Api
EcmaArrayProps
)
{
SrsAmf0EcmaArray
*
o
=
NULL
;
...
...
请
注册
或
登录
后发表评论