8 // FIXME: don't include private definitions in external header
9 #include "mpeg3private.h"
12 /* Supported color models for mpeg3_read_frame */
13 #define MPEG3_RGB565 2
14 #define MPEG3_BGR888 0
15 #define MPEG3_BGRA8888 1
16 #define MPEG3_RGB888 3
17 #define MPEG3_RGBA8888 4
18 #define MPEG3_RGBA16161616 5
20 /* Color models for the 601 to RGB conversion */
21 /* 601 not implemented for scalar code */
22 #define MPEG3_601_RGB565 11
23 #define MPEG3_601_BGR888 7
24 #define MPEG3_601_BGRA8888 8
25 #define MPEG3_601_RGB888 9
26 #define MPEG3_601_RGBA8888 10
28 /* Supported color models for mpeg3_read_yuvframe */
29 #define MPEG3_YUV420P 12
30 #define MPEG3_YUV422P 13
35 /* Get version information */
41 /* Check for file compatibility. Return 1 if compatible. */
42 int mpeg3_check_sig(char *path
);
44 /* Open the MPEG stream. */
45 mpeg3_t
* mpeg3_open(char *path
);
47 /* Open the MPEG stream and copy the tables from an already open stream. */
48 /* Eliminates some initial scanning and is used for opening audio streams. */
49 mpeg3_t
* mpeg3_open_copy(char *path
, mpeg3_t
*old_file
);
50 int mpeg3_close(mpeg3_t
*file
);
56 int mpeg3_set_cpus(mpeg3_t
*file
, int cpus
);
58 /* Query the MPEG3 stream about audio. */
59 int mpeg3_has_audio(mpeg3_t
*file
);
60 int mpeg3_total_astreams(mpeg3_t
*file
); /* Number of multiplexed audio streams */
61 int mpeg3_audio_channels(mpeg3_t
*file
, int stream
);
62 int mpeg3_sample_rate(mpeg3_t
*file
, int stream
);
63 char* mpeg3_audio_format(mpeg3_t
*file
, int stream
);
65 /* Total length obtained from the timecode. */
66 /* For DVD files, this is unreliable. */
67 long mpeg3_audio_samples(mpeg3_t
*file
, int stream
);
68 int mpeg3_set_sample(mpeg3_t
*file
, long sample
, int stream
); /* Seek to a sample */
69 long mpeg3_get_sample(mpeg3_t
*file
, int stream
); /* Tell current position */
71 /* Read a PCM buffer of audio from 1 channel and advance the position. */
72 /* Return a 1 if error. */
73 /* Stream defines the number of the multiplexed stream to read. */
74 /* If both output arguments are null the audio is not rendered. */
75 int mpeg3_read_audio(mpeg3_t
*file
,
76 float *output_f
, /* Pointer to pre-allocated buffer of floats */
77 short *output_i
, /* Pointer to pre-allocated buffer of int16's */
78 int channel
, /* Channel to decode */
79 long samples
, /* Number of samples to decode */
80 int stream
); /* Stream containing the channel */
82 /* Reread the last PCM buffer from a different channel and advance the position */
83 int mpeg3_reread_audio(mpeg3_t
*file
,
84 float *output_f
, /* Pointer to pre-allocated buffer of floats */
85 short *output_i
, /* Pointer to pre-allocated buffer of int16's */
86 int channel
, /* Channel to decode */
87 long samples
, /* Number of samples to decode */
88 int stream
); /* Stream containing the channel */
90 /* Read the next compressed audio chunk. Store the size in size and return a */
92 /* Stream defines the number of the multiplexed stream to read. */
93 int mpeg3_read_audio_chunk(mpeg3_t
*file
,
94 unsigned char *output
,
99 /* Query the stream about video. */
100 int mpeg3_has_video(mpeg3_t
*file
);
101 int mpeg3_total_vstreams(mpeg3_t
*file
); /* Number of multiplexed video streams */
102 int mpeg3_video_width(mpeg3_t
*file
, int stream
);
103 int mpeg3_video_height(mpeg3_t
*file
, int stream
);
104 float mpeg3_aspect_ratio(mpeg3_t
*file
, int stream
); /* aspect ratio. 0 if none */
105 double mpeg3_frame_rate(mpeg3_t
*file
, int stream
); /* Frames/sec */
108 /* This is meaningless except for TOC files. */
109 long mpeg3_video_frames(mpeg3_t
*file
, int stream
);
110 int mpeg3_set_frame(mpeg3_t
*file
, long frame
, int stream
); /* Seek to a frame */
111 int mpeg3_skip_frames();
112 long mpeg3_get_frame(mpeg3_t
*file
, int stream
); /* Tell current position */
114 /* Total bytes. Used for absolute byte seeking. */
115 int64_t mpeg3_get_bytes(mpeg3_t
*file
);
117 /* Seek all the tracks to the absolute byte in the */
118 /* file. This eliminates the need for tocs but doesn't */
119 /* give frame accuracy. */
120 int mpeg3_seek_byte(mpeg3_t
*file
, int64_t byte
);
121 int64_t mpeg3_tell_byte(mpeg3_t
*file
);
124 /* To synchronize audio and video in percentage seeking mode, these must */
125 /* be called after percentage seeking the video file and before */
126 /* percentage seeking the audio file. Then when the audio file is percentage */
127 /* seeked it will search for the nearest pts to file->percentage_pts. */
129 * double mpeg3_get_percentage_pts(mpeg3_t *file);
130 * void mpeg3_set_percentage_pts(mpeg3_t *file, double pts);
133 int mpeg3_previous_frame(mpeg3_t
*file
, int stream
);
134 int mpeg3_end_of_audio(mpeg3_t
*file
, int stream
);
135 int mpeg3_end_of_video(mpeg3_t
*file
, int stream
);
137 /* Give the seconds time in the last packet read */
138 double mpeg3_get_time(mpeg3_t
*file
);
140 /* Read a frame. The dimensions of the input area and output frame must be supplied. */
141 /* The frame is taken from the input area and scaled to fit the output frame in 1 step. */
142 /* Stream defines the number of the multiplexed stream to read. */
143 /* The last row of **output_rows must contain 4 extra bytes for scratch work. */
144 int mpeg3_read_frame(mpeg3_t
*file
,
145 unsigned char **output_rows
, /* Array of pointers to the start of each output row */
146 int in_x
, /* Location in input frame to take picture */
150 int out_w
, /* Dimensions of output_rows */
152 int color_model
, /* One of the color model #defines */
155 /* Get the colormodel being used natively by the stream */
156 int mpeg3_colormodel(mpeg3_t
*file
, int stream
);
157 /* Set the row stride to be used in mpeg3_read_yuvframe */
158 int mpeg3_set_rowspan(mpeg3_t
*file
, int bytes
, int stream
);
160 /* Read a frame in the native color model used by the stream. */
161 /* The Y, U, and V planes are copied into the y, u, and v */
162 /* buffers provided. */
163 /* The input is cropped to the dimensions given but not scaled. */
164 int mpeg3_read_yuvframe(mpeg3_t
*file
,
174 /* Read a frame in the native color model used by the stream. */
175 /* The Y, U, and V planes are not copied but the _output pointers */
176 /* are redirected to the frame buffer. */
177 int mpeg3_read_yuvframe_ptr(mpeg3_t
*file
,
183 /* Drop frames number of frames */
184 int mpeg3_drop_frames(mpeg3_t
*file
, long frames
, int stream
);
186 /* Read the next compressed frame including headers. */
187 /* Store the size in size and return a 1 if error. */
188 /* Stream defines the number of the multiplexed stream to read. */
189 int mpeg3_read_video_chunk(mpeg3_t
*file
,
190 unsigned char *output
,
196 int mpeg3_total_programs();
197 int mpeg3_set_program(int program
);
207 /* Table of contents generation */
208 /* Begin constructing table of contents */
209 mpeg3_t
* mpeg3_start_toc(char *path
, char *toc_path
, int64_t *total_bytes
);
210 /* Set the maximum number of bytes per index track */
211 void mpeg3_set_index_bytes(mpeg3_t
*file
, int64_t bytes
);
212 /* Process one packet */
213 int mpeg3_do_toc(mpeg3_t
*file
, int64_t *bytes_processed
);
214 /* Write table of contents */
215 void mpeg3_stop_toc(mpeg3_t
*file
);
224 /* Table of contents queries */
225 /* Return number of tracks in the table of contents */
226 int mpeg3_index_tracks(mpeg3_t
*file
);
227 /* Return number of channels in track */
228 int mpeg3_index_channels(mpeg3_t
*file
, int track
);
229 /* Return zoom factor of index */
230 int mpeg3_index_zoom(mpeg3_t
*file
);
231 /* Number of high/low pairs in a channel of the track */
232 int mpeg3_index_size(mpeg3_t
*file
, int track
);
233 /* Get data for one index channel */
234 float* mpeg3_index_data(mpeg3_t
*file
, int track
, int channel
);
235 /* Returns 1 if the file has a table of contents */
236 int mpeg3_has_toc(mpeg3_t
*file
);