[Mplayerxp-cvslog] SF.net SVN: mplayerxp:[286] mplayerxp
Brought to you by:
olov
From: <nic...@us...> - 2012-11-02 17:31:38
|
Revision: 286 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=286&view=rev Author: nickols_k Date: 2012-11-02 17:31:28 +0000 (Fri, 02 Nov 2012) Log Message: ----------- move xmpcore into separate subfolder Modified Paths: -------------- mplayerxp/Makefile mplayerxp/libao2/ao_wav.c mplayerxp/libao2/audio_out.h mplayerxp/libmpcodecs/ad.h mplayerxp/libmpcodecs/dec_audio.c mplayerxp/libmpcodecs/dec_video.c mplayerxp/libmpcodecs/vd.c mplayerxp/libmpcodecs/vd.h mplayerxp/libmpcodecs/vd_ffmpeg.c mplayerxp/libmpdemux/demuxer_r.c mplayerxp/libmpsub/spudec.c mplayerxp/libvo/sub.c mplayerxp/libvo/video_out.c mplayerxp/libvo/video_out.h mplayerxp/libvo/vo_opengl.c mplayerxp/libvo/vo_sdl.c mplayerxp/libvo/vo_x11.c mplayerxp/libvo/vo_xv.c mplayerxp/libvo/vo_xvidix.c mplayerxp/mplayer.c mplayerxp/postproc/af.h mplayerxp/postproc/mpc_info.h mplayerxp/postproc/vf.c mplayerxp/postproc/vf.h mplayerxp/sig_hand.c mplayerxp/sig_hand.h Added Paths: ----------- mplayerxp/xmpcore/ mplayerxp/xmpcore/Makefile mplayerxp/xmpcore/xmp_adecoder.c mplayerxp/xmpcore/xmp_adecoder.h mplayerxp/xmpcore/xmp_aplayer.c mplayerxp/xmpcore/xmp_aplayer.h mplayerxp/xmpcore/xmp_core.c mplayerxp/xmpcore/xmp_core.h mplayerxp/xmpcore/xmp_enums.h mplayerxp/xmpcore/xmp_vdecoder.c mplayerxp/xmpcore/xmp_vdecoder.h mplayerxp/xmpcore/xmp_vplayer.c mplayerxp/xmpcore/xmp_vplayer.h Removed Paths: ------------- mplayerxp/xmp_adecoder.c mplayerxp/xmp_adecoder.h mplayerxp/xmp_aplayer.c mplayerxp/xmp_aplayer.h mplayerxp/xmp_core.c mplayerxp/xmp_core.h mplayerxp/xmp_enums.h mplayerxp/xmp_vdecoder.c mplayerxp/xmp_vdecoder.h mplayerxp/xmp_vplayer.c mplayerxp/xmp_vplayer.h Modified: mplayerxp/Makefile =================================================================== --- mplayerxp/Makefile 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/Makefile 2012-11-02 17:31:28 UTC (rev 286) @@ -13,7 +13,7 @@ PRG_FIBMAP = fibmap_mplayerxp PRG_CFG = codec-cfg-xp # these subdirectories required installation due binaries within them -SUBDIRS = libmpdemux libmpsub libplaytree libmpcodecs libmpconf libao2 osdep postproc input nls libvo +SUBDIRS = libmpdemux libmpsub libplaytree libmpcodecs libmpconf libao2 osdep postproc input nls libvo xmpcore ifeq ($(TARGET_ARCH_X86),yes) SUBDIRS+=loader endif @@ -25,7 +25,6 @@ SRCS_COMMON = mp_msg.c mp_image.c SRCS_MPLAYER = mplayer.c fifo.c $(SRCS_COMMON) mixer.c mp-opt-reg.c sig_hand.c dump.c -SRCS_MPLAYER+= xmp_core.c xmp_aplayer.c xmp_vplayer.c xmp_vdecoder.c xmp_adecoder.c OBJS_MPLAYER = $(SRCS_MPLAYER:.c=.o) @@ -45,7 +44,8 @@ libvo/libvo.a \ osdep/libosdep.a \ nls/libnls.a \ - libmpconf/libmpconf.a + libmpconf/libmpconf.a \ + xmpcore/libxmpcore.a ifeq ($(TARGET_ARCH_X86),yes) MP_LIBS += loader/libloader.a endif Modified: mplayerxp/libao2/ao_wav.c =================================================================== --- mplayerxp/libao2/ao_wav.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/libao2/ao_wav.c 2012-11-02 17:31:28 UTC (rev 286) @@ -23,7 +23,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "xmp_core.h" +#include "xmpcore/xmp_core.h" #include "osdep/bswap.h" #include "postproc/af_format.h" Modified: mplayerxp/libao2/audio_out.h =================================================================== --- mplayerxp/libao2/audio_out.h 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/libao2/audio_out.h 2012-11-02 17:31:28 UTC (rev 286) @@ -1,7 +1,7 @@ #ifndef __AUDIO_OUT_H #define __AUDIO_OUT_H 1 #include "mp_config.h" -#include "xmp_enums.h" +#include "xmpcore/xmp_enums.h" /** Text description of AO-driver */ typedef struct ao_info_s { Modified: mplayerxp/libmpcodecs/ad.h =================================================================== --- mplayerxp/libmpcodecs/ad.h 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/libmpcodecs/ad.h 2012-11-02 17:31:28 UTC (rev 286) @@ -5,7 +5,7 @@ #define AD_H_INCLUDED 1 #include "libmpconf/cfgparser.h" -#include "xmp_enums.h" +#include "xmpcore/xmp_enums.h" typedef struct ad_info_s { Modified: mplayerxp/libmpcodecs/dec_audio.c =================================================================== --- mplayerxp/libmpcodecs/dec_audio.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/libmpcodecs/dec_audio.c 2012-11-02 17:31:28 UTC (rev 286) @@ -6,7 +6,7 @@ #include "help_mp.h" #include "mplayer.h" -#include "xmp_core.h" +#include "xmpcore/xmp_core.h" #include "libmpdemux/stream.h" #include "libmpdemux/demuxer.h" Modified: mplayerxp/libmpcodecs/dec_video.c =================================================================== --- mplayerxp/libmpcodecs/dec_video.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/libmpcodecs/dec_video.c 2012-11-02 17:31:28 UTC (rev 286) @@ -27,7 +27,7 @@ #include "vd.h" -#include "xmp_core.h" +#include "xmpcore/xmp_core.h" #include "dec_video.h" #include "libmpsub/spudec.h" #include "libmpsub/vobsub.h" Modified: mplayerxp/libmpcodecs/vd.c =================================================================== --- mplayerxp/libmpcodecs/vd.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/libmpcodecs/vd.c 2012-11-02 17:31:28 UTC (rev 286) @@ -5,7 +5,7 @@ #include "mp_config.h" #include "help_mp.h" -#include "xmp_core.h" +#include "xmpcore/xmp_core.h" #include "libmpconf/codec-cfg.h" #include "libvo/img_format.h" Modified: mplayerxp/libmpcodecs/vd.h =================================================================== --- mplayerxp/libmpcodecs/vd.h 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/libmpcodecs/vd.h 2012-11-02 17:31:28 UTC (rev 286) @@ -2,7 +2,7 @@ #define VD_H_INCLUDED 1 #include "libmpconf/cfgparser.h" -#include "xmp_enums.h" +#include "xmpcore/xmp_enums.h" typedef struct vd_info_s { Modified: mplayerxp/libmpcodecs/vd_ffmpeg.c =================================================================== --- mplayerxp/libmpcodecs/vd_ffmpeg.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/libmpcodecs/vd_ffmpeg.c 2012-11-02 17:31:28 UTC (rev 286) @@ -6,7 +6,7 @@ #include "mp_config.h" #include "mplayer.h" -#include "xmp_core.h" +#include "xmpcore/xmp_core.h" #ifdef HAVE_GOMP #include <omp.h> #endif Modified: mplayerxp/libmpdemux/demuxer_r.c =================================================================== --- mplayerxp/libmpdemux/demuxer_r.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/libmpdemux/demuxer_r.c 2012-11-02 17:31:28 UTC (rev 286) @@ -11,7 +11,7 @@ #include "osdep/timer.h" #include "mplayer.h" -#include "xmp_core.h" +#include "xmpcore/xmp_core.h" #include "demux_msg.h" pthread_mutex_t demuxer_mutex=PTHREAD_MUTEX_INITIALIZER; Modified: mplayerxp/libmpsub/spudec.c =================================================================== --- mplayerxp/libmpsub/spudec.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/libmpsub/spudec.c 2012-11-02 17:31:28 UTC (rev 286) @@ -21,7 +21,7 @@ #include <unistd.h> #include <math.h> -#include "xmp_core.h" +#include "xmpcore/xmp_core.h" #include "spudec.h" #include "postproc/swscale.h" #include "osdep/mplib.h" Modified: mplayerxp/libvo/sub.c =================================================================== --- mplayerxp/libvo/sub.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/libvo/sub.c 2012-11-02 17:31:28 UTC (rev 286) @@ -5,7 +5,7 @@ #include <string.h> #include "mplayer.h" -#include "xmp_core.h" +#include "xmpcore/xmp_core.h" #include "video_out.h" #include "font_load.h" #include "sub.h" Modified: mplayerxp/libvo/video_out.c =================================================================== --- mplayerxp/libvo/video_out.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/libvo/video_out.c 2012-11-02 17:31:28 UTC (rev 286) @@ -32,7 +32,7 @@ #include "osdep/shmem.h" #include "postproc/swscale.h" #include "postproc/vf.h" -#include "xmp_core.h" +#include "xmpcore/xmp_core.h" #include "osdep/mplib.h" #include "mplayer.h" #include "osdep/fastmemcpy.h" Modified: mplayerxp/libvo/video_out.h =================================================================== --- mplayerxp/libvo/video_out.h 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/libvo/video_out.h 2012-11-02 17:31:28 UTC (rev 286) @@ -21,7 +21,7 @@ #include "libmpsub/subreader.h" #include "img_format.h" #include "mp_image.h" -#include "xmp_enums.h" +#include "xmpcore/xmp_enums.h" enum { VO_EVENT_EXPOSE=1, Modified: mplayerxp/libvo/vo_opengl.c =================================================================== --- mplayerxp/libvo/vo_opengl.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/libvo/vo_opengl.c 2012-11-02 17:31:28 UTC (rev 286) @@ -25,7 +25,7 @@ #include "mp_config.h" #include "mplayer.h" -#include "xmp_core.h" +#include "xmpcore/xmp_core.h" #include "dri_vo.h" #include "video_out.h" Modified: mplayerxp/libvo/vo_sdl.c =================================================================== --- mplayerxp/libvo/vo_sdl.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/libvo/vo_sdl.c 2012-11-02 17:31:28 UTC (rev 286) @@ -109,7 +109,7 @@ #include "mp_config.h" #include "mplayer.h" -#include "xmp_core.h" +#include "xmpcore/xmp_core.h" #include "video_out.h" Modified: mplayerxp/libvo/vo_x11.c =================================================================== --- mplayerxp/libvo/vo_x11.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/libvo/vo_x11.c 2012-11-02 17:31:28 UTC (rev 286) @@ -28,7 +28,7 @@ #include "mp_config.h" #include "mplayer.h" -#include "xmp_core.h" +#include "xmpcore/xmp_core.h" #include "aspect.h" #include "video_out.h" Modified: mplayerxp/libvo/vo_xv.c =================================================================== --- mplayerxp/libvo/vo_xv.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/libvo/vo_xv.c 2012-11-02 17:31:28 UTC (rev 286) @@ -18,7 +18,7 @@ #include "mp_config.h" #include "mplayer.h" -#include "xmp_core.h" +#include "xmpcore/xmp_core.h" #include "osdep/mplib.h" #include "video_out.h" #include "video_out_internal.h" Modified: mplayerxp/libvo/vo_xvidix.c =================================================================== --- mplayerxp/libvo/vo_xvidix.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/libvo/vo_xvidix.c 2012-11-02 17:31:28 UTC (rev 286) @@ -17,7 +17,7 @@ #include "mp_config.h" #include "mplayer.h" #include "osdep/mplib.h" -#include "xmp_core.h" +#include "xmpcore/xmp_core.h" #include "video_out.h" #include "video_out_internal.h" Modified: mplayerxp/mplayer.c =================================================================== --- mplayerxp/mplayer.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/mplayer.c 2012-11-02 17:31:28 UTC (rev 286) @@ -72,9 +72,9 @@ #include "postproc/libmenu/menu.h" #include "mixer.h" -#include "xmp_core.h" -#include "xmp_vplayer.h" -#include "xmp_adecoder.h" +#include "xmpcore/xmp_core.h" +#include "xmpcore/xmp_vplayer.h" +#include "xmpcore/xmp_adecoder.h" #define MSGT_CLASS MSGT_CPLAYER #include "mp_msg.h" Modified: mplayerxp/postproc/af.h =================================================================== --- mplayerxp/postproc/af.h 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/postproc/af.h 2012-11-02 17:31:28 UTC (rev 286) @@ -4,10 +4,10 @@ #include <stdio.h> #include "af_mp.h" -#include "../mp_config.h" +#include "mp_config.h" #include "af_control.h" #include "af_format.h" -#include "xmp_enums.h" +#include "xmpcore/xmp_enums.h" struct af_instance_s; Modified: mplayerxp/postproc/mpc_info.h =================================================================== --- mplayerxp/postproc/mpc_info.h 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/postproc/mpc_info.h 2012-11-02 17:31:28 UTC (rev 286) @@ -1,6 +1,5 @@ #ifndef MP_CODEC_INFO_T #define MP_CODEC_INFO_T -#include "xmp_enums.h" typedef struct mp_codec_info_s { Modified: mplayerxp/postproc/vf.c =================================================================== --- mplayerxp/postproc/vf.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/postproc/vf.c 2012-11-02 17:31:28 UTC (rev 286) @@ -3,7 +3,7 @@ #include <string.h> #include "mp_config.h" -#include "xmp_core.h" +#include "xmpcore/xmp_core.h" #include "mplayer.h" #include "help_mp.h" Modified: mplayerxp/postproc/vf.h =================================================================== --- mplayerxp/postproc/vf.h 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/postproc/vf.h 2012-11-02 17:31:28 UTC (rev 286) @@ -1,6 +1,6 @@ #ifndef __VF_H #define __VF_H 1 -#include "xmp_enums.h" +#include "xmpcore/xmp_enums.h" #include "libmpdemux/stream.h" #include "libmpdemux/demuxer.h" #include "libmpdemux/stheader.h" Modified: mplayerxp/sig_hand.c =================================================================== --- mplayerxp/sig_hand.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/sig_hand.c 2012-11-02 17:31:28 UTC (rev 286) @@ -15,7 +15,7 @@ #include <sys/types.h> #include <unistd.h> #include <stdlib.h> -#include "xmp_core.h" +#include "xmpcore/xmp_core.h" #include "mp_msg.h" #include "osdep/mplib.h" #define MSGT_CLASS MSGT_CPLAYER Modified: mplayerxp/sig_hand.h =================================================================== --- mplayerxp/sig_hand.h 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/sig_hand.h 2012-11-02 17:31:28 UTC (rev 286) @@ -5,7 +5,7 @@ #define __SIG_HAND_H 1 #include <sys/types.h> -#include "xmp_core.h" +#include "xmpcore/xmp_core.h" static inline void __MP_UNIT(unsigned id,const char *name) { xp_core->mpxp_threads[id]->unit=name; } static inline void MP_UNIT(const char *name) { xp_core->mpxp_threads[main_id]->unit=name; } Deleted: mplayerxp/xmp_adecoder.c =================================================================== --- mplayerxp/xmp_adecoder.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/xmp_adecoder.c 2012-11-02 17:31:28 UTC (rev 286) @@ -1,520 +0,0 @@ -#include "mplayer.h" -#include "mp_msg.h" -#include "sig_hand.h" -#include "xmp_core.h" -#include "xmp_adecoder.h" -#include "osdep/mplib.h" -#include "osdep/timer.h" -#include "libmpcodecs/dec_audio.h" - -#include <errno.h> -#include <stdio.h> -#include <unistd.h> // for usleep() -#include <math.h> - -#ifdef ENABLE_DEC_AHEAD_DEBUG -#define MSG_T(args...) mp_msg(MSGT_GLOBAL, MSGL_DBG2,__FILE__,__LINE__, ## args ) -#else -#define MSG_T(args...) -#endif - -extern int get_free_audio_buffer(void); - -/************************************************************************ - AUDIO XP-CORE! ToDo: rewrite it in packet-mode -************************************************************************/ -/* XP audio buffer */ -pthread_mutex_t audio_timer_mutex=PTHREAD_MUTEX_INITIALIZER; -typedef struct audio_buffer_index_s { - float pts; - int index; -} audio_buffer_index_t; - -typedef struct audio_buffer_s { - unsigned char* buffer; - int head; - int tail; - unsigned len; - unsigned size; - int min_reserv; - int min_len; - int eof; - int HasReset; - int blocked_readers; - pthread_mutex_t head_mutex; - pthread_mutex_t tail_mutex; - pthread_cond_t wait_buffer_cond; - sh_audio_t *sh_audio; - - audio_buffer_index_t *indices; - int index_head; - int index_tail; - int index_len; -} audio_buffer_t; - -audio_buffer_t audio_buffer; - -int init_audio_buffer( int size, int min_reserv, int indices, sh_audio_t *sha ) -{ - MSG_V("Using audio buffer %i bytes (min reserve = %i, indices %i)\n",size,min_reserv, indices); - if( !(audio_buffer.buffer = mp_malloc(size)) ) - return ENOMEM; - if( !(audio_buffer.indices = mp_malloc(indices*sizeof(audio_buffer_index_t))) ) { - mp_free(audio_buffer.buffer); - audio_buffer.buffer=NULL; - return ENOMEM; - } - audio_buffer.index_len=indices; - audio_buffer.index_head=0; - audio_buffer.index_tail=0; - audio_buffer.head = 0; - audio_buffer.tail = 0; - audio_buffer.len = size; - audio_buffer.size = size; - audio_buffer.min_reserv = min_reserv; - audio_buffer.min_len = size/indices+1; - audio_buffer.eof = 0; - audio_buffer.HasReset = 0; - audio_buffer.blocked_readers = 0; - pthread_mutex_init( &audio_buffer.head_mutex, NULL); - pthread_mutex_init( &audio_buffer.tail_mutex, NULL); - pthread_cond_init( &audio_buffer.wait_buffer_cond, NULL); - audio_buffer.sh_audio = sha; - return 0; -} - -void uninit_audio_buffer(void) -{ - audio_buffer.eof = 1; - - if( audio_buffer.blocked_readers > 0 ) { /* Make blocked reader exit */ - int loops = 10; - pthread_cond_broadcast( &audio_buffer.wait_buffer_cond ); - while( audio_buffer.blocked_readers > 0 && loops > 0 ) { - usleep(1); - loops--; - } - if( audio_buffer.blocked_readers > 0 ) - MSG_V("uninit_audio_buffer: %d blocked readers did not wake up\n", - audio_buffer.blocked_readers); - } - - audio_buffer.index_len=0; - audio_buffer.index_head=0; - audio_buffer.index_tail=0; - audio_buffer.head = 0; - audio_buffer.tail = 0; - audio_buffer.len = 0; - audio_buffer.size = 0; - audio_buffer.min_reserv = 0; - audio_buffer.min_len = 0; - audio_buffer.HasReset = 0; - audio_buffer.blocked_readers = 0; - - pthread_mutex_lock( &audio_buffer.head_mutex ); - pthread_mutex_unlock( &audio_buffer.head_mutex ); - pthread_mutex_destroy( &audio_buffer.head_mutex ); - - pthread_mutex_lock( &audio_buffer.tail_mutex ); - pthread_mutex_unlock( &audio_buffer.tail_mutex ); - pthread_mutex_destroy( &audio_buffer.tail_mutex ); - - pthread_cond_destroy( &audio_buffer.wait_buffer_cond ); - - if( audio_buffer.buffer ) - mp_free( audio_buffer.buffer ); - audio_buffer.buffer = NULL; - - if( audio_buffer.indices ) - mp_free( audio_buffer.indices ); - audio_buffer.indices = NULL; - /* audio_buffer.sh_audio = ?; */ -} - -int read_audio_buffer( sh_audio_t *audio, unsigned char *buffer, unsigned minlen, unsigned maxlen, float *pts ) -{ - unsigned len = 0; - int l = 0; - int next_idx; - int head_idx; - int head_pos; - int head; - UNUSED(audio); - pthread_mutex_lock( &audio_buffer.tail_mutex ); - - while( len < minlen ) { - if( audio_buffer.tail == audio_buffer.head ) { - if( audio_buffer.eof ) { - break; - } - audio_buffer.blocked_readers++; - dec_ahead_can_aseek=1; /* Safe to seek while we wait for data */ - pthread_cond_wait(&audio_buffer.wait_buffer_cond, &audio_buffer.tail_mutex ); - dec_ahead_can_aseek=0; - audio_buffer.blocked_readers--; - if( audio_buffer.HasReset ) { - audio_buffer.HasReset = 0; - len = 0; - l =0; - } - continue; - } - - l = min( (int)(maxlen - len), audio_buffer.head - audio_buffer.tail ); - if(l<0) { - l = min( maxlen - len, audio_buffer.len - audio_buffer.tail ); - if( l == 0 ) { - if( audio_buffer.head != audio_buffer.tail ) - audio_buffer.tail = 0; - continue; - } - } - - memcpy( &buffer[len], &audio_buffer.buffer[audio_buffer.tail], l ); - len += l; - audio_buffer.tail += l; - if( audio_buffer.tail >= audio_buffer.len && audio_buffer.tail != audio_buffer.head ) - audio_buffer.tail = 0; - } - - if( len > 0 ) { /* get pts to return and calculate next pts */ - next_idx = (audio_buffer.index_tail+1)%audio_buffer.index_len; - head_idx = audio_buffer.index_head; - head_pos = audio_buffer.indices[(head_idx-1+audio_buffer.index_len)%audio_buffer.index_len].index; - head = audio_buffer.head; - if( next_idx != head_idx && audio_buffer.indices[next_idx].index == audio_buffer.indices[audio_buffer.index_tail].index ) { - audio_buffer.index_tail = next_idx; /* Buffer was empty */ - next_idx = (audio_buffer.index_tail+1)%audio_buffer.index_len; - } - *pts = audio_buffer.indices[audio_buffer.index_tail].pts; - - MSG_DBG3("audio_ahead: len %i, tail %i pts %.3f tail_idx %3i head_idx %3i head_pos %3i\n", len,audio_buffer.tail,*pts, audio_buffer.index_tail, head_idx, head_pos ); - while( next_idx != head_idx && - ((audio_buffer.tail <= head && - (audio_buffer.indices[next_idx].index <= audio_buffer.tail || - head_pos < audio_buffer.indices[next_idx].index)) || - (head < audio_buffer.indices[next_idx].index && - audio_buffer.indices[next_idx].index <= audio_buffer.tail))) { - MSG_DBG3("audio_ahead: next_idx %3i index %3i \n", next_idx, audio_buffer.indices[next_idx].index); - next_idx=(next_idx+1)%audio_buffer.index_len; - } - audio_buffer.index_tail = (next_idx-1+audio_buffer.index_len)%audio_buffer.index_len; - if( audio_buffer.indices[audio_buffer.index_tail].index != audio_buffer.tail ) { - int buff_len = audio_buffer.len; - MSG_DBG3("audio_ahead: orig idx %3i pts %.3f pos %i \n",audio_buffer.index_tail, audio_buffer.indices[audio_buffer.index_tail].pts,audio_buffer.indices[audio_buffer.index_tail].index ); - audio_buffer.indices[audio_buffer.index_tail].pts += (float)((audio_buffer.tail - audio_buffer.indices[audio_buffer.index_tail].index + buff_len) % buff_len) / (float)audio_buffer.sh_audio->af_bps; - audio_buffer.indices[audio_buffer.index_tail].index = audio_buffer.tail; - MSG_DBG3("audio_ahead: read next_idx %3i next_pts %.3f pos %i \n", audio_buffer.index_tail,audio_buffer.indices[audio_buffer.index_tail].pts,audio_buffer.indices[audio_buffer.index_tail].index ); - } - } - - pthread_mutex_unlock( &audio_buffer.tail_mutex ); - - return len; -} - -float get_delay_audio_buffer(void) -{ - int delay = audio_buffer.head - audio_buffer.tail; - if( delay < 0 ) - delay += audio_buffer.len; - return (float)delay / (float)audio_buffer.sh_audio->af_bps; -} - -int decode_audio_buffer(demux_stream_t *d_audio,unsigned len) -{ - int ret, blen, l, l2; - int next_idx; - unsigned int t; - - pthread_mutex_lock( &audio_buffer.head_mutex ); - - t = GetTimer(); - if (len < audio_buffer.sh_audio->audio_out_minsize) - len = audio_buffer.sh_audio->audio_out_minsize; - - if( audio_buffer.size - audio_buffer.head <= audio_buffer.min_reserv ) { - if( audio_buffer.tail == 0 ) { - pthread_mutex_unlock( &audio_buffer.head_mutex ); - return 0; - } - audio_buffer.len = audio_buffer.head; - audio_buffer.head = 0; - len = min( len, audio_buffer.tail - audio_buffer.head - audio_buffer.min_reserv); - if( len < audio_buffer.sh_audio->audio_out_minsize ) { - pthread_mutex_unlock( &audio_buffer.head_mutex ); - return 0; - } - } - - blen = audio_buffer.size - audio_buffer.head; - if( (l = (blen - audio_buffer.min_reserv)) < len ) { - len = max(l,audio_buffer.sh_audio->audio_out_minsize); - } - - if( (l = (audio_buffer.tail - audio_buffer.head)) > 0 ) { - blen = l; - l -= audio_buffer.min_reserv; - if( l < len ) { - len = l; - if( len < audio_buffer.sh_audio->audio_out_minsize ) { - pthread_mutex_unlock( &audio_buffer.head_mutex ); - return 0; - } - } - } - MSG_DBG3("decode audio %d h %d, t %d, l %d \n", len, audio_buffer.head, audio_buffer.tail, audio_buffer.len); - - for( l = 0, l2 = len, ret = 0; l < len && l2 >= audio_buffer.sh_audio->audio_out_minsize; ) { - float pts; - ret = mpca_decode( audio_buffer.sh_audio, &audio_buffer.buffer[audio_buffer.head], audio_buffer.min_len, l2,blen,&pts); - if( ret <= 0 ) - break; - - next_idx = (audio_buffer.index_head+1)%audio_buffer.index_len; - if( next_idx != audio_buffer.index_tail ) { - MSG_DBG3("decode audio idx %3i tail %3i next pts %.3f %i\n",audio_buffer.index_head, audio_buffer.index_tail, pts, audio_buffer.head ); - audio_buffer.indices[audio_buffer.index_head].pts = pts; - audio_buffer.indices[audio_buffer.index_head].index = audio_buffer.head; - audio_buffer.index_head = next_idx; - } - audio_buffer.head+=ret; - MSG_DBG3("new head %6d \n", audio_buffer.head); - l += ret; - l2 -= ret; - blen -= ret; - } - MSG_DBG2("decoded audio %d diff %d\n", l, l - len); - - if( ret <= 0 && d_audio->eof) { - MSG_V("audio eof\n"); - audio_buffer.eof=1; - pthread_mutex_unlock( &audio_buffer.head_mutex ); - pthread_mutex_lock( &audio_buffer.tail_mutex ); - pthread_cond_broadcast( &audio_buffer.wait_buffer_cond ); - pthread_mutex_unlock( &audio_buffer.tail_mutex ); - return 0; - } - - if( audio_buffer.head > audio_buffer.len ) - audio_buffer.len=audio_buffer.head; - if( audio_buffer.head >= audio_buffer.size && audio_buffer.tail > 0 ) - audio_buffer.head = 0; - - pthread_cond_signal( &audio_buffer.wait_buffer_cond ); - - t=GetTimer()-t; - mp_data->bench->audio_decode+=t*0.000001f; - mp_data->bench->audio_decode-=mp_data->bench->audio_decode_correction; - if(mp_conf.benchmark) - { - if(t > mp_data->bench->max_audio_decode) mp_data->bench->max_audio_decode = t; - if(t < mp_data->bench->min_audio_decode) mp_data->bench->min_audio_decode = t; - } - - pthread_mutex_unlock( &audio_buffer.head_mutex ); - - - blen = audio_buffer.head - audio_buffer.tail; - if( blen < 0 ) - blen += audio_buffer.len; - if( blen < MAX_OUTBURST ) { - return 2; - } - return 1; -} - -void reset_audio_buffer(void) -{ - pthread_mutex_lock( &audio_buffer.head_mutex ); - pthread_mutex_lock( &audio_buffer.tail_mutex ); - - audio_buffer.tail = audio_buffer.head; - audio_buffer.len = audio_buffer.size; - audio_buffer.eof = 0; - audio_buffer.HasReset = 1; - audio_buffer.index_tail = audio_buffer.index_head; - - pthread_mutex_unlock( &audio_buffer.tail_mutex ); - pthread_mutex_unlock( &audio_buffer.head_mutex ); -} - -int get_len_audio_buffer(void) -{ - int len = audio_buffer.head - audio_buffer.tail; - if( len < 0 ) - len += audio_buffer.len; - return len; -} - -int get_free_audio_buffer(void) -{ - int len; - - if( audio_buffer.eof ) - return -1; - - if( audio_buffer.size - audio_buffer.head < audio_buffer.min_reserv && - audio_buffer.tail > 0 ) { - pthread_mutex_lock( &audio_buffer.head_mutex ); - audio_buffer.len = audio_buffer.head; - audio_buffer.head = 0; - pthread_mutex_unlock( &audio_buffer.head_mutex ); - } - - len = audio_buffer.tail - audio_buffer.head; - if( len <= 0 ) - len += audio_buffer.size; - len -= audio_buffer.min_reserv; - - if( len <= 0 ) - return 0; - - return len; -} - - -/* Audio stuff */ -volatile float dec_ahead_audio_delay; -int xp_thread_decode_audio(demux_stream_t *d_audio) -{ - sh_audio_t* sh_audio=xp_core->audio->sh; - sh_video_t* sh_video=NULL; - if(xp_core->video) sh_video=xp_core->video->sh; - int free_buf, vbuf_size, pref_buf; - unsigned len=0; - - free_buf = get_free_audio_buffer(); - - if( free_buf == -1 ) { /* End of file */ - xp_core->audio->eof = 1; - return 0; - } - if( free_buf < (int)sh_audio->audio_out_minsize ) /* full */ - return 0; - - len = get_len_audio_buffer(); - - if( len < MAX_OUTBURST ) /* Buffer underrun */ - return decode_audio_buffer(d_audio,MAX_OUTBURST); - - if(xp_core->video) { - /* Match video buffer */ - vbuf_size = dae_get_decoder_outrun(xp_core->video); - pref_buf = vbuf_size / sh_video->fps * sh_audio->af_bps; - pref_buf -= len; - if( pref_buf > 0 ) { - len = min( pref_buf, free_buf ); - if( len > sh_audio->audio_out_minsize ) { - return decode_audio_buffer(d_audio,len); - } - } - } else - return decode_audio_buffer(d_audio,min(free_buf,MAX_OUTBURST)); - - return 0; -} - -static volatile int dec_ahead_can_adseek=1; /* It is safe to seek audio buffer thread */ -/* this routine decodes audio only */ -any_t* a_dec_ahead_routine( any_t* arg ) -{ - mpxp_thread_t* priv=arg; - sh_audio_t* sh_audio=priv->dae->sh; - demux_stream_t *d_audio=sh_audio->ds; - - int ret, retval; - struct timeval now; - struct timespec timeout; - float d; - - priv->state=Pth_Run; - if(xp_core->video) xp_core->video->eof=0; - xp_core->audio->eof=0; - MSG_T("\nDEC_AHEAD: entering...\n"); - priv->pid = getpid(); - __MP_UNIT(priv->p_idx,"dec_ahead"); - - dec_ahead_can_adseek=0; - while(priv->state!=Pth_Canceling) { - if(priv->state==Pth_Sleep) { - priv->state=Pth_ASleep; - while(priv->state==Pth_ASleep) usleep(0); - continue; - } - __MP_UNIT(priv->p_idx,"decode audio"); - while((ret = xp_thread_decode_audio(d_audio)) == 2) {/* Almost empty buffer */ - if(xp_core->audio->eof) break; - } - dec_ahead_can_adseek=1; - - if(priv->state==Pth_Canceling) break; - - __MP_UNIT(priv->p_idx,"sleep"); - LOCK_AUDIO_DECODE(); - if(priv->state!=Pth_Canceling) { - if(xp_core->audio->eof) { - __MP_UNIT(priv->p_idx,"wait end of work"); - pthread_cond_wait( &audio_decode_cond, &audio_decode_mutex ); - } else if(ret==0) { /* Full buffer or end of file */ - if(audio_play_in_sleep) { /* Sleep a little longer than player thread */ - timeout.tv_nsec = audio_play_timeout.tv_nsec + 10000; - if( timeout.tv_nsec > 1000000000l ) { - timeout.tv_nsec-=1000000000l; - timeout.tv_sec = audio_play_timeout.tv_sec; - } else - timeout.tv_sec = audio_play_timeout.tv_sec; - } else { - if(xp_core->in_pause) - d = 1.0; - else - d = 0.1; - gettimeofday(&now,NULL); - timeout.tv_nsec = now.tv_usec * 1000 + d*1000000000l; - if( timeout.tv_nsec > 1000000000l ) { - timeout.tv_nsec-=1000000000l; - timeout.tv_sec = now.tv_sec + 1; - } else - timeout.tv_sec = now.tv_sec; - } - pthread_cond_timedwait( &audio_decode_cond, &audio_decode_mutex, &timeout ); - } else - usleep(1); - } - UNLOCK_AUDIO_DECODE(); - - if(priv->state==Pth_Canceling) break; - - __MP_UNIT(priv->p_idx,"seek"); - LOCK_AUDIO_DECODE(); -#if 0 - while(priv->state==Pth_Sleep && priv->state!=Pth_Canceling) { - gettimeofday(&now,NULL); - timeout.tv_nsec = now.tv_usec * 1000; - timeout.tv_sec = now.tv_sec + 1; - retval = pthread_cond_timedwait( &audio_decode_cond, &audio_decode_mutex, &timeout ); - if( retval == ETIMEDOUT ) - MSG_V("Audio decode seek timeout\n"); - } -#endif - dec_ahead_can_adseek = 0; /* Not safe to seek */ - UNLOCK_AUDIO_DECODE(); - } - __MP_UNIT(priv->p_idx,"exit"); - dec_ahead_can_adseek = 1; - priv->state=Pth_Stand; - return arg; /* terminate thread here !!! */ -} - -void sig_audio_decode( void ) -{ - MSG_T("sig_audio_decode\n"); - mp_msg_flush(); - - dec_ahead_can_adseek=1; - - UNLOCK_AUDIO_DECODE(); - - xmp_killall_threads(pthread_self()); - __exit_sighandler(); -} Deleted: mplayerxp/xmp_adecoder.h =================================================================== --- mplayerxp/xmp_adecoder.h 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/xmp_adecoder.h 2012-11-02 17:31:28 UTC (rev 286) @@ -1,14 +0,0 @@ -#ifndef XMP_ADECODER_H_INCLUDED -#define XMP_ADECODER_H_INCLUDED 1 - -extern int get_len_audio_buffer(void); -extern float get_delay_audio_buffer(void); -extern int init_audio_buffer(int size, int min_reserv, int indices, sh_audio_t *sh_audio); -extern void uninit_audio_buffer(void); -extern void reset_audio_buffer(void); -extern int read_audio_buffer(sh_audio_t *audio, unsigned char *buffer, unsigned minlen, unsigned maxlen, float *pts ); - -extern any_t* a_dec_ahead_routine( any_t* arg ); -extern void sig_audio_decode( void ); -extern int xp_thread_decode_audio(demux_stream_t *d_audio); -#endif Deleted: mplayerxp/xmp_aplayer.c =================================================================== --- mplayerxp/xmp_aplayer.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/xmp_aplayer.c 2012-11-02 17:31:28 UTC (rev 286) @@ -1,297 +0,0 @@ -#include "mplayer.h" -#include "mp_msg.h" -#include "sig_hand.h" -#include "xmp_core.h" -#include "xmp_aplayer.h" -#include "xmp_adecoder.h" -#include "osdep/timer.h" -#include "libmpcodecs/dec_audio.h" - -#include "libao2/audio_out.h" - -#include <stdio.h> -#include <unistd.h> // for usleep() -#include <pthread.h> -#include <math.h> - -#ifdef ENABLE_DEC_AHEAD_DEBUG -#define MSG_T(args...) mp_msg(MSGT_GLOBAL, MSGL_DBG2,__FILE__,__LINE__, ## args ) -#else -#define MSG_T(args...) -#endif - -#define MIN_AUDIO_TIME 0.05 -#define NOTHING_PLAYED (-1.0) -#define XP_MIN_TIMESLICE 0.010 /* under Linux on x86 min time_slice = 10 ms */ - -extern ao_data_t*ao_data; - -static int decore_audio(demux_stream_t *d_audio,sh_audio_t* sh_audio,sh_video_t*sh_video,unsigned _xp_id ) -{ - int eof = 0; -/*========================== PLAY AUDIO ============================*/ -while(sh_audio){ - unsigned int t; - double tt; - int playsize; - float pts=HUGE; - int ret=0; - - ao_data->pts=sh_audio->timer*90000.0; - playsize=ao_get_space(ao_data); - - if(!playsize) { - if(sh_video) - break; // buffer is full, do not block here!!! - usec_sleep(10000); // Wait a tick before retry - continue; - } - - if(playsize>MAX_OUTBURST) playsize=MAX_OUTBURST; // we shouldn't exceed it! - //if(playsize>outburst) playsize=outburst; - - // Update buffer if needed - MP_UNIT("mpca_decode"); // Enter AUDIO decoder module - t=GetTimer(); - while(sh_audio->a_buffer_len<playsize && !xp_core->audio->eof){ - if(mp_conf.xp>=XP_VideoAudio) { - ret=read_audio_buffer(sh_audio,&sh_audio->a_buffer[sh_audio->a_buffer_len], - playsize-sh_audio->a_buffer_len,sh_audio->a_buffer_size-sh_audio->a_buffer_len,&pts); - } else - { - ret=mpca_decode(sh_audio,&sh_audio->a_buffer[sh_audio->a_buffer_len], - playsize-sh_audio->a_buffer_len,sh_audio->a_buffer_size-sh_audio->a_buffer_len,sh_audio->a_buffer_size-sh_audio->a_buffer_len,&pts); - } - if(ret>0) sh_audio->a_buffer_len+=ret; - else { - if(!d_audio->eof) break; - xp_core->audio->eof=1; - break; - } - } - MP_UNIT("play_audio"); // Leave AUDIO decoder module - t=GetTimer()-t; - tt = t*0.000001f; - mp_data->bench->audio+=tt; - if(mp_conf.benchmark) - { - if(tt > mp_data->bench->max_audio) mp_data->bench->max_audio = tt; - if(tt < mp_data->bench->min_audio) mp_data->bench->min_audio = tt; - mp_data->bench->cur_audio=tt; - } - if(playsize>sh_audio->a_buffer_len) playsize=sh_audio->a_buffer_len; - - if(mp_conf.xp>=XP_VAPlay) dec_ahead_audio_delay=ao_get_delay(ao_data); - - playsize=ao_play(ao_data,sh_audio->a_buffer,playsize,0); - - if(playsize>0){ - sh_audio->a_buffer_len-=playsize; - memcpy(sh_audio->a_buffer,&sh_audio->a_buffer[playsize],sh_audio->a_buffer_len); - if(!mp_conf.av_sync_pts && mp_conf.xp>=XP_VAPlay) - pthread_mutex_lock(&audio_timer_mutex); - if(mp_data->use_pts_fix2) { - if(sh_audio->a_pts != HUGE) { - sh_audio->a_pts_pos-=playsize; - if(sh_audio->a_pts_pos > -ao_get_delay(ao_data)*sh_audio->af_bps) { - sh_audio->timer+=playsize/(float)(sh_audio->af_bps); - } else { - sh_audio->timer=sh_audio->a_pts-(float)sh_audio->a_pts_pos/(float)sh_audio->af_bps; - MSG_V("Audio chapter change detected\n"); - sh_audio->chapter_change=1; - sh_audio->a_pts = HUGE; - } - } else if(pts != HUGE) { - if(pts < 1.0 && sh_audio->timer > 2.0) { - sh_audio->timer+=playsize/(float)(sh_audio->af_bps); - sh_audio->a_pts=pts; - sh_audio->a_pts_pos=sh_audio->a_buffer_len-ret; - } else { - sh_audio->timer=pts+(ret-sh_audio->a_buffer_len)/(float)(sh_audio->af_bps); - sh_audio->a_pts=HUGE; - } - } else - sh_audio->timer+=playsize/(float)(sh_audio->af_bps); - } else if(mp_conf.av_sync_pts && pts!=HUGE) - sh_audio->timer=pts+(ret-sh_audio->a_buffer_len)/(float)(sh_audio->af_bps); - else - sh_audio->timer+=playsize/(float)(sh_audio->af_bps); - if(!mp_conf.av_sync_pts && mp_conf.xp>=XP_VAPlay) - pthread_mutex_unlock(&audio_timer_mutex); - } - - break; - } // if(sh_audio) - return eof; -} - - -extern ao_data_t* ao_data; -any_t* audio_play_routine( any_t* arg ) -{ - mpxp_thread_t* priv=arg; - sh_audio_t* sh_audio=priv->dae->sh; - demux_stream_t *d_audio=sh_audio->ds; - demuxer_t *demuxer=d_audio->demuxer; - sh_video_t* sh_video=demuxer->video->sh; - - int eof = 0; - struct timeval now; - struct timespec timeout; - float d; - int retval; - const float MAX_AUDIO_TIME = (float)ao_get_space(ao_data) / sh_audio->af_bps + ao_get_delay(ao_data); - float min_audio_time = MAX_AUDIO_TIME; - float min_audio, max_audio; - int samples, collect_samples; - float audio_buff_max, audio_buff_norm, audio_buff_min, audio_buff_alert; - - audio_buff_alert = max(XP_MIN_TIMESLICE, min(MIN_AUDIO_TIME,MAX_AUDIO_TIME/4)); - audio_buff_max = max(audio_buff_alert, min(MAX_AUDIO_TIME-XP_MIN_TIMESLICE, audio_buff_alert*4)); - audio_buff_min = min(audio_buff_max, audio_buff_alert*2); - audio_buff_norm = (audio_buff_max + audio_buff_min) / 2; - - MSG_DBG2("alert %f, min %f, norm %f, max %f \n", audio_buff_alert, audio_buff_min, audio_buff_norm, audio_buff_max ); - - samples = 5; - collect_samples = 1; - min_audio = MAX_AUDIO_TIME; - max_audio = 0; - - priv->pid = getpid(); - __MP_UNIT(priv->p_idx,"audio_play_routine"); - priv->state=Pth_Run; - dec_ahead_can_aseek=0; - - while(priv->state!=Pth_Canceling) { - if(priv->state==Pth_Sleep) { - priv->state=Pth_ASleep; - while(priv->state==Pth_ASleep) usleep(0); - continue; - } - __MP_UNIT(priv->p_idx,"audio decore_audio"); - dec_ahead_audio_delay = NOTHING_PLAYED; - eof = decore_audio(d_audio,sh_audio,sh_video,priv->p_idx); - - if(priv->state==Pth_Canceling) break; - - __MP_UNIT(priv->p_idx,"audio sleep"); - - dec_ahead_can_aseek = 1; /* Safe for other threads to seek */ - - if( dec_ahead_audio_delay == NOTHING_PLAYED ) { /* To fast, we can sleep longer */ - if( min_audio_time > audio_buff_alert ) { - min_audio_time *= 0.75; - MSG_DBG2("To fast, set min_audio_time %.5f (delay %5f) \n", min_audio_time, dec_ahead_audio_delay ); - } - collect_samples = 1; - samples = 5; - min_audio = MAX_AUDIO_TIME; - max_audio = 0; - } else if( dec_ahead_audio_delay <= audio_buff_alert ) { /* To slow, sleep shorter */ - if ( min_audio_time < MAX_AUDIO_TIME ) { - min_audio_time *= 2.0; - MSG_DBG2("To slow, set min_audio_time %.5f (delay %5f) \n", min_audio_time, dec_ahead_audio_delay ); - } - collect_samples = 1; - samples = 10; - min_audio = MAX_AUDIO_TIME; - max_audio = 0; - } else if( !xp_core->audio->eof && collect_samples) { - if( dec_ahead_audio_delay < min_audio ) - min_audio = dec_ahead_audio_delay; - if( dec_ahead_audio_delay > max_audio ) - max_audio = dec_ahead_audio_delay; - samples--; - - if( samples <= 0 ) { - if( min_audio > audio_buff_max ) { - min_audio_time -= min_audio-audio_buff_norm; - collect_samples = 1; - MSG_DBG2("Decrease min_audio_time %.5f (min %.5f max %.5f) \n", min_audio_time, min_audio, max_audio ); - } else if( max_audio < audio_buff_min ) { - min_audio_time *= 1.25; - collect_samples = 1; - MSG_DBG2("Increase min_audio_time %.5f (min %.5f max %.5f) \n", min_audio_time, min_audio, max_audio ); - } else { - collect_samples = 0; /* No change, stop */ - MSG_DBG2("Stop collecting samples time %.5f (min %.5f max %.5f) \n", min_audio_time, min_audio, max_audio ); - } - if(collect_samples) { - samples = 5; - min_audio = MAX_AUDIO_TIME; - max_audio = 0; - } - } - } - - LOCK_AUDIO_PLAY(); - d = ao_get_delay(ao_data) - min_audio_time; - if( d > 0 ) { - gettimeofday(&now,NULL); - audio_play_timeout.tv_nsec = now.tv_usec * 1000 + d*1000000000l; - if( audio_play_timeout.tv_nsec > 1000000000l ) { - audio_play_timeout.tv_nsec-=1000000000l; - audio_play_timeout.tv_sec = now.tv_sec + 1; - } else - audio_play_timeout.tv_sec = now.tv_sec; - audio_play_in_sleep=1; - pthread_cond_timedwait( &audio_play_cond, &audio_play_mutex, &audio_play_timeout ); - audio_play_in_sleep=0; - } - UNLOCK_AUDIO_PLAY(); - - if(priv->state==Pth_Canceling) break; - - LOCK_AUDIO_PLAY(); - if(eof && priv->state!=Pth_Canceling) { - __MP_UNIT(priv->p_idx,"wait end of work"); - pthread_cond_wait( &audio_play_cond, &audio_play_mutex ); - } - UNLOCK_AUDIO_PLAY(); - - if(priv->state==Pth_Canceling) break; - - __MP_UNIT(priv->p_idx,"audio pause"); - LOCK_AUDIO_PLAY(); - while( xp_core->in_pause && priv->state!=Pth_Canceling) { - pthread_cond_wait( &audio_play_cond, &audio_play_mutex ); - } - UNLOCK_AUDIO_PLAY(); - - if(priv->state==Pth_Canceling) break; - - __MP_UNIT(priv->p_idx,"audio seek"); - LOCK_AUDIO_PLAY(); -#if 0 - while( priv->state==Pth_Sleep && priv->state!=Pth_Canceling) { - gettimeofday(&now,NULL); - timeout.tv_nsec = now.tv_usec * 1000; - timeout.tv_sec = now.tv_sec + 1; - retval = pthread_cond_timedwait( &audio_play_cond, &audio_play_mutex, &timeout ); - if( retval == ETIMEDOUT ) - MSG_V("Audio seek timeout\n"); - } -#endif - dec_ahead_can_aseek = 0; /* Not safe to seek */ - UNLOCK_AUDIO_PLAY(); - } - fflush(stdout); - __MP_UNIT(priv->p_idx,"audio exit"); - dec_ahead_can_aseek=1; - priv->state=Pth_Stand; - return arg; -} - -void sig_audio_play( void ) -{ - MSG_T("sig_audio_play\n"); - mp_msg_flush(); - - dec_ahead_can_aseek=1; - - UNLOCK_AUDIO_PLAY(); - - xmp_killall_threads(pthread_self()); - __exit_sighandler(); -} Deleted: mplayerxp/xmp_aplayer.h =================================================================== --- mplayerxp/xmp_aplayer.h 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/xmp_aplayer.h 2012-11-02 17:31:28 UTC (rev 286) @@ -1,6 +0,0 @@ -#ifndef XMP_APLAYER_H_INCLUDED -#define XMP_APLAYER_H_INCLUDED 1 - -extern any_t* audio_play_routine( any_t* arg ); -extern void sig_audio_play( void ); -#endif Deleted: mplayerxp/xmp_core.c =================================================================== --- mplayerxp/xmp_core.c 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/xmp_core.c 2012-11-02 17:31:28 UTC (rev 286) @@ -1,354 +0,0 @@ -/* - Decoding ahead - Licence: GPL v2 - Author: Nickols_K - Note: Threaded engine to decode frames ahead -*/ - -#include "mp_config.h" -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <errno.h> -#include <signal.h> -#define __USE_ISOC99 1 /* for lrint */ -#include <math.h> -#include <sys/time.h> -#include "osdep/mplib.h" -#define DA_PREFIX "DEC_AHEAD:" -#define MSGT_CLASS MSGT_CPLAYER -#include "mp_msg.h" - -#include "xmp_core.h" -#include "xmp_aplayer.h" -#include "xmp_vplayer.h" -#include "xmp_adecoder.h" -#include "xmp_vdecoder.h" - -#include "mplayer.h" -#include "libao2/audio_out.h" -#include "libvo/video_out.h" - -#include "libmpcodecs/dec_video.h" -#include "libmpcodecs/dec_audio.h" -#include "sig_hand.h" -#include "osdep/timer.h" - -#ifdef ENABLE_DEC_AHEAD_DEBUG -#define MSG_T(args...) mp_msg(MSGT_GLOBAL, MSGL_DBG2,__FILE__,__LINE__, ## args ) -#else -#define MSG_T(args...) -#endif - -void xmp_init(void) { - xp_core=mp_mallocz(sizeof(xp_core_t)); - xp_core->initial_apts=HUGE; -} - -void xmp_uninit(void) { - mp_free(xp_core->mpxp_threads[0]); - mp_free(xp_core); - xp_core=NULL; -} - -unsigned xmp_register_main(sig_handler_t sigfunc) { - unsigned idx=0; - xp_core->mpxp_threads[idx]=mp_mallocz(sizeof(mpxp_thread_t)); - xp_core->mpxp_threads[idx]->p_idx=idx; - xp_core->mpxp_threads[idx]->pid=getpid(); - xp_core->main_pth_id=xp_core->mpxp_threads[idx]->pth_id=pthread_self(); - xp_core->mpxp_threads[idx]->name = "main"; - xp_core->mpxp_threads[idx]->sigfunc = sigfunc; - xp_core->mpxp_threads[idx]->dae = NULL; - xp_core->num_threads++; - - return idx; -} - -static void print_stopped_thread(unsigned idx) { - MSG_OK("*** stop thread: [%i] %s\n",idx,xp_core->mpxp_threads[idx]->name); -} - -void xmp_killall_threads(pthread_t _self) -{ - unsigned i; - for(i=0;i < MAX_MPXP_THREADS;i++) { - if( _self && - xp_core->mpxp_threads[i]->pth_id && - xp_core->mpxp_threads[i]->pth_id != xp_core->main_pth_id) { - pthread_kill(xp_core->mpxp_threads[i]->pth_id,SIGKILL); - print_stopped_thread(i); - mp_free(xp_core->mpxp_threads[i]); - xp_core->mpxp_threads[i]=NULL; - } - } -} - -void dae_reset(dec_ahead_engine_t* it) { - it->player_idx=0; - it->decoder_idx=0; - it->num_slow_frames=0; - it->num_played_frames=0; - it->num_decoded_frames=0; -} - -void dae_init(dec_ahead_engine_t* it,unsigned nframes,any_t* sh) -{ - it->nframes=nframes; - it->frame = mp_malloc(sizeof(xmp_frame_t)*nframes); - it->sh=sh; - dae_reset(it); -} - -void dae_uninit(dec_ahead_engine_t* it) { mp_free(it->frame); it->frame=NULL; } - -/* returns 1 - on success 0 - if busy */ -int dae_try_inc_played(dec_ahead_engine_t* it) { - unsigned new_idx; - new_idx=(it->player_idx+1)%it->nframes; - if(new_idx==it->decoder_idx) { - it->num_slow_frames++; - return 0; - } - it->num_slow_frames=0; - it->num_played_frames++; - return 1; -} - -int dae_inc_played(dec_ahead_engine_t* it) { - unsigned new_idx; - new_idx=(it->player_idx+1)%it->nframes; - if(new_idx==it->decoder_idx) return 0; - if(it->free_priv) (*it->free_priv)(it,it->frame[it->player_idx].priv); - it->player_idx=new_idx; - return 1; -} - -/* returns 1 - on success 0 - if busy */ -int dae_inc_decoded(dec_ahead_engine_t* it) { - unsigned new_idx; - new_idx=(it->decoder_idx+1)%it->nframes; - if(new_idx==it->player_idx) return 0; - it->decoder_idx=new_idx; - if(it->new_priv) it->frame[it->player_idx].priv=(*it->new_priv)(it); - it->num_decoded_frames++; - return 1; -} - -unsigned dae_prev_played(const dec_ahead_engine_t* it) { return (it->player_idx-1)%it->nframes; } -unsigned dae_prev_decoded(const dec_ahead_engine_t* it) { return (it->decoder_idx-1)%it->nframes; } -unsigned dae_next_played(const dec_ahead_engine_t* it) { return (it->player_idx+1)%it->nframes; } -unsigned dae_next_decoded(const dec_ahead_engine_t* it) { return (it->decoder_idx+1)%it->nframes; } - -unsigned dae_get_decoder_outrun(const dec_ahead_engine_t* it) { - unsigned decoder_idx=it->decoder_idx; - if(decoder_idx<it->player_idx) decoder_idx+=it->nframes; - return decoder_idx-it->player_idx; -} - -void dae_wait_decoder_outrun(const dec_ahead_engine_t* it) { - if(it) { - do { - usleep(0); - }while(dae_get_decoder_outrun(it) < xp_core->num_v_buffs/2); - } -} - -xmp_frame_t dae_played_frame(const dec_ahead_engine_t* it) { - unsigned idx=it->player_idx; - return it->frame[idx]; -} -xmp_frame_t dae_decoded_frame(const dec_ahead_engine_t* it) { - unsigned idx=it->decoder_idx; - return it->frame[idx]; -} -xmp_frame_t dae_next_played_frame(const dec_ahead_engine_t* it) { - unsigned idx=dae_next_played(it); - return it->frame[idx]; -} -xmp_frame_t dae_next_decoded_frame(const dec_ahead_engine_t* it) { - unsigned idx=dae_next_decoded(it); - return it->frame[idx]; -} -xmp_frame_t dae_prev_played_frame(const dec_ahead_engine_t* it) { - unsigned idx=dae_prev_played(it); - return it->frame[idx]; -} -xmp_frame_t dae_prev_decoded_frame(const dec_ahead_engine_t* it) { - unsigned idx=dae_prev_decoded(it); - return it->frame[idx]; -} - -int dae_played_eof(const dec_ahead_engine_t* it) { - unsigned idx=it->player_idx; - return (it->frame[idx].v_pts==HUGE_VALF)?1:0; -} - -int dae_decoded_eof(const dec_ahead_engine_t* it) { - unsigned idx=it->decoder_idx; - return (it->frame[idx].v_pts==HUGE_VALF)?1:0; -} - -void dae_decoded_mark_eof(dec_ahead_engine_t* it) { - unsigned idx=it->decoder_idx; - it->frame[idx].v_pts=HUGE_VALF; -} - -pthread_mutex_t audio_play_mutex=PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t audio_play_cond=PTHREAD_COND_INITIALIZER; - -pthread_mutex_t audio_decode_mutex=PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t audio_decode_cond=PTHREAD_COND_INITIALIZER; - -volatile int dec_ahead_can_aseek=0; /* It is safe to seek audio */ - -/* To let audio decoder thread sleep as long as player */ -struct timespec audio_play_timeout; -int audio_play_in_sleep=0; - -/* Min audio buffer to keep mp_free, used to tell differ between full and empty buffer */ -#define MIN_BUFFER_RESERV 8 - -int xmp_init_engine(sh_video_t *shv, sh_audio_t *sha) -{ - if(shv) { - xp_core->video=mp_mallocz(sizeof(dec_ahead_engine_t)); - dae_init(xp_core->video,xp_core->num_v_buffs,shv); - } - if(mp_conf.xp>=XP_VideoAudio && sha) { - int asize; - unsigned o_bps; - unsigned min_reserv; - o_bps=sha->afilter_inited?sha->af_bps:sha->o_bps; - if(xp_core->video) asize = max(3*sha->audio_out_minsize,max(3*MAX_OUTBURST,o_bps*xp_core->num_v_buffs/shv->fps))+MIN_BUFFER_RESERV; - else asize = o_bps*xp_core->num_a_buffs; - /* FIXME: get better indices from asize/real_audio_packet_size */ - min_reserv = sha->audio_out_minsize; - if (o_bps > sha->o_bps) - min_reserv = (float)min_reserv * (float)o_bps / (float)sha->o_bps; - init_audio_buffer(asize+min_reserv,min_reserv+MIN_BUFFER_RESERV,asize/(sha->audio_out_minsize<10000?sha->audio_out_minsize:4000)+100,sha); - xp_core->audio=mp_mallocz(sizeof(dec_ahead_engine_t)); - dae_init(xp_core->audio,xp_core->num_a_buffs,sha); - } - return 0; -} - -void xmp_uninit_engine( int force ) -{ - xmp_stop_threads(force); - - if(xp_core->video) { - dae_uninit(xp_core->video); - xp_core->video=NULL; - } - - if(xp_core->audio) { /* audio state doesn't matter on segfault :( */ - uninit_audio_buffer(); - xp_core->audio=NULL; - } -} - -unsigned xmp_register_thread(dec_ahead_engine_t* dae,sig_handler_t sigfunc,mpxp_routine_t routine,const char *name) { - unsigned idx=xp_core->num_threads; - int rc; - if(idx>=MAX_MPXP_THREADS) return UINT_MAX; - pthread_attr_t attr; - pthread_attr_init(&attr); - rc=pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED); - if(rc) { - MSG_ERR("running thread: attr_setdetachstate fault!!!\n"); - pthread_attr_destroy(&attr); - return rc; - } - pthread_attr_setscope(&attr,PTHREAD_SCOPE_SYSTEM); -#if 0 - /* requires root privelegies */ - pthread_attr_setschedpolicy(&attr,SCHED_FIFO); -#endif - xp_core->mpxp_threads[idx]=mp_mallocz(sizeof(mpxp_thread_t)); - - xp_core->mpxp_threads[idx]->p_idx=idx; - xp_core->mpxp_threads[idx]->name=name; - xp_core->mpxp_threads[idx]->routine=routine; - xp_core->mpxp_threads[idx]->sigfunc=sigfunc; - xp_core->mpxp_threads[idx]->state=Pth_Stand; - xp_core->mpxp_threads[idx]->dae=dae; - - rc=pthread_create(&xp_core->mpxp_threads[idx]->pth_id,&attr,routine,xp_core->mpxp_threads[idx]); - pthread_attr_destroy(&attr); - - xp_core->num_threads++; - return (rc?UINT_MAX:idx); -} - -int xmp_run_decoders( void ) -{ - unsigned rc; - if((xp_core->audio && mp_conf.xp >= XP_VAFull) || !xp_core->video) { - if((rc=xmp_register_thread(xp_core->audio,sig_audio_decode,a_dec_ahead_routine,"audio decoder+af"))==UINT_MAX) return rc; - while(xp_core->mpxp_threads[rc]->state!=Pth_Run) usleep(0); - } - if(xp_core->video) { - if((rc=xmp_register_thread(xp_core->video,sig_video_decode,xmp_video_decoder,"video+audio decoders+filters"))==UINT_MAX) return rc; - while(xp_core->mpxp_threads[rc]->state!=Pth_Run) usleep(0); - } - return 0; -} - -int xmp_run_players(void) -{ - unsigned rc; - if( xp_core->audio && mp_conf.xp >= XP_VAPlay ) { - if((rc=xmp_register_thread(xp_core->audio,sig_audio_play,audio_play_routine,"audio player"))==UINT_MAX) return rc; - while(xp_core->mpxp_threads[rc]->state!=Pth_Run) usleep(0); - } - if( xp_core->video ) { - if((rc=xmp_register_thread(xp_core->video,sig_video_play,xmp_video_player,"video player"))==UINT_MAX) return rc; - while(xp_core->mpxp_threads[rc]->state!=Pth_Run) usleep(0); - } - return 0; -} - -/* Stops threads before seek */ -void xmp_stop_threads(int force) -{ - unsigned i; - for(i=1;i<xp_core->num_threads;i++) { - if(force) pthread_kill(xp_core->mpxp_threads[i]->pth_id,SIGKILL); - else { - xp_core->mpxp_threads[i]->state=Pth_Canceling; - while(xp_core->mpxp_threads[i]->state==Pth_Canceling) usleep(0); - } - print_stopped_thread(i); - mp_free(xp_core->mpxp_threads[i]); - xp_core->mpxp_threads[i]=NULL; - } -} - -/* Halt threads before seek */ -void xmp_halt_threads(int is_reset_vcache) -{ - unsigned i; - for(i=1;i<xp_core->num_threads;i++) { - xp_core->mpxp_threads[i]->state=Pth_Sleep; - while(xp_core->mpxp_threads[i]->state==Pth_Sleep) usleep(0); - } -} - -/* Restart threads after seek */ -void xmp_restart_threads(int xp_id) -{ - /* reset counters */ - dae_reset(xp_core->video); - /* temporary solution */ - reset_audio_buffer(); - /* Ugly hack: but we should read audio packet before video after seeking. - Else we'll get picture destortion on the screen */ - xp_core->initial_apts=HUGE; - - unsigned i; - for(i=1;i<xp_core->num_threads;i++) { - xp_core->mpxp_threads[i]->state=Pth_Run; - while(xp_core->mpxp_threads[i]->state==Pth_ASleep) usleep(0); - } -} Deleted: mplayerxp/xmp_core.h =================================================================== --- mplayerxp/xmp_core.h 2012-11-02 17:03:04 UTC (rev 285) +++ mplayerxp/xmp_core.h 2012-11-02 17:31:28 UTC (rev 286) @@ -1,184 +0,0 @@ -/* - eXtra performance MPlayer's CORE - Licence: GPL v2 - Note: Threaded engine to decode frames ahead -*/ - -#ifndef __XMP_CORE_H -#define __XMP_CORE_H 1 - -#include <inttypes.h> -#include <pthread.h> -#include "libmpdemux/stream.h" -#include "libmpdemux/demuxer.h" -#include "libmpdemux/stheader.h" -#include "libmpdemux/demuxer_r.h" -#include "libvo/video_out.h" - -//#define ENABLE_DEC_AHEAD_DEBUG 1 - -enum xp_modes { XP_NA=0, XP_Video, XP_VideoAudio, XP_VAPlay, XP_VAFull }; - -typedef struct xmp_frame_s -{ - float v_pts; /* presentation time-stamp from input stream - __huge_valf indicates EOF */ - float duration; /* frame duration */ - any_t* priv; -}xmp_frame_t; - -struct dec_ahead_engine_s; - -typedef any_t* (*func_new_frame_priv_t)(struct dec_ahead_engine_s*); -typedef void (*func_free_frame_priv_t)(struct dec_ahead_engine_s*,any_t*); - -typedef struct dec_ahead_engine_s { - volatile unsigned player_idx; /* index of frame which is currently played */ - volatile unsigned decoder_idx; /* index of frame which is currently decoded */ - unsigned nframes; /* number of frames in buffer */ - xmp_frame_t* frame; /* frame related attributes */ - any_t* sh; /* corresponded sh_audio_t or sh_video_t */ - int eof; /* EOF for stream */ - /* methods */ - func_new_frame_priv_t new_priv; - func_free_frame_priv_t free_priv; - /* for statistics */ - unsigned num_slow_frames;/* number of frames which were delayed due slow computer */ - long long int num_played_frames; - long long int num_decoded_frames; /* for frame dropping */ - long long int num_dropped_frames; -}dec_ahead_engine_t; - -enum { main_id=0 }; -enum { MAX_MPXP_THREADS=16 }; -enum mpxp_thread_state { Pth_Stand=0, Pth_Canceling, Pth_Run, Pth_Sleep, Pth_ASleep }; - -typedef any_t*(*mpxp_routine_t)(any_t*); -typedef void (*sig_handler_t)(void); - -typedef struct mpxp_thread_s { - unsigned p_idx; - const char* name; - const char* unit; - pthread_t pth_id; - pid_t pid; - mpxp_routine_t routine; - sig_handler_t sigfunc; - dec_ahead_engine_t* dae; - volatile enum mpxp_thread_state state; -}mpxp_thread_t; - -typedef struct initial_audio_pts_correction_s -{ - int need_correction; - int pts_bytes; - int nbytes; -}initial_audio_pts_correction_t; - -typedef struct xp_core_s { - dec_ahead_engine_t* video; - dec_ahead_engine_t* audio; - volatile int in_pause; - volatile int in_resize; - /* XMP engine */ - mpxp_thread_t* mpxp_threads[MAX_MPXP_THREADS]; - unsigned num_threads; - pthread_t main_pth_id; - /* doubtful stuff */ - unsigned num_a_buffs; // number of audio buffers - unsigned num_v_buffs; // number of video buffers - int bad_pts; // for MPEGxx codecs - float initial_apts; - initial_audio_pts_correction_t initial_apts_corr; -}xp_core_t; -extern xp_core_t *xp_core; - -extern void xmp_init(void); -extern void xmp_uninit(void); - -/* returns idx of main thread */ -extern unsigned xmp_register_main(sig_handler_t sigfunc); -/* returns idx of the thread or UINT_MAX on fault */ -extern unsigned xmp_register_thread(dec_ahead_engine_t* dae,sig_handler_t sigfunc,mpxp_routine_t routine,const char *name); -extern void xmp_stop_threads(int force); - -extern void xmp_halt_threads(int is_reset_vcache); -extern void xmp_restart_threads(int xp_id); - -extern void xmp_killall_threads(pthread_t _self); - -extern int xmp_init_engine(sh_video_t*stream, sh_audio_t *astream); -extern void xmp_uninit_engine( int force ); -extern int xmp_run_decoders( void ); -extern int xmp_run_players( void ); -extern void xmp_reset_sh_video(sh_video_t* shv); - -extern void dae_init(dec_ahead_engine_t* it,unsigned nframes,any_t* sh); -extern void dae_uninit(dec_ahead_engine_t* it); -extern void dae_reset(dec_ahead_engine_t* it); /* after mpxp_seek */ - -/* returns 1 - on success 0 - if busy */ -extern int dae_try_inc_played(dec_ahead_engine_t* it); -extern int dae_inc_played(dec_ahead_engine_t* it); -extern int dae_inc_decoded(dec_ahead_engine_t* it); - -extern unsigned dae_prev_played(const dec_ahead_engine_t* it); -extern unsigned dae_prev_decoded(const dec_ahead_engine_t* it); -extern unsigned dae_next_played(const dec_ahead_engine_t* it); -extern unsigned dae_next_decoded(const dec_ahead_engine_t* it); -/* returns normalized decoder_idx-player_idx */ -extern unsigned dae_get_decoder_outrun(const dec_ahead_engine_t* it); -extern void dae_wait_decoder_outrun(const dec_ahead_engine_t* it); - -static inline unsigned dae_curr_vplayed(const xp_core_t* xpc) { return xpc->video->player_idx; } -static inline unsigned dae_curr_vdecoded(const xp_core_t* xpc) { return xpc->video->decoder_idx; } -static inline unsigned dae_prev_vplayed(const xp_core_t* xpc) { return dae_prev_played(xpc->video); } -static inline unsigned dae_prev_vdecoded(const xp_core_t* xpc) { return dae_prev_decoded(xpc->video); } -static inline unsigned dae_next_vplayed(const xp_core_t* xpc) { return dae_next_played(xpc->video); } -static inline unsigned dae_next_vdecoded(const xp_core_t* xpc) { return dae_next_decoded(xpc->video); } - -extern xmp_frame_t dae_played_frame(const dec_ahead_engine_t* it); -extern xmp_frame_t dae_decoded_frame(const dec_ahead_engine_t* it); -extern xmp_frame_t dae_next_played_frame(const dec_ahead_engine_t* it); -extern xmp_frame_t dae_next_decoded_frame(const dec_ahead_engine_t* it); -extern xmp_frame_t dae_prev_played_frame(const dec_ahead_engine_t* it); -extern xmp_frame_t dae_prev_decoded_frame(const dec_ahead_engine_t* it); - -extern int dae_played_eof(const dec_ahead_engine_t* it); -extern int dae_decoded_eof(const dec_ahead_engine_t* it); -extern void dae_decoded_mark_eof(dec_ahead_engine_t* it); -extern inline void dae_decoded_clear_eof(dec_ahead_engine_t* it) { UNUSED(it); } - -extern pthread_mutex_t audio_play_mutex; -extern pthread_cond_t audio_play_cond; - -extern pthread_mutex_t audio_decode_mutex; -extern pthread_cond_t audio_decode_cond; - -#ifdef ENABLE_DEC_AHEAD_DEBUG -#include "mp_msg.h" -#ifndef DA_PREFIX -#define DA_PREFIX "dec_ahead:" -#endif -#define MSG_D(args...) { mp_msg(MSGT_GLOBAL, MSGL_V, __FILE__, __LINE__, ## args ); mp_msg_flush(); } -#else -#define MSG_D(args...) -#endif - -#define LOCK_AUDIO_PLAY() { MSG_D(DA_PREFIX"LOCK_AUDIO_PLAY\n"); pthread_mutex_lock(&audio_play_mutex); } -#define ... [truncated message content] |