Commit 7d26a5b2 authored by David Flynn's avatar David Flynn Committed by Laurent Aimar

mux/mpeg/pes: Add support for unbounded VIDEO_ES

For some stream_id's in a transport stream, the PES packet may be
unbounded in length; add support for this.
Signed-off-by: default avatarDavid Flynn <davidf@rd.bbc.co.uk>
Signed-off-by: default avatarLaurent Aimar <fenrir@videolan.org>
parent cbab46c4
...@@ -48,6 +48,8 @@ ...@@ -48,6 +48,8 @@
#include "bits.h" #include "bits.h"
/** PESHeader, write a pes header /** PESHeader, write a pes header
* \param i_es_size length of payload data. (Must be < PES_PAYLOAD_SIZE_MAX
* unless the conditions for unbounded PES packets are met)
* \param i_header_size length of padding data to insert into PES packet * \param i_header_size length of padding data to insert into PES packet
* header in bytes. * header in bytes.
*/ */
...@@ -116,6 +118,11 @@ static inline int PESHeader( uint8_t *p_hdr, mtime_t i_pts, mtime_t i_dts, ...@@ -116,6 +118,11 @@ static inline int PESHeader( uint8_t *p_hdr, mtime_t i_pts, mtime_t i_dts,
if ( !i_header_size ) i_header_size = 0x0; if ( !i_header_size ) i_header_size = 0x0;
} }
/* Unbounded streams are only allowed in TS (not PS) and only
* for some ES, eg. MPEG* Video ES or Dirac ES. */
if( i_es_size > PES_PAYLOAD_SIZE_MAX )
bits_write( &bits, 16, 0 ); // size unbounded
else
bits_write( &bits, 16, i_es_size + i_extra + 3 bits_write( &bits, 16, i_es_size + i_extra + 3
+ i_header_size ); // size + i_header_size ); // size
bits_write( &bits, 2, 0x02 ); // mpeg2 id bits_write( &bits, 2, 0x02 ); // mpeg2 id
...@@ -238,10 +245,24 @@ static inline int PESHeader( uint8_t *p_hdr, mtime_t i_pts, mtime_t i_dts, ...@@ -238,10 +245,24 @@ static inline int PESHeader( uint8_t *p_hdr, mtime_t i_pts, mtime_t i_dts,
/** EStoPES, encapsulate an elementary stream block into PES packet(s) /** EStoPES, encapsulate an elementary stream block into PES packet(s)
* each with a maximal payload size of @i_max_pes_size@. * each with a maximal payload size of @i_max_pes_size@.
* *
* In some circumstances, unbounded PES packets are allowed:
* - Transport streams only (NOT programme streams)
* - Only some types of elementary streams (eg MPEG2 video)
* It is the responsibility of the caller to enforce these constraints.
*
* EStoPES will only produce an unbounded PES packet if:
* - ES is VIDEO_ES
* - i_max_pes_size > PES_PAYLOAD_SIZE_MAX
* - length of p_es > PES_PAYLOAD_SIZE_MAX
* If the last condition is not met, a single PES packet is produced
* which is not unbounded in length.
*
* \param i_header_size length of padding data to insert into PES packet * \param i_header_size length of padding data to insert into PES packet
* header in bytes. * header in bytes.
* \param i_max_pes_size maximum length of the pes packet payload * \param i_max_pes_size maximum length of each pes packet payload.
* if zero, uses default maximum * if zero, uses default maximum.
* To allow unbounded PES packets in transport stream
* VIDEO_ES, set to INT_MAX.
*/ */
int EStoPES ( sout_instance_t *p_sout, block_t **pp_pes, block_t *p_es, int EStoPES ( sout_instance_t *p_sout, block_t **pp_pes, block_t *p_es,
es_format_t *p_fmt, int i_stream_id, es_format_t *p_fmt, int i_stream_id,
...@@ -262,6 +283,13 @@ int EStoPES ( sout_instance_t *p_sout, block_t **pp_pes, block_t *p_es, ...@@ -262,6 +283,13 @@ int EStoPES ( sout_instance_t *p_sout, block_t **pp_pes, block_t *p_es,
int i_pes_count = 1; int i_pes_count = 1;
/* NB, Only video ES may have unbounded length */
if( !i_max_pes_size ||
( p_fmt->i_cat != VIDEO_ES && i_max_pes_size > PES_PAYLOAD_SIZE_MAX ) )
{
i_max_pes_size = PES_PAYLOAD_SIZE_MAX;
}
/* HACK for private stream 1 in ps */ /* HACK for private stream 1 in ps */
if( ( i_stream_id >> 8 ) == PES_PRIVATE_STREAM_1 ) if( ( i_stream_id >> 8 ) == PES_PRIVATE_STREAM_1 )
{ {
...@@ -292,8 +320,7 @@ int EStoPES ( sout_instance_t *p_sout, block_t **pp_pes, block_t *p_es, ...@@ -292,8 +320,7 @@ int EStoPES ( sout_instance_t *p_sout, block_t **pp_pes, block_t *p_es,
do do
{ {
i_pes_payload = __MIN( i_size, (i_max_pes_size ? i_pes_payload = __MIN( i_size, i_max_pes_size );
i_max_pes_size : PES_PAYLOAD_SIZE_MAX) );
i_pes_header = PESHeader( header, i_pts, i_dts, i_pes_payload, i_pes_header = PESHeader( header, i_pts, i_dts, i_pes_payload,
p_fmt, i_stream_id, i_private_id, b_mpeg2, p_fmt, i_stream_id, i_private_id, b_mpeg2,
b_data_alignment, i_header_size ); b_data_alignment, i_header_size );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment