libgpac
Documentation of the core library of GPAC
mpeg2_ps.c File Reference
#include "mpeg2_ps.h"
+ Include dependency graph for mpeg2_ps.c:

Data Structures

struct  mpeg2ps_ts_t
 
struct  mpeg2ps_record_pes_t
 
struct  mpeg2ps_stream_t
 
struct  mpeg2ps_t
 

Macros

#define FDNULL   0
 
#define file_location(__f)   gf_ftell(__f)
 
#define file_seek_to(__f, __off)   gf_fseek(__f, __off, SEEK_SET)
 
#define MPEG2PS_RECORD_TIME   ((u64) (5 * 90000))
 
#define SEQ_ID   1
 
#define IS_MPEG_START(a)   ((a) == 0xb3 || (a) == 0x00 || (a) == 0xb8)
 
#define NUM_ELEMENTS_IN_ARRAY(name)   ((sizeof((name))) / (sizeof(*(name))))
 

Functions

static GFINLINE u16 convert16 (u8 *p)
 
static GFINLINE u32 convert32 (u8 *p)
 
static FILE * file_open (const char *name)
 
static Bool file_okay (FILE *fd)
 
static void file_close (FILE *fd)
 
static Bool file_read_bytes (FILE *fd, u8 *buffer, u32 len)
 
static void file_skip_bytes (FILE *fd, s32 len)
 
static u64 file_size (FILE *fd)
 
static mpeg2ps_record_pes_tcreate_record (s64 loc, u64 ts)
 
void mpeg2ps_record_pts (mpeg2ps_stream_t *sptr, s64 location, mpeg2ps_ts_t *pTs)
 
int MPEG12_ParseSeqHdr (unsigned char *pbuffer, u32 buflen, s32 *have_mpeg2, u32 *height, u32 *width, Double *frame_rate, Double *bitrate, u32 *aspect_ratio)
 
s32 MPEG12_PictHdrType (unsigned char *pbuffer)
 
static u64 read_pts (u8 *pak)
 
static mpeg2ps_stream_tmpeg2ps_stream_create (u8 stream_id, u8 substream)
 
static void mpeg2ps_stream_destroy (mpeg2ps_stream_t *sptr)
 
static void adv_past_pack_hdr (FILE *fd, u8 *pak, u32 read_from_start)
 
static Bool find_pack_start (FILE *fd, u8 *saved, u32 len)
 
static void copy_bytes_to_pes_buffer (mpeg2ps_stream_t *sptr, u16 pes_len)
 
static Bool read_to_next_pes_header (FILE *fd, u8 *stream_id, u16 *pes_len)
 
static Bool read_pes_header_data (FILE *fd, u16 orig_pes_len, u16 *pes_left, Bool *have_ts, mpeg2ps_ts_t *ts)
 
static Bool search_for_next_pes_header (mpeg2ps_stream_t *sptr, u16 *pes_len, Bool *have_ts, s64 *found_loc)
 
static Bool mpeg2ps_stream_read_next_pes_buffer (mpeg2ps_stream_t *sptr)
 
static Bool mpeg2ps_stream_find_mpeg_video_frame (mpeg2ps_stream_t *sptr)
 
static Bool mpeg2ps_stream_find_ac3_frame (mpeg2ps_stream_t *sptr)
 
static Bool mpeg2ps_stream_find_mp3_frame (mpeg2ps_stream_t *sptr)
 
static Bool mpeg2ps_stream_read_frame (mpeg2ps_stream_t *sptr, u8 **buffer, u32 *buflen, Bool advance_pointers)
 
static void get_info_from_frame (mpeg2ps_stream_t *sptr, u8 *buffer, u32 buflen)
 
static void clear_stream_buffer (mpeg2ps_stream_t *sptr)
 
static u64 convert_ts (mpeg2ps_stream_t *sptr, mpeg2ps_ts_type_t ts_type, u64 ts, u64 base_ts, u32 frames_since_ts)
 
static mpeg2ps_stream_tfind_stream_from_id (mpeg2ps_t *ps, u8 stream_id, u8 substream)
 
static Bool add_stream (mpeg2ps_t *ps, u8 stream_id, u8 substream, s64 first_loc, mpeg2ps_ts_t *ts)
 
static void check_fd_for_stream (mpeg2ps_t *ps, mpeg2ps_stream_t *sptr)
 
static void advance_frame (mpeg2ps_stream_t *sptr)
 
static void get_info_for_all_streams (mpeg2ps_t *ps)
 
static void mpeg2ps_scan_file (mpeg2ps_t *ps)
 
u64 mpeg2ps_get_max_time_msec (mpeg2ps_t *ps)
 
u32 mpeg2ps_get_video_stream_count (mpeg2ps_t *ps)
 
static Bool invalid_video_streamno (mpeg2ps_t *ps, u32 streamno)
 
mpeg2ps_video_type_t mpeg2ps_get_video_stream_type (mpeg2ps_t *ps, u32 streamno)
 
u32 mpeg2ps_get_video_stream_width (mpeg2ps_t *ps, u32 streamno)
 
u32 mpeg2ps_get_video_stream_height (mpeg2ps_t *ps, u32 streamno)
 
u32 mpeg2ps_get_video_stream_aspect_ratio (mpeg2ps_t *ps, u32 streamno)
 
Double mpeg2ps_get_video_stream_bitrate (mpeg2ps_t *ps, u32 streamno)
 
Double mpeg2ps_get_video_stream_framerate (mpeg2ps_t *ps, u32 streamno)
 
u32 mpeg2ps_get_video_stream_id (mpeg2ps_t *ps, u32 streamno)
 
static Bool invalid_audio_streamno (mpeg2ps_t *ps, u32 streamno)
 
u32 mpeg2ps_get_audio_stream_count (mpeg2ps_t *ps)
 
mpeg2ps_audio_type_t mpeg2ps_get_audio_stream_type (mpeg2ps_t *ps, u32 streamno)
 
u32 mpeg2ps_get_audio_stream_sample_freq (mpeg2ps_t *ps, u32 streamno)
 
u32 mpeg2ps_get_audio_stream_channels (mpeg2ps_t *ps, u32 streamno)
 
u32 mpeg2ps_get_audio_stream_bitrate (mpeg2ps_t *ps, u32 streamno)
 
u32 mpeg2ps_get_audio_stream_id (mpeg2ps_t *ps, u32 streamno)
 
mpeg2ps_t * mpeg2ps_init (const char *filename)
 
void mpeg2ps_close (mpeg2ps_t *ps)
 
static u64 stream_convert_frame_ts_to_msec (mpeg2ps_stream_t *sptr, mpeg2ps_ts_type_t ts_type, u64 base_dts, u32 *freq_ts)
 
Bool mpeg2ps_get_video_frame (mpeg2ps_t *ps, u32 streamno, u8 **buffer, u32 *buflen, u8 *frame_type, mpeg2ps_ts_type_t ts_type, u64 *decode_timestamp, u64 *compose_timestamp)
 
Bool mpeg2ps_get_audio_frame (mpeg2ps_t *ps, u32 streamno, u8 **buffer, u32 *buflen, mpeg2ps_ts_type_t ts_type, u32 *freq_timestamp, u64 *timestamp)
 
static void mpeg2ps_binary_seek (mpeg2ps_t *ps, mpeg2ps_stream_t *sptr, u64 search_dts, u64 start_dts, u64 start_loc, u64 end_dts, u64 end_loc)
 
static mpeg2ps_record_pes_tsearch_for_ts (mpeg2ps_stream_t *sptr, u64 dts)
 
static Bool mpeg2ps_seek_frame (mpeg2ps_t *ps, mpeg2ps_stream_t *sptr, u64 search_msec_timestamp)
 
Bool mpeg2ps_seek_video_frame (mpeg2ps_t *ps, u32 streamno, u64 msec_timestamp)
 
Bool mpeg2ps_seek_audio_frame (mpeg2ps_t *ps, u32 streamno, u64 msec_timestamp)
 
u64 mpeg2ps_get_first_cts (mpeg2ps_t *ps)
 

Variables

static Double mpeg12_frame_rate_table [16]
 

Data Structure Documentation

◆ mpeg2ps_ts_t

struct mpeg2ps_ts_t
Data Fields
Bool have_pts
Bool have_dts
u64 pts
u64 dts

◆ mpeg2ps_record_pes_t

