comparison mplayer.c @ 17935:d72e7330c548

Subtitles properties: move sub_select, sub_pos, sub_visibilty, sub_alignment and sub_forced_only to properties.
author albeu
date Fri, 24 Mar 2006 19:32:23 +0000
parents 3fe3b2b3a6ce
children 810b407ba6c4
comparison
equal deleted inserted replaced
17934:a666367d5f44 17935:d72e7330c548
353 353
354 static stream_t* stream=NULL; 354 static stream_t* stream=NULL;
355 static demuxer_t *demuxer=NULL; 355 static demuxer_t *demuxer=NULL;
356 static sh_audio_t *sh_audio=NULL; 356 static sh_audio_t *sh_audio=NULL;
357 static sh_video_t *sh_video=NULL; 357 static sh_video_t *sh_video=NULL;
358 static demux_stream_t *d_audio=NULL;
359 static demux_stream_t *d_video=NULL;
360 static demux_stream_t *d_dvdsub=NULL;
358 361
359 char* current_module=NULL; // for debugging 362 char* current_module=NULL; // for debugging
360 363
361 extern int vo_gamma_gamma; 364 extern int vo_gamma_gamma;
362 extern int vo_gamma_brightness; 365 extern int vo_gamma_brightness;
1061 #define OSD_MSG_BAR 5 1064 #define OSD_MSG_BAR 5
1062 #define OSD_MSG_PAUSE 6 1065 #define OSD_MSG_PAUSE 6
1063 // Base id for the messages generated from the commmand to property bridge 1066 // Base id for the messages generated from the commmand to property bridge
1064 #define OSD_MSG_PROPERTY 0x100 1067 #define OSD_MSG_PROPERTY 0x100
1065 1068
1066
1067 // These will later be implemented via properties and removed
1068 #define OSD_MSG_SUB_POS 105
1069 #define OSD_MSG_SUB_ALIGN 106
1070 #define OSD_MSG_SUB_VISIBLE 107
1071 #define OSD_MSG_SUB_CHANGED 108
1072 1069
1073 typedef struct mp_osd_msg mp_osd_msg_t; 1070 typedef struct mp_osd_msg mp_osd_msg_t;
1074 struct mp_osd_msg { 1071 struct mp_osd_msg {
1075 mp_osd_msg_t* prev; 1072 mp_osd_msg_t* prev;
1076 char msg[64]; 1073 char msg[64];
1673 static int mp_property_aspect(m_option_t* prop,int action,void* arg) { 1670 static int mp_property_aspect(m_option_t* prop,int action,void* arg) {
1674 if(!sh_video) return M_PROPERTY_UNAVAILABLE; 1671 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
1675 return m_property_float_ro(prop,action,arg,sh_video->aspect); 1672 return m_property_float_ro(prop,action,arg,sh_video->aspect);
1676 } 1673 }
1677 1674
1675 // Subtitles properties
1676
1677 static int mp_property_sub_pos(m_option_t* prop,int action,void* arg) {
1678 #ifdef USE_SUB
1679 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
1680
1681 switch(action) {
1682 case M_PROPERTY_SET:
1683 if(!arg) return 0;
1684 case M_PROPERTY_STEP_UP:
1685 case M_PROPERTY_STEP_DOWN:
1686 vo_osd_changed(OSDTYPE_SUBTITLE);
1687 default:
1688 return m_property_int_range(prop,action,arg,&sub_pos);
1689 }
1690 #else
1691 return M_PROPERTY_UNAVAILABLE;
1692 #endif
1693 }
1694
1695 static int mp_property_sub(m_option_t* prop,int action,void* arg) {
1696 int source = -1, reset_spu = 0;
1697
1698 if(global_sub_size <= 0) return M_PROPERTY_UNAVAILABLE;
1699
1700 switch(action) {
1701 case M_PROPERTY_GET:
1702 if(!arg) return 0;
1703 *(int*)arg = global_sub_pos;
1704 return 1;
1705 case M_PROPERTY_PRINT:
1706 if(!arg) return 0;
1707 *(char**)arg = malloc(64);
1708 (*(char**)arg)[63] = 0;
1709 #ifdef USE_SUB
1710 if(subdata) {
1711 char *tmp,*tmp2;
1712 tmp = subdata->filename;
1713 if ((tmp2 = strrchr(tmp, '/')))
1714 tmp = tmp2+1;
1715
1716 snprintf(*(char**)arg, 63, "(%d) %s%s",
1717 set_of_sub_pos + 1,
1718 strlen(tmp) < 20 ? "" : "...",
1719 strlen(tmp) < 20 ? tmp : tmp+strlen(tmp)-19);
1720 return 1;
1721 }
1722 #endif
1723 #ifdef HAVE_MATROSKA
1724 if (demuxer->type == DEMUXER_TYPE_MATROSKA && dvdsub_id >= 0) {
1725 char lang[40] = MSGTR_Unknown;
1726 demux_mkv_get_sub_lang(demuxer, dvdsub_id, lang, 9);
1727 lang[39] = 0;
1728 snprintf(*(char**)arg, 63, "(%d) %s", dvdsub_id, lang);
1729 return 1;
1730 }
1731 #endif
1732 #ifdef HAVE_OGGVORBIS
1733 if (demuxer->type == DEMUXER_TYPE_OGG && d_dvdsub && dvdsub_id >= 0) {
1734 char *lang = demux_ogg_sub_lang(demuxer, dvdsub_id);
1735 if (!lang) lang = MSGTR_Unknown;
1736 snprintf(*(char**)arg, 63, "(%d) %s",
1737 dvdsub_id, lang);
1738 return 1;
1739 }
1740 #endif
1741 if (vo_vobsub && vobsub_id >= 0) {
1742 const char *language = MSGTR_Unknown;
1743 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
1744 snprintf(*(char**)arg, 63, "(%d) %s",
1745 vobsub_id, language ? language : MSGTR_Unknown);
1746 return 1;
1747 }
1748 #ifdef USE_DVDREAD
1749 if (vo_spudec && dvdsub_id >= 0) {
1750 char lang[3] = "\0\0\0";
1751 int code = 0;
1752 code = dvd_lang_from_sid(stream, dvdsub_id);
1753 if (code) {
1754 lang[0] = code >> 8;
1755 lang[1] = code;
1756 lang[2] = 0;
1757 }
1758 snprintf(*(char**)arg, 63, "(%d) %s",
1759 dvdsub_id, lang);
1760 return 1;
1761 }
1762 #endif
1763 snprintf(*(char**)arg, 63, MSGTR_Disabled);
1764 return 1;
1765
1766 case M_PROPERTY_SET:
1767 if(!arg) return 0;
1768 if(*(int*)arg < -1) *(int*)arg = -1;
1769 else if(*(int*)arg >= global_sub_size) *(int*)arg = global_sub_size-1;
1770 global_sub_pos = *(int*)arg;
1771 break;
1772 case M_PROPERTY_STEP_UP:
1773 global_sub_pos += 2;
1774 global_sub_pos = (global_sub_pos % (global_sub_size+1)) - 1;
1775 break;
1776 case M_PROPERTY_STEP_DOWN:
1777 global_sub_pos += global_sub_size+1;
1778 global_sub_pos = (global_sub_pos % (global_sub_size+1)) - 1;
1779 break;
1780 default:
1781 return M_PROPERTY_NOT_IMPLEMENTED;
1782 }
1783
1784 if (global_sub_pos >= 0)
1785 source = sub_source();
1786
1787 mp_msg(MSGT_CPLAYER, MSGL_DBG3,
1788 "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
1789 global_sub_size, global_sub_indices[SUB_SOURCE_VOBSUB],
1790 global_sub_indices[SUB_SOURCE_SUBS],
1791 global_sub_indices[SUB_SOURCE_DEMUX],
1792 global_sub_pos, source);
1793
1794 #ifdef USE_SUB
1795 set_of_sub_pos = -1;
1796 subdata = NULL;
1797 vo_sub_last = vo_sub = NULL;
1798 #endif
1799 vobsub_id = -1;
1800 dvdsub_id = -1;
1801 if (d_dvdsub) {
1802 if(d_dvdsub->id > -2) reset_spu = 1;
1803 d_dvdsub->id = -2;
1804 }
1805
1806 if (source == SUB_SOURCE_VOBSUB) {
1807 vobsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_VOBSUB];
1808 #ifdef USE_SUB
1809 } else if (source == SUB_SOURCE_SUBS) {
1810 set_of_sub_pos = global_sub_pos - global_sub_indices[SUB_SOURCE_SUBS];
1811 subdata = set_of_subtitles[set_of_sub_pos];
1812 vo_osd_changed(OSDTYPE_SUBTITLE);
1813 #endif
1814 } else if (source == SUB_SOURCE_DEMUX) {
1815 dvdsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_DEMUX];
1816 if (d_dvdsub) {
1817 #ifdef USE_DVDREAD
1818 if (vo_spudec && stream->type == STREAMTYPE_DVD) {
1819 d_dvdsub->id = dvdsub_id;
1820 spudec_reset(vo_spudec);
1821 }
1822 #endif
1823 #ifdef HAVE_OGGVORBIS
1824 if (demuxer->type == DEMUXER_TYPE_OGG)
1825 d_dvdsub->id = demux_ogg_sub_id(demuxer, dvdsub_id);
1826 #endif
1827 #ifdef HAVE_MATROSKA
1828 if (demuxer->type == DEMUXER_TYPE_MATROSKA) {
1829 d_dvdsub->id = demux_mkv_change_subs(demuxer, dvdsub_id);
1830 if (d_dvdsub->id >= 0 &&
1831 ((mkv_sh_sub_t *)d_dvdsub->sh)->type == 'v') {
1832 mkv_sh_sub_t *mkv_sh_sub = (mkv_sh_sub_t *)d_dvdsub->sh;
1833 if (vo_spudec != NULL)
1834 spudec_free(vo_spudec);
1835 vo_spudec =
1836 spudec_new_scaled_vobsub(mkv_sh_sub->has_palette ?
1837 mkv_sh_sub->palette :
1838 NULL, mkv_sh_sub->colors,
1839 mkv_sh_sub->custom_colors,
1840 mkv_sh_sub->width,
1841 mkv_sh_sub->height);
1842 if (!forced_subs_only)
1843 forced_subs_only = mkv_sh_sub->forced_subs_only;
1844 if (vo_spudec) {
1845 spudec_set_forced_subs_only(vo_spudec,
1846 forced_subs_only);
1847 inited_flags |= INITED_SPUDEC;
1848 }
1849 }
1850 }
1851 #endif
1852 }
1853 } else { // off
1854 #ifdef USE_SUB
1855 vo_osd_changed(OSDTYPE_SUBTITLE);
1856 #endif
1857 if(vo_spudec) vo_osd_changed(OSDTYPE_SPU);
1858 }
1859 #ifdef USE_DVDREAD
1860 if (vo_spudec && stream->type == STREAMTYPE_DVD && dvdsub_id < 0 && reset_spu) {
1861 dvdsub_id = -2;
1862 d_dvdsub->id = dvdsub_id;
1863 spudec_reset(vo_spudec);
1864 }
1865 #endif
1866
1867 return 1;
1868 }
1869
1870 static int mp_property_sub_delay(m_option_t* prop,int action,void* arg) {
1871 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
1872 return m_property_delay(prop,action,arg,&sub_delay);
1873 }
1874
1875 static int mp_property_sub_alignment(m_option_t* prop,int action,void* arg) {
1876 #ifdef USE_SUB
1877 char* name[] = { MSGTR_Top, MSGTR_Center, MSGTR_Bottom };
1878
1879 if(!sh_video || global_sub_pos < 0 || sub_source() != SUB_SOURCE_SUBS)
1880 return M_PROPERTY_UNAVAILABLE;
1881
1882 switch(action) {
1883 case M_PROPERTY_PRINT:
1884 if(!arg) return 0;
1885 M_PROPERTY_CLAMP(prop,sub_alignment);
1886 *(char**)arg = strdup(name[sub_alignment]);
1887 return 1;
1888 case M_PROPERTY_SET:
1889 if(!arg) return 0;
1890 case M_PROPERTY_STEP_UP:
1891 case M_PROPERTY_STEP_DOWN:
1892 vo_osd_changed(OSDTYPE_SUBTITLE);
1893 default:
1894 return m_property_choice(prop,action,arg,&sub_alignment);
1895 }
1896 #else
1897 return M_PROPERTY_UNAVAILABLE;
1898 #endif
1899 }
1900
1901 static int mp_property_sub_visibility(m_option_t* prop,int action,void* arg) {
1902 #ifdef USE_SUB
1903 if(!sh_video) return M_PROPERTY_UNAVAILABLE;
1904
1905 switch(action) {
1906 case M_PROPERTY_SET:
1907 if(!arg) return 0;
1908 case M_PROPERTY_STEP_UP:
1909 case M_PROPERTY_STEP_DOWN:
1910 vo_osd_changed(OSDTYPE_SUBTITLE);
1911 if(vo_spudec) vo_osd_changed(OSDTYPE_SPU);
1912 default:
1913 return m_property_flag(prop,action,arg,&sub_visibility);
1914 }
1915 #else
1916 return M_PROPERTY_UNAVAILABLE;
1917 #endif
1918 }
1919
1920 static int mp_property_sub_forced_only(m_option_t* prop,int action,void* arg) {
1921 if(!vo_spudec) return M_PROPERTY_UNAVAILABLE;
1922
1923 switch(action) {
1924 case M_PROPERTY_SET:
1925 if(!arg) return 0;
1926 case M_PROPERTY_STEP_UP:
1927 case M_PROPERTY_STEP_DOWN:
1928 m_property_flag(prop,action,arg,&forced_subs_only);
1929 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
1930 return 1;
1931 default:
1932 return m_property_flag(prop,action,arg,&forced_subs_only);
1933 }
1934
1935 }
1678 1936
1679 static m_option_t mp_properties[] = { 1937 static m_option_t mp_properties[] = {
1680 // General 1938 // General
1681 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT, 1939 { "osdlevel", mp_property_osdlevel, CONF_TYPE_INT,
1682 M_OPT_RANGE, 0, 3, NULL }, 1940 M_OPT_RANGE, 0, 3, NULL },
1743 { "fps", mp_property_fps, CONF_TYPE_FLOAT, 2001 { "fps", mp_property_fps, CONF_TYPE_FLOAT,
1744 0, 0, 0, NULL }, 2002 0, 0, 0, NULL },
1745 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT, 2003 { "aspect", mp_property_aspect, CONF_TYPE_FLOAT,
1746 0, 0, 0, NULL }, 2004 0, 0, 0, NULL },
1747 2005
2006 // Subs
2007 { "sub", mp_property_sub, CONF_TYPE_INT,
2008 M_OPT_MIN, -1, 0, NULL },
2009 { "sub_delay", mp_property_sub_delay, CONF_TYPE_FLOAT,
2010 0, 0, 0, NULL },
2011 { "sub_pos", mp_property_sub_pos, CONF_TYPE_INT,
2012 M_OPT_RANGE, 0, 100, NULL },
2013 { "sub_alignment", mp_property_sub_alignment, CONF_TYPE_INT,
2014 M_OPT_RANGE, 0, 2, NULL },
2015 { "sub_visibility", mp_property_sub_visibility, CONF_TYPE_FLAG,
2016 M_OPT_RANGE, 0, 1, NULL },
2017 { "sub_forced_only", mp_property_sub_forced_only, CONF_TYPE_FLAG,
2018 M_OPT_RANGE, 0, 1, NULL },
2019
1748 { NULL, NULL, NULL, 0, 0, 0, NULL } 2020 { NULL, NULL, NULL, 0, 0, 0, NULL }
1749 }; 2021 };
1750 2022
1751 m_option_t* mp_property_find(char* name) { 2023 m_option_t* mp_property_find(char* name) {
1752 return m_option_list_find(mp_properties,name); 2024 return m_option_list_find(mp_properties,name);
1800 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness }, 2072 { "brightness", MP_CMD_BRIGHTNESS, 0, OSD_BRIGHTNESS, -1, MSGTR_Brightness },
1801 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast }, 2073 { "contrast", MP_CMD_CONTRAST, 0, OSD_CONTRAST, -1, MSGTR_Contrast },
1802 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation }, 2074 { "saturation", MP_CMD_SATURATION, 0, OSD_SATURATION, -1, MSGTR_Saturation },
1803 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue }, 2075 { "hue", MP_CMD_HUE, 0, OSD_HUE, -1, MSGTR_Hue },
1804 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus }, 2076 { "vsync", MP_CMD_SWITCH_VSYNC, 1, 0, -1, MSGTR_VSyncStatus },
2077 // subs
2078 { "sub", MP_CMD_SUB_SELECT, 1, 0, -1, MSGTR_SubSelectStatus },
2079 { "sub_pos", MP_CMD_SUB_POS, 0, 0, -1, MSGTR_SubPosStatus },
2080 { "sub_alignment", MP_CMD_SUB_ALIGNMENT, 1, 0, -1, MSGTR_SubAlignStatus },
2081 { "sub_delay", MP_CMD_SUB_DELAY, 0, 0, OSD_MSG_SUB_DELAY, MSGTR_SubDelayStatus },
2082 { "sub_visibility", MP_CMD_SUB_VISIBILITY, 1, 0, -1, MSGTR_SubVisibleStatus },
2083 { "sub_forced_only", MP_CMD_SUB_FORCED_ONLY, 1, 0, -1, MSGTR_SubForcedOnlyStatus },
1805 2084
1806 { NULL, 0, 0, 0, -1, NULL } 2085 { NULL, 0, 0, 0, -1, NULL }
1807 }; 2086 };
1808 2087
1809 static int set_property_command(mp_cmd_t* cmd) { 2088 static int set_property_command(mp_cmd_t* cmd) {
1864 int main(int argc,char* argv[]){ 2143 int main(int argc,char* argv[]){
1865 2144
1866 2145
1867 char * mem_ptr; 2146 char * mem_ptr;
1868 2147
1869 static demux_stream_t *d_audio=NULL;
1870 static demux_stream_t *d_video=NULL;
1871 static demux_stream_t *d_dvdsub=NULL;
1872
1873 int file_format=DEMUXER_TYPE_UNKNOWN; 2148 int file_format=DEMUXER_TYPE_UNKNOWN;
1874 2149
1875 int delay_corrected=1; 2150 int delay_corrected=1;
1876 2151
1877 // movie info: 2152 // movie info:
1878
1879 // still needed for the subtitles mess
1880 int osd_show_vobsub_changed = 0;
1881 int osd_show_sub_changed = 0;
1882 2153
1883 int rtc_fd=-1; 2154 int rtc_fd=-1;
1884 2155
1885 int opt_exit = 0; // flag indicating whether mplayer should exit without playing anything 2156 int opt_exit = 0; // flag indicating whether mplayer should exit without playing anything
1886 2157
2859 // nothing worth doing automatically. 3130 // nothing worth doing automatically.
2860 global_sub_pos = -1; 3131 global_sub_pos = -1;
2861 } 3132 }
2862 // rather than duplicate code, use the SUB_SELECT handler to init the right one. 3133 // rather than duplicate code, use the SUB_SELECT handler to init the right one.
2863 global_sub_pos--; 3134 global_sub_pos--;
2864 mp_input_queue_cmd(mp_input_parse_cmd("sub_select")); 3135 mp_property_do("sub",M_PROPERTY_STEP_UP,NULL);
3136 if(subdata)
3137 switch (stream_dump_type) {
3138 case 3: list_sub_file(subdata); break;
3139 case 4: dump_mpsub(subdata, sh_video->fps); break;
3140 case 6: dump_srt(subdata, sh_video->fps); break;
3141 case 7: dump_microdvd(subdata, sh_video->fps); break;
3142 case 8: dump_jacosub(subdata, sh_video->fps); break;
3143 case 9: dump_sami(subdata, sh_video->fps); break;
3144 }
2865 } 3145 }
2866 3146
2867 //================== Init AUDIO (codec) ========================== 3147 //================== Init AUDIO (codec) ==========================
2868 if(sh_audio){ 3148 if(sh_audio){
2869 // Go through the codec.conf and find the best codec... 3149 // Go through the codec.conf and find the best codec...
3011 //float v_frame=0; // Video 3291 //float v_frame=0; // Video
3012 float time_frame=0; // Timer 3292 float time_frame=0; // Timer
3013 //float num_frames=0; // number of frames played 3293 //float num_frames=0; // number of frames played
3014 int grab_frames=0; 3294 int grab_frames=0;
3015 char osd_text_buffer[64]; 3295 char osd_text_buffer[64];
3016 char osd_show_text_buffer[64];
3017 int drop_frame=0; // current dropping status 3296 int drop_frame=0; // current dropping status
3018 int dropped_frames=0; // how many frames dropped since last non-dropped frame 3297 int dropped_frames=0; // how many frames dropped since last non-dropped frame
3019 int too_slow_frame_cnt=0; 3298 int too_slow_frame_cnt=0;
3020 int too_fast_frame_cnt=0; 3299 int too_fast_frame_cnt=0;
3021 // for auto-quality: 3300 // for auto-quality:
3834 eof = PT_NEXT_SRC; 4113 eof = PT_NEXT_SRC;
3835 else if(v < 0 && playtree_iter->file > 1) 4114 else if(v < 0 && playtree_iter->file > 1)
3836 eof = PT_PREV_SRC; 4115 eof = PT_PREV_SRC;
3837 } 4116 }
3838 brk_cmd = 1; 4117 brk_cmd = 1;
3839 } break;
3840 case MP_CMD_SUB_DELAY : {
3841 #ifdef USE_SUB
3842 if (sh_video) {
3843 int abs= cmd->args[1].v.i;
3844 float v = cmd->args[0].v.f;
3845 if(abs)
3846 sub_delay = v;
3847 else
3848 sub_delay += v;
3849 set_osd_msg(OSD_MSG_SUB_DELAY,1,osd_duration,
3850 MSGTR_OSDSubDelay, ROUND(sub_delay*1000));
3851 }
3852 #endif
3853 } break; 4118 } break;
3854 case MP_CMD_SUB_STEP : { 4119 case MP_CMD_SUB_STEP : {
3855 #ifdef USE_SUB 4120 #ifdef USE_SUB
3856 if (sh_video) { 4121 if (sh_video) {
3857 int movement = cmd->args[0].v.i; 4122 int movement = cmd->args[0].v.i;
4038 case MP_CMD_TV_STEP_CHANNEL_LIST : { 4303 case MP_CMD_TV_STEP_CHANNEL_LIST : {
4039 if (file_format == DEMUXER_TYPE_TV) 4304 if (file_format == DEMUXER_TYPE_TV)
4040 tv_step_chanlist((tvi_handle_t*)(demuxer->priv)); 4305 tv_step_chanlist((tvi_handle_t*)(demuxer->priv));
4041 } break; 4306 } break;
4042 #endif /* USE_TV */ 4307 #endif /* USE_TV */
4043 case MP_CMD_SUB_POS:
4044 {
4045 #ifdef USE_SUB
4046 if (sh_video) {
4047 int v;
4048 v = cmd->args[0].v.i;
4049
4050 sub_pos+=v;
4051 if(sub_pos >100) sub_pos=100;
4052 if(sub_pos <0) sub_pos=0;
4053 set_osd_msg(OSD_MSG_SUB_POS,1,osd_duration,
4054 MSGTR_OSDSubPosition, sub_pos);
4055 vo_osd_changed(OSDTYPE_SUBTITLE);
4056 }
4057 #endif
4058 } break;
4059 case MP_CMD_SUB_ALIGNMENT:
4060 {
4061 #ifdef USE_SUB
4062 if (sh_video) {
4063 if (cmd->nargs >= 1)
4064 sub_alignment = cmd->args[0].v.i;
4065 else
4066 sub_alignment = (sub_alignment+1) % 3;
4067 set_osd_msg(OSD_MSG_SUB_ALIGN,1,osd_duration,
4068 MSGTR_OSDSubAlignment,(sub_alignment == 2 ? MSGTR_OSDSubBottom :
4069 (sub_alignment == 1 ? MSGTR_OSDSubCenter : MSGTR_OSDSubTop)));
4070 vo_osd_changed(OSDTYPE_SUBTITLE);
4071 }
4072 #endif
4073 } break;
4074 case MP_CMD_SUB_VISIBILITY:
4075 {
4076 #ifdef USE_SUB
4077 if (sh_video) {
4078 sub_visibility=1-sub_visibility;
4079 set_osd_msg(OSD_MSG_SUB_VISIBLE,1,osd_duration,
4080 MSGTR_OSDSubtitles, sub_visibility?MSGTR_OSDenabled:MSGTR_OSDdisabled);
4081 vo_osd_changed(OSDTYPE_SUBTITLE);
4082 }
4083 #endif
4084 } break;
4085 case MP_CMD_SUB_LOAD: 4308 case MP_CMD_SUB_LOAD:
4086 { 4309 {
4087 #ifdef USE_SUB 4310 #ifdef USE_SUB
4088 if (sh_video) { 4311 if (sh_video) {
4089 int n = set_of_sub_size; 4312 int n = set_of_sub_size;
4152 if (sh_video) { 4375 if (sh_video) {
4153 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_SUB_VISIBILITY=%d\n", sub_visibility); 4376 mp_msg(MSGT_GLOBAL,MSGL_INFO, "ANS_SUB_VISIBILITY=%d\n", sub_visibility);
4154 } 4377 }
4155 #endif 4378 #endif
4156 } break; 4379 } break;
4157 case MP_CMD_SUB_SELECT:
4158 if (global_sub_size) {
4159 int source = -1;
4160 int reset=0;
4161 int v = cmd->args[0].v.i;
4162
4163 if (v < -1)
4164 global_sub_pos++;
4165 else
4166 global_sub_pos = v;
4167 if(global_sub_pos == global_sub_size)
4168 reset = 1;
4169 if (global_sub_pos >= global_sub_size)
4170 global_sub_pos = -1;
4171 if (global_sub_pos >= 0)
4172 source = sub_source();
4173
4174 mp_msg(MSGT_CPLAYER, MSGL_DBG3, "subtitles: %d subs, (v@%d s@%d d@%d), @%d, source @%d\n",
4175 global_sub_size, global_sub_indices[SUB_SOURCE_VOBSUB],
4176 global_sub_indices[SUB_SOURCE_SUBS], global_sub_indices[SUB_SOURCE_DEMUX],
4177 global_sub_pos, source);
4178
4179 #ifdef USE_SUB
4180 set_of_sub_pos = -1;
4181 subdata = NULL;
4182 vo_sub_last = vo_sub = NULL;
4183 #endif
4184 vobsub_id = -1;
4185 if(dvdsub_lang || reset) {
4186 dvdsub_id = -1;
4187 if (d_dvdsub) d_dvdsub->id = -1;
4188 }
4189
4190 // be careful!
4191 // if sub_changed is till on but subdata's been reset, bad things happen.
4192 osd_show_vobsub_changed = 0;
4193 osd_show_sub_changed = 0;
4194
4195 if (source == SUB_SOURCE_VOBSUB) {
4196 vobsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_VOBSUB];
4197 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
4198 #ifdef USE_SUB
4199 } else if (source == SUB_SOURCE_SUBS) {
4200 set_of_sub_pos = global_sub_pos - global_sub_indices[SUB_SOURCE_SUBS];
4201 subdata = set_of_subtitles[set_of_sub_pos];
4202 if (!global_sub_quiet_osd_hack) osd_show_sub_changed = sh_video->fps;
4203 vo_osd_changed(OSDTYPE_SUBTITLE);
4204
4205 // FIXME: is this the correct place for these?
4206 switch (stream_dump_type) {
4207 case 3: list_sub_file(subdata); break;
4208 case 4: dump_mpsub(subdata, sh_video->fps); break;
4209 case 6: dump_srt(subdata, sh_video->fps); break;
4210 case 7: dump_microdvd(subdata, sh_video->fps); break;
4211 case 8: dump_jacosub(subdata, sh_video->fps); break;
4212 case 9: dump_sami(subdata, sh_video->fps); break;
4213 }
4214 #endif
4215 } else if (source == SUB_SOURCE_DEMUX) {
4216 dvdsub_id = global_sub_pos - global_sub_indices[SUB_SOURCE_DEMUX];
4217 if (d_dvdsub) {
4218 #ifdef USE_DVDREAD
4219 if (vo_spudec && stream->type == STREAMTYPE_DVD) {
4220 d_dvdsub->id = dvdsub_id;
4221 spudec_reset(vo_spudec);
4222 }
4223 #endif
4224 #ifdef HAVE_OGGVORBIS
4225 if (demuxer->type == DEMUXER_TYPE_OGG)
4226 d_dvdsub->id = demux_ogg_sub_id(demuxer, dvdsub_id);
4227 #endif
4228 #ifdef HAVE_MATROSKA
4229 if (demuxer->type == DEMUXER_TYPE_MATROSKA) {
4230 d_dvdsub->id = demux_mkv_change_subs(demuxer, dvdsub_id);
4231 if (d_dvdsub->id >= 0 && ((mkv_sh_sub_t *)d_dvdsub->sh)->type == 'v') {
4232 mkv_sh_sub_t *mkv_sh_sub = (mkv_sh_sub_t *)d_dvdsub->sh;
4233 if (vo_spudec != NULL)
4234 spudec_free(vo_spudec);
4235 vo_spudec =
4236 spudec_new_scaled_vobsub(mkv_sh_sub->has_palette ? mkv_sh_sub->palette : NULL, mkv_sh_sub->colors,
4237 mkv_sh_sub->custom_colors,
4238 mkv_sh_sub->width,
4239 mkv_sh_sub->height);
4240 if (!forced_subs_only)
4241 forced_subs_only = mkv_sh_sub->forced_subs_only;
4242 if (vo_spudec) {
4243 spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
4244 inited_flags |= INITED_SPUDEC;
4245 }
4246 }
4247 }
4248 #endif
4249 }
4250 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
4251 } else { // off
4252 #ifdef USE_DVDREAD
4253 if (vo_spudec && stream->type == STREAMTYPE_DVD && dvdsub_id < 0) {
4254 dvdsub_id = -2;
4255 d_dvdsub->id = dvdsub_id;
4256 spudec_reset(vo_spudec);
4257 }
4258 #endif
4259 if (!global_sub_quiet_osd_hack) osd_show_vobsub_changed = sh_video->fps;
4260 #ifdef USE_SUB
4261 vo_osd_changed(OSDTYPE_SUBTITLE);
4262 #endif
4263 }
4264 // it's annoying and dumb to show osd saying "off" at every subless file...
4265 global_sub_quiet_osd_hack = 0;
4266 }
4267 break;
4268 case MP_CMD_SUB_FORCED_ONLY:
4269 if (vo_spudec) {
4270 forced_subs_only = forced_subs_only ? 0 : ~0; // toggle state
4271 spudec_set_forced_subs_only(vo_spudec,forced_subs_only);
4272 }
4273 break;
4274 case MP_CMD_SCREENSHOT : 4380 case MP_CMD_SCREENSHOT :
4275 if(vo_config_count){ 4381 if(vo_config_count){
4276 mp_msg(MSGT_CPLAYER,MSGL_INFO,"sending VFCTRL_SCREENSHOT!\n"); 4382 mp_msg(MSGT_CPLAYER,MSGL_INFO,"sending VFCTRL_SCREENSHOT!\n");
4277 if(CONTROL_OK!=((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, VFCTRL_SCREENSHOT, 0)) 4383 if(CONTROL_OK!=((vf_instance_t *)sh_video->vfilter)->control(sh_video->vfilter, VFCTRL_SCREENSHOT, 0))
4278 video_out->control(VOCTRL_SCREENSHOT, NULL); 4384 video_out->control(VOCTRL_SCREENSHOT, NULL);
4694 } 4800 }
4695 #endif /* HAVE_NEW_GUI */ 4801 #endif /* HAVE_NEW_GUI */
4696 4802
4697 4803
4698 //================= Update OSD ==================== 4804 //================= Update OSD ====================
4699 #ifdef USE_OSD
4700 if(sh_video){
4701 char osd_text_tmp[64];
4702 // The subtitles stuff is particulary messy. Keep the mess for now it will be
4703 // cleaned up when properties get implemented.
4704 if (osd_show_vobsub_changed) {
4705 snprintf(osd_text_tmp, 63, MSGTR_OSDSubtitlesOff);
4706 switch (demuxer->type) {
4707 #ifdef HAVE_MATROSKA
4708 case DEMUXER_TYPE_MATROSKA:
4709 if (dvdsub_id >= 0) {
4710 char lang[40] = MSGTR_OSDunknown;
4711 demux_mkv_get_sub_lang(demuxer, dvdsub_id, lang, 39);
4712 lang[39] = 0;
4713 snprintf(osd_text_tmp, 63, MSGTR_OSDSubtitlesLanguage, dvdsub_id, lang);
4714 }
4715 break;
4716 #endif
4717 #ifdef HAVE_OGGVORBIS
4718 case DEMUXER_TYPE_OGG:
4719 if (d_dvdsub && dvdsub_id >= 0) {
4720 char *lang = demux_ogg_sub_lang(demuxer, dvdsub_id);
4721 snprintf(osd_text_tmp, 63, MSGTR_OSDSubtitlesLanguage, dvdsub_id, lang ? lang : MSGTR_OSDunknown);
4722 }
4723 break;
4724 #endif
4725 default:
4726 if (vo_vobsub && vobsub_id >= 0) {
4727 char *language = MSGTR_OSDnone;
4728 language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
4729 snprintf(osd_text_tmp, 63, MSGTR_OSDSubtitlesLanguage, vobsub_id, language ? language : MSGTR_OSDunknown);
4730 }
4731 #ifdef USE_DVDREAD
4732 if (vo_spudec && dvdsub_id >= 0) {
4733 char lang[3] = "\0\0\0";
4734 int code = 0;
4735 code = dvd_lang_from_sid(stream, dvdsub_id);
4736 if (code) {
4737 lang[0] = code >> 8;
4738 lang[1] = code;
4739 }
4740 snprintf(osd_text_tmp, 63, MSGTR_OSDSubtitlesLanguage, dvdsub_id, code ? lang : MSGTR_OSDnone);
4741 }
4742 #endif
4743 break;
4744 }
4745 osd_show_vobsub_changed = 0;
4746 set_osd_msg(OSD_MSG_SUB_CHANGED,1,osd_duration,
4747 "%s",osd_text_tmp);
4748 } else
4749 #ifdef USE_SUB
4750 if (osd_show_sub_changed) {
4751 char *tmp2;
4752 tmp = subdata->filename;
4753 if ((tmp2 = strrchr(tmp, '/'))) {
4754 tmp = tmp2+1;
4755 }
4756 set_osd_msg(OSD_MSG_SUB_CHANGED,1,osd_duration,
4757 MSGTR_OSDSub, set_of_sub_pos + 1,
4758 strlen(tmp) < 20 ? "" : "...",
4759 strlen(tmp) < 20 ? tmp : tmp+strlen(tmp)-19);
4760 osd_show_sub_changed = 0;
4761 }
4762 #endif
4763 }
4764 // for(i=1;i<=11;i++) osd_text_buffer[10+i]=i;osd_text_buffer[10+i]=0;
4765 // vo_osd_text=osd_text_buffer;
4766 #endif /* USE_OSD */
4767 4805
4768 update_osd_msg(); 4806 update_osd_msg();
4769 4807
4770 #ifdef USE_SUB 4808 #ifdef USE_SUB
4771 // find sub 4809 // find sub