⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 av_play.c

📁 ESS3890+SL原代码(1*16内存)
💻 C
📖 第 1 页 / 共 3 页
字号:
/* Copyright 1996, ESS Technology, Inc.                                 *//* SCCSID @(#)av_play.c	4.67 03/16/05 *//* * $Log$ */#include <stdlib.h>#include <ctype.h>#include "vcxi.h"#include "av_play.h"#include "const.h"#include "buffer.h"#include "dsa.h"#include "display.h"#include "mpeg1vid.h"#include "tdm.h"#include "timedef.h"#include "util.h"#include "xport.h"#include "mpgaudio.h"#include "memmap.h"#include "filesys.h"#include "debug.h"#include "play.h"#include "cd.h"#include "low.h"#if defined(ABNORMAL_VCD ) || defined(ANTI_SHOCK)#include "pts.h"#include "vcd.h"#endif#ifdef ECHO#include "echo.h"#endif#ifdef EQUALIZER#include "eq.h"#endif#ifdef MP3#include "mp3.h"#endif#ifdef SERVO#include "servo.h"#endif#ifdef TWO_FIELDS_OSD#include "cg.h"#else#include "fsosd.h"#endif#ifdef JPEG_THUMBNAILextern int JPG_digest;extern int g_jpeg_SOI;extern int g_jpeg_filesize;#endif#ifdef CDG#include "cdg.h"#include "cd_text.h"#endif/*------------------------------------------------------------------------ * Debugging macros *------------------------------------------------------------------------*/#if 0int bpt;#define BREAKPOINT(x) {bpt=x;while(bpt) VCX_service();}#else#define BREAKPOINT(x) #endif#ifdef DEBUG_OSDextern int osdreg;#define CPRINTF(a,b) {osdreg+=3;if(osdreg>13)osdreg=1;debug_osd(a,b,osdreg);}#else#define CPRINTF(a,b)#endif/*------------------------------------------------------------------------  External Variables------------------------------------------------------------------------*/extern int play_sector_state;#ifdef WMA_DECextern int wma_seek_size,wma_smpl_num,wma_byterate,wma_freq;extern int play_item_begin_time;extern ushort sample_rate[];#endif/*------------------------------------------------------------------------  Function Prototypes------------------------------------------------------------------------*/static int play_speed_start();/*------------------------------------------------------------------------  Definitions------------------------------------------------------------------------*/#define VIDEO_DATA_TYPE			0#define AUDIO_DATA_TYPE			1#define TurnOffTDM system_reset/*------------------------------------------------------------------------  Local functions------------------------------------------------------------------------*/static void AV_near_track_end_init(uint);static int start_play_still(void);/*------------------------------------------------------------------------  Global Variables------------------------------------------------------------------------*/uint	AV_near_track_end_time; /* ~10 seconds before end of track */int	vcx_fast_speed_done;static int previous_sector;	/* stored the cd sector that will be used				   to start later.			*/static int skip_mmssff;     /* The skip time for FF/FR      */static int fast_speed_time_limit; /* the end time of FF/FR mode.	*/static int av_timeout;static int play_start_time;static int play_end_time;static int still_type;		/* e1 or e2 */static char data_type=0;		/* VIDEO or AUDIO */int video_state;	        /* state of av play state machine.	*/int cd_pause;		 /* 1 -> in pause mode.			*/static unsigned int	cdda_track_start_time;static int av_in_trick_mode=0;	/* for jumping errors in FF/FR *//*------------------------------------------------------------------------  Function:  Description: In some cases, ther servo will stop and we do not notice.               We have to avoid program hangs in the while loop.------------------------------------------------------------------------*/void turn_off_data(){    int time_out;    /* Set RISC stat bit so XPORT will before at the next SYNC */    mvd[xport_input_mode] = XPORT_input_mode | 0x4;        time_out = glbTimer + TWO_SECOND;    while (XPORT_active) {	if (glbTimer >= time_out) {	    /* force XPORT_active to 0 to get out the loop. */	    TDM_force_stop(1);	/* save stopCDtime */	}#ifdef ECHO	MIC_service();#endif	/* Don't need AUD_service() here...	 * we are stopping data stream(xport) 	 * and don't need to decode audio.	 */    }}#if defined(ABNORMAL_VCD) || defined(ANTI_SHOCK)static void mem_config_restore(int mode){    if (mode & TRACK_IS_ABVCD) {	ABV_start = VCD_ABV_start;	ABV_size = ABNORMAL_ABV_size;	ABV_end = ABV_start + ABV_size;	VBV_end = ISO_end;	VBV_size = ABNORMAL_VBV_size;	VBV_start = VBV_end - VBV_size;    } else#ifdef ANTI_SHOCK    if (mode & ESP_FOR_VCD) {	ABV_start = SHARE_start;	ABV_size = AS_VCD_ABV_size;	ABV_end = ABV_start + ABV_size;	VBV_start = ABV_end;	VBV_size = AS_VCD_VBV_size;	VBV_end = VBV_start + VBV_size;    } else#endif    {	VBV_ABV_default();    }    ABV_wrptr = ABV_rdptr = ABV_start;    VBV_wrptr = VBV_rdptr = VBV_start;}#endif#ifdef ABNORMAL_VCDstatic int sample_stream(int mmssff,uint *pts, uint *time){    int start_time;    clear_dec();     *pts = PTS_vid = 0;    endCDtime = adjCDtime(mmssff, 0x300, 1);    end_of_play = 0;    if (!fuzzyPlaySector(mmssff, 2324)) {        end_of_play = 1;        return (0);    } else {        start_time = glbTimer;        while (1) {            VCX_service();            if (PTS_vid != *pts) {                *pts = PTS_vid;                *time = currCDtime;                break;            }            else if (end_of_play || (currCDtime == endCDtime))                 return (0);            else if ((glbTimer - 240) > start_time)                return (0);        }    }    TDM_force_stop(0);    return (1);}int calc_bitrate(int start_mmssff, int end_mmssff){    uint track_length;    int sample1, sample2, sample3;     uint first_pts, second_pts;    uint firstCDtime, secondCDtime;    track_length = adjCDtime(end_mmssff, start_mmssff, 0);    if ((track_length >> 8) < MIN_TRACK_LEN_CALC) return (600);    sample1 = start_mmssff;    if ((track_length >> 16) >= 5) /* sector time >= 5 minutes */         sample2 = adjCDtime(start_mmssff, 0x0430<<8, 1); /* msf=4:30:00 */    else        sample2 = adjCDtime(end_mmssff, 0x0300, 0);    if (!(sample_stream(sample2, &second_pts, &secondCDtime))) {        sample2 = adjCDtime(end_mmssff, 0x0600, 0);        if (!(sample_stream(sample2, &second_pts, &secondCDtime)))            return (600);     }    if (!(sample_stream(sample1, &first_pts, &firstCDtime))) {        sample1 = adjCDtime(start_mmssff, 0x0300, 1);        if (!(sample_stream(sample1, &first_pts, &firstCDtime)))            return (600);     }    if ((second_pts == first_pts) || (secondCDtime == firstCDtime))        return(600);    mpeg_mux_rate = (second_pts - first_pts) /                      (msf2sectors(secondCDtime) - msf2sectors(firstCDtime));    return (mpeg_mux_rate);}#endif/*------------------------------------------------------------------------  Function: av_play_cdda_audio  Parameters:      start_mmssff :           the start time in BCD's minute, second and frame format.      end_mmssff:          the end time in BCD's minute, second and frame format.  Description:      This function will play a section of audio CD from start_mmssff      to end_mmssff. When this section is finish, the end_of_play      variable will be set to 1.------------------------------------------------------------------------*/int av_play_cdda_audio(int track_mmssff, int start_mmssff, int end_mmssff){#if (defined(CDG) && !defined(ANTI_SHOCK) && !defined(HOST_SLAVE))    if ((track_mmssff==start_mmssff) && (!repeat_a2b)) CDG_init(1);#endif    reset_video_normal_mode(0);    clear_dec();    /* Do this *after* clear_dec() */#ifdef ANTI_SHOCK    PLAY_set_2x_speed = 1; /* fill ABV faster at 2X speed */    /* Get extra space for ABV from VBV */    ABV_size = VCD_ABV_size+32*VBV_write;     ABV_end = ABV_start+ABV_size;    VBV_start = ABV_end;    VBV_size = VCD_VBV_size-32*VBV_write;     VBV_end = VBV_start+VBV_size;#endif    cdda_track_start_time = track_mmssff;    endCDtime = end_mmssff;    if (!playCDDA(track_mmssff, start_mmssff, end_mmssff)) {	end_of_play = 1;	CPRINTF("PLAYCDDA DEAD", start_mmssff);	BREAKPOINT(0);	return (0);    }        /* initialize "near track end" timer */    AV_near_track_end_init(adjCDtime(end_mmssff, track_mmssff, -1));#ifdef DAE_SPATIAL    if (DAE_mode_save > 0) {	/* restore DAE effects processing */	DAE_mode = DAE_mode_save;    }#endif/* Victor: just add a end_of_play reset here to be safe and in sync with other   operation like play_motion and etc. This should be redundente because play.c   will reset end_of_play when each playitem is played. And I already reset it    in dsa.c when end_of_play is set by TDM.c when we read PSD sectors. But I    still got a false end_of_play set by somebody once ?! */    end_of_play = 0;    play_start_time = start_mmssff;    data_type = AUDIO_DATA_TYPE;#ifdef ANTI_SHOCK    video_state = AUDIO_ESP; #else    video_state = AUDIO_NORMAL;#endif}/*------------------------------------------------------------------------  Function: av_play_motion_video  Parameters:      start_mmssff :           the start time in BCD's minute, second and frame format.      end_mmssff:          the end time in BCD's minute, second and frame format.  Description:      This function will play a section of motion video from start_mmssff      to end_mmssff. When this section is finish, the end_of_play      variable will be set to 1.------------------------------------------------------------------------*/int av_play_motion_video(int start_mmssff, int end_mmssff){    ushort *track_muxrate;    #ifdef ANTI_SHOCK    PLAY_set_2x_speed = 1; /* fill buffers quicker at start */#endif /* ANTI_SHOCK */#ifdef ABNORMAL_VCD    if ((vcx_bitstream_type == MPEG1_PS) && iso9660_file_cnt) {        track_muxrate = (ushort *)dram_cached(TRACK_MUXRATE_OFFSET);        if (track_muxrate[cur_track_number] == 0xffff) {            track_muxrate[cur_track_number] =  calc_bitrate(start_mmssff,                                                             end_mmssff);        }        mpeg_mux_rate = track_muxrate[cur_track_number];        if (mpeg_mux_rate >= (600 + MAX_RATE_DIFF)) {	    PLAY_set_2x_speed = 0; /* lower than normal..1X is enough */            abnormal_vcd |= (TRACK_IS_ABVCD | DISC_IS_ABVCD);        } else if (mpeg_mux_rate <= (600 - MAX_RATE_DIFF)) {	    PLAY_set_2x_speed = 1; /* higher than normal..need 2X */	                abnormal_vcd |= (TRACK_IS_ABVCD | DISC_IS_ABVCD);        } else {#ifdef ANTI_SHOCK	    PLAY_set_2x_speed = 1; /* fill buffers quicker at start */#else	    PLAY_set_2x_speed = 0; /* lower than normal..1X is enough */#endif /* ANTI_SHOCK */	    abnormal_vcd &= ~TRACK_IS_ABVCD; /* normal muxrate */	}		PLAY_adj_abvcd_ref_times(); /* adjust some reference times */    }#endif /* ABNORMAL_VCD */        /* set relative variables */    endCDtime = end_mmssff;    end_of_play = 0;    av_in_trick_mode = 0;        /* clear buffers and reset some variables */    reset_video_normal_mode(1);    clear_dec();    data_type = VIDEO_DATA_TYPE;    video_state = VIDEO_NORMAL;#if defined(ABNORMAL_VCD) || defined(ANTI_SHOCK)    if (CDinfo.type == CD_VCD) {        if (abnormal_vcd) {	    if (play_item_begin_time == start_mmssff) {		PTS_vid = 0; /* reset at track begin */	    }            video_state = VIDEO_ABNORMAL;        }    }#endif#ifdef MP3    if (vcx_bitstream_type == MP3_PS) {	video_state = MP3_NORMAL;    }#endif /* MP3 */#ifdef WMA_DEC    if (STREAM_type == WMA_ID) {	video_state = MP3_NORMAL;    	wma_seek_size =( msf2sectors(start_mmssff) -         	msf2sectors(play_item_begin_time) )<<11;    	if ( wma_byterate )            wma_smpl_num = wma_seek_size/wma_byterate * sample_rate[wma_freq];    }#endif /*WMA_DEC*/#ifdef JPEG_DEC    /*     * For jpeg pictures, by the time we see endCDtime, we won't see EOR.     * We'll force a flush to kick out all the data.     */      if (is_jpeg == 1) {         TDM_needs_flush = 1;         video_state = JPEG_NORMAL;    }#endif    if (!playSectors(start_mmssff, 0xe0, 2324)) {	end_of_play = 1;	CPRINTF("PLAYSECTORS DEAD", start_mmssff);	BREAKPOINT(0);	return (0);    }    /* initialize "near track end" time */    AV_near_track_end_init(adjCDtime(end_mmssff, play_item_begin_time, -1));#ifdef DAE_SPATIAL    if (DAE_mode_save > 0) {	/* restore DAE effects processing */	DAE_mode = DAE_mode_save;    }#endif    return (1);}#if defined (WMA_DEC) && defined(FAST_MODE_CONTROL)/* Required for FR across WMA tracks.. * WMA needs to parse header at beginning of the file. */int av_play_init_wma(int start_mmssff, int end_mmssff){    /* set relative variables */    previous_sector = endCDtime = end_mmssff;    end_of_play = 0;        /* clear buffers and reset some variables */    reset_video_normal_mode(1);    clear_dec();    data_type = VIDEO_DATA_TYPE;    video_state = VIDEO_INIT_STATE;    playSectors(start_mmssff, 0xe0, 2324);    return (1);}#endif /* WMA_DEC && FAST_MODE_CONTROL *//*------------------------------------------------------------------------  Function: av_play_still  Parameters:      start_mmssff :           the start time in BCD's minute, second and frame format.      end_mmssff:          the end time in BCD's minute, second and frame format.      type : value should be "0xe1" or "0xe2".  Description:      This function will play a section of still video from start_mmssff      to end_mmssff. When this section is finish, the end_of_play      variable will be set to 1.------------------------------------------------------------------------*/int av_play_still(int start_mmssff, int end_mmssff, int type){    /* store variables used later */    play_start_time = start_mmssff;    play_end_time = end_mmssff;    still_type = type;    end_of_play = 0;    /* clear buffers */    reset_video_normal_mode(1);    /* clear buffers */    clear_dec();    if (!start_play_still()){        TDM_hw_error = 1;        end_of_play = 1;    }    /*     * For still pictures, by the time we see endCDtime, if we have not     * see an EOR, we'll force a flush to kick out all the data.     */    TDM_needs_flush = 1;    return (1);}static int start_play_still(){    endCDtime = play_end_time & x00ffff00;    end_of_play = 0;    VID_frame_count = 0; /* for slide-show detection */    data_type = VIDEO_DATA_TYPE;    video_state = VIDEO_STILL;    /* reset decoder to reset mode */    return (playSectors(play_start_time & x00ffff00, still_type, 2324));}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -