summaryrefslogtreecommitdiff
authorke.gong <ke.gong@amlogic.com>2012-08-10 05:51:29 (GMT)
committer ke.gong <ke.gong@amlogic.com>2012-08-10 05:51:29 (GMT)
commit623d50089561d4db65ddbe7643e8b1a4f63585e1 (patch)
treea3a8077cd75248b8eed0a3970466320836388c82
parent7b7d97b6d4d82c141b1a1942e1aed193d07bf258 (diff)
downloadlibzvbi-623d50089561d4db65ddbe7643e8b1a4f63585e1.zip
libzvbi-623d50089561d4db65ddbe7643e8b1a4f63585e1.tar.gz
libzvbi-623d50089561d4db65ddbe7643e8b1a4f63585e1.tar.bz2
add vbi_get_next_pgno
Diffstat
-rw-r--r--src/cache-priv.h12
-rw-r--r--src/cache.c76
-rw-r--r--src/libzvbi.h1
-rw-r--r--src/teletext.c49
-rw-r--r--src/teletext_decoder.h2
5 files changed, 140 insertions, 0 deletions
diff --git a/src/cache-priv.h b/src/cache-priv.h
index 2501536..a60ed37 100644
--- a/src/cache-priv.h
+++ b/src/cache-priv.h
@@ -470,6 +470,18 @@ _vbi_ttx_charset_init (const vbi_ttx_charset *charset[2],
const struct ttx_extension *ext,
const cache_page * cp);
+extern cache_page *
+_vbi_cache_find_next_page (vbi_cache * ca,
+ int dir,
+ vbi_subno pgno,
+ vbi_subno subno);
+
+extern cache_page *
+_vbi_cache_find_page (vbi_cache * ca,
+ int dir,
+ vbi_subno pgno);
+
+
#endif /* CACHE_PRIV_H */
/*
diff --git a/src/cache.c b/src/cache.c
index 19a27a7..7a82bab 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -1337,6 +1337,82 @@ _vbi_cache_get_page (vbi_cache * ca,
return cache_page_ref (cp);
}
+cache_page *
+_vbi_cache_find_next_page (vbi_cache * ca,
+ int dir,
+ vbi_subno pgno,
+ vbi_subno subno)
+{
+ struct node *hash_list;
+ cache_page *cp, *cp1, *ret = NULL;
+
+ assert (NULL != ca);
+
+ if (pgno < 0x100 || pgno > 0x8FF || 0xFF == (pgno & 0xFF)) {
+ warning (&ca->log,
+ "Invalid pgno 0x%x.", pgno);
+ return NULL;
+ }
+
+ hash_list = ca->hash + hash (pgno);
+
+ FOR_ALL_NODES (cp, cp1, hash_list, hash_node) {
+ if (cp->pgno == pgno) {
+ if(dir > 0){
+ if((cp->subno > subno) && (!ret || (ret->subno > cp->subno)))
+ ret = cp;
+ }else if(dir < 0){
+ if((cp->subno < subno) && (!ret || (ret->subno < cp->subno)))
+ ret = cp;
+ }
+ }
+ }
+
+ if(ret){
+ return cache_page_ref(ret);
+ }
+
+ return NULL;
+}
+
+cache_page *
+_vbi_cache_find_page (vbi_cache * ca,
+ int dir,
+ vbi_subno pgno)
+{
+ struct node *hash_list;
+ cache_page *cp, *cp1, *ret = NULL;
+
+ assert (NULL != ca);
+
+ if (pgno < 0x100 || pgno > 0x8FF || 0xFF == (pgno & 0xFF)) {
+ warning (&ca->log,
+ "Invalid pgno 0x%x.", pgno);
+ return NULL;
+ }
+
+ hash_list = ca->hash + hash (pgno);
+
+ FOR_ALL_NODES (cp, cp1, hash_list, hash_node) {
+ if (cp->pgno == pgno) {
+ if(dir > 0){
+ if(!ret || (ret->subno > cp->subno))
+ ret = cp;
+ }else if(dir < 0){
+ if(!ret || (ret->subno < cp->subno))
+ ret = cp;
+ }
+ }
+ }
+
+ if(ret){
+ return cache_page_ref(ret);
+ }
+
+ return NULL;
+
+}
+
/**
* @internal
* For vbi_search.
diff --git a/src/libzvbi.h b/src/libzvbi.h
index fa422db..28c3dc7 100644
--- a/src/libzvbi.h
+++ b/src/libzvbi.h
@@ -1836,6 +1836,7 @@ extern void vbi_resolve_link(vbi_page *pg, int column, int row,
vbi_link *ld);
extern void vbi_resolve_home(vbi_page *pg, vbi_link *ld);
+extern vbi_bool vbi_get_next_pgno(vbi_decoder *vbi, int dir, vbi_pgno *pgno, vbi_pgno *subno);
/* tables.h */
diff --git a/src/teletext.c b/src/teletext.c
index f9165a9..803cf5f 100644
--- a/src/teletext.c
+++ b/src/teletext.c
@@ -2872,6 +2872,55 @@ vbi_fetch_vt_page(vbi_decoder *vbi, vbi_page *pg,
}
}
+vbi_bool
+vbi_get_next_pgno(vbi_decoder *vbi, int dir, vbi_pgno *pgno, vbi_pgno *subno)
+{
+ cache_page *vtp;
+ vbi_pgno pg, sub;
+
+ assert(pgno && subno && (pgno>0x899 || pgno < 0x100));
+
+ pg = *pgno;
+ sub = *subno;
+
+ vtp = _vbi_cache_find_next_page (vbi->ca, dir, pg, sub);
+
+ if (!vtp) {
+ int start, no;
+
+ start = no = vbi_bcd2dec(pg);
+
+ if(dir > 0){
+ do{
+ no++;
+ if(no > 899)
+ no = 0;
+ vtp = _vbi_cache_find_page(vbi->ca, dir, vbi_dec2bcd(no));
+ if(vtp)
+ break;
+ }while(no != start);
+ }else if(dir < 0){
+ do {
+ no--;
+ if(no < 100)
+ no = 899;
+ vtp = _vbi_cache_find_page(vbi->ca, dir, vbi_dec2bcd(no));
+ if(vtp)
+ break;
+ }while(no != start);
+ }
+ }
+
+ if(vtp) {
+ *pgno = vtp->pgno;
+ *subno = vtp->subno;
+ cache_page_unref (vtp);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
/*
Local variables:
c-set-style: K&R
diff --git a/src/teletext_decoder.h b/src/teletext_decoder.h
index aa06bf4..f31548f 100644
--- a/src/teletext_decoder.h
+++ b/src/teletext_decoder.h
@@ -119,6 +119,8 @@ extern vbi_bool vbi_format_vt_page(vbi_decoder *, vbi_page *,
int display_rows,
vbi_bool navigation);
+extern vbi_bool vbi_get_next_pgno(vbi_decoder *vbi, int dir, vbi_pgno *pgno, vbi_pgno *subno);
+
#endif
/*