1
mirror of https://github.com/mpv-player/mpv synced 2024-12-24 07:33:46 +01:00

cleanup: reindent demuxer.h, use struct names for types

Reindent demuxer.h and also change some comments. Change some types
from 'foo_t' to 'struct foo'.
This commit is contained in:
Uoti Urpala 2011-02-10 12:05:26 +02:00
parent e786c70de9
commit 496b09e04d

View File

@ -32,8 +32,8 @@
struct MPOpts;
#ifdef HAVE_BUILTIN_EXPECT
#define likely(x) __builtin_expect ((x) != 0, 1)
#define unlikely(x) __builtin_expect ((x) != 0, 0)
#define likely(x) __builtin_expect((x) != 0, 1)
#define unlikely(x) __builtin_expect((x) != 0, 0)
#else
#define likely(x) (x)
#define unlikely(x) (x)
@ -93,9 +93,9 @@ struct MPOpts;
#define DEMUXER_TYPE_MIN 0
#define DEMUXER_TYPE_MAX 46
#define DEMUXER_TYPE_DEMUXERS (1<<16)
#define DEMUXER_TYPE_DEMUXERS (1 << 16)
// A virtual demuxer type for the network code
#define DEMUXER_TYPE_PLAYLIST (2<<16)
#define DEMUXER_TYPE_PLAYLIST (2 << 16)
enum timestamp_type {
TIMESTAMP_TYPE_PTS,
@ -125,54 +125,54 @@ enum timestamp_type {
// Holds one packet/frame/whatever
typedef struct demux_packet {
int len;
double pts;
double duration;
double stream_pts;
off_t pos; // position in index (AVI) or file (MPG)
unsigned char* buffer;
int flags; // keyframe, etc
int refcount; //refcounter for the master packet, if 0, buffer can be free()d
struct demux_packet *master; //pointer to the master packet if this one is a cloned one
struct demux_packet *next;
int len;
double pts;
double duration;
double stream_pts;
off_t pos; // position in index (AVI) or file (MPG)
unsigned char *buffer;
int flags; // keyframe, etc
int refcount; // counter for the master packet, if 0, buffer can be free()d
struct demux_packet *master; //in clones, pointer to the master packet
struct demux_packet *next;
} demux_packet_t;
typedef struct demux_stream {
int buffer_pos; // current buffer position
int buffer_size; // current buffer size
unsigned char* buffer; // current buffer, never free() it, always use free_demux_packet(buffer_ref);
double pts; // current buffer's pts
int pts_bytes; // number of bytes read after last pts stamp
int eof; // end of demuxed stream? (true if all buffer empty)
off_t pos; // position in the input stream (file)
off_t dpos; // position in the demuxed stream
int pack_no; // serial number of packet
int flags; // flags of current packet (keyframe etc)
int non_interleaved; // 1 if this stream is not properly interleaved,
int buffer_pos; // current buffer position
int buffer_size; // current buffer size
unsigned char *buffer; // current buffer, never free() it, always use free_demux_packet(buffer_ref);
double pts; // current buffer's pts
int pts_bytes; // number of bytes read after last pts stamp
int eof; // end of demuxed stream? (true if all buffer empty)
off_t pos; // position in the input stream (file)
off_t dpos; // position in the demuxed stream
int pack_no; // serial number of packet
int flags; // flags of current packet (keyframe etc)
int non_interleaved; // 1 if this stream is not properly interleaved,
// so e.g. subtitle handling must do explicit reads.
//---------------
int packs; // number of packets in buffer
int bytes; // total bytes of packets in buffer
demux_packet_t *first; // read to current buffer from here
demux_packet_t *last; // append new packets from input stream to here
demux_packet_t *current;// needed for refcounting of the buffer
int id; // stream ID (for multiple audio/video streams)
struct demuxer *demuxer; // parent demuxer structure (stream handler)
int packs; // number of packets in buffer
int bytes; // total bytes of packets in buffer
demux_packet_t *first; // read to current buffer from here
demux_packet_t *last; // append new packets from input stream to here
demux_packet_t *current; // needed for refcounting of the buffer
int id; // stream ID (for multiple audio/video streams)
struct demuxer *demuxer; // parent demuxer structure (stream handler)
// ---- asf -----
demux_packet_t *asf_packet; // read asf fragments here
int asf_seq;
struct demux_packet *asf_packet; // read asf fragments here
int asf_seq;
// ---- mov -----
unsigned int ss_mul,ss_div;
unsigned int ss_mul, ss_div;
// ---- stream header ----
void* sh;
void *sh;
} demux_stream_t;
typedef struct demuxer_info {
char *name;
char *author;
char *encoder;
char *comments;
char *copyright;
char *name;
char *author;
char *encoder;
char *comments;
char *copyright;
} demuxer_info_t;
#define MAX_A_STREAMS 256
@ -185,33 +185,36 @@ struct demuxer;
* Demuxer description structure
*/
typedef struct demuxer_desc {
const char *info; ///< What is it (long name and/or description)
const char *name; ///< Demuxer name, used with -demuxer switch
const char *shortdesc; ///< Description printed at demuxer detection
const char *author; ///< Demuxer author(s)
const char *comment; ///< Comment, printed with -demuxer help
const char *info; // What is it (long name and/or description)
const char *name; // Demuxer name, used with -demuxer switch
const char *shortdesc; // Description printed at demuxer detection
const char *author; // Demuxer author(s)
const char *comment; // Comment, printed with -demuxer help
int type; ///< DEMUXER_TYPE_xxx
int safe_check; ///< If 1 detection is safe and fast, do it before file extension check
int type; // DEMUXER_TYPE_xxx
// If 1 detection is safe and fast, do it before file extension check
int safe_check;
/// Check if can demux the file, return DEMUXER_TYPE_xxx on success
int (*check_file)(struct demuxer *demuxer); ///< Mandatory if safe_check == 1, else optional
/// Get packets from file, return 0 on eof
int (*fill_buffer)(struct demuxer *demuxer, demux_stream_t *ds); ///< Mandatory
/// Open the demuxer, return demuxer on success, NULL on failure
struct demuxer* (*open)(struct demuxer *demuxer); ///< Optional
/// Close the demuxer
void (*close)(struct demuxer *demuxer); ///< Optional
// Seek
void (*seek)(struct demuxer *demuxer, float rel_seek_secs, float audio_delay, int flags); ///< Optional
// Control
int (*control)(struct demuxer *demuxer, int cmd, void *arg); ///< Optional
// Check if can demux the file, return DEMUXER_TYPE_xxx on success
// Mandatory if safe_check == 1, else optional
int (*check_file)(struct demuxer *demuxer);
/// Get packets from file, return 0 on eof. Mandatory
int (*fill_buffer)(struct demuxer *demuxer, struct demux_stream *ds);
/// Open the demuxer, return demuxer on success, NULL on failure
struct demuxer *(*open)(struct demuxer *demuxer); // Optional
/// Close the demuxer
void (*close)(struct demuxer *demuxer); // Optional
// Seek. Optional
void (*seek)(struct demuxer *demuxer, float rel_seek_secs,
float audio_delay, int flags);
// Various control functions. Optional
int (*control)(struct demuxer *demuxer, int cmd, void *arg);
} demuxer_desc_t;
typedef struct demux_chapter
{
uint64_t start, end;
char* name;
uint64_t start, end;
char *name;
} demux_chapter_t;
struct matroska_data {
@ -229,59 +232,65 @@ struct matroska_data {
typedef struct demux_attachment
{
char* name;
char* type;
void* data;
unsigned int data_size;
char *name;
char *type;
void *data;
unsigned int data_size;
} demux_attachment_t;
typedef struct demuxer {
const demuxer_desc_t *desc; ///< Demuxer description structure
char *filetype; // format name when not identified by demuxer (libavformat)
off_t filepos; // input stream current pos.
off_t movi_start;
off_t movi_end;
stream_t *stream;
double stream_pts; // current stream pts, if applicable (e.g. dvd)
double reference_clock;
char *filename; ///< Needed by avs_check_file
int synced; // stream synced (used by mpeg)
int type; // demuxer type: mpeg PS, mpeg ES, avi, avi-ni, avi-nini, asf
int file_format; // file format: mpeg/avi/asf
int seekable; // flag
const demuxer_desc_t *desc; ///< Demuxer description structure
char *filetype; // format name when not identified by demuxer (libavformat)
off_t filepos; // input stream current pos.
off_t movi_start;
off_t movi_end;
struct stream *stream;
double stream_pts; // current stream pts, if applicable (e.g. dvd)
double reference_clock;
char *filename; // Needed by avs_check_file
int synced; // stream synced (used by mpeg)
int type; // DEMUXER_TYPE_xxx
/* Normally the file_format field is just a copy of the type field above.
* There are 2 exceptions I noticed. Internal demux_avi may force
* ->type to DEMUXER_TYPE_AVI_[NI|NINI] while leaving ->file_format at
* DEMUXER_TYPE_AVI. Internal demux_mov may set ->type to
* DEMUXER_TYPE_PLAYLIST and also return that from the check function
* or not (looks potentially buggy). */
int file_format;
int seekable; // flag
/* Set if using absolute seeks for small movements is OK (no pts resets
* that would make pts ambigious, preferably supports back/forward flags */
bool accurate_seek;
enum timestamp_type timestamp_type;
//
demux_stream_t *audio; // audio buffer/demuxer
demux_stream_t *video; // video buffer/demuxer
demux_stream_t *sub; // dvd subtitle buffer/demuxer
// stream headers:
struct sh_audio *a_streams[MAX_A_STREAMS];
struct sh_video *v_streams[MAX_V_STREAMS];
struct sh_sub *s_streams[MAX_S_STREAMS];
struct demux_stream *audio; // audio buffer/demuxer
struct demux_stream *video; // video buffer/demuxer
struct demux_stream *sub; // dvd subtitle buffer/demuxer
// pointer to teletext decoder private data, if demuxer stream contains teletext
void *teletext;
// stream headers:
struct sh_audio *a_streams[MAX_A_STREAMS];
struct sh_video *v_streams[MAX_V_STREAMS];
struct sh_sub *s_streams[MAX_S_STREAMS];
demux_chapter_t* chapters;
int num_chapters;
// teletext decoder private data, if demuxer stream contains teletext
void *teletext;
demux_attachment_t* attachments;
int num_attachments;
struct demux_chapter *chapters;
int num_chapters;
struct demux_attachment *attachments;
int num_attachments;
struct matroska_data matroska_data;
void* priv; // fileformat-dependent data
char** info;
struct MPOpts *opts;
void *priv; // demuxer-specific internal data
char **info; // metadata
struct MPOpts *opts;
} demuxer_t;
typedef struct {
int progid; //program id
int aid, vid, sid; //audio, video and subtitle id
int progid; //program id
int aid, vid, sid; //audio, video and subtitle id
} demux_program_t;
struct demux_packet *new_demux_packet(size_t len);
@ -293,80 +302,94 @@ void free_demux_packet(struct demux_packet *dp);
#define SIZE_MAX ((size_t)-1)
#endif
static inline void *realloc_struct(void *ptr, size_t nmemb, size_t size) {
if (nmemb > SIZE_MAX / size) {
free(ptr);
return NULL;
}
return realloc(ptr, nmemb * size);
static inline void *realloc_struct(void *ptr, size_t nmemb, size_t size)
{
if (nmemb > SIZE_MAX / size) {
free(ptr);
return NULL;
}
return realloc(ptr, nmemb * size);
}
demux_stream_t* new_demuxer_stream(struct demuxer *demuxer,int id);
demuxer_t* new_demuxer(struct MPOpts *opts, stream_t *stream,int type,int a_id,int v_id,int s_id,char *filename);
void free_demuxer_stream(demux_stream_t *ds);
void free_demuxer(demuxer_t *demuxer);
struct demux_stream *new_demuxer_stream(struct demuxer *demuxer, int id);
struct demuxer *new_demuxer(struct MPOpts *opts, struct stream *stream,
int type, int a_id, int v_id, int s_id,
char *filename);
void free_demuxer_stream(struct demux_stream *ds);
void free_demuxer(struct demuxer *demuxer);
void ds_add_packet(demux_stream_t *ds,demux_packet_t* dp);
void ds_read_packet(demux_stream_t *ds, stream_t *stream, int len, double pts, off_t pos, int flags);
void ds_add_packet(struct demux_stream *ds, struct demux_packet *dp);
void ds_read_packet(struct demux_stream *ds, struct stream *stream, int len,
double pts, off_t pos, int flags);
int demux_fill_buffer(demuxer_t *demux,demux_stream_t *ds);
int ds_fill_buffer(demux_stream_t *ds);
int demux_fill_buffer(struct demuxer *demux, struct demux_stream *ds);
int ds_fill_buffer(struct demux_stream *ds);
static inline off_t ds_tell(demux_stream_t *ds){
return (ds->dpos-ds->buffer_size)+ds->buffer_pos;
static inline off_t ds_tell(struct demux_stream *ds)
{
return (ds->dpos - ds->buffer_size) + ds->buffer_pos;
}
static inline int ds_tell_pts(demux_stream_t *ds){
return (ds->pts_bytes-ds->buffer_size)+ds->buffer_pos;
static inline int ds_tell_pts(struct demux_stream *ds)
{
return (ds->pts_bytes - ds->buffer_size) + ds->buffer_pos;
}
int demux_read_data(demux_stream_t *ds,unsigned char* mem,int len);
int demux_pattern_3(demux_stream_t *ds, unsigned char *mem, int maxlen,
int demux_read_data(struct demux_stream *ds, unsigned char *mem, int len);
int demux_pattern_3(struct demux_stream *ds, unsigned char *mem, int maxlen,
int *read, uint32_t pattern);
#define demux_peekc(ds) (\
(likely(ds->buffer_pos<ds->buffer_size)) ? ds->buffer[ds->buffer_pos] \
:((unlikely(!ds_fill_buffer(ds)))? (-1) : ds->buffer[ds->buffer_pos] ) )
#define demux_peekc(ds) ( \
(likely(ds->buffer_pos<ds->buffer_size)) ? ds->buffer[ds->buffer_pos] \
: ((unlikely(!ds_fill_buffer(ds))) ? (-1) : ds->buffer[ds->buffer_pos]))
#if 1
#define demux_getc(ds) (\
(likely(ds->buffer_pos<ds->buffer_size)) ? ds->buffer[ds->buffer_pos++] \
:((unlikely(!ds_fill_buffer(ds)))? (-1) : ds->buffer[ds->buffer_pos++] ) )
#define demux_getc(ds) ( \
(likely(ds->buffer_pos<ds->buffer_size)) ? ds->buffer[ds->buffer_pos++] \
: ((unlikely(!ds_fill_buffer(ds))) ? (-1) : ds->buffer[ds->buffer_pos++]))
#else
static inline int demux_getc(demux_stream_t *ds){
if(ds->buffer_pos>=ds->buffer_size){
if(!ds_fill_buffer(ds)){
if (ds->buffer_pos>=ds->buffer_size) {
if (!ds_fill_buffer(ds)) {
// printf("DEMUX_GETC: EOF reached!\n");
return -1; // EOF
return -1; // EOF
}
}
}
// printf("[%02X]",ds->buffer[ds->buffer_pos]);
return ds->buffer[ds->buffer_pos++];
return ds->buffer[ds->buffer_pos++];
}
#endif
void ds_free_packs(demux_stream_t *ds);
int ds_get_packet(demux_stream_t *ds,unsigned char **start);
int ds_get_packet_pts(demux_stream_t *ds, unsigned char **start, double *pts);
int ds_get_packet_sub(demux_stream_t *ds,unsigned char **start);
double ds_get_next_pts(demux_stream_t *ds);
int ds_parse(demux_stream_t *sh, uint8_t **buffer, int *len, double pts, off_t pos);
void ds_clear_parser(demux_stream_t *sh);
void ds_free_packs(struct demux_stream *ds);
int ds_get_packet(struct demux_stream *ds, unsigned char **start);
int ds_get_packet_pts(struct demux_stream *ds, unsigned char **start,
double *pts);
int ds_get_packet_sub(struct demux_stream *ds, unsigned char **start);
double ds_get_next_pts(struct demux_stream *ds);
int ds_parse(struct demux_stream *sh, uint8_t **buffer, int *len, double pts,
off_t pos);
void ds_clear_parser(struct demux_stream *sh);
// This is defined here because demux_stream_t ins't defined in stream.h
stream_t* new_ds_stream(demux_stream_t *ds);
stream_t *new_ds_stream(demux_stream_t *ds);
static inline int avi_stream_id(unsigned int id){
unsigned char a,b;
a = id - '0';
b = (id >> 8) - '0';
if(a>9 || b>9) return 100; // invalid ID
return a*10+b;
static inline int avi_stream_id(unsigned int id)
{
unsigned char a, b;
a = id - '0';
b = (id >> 8) - '0';
if (a>9 || b>9)
return 100; // invalid ID
return a * 10 + b;
}
demuxer_t* demux_open(struct MPOpts *opts, stream_t *stream,int file_format,int aid,int vid,int sid,char* filename);
void demux_flush(demuxer_t *demuxer);
int demux_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags);
demuxer_t* new_demuxers_demuxer(demuxer_t* vd, demuxer_t* ad, demuxer_t* sd);
struct demuxer *demux_open(struct MPOpts *opts, struct stream *stream,
int file_format, int aid, int vid, int sid,
char *filename);
void demux_flush(struct demuxer *demuxer);
int demux_seek(struct demuxer *demuxer, float rel_seek_secs, float audio_delay,
int flags);
struct demuxer *new_demuxers_demuxer(struct demuxer *vd, struct demuxer *ad,
struct demuxer *sd);
// AVI demuxer params:
extern int index_mode; // -1=untouched 0=don't use index 1=use (geneate) index
@ -376,43 +399,44 @@ extern int pts_from_bps;
extern int extension_parsing;
int demux_info_add(demuxer_t *demuxer, const char *opt, const char *param);
int demux_info_add_bstr(demuxer_t *demuxer, struct bstr opt, struct bstr param);
char* demux_info_get(demuxer_t *demuxer, const char *opt);
int demux_info_print(demuxer_t *demuxer);
int demux_control(demuxer_t *demuxer, int cmd, void *arg);
int demux_info_add(struct demuxer *demuxer, const char *opt, const char *param);
int demux_info_add_bstr(struct demuxer *demuxer, struct bstr opt,
struct bstr param);
char *demux_info_get(struct demuxer *demuxer, const char *opt);
int demux_info_print(struct demuxer *demuxer);
int demux_control(struct demuxer *demuxer, int cmd, void *arg);
int demuxer_switch_audio(demuxer_t *demuxer, int index);
int demuxer_switch_video(demuxer_t *demuxer, int index);
int demuxer_switch_audio(struct demuxer *demuxer, int index);
int demuxer_switch_video(struct demuxer *demuxer, int index);
int demuxer_type_by_filename(char* filename);
int demuxer_type_by_filename(char *filename);
void demuxer_help(void);
int get_demuxer_type_from_name(char *demuxer_name, int *force);
int demuxer_add_attachment(demuxer_t *demuxer, struct bstr name,
int demuxer_add_attachment(struct demuxer *demuxer, struct bstr name,
struct bstr type, struct bstr data);
int demuxer_add_chapter(demuxer_t *demuxer, struct bstr name,
int demuxer_add_chapter(struct demuxer *demuxer, struct bstr name,
uint64_t start, uint64_t end);
int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, double *seek_pts,
int demuxer_seek_chapter(struct demuxer *demuxer, int chapter, double *seek_pts,
char **chapter_name);
/// Get current chapter index if available.
int demuxer_get_current_chapter(demuxer_t *demuxer, double time_now);
int demuxer_get_current_chapter(struct demuxer *demuxer, double time_now);
/// Get chapter name by index if available.
char *demuxer_chapter_name(demuxer_t *demuxer, int chapter);
char *demuxer_chapter_name(struct demuxer *demuxer, int chapter);
/// Get chapter display name by index.
char *demuxer_chapter_display_name(demuxer_t *demuxer, int chapter);
char *demuxer_chapter_display_name(struct demuxer *demuxer, int chapter);
/// Get chapter start time and end time by index if available.
float demuxer_chapter_time(demuxer_t *demuxer, int chapter, float *end);
float demuxer_chapter_time(struct demuxer *demuxer, int chapter, float *end);
/// Get total chapter number.
int demuxer_chapter_count(demuxer_t *demuxer);
int demuxer_chapter_count(struct demuxer *demuxer);
/// Get current angle index.
int demuxer_get_current_angle(demuxer_t *demuxer);
int demuxer_get_current_angle(struct demuxer *demuxer);
/// Set angle.
int demuxer_set_angle(demuxer_t *demuxer, int angle);
int demuxer_set_angle(struct demuxer *demuxer, int angle);
/// Get number of angles.
int demuxer_angles_count(demuxer_t *demuxer);
int demuxer_angles_count(struct demuxer *demuxer);
/* Get the index of a track.
* lang is a comma-separated list, NULL is same as empty list