Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libdvbpsi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
libdvbpsi
Commits
9f095dd9
Commit
9f095dd9
authored
Mar 28, 2011
by
Jean-Paul Saman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
src/dvbpsi.c: cleanup indentation
parent
c0ca06c3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
187 additions
and
187 deletions
+187
-187
src/dvbpsi.c
src/dvbpsi.c
+187
-187
No files found.
src/dvbpsi.c
View file @
9f095dd9
/*****************************************************************************
/*****************************************************************************
* dvbpsi.c: conversion from TS packets to PSI sections
* dvbpsi.c: conversion from TS packets to PSI sections
*----------------------------------------------------------------------------
*----------------------------------------------------------------------------
* Copyright (C) 2001-201
0
VideoLAN
* Copyright (C) 2001-201
1
VideoLAN
* $Id$
* $Id$
*
*
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
...
@@ -177,6 +177,7 @@ dvbpsi_decoder_t *dvbpsi_NewDecoder(dvbpsi_t *handle, dvbpsi_callback *callback)
...
@@ -177,6 +177,7 @@ dvbpsi_decoder_t *dvbpsi_NewDecoder(dvbpsi_t *handle, dvbpsi_callback *callback)
p_decoder
->
pf_callback
=
NULL
;
p_decoder
->
pf_callback
=
NULL
;
p_decoder
->
p_current_section
=
NULL
;
p_decoder
->
p_current_section
=
NULL
;
p_decoder
->
i_continuity_counter
=
0xFF
;
/* invalid CC */
return
p_decoder
;
return
p_decoder
;
}
}
...
@@ -213,226 +214,225 @@ bool dvbpsi_HasDecoder(dvbpsi_t *p_dvbpsi)
...
@@ -213,226 +214,225 @@ bool dvbpsi_HasDecoder(dvbpsi_t *p_dvbpsi)
*****************************************************************************/
*****************************************************************************/
void
dvbpsi_PushPacket
(
dvbpsi_t
*
handle
,
uint8_t
*
p_data
)
void
dvbpsi_PushPacket
(
dvbpsi_t
*
handle
,
uint8_t
*
p_data
)
{
{
uint8_t
i_expected_counter
;
/* Expected continuity counter */
uint8_t
i_expected_counter
;
/* Expected continuity counter */
dvbpsi_psi_section_t
*
p_section
;
/* Current section */
dvbpsi_psi_section_t
*
p_section
;
/* Current section */
uint8_t
*
p_payload_pos
;
/* Where in the TS packet */
uint8_t
*
p_payload_pos
;
/* Where in the TS packet */
uint8_t
*
p_new_pos
=
NULL
;
/* Beginning of the new section,
uint8_t
*
p_new_pos
=
NULL
;
/* Beginning of the new section,
updated to NULL when the new
updated to NULL when the new
section is handled */
section is handled */
int
i_available
;
/* Byte count available in the
int
i_available
;
/* Byte count available in the
packet */
packet */
dvbpsi_decoder_t
*
p_decoder
=
(
dvbpsi_decoder_t
*
)
handle
->
p_private
;
dvbpsi_decoder_t
*
p_decoder
=
(
dvbpsi_decoder_t
*
)
handle
->
p_private
;
assert
(
p_decoder
);
assert
(
p_decoder
);
assert
(
p_decoder
->
pf_callback
);
/* TS start code */
if
(
p_data
[
0
]
!=
0x47
)
/* TS start code */
{
if
(
p_data
[
0
]
!=
0x47
)
dvbpsi_error
(
handle
,
"PSI decoder"
,
"not a TS packet"
);
{
return
;
dvbpsi_error
(
handle
,
"PSI decoder"
,
"not a TS packet"
);
}
return
;
}
/* Continuity check */
i_expected_counter
=
(
p_decoder
->
i_continuity_counter
+
1
)
&
0xf
;
/* Continuity check */
p_decoder
->
i_continuity_counter
=
p_data
[
3
]
&
0xf
;
i_expected_counter
=
(
p_decoder
->
i_continuity_counter
+
1
)
&
0xf
;
p_decoder
->
i_continuity_counter
=
p_data
[
3
]
&
0xf
;
if
(
i_expected_counter
==
((
p_decoder
->
i_continuity_counter
+
1
)
&
0xf
)
&&
!
p_decoder
->
b_discontinuity
)
if
(
i_expected_counter
==
((
p_decoder
->
i_continuity_counter
+
1
)
&
0xf
)
{
&&
!
p_decoder
->
b_discontinuity
)
dvbpsi_error
(
handle
,
"PSI decoder"
,
{
dvbpsi_error
(
handle
,
"PSI decoder"
,
"TS duplicate (received %d, expected %d) for PID %d"
,
"TS duplicate (received %d, expected %d) for PID %d"
,
p_decoder
->
i_continuity_counter
,
i_expected_counter
,
p_decoder
->
i_continuity_counter
,
i_expected_counter
,
((
uint16_t
)(
p_data
[
1
]
&
0x1f
)
<<
8
)
|
p_data
[
2
]);
((
uint16_t
)(
p_data
[
1
]
&
0x1f
)
<<
8
)
|
p_data
[
2
]);
return
;
return
;
}
}
if
(
i_expected_counter
!=
p_decoder
->
i_continuity_counter
)
if
(
i_expected_counter
!=
p_decoder
->
i_continuity_counter
)
{
{
dvbpsi_error
(
handle
,
"PSI decoder"
,
dvbpsi_error
(
handle
,
"PSI decoder"
,
"TS discontinuity (received %d, expected %d) for PID %d"
,
"TS discontinuity (received %d, expected %d) for PID %d"
,
p_decoder
->
i_continuity_counter
,
i_expected_counter
,
p_decoder
->
i_continuity_counter
,
i_expected_counter
,
((
uint16_t
)(
p_data
[
1
]
&
0x1f
)
<<
8
)
|
p_data
[
2
]);
((
uint16_t
)(
p_data
[
1
]
&
0x1f
)
<<
8
)
|
p_data
[
2
]);
p_decoder
->
b_discontinuity
=
true
;
p_decoder
->
b_discontinuity
=
true
;
if
(
p_decoder
->
p_current_section
)
if
(
p_decoder
->
p_current_section
)
{
{
dvbpsi_DeletePSISections
(
p_decoder
->
p_current_section
);
dvbpsi_DeletePSISections
(
p_decoder
->
p_current_section
);
p_decoder
->
p_current_section
=
NULL
;
p_decoder
->
p_current_section
=
NULL
;
}
}
}
/* Return if no payload in the TS packet */
if
(
!
(
p_data
[
3
]
&
0x10
))
{
return
;
}
/* Skip the adaptation_field if present */
if
(
p_data
[
3
]
&
0x20
)
p_payload_pos
=
p_data
+
5
+
p_data
[
4
];
else
p_payload_pos
=
p_data
+
4
;
/* Unit start -> skip the pointer_field and a new section begins */
if
(
p_data
[
1
]
&
0x40
)
{
p_new_pos
=
p_payload_pos
+
*
p_payload_pos
+
1
;
p_payload_pos
+=
1
;
}
p_section
=
p_decoder
->
p_current_section
;
/* If the psi decoder needs a begginning of section and a new section
begins in the packet then initialize the dvbpsi_psi_section_t structure */
if
(
p_section
==
NULL
)
{
if
(
p_new_pos
)
{
/* Allocation of the structure */
p_decoder
->
p_current_section
=
p_section
=
dvbpsi_NewPSISection
(
p_decoder
->
i_section_max_size
);
/* Update the position in the packet */
p_payload_pos
=
p_new_pos
;
/* New section is being handled */
p_new_pos
=
NULL
;
/* Just need the header to know how long is the section */
p_decoder
->
i_need
=
3
;
p_decoder
->
b_complete_header
=
false
;
}
}
/* Return if no payload in the TS packet */
if
(
!
(
p_data
[
3
]
&
0x10
))
return
;
/* Skip the adaptation_field if present */
if
(
p_data
[
3
]
&
0x20
)
p_payload_pos
=
p_data
+
5
+
p_data
[
4
];
else
else
p_payload_pos
=
p_data
+
4
;
/* Unit start -> skip the pointer_field and a new section begins */
if
(
p_data
[
1
]
&
0x40
)
{
{
/* No new section => return */
p_new_pos
=
p_payload_pos
+
*
p_payload_pos
+
1
;
return
;
p_payload_pos
+=
1
;
}
}
}
/* Remaining bytes in the payload */
p_section
=
p_decoder
->
p_current_section
;
i_available
=
188
+
p_data
-
p_payload_pos
;
while
(
i_available
>
0
)
/* If the psi decoder needs a begginning of section and a new section
{
begins in the packet then initialize the dvbpsi_psi_section_t structure */
if
(
i_available
>=
p_decoder
->
i_need
)
if
(
p_section
==
NULL
)
{
{
/* There are enough bytes in this packet to complete the
if
(
p_new_pos
)
header/section */
memcpy
(
p_section
->
p_payload_end
,
p_payload_pos
,
p_decoder
->
i_need
);
p_payload_pos
+=
p_decoder
->
i_need
;
p_section
->
p_payload_end
+=
p_decoder
->
i_need
;
i_available
-=
p_decoder
->
i_need
;
if
(
!
p_decoder
->
b_complete_header
)
{
/* Header is complete */
p_decoder
->
b_complete_header
=
true
;
/* Compute p_section->i_length and update p_decoder->i_need */
p_decoder
->
i_need
=
p_section
->
i_length
=
((
uint16_t
)(
p_section
->
p_data
[
1
]
&
0xf
))
<<
8
|
p_section
->
p_data
[
2
];
/* Check that the section isn't too long */
if
(
p_decoder
->
i_need
>
p_decoder
->
i_section_max_size
-
3
)
{
{
dvbpsi_error
(
handle
,
"PSI decoder"
,
"PSI section too long"
);
/* Allocation of the structure */
dvbpsi_DeletePSISections
(
p_section
);
p_decoder
->
p_current_section
=
NULL
;
/* If there is a new section not being handled then go forward
in the packet */
if
(
p_new_pos
)
{
p_decoder
->
p_current_section
p_decoder
->
p_current_section
=
p_section
=
p_section
=
dvbpsi_NewPSISection
(
p_decoder
->
i_section_max_size
);
=
dvbpsi_NewPSISection
(
p_decoder
->
i_section_max_size
);
/* Update the position in the packet */
p_payload_pos
=
p_new_pos
;
p_payload_pos
=
p_new_pos
;
/* New section is being handled */
p_new_pos
=
NULL
;
p_new_pos
=
NULL
;
/* Just need the header to know how long is the section */
p_decoder
->
i_need
=
3
;
p_decoder
->
i_need
=
3
;
p_decoder
->
b_complete_header
=
false
;
p_decoder
->
b_complete_header
=
false
;
i_available
=
188
+
p_data
-
p_payload_pos
;
}
else
{
i_available
=
0
;
}
}
}
else
{
/* PSI section is complete */
p_section
->
b_syntax_indicator
=
p_section
->
p_data
[
1
]
&
0x80
;
p_section
->
b_private_indicator
=
p_section
->
p_data
[
1
]
&
0x40
;
/* Update the end of the payload if CRC_32 is present */
if
(
p_section
->
b_syntax_indicator
)
p_section
->
p_payload_end
-=
4
;
if
(
p_section
->
p_data
[
0
]
!=
0x72
&&
dvbpsi_ValidPSISection
(
p_section
))
{
/* PSI section is valid */
p_section
->
i_table_id
=
p_section
->
p_data
[
0
];
if
(
p_section
->
b_syntax_indicator
)
{
p_section
->
i_extension
=
(
p_section
->
p_data
[
3
]
<<
8
)
|
p_section
->
p_data
[
4
];
p_section
->
i_version
=
(
p_section
->
p_data
[
5
]
&
0x3e
)
>>
1
;
p_section
->
b_current_next
=
p_section
->
p_data
[
5
]
&
0x1
;
p_section
->
i_number
=
p_section
->
p_data
[
6
];
p_section
->
i_last_number
=
p_section
->
p_data
[
7
];
p_section
->
p_payload_start
=
p_section
->
p_data
+
8
;
}
else
{
p_section
->
i_extension
=
0
;
p_section
->
i_version
=
0
;
p_section
->
b_current_next
=
1
;
p_section
->
i_number
=
0
;
p_section
->
i_last_number
=
0
;
p_section
->
p_payload_start
=
p_section
->
p_data
+
3
;
}
p_decoder
->
pf_callback
(
handle
,
p_section
);
p_decoder
->
p_current_section
=
NULL
;
}
}
else
else
{
{
dvbpsi_error
(
handle
,
"misc PSI"
,
"Bad CRC_32 !!!"
);
/* No new section => return */
return
;
/* PSI section isn't valid => trash it */
dvbpsi_DeletePSISections
(
p_section
);
p_decoder
->
p_current_section
=
NULL
;
}
}
}
/* A TS packet may contain any number of sections, only the first
/* Remaining bytes in the payload */
* new one is flagged by the pointer_field. If the next payload
i_available
=
188
+
p_data
-
p_payload_pos
;
* byte isn't 0xff then a new section starts. */
if
(
p_new_pos
==
NULL
&&
i_available
&&
*
p_payload_pos
!=
0xff
)
p_new_pos
=
p_payload_pos
;
/* If there is a new section not being handled then go forward
while
(
i_available
>
0
)
in the packet */
{
if
(
p_new_pos
)
if
(
i_available
>=
p_decoder
->
i_need
)
{
{
p_decoder
->
p_current_section
/* There are enough bytes in this packet to complete the
=
p_section
header/section */
=
dvbpsi_NewPSISection
(
p_decoder
->
i_section_max_size
);
memcpy
(
p_section
->
p_payload_end
,
p_payload_pos
,
p_decoder
->
i_need
);
p_payload_pos
=
p_new_pos
;
p_payload_pos
+=
p_decoder
->
i_need
;
p_new_pos
=
NULL
;
p_section
->
p_payload_end
+=
p_decoder
->
i_need
;
p_decoder
->
i_need
=
3
;
i_available
-=
p_decoder
->
i_need
;
p_decoder
->
b_complete_header
=
false
;
i_available
=
188
+
p_data
-
p_payload_pos
;
if
(
!
p_decoder
->
b_complete_header
)
{
/* Header is complete */
p_decoder
->
b_complete_header
=
true
;
/* Compute p_section->i_length and update p_decoder->i_need */
p_decoder
->
i_need
=
p_section
->
i_length
=
((
uint16_t
)(
p_section
->
p_data
[
1
]
&
0xf
))
<<
8
|
p_section
->
p_data
[
2
];
/* Check that the section isn't too long */
if
(
p_decoder
->
i_need
>
p_decoder
->
i_section_max_size
-
3
)
{
dvbpsi_error
(
handle
,
"PSI decoder"
,
"PSI section too long"
);
dvbpsi_DeletePSISections
(
p_section
);
p_decoder
->
p_current_section
=
NULL
;
/* If there is a new section not being handled then go forward
in the packet */
if
(
p_new_pos
)
{
p_decoder
->
p_current_section
=
p_section
=
dvbpsi_NewPSISection
(
p_decoder
->
i_section_max_size
);
p_payload_pos
=
p_new_pos
;
p_new_pos
=
NULL
;
p_decoder
->
i_need
=
3
;
p_decoder
->
b_complete_header
=
false
;
i_available
=
188
+
p_data
-
p_payload_pos
;
}
else
{
i_available
=
0
;
}
}
}
else
{
/* PSI section is complete */
p_section
->
b_syntax_indicator
=
p_section
->
p_data
[
1
]
&
0x80
;
p_section
->
b_private_indicator
=
p_section
->
p_data
[
1
]
&
0x40
;
/* Update the end of the payload if CRC_32 is present */
if
(
p_section
->
b_syntax_indicator
)
p_section
->
p_payload_end
-=
4
;
if
(
p_section
->
p_data
[
0
]
!=
0x72
&&
dvbpsi_ValidPSISection
(
p_section
))
{
/* PSI section is valid */
p_section
->
i_table_id
=
p_section
->
p_data
[
0
];
if
(
p_section
->
b_syntax_indicator
)
{
p_section
->
i_extension
=
(
p_section
->
p_data
[
3
]
<<
8
)
|
p_section
->
p_data
[
4
];
p_section
->
i_version
=
(
p_section
->
p_data
[
5
]
&
0x3e
)
>>
1
;
p_section
->
b_current_next
=
p_section
->
p_data
[
5
]
&
0x1
;
p_section
->
i_number
=
p_section
->
p_data
[
6
];
p_section
->
i_last_number
=
p_section
->
p_data
[
7
];
p_section
->
p_payload_start
=
p_section
->
p_data
+
8
;
}
else
{
p_section
->
i_extension
=
0
;
p_section
->
i_version
=
0
;
p_section
->
b_current_next
=
1
;
p_section
->
i_number
=
0
;
p_section
->
i_last_number
=
0
;
p_section
->
p_payload_start
=
p_section
->
p_data
+
3
;
}
p_decoder
->
pf_callback
(
handle
,
p_section
);
p_decoder
->
p_current_section
=
NULL
;
}
else
{
dvbpsi_error
(
handle
,
"misc PSI"
,
"Bad CRC_32 !!!"
);
/* PSI section isn't valid => trash it */
dvbpsi_DeletePSISections
(
p_section
);
p_decoder
->
p_current_section
=
NULL
;
}
/* A TS packet may contain any number of sections, only the first
* new one is flagged by the pointer_field. If the next payload
* byte isn't 0xff then a new section starts. */
if
(
p_new_pos
==
NULL
&&
i_available
&&
*
p_payload_pos
!=
0xff
)
p_new_pos
=
p_payload_pos
;
/* If there is a new section not being handled then go forward
in the packet */
if
(
p_new_pos
)
{
p_decoder
->
p_current_section
=
p_section
=
dvbpsi_NewPSISection
(
p_decoder
->
i_section_max_size
);
p_payload_pos
=
p_new_pos
;
p_new_pos
=
NULL
;
p_decoder
->
i_need
=
3
;
p_decoder
->
b_complete_header
=
false
;
i_available
=
188
+
p_data
-
p_payload_pos
;
}
else
{
i_available
=
0
;
}
}
}
}
else
else
{
{
i_available
=
0
;
/* There aren't enough bytes in this packet to complete the
header/section */
memcpy
(
p_section
->
p_payload_end
,
p_payload_pos
,
i_available
);
p_section
->
p_payload_end
+=
i_available
;
p_decoder
->
i_need
-=
i_available
;
i_available
=
0
;
}
}
}
}
else
{
/* There aren't enough bytes in this packet to complete the
header/section */
memcpy
(
p_section
->
p_payload_end
,
p_payload_pos
,
i_available
);
p_section
->
p_payload_end
+=
i_available
;
p_decoder
->
i_need
-=
i_available
;
i_available
=
0
;
}
}
}
}
}
/*****************************************************************************
/*****************************************************************************
...
...
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