struct mpeg2ps_record_pes_t
+ Collaboration diagram for mpeg2ps_record_pes_t:
Data Fields
struct mpeg2ps_record_pes_t * next_rec
u64 dts
u64 location

◆ mpeg2ps_stream_t

struct mpeg2ps_stream_t
+ Collaboration diagram for mpeg2ps_stream_t:
Data Fields
mpeg2ps_record_pes_t * record_first
mpeg2ps_record_pes_t * record_last
FILE * m_fd
Bool is_video
u8 m_stream_id
u8 m_substream_id
mpeg2ps_ts_t next_pes_ts
mpeg2ps_ts_t frame_ts
u32 frames_since_last_ts
u64 last_ts
Bool have_frame_loaded
u8 * pes_buffer
u32 pes_buffer_size
u32 pes_buffer_size_max
u32 pes_buffer_on
u32 frame_len
u32 pict_header_offset
s64 first_pes_loc
u64 start_dts
Bool first_pes_has_dts
s64 end_dts_loc
u64 end_dts
u32 freq
u32 channels
u32 bitrate
u32 samples_per_frame
u32 layer
u32 h
u32 w
u32 par
Double frame_rate
s32 have_mpeg2
Double bit_rate
u64 ticks_per_frame

◆ mpeg2ps_

struct mpeg2ps_
+ Collaboration diagram for mpeg2ps_t:
Data Fields
mpeg2ps_stream_t * video_streams[16]
mpeg2ps_stream_t * audio_streams[32]
char * filename
FILE * fd
u64 first_dts
u32 audio_cnt
u32 video_cnt
s64 end_loc
u64 max_dts
u64 max_time

Macro Definition Documentation

◆ FDNULL

#define FDNULL   0

◆ file_location

#define file_location (   __f)    gf_ftell(__f)

◆ file_seek_to

#define file_seek_to (   __f,
  __off 
)    gf_fseek(__f, __off, SEEK_SET)

◆ MPEG2PS_RECORD_TIME

#define MPEG2PS_RECORD_TIME   ((u64) (5 * 90000))

◆ SEQ_ID

#define SEQ_ID   1

◆ IS_MPEG_START

#define IS_MPEG_START (   a)    ((a) == 0xb3 || (a) == 0x00 || (a) == 0xb8)

◆ NUM_ELEMENTS_IN_ARRAY

#define NUM_ELEMENTS_IN_ARRAY (   name)    ((sizeof((name))) / (sizeof(*(name))))

Function Documentation

◆ convert16()

static GFINLINE u16 convert16 ( u8 p)
static
+ Here is the caller graph for this function:

◆ convert32()

static GFINLINE u32 convert32 ( u8 p)
static
+ Here is the caller graph for this function:

◆ file_open()

static FILE* file_open ( const char *  name)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ file_okay()

static Bool file_okay ( FILE *  fd)
static
+ Here is the caller graph for this function:

◆ file_close()

static void file_close ( FILE *  fd)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ file_read_bytes()

static Bool file_read_bytes ( FILE *  fd,
u8 buffer,
u32  len 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ file_skip_bytes()

static void file_skip_bytes ( FILE *  fd,
s32  len 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ file_size()

static u64 file_size ( FILE *  fd)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create_record()

static mpeg2ps_record_pes_t* create_record ( s64  loc,
u64  ts 
)
static
+ Here is the caller graph for this function:

◆ mpeg2ps_record_pts()

void mpeg2ps_record_pts ( mpeg2ps_stream_t sptr,
s64  location,
mpeg2ps_ts_t pTs 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MPEG12_ParseSeqHdr()

int MPEG12_ParseSeqHdr ( unsigned char *  pbuffer,
u32  buflen,
s32 have_mpeg2,
u32 height,
u32 width,
Double frame_rate,
Double bitrate,
u32 aspect_ratio 
)
+ Here is the caller graph for this function:

◆ MPEG12_PictHdrType()

s32 MPEG12_PictHdrType ( unsigned char *  pbuffer)
+ Here is the caller graph for this function:

◆ read_pts()

static u64 read_pts ( u8 pak)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_stream_create()

static mpeg2ps_stream_t* mpeg2ps_stream_create ( u8  stream_id,
u8  substream 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_stream_destroy()

static void mpeg2ps_stream_destroy ( mpeg2ps_stream_t sptr)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ adv_past_pack_hdr()

static void adv_past_pack_hdr ( FILE *  fd,
u8 pak,
u32  read_from_start 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_pack_start()

static Bool find_pack_start ( FILE *  fd,
u8 saved,
u32  len 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ copy_bytes_to_pes_buffer()

static void copy_bytes_to_pes_buffer ( mpeg2ps_stream_t sptr,
u16  pes_len 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read_to_next_pes_header()

static Bool read_to_next_pes_header ( FILE *  fd,
u8 stream_id,
u16 pes_len 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read_pes_header_data()

static Bool read_pes_header_data ( FILE *  fd,
u16  orig_pes_len,
u16 pes_left,
Bool have_ts,
mpeg2ps_ts_t ts 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ search_for_next_pes_header()

static Bool search_for_next_pes_header ( mpeg2ps_stream_t sptr,
u16 pes_len,
Bool have_ts,
s64 found_loc 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_stream_read_next_pes_buffer()

static Bool mpeg2ps_stream_read_next_pes_buffer ( mpeg2ps_stream_t sptr)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_stream_find_mpeg_video_frame()

static Bool mpeg2ps_stream_find_mpeg_video_frame ( mpeg2ps_stream_t sptr)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_stream_find_ac3_frame()

static Bool mpeg2ps_stream_find_ac3_frame ( mpeg2ps_stream_t sptr)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_stream_find_mp3_frame()

static Bool mpeg2ps_stream_find_mp3_frame ( mpeg2ps_stream_t sptr)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_stream_read_frame()

static Bool mpeg2ps_stream_read_frame ( mpeg2ps_stream_t sptr,
u8 **  buffer,
u32 buflen,
Bool  advance_pointers 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_info_from_frame()

static void get_info_from_frame ( mpeg2ps_stream_t sptr,
u8 buffer,
u32  buflen 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clear_stream_buffer()

static void clear_stream_buffer ( mpeg2ps_stream_t sptr)
static
+ Here is the caller graph for this function:

◆ convert_ts()

static u64 convert_ts ( mpeg2ps_stream_t sptr,
mpeg2ps_ts_type_t  ts_type,
u64  ts,
u64  base_ts,
u32  frames_since_ts 
)
static
+ Here is the caller graph for this function:

◆ find_stream_from_id()

static mpeg2ps_stream_t* find_stream_from_id ( mpeg2ps_t *  ps,
u8  stream_id,
u8  substream 
)
static
+ Here is the caller graph for this function:

◆ add_stream()

static Bool add_stream ( mpeg2ps_t *  ps,
u8  stream_id,
u8  substream,
s64  first_loc,
mpeg2ps_ts_t ts 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_fd_for_stream()

static void check_fd_for_stream ( mpeg2ps_t *  ps,
mpeg2ps_stream_t sptr 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ advance_frame()

static void advance_frame ( mpeg2ps_stream_t sptr)
static
+ Here is the caller graph for this function:

◆ get_info_for_all_streams()

static void get_info_for_all_streams ( mpeg2ps_t *  ps)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_scan_file()

static void mpeg2ps_scan_file ( mpeg2ps_t *  ps)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_get_max_time_msec()

u64 mpeg2ps_get_max_time_msec ( mpeg2ps_t *  ps)
+ Here is the caller graph for this function:

◆ mpeg2ps_get_video_stream_count()

u32 mpeg2ps_get_video_stream_count ( mpeg2ps_t *  ps)
+ Here is the caller graph for this function:

◆ invalid_video_streamno()

static Bool invalid_video_streamno ( mpeg2ps_t *  ps,
u32  streamno 
)
static
+ Here is the caller graph for this function:

◆ mpeg2ps_get_video_stream_type()

mpeg2ps_video_type_t mpeg2ps_get_video_stream_type ( mpeg2ps_t *  ps,
u32  streamno 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_get_video_stream_width()

u32 mpeg2ps_get_video_stream_width ( mpeg2ps_t *  ps,
u32  streamno 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_get_video_stream_height()

u32 mpeg2ps_get_video_stream_height ( mpeg2ps_t *  ps,
u32  streamno 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_get_video_stream_aspect_ratio()

u32 mpeg2ps_get_video_stream_aspect_ratio ( mpeg2ps_t *  ps,
u32  streamno 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_get_video_stream_bitrate()

Double mpeg2ps_get_video_stream_bitrate ( mpeg2ps_t *  ps,
u32  streamno 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_get_video_stream_framerate()

Double mpeg2ps_get_video_stream_framerate ( mpeg2ps_t *  ps,
u32  streamno 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_get_video_stream_id()

u32 mpeg2ps_get_video_stream_id ( mpeg2ps_t *  ps,
u32  streamno 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ invalid_audio_streamno()

static Bool invalid_audio_streamno ( mpeg2ps_t *  ps,
u32  streamno 
)
static
+ Here is the caller graph for this function:

◆ mpeg2ps_get_audio_stream_count()

u32 mpeg2ps_get_audio_stream_count ( mpeg2ps_t *  ps)
+ Here is the caller graph for this function:

◆ mpeg2ps_get_audio_stream_type()

mpeg2ps_audio_type_t mpeg2ps_get_audio_stream_type ( mpeg2ps_t *  ps,
u32  streamno 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_get_audio_stream_sample_freq()

u32 mpeg2ps_get_audio_stream_sample_freq ( mpeg2ps_t *  ps,
u32  streamno 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_get_audio_stream_channels()

u32 mpeg2ps_get_audio_stream_channels ( mpeg2ps_t *  ps,
u32  streamno 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_get_audio_stream_bitrate()

u32 mpeg2ps_get_audio_stream_bitrate ( mpeg2ps_t *  ps,
u32  streamno 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_get_audio_stream_id()

u32 mpeg2ps_get_audio_stream_id ( mpeg2ps_t *  ps,
u32  streamno 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_init()

mpeg2ps_t* mpeg2ps_init ( const char *  filename)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_close()

void mpeg2ps_close ( mpeg2ps_t *  ps)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stream_convert_frame_ts_to_msec()

static u64 stream_convert_frame_ts_to_msec ( mpeg2ps_stream_t sptr,
mpeg2ps_ts_type_t  ts_type,
u64  base_dts,
u32 freq_ts 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_get_video_frame()

Bool mpeg2ps_get_video_frame ( mpeg2ps_t *  ps,
u32  streamno,
u8 **  buffer,
u32 buflen,
u8 frame_type,
mpeg2ps_ts_type_t  ts_type,
u64 decode_timestamp,
u64 compose_timestamp 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_get_audio_frame()

Bool mpeg2ps_get_audio_frame ( mpeg2ps_t *  ps,
u32  streamno,
u8 **  buffer,
u32 buflen,
mpeg2ps_ts_type_t  ts_type,
u32 freq_timestamp,
u64 timestamp 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_binary_seek()

static void mpeg2ps_binary_seek ( mpeg2ps_t *  ps,
mpeg2ps_stream_t sptr,
u64  search_dts,
u64  start_dts,
u64  start_loc,
u64  end_dts,
u64  end_loc 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ search_for_ts()

static mpeg2ps_record_pes_t* search_for_ts ( mpeg2ps_stream_t sptr,
u64  dts 
)
static
+ Here is the caller graph for this function:

◆ mpeg2ps_seek_frame()

static Bool mpeg2ps_seek_frame ( mpeg2ps_t *  ps,
mpeg2ps_stream_t sptr,
u64  search_msec_timestamp 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_seek_video_frame()

Bool mpeg2ps_seek_video_frame ( mpeg2ps_t *  ps,
u32  streamno,
u64  msec_timestamp 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_seek_audio_frame()

Bool mpeg2ps_seek_audio_frame ( mpeg2ps_t *  ps,
u32  streamno,
u64  msec_timestamp 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mpeg2ps_get_first_cts()

u64 mpeg2ps_get_first_cts ( mpeg2ps_t *  ps)
+ Here is the caller graph for this function:

Variable Documentation

◆ mpeg12_frame_rate_table

Double mpeg12_frame_rate_table[16]
static
Initial value:
=
{
0.0,
24000.0/1001.0,
24.0,
25.0,
30000.0/1001.0,
30.0,
50.0,
((60.0*1000.0)/1001.0),
60.0,
1,
5,
10,
12,
15,
0,
0,
}