Changeset 20233


Ignore:
Timestamp:
02/27/13 20:51:11 (11 years ago)
Author:
nit
Message:

[titan] first step auto subtitle start

Location:
titan/titan
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • titan/titan/header.h

    r20192 r20233  
    778778int subtitlestop(int flag);
    779779int subtitlepause(int flag);
     780void changelastsubtitle(struct lastsubtitle* lsnode, int pid);
     781void dellastsubtitle(struct lastsubtitle* lsnode);
     782struct lastsubtitle* addlastsubtitle(char* line, int count, struct lastsubtitle* last);
     783struct lastsubtitle* getlastsubtitle(uint64_t transponderid, int serviceid);
    780784
    781785//linkedchannel.h
  • titan/titan/struct.h

    r20107 r20233  
    190190enum {FUNCTEXT, FUNCPIC, FUNCPROGRESS};
    191191enum {CASESSIONCREATE, CASESSIONBUSY, CASESSIONDEL, CASESSIONSTART, CASESSIONFINAL, CARESFIRSTENQUIRY, CARESCHANGE, CARESENQUIRY, CADATETIMESEND, CAMMIIDLE, CAMMIDISPLAYREPLAY, CAMMIFAKEOK};
     192
     193struct lastsubtitle
     194{
     195        uint64_t transponderid;
     196        int serviceid;
     197        int16_t subtitlepid;
     198        struct lastsubtitle* next;
     199};
    192200
    193201struct newsletter
     
    11931201        int writemostzap;
    11941202        int writemediadb;
     1203        int writelastsubtitle;
    11951204        // 1 mute is aktiv
    11961205        int mute;
     
    13401349        //pointer to marker for recordings
    13411350        struct marker* playmarker;
     1351        int autosubtitle;
    13421352} status;
    13431353
  • titan/titan/subtitle.h

    r16511 r20233  
    15921592        struct skin* tmp = NULL;
    15931593        struct subtitle* node = NULL;
     1594        struct lastsubtitle* lsnode = NULL;
    15941595
    15951596        listbox->aktline = 1;
     
    16411642                                subtitlestop(1);
    16421643                                m_lock(&status.subtitlemutex, 8);
     1644
     1645                                if(status.autosubtitle == 1 && status.aktservice->channel != NULL)
     1646                                {
     1647                                        lsnode = getlastsubtitle(status.aktservice->channel->transponderid, status.aktservice->channel->serviceid);
     1648                                        dellastsubtitle(lsnode);
     1649                                        lsnode = NULL;
     1650                                }
     1651                               
    16431652                                if(checksubtitle(status.aktservice->channel, (struct subtitle*)listbox->select->handle) != NULL)
    16441653                                {
     
    16491658                                                if(subtitlestart((struct subtitle*)listbox->select->handle) == 0)
    16501659                                                        status.subthreadpid = ((struct subtitle*)listbox->select->handle)->pid;
     1660
     1661                                                if(status.autosubtitle == 1 && status.aktservice->channel != NULL)
     1662                                                {
     1663                                                        lsnode = getlastsubtitle(status.aktservice->channel->transponderid, status.aktservice->channel->serviceid);
     1664                                                        if(lsnode == NULL)
     1665                                                        {
     1666                                                                char* tmpstr = NULL;
     1667                                                                tmpstr = ostrcat(ollutoa(status.aktservice->channel->transponderid), "#", 1, 0);
     1668                                                                tmpstr = ostrcat(tmpstr, oitoa(status.aktservice->channel->serviceid), 1, 1);
     1669                                                                tmpstr = ostrcat(tmpstr, "#", 1, 0);
     1670                                                                tmpstr = ostrcat(tmpstr, oitoa(((struct subtitle*)listbox->select->handle)->pid), 1, 1);
     1671                                                                addlastsubtitle(tmpstr, 1, NULL);
     1672                                                                free(tmpstr); tmpstr = NULL;
     1673                                                        }
     1674                                                        else
     1675                                                                changelastsubtitle(lsnode, ((struct subtitle*)listbox->select->handle)->pid);
     1676                                                }
     1677
    16511678                                        }
    16521679                                        else
     
    17731800}
    17741801
     1802int subtitlestartlast()
     1803{
     1804        int ret = 1;
     1805        struct subtitle* node = NULL;
     1806        struct lastsubtitle* lsnode = NULL;
     1807       
     1808        if(status.aktservice->channel != NULL)
     1809        {
     1810                m_lock(&status.subtitlemutex, 8);
     1811                node = status.aktservice->channel->subtitle;
     1812                lsnode = getlastsubtitle(status.aktservice->channel->transponderid, status.aktservice->channel->serviceid);
     1813               
     1814                if(lsnode != NULL)
     1815                {
     1816                        while(node != NULL)
     1817                        {
     1818                                if(node->pid == lsnode->subtitlepid)
     1819                                        break;
     1820                                node = node->next;
     1821                        }
     1822               
     1823                        if(node != NULL)
     1824                        {
     1825                                if(subtitlestart(node) == 0)
     1826                                {
     1827                                        status.subthreadpid = node->pid;
     1828                                        ret = 0;
     1829                                }
     1830                        }
     1831                }
     1832                m_unlock(&status.subtitlemutex, 8);
     1833        }
     1834        return ret;
     1835}
     1836
     1837void changelastsubtitle(struct lastsubtitle* lsnode, int pid)
     1838{
     1839        if(lsnode == NULL) return;
     1840
     1841        if(lsnode->subtitlepid != pid)
     1842        {
     1843                lsnode->subtitlepid = pid;
     1844                status.writelastsubtitle = 1;
     1845        }
     1846}
     1847
     1848struct lastsubtitle* getlastsubtitle(uint64_t transponderid, int serviceid)
     1849{
     1850        struct lastsubtitle *node = lastsubtitle;
     1851
     1852        while(node != NULL)
     1853        {
     1854                if(node->transponderid == transponderid && node->serviceid == serviceid)
     1855                        break;
     1856                node = node->next;
     1857        }
     1858       
     1859        return node;
     1860}
     1861
     1862struct lastsubtitle* addlastsubtitle(char* line, int count, struct lastsubtitle* last)
     1863{
     1864        //debug(1000, "in");
     1865        struct lastsubtitle *newnode = NULL, *prev = NULL, *node = lastsubtitle;
     1866        int ret = 0;
     1867
     1868        if(line == NULL) return NULL;
     1869
     1870        newnode = (struct lastsubtitle*)calloc(1, sizeof(struct lastsubtitle));
     1871        if(newnode == NULL)
     1872        {
     1873                err("no memory");
     1874                return NULL;
     1875        }
     1876
     1877        ret = sscanf(line, "%llu#%d#%"SCNu16"", &newnode->transponderid, &newnode->serviceid, &newnode->subtitlepid);
     1878        if(ret != 12)
     1879        {
     1880                if(count > 0)
     1881                {
     1882                        err("lastsubtitle line %d not ok", count);
     1883                }
     1884                else
     1885                {
     1886                        err("add lastsubtitle");
     1887                }
     1888                free(newnode);
     1889                return NULL;
     1890        }
     1891
     1892        status.writelastsubtitle = 1;
     1893       
     1894        if(last == NULL)
     1895        {
     1896                while(node != NULL)
     1897                {
     1898                        prev = node;
     1899                        node = node->next;
     1900                }
     1901        }
     1902        else
     1903        {
     1904                prev = last;
     1905                node = last->next;
     1906        }
     1907
     1908        if(prev == NULL)
     1909                lastsubtitle = newnode;
     1910        else
     1911                prev->next = newnode;
     1912        newnode->next = node;
     1913
     1914        //debug(1000, "out");
     1915        return newnode;
     1916}
     1917
     1918int readlastsubtitle(const char* filename)
     1919{
     1920        debug(1000, "in");
     1921        FILE *fd = NULL;
     1922        char *fileline = NULL;
     1923        int linecount = 0, len = 0;
     1924        struct lastsubtitle* last = NULL, *tmplast = NULL;
     1925
     1926        fileline = malloc(MINMALLOC);
     1927        if(fileline == NULL)
     1928        {
     1929                err("no memory");
     1930                return 1;
     1931        }
     1932
     1933        fd = fopen(filename, "r");
     1934        if(fd == NULL)
     1935        {
     1936                perr("can't open %s", filename);
     1937                free(fileline);
     1938                return 1;
     1939        }
     1940
     1941        while(fgets(fileline, MINMALLOC, fd) != NULL)
     1942        {
     1943                if(fileline[0] == '#' || fileline[0] == '\n')
     1944                        continue;
     1945                len = strlen(fileline) - 1;
     1946                if(len >= 0 && fileline[len] == '\n')
     1947                        fileline[len] = '\0';
     1948                len--;
     1949                if(len >= 0 && fileline[len] == '\r')
     1950                        fileline[len] = '\0';
     1951
     1952                linecount++;
     1953               
     1954                if(last == NULL) last = tmplast;
     1955                last = addlastsubtitle(fileline, linecount, last);
     1956                if(last != NULL) tmplast = last;
     1957        }
     1958
     1959        status.writelastsubtitle = 0;
     1960        free(fileline);
     1961        fclose(fd);
     1962        return 0;
     1963}
     1964
     1965void dellastsubtitle(struct lastsubtitle* lsnode)
     1966{
     1967        debug(1000, "in");
     1968        struct lastsubtitle *node = lastsubtitle, *prev = lastsubtitle;
     1969
     1970        while(node != NULL)
     1971        {
     1972                if(node == lsnode)
     1973                {
     1974                        status.writetransponder = 1;
     1975                        if(node == lastsubtitle)
     1976                                lastsubtitle = node->next;
     1977                        else
     1978                                prev->next = node->next;
     1979
     1980                        free(node);
     1981                        node = NULL;
     1982                        break;
     1983                }
     1984
     1985                prev = node;
     1986                node = node->next;
     1987        }
     1988        debug(1000, "out");
     1989}
     1990
     1991void freelastsubtitle()
     1992{
     1993        debug(1000, "in");
     1994        struct lastsubtitle *node = lastsubtitle, *prev = lastsubtitle;
     1995
     1996        while(node != NULL)
     1997        {
     1998                prev = node;
     1999                node = node->next;
     2000                if(prev != NULL)
     2001                        dellastsubtitle(prev);
     2002        }
     2003        debug(1000, "out");
     2004}
     2005
     2006int writelastsubtitle(const char *filename)
     2007{
     2008        debug(1000, "in");
     2009        FILE *fd = NULL;
     2010        struct lastsubtitle *node = lastsubtitle;
     2011        int ret = 0;
     2012
     2013        fd = fopen(filename, "w");
     2014        if(fd == NULL)
     2015        {
     2016                perr("can't open %s", filename);
     2017                return 1;
     2018        }
     2019
     2020        while(node != NULL)
     2021        {
     2022                ret = fprintf(fd, "%llu#%d#%d\n", node->transponderid, node->serviceid, node->subtitlepid);
     2023                if(ret < 0)
     2024                {
     2025                        perr("writting file %s", filename);
     2026                }
     2027                node = node->next;
     2028        }
     2029
     2030        fclose(fd);
     2031        debug(1000, "out");
     2032        return 0;
     2033}
     2034
     2035//TODO:
     2036/*
     2037add writelastsubtitle to global write
     2038add readlastsubtitle to titan.c
     2039add freelastsubtitle to titan.c
     2040add subtitlestartlast to service (end) with config (status.autosubtitle == 1)
     2041*/
     2042
    17752043#endif
  • titan/titan/titan.c

    r20211 r20233  
    5353struct extepgchannel* extepgchannel = NULL;
    5454struct extepgconfig* extepgconfig = NULL;
     55struct lastsubtitle* lastsubtitle = NULL;
    5556
    5657#ifdef SH4
Note: See TracChangeset for help on using the changeset viewer.