/* Ogle - A video player * Copyright (C) 2000, 2001 Björn Englund, Håkan Hjort * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "debug_print.h" #include "ogle_endian.h" #include "programstream.h" #include "common.h" #include "queue.h" #include "mpeg.h" #ifndef SHM_SHARE_MMU #define SHM_SHARE_MMU 0 #endif typedef enum { STREAM_NOT_REGISTERED = 0, STREAM_DISCARD = 1, STREAM_DECODE = 2, STREAM_MUTED = 3 } stream_state_t; typedef struct { int infile; FILE *file; int shmid; char *shmaddr; stream_state_t state; // not_registerd, in_use, muted, ... } buf_data_t; buf_data_t id_reg[256]; buf_data_t id_reg_ps1[256]; int register_id(uint8_t id, int subtype); int id_registered(uint8_t id, uint8_t subtype); int init_id_reg(stream_state_t default_state); //int wait_for_msg(mq_cmdtype_t cmdtype); //int eval_msg(mq_cmd_t *cmd); int get_buffer(int size); int attach_decoder_buffer(uint8_t stream_id, uint8_t subtype, int shmid); int id_stat(uint8_t id, uint8_t subtype); char *id_qaddr(uint8_t id, uint8_t subtype); FILE *id_file(uint8_t id, uint8_t subtype); void id_add(uint8_t stream_id, uint8_t subtype, stream_state_t state, int shmid, char *shmaddr, FILE *file); int put_in_q(char *q_addr, int off, int len, uint8_t PTS_DTS_flags, uint64_t PTS, uint64_t DTS, int is_new_file, int extra_cmd, PacketType_t packet_type, uint32_t packet_offset); int attach_buffer(int shmid, int size); //int chk_for_msg(void); void loadinputfile(char *infilename); void add_to_demux_q(MsgEvent_t *ev); static void handle_events(MsgEvent_t *ev); int id_infile(uint8_t id, uint8_t subtype); void id_setinfile(uint8_t id, uint8_t subtype, int newfile); uint8_t type_registered(uint8_t id, uint8_t subtype); int switch_to_stream(uint8_t id, uint8_t subtype); int switch_from_to_stream(uint8_t oldid, uint8_t oldsubtype, uint8_t newid, uint8_t newsubtype); int id_has_output(uint8_t stream_id, uint8_t subtype); int id_get_output(uint8_t id, int subtype); typedef struct { uint8_t *buf_start; int len; int in_use; } q_elem; static int msgqid = -1; static MsgEventQ_t *msgq; int scr_discontinuity = 0; uint64_t SCR_base; uint16_t SCR_ext; uint8_t SCR_flags; int packnr = 0; #define MPEG1 0x0 #define MPEG2 0x1 uint8_t *disk_buf; int shmid; char *shmaddr; int shmsize; static int ctrl_data_shmid; static ctrl_data_t *ctrl_data; static ctrl_time_t *ctrl_time; char *data_buf_addr; int off_from; int off_to; int demux_cmd; extern char *optarg; extern int optind, opterr, optopt; /* Variables for getbits */ unsigned int bits_left = 64; uint64_t cur_word = 0; unsigned int nextbits(unsigned int nr_of_bits); int synced = 0; int audio = 0; int debug = 0; char *program_name; int dlevel; FILE *video_file; FILE *audio_file; FILE *subtitle_file; FILE *ps1_file; int video_stream = -1; int infilefd; void* infileaddr; long infilelen; uint32_t offs; char cur_filename[PATH_MAX+1]; int new_file; // #define DEBUG #ifdef STATS static uint32_t stat_video_unaligned_packet_offset = 0; static uint32_t stat_video_unaligned_packet_end = 0; static uint32_t stat_video_n_packets = 0; static uint32_t stat_audio_n_packets = 0; static uint32_t stat_subpicture_n_packets = 0; static uint32_t stat_n_packets = 0; #endif //STATS void usage(void) { fprintf(stderr, "Usage: %s [-v