mirror of
https://github.com/mpv-player/mpv
synced 2025-01-22 07:33:14 +00:00
Split command/property handling from mplayer.c to a new file command.c.
Move some global and static variables under a struct that can be given as a parameter. Add a context argument to the property functions so that they do not have to depend on global/static variables. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@22298 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
e23b2395c0
commit
d5d4c6c7e2
1
Makefile
1
Makefile
@ -45,6 +45,7 @@ SRCS_MPLAYER = mplayer.c \
|
||||
mixer.c \
|
||||
parser-mpcmd.c \
|
||||
subopt-helper.c \
|
||||
command.c \
|
||||
|
||||
SRCS_MENCODER = mencoder.c \
|
||||
mp_msg-mencoder.c \
|
||||
|
3
command.h
Normal file
3
command.h
Normal file
@ -0,0 +1,3 @@
|
||||
int run_command(MPContext *mpctx, mp_cmd_t *cmd);
|
||||
char *property_expand_string(MPContext *mpctx, char *str);
|
||||
void property_print_help(void);
|
22
m_property.c
22
m_property.c
@ -17,13 +17,13 @@
|
||||
|
||||
#define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
|
||||
|
||||
int m_property_do(m_option_t* prop, int action, void* arg) {
|
||||
int m_property_do(m_option_t* prop, int action, void* arg, void *ctx) {
|
||||
if(!prop) return M_PROPERTY_UNKNOWN;
|
||||
return ((m_property_ctrl_f)prop->p)(prop,action,arg);
|
||||
return ((m_property_ctrl_f)prop->p)(prop,action,arg,ctx);
|
||||
}
|
||||
|
||||
|
||||
char* m_property_print(m_option_t* prop) {
|
||||
char* m_property_print(m_option_t* prop, void *ctx) {
|
||||
m_property_ctrl_f ctrl;
|
||||
void* val;
|
||||
char* ret;
|
||||
@ -32,11 +32,11 @@ char* m_property_print(m_option_t* prop) {
|
||||
|
||||
ctrl = prop->p;
|
||||
// look if the property have it's own print func
|
||||
if(ctrl(prop,M_PROPERTY_PRINT,&ret) >= 0)
|
||||
if(ctrl(prop,M_PROPERTY_PRINT,&ret, ctx) >= 0)
|
||||
return ret;
|
||||
// fallback on the default print for this type
|
||||
val = calloc(1,prop->type->size);
|
||||
if(ctrl(prop,M_PROPERTY_GET,val) <= 0) {
|
||||
if(ctrl(prop,M_PROPERTY_GET,val,ctx) <= 0) {
|
||||
free(val);
|
||||
return NULL;
|
||||
}
|
||||
@ -45,7 +45,7 @@ char* m_property_print(m_option_t* prop) {
|
||||
return ret == (char*)-1 ? NULL : ret;
|
||||
}
|
||||
|
||||
int m_property_parse(m_option_t* prop, char* txt) {
|
||||
int m_property_parse(m_option_t* prop, char* txt, void *ctx) {
|
||||
m_property_ctrl_f ctrl;
|
||||
void* val;
|
||||
int r;
|
||||
@ -54,7 +54,7 @@ int m_property_parse(m_option_t* prop, char* txt) {
|
||||
|
||||
ctrl = prop->p;
|
||||
// try the property own parsing func
|
||||
if((r = ctrl(prop,M_PROPERTY_PARSE,txt)) != M_PROPERTY_NOT_IMPLEMENTED)
|
||||
if((r = ctrl(prop,M_PROPERTY_PARSE,txt,ctx)) != M_PROPERTY_NOT_IMPLEMENTED)
|
||||
return r;
|
||||
// fallback on the default
|
||||
val = calloc(1,prop->type->size);
|
||||
@ -62,13 +62,13 @@ int m_property_parse(m_option_t* prop, char* txt) {
|
||||
free(val);
|
||||
return r;
|
||||
}
|
||||
r = ctrl(prop,M_PROPERTY_SET,val);
|
||||
r = ctrl(prop,M_PROPERTY_SET,val,ctx);
|
||||
m_option_free(prop,val);
|
||||
free(val);
|
||||
return r;
|
||||
}
|
||||
|
||||
char* m_properties_expand_string(m_option_t* prop_list,char* str) {
|
||||
char* m_properties_expand_string(m_option_t* prop_list,char* str, void *ctx) {
|
||||
int l,fr=0,pos=0,size=strlen(str)+512;
|
||||
char *p = NULL,*e,*ret = malloc(size), num_val;
|
||||
int skip = 0, lvl = 0, skip_lvl = 0;
|
||||
@ -110,7 +110,7 @@ char* m_properties_expand_string(m_option_t* prop_list,char* str) {
|
||||
memcpy(pname,str+2,pl);
|
||||
pname[pl] = 0;
|
||||
if((prop = m_option_list_find(prop_list,pname)) &&
|
||||
(p = m_property_print(prop)))
|
||||
(p = m_property_print(prop, ctx)))
|
||||
l = strlen(p), fr = 1;
|
||||
else
|
||||
l = 0;
|
||||
@ -124,7 +124,7 @@ char* m_properties_expand_string(m_option_t* prop_list,char* str) {
|
||||
memcpy(pname,str+2,pl);
|
||||
pname[pl] = 0;
|
||||
if(!(prop = m_option_list_find(prop_list,pname)) ||
|
||||
m_property_do(prop,M_PROPERTY_GET,NULL) < 0)
|
||||
m_property_do(prop,M_PROPERTY_GET,NULL, ctx) < 0)
|
||||
skip = 1, skip_lvl = lvl;
|
||||
}
|
||||
str = e+1, l = 0;
|
||||
|
12
m_property.h
12
m_property.h
@ -78,7 +78,7 @@
|
||||
|
||||
/// \ingroup Properties
|
||||
/// \brief Property action callback.
|
||||
typedef int(*m_property_ctrl_f)(m_option_t* prop,int action,void* arg);
|
||||
typedef int(*m_property_ctrl_f)(m_option_t* prop,int action,void* arg,void *ctx);
|
||||
|
||||
/// Do an action on a property.
|
||||
/** \param prop The property.
|
||||
@ -86,20 +86,20 @@ typedef int(*m_property_ctrl_f)(m_option_t* prop,int action,void* arg);
|
||||
* \param arg Argument, usually a pointer to the data type used by the property.
|
||||
* \return See \ref PropertyActionsReturn.
|
||||
*/
|
||||
int m_property_do(m_option_t* prop, int action, void* arg);
|
||||
int m_property_do(m_option_t* prop, int action, void* arg, void *ctx);
|
||||
|
||||
/// Print the current value of a property.
|
||||
/** \param prop The property.
|
||||
* \return A newly allocated string with the current value or NULL on error.
|
||||
*/
|
||||
char* m_property_print(m_option_t* prop);
|
||||
char* m_property_print(m_option_t* prop, void *ctx);
|
||||
|
||||
/// Set a property.
|
||||
/** \param prop The property.
|
||||
* \param txt The value to set.
|
||||
* \return 1 on success, 0 on error.
|
||||
*/
|
||||
int m_property_parse(m_option_t* prop, char* txt);
|
||||
int m_property_parse(m_option_t* prop, char* txt, void *ctx);
|
||||
|
||||
/// Print a list of properties.
|
||||
void m_properties_print_help_list(m_option_t* list);
|
||||
@ -115,7 +115,7 @@ void m_properties_print_help_list(m_option_t* list);
|
||||
* \param str The string to expand.
|
||||
* \return The newly allocated expanded string.
|
||||
*/
|
||||
char* m_properties_expand_string(m_option_t* prop_list,char* str);
|
||||
char* m_properties_expand_string(m_option_t* prop_list,char* str, void *ctx);
|
||||
|
||||
// Helpers to use MPlayer's properties
|
||||
|
||||
@ -123,7 +123,7 @@ char* m_properties_expand_string(m_option_t* prop_list,char* str);
|
||||
m_option_t* mp_property_find(const char* name);
|
||||
|
||||
/// Do an action with an MPlayer property.
|
||||
int mp_property_do(const char* name,int action, void* val);
|
||||
int mp_property_do(const char* name,int action, void* val, void *ctx);
|
||||
|
||||
/// \defgroup PropertyImplHelper Property implementation helpers
|
||||
/// \ingroup Properties
|
||||
|
128
mp_core.h
Normal file
128
mp_core.h
Normal file
@ -0,0 +1,128 @@
|
||||
// definitions used internally by the core player code
|
||||
|
||||
#define INITED_VO 1
|
||||
#define INITED_AO 2
|
||||
#define INITED_GUI 4
|
||||
#define INITED_GETCH2 8
|
||||
#define INITED_SPUDEC 32
|
||||
#define INITED_STREAM 64
|
||||
#define INITED_INPUT 128
|
||||
#define INITED_VOBSUB 256
|
||||
#define INITED_DEMUXER 512
|
||||
#define INITED_ACODEC 1024
|
||||
#define INITED_VCODEC 2048
|
||||
#define INITED_ALL 0xFFFF
|
||||
|
||||
|
||||
#define SUB_SOURCE_SUBS 0
|
||||
#define SUB_SOURCE_VOBSUB 1
|
||||
#define SUB_SOURCE_DEMUX 2
|
||||
#define SUB_SOURCES 3
|
||||
|
||||
|
||||
#define PT_NEXT_ENTRY 1
|
||||
#define PT_PREV_ENTRY -1
|
||||
#define PT_NEXT_SRC 2
|
||||
#define PT_PREV_SRC -2
|
||||
#define PT_UP_NEXT 3
|
||||
#define PT_UP_PREV -3
|
||||
|
||||
|
||||
#define OSD_MSG_TV_CHANNEL 0
|
||||
#define OSD_MSG_TEXT 1
|
||||
#define OSD_MSG_SUB_DELAY 2
|
||||
#define OSD_MSG_SPEED 3
|
||||
#define OSD_MSG_OSD_STATUS 4
|
||||
#define OSD_MSG_BAR 5
|
||||
#define OSD_MSG_PAUSE 6
|
||||
#define OSD_MSG_RADIO_CHANNEL 7
|
||||
/// Base id for messages generated from the commmand to property bridge.
|
||||
#define OSD_MSG_PROPERTY 0x100
|
||||
|
||||
#define MAX_OSD_LEVEL 3
|
||||
#define MAX_TERM_OSD_LEVEL 1
|
||||
|
||||
|
||||
typedef struct MPContext {
|
||||
int osd_show_percentage;
|
||||
int osd_function;
|
||||
demux_stream_t *d_audio;
|
||||
ao_functions_t *audio_out;
|
||||
float begin_skip; ///< start time of the current skip while on edlout mode
|
||||
play_tree_t *playtree;
|
||||
play_tree_iter_t *playtree_iter;
|
||||
int eof;
|
||||
int play_tree_step;
|
||||
|
||||
stream_t *stream;
|
||||
demuxer_t *demuxer;
|
||||
sh_audio_t *sh_audio;
|
||||
sh_video_t *sh_video;
|
||||
demux_stream_t *d_video;
|
||||
demux_stream_t *d_sub;
|
||||
mixer_t mixer;
|
||||
vo_functions_t *video_out;
|
||||
|
||||
short edl_muted; ///< Stores whether EDL is currently in muted mode.
|
||||
short user_muted; ///< Stores whether user wanted muted mode.
|
||||
|
||||
int global_sub_size; // this encompasses all subtitle sources
|
||||
int global_sub_pos; // this encompasses all subtitle sources
|
||||
int set_of_sub_pos;
|
||||
int set_of_sub_size;
|
||||
int global_sub_indices[SUB_SOURCES];
|
||||
#ifdef USE_ASS
|
||||
// set_of_ass_tracks[i] contains subtitles from set_of_subtitles[i]
|
||||
// parsed by libass or NULL if format unsupported
|
||||
ass_track_t* set_of_ass_tracks[MAX_SUBTITLE_FILES];
|
||||
#endif
|
||||
sub_data* set_of_subtitles[MAX_SUBTITLE_FILES];
|
||||
|
||||
int file_format;
|
||||
|
||||
#ifdef HAS_DVBIN_SUPPORT
|
||||
int last_dvb_step;
|
||||
int dvbin_reopen;
|
||||
#endif
|
||||
|
||||
int was_paused;
|
||||
} MPContext;
|
||||
|
||||
|
||||
// Most of these should not be globals
|
||||
extern int abs_seek_pos;
|
||||
extern float rel_seek_secs;
|
||||
extern FILE *edl_fd;
|
||||
extern int file_filter;
|
||||
// These appear in options list
|
||||
extern float playback_speed;
|
||||
extern int osd_duration;
|
||||
extern int term_osd;
|
||||
extern int fixed_vo;
|
||||
extern int ass_enabled;
|
||||
extern int fixed_vo;
|
||||
extern int forced_subs_only;
|
||||
|
||||
// These were listed as externs in mplayer.c, should be in some other header
|
||||
extern int vo_gamma_gamma;
|
||||
extern int vo_gamma_brightness;
|
||||
extern int vo_gamma_contrast;
|
||||
extern int vo_gamma_saturation;
|
||||
extern int vo_gamma_hue;
|
||||
|
||||
|
||||
|
||||
int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data);
|
||||
void uninit_player(unsigned int mask);
|
||||
void reinit_audio_chain(void);
|
||||
void init_vo_spudec(void);
|
||||
void set_osd_bar(int type,const char* name,double min,double max,double val);
|
||||
void set_osd_msg(int id, int level, int time, const char* fmt, ...);
|
||||
double playing_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio,
|
||||
ao_functions_t *audio_out);
|
||||
void exit_player_with_rc(const char* how, int rc);
|
||||
char *get_path(const char *filename);
|
||||
void rm_osd_msg(int id);
|
||||
void add_subtitles(char *filename, float fps, int silent);
|
||||
void mplayer_put_key(int code);
|
||||
int reinit_video_chain(void);
|
Loading…
Reference in New Issue
Block a user