Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
6d1c9945
Commit
6d1c9945
authored
Jul 21, 2012
by
Samuel Pitoiset
Committed by
Martin Storsjö
Jul 25, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rtmp: Factorize the code by adding handle_invoke
Signed-off-by:
Martin Storsjö
<
martin@martin.st
>
parent
7be2a7d8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
66 deletions
+77
-66
rtmpproto.c
libavformat/rtmpproto.c
+77
-66
No files found.
libavformat/rtmpproto.c
View file @
6d1c9945
...
...
@@ -953,50 +953,23 @@ static int handle_server_bw(URLContext *s, RTMPPacket *pkt)
return
0
;
}
/**
* Parse received packet and possibly perform some action depending on
* the packet contents.
* @return 0 for no errors, negative values for serious errors which prevent
* further communications, positive values for uncritical errors
*/
static
int
rtmp_parse_result
(
URLContext
*
s
,
RTMPContext
*
rt
,
RTMPPacket
*
pkt
)
static
int
handle_invoke
(
URLContext
*
s
,
RTMPPacket
*
pkt
)
{
RTMPContext
*
rt
=
s
->
priv_data
;
int
i
,
t
;
const
uint8_t
*
data_end
=
pkt
->
data
+
pkt
->
data_size
;
int
ret
;
#ifdef DEBUG
ff_rtmp_packet_dump
(
s
,
pkt
);
#endif
//TODO: check for the messages sent for wrong state?
if
(
!
memcmp
(
pkt
->
data
,
"
\002\000\006
_error"
,
9
))
{
uint8_t
tmpstr
[
256
];
switch
(
pkt
->
type
)
{
case
RTMP_PT_CHUNK_SIZE
:
if
((
ret
=
handle_chunk_size
(
s
,
pkt
))
<
0
)
return
ret
;
break
;
case
RTMP_PT_PING
:
if
((
ret
=
handle_ping
(
s
,
pkt
))
<
0
)
return
ret
;
break
;
case
RTMP_PT_CLIENT_BW
:
if
((
ret
=
handle_client_bw
(
s
,
pkt
))
<
0
)
return
ret
;
break
;
case
RTMP_PT_SERVER_BW
:
if
((
ret
=
handle_server_bw
(
s
,
pkt
))
<
0
)
return
ret
;
break
;
case
RTMP_PT_INVOKE
:
//TODO: check for the messages sent for wrong state?
if
(
!
memcmp
(
pkt
->
data
,
"
\002\000\006
_error"
,
9
))
{
uint8_t
tmpstr
[
256
];
if
(
!
ff_amf_get_field_value
(
pkt
->
data
+
9
,
data_end
,
"description"
,
tmpstr
,
sizeof
(
tmpstr
)))
av_log
(
s
,
AV_LOG_ERROR
,
"Server error: %s
\n
"
,
tmpstr
);
return
-
1
;
}
else
if
(
!
memcmp
(
pkt
->
data
,
"
\002\000\007
_result"
,
10
))
{
switch
(
rt
->
state
)
{
if
(
!
ff_amf_get_field_value
(
pkt
->
data
+
9
,
data_end
,
"description"
,
tmpstr
,
sizeof
(
tmpstr
)))
av_log
(
s
,
AV_LOG_ERROR
,
"Server error: %s
\n
"
,
tmpstr
);
return
-
1
;
}
else
if
(
!
memcmp
(
pkt
->
data
,
"
\002\000\007
_result"
,
10
))
{
switch
(
rt
->
state
)
{
case
STATE_HANDSHAKED
:
if
(
!
rt
->
is_input
)
{
if
((
ret
=
gen_release_stream
(
s
,
rt
))
<
0
)
...
...
@@ -1044,35 +1017,73 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
}
rt
->
state
=
STATE_READY
;
break
;
}
}
else
if
(
!
memcmp
(
pkt
->
data
,
"
\002\000\010
onStatus"
,
11
))
{
const
uint8_t
*
ptr
=
pkt
->
data
+
11
;
uint8_t
tmpstr
[
256
];
for
(
i
=
0
;
i
<
2
;
i
++
)
{
t
=
ff_amf_tag_size
(
ptr
,
data_end
);
if
(
t
<
0
)
return
1
;
ptr
+=
t
;
}
t
=
ff_amf_get_field_value
(
ptr
,
data_end
,
"level"
,
tmpstr
,
sizeof
(
tmpstr
));
if
(
!
t
&&
!
strcmp
(
tmpstr
,
"error"
))
{
if
(
!
ff_amf_get_field_value
(
ptr
,
data_end
,
"description"
,
tmpstr
,
sizeof
(
tmpstr
)))
av_log
(
s
,
AV_LOG_ERROR
,
"Server error: %s
\n
"
,
tmpstr
);
return
-
1
;
}
t
=
ff_amf_get_field_value
(
ptr
,
data_end
,
"code"
,
tmpstr
,
sizeof
(
tmpstr
));
if
(
!
t
&&
!
strcmp
(
tmpstr
,
"NetStream.Play.Start"
))
rt
->
state
=
STATE_PLAYING
;
if
(
!
t
&&
!
strcmp
(
tmpstr
,
"NetStream.Play.Stop"
))
rt
->
state
=
STATE_STOPPED
;
if
(
!
t
&&
!
strcmp
(
tmpstr
,
"NetStream.Play.UnpublishNotify"
))
rt
->
state
=
STATE_STOPPED
;
if
(
!
t
&&
!
strcmp
(
tmpstr
,
"NetStream.Publish.Start"
))
rt
->
state
=
STATE_PUBLISHING
;
}
else
if
(
!
memcmp
(
pkt
->
data
,
"
\002\000\010
onBWDone"
,
11
))
{
if
((
ret
=
gen_check_bw
(
s
,
rt
))
<
0
)
return
ret
;
}
}
else
if
(
!
memcmp
(
pkt
->
data
,
"
\002\000\010
onStatus"
,
11
))
{
const
uint8_t
*
ptr
=
pkt
->
data
+
11
;
uint8_t
tmpstr
[
256
];
for
(
i
=
0
;
i
<
2
;
i
++
)
{
t
=
ff_amf_tag_size
(
ptr
,
data_end
);
if
(
t
<
0
)
return
1
;
ptr
+=
t
;
}
t
=
ff_amf_get_field_value
(
ptr
,
data_end
,
"level"
,
tmpstr
,
sizeof
(
tmpstr
));
if
(
!
t
&&
!
strcmp
(
tmpstr
,
"error"
))
{
if
(
!
ff_amf_get_field_value
(
ptr
,
data_end
,
"description"
,
tmpstr
,
sizeof
(
tmpstr
)))
av_log
(
s
,
AV_LOG_ERROR
,
"Server error: %s
\n
"
,
tmpstr
);
return
-
1
;
}
t
=
ff_amf_get_field_value
(
ptr
,
data_end
,
"code"
,
tmpstr
,
sizeof
(
tmpstr
));
if
(
!
t
&&
!
strcmp
(
tmpstr
,
"NetStream.Play.Start"
))
rt
->
state
=
STATE_PLAYING
;
if
(
!
t
&&
!
strcmp
(
tmpstr
,
"NetStream.Play.Stop"
))
rt
->
state
=
STATE_STOPPED
;
if
(
!
t
&&
!
strcmp
(
tmpstr
,
"NetStream.Play.UnpublishNotify"
))
rt
->
state
=
STATE_STOPPED
;
if
(
!
t
&&
!
strcmp
(
tmpstr
,
"NetStream.Publish.Start"
))
rt
->
state
=
STATE_PUBLISHING
;
}
else
if
(
!
memcmp
(
pkt
->
data
,
"
\002\000\010
onBWDone"
,
11
))
{
if
((
ret
=
gen_check_bw
(
s
,
rt
))
<
0
)
return
ret
;
}
return
0
;
}
/**
* Parse received packet and possibly perform some action depending on
* the packet contents.
* @return 0 for no errors, negative values for serious errors which prevent
* further communications, positive values for uncritical errors
*/
static
int
rtmp_parse_result
(
URLContext
*
s
,
RTMPContext
*
rt
,
RTMPPacket
*
pkt
)
{
int
ret
;
#ifdef DEBUG
ff_rtmp_packet_dump
(
s
,
pkt
);
#endif
switch
(
pkt
->
type
)
{
case
RTMP_PT_CHUNK_SIZE
:
if
((
ret
=
handle_chunk_size
(
s
,
pkt
))
<
0
)
return
ret
;
break
;
case
RTMP_PT_PING
:
if
((
ret
=
handle_ping
(
s
,
pkt
))
<
0
)
return
ret
;
break
;
case
RTMP_PT_CLIENT_BW
:
if
((
ret
=
handle_client_bw
(
s
,
pkt
))
<
0
)
return
ret
;
break
;
case
RTMP_PT_SERVER_BW
:
if
((
ret
=
handle_server_bw
(
s
,
pkt
))
<
0
)
return
ret
;
break
;
case
RTMP_PT_INVOKE
:
if
((
ret
=
handle_invoke
(
s
,
pkt
))
<
0
)
return
ret
;
break
;
case
RTMP_PT_VIDEO
:
case
RTMP_PT_AUDIO
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment