* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
-#include <vlc_demux.h>
#include <assert.h>
+#include <vlc_demux.h>
+#include <vlc_memory.h>
/* 256-0xC0 for normal stream, 256 for 0xbd stream, 256 for 0xfd stream, 8 for 0xa0 AOB stream */
#define PS_TK_COUNT (256+256+256+8 - 0xc0)
{
uint8_t header[34];
unsigned int i_skip = 0;
+ int64_t i_pts = -1;
+ int64_t i_dts = -1;
memcpy( header, p_pes->p_buffer, __MIN( p_pes->i_buffer, 34 ) );
if( header[7]&0x80 ) /* has pts */
{
- p_pes->i_pts = ((mtime_t)(header[ 9]&0x0e ) << 29)|
- (mtime_t)(header[10] << 22)|
- ((mtime_t)(header[11]&0xfe) << 14)|
- (mtime_t)(header[12] << 7)|
- (mtime_t)(header[13] >> 1);
+ i_pts = ((mtime_t)(header[ 9]&0x0e ) << 29)|
+ (mtime_t)(header[10] << 22)|
+ ((mtime_t)(header[11]&0xfe) << 14)|
+ (mtime_t)(header[12] << 7)|
+ (mtime_t)(header[13] >> 1);
if( header[7]&0x40 ) /* has dts */
{
- p_pes->i_dts = ((mtime_t)(header[14]&0x0e ) << 29)|
- (mtime_t)(header[15] << 22)|
- ((mtime_t)(header[16]&0xfe) << 14)|
- (mtime_t)(header[17] << 7)|
- (mtime_t)(header[18] >> 1);
+ i_dts = ((mtime_t)(header[14]&0x0e ) << 29)|
+ (mtime_t)(header[15] << 22)|
+ ((mtime_t)(header[16]&0xfe) << 14)|
+ (mtime_t)(header[17] << 7)|
+ (mtime_t)(header[18] >> 1);
}
}
}
if( header[i_skip]&0x20 )
{
- p_pes->i_pts = ((mtime_t)(header[i_skip]&0x0e ) << 29)|
- (mtime_t)(header[i_skip+1] << 22)|
- ((mtime_t)(header[i_skip+2]&0xfe) << 14)|
- (mtime_t)(header[i_skip+3] << 7)|
- (mtime_t)(header[i_skip+4] >> 1);
+ i_pts = ((mtime_t)(header[i_skip]&0x0e ) << 29)|
+ (mtime_t)(header[i_skip+1] << 22)|
+ ((mtime_t)(header[i_skip+2]&0xfe) << 14)|
+ (mtime_t)(header[i_skip+3] << 7)|
+ (mtime_t)(header[i_skip+4] >> 1);
if( header[i_skip]&0x10 ) /* has dts */
{
- p_pes->i_dts = ((mtime_t)(header[i_skip+5]&0x0e ) << 29)|
- (mtime_t)(header[i_skip+6] << 22)|
- ((mtime_t)(header[i_skip+7]&0xfe) << 14)|
- (mtime_t)(header[i_skip+8] << 7)|
- (mtime_t)(header[i_skip+9] >> 1);
+ i_dts = ((mtime_t)(header[i_skip+5]&0x0e ) << 29)|
+ (mtime_t)(header[i_skip+6] << 22)|
+ ((mtime_t)(header[i_skip+7]&0xfe) << 14)|
+ (mtime_t)(header[i_skip+8] << 7)|
+ (mtime_t)(header[i_skip+9] >> 1);
i_skip += 10;
}
else
p_pes->p_buffer += i_skip;
p_pes->i_buffer -= i_skip;
- p_pes->i_dts = 100 * p_pes->i_dts / 9;
- p_pes->i_pts = 100 * p_pes->i_pts / 9;
+ if( i_dts >= 0 )
+ p_pes->i_dts = VLC_TS_0 + 100 * i_dts / 9;
+ if( i_pts >= 0 )
+ p_pes->i_pts = VLC_TS_0 + 100 * i_pts / 9;
return VLC_SUCCESS;
}
}
}
- tmp_es = realloc( p_psm->es, sizeof(ps_es_t *) * (p_psm->i_es+1) );
+ tmp_es = realloc_or_free( p_psm->es, sizeof(ps_es_t *) * (p_psm->i_es+1) );
if( tmp_es )
{
p_psm->es = tmp_es;
if( ps_track_fill( &tk_tmp, p_psm, tk[i].i_id ) != VLC_SUCCESS )
continue;
- if( tk_tmp.fmt.i_codec == tk[i].fmt.i_codec ) continue;
+ if( tk_tmp.fmt.i_codec == tk[i].fmt.i_codec )
+ {
+ es_format_Clean( &tk_tmp.fmt );
+ continue;
+ }
es_out_Del( out, tk[i].es );
+ es_format_Clean( &tk[i].fmt );
+
tk[i] = tk_tmp;
tk[i].b_seen = true;
tk[i].es = es_out_Add( out, &tk[i].fmt );