[vlc-devel] [PATCH 3/4] mux/mpeg/pes: Add support for stream_id_extension

davidf+nntp at woaf.net davidf+nntp at woaf.net
Thu Nov 13 17:19:58 CET 2008


From: David Flynn <davidf at rd.bbc.co.uk>

ISO/IEC 13818-1:2000/Amd.2:2003 Adds support for signalling
a stream_id_extension.  This is used in mapping standards
for Dirac/VC-2 and VC-1.

Signed-off-by: David Flynn <davidf at rd.bbc.co.uk>
---
 modules/mux/mpeg/pes.c |   63 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/modules/mux/mpeg/pes.c b/modules/mux/mpeg/pes.c
index 49d21b8..91f8b40 100644
--- a/modules/mux/mpeg/pes.c
+++ b/modules/mux/mpeg/pes.c
@@ -48,6 +48,13 @@
 #include "bits.h"
 
 /** PESHeader, write a pes header
+ * \param i_es_size length of the pes packet payload.  For video elementary
+ *                  streams this may be 0 to indicate an unbounded pes packet.
+ *                  This is only valid in transport streams.
+ * \param i_stream_id stream id as follows:
+ *                     - 0x00   -  0xff  : normal stream_id as per Table 2-18
+ *                     - 0x100  -  0x17f : 256 + stream_id_extension
+ *                                          (implies stream_id = 0xfd)
  * \param i_header_size length of padding data to insert into PES packet
  *                      header in bytes.
  */
@@ -59,6 +66,7 @@ static inline int PESHeader( uint8_t *p_hdr, mtime_t i_pts, mtime_t i_dts,
 {
     bits_buffer_t bits;
     int     i_extra = 0;
+    int i_stream_id_extension = 0;
 
     /* For PES_PRIVATE_STREAM_1 there is an extra header after the
        pes header */
@@ -72,6 +80,15 @@ static inline int PESHeader( uint8_t *p_hdr, mtime_t i_pts, mtime_t i_dts,
         }
     }
 
+    if( i_stream_id > 255 )
+    {
+        /* Enable support for extended_stream_id as defined in
+         * ISO/IEC 13818-1:2000/Amd.2:2003 */
+        /* NB, i_extended_stream_id is limited to 7 bits */
+        i_stream_id_extension = i_stream_id - 256;
+        i_stream_id = 0xfd;
+    }
+
     bits_initwrite( &bits, 50, p_hdr );
 
     /* add start code */
@@ -97,6 +114,7 @@ static inline int PESHeader( uint8_t *p_hdr, mtime_t i_pts, mtime_t i_dts,
             if( b_mpeg2 )
             {
                 int i_pts_dts;
+                bool b_pes_extension_flag = false;
 
                 if( i_pts > 0 && i_dts > 0 &&
                     ( i_pts != i_dts || ( p_fmt->i_cat == VIDEO_ES &&
@@ -116,6 +134,17 @@ 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_stream_id == 0xfd )
+                {
+                    b_pes_extension_flag = true;
+                    i_header_size += 1 + 1;
+                }
+
+                if( b_pes_extension_flag )
+                {
+                    i_header_size += 1;
+                }
+
                 /* there are two ways to handle unbounded PES packets:
                  *   Unbounded streams are only allowed in certain environments
                  *   eg, MPEG* Video ES or a dirac stream.
@@ -142,8 +171,8 @@ static inline int PESHeader( uint8_t *p_hdr, mtime_t i_pts, mtime_t i_dts,
                 bits_write( &bits, 1, 0x00 ); // dsm trick mode flag
                 bits_write( &bits, 1, 0x00 ); // additional copy info flag
                 bits_write( &bits, 1, 0x00 ); // pes crc flag
-                bits_write( &bits, 1, 0x00 ); // pes extension flags
-                bits_write( &bits, 8, i_header_size ); // header size -> pts and dts
+                bits_write( &bits, 1, b_pes_extension_flag );
+                bits_write( &bits, 8, i_header_size );
 
                 /* write pts */
                 if( i_pts_dts & 0x02 )
@@ -169,6 +198,30 @@ static inline int PESHeader( uint8_t *p_hdr, mtime_t i_pts, mtime_t i_dts,
                     bits_write( &bits, 1, 0x01 ); // marker
                     i_header_size -= 0x5;
                 }
+                if( b_pes_extension_flag )
+                {
+                    bits_write( &bits, 1, 0x00 ); // PES_private_data_flag
+                    bits_write( &bits, 1, 0x00 ); // pack_header_field_flag
+                    bits_write( &bits, 1, 0x00 ); // program_packet_sequence_counter_flag
+                    bits_write( &bits, 1, 0x00 ); // P-STD_buffer_flag
+                    bits_write( &bits, 3, 0x07 ); // reserved
+                    bits_write( &bits, 1, 0x01 ); // PES_extension_flag_2
+                    /* skipping unsupported parts: */
+                    /*   PES_private_data */
+                    /*   pack_header */
+                    /*   program_packet_sequence_counter */
+                    /*   P-STD_buffer_flag */
+                    if( i_stream_id == 0xfd )
+                    {
+                        /* PES_extension_2 */
+                        bits_write( &bits, 1, 0x01 ); // marker
+                        bits_write( &bits, 7, 0x01 ); // PES_extension_field_length
+                        bits_write( &bits, 1, 0x01 ); // stream_id_extension_flag
+                        bits_write( &bits, 7, i_stream_id_extension );
+                        i_header_size -= 0x2;
+                    }
+                    i_header_size -= 0x1;
+                }
                 while ( i_header_size )
                 {
                     bits_write( &bits, 8, 0xff );
@@ -247,6 +300,12 @@ static inline int PESHeader( uint8_t *p_hdr, mtime_t i_pts, mtime_t i_dts,
 }
 
 /** EStoPES, encapsulate an elementary stream block into a pes packet
+ * \param i_stream_id stream id as follows:
+ *                     - 0x00   -  0xff  : normal stream_id as per Table 2-18
+ *                     - 0x100  -  0x17f : 256 + stream_id_extension
+ *                                          (implies stream_id = 0xfd)
+ *                     - 0xbd00 - 0xbdff : private_id = low 8 bits
+ *                                          (stream_id = PES_PRIVATE_STREAM)
  * \param i_header_size length of padding data to insert into PES packet
  *                      header in bytes.
  * \param i_max_pes_size maximum length of the pes packet payload
-- 
1.5.6.5




More information about the vlc-devel mailing list