Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
red5-server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Otmane Mabrouk
red5-server
Commits
1cb7dd4a
Commit
1cb7dd4a
authored
2 years ago
by
Paul Gregoire
Browse files
Options
Downloads
Patches
Plain Diff
Refactoring decode packet and header
parent
76d3194a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/src/main/java/org/red5/server/net/rtmp/codec/RTMPProtocolDecoder.java
+28
-24
28 additions, 24 deletions
...a/org/red5/server/net/rtmp/codec/RTMPProtocolDecoder.java
with
28 additions
and
24 deletions
common/src/main/java/org/red5/server/net/rtmp/codec/RTMPProtocolDecoder.java
+
28
−
24
View file @
1cb7dd4a
...
...
@@ -226,31 +226,16 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
RTMP
rtmp
=
conn
.
getState
();
// read the chunk header (variable from 1-3 bytes)
final
ChunkHeader
chunkHeader
=
ChunkHeader
.
read
(
in
);
// represents "packet" header length via "format" only 1 byte in the chunk header is needed here
int
headerLength
=
RTMPUtils
.
getHeaderLength
(
chunkHeader
.
getFormat
());
headerLength
+=
chunkHeader
.
getSize
()
-
1
;
if
(
in
.
remaining
()
<
headerLength
||
in
.
remaining
()
<
3
)
{
state
.
bufferDecoding
(
headerLength
-
in
.
remaining
());
in
.
position
(
position
);
return
null
;
}
else
{
int
currentPostition
=
in
.
position
();
// medium int is 3 bytes
int
timeBase
=
RTMPUtils
.
readUnsignedMediumInt
(
in
);
in
.
position
(
currentPostition
);
if
(
timeBase
>=
MEDIUM_INT_MAX
)
{
headerLength
+=
4
;
if
(
in
.
remaining
()
<
headerLength
)
{
state
.
bufferDecoding
(
headerLength
-
in
.
remaining
());
in
.
position
(
position
);
final
Header
header
=
decodeHeader
(
chunkHeader
,
state
,
in
,
rtmp
,
position
);
// header is null if we were unable to decode it, we may just need more data
if
(
header
==
null
)
{
// we were unable to decode the header, return null
return
null
;
}
}
}
final
Header
header
=
decodeHeader
(
chunkHeader
,
state
,
in
,
rtmp
);
// get the channel id
final
int
channelId
=
header
!=
null
?
header
.
getChannelId
()
:
chunkHeader
.
getChannelId
();
if
(
header
==
null
||
header
.
isEmpty
())
{
// header empty vs header null will return the NS_FAILED message
if
(
header
.
isEmpty
())
{
if
(
log
.
isTraceEnabled
())
{
log
.
trace
(
"Header was null or empty - chh: {}"
,
chunkHeader
);
}
...
...
@@ -366,7 +351,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
* RTMP object to get last header
* @return Decoded header
*/
public
Header
decodeHeader
(
ChunkHeader
chh
,
RTMPDecodeState
state
,
IoBuffer
in
,
RTMP
rtmp
)
{
public
Header
decodeHeader
(
ChunkHeader
chh
,
RTMPDecodeState
state
,
IoBuffer
in
,
RTMP
rtmp
,
int
startPostion
)
{
//if (log.isTraceEnabled()) {
//log.trace("decodeHeader - chh: {} input: {}", chh, Hex.encodeHexString(Arrays.copyOfRange(in.array(), in.position(), in.limit())));
//log.trace("decodeHeader - chh: {}", chh);
...
...
@@ -374,6 +359,27 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
final
int
channelId
=
chh
.
getChannelId
();
// identifies the header type of the four types
final
byte
headerSize
=
chh
.
getFormat
();
// represents "packet" header length via "format" only 1 byte in the chunk header is needed here
int
headerLength
=
RTMPUtils
.
getHeaderLength
(
headerSize
);
headerLength
+=
chh
.
getSize
()
-
1
;
if
(
in
.
remaining
()
<
headerLength
||
in
.
remaining
()
<
3
)
{
state
.
bufferDecoding
(
headerLength
-
in
.
remaining
());
in
.
position
(
startPostion
);
return
null
;
}
else
{
int
currentPostition
=
in
.
position
();
// medium int is 3 bytes
int
timeBase
=
RTMPUtils
.
readUnsignedMediumInt
(
in
);
in
.
position
(
currentPostition
);
if
(
timeBase
>=
MEDIUM_INT_MAX
)
{
headerLength
+=
4
;
if
(
in
.
remaining
()
<
headerLength
)
{
state
.
bufferDecoding
(
headerLength
-
in
.
remaining
());
in
.
position
(
startPostion
);
return
null
;
}
}
}
Header
lastHeader
=
rtmp
.
getLastReadHeader
(
channelId
);
if
(
log
.
isTraceEnabled
())
{
log
.
trace
(
"{} lastHeader: {}"
,
Header
.
HeaderType
.
values
()[
headerSize
],
lastHeader
);
...
...
@@ -392,8 +398,6 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
return
null
;
}
}
int
headerLength
=
RTMPUtils
.
getHeaderLength
(
headerSize
);
headerLength
+=
chh
.
getSize
()
-
1
;
// if (log.isTraceEnabled()) {
// log.trace("headerLength: {}", headerLength);
// }
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment