comparison stream/tvi_vbi.c @ 24342:8873c972c6aa

Decrease teletext page rendering frequency from 1/frame to about 4/sec.
author voroshil
date Sat, 08 Sep 2007 03:06:23 +0000
parents 31dbcf68a706
children 09d402672398
comparison
equal deleted inserted replaced
24341:23e69a6846ee 24342:8873c972c6aa
94 #include "mp_msg.h" 94 #include "mp_msg.h"
95 #include "help_mp.h" 95 #include "help_mp.h"
96 #include "libmpcodecs/img_format.h" 96 #include "libmpcodecs/img_format.h"
97 #include "libavutil/common.h" 97 #include "libavutil/common.h"
98 #include "input/input.h" 98 #include "input/input.h"
99 #include "osdep/timer.h"
99 100
100 //#define DEBUG_DUMP 1 101 //#define DEBUG_DUMP 1
101 102
102 /// page magazine entry structure 103 /// page magazine entry structure
103 typedef struct mag_s{ 104 typedef struct mag_s{
148 int timeoffset; // timeoffset=realoffset*2 149 int timeoffset; // timeoffset=realoffset*2
149 unsigned int juliandate; 150 unsigned int juliandate;
150 unsigned int universaltime; 151 unsigned int universaltime;
151 unsigned char networkname[21]; 152 unsigned char networkname[21];
152 int cache_reset; 153 int cache_reset;
154 /// "page changed" flag: 0-unchanged, 1-entire page, 3-only header
155 int page_changed;
153 } priv_vbi_t; 156 } priv_vbi_t;
154 157
155 static unsigned char fixParity[256]; 158 static unsigned char fixParity[256];
156 159
157 static tt_char tt_space={0x20,7,0,0,0,0,0x20}; 160 static tt_char tt_space={0x20,7,0,0,0,0,0x20};
1633 priv_vbi_t* priv=(priv_vbi_t*)p; 1636 priv_vbi_t* priv=(priv_vbi_t*)p;
1634 tt_page* pgc; 1637 tt_page* pgc;
1635 1638
1636 if (!priv && cmd!=TV_VBI_CONTROL_START) 1639 if (!priv && cmd!=TV_VBI_CONTROL_START)
1637 return TVI_CONTROL_FALSE; 1640 return TVI_CONTROL_FALSE;
1638 if (!arg && cmd!=TV_VBI_CONTROL_STOP) 1641 if (!arg && cmd!=TV_VBI_CONTROL_STOP && cmd!=TV_VBI_CONTROL_MARK_UNCHANGED)
1639 return TVI_CONTROL_FALSE; 1642 return TVI_CONTROL_FALSE;
1640 1643
1641 switch (cmd) { 1644 switch (cmd) {
1642 case TV_VBI_CONTROL_RESET: 1645 case TV_VBI_CONTROL_RESET:
1643 { 1646 {
1667 mp_msg(MSGT_TV,MSGL_INFO,MSGTR_TV_TTSelectedLanguage, 1670 mp_msg(MSGT_TV,MSGL_INFO,MSGTR_TV_TTSelectedLanguage,
1668 tt_languages[i].lang_name); 1671 tt_languages[i].lang_name);
1669 priv->primary_language=tt_languages[i].lang_code; 1672 priv->primary_language=tt_languages[i].lang_code;
1670 } 1673 }
1671 } 1674 }
1675 priv->page_changed=1;
1672 pthread_mutex_unlock(&(priv->buffer_mutex)); 1676 pthread_mutex_unlock(&(priv->buffer_mutex));
1673 return TVI_CONTROL_TRUE; 1677 return TVI_CONTROL_TRUE;
1674 } 1678 }
1675 case TV_VBI_CONTROL_START: 1679 case TV_VBI_CONTROL_START:
1676 { 1680 {
1694 1698
1695 priv->mag=calloc(8,sizeof(mag_t)); 1699 priv->mag=calloc(8,sizeof(mag_t));
1696 init_cache(priv); 1700 init_cache(priv);
1697 init_vbi_consts(priv); 1701 init_vbi_consts(priv);
1698 pll_reset(priv,fine_tune); 1702 pll_reset(priv,fine_tune);
1703 priv->page_changed=1;
1699 return TVI_CONTROL_TRUE; 1704 return TVI_CONTROL_TRUE;
1700 } 1705 }
1701 case TV_VBI_CONTROL_STOP: 1706 case TV_VBI_CONTROL_STOP:
1702 { 1707 {
1703 if(priv->mag) 1708 if(priv->mag)
1704 free(priv->mag); 1709 free(priv->mag);
1705 if(priv->ptsp) 1710 if(priv->ptsp)
1706 free(priv->ptsp); 1711 free(priv->ptsp);
1707 destroy_cache(priv); 1712 destroy_cache(priv);
1713 priv->page_changed=1;
1708 free(priv); 1714 free(priv);
1709 return TVI_CONTROL_TRUE; 1715 return TVI_CONTROL_TRUE;
1710 } 1716 }
1711 case TV_VBI_CONTROL_SET_MODE: 1717 case TV_VBI_CONTROL_SET_MODE:
1712 priv->on=(*(int*)arg%2); 1718 priv->on=(*(int*)arg%2);
1719 priv->page_changed=1;
1713 return TVI_CONTROL_TRUE; 1720 return TVI_CONTROL_TRUE;
1714 case TV_VBI_CONTROL_GET_MODE: 1721 case TV_VBI_CONTROL_GET_MODE:
1715 *(int*)arg=priv->on; 1722 *(int*)arg=priv->on;
1716 return TVI_CONTROL_TRUE; 1723 return TVI_CONTROL_TRUE;
1717 case TV_VBI_CONTROL_SET_FORMAT: 1724 case TV_VBI_CONTROL_SET_FORMAT:
1725 priv->page_changed=1;
1718 return teletext_set_format(priv, *(int *) arg); 1726 return teletext_set_format(priv, *(int *) arg);
1719 case TV_VBI_CONTROL_GET_FORMAT: 1727 case TV_VBI_CONTROL_GET_FORMAT:
1720 pthread_mutex_lock(&(priv->buffer_mutex)); 1728 pthread_mutex_lock(&(priv->buffer_mutex));
1721 *(int*)arg=priv->tformat; 1729 *(int*)arg=priv->tformat;
1722 pthread_mutex_unlock(&(priv->buffer_mutex)); 1730 pthread_mutex_unlock(&(priv->buffer_mutex));
1732 val%=3; 1740 val%=3;
1733 if(val<0) 1741 if(val<0)
1734 val+=3; 1742 val+=3;
1735 pthread_mutex_lock(&(priv->buffer_mutex)); 1743 pthread_mutex_lock(&(priv->buffer_mutex));
1736 priv->zoom=val; 1744 priv->zoom=val;
1745 priv->page_changed=1;
1737 pthread_mutex_unlock(&(priv->buffer_mutex)); 1746 pthread_mutex_unlock(&(priv->buffer_mutex));
1738 return TVI_CONTROL_TRUE; 1747 return TVI_CONTROL_TRUE;
1739 } 1748 }
1740 case TV_VBI_CONTROL_GO_LINK: 1749 case TV_VBI_CONTROL_GO_LINK:
1741 { 1750 {
1754 priv->pagenum=pgc->links[val-1].pagenum; 1763 priv->pagenum=pgc->links[val-1].pagenum;
1755 if(pgc->links[val-1].subpagenum!=0x3f7f) 1764 if(pgc->links[val-1].subpagenum!=0x3f7f)
1756 priv->subpagenum=pgc->links[val-1].subpagenum; 1765 priv->subpagenum=pgc->links[val-1].subpagenum;
1757 else 1766 else
1758 priv->subpagenum=get_subpagenum_from_cache(priv,priv->pagenum); 1767 priv->subpagenum=get_subpagenum_from_cache(priv,priv->pagenum);
1768 priv->page_changed=1;
1759 pthread_mutex_unlock(&(priv->buffer_mutex)); 1769 pthread_mutex_unlock(&(priv->buffer_mutex));
1760 return TVI_CONTROL_TRUE; 1770 return TVI_CONTROL_TRUE;
1761 } 1771 }
1762 case TV_VBI_CONTROL_SET_PAGE: 1772 case TV_VBI_CONTROL_SET_PAGE:
1763 { 1773 {
1766 return TVI_CONTROL_FALSE; 1776 return TVI_CONTROL_FALSE;
1767 pthread_mutex_lock(&(priv->buffer_mutex)); 1777 pthread_mutex_lock(&(priv->buffer_mutex));
1768 priv->pagenum=val&0x7ff; 1778 priv->pagenum=val&0x7ff;
1769 priv->subpagenum=get_subpagenum_from_cache(priv,priv->pagenum); 1779 priv->subpagenum=get_subpagenum_from_cache(priv,priv->pagenum);
1770 priv->pagenumdec=0; 1780 priv->pagenumdec=0;
1781 priv->page_changed=1;
1771 pthread_mutex_unlock(&(priv->buffer_mutex)); 1782 pthread_mutex_unlock(&(priv->buffer_mutex));
1772 return TVI_CONTROL_TRUE; 1783 return TVI_CONTROL_TRUE;
1773 } 1784 }
1774 case TV_VBI_CONTROL_STEP_PAGE: 1785 case TV_VBI_CONTROL_STEP_PAGE:
1775 { 1786 {
1776 int direction=*(int *) arg; 1787 int direction=*(int *) arg;
1777 pthread_mutex_lock(&(priv->buffer_mutex)); 1788 pthread_mutex_lock(&(priv->buffer_mutex));
1778 priv->pagenum=steppage(priv->pagenum, direction,1); 1789 priv->pagenum=steppage(priv->pagenum, direction,1);
1779 priv->subpagenum=get_subpagenum_from_cache(priv,priv->pagenum); 1790 priv->subpagenum=get_subpagenum_from_cache(priv,priv->pagenum);
1780 priv->pagenumdec=0; 1791 priv->pagenumdec=0;
1792 priv->page_changed=1;
1781 pthread_mutex_unlock(&(priv->buffer_mutex)); 1793 pthread_mutex_unlock(&(priv->buffer_mutex));
1782 return TVI_CONTROL_TRUE; 1794 return TVI_CONTROL_TRUE;
1783 } 1795 }
1784 case TV_VBI_CONTROL_GET_PAGE: 1796 case TV_VBI_CONTROL_GET_PAGE:
1785 *(int*)arg=((priv->pagenum+0x700)&0x7ff)+0x100; 1797 *(int*)arg=((priv->pagenum+0x700)&0x7ff)+0x100;
1790 priv->subpagenum=*(int*)arg; 1802 priv->subpagenum=*(int*)arg;
1791 if(priv->subpagenum<0) 1803 if(priv->subpagenum<0)
1792 priv->subpagenum=0x3f7f; 1804 priv->subpagenum=0x3f7f;
1793 if(priv->subpagenum>=VBI_MAX_SUBPAGES) 1805 if(priv->subpagenum>=VBI_MAX_SUBPAGES)
1794 priv->subpagenum=VBI_MAX_SUBPAGES-1; 1806 priv->subpagenum=VBI_MAX_SUBPAGES-1;
1807 priv->page_changed=1;
1795 pthread_mutex_unlock(&(priv->buffer_mutex)); 1808 pthread_mutex_unlock(&(priv->buffer_mutex));
1796 return TVI_CONTROL_TRUE; 1809 return TVI_CONTROL_TRUE;
1797 case TV_VBI_CONTROL_GET_SUBPAGE: 1810 case TV_VBI_CONTROL_GET_SUBPAGE:
1798 *(int*)arg=priv->subpagenum; 1811 *(int*)arg=priv->subpagenum;
1799 return TVI_CONTROL_TRUE; 1812 return TVI_CONTROL_TRUE;
1800 case TV_VBI_CONTROL_ADD_DEC: 1813 case TV_VBI_CONTROL_ADD_DEC:
1801 vbi_add_dec(priv, *(char **) arg); 1814 vbi_add_dec(priv, *(char **) arg);
1815 priv->page_changed=1;
1802 return TVI_CONTROL_TRUE; 1816 return TVI_CONTROL_TRUE;
1803 case TV_VBI_CONTROL_DECODE_PAGE: 1817 case TV_VBI_CONTROL_DECODE_PAGE:
1804 vbi_decode(priv,*(unsigned char**)arg); 1818 vbi_decode(priv,*(unsigned char**)arg);
1805 return TVI_CONTROL_TRUE; 1819 return TVI_CONTROL_TRUE;
1806 case TV_VBI_CONTROL_GET_VBIPAGE: 1820 case TV_VBI_CONTROL_GET_VBIPAGE:
1810 *(void **)arg=priv->display_page; 1824 *(void **)arg=priv->display_page;
1811 return TVI_CONTROL_TRUE; 1825 return TVI_CONTROL_TRUE;
1812 case TV_VBI_CONTROL_GET_NETWORKNAME: 1826 case TV_VBI_CONTROL_GET_NETWORKNAME:
1813 *(void **)arg=priv->networkname; 1827 *(void **)arg=priv->networkname;
1814 return TVI_CONTROL_TRUE; 1828 return TVI_CONTROL_TRUE;
1829 case TV_VBI_CONTROL_MARK_UNCHANGED:
1830 priv->page_changed=0;
1831 return TVI_CONTROL_TRUE;
1832 case TV_VBI_CONTROL_IS_CHANGED:
1833 if((GetTimerMS()/250)%2) //forcing page update every 1/4 sec
1834 priv->page_changed=3; //mark that header update is enough
1835 *(int*)arg=priv->page_changed;
1836 return TVI_CONTROL_TRUE;
1815 } 1837 }
1816 return TVI_CONTROL_UNKNOWN; 1838 return TVI_CONTROL_UNKNOWN;
1817 } 1839 }