summaryrefslogtreecommitdiff
authorkui.zhang <kui.zhang@amlogic.com>2012-08-31 05:14:15 (GMT)
committer kui.zhang <kui.zhang@amlogic.com>2012-08-31 05:14:15 (GMT)
commit13ab269d1919746ee585c4d1ab07b4efb274025e (patch)
tree093e860b1e3c0ba0c7d7efd78c7c9b5f54c747f8
parent98f70a46069f264252818af6e7699959dca090f6 (diff)
downloadlibzvbi-13ab269d1919746ee585c4d1ab07b4efb274025e.zip
libzvbi-13ab269d1919746ee585c4d1ab07b4efb274025e.tar.gz
libzvbi-13ab269d1919746ee585c4d1ab07b4efb274025e.tar.bz2
add ntsc decode
Diffstat
-rwxr-xr-x[-rw-r--r--]Android.mk2
-rwxr-xr-xntsc_decode/Android.mk15
-rwxr-xr-xntsc_decode/decode.c1415
-rwxr-xr-x[-rw-r--r--]ntsc_decode/sliced1.c (copied from test/sliced.c)156
-rwxr-xr-x[-rw-r--r--]ntsc_decode/sliced1.h (copied from test/sliced.h)14
-rwxr-xr-x[-rw-r--r--]src/xds_demux.c57
-rwxr-xr-x[-rw-r--r--]test/sliced1.c (renamed from test/sliced.c)0
-rwxr-xr-x[-rw-r--r--]test/sliced1.h (renamed from test/sliced.h)0
8 files changed, 1585 insertions, 74 deletions
diff --git a/Android.mk b/Android.mk
index df10b2c..ca4b78b 100644..100755
--- a/Android.mk
+++ b/Android.mk
@@ -7,7 +7,7 @@ LOCAL_SRC_FILES := src/bit_slicer.c src/cache.c src/caption.c src/conv.c src/dvb
src/exp-templ.c src/exp-txt.c src/exp-vtx.c src/exp-gfx.c src/export.c src/hamm.c src/idl_demux.c src/io.c src/io-bktr.c src/io-dvb.c \
src/io-sim.c src/io-v4l.c src/io-v4l2.c src/io-v4l2k.c src/lang.c src/misc.c src/packet.c src/teletext.c src/page_table.c \
src/pfc_demux.c src/proxy-client.c src/raw_decoder.c src/sampling_par.c src/search.c src/ure.c src/sliced_filter.c \
- src/tables.c src/trigger.c src/vbi.c src/vps.c src/wss.c src/xds_demux.c src/decoder.c src/dtvcc.c
+ src/tables.c src/trigger.c src/vbi.c src/vps.c src/wss.c src/xds_demux.c src/decoder.c src/dtvcc.c
LOCAL_CFLAGS+=-D_REENTRANT -D_GNU_SOURCE -DENABLE_DVB=1 -DENABLE_V4L=1 -DENABLE_V4L2=1 -DHAVE_ICONV=1 -DPACKAGE=\"zvbi\" -DVERSION=\"0.2.33\" -DANDROID
LOCAL_ARM_MODE := arm
diff --git a/ntsc_decode/Android.mk b/ntsc_decode/Android.mk
new file mode 100755
index 0000000..07effe5
--- a/dev/null
+++ b/ntsc_decode/Android.mk
@@ -0,0 +1,15 @@
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES:=decode.c sliced1.c
+LOCAL_SHARED_LIBRARIES+= libzvbi
+
+LOCAL_C_INCLUDES:=$(LOCAL_PATH)/../src \
+ $(LOCAL_PATH)/
+
+LOCAL_MODULE:= xds_decode
+LOCAL_MODULE_TAGS := optional
+LOCAL_ARM_MODE := arm
+LOCAL_CFLAGS+=-D_REENTRANT -D_GNU_SOURCE -DENABLE_DVB=1 -DENABLE_V4L=1 -DENABLE_V4L2=1 -DHAVE_ICONV=1 -DPACKAGE=\"zvbi\" -DVERSION=\"0.2.33\" -DANDROID -DHAVE_GETOPT_LONG=1
+LOCAL_SHARED_LIBRARIES += libicuuc liblog
+include $(BUILD_EXECUTABLE)
diff --git a/ntsc_decode/decode.c b/ntsc_decode/decode.c
new file mode 100755
index 0000000..7cfff30
--- a/dev/null
+++ b/ntsc_decode/decode.c
@@ -0,0 +1,1415 @@
+ /*
+ * zvbi-decode -- Decode sliced VBI data using low-level
+ * libzvbi functions
+ *
+ * Copyright (C) 2004, 2006, 2007 Michael H. Schimek
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+/* $Id: decode.c,v 1.32 2008/03/01 07:36:59 mschimek Exp $ */
+
+/* For libzvbi version 0.2.x / 0.3.x. */
+
+#undef NDEBUG
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <locale.h>
+#include <assert.h>
+#include <unistd.h>
+#include <errno.h>
+#include <time.h>
+#ifdef HAVE_GETOPT_LONG
+# include <getopt.h>
+#endif
+
+#include "version.h"
+#if 2 == VBI_VERSION_MINOR
+# include "bcd.h"
+# include "conv.h"
+# include "pfc_demux.h"
+# include "dvb_demux.h"
+# include "idl_demux.h"
+# include "xds_demux.h"
+# include "vps.h"
+# include "hamm.h"
+# include "lang.h"
+#elif 3 == VBI_VERSION_MINOR
+# include "zvbi.h"
+# include "misc.h" /* _vbi_to_ascii() */
+#else
+# error VBI_VERSION_MINOR == ?
+#endif
+
+#include "sliced.h"
+#include "sliced1.h"
+
+#undef _
+#define _(x) x /* i18n TODO */
+
+/* Will be installed one day. */
+#define PROGRAM_NAME "zvbi-decode"
+
+static const char * option_in_file_name;
+static enum file_format option_in_file_format;
+static unsigned int option_in_ts_pid;
+
+static vbi_pgno option_pfc_pgno;
+static unsigned int option_pfc_stream;
+
+static vbi_bool option_decode_ttx;
+static vbi_bool option_decode_8301;
+static vbi_bool option_decode_8302;
+static vbi_bool option_decode_caption;
+static vbi_bool option_decode_xds;
+static vbi_bool option_decode_idl;
+static vbi_bool option_decode_vps;
+static vbi_bool option_decode_vps_other;
+static vbi_bool option_decode_wss;
+
+static vbi_bool option_dump_network;
+static vbi_bool option_dump_hex;
+static vbi_bool option_dump_bin;
+static vbi_bool option_dump_time;
+static double option_metronome_tick;
+
+static vbi_pgno option_pfc_pgno = 0;
+static unsigned int option_pfc_stream = 0;
+
+static unsigned int option_idl_channel = 0;
+static unsigned int option_idl_address = 0;
+
+static struct stream * rst;
+
+static vbi_pfc_demux * pfc;
+static vbi_idl_demux * idl;
+static vbi_xds_demux * xds;
+
+extern void
+_vbi_pfc_block_dump (const vbi_pfc_block * pb,
+ FILE * fp,
+ vbi_bool binary);
+
+static void
+put_cc_char (unsigned int c1,
+ unsigned int c2)
+{
+ uint16_t ucs2_str[1];
+
+ /* All caption characters are representable
+ in UTF-8, but not necessarily in ASCII. */
+ ucs2_str[0] = vbi_caption_unicode ((c1 * 256 + c2) & 0x777F,
+ /* to_upper */ FALSE);
+
+ vbi_fputs_iconv_ucs2 (stdout,
+ vbi_locale_codeset (),
+ ucs2_str, 1,
+ /* repl_char */ '?');
+}
+
+static void
+caption_command (unsigned int line,
+ unsigned int c1,
+ unsigned int c2)
+{
+ unsigned int ch;
+ unsigned int a7;
+ unsigned int f;
+ unsigned int b7;
+ unsigned int u;
+
+ printf ("CC line=%3u cmd 0x%02x 0x%02x ", line, c1, c2);
+
+ if (0 == c1) {
+ printf ("null\n");
+ return;
+ } else if (c2 < 0x20) {
+ printf ("invalid\n");
+ return;
+ }
+
+ /* Some common bit groups. */
+
+ ch = (c1 >> 3) & 1; /* channel */
+ a7 = c1 & 7;
+ f = c1 & 1; /* field */
+ b7 = (c2 >> 1) & 7;
+ u = c2 & 1; /* underline */
+
+ if (c2 >= 0x40) {
+ static const int row [16] = {
+ /* 0 */ 10, /* 0x1040 */
+ /* 1 */ -1, /* unassigned */
+ /* 2 */ 0, 1, 2, 3, /* 0x1140 ... 0x1260 */
+ /* 6 */ 11, 12, 13, 14, /* 0x1340 ... 0x1460 */
+ /* 10 */ 4, 5, 6, 7, 8, 9 /* 0x1540 ... 0x1760 */
+ };
+ unsigned int rrrr;
+
+ /* Preamble Address Codes -- 001 crrr 1ri bbbu */
+
+ rrrr = a7 * 2 + ((c2 >> 5) & 1);
+
+ if (c2 & 0x10)
+ printf ("PAC ch=%u row=%d column=%u u=%u\n",
+ ch, row[rrrr], b7 * 4, u);
+ else
+ printf ("PAC ch=%u row=%d color=%u u=%u\n",
+ ch, row[rrrr], b7, u);
+ return;
+ }
+
+ /* Control codes -- 001 caaa 01x bbbu */
+
+ switch (a7) {
+ case 0:
+ if (c2 < 0x30) {
+ const char *mnemo [16] = {
+ "BWO", "BWS", "BGO", "BGS",
+ "BBO", "BBS", "BCO", "BCS",
+ "BRO", "BRS", "BYO", "BYS",
+ "BMO", "BMS", "BAO", "BAS"
+ };
+
+ printf ("%s ch=%u\n", mnemo[c2 & 0xF], ch);
+ return;
+ }
+
+ break;
+
+ case 1:
+ if (c2 < 0x30) {
+ printf ("mid-row ch=%u color=%u u=%u\n", ch, b7, u);
+ } else {
+ printf ("special character ch=%u 0x%02x%02x='",
+ ch, c1, c2);
+ put_cc_char (c1, c2);
+ puts ("'");
+ }
+
+ return;
+
+ case 2: /* first group */
+ case 3: /* second group */
+ printf ("extended character ch=%u 0x%02x%02x='", ch, c1, c2);
+ put_cc_char (c1, c2);
+ puts ("'");
+ return;
+
+ case 4: /* f=0 */
+ case 5: /* f=1 */
+ if (c2 < 0x30) {
+ const char *mnemo [16] = {
+ "RCL", "BS", "AOF", "AON",
+ "DER", "RU2", "RU3", "RU4",
+ "FON", "RDC", "TR", "RTD",
+ "EDM", "CR", "ENM", "EOC"
+ };
+
+ printf ("%s ch=%u f=%u\n", mnemo[c2 & 0xF], ch, f);
+ return;
+ }
+
+ break;
+
+ case 6:
+ printf ("reserved\n");
+ return;
+
+ case 7:
+ switch (c2) {
+ case 0x21 ... 0x23:
+ printf ("TO%u ch=%u\n", c2 - 0x20, ch);
+ return;
+
+ case 0x2D:
+ printf ("BT ch=%u\n", ch);
+ return;
+
+ case 0x2E:
+ printf ("FA ch=%u\n", ch);
+ return;
+
+ case 0x2F:
+ printf ("FAU ch=%u\n", ch);
+ return;
+
+ default:
+ break;
+ }
+
+ break;
+ }
+
+ printf ("unknown\n");
+}
+
+static vbi_bool
+xds_cb (vbi_xds_demux * xd,
+ const vbi_xds_packet * xp,
+ void * user_data)
+{
+ xd = xd; /* unused */
+ user_data = user_data;
+ printf("************xds_cb**********\n");
+ vbi_program_info *pi;
+ _vbi_xds_packet_dump (xp, stdout);
+
+ return TRUE; /* no errors */
+}
+
+static void
+caption ( uint8_t buffer[4],
+ unsigned int line)
+{
+
+ if (option_decode_xds && 284== line) {
+ int c1;
+ int c2;
+ /*c1 = buffer[0];//vbi_unpar8 (buffer[0]);
+ c2 = buffer[1];//vbi_unpar8 (buffer[1]);
+
+ //switch (c1) {
+ case 0x00:
+ //* Stuffing.
+ break;
+ case 0x01 ... 0x0E:
+ printf("line is 284 is %d %d\n",buffer[2],buffer[3]);
+ xds->subpacket[c1][c2].count = buffer[0] + buffer[1];
+ xds->subpacket[c1][c2].buffer[0] = buffer[2];
+ xds->subpacket[c1][c2].buffer[1] = buffer[3];
+ break;
+ case 0x0F:
+ //* Packet terminator.
+ break;
+ }*/
+ if (!vbi_xds_demux_feed (xds, buffer)) {
+ printf ("Parity error in XDS data.\n");
+ }
+ }
+
+ if (option_decode_caption
+ && (21 == line || 284 == line /* NTSC */
+ || 22 == line /* PAL? */)) {
+ int c1;
+ int c2;
+
+ c1 = buffer[0];//vbi_unpar8 (buffer[0]);
+ c2 = buffer[1];//vbi_unpar8 (buffer[1]);
+
+
+
+ if ((c1 | c2) < 0) {
+ printf ("Parity error in CC line=%u "
+ " %s0x%02x %s0x%02x.\n",
+ line,
+ (c1 < 0) ? ">" : "", buffer[0] & 0xFF,
+ (c2 < 0) ? ">" : "", buffer[1] & 0xFF);
+ } else if (c1 >= 0x20) {
+ char text[2];
+
+ printf ("CC line=%3u text 0x%02x 0x%02x '",
+ line, c1, c2);
+
+ /* All caption characters are representable
+ in UTF-8, but not necessarily in ASCII. */
+ text[0] = c1;
+ text[1] = c2; /* may be zero */
+
+ /* Error ignored. */
+ vbi_fputs_iconv (stdout,
+ /* dst_codeset */
+ vbi_locale_codeset (),
+ /* src_codeset */ "EIA-608",
+ text, 2,
+ /* repl_char */ '?');
+
+ puts ("'");
+ } else if (0 == c1 || c1 >= 0x10) {
+ caption_command (line, c1, c2);
+ } else if (option_decode_xds) {
+ printf ("CC line=%3u cmd 0x%02x 0x%02x ",
+ line, c1, c2);
+ if (0x0F == c1)
+ puts ("XDS packet end");
+ else
+ puts ("XDS packet start/continue");
+ }
+ }
+}
+
+#if 3 == VBI_VERSION_MINOR /* XXX port me back */
+
+static void
+dump_cni (vbi_cni_type type,
+ unsigned int cni)
+{
+ vbi_network nk;
+ vbi_bool success;
+
+ if (!option_dump_network)
+ return;
+
+ success = vbi_network_init (&nk);
+ if (!success)
+ no_mem_exit ();
+
+ success = vbi_network_set_cni (&nk, type, cni);
+ if (!success)
+ no_mem_exit ();
+
+ _vbi_network_dump (&nk, stdout);
+ putchar ('\n');
+
+ vbi_network_destroy (&nk);
+}
+
+#endif /* 3 == VBI_VERSION_MINOR */
+
+static void
+dump_bytes (const uint8_t * buffer,
+ unsigned int n_bytes)
+{
+ unsigned int j;
+
+ if (option_dump_bin) {
+ fwrite (buffer, 1, n_bytes, stdout);
+ return;
+ }
+
+ if (option_dump_hex) {
+ for (j = 0; j < n_bytes; ++j)
+ printf ("%02x ", buffer[j]);
+ }
+
+ putchar ('>');
+
+ for (j = 0; j < n_bytes; ++j) {
+ /* Not all Teletext characters are representable
+ in ASCII or even UTF-8, but at this stage we don't
+ know the Teletext code page for a proper conversion. */
+ char c = _vbi_to_ascii (buffer[j]);
+
+ putchar (c);
+ }
+
+ puts ("<");
+}
+
+#if 3 == VBI_VERSION_MINOR /* XXX port me back */
+
+static void
+packet_8301 (const uint8_t buffer[42],
+ unsigned int designation)
+{
+ unsigned int cni;
+ time_t time;
+ int gmtoff;
+ struct tm tm;
+
+ if (!option_decode_8301)
+ return;
+
+ if (!vbi_decode_teletext_8301_cni (&cni, buffer)) {
+ printf ("Error in Teletext "
+ "packet 8/30 format 1 CNI.\n");
+ return;
+ }
+
+ if (!vbi_decode_teletext_8301_local_time (&time, &gmtoff, buffer)) {
+ printf ("Error in Teletext "
+ "packet 8/30 format 1 local time.\n");
+ return;
+ }
+
+ printf ("Teletext packet 8/30/%u cni=%x time=%u gmtoff=%d ",
+ designation, cni, (unsigned int) time, gmtoff);
+
+ gmtime_r (&time, &tm);
+
+ printf ("(%4u-%02u-%02u %02u:%02u:%02u UTC)\n",
+ tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
+ tm.tm_hour, tm.tm_min, tm.tm_sec);
+
+ if (0 != cni)
+ dump_cni (VBI_CNI_TYPE_8301, cni);
+}
+
+static void
+packet_8302 (const uint8_t buffer[42],
+ unsigned int designation)
+{
+ unsigned int cni;
+ vbi_program_id pi;
+
+ if (!option_decode_8302)
+ return;
+
+ if (!vbi_decode_teletext_8302_cni (&cni, buffer)) {
+ printf ("Error in Teletext "
+ "packet 8/30 format 2 CNI.\n");
+ return;
+ }
+
+ if (!vbi_decode_teletext_8302_pdc (&pi, buffer)) {
+ printf ("Error in Teletext "
+ "packet 8/30 format 2 PDC data.\n");
+ return;
+ }
+
+ printf ("Teletext packet 8/30/%u cni=%x ", designation, cni);
+
+ _vbi_program_id_dump (&pi, stdout);
+
+ putchar ('\n');
+
+ if (0 != pi.cni)
+ dump_cni (pi.cni_type, pi.cni);
+}
+
+#endif /* 3 == VBI_VERSION_MINOR */
+
+static vbi_bool
+page_function_clear_cb (vbi_pfc_demux * dx,
+ void * user_data,
+ const vbi_pfc_block * block)
+{
+ dx = dx; /* unused */
+ user_data = user_data;
+
+ _vbi_pfc_block_dump (block, stdout, option_dump_bin);
+
+ return TRUE;
+}
+
+static vbi_bool
+idl_format_a_cb (vbi_idl_demux * idl,
+ const uint8_t * buffer,
+ unsigned int n_bytes,
+ unsigned int flags,
+ void * user_data)
+{
+ idl = idl;
+ user_data = user_data;
+
+ if (!option_dump_bin) {
+ printf ("IDL-A%s%s ",
+ (flags & VBI_IDL_DATA_LOST) ? " <data lost>" : "",
+ (flags & VBI_IDL_DEPENDENT) ? " <dependent>" : "");
+ }
+
+ dump_bytes (buffer, n_bytes);
+
+ return TRUE;
+}
+
+static void
+packet_idl (const uint8_t buffer[42],
+ unsigned int channel)
+{
+ int pa; /* packet address */
+ int ft; /* format type */
+
+ printf ("IDL ch=%u ", channel);
+
+ switch (channel) {
+ case 0:
+ assert (0);
+
+ case 4:
+ case 12:
+ printf ("(Low bit rate audio) ");
+
+ dump_bytes (buffer, 42);
+
+ break;
+
+ case 5:
+ case 6:
+ case 13:
+ case 14:
+ pa = vbi_unham8 (buffer[3]);
+ pa |= vbi_unham8 (buffer[4]) << 4;
+ pa |= vbi_unham8 (buffer[5]) << 8;
+
+ if (pa < 0) {
+ printf ("Hamming error in Datavideo "
+ "packet-address byte.\n");
+ return;
+ }
+
+ printf ("(Datavideo) pa=0x%x ", pa);
+
+ dump_bytes (buffer, 42);
+
+ break;
+
+ case 8:
+ case 9:
+ case 10:
+ case 11:
+ case 15:
+ ft = vbi_unham8 (buffer[2]);
+ if (ft < 0) {
+ printf ("Hamming error in IDL format "
+ "A or B format-type byte.\n");
+ return;
+ }
+
+ if (0 == (ft & 1)) {
+ int ial; /* interpretation and address length */
+ unsigned int spa_length;
+ int spa; /* service packet address */
+ unsigned int i;
+
+ ial = vbi_unham8 (buffer[3]);
+ if (ial < 0) {
+ printf ("Hamming error in IDL format "
+ "A interpretation-and-address-"
+ "length byte.\n");
+ return;
+ }
+
+ spa_length = (unsigned int) ial & 7;
+ if (7 == spa_length) {
+ printf ("(Format A?) ");
+ dump_bytes (buffer, 42);
+ return;
+ }
+
+ spa = 0;
+
+ for (i = 0; i < spa_length; ++i)
+ spa |= vbi_unham8 (buffer[4 + i]) << (4 * i);
+
+ if (spa < 0) {
+ printf ("Hamming error in IDL format "
+ "A service-packet-address byte.\n");
+ return;
+ }
+
+ printf ("(Format A) spa=0x%x ", spa);
+ } else if (1 == (ft & 3)) {
+ int an; /* application number */
+ int ai; /* application identifier */
+
+ an = (ft >> 2);
+
+ ai = vbi_unham8 (buffer[3]);
+ if (ai < 0) {
+ printf ("Hamming error in IDL format "
+ "B application-number byte.\n");
+ return;
+ }
+
+ printf ("(Format B) an=%d ai=%d ", an, ai);
+ }
+
+ dump_bytes (buffer, 42);
+
+ break;
+
+ default:
+ dump_bytes (buffer, 42);
+
+ break;
+ }
+}
+
+static void
+teletext (const uint8_t buffer[42],
+ unsigned int line)
+{
+ int pmag;
+ unsigned int magazine;
+ unsigned int packet;
+
+ if (NULL != pfc) {
+ if (!vbi_pfc_demux_feed (pfc, buffer)) {
+ printf ("Error in Teletext "
+ "PFC packet.\n");
+ return;
+ }
+ }
+
+ if (NULL != idl) {
+ if (!vbi_idl_demux_feed (idl, buffer)) {
+ printf ("Error in Teletext "
+ "IDL packet.\n");
+ return;
+ }
+ }
+
+ if (!(option_decode_ttx |
+ option_decode_8301 |
+ option_decode_8302 |
+ option_decode_idl))
+ return;
+
+ pmag = vbi_unham16p (buffer);
+ if (pmag < 0) {
+ printf ("Hamming error in Teletext "
+ "packet number.\n");
+ return;
+ }
+
+ magazine = pmag & 7;
+ if (0 == magazine)
+ magazine = 8;
+
+ packet = pmag >> 3;
+
+ if (8 == magazine && 30 == packet) {
+ int designation;
+
+ designation = vbi_unham8 (buffer[2]);
+ if (designation < 0 ) {
+ printf ("Hamming error in Teletext "
+ "packet 8/30 designation byte.\n");
+ return;
+ }
+
+ if (designation >= 0 && designation <= 1) {
+#if 3 == VBI_VERSION_MINOR /* XXX port me back */
+ packet_8301 (buffer, designation);
+#endif
+ return;
+ }
+
+ if (designation >= 2 && designation <= 3) {
+#if 3 == VBI_VERSION_MINOR /* XXX port me back */
+ packet_8302 (buffer, designation);
+#endif
+ return;
+ }
+ }
+
+ if (30 == packet || 31 == packet) {
+ if (option_decode_idl) {
+#if 1
+ packet_idl (buffer, pmag & 15);
+#else
+ printf ("Teletext IDL packet %u/%2u ",
+ magazine, packet);
+ dump_bytes (buffer, /* n_bytes */ 42);
+#endif
+ return;
+ }
+ }
+
+ if (option_decode_ttx) {
+ printf ("Teletext line=%3u %x/%2u ",
+ line, magazine, packet);
+ dump_bytes (buffer, /* n_bytes */ 42);
+ return;
+ }
+}
+
+static void
+vps (const uint8_t buffer[13],
+ unsigned int line)
+{
+ if (option_decode_vps) {
+ unsigned int cni;
+#if 3 == VBI_VERSION_MINOR
+ vbi_program_id pi;
+#endif
+ if (option_dump_bin) {
+ printf ("VPS line=%3u ", line);
+ fwrite (buffer, 1, 13, stdout);
+ fflush (stdout);
+ return;
+ }
+
+ if (!vbi_decode_vps_cni (&cni, buffer)) {
+ printf ("Error in VPS packet CNI.\n");
+ return;
+ }
+
+#if 3 == VBI_VERSION_MINOR
+ if (!vbi_decode_vps_pdc (&pi, buffer)) {
+ printf ("Error in VPS packet PDC data.\n");
+ return;
+ }
+
+ printf ("VPS line=%3u ", line);
+
+ _vbi_program_id_dump (&pi, stdout);
+
+ putchar ('\n');
+
+ if (0 != pi.cni)
+ dump_cni (pi.cni_type, pi.cni);
+#else
+ printf ("VPS line=%3u CNI=%x\n", line, cni);
+#endif
+ }
+
+ if (option_decode_vps_other) {
+ static char pr_label[2][20];
+ static char label[2][20];
+ static int l[2] = { 0, 0 };
+ unsigned int i;
+ int c;
+
+ i = (line != 16);
+
+ c = vbi_rev8 (buffer[1]);
+
+ if (c & 0x80) {
+ label[i][l[i]] = 0;
+ strcpy (pr_label[i], label[i]);
+ l[i] = 0;
+ }
+
+ label[i][l[i]] = _vbi_to_ascii (c);
+
+ l[i] = (l[i] + 1) % 16;
+
+ printf ("VPS line=%3u bytes 3-10: "
+ "%02x %02x (%02x='%c') %02x %02x "
+ "%02x %02x %02x %02x (\"%s\")\n",
+ line,
+ buffer[0], buffer[1],
+ c, _vbi_to_ascii (c),
+ buffer[2], buffer[3],
+ buffer[4], buffer[5], buffer[6], buffer[7],
+ pr_label[i]);
+ }
+}
+
+#if 3 == VBI_VERSION_MINOR /* XXX port me back */
+
+static void
+wss_625 (const uint8_t buffer[2])
+{
+ if (option_decode_wss) {
+ vbi_aspect_ratio ar;
+
+ if (!vbi_decode_wss_625 (&ar, buffer)) {
+ printf ("Error in WSS packet.\n");
+ return;
+ }
+
+ fputs ("WSS ", stdout);
+
+ _vbi_aspect_ratio_dump (&ar, stdout);
+
+ putchar ('\n');
+ }
+}
+
+#endif /* 3 == VBI_VERSION_MINOR */
+
+static vbi_bool
+decode_frame ( vbi_sliced * s,
+ unsigned int n_lines,
+ const uint8_t * raw,
+ const vbi_sampling_par *sp,
+ double sample_time,
+ int64_t stream_time)
+{
+ printf("decode_frame\n");
+ static double metronome = 0.0;
+ static double last_sample_time = 0.0;
+ static int64_t last_stream_time = 0;
+
+ raw = raw; /* unused */
+ sp = sp;
+
+ if (option_dump_time || option_metronome_tick > 0.0) {
+ /* Sample time: When we captured the data, in
+ seconds since 1970-01-01 (gettimeofday()).
+ Stream time: For ATSC/DVB the Presentation Time Stamp.
+ For analog the frame number multiplied by
+ the nominal frame period (1/25 or
+ 1001/30000 s). Both given in 90 kHz units.
+ Note this isn't fully implemented yet. */
+
+ if (option_metronome_tick > 0.0) {
+ printf ("ST %f (adv %+f, err %+f) PTS %"
+ PRId64 " (adv %+" PRId64 ", err %+f)\n",
+ sample_time, sample_time - last_sample_time,
+ sample_time - metronome,
+ stream_time, stream_time - last_stream_time,
+ (double) stream_time - metronome);
+
+ metronome += option_metronome_tick;
+ } else {
+ printf ("ST %f (%+f) PTS %" PRId64 " (%+" PRId64 ")\n",
+ sample_time, sample_time - last_sample_time,
+ stream_time, stream_time - last_stream_time);
+ }
+
+ last_sample_time = sample_time;
+ last_stream_time = stream_time;
+ }
+ printf("decode_frame while\n");
+ static int i =0;
+
+ //******************temp*************************//
+ //s->id = VBI_SLICED_CAPTION_525;
+ while (n_lines > 0) {
+ switch (s->id) {
+ case VBI_SLICED_TELETEXT_B_L10_625:
+ case VBI_SLICED_TELETEXT_B_L25_625:
+ case VBI_SLICED_TELETEXT_B_625:
+ teletext (s->data, s->line);
+ break;
+
+ case VBI_SLICED_VPS:
+ case VBI_SLICED_VPS_F2:
+ vps (s->data, s->line);
+ break;
+
+ case VBI_SLICED_CAPTION_625_F1:
+ case VBI_SLICED_CAPTION_625_F2:
+ case VBI_SLICED_CAPTION_625:
+ case VBI_SLICED_CAPTION_525_F1:
+ case VBI_SLICED_CAPTION_525_F2:
+ case VBI_SLICED_CAPTION_525:
+ //******************************************************************//
+ //printf("decode_frame VBI_SLICED_CAPTION_525\n");
+ caption (s->data, s->line);
+ //******************************************************************//
+ break;
+
+ case VBI_SLICED_WSS_625:
+#if 3 == VBI_VERSION_MINOR /* XXX port me back */
+ wss_625 (s->data);
+#endif
+ break;
+
+ case VBI_SLICED_WSS_CPR1204:
+ break;
+
+
+ }
+
+ ++s;
+ --n_lines;
+ }
+
+ return TRUE;
+}
+
+static void
+usage (FILE * fp)
+{
+ /* FIXME Supposed to be localized but we can't use #ifs
+ within the _() macro. */
+ fprintf (fp, "\
+%s %s -- Low-level VBI decoder\n\n\
+Copyright (C) 2004, 2006, 2007 Michael H. Schimek\n\
+This program is licensed under GPLv2 or later. NO WARRANTIES.\n\n\
+Usage: %s [options] < sliced VBI data\n\
+-h | --help | --usage Print this message and exit\n\
+-q | --quiet Suppress progress and error messages\n\
+-V | --version Print the program version and exit\n\
+Input options:\n\
+-i | --input name Read the VBI data from this file instead of\n\
+ standard input\n\
+-P | --pes Source is a DVB PES stream\n\
+-T | --ts pid Source is a DVB TS stream\n\
+Decoding options:\n"
+#if 3 == VBI_VERSION_MINOR /* XXX port me back */
+"-1 | --8301 Teletext packet 8/30 format 1 (local time)\n\
+-2 | --8302 Teletext packet 8/30 format 2 (PDC)\n"
+#endif
+"-c | --cc Closed Caption\n\
+-j | --idl Any Teletext IDL packets (M/30, M/31)\n\
+-t | --ttx Decode any Teletext packet\n\
+-v | --vps Video Programming System (PDC)\n"
+#if 3 == VBI_VERSION_MINOR /* XXX port me back */
+"-w | --wss Wide Screen Signalling\n"
+#endif
+"-x | --xds Decode eXtended Data Service (NTSC line 284)\n\
+-a | --all Everything above, e.g.\n\
+ -i decode IDL packets\n\
+ -a decode everything\n\
+ -a -i everything except IDL\n\
+-l | --idl-ch N\n\
+-d | --idl-addr NNN Decode Teletext IDL format A data from channel N,\n\
+ service packet address NNN (default 0)\n\
+-r | --vps-other Decode VPS data unrelated to PDC\n\
+-p | --pfc-pgno NNN\n\
+-s | --pfc-stream NN Decode Teletext Page Function Clear data\n\
+ from page NNN (for example 1DF), stream NN\n\
+ (default 0)\n\
+Modifying options:\n\
+-e | --hex With -t dump packets in hex and ASCII,\n\
+ otherwise only ASCII\n\
+-n | --network With -1, -2, -v decode CNI and print\n\
+ available information about the network\n\
+-b | --bin With -t, -p, -v dump data in binary format\n\
+ instead of ASCII\n\
+-m | --time Dump capture timestamps\n\
+-M | --metronome tick Compare timestamps against a metronome advancing\n\
+ by tick seconds per frame\n\
+",
+ PROGRAM_NAME, VERSION, program_invocation_name);
+}
+
+static const char
+short_options [] = "12abcd:ehi:jl:mnp:qrs:tvwxM:PT:V";
+
+#ifdef HAVE_GETOPT_LONG
+static const struct option
+long_options [] = {
+ { "8301", no_argument, NULL, '1' },
+ { "8302", no_argument, NULL, '2' },
+ { "all", no_argument, NULL, 'a' },
+ { "bin", no_argument, NULL, 'b' },
+ { "cc", no_argument, NULL, 'c' },
+ { "idl-addr", required_argument, NULL, 'd' },
+ { "hex", no_argument, NULL, 'e' },
+ { "help", no_argument, NULL, 'h' },
+ { "usage", no_argument, NULL, 'h' },
+ { "input", required_argument, NULL, 'i' },
+ { "idl", no_argument, NULL, 'j' },
+ { "idl-ch", required_argument, NULL, 'l' },
+ { "time", no_argument, NULL, 'm' },
+ { "network", no_argument, NULL, 'n' },
+ { "pfc-pgno", required_argument, NULL, 'p' },
+ { "quiet", no_argument, NULL, 'q' },
+ { "vps-other", no_argument, NULL, 'r' },
+ { "pfc-stream", required_argument, NULL, 's' },
+ { "ttx", no_argument, NULL, 't' },
+ { "vps", no_argument, NULL, 'v' },
+ { "wss", no_argument, NULL, 'w' },
+ { "xds", no_argument, NULL, 'x' },
+ { "metronome", required_argument, NULL, 'M' },
+ { "pes", no_argument, NULL, 'P' },
+ { "ts", required_argument, NULL, 'T' },
+ { "version", no_argument, NULL, 'V' },
+ { NULL, 0, 0, 0 }
+};
+#else
+# define getopt_long(ac, av, s, l, i) getopt(ac, av, s)
+#endif
+
+static int option_index;
+
+int
+main (int argc,
+ char ** argv)
+{
+
+//*************************************************
+ /*unsigned char pBuffer [5100] ;
+ memset(pBuffer,0, 5100 ); */
+ #if defined(VBI_CC_SUPPORT)
+ typedef struct cc_data_s {
+ unsigned int vbi_type : 8; // vbi data type: us_cc, teletext,wss_625,wssj,vps....
+ unsigned int field_id : 8; // field type: 0:even; 1:odd;
+ unsigned int nbytes : 16; // data byte count: cc:two bytes; tt: depends on tt spec
+ unsigned int line_num : 16; // vbi data line number
+ unsigned char b[2]; // : 8; // cc data1
+ //unsigned int b2 : 8; // cc data2
+ } cc_data_t;
+ #endif
+
+ unsigned char pBuffer[] ={
+ 0x00,0x01,0x02,0x00,0x15,0x00,0x00,0x00,
+ 0x00,0x01,0x02,0x00,0x15,0x00,0x01,0x05,
+ 0x00,0x01,0x02,0x00,0x15,0x00,0x41,0x40,
+ 0x00,0x01,0x02,0x00,0x15,0x00,0x0f,0x6a,
+ 0x00,0x01,0x02,0x00,0x15,0x00,0x00,0x00,
+ 0x00,0x01,0x02,0x00,0x15,0x00,0x00,0x00,
+ 0x00,0x01,0x02,0x00,0x15,0x00,0x15,0x2c,
+ 0x00,0x01,0x02,0x00,0x15,0x00,0x15,0x2e,
+ 0x00,0x01,0x02,0x00,0x15,0x00,0x15,0x20,
+ 0x00,0x01,0x02,0x00,0x15,0x00,0x16,0x46,
+ 0x00,0x01,0x02,0x00,0x15,0x00,0x20,0x20,
+ 0x00,0x01,0x02,0x00,0x15,0x00,0x10,0x22,
+ 0x00,0x01,0x02,0x00,0x15,0x00,0x43,0x6c,
+ 0x00,0x01,0x02,0x00,0x15,0x00,0x6f,0x73,
+ 0x00,0x01,0x02,0x00,0x15,0x00,0x65,0x64,
+ 0x00,0x01,0x02,0x00,0x15,0x00,0x20,0x43,
+ 0x00,0x01,0x02,0x00,0x15,0x00,0x61,0x70,
+ 0x00,0x01,0x02,0x00,0x15,0x00,0x74,0x69,
+ 0x00,0x01,0x02,0x00,0x15,0x00,0x6f,0x6e ,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x2f,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x41,0x00,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x45,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x4f,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x75,0x00,
+
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x2f,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x41,0x00,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x45,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x4f,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x75,0x00,
+
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x2f,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x41,0x00,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x45,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x4f,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x75,0x00,
+
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x2f,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x41,0x00,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x45,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x4f,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x75,0x00,
+ };
+
+ unsigned char pBuffer11[] ={ 1,21,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x2f,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1c,0x29,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1d,0x6a,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x41,0x00,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x20,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x45,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x21,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x4f,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x22,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23,
+
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x23,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x55,0x00,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x1a,0x24,
+ 0x00,0x00,0x02,0x00,0x1c,0x01,0x75,0x00,
+
+ };
+
+
+ int length = N_ELEMENTS (pBuffer);
+ /*int write_len ;
+ static FILE *file_fd = NULL;
+ if(!file_fd){
+ file_fd = fopen("/mnt/sda1/111.bin", "wb+");
+ if(file_fd == NULL)
+ {
+ printf(">>> transfer_vod_fwrite(), fopen() error1111\n");
+ }
+ }
+ write_len = fwrite(pBuffer, 1, length, file_fd);
+ printf("->>> Write kankan_file, size=%d write_len =%d\n", length,write_len);
+ if(file_fd != NULL){
+ fclose(file_fd);
+ file_fd = NULL;
+ }*/
+//*************************************************
+
+
+ init_helpers (argc, argv);
+ printf("zkinit_helpers\n");
+ option_in_file_format = FILE_FORMAT_SLICED;
+
+ #ifdef HAVE_GETOPT_LONG
+ printf("HAVE_GETOPT_LONG\n");
+ #else
+ printf("NOT_HAVE_GETOPT_LONG\n");
+ #endif
+
+ printf("_HAVEFAFDAFDASFD_GETOPT_LONG\n");
+ while(FALSE) { // (;;) {
+ int c;
+ printf(" 111111111111");
+ c = getopt_long (argc, argv, short_options,
+ long_options, &option_index);
+ printf("zk%d\n",c);
+ if (-1 == c)
+ break;
+
+ switch (c) {
+ case 0: /* getopt_long() flag */
+ break;
+
+ case '1':
+ option_decode_8301 ^= TRUE;
+ break;
+
+ case '2':
+ option_decode_8302 ^= TRUE;
+ break;
+
+ case 'a':
+ option_decode_ttx = TRUE;
+ option_decode_8301 = TRUE;
+ option_decode_8302 = TRUE;
+ option_decode_caption = TRUE;
+ option_decode_idl = TRUE;
+ option_decode_vps = TRUE;
+ option_decode_wss = TRUE;
+ option_decode_xds = TRUE;
+ option_pfc_pgno = 0x1DF;
+ break;
+
+ case 'b':
+ option_dump_bin ^= TRUE;
+ break;
+
+ case 'c':
+ option_decode_caption ^= TRUE;
+ break;
+
+ case 'd':
+ assert (NULL != optarg);
+ option_idl_address = strtol (optarg, NULL, 0);
+ break;
+
+ case 'e':
+ option_dump_hex ^= TRUE;
+ break;
+
+ case 'h':
+ usage (stdout);
+ exit (EXIT_SUCCESS);
+
+ case 'i':
+ assert (NULL != optarg);
+ option_in_file_name = optarg;
+ break;
+
+ case 'j':
+ option_decode_idl ^= TRUE;
+ break;
+
+ case 'l':
+ assert (NULL != optarg);
+ option_idl_channel = strtol (optarg, NULL, 0);
+ break;
+
+ case 'm':
+ option_dump_time ^= TRUE;
+ break;
+
+ case 'n':
+ option_dump_network ^= TRUE;
+ break;
+
+ case 'p':
+ assert (NULL != optarg);
+ option_pfc_pgno = strtol (optarg, NULL, 16);
+ break;
+
+ case 'q':
+ parse_option_quiet ();
+ break;
+
+ case 'r':
+ option_decode_vps_other ^= TRUE;
+ break;
+
+ case 's':
+ assert (NULL != optarg);
+ option_pfc_stream = strtol (optarg, NULL, 0);
+ break;
+
+ case 't':
+ option_decode_ttx ^= TRUE;
+ break;
+
+ case 'v':
+ option_decode_vps ^= TRUE;
+ break;
+
+ case 'w':
+ option_decode_wss ^= TRUE;
+ break;
+
+ case 'x':
+ option_decode_xds ^= TRUE;
+ break;
+
+ case 'M':
+ assert (NULL != optarg);
+ option_metronome_tick = strtod (optarg, NULL);
+ break;
+
+ case 'P':
+ option_in_file_format = FILE_FORMAT_DVB_PES;
+ break;
+
+ case 'T':
+ option_in_ts_pid = parse_option_ts ();
+ option_in_file_format = FILE_FORMAT_DVB_TS;
+ break;
+
+ case 'V':
+ printf (PROGRAM_NAME " " VERSION "\n");
+ exit (EXIT_SUCCESS);
+
+ default:
+ usage (stderr);
+ exit (EXIT_FAILURE);
+ }
+ }
+
+ //****************************************temp***************
+ option_decode_xds = TRUE;
+ option_decode_caption = TRUE;
+ //option_in_file_name = argv[1];
+
+ printf("zkoption_decode_xds\n");
+ //printf("option_in_file_name%s\n",option_in_file_name);
+
+ if (0 != option_pfc_pgno) {
+ printf("option_pfc_pgno\n");
+ pfc = vbi_pfc_demux_new (option_pfc_pgno,
+ option_pfc_stream,
+ page_function_clear_cb,
+ /* user_data */ NULL);
+ if (NULL == pfc)
+ no_mem_exit ();
+ }
+
+ if (0 != option_idl_channel) {
+ printf("option_idl_channel\n");
+ idl = vbi_idl_a_demux_new (option_idl_channel,
+ option_idl_address,
+ idl_format_a_cb,
+ /* user_data */ NULL);
+ if (NULL == idl)
+ no_mem_exit ();
+ }
+
+ if (option_decode_xds) {
+ printf("decode xds\n");
+ xds = vbi_xds_demux_new (xds_cb,
+ /* used_data */ NULL);
+ if (NULL == xds)
+ no_mem_exit ();
+ }else
+ printf("not decode xds\n");
+
+ rst = read_stream_new (pBuffer,length,
+ option_in_file_format,
+ option_in_ts_pid,
+ decode_frame);
+
+ printf("stream_loop\n");
+ stream_loop (rst);
+
+ stream_delete (rst);
+ rst = NULL;
+
+ error_msg (_("End of stream."));
+
+ vbi_xds_demux_delete (xds);
+ xds = NULL;
+
+ vbi_idl_demux_delete (idl);
+ idl = NULL;
+
+ vbi_pfc_demux_delete (pfc);
+ pfc = NULL;
+
+ exit (EXIT_SUCCESS);
+}
diff --git a/test/sliced.c b/ntsc_decode/sliced1.c
index f9abf0c..0b4d731 100644..100755
--- a/test/sliced.c
+++ b/ntsc_decode/sliced1.c
@@ -45,17 +45,17 @@
#include <sys/stat.h>
#include <fcntl.h>
-#include "src/dvb_mux.h"
-#include "src/dvb_demux.h"
-#include "src/io.h"
-#include "src/io-sim.h"
-#include "src/raw_decoder.h"
-#include "src/vbi.h"
-#include "sliced.h"
+#include "dvb_mux.h"
+#include "dvb_demux.h"
+#include "io.h"
+#include "io-sim.h"
+#include "raw_decoder.h"
+#include "vbi.h"
+#include "sliced1.h"
#if 2 == VBI_VERSION_MINOR
-# include "src/proxy-msg.h"
-# include "src/proxy-client.h"
+# include "proxy-msg.h"
+# include "proxy-client.h"
# define sp_sample_format sampling_format
# define sp_samples_per_line bytes_per_line
# define VBI_PIXFMT_Y8 VBI_PIXFMT_YUV420
@@ -241,6 +241,7 @@ stream_delete (struct stream * st)
vbi_bool
stream_loop (struct stream * st)
{
+ printf("stream_loop11\n");
return st->loop (st);
}
@@ -776,20 +777,23 @@ read_more (struct stream * st)
s = /* const cast */ st->end;
e = st->buffer + sizeof (st->buffer);
-
+ printf("111read_more %d \n",sizeof (st->buffer));
if (s >= e)
s = st->buffer;
-
+
+ //**********************************get buffer way***********
+ return TRUE;
+ //**********************************finish**********
retry = 100;
do {
ssize_t actual;
- int saved_errno;
-
+ int saved_errno;
+
actual = read (st->fd, s, e - s);
if (0 == actual)
return FALSE; /* EOF */
-
+ printf("111read_more actual %d \n",actual);
if (actual > 0) {
st->bp = s;
st->end = s + actual;
@@ -856,8 +860,10 @@ next_byte (struct stream * st,
int * c)
{
do {
+
if (st->bp < st->end) {
*c = *st->bp++;
+ printf("next_byte %x\n",*c);
return TRUE;
}
} while (read_more (st));
@@ -877,6 +883,8 @@ next_block (struct stream * st,
if (buffer_size <= available) {
memcpy (buffer, st->bp, buffer_size);
+ printf("block %d,%d %d %d \n",buffer[0],buffer[1],buffer[2],buffer[3]);
+
st->bp += buffer_size;
return;
}
@@ -1001,7 +1009,7 @@ next_time_delta (struct stream * st,
{
char buffer[32];
unsigned int i;
-
+ printf("start next_time_delta");
for (i = 0; i < N_ELEMENTS (buffer); ++i) {
int c;
@@ -1011,7 +1019,7 @@ next_time_delta (struct stream * st,
else
return FALSE;
}
-
+ printf("cccccccccc = %x i= %d \n",c,i);
if ('\n' == c) {
if (0 == i) {
bad_format_exit ();
@@ -1021,10 +1029,15 @@ next_time_delta (struct stream * st,
return TRUE;
}
}
-
+ c =c + '0';
+ if(isdigit (c))
+ printf("is digit\n");
+ else
+ printf("isnot digit\n");
+
if ('-' != c && '.' != c && !isdigit (c))
bad_format_exit ();
-
+ return TRUE;
buffer[i] = c;
}
@@ -1034,6 +1047,8 @@ next_time_delta (struct stream * st,
static vbi_bool
read_loop_old_sliced (struct stream * st)
{
+ int ii = 0;
+ printf("start read_loop_old_sliced ");
for (;;) {
vbi_sliced *s;
uint8_t *raw;
@@ -1042,33 +1057,57 @@ read_loop_old_sliced (struct stream * st)
vbi_bool success;
int n_lines;
int count;
-
- if (!next_time_delta (st, &dt))
- break; /* EOF */
+
+ //*************temp cancel********
+ //if (!next_time_delta (st, &dt))
+ // break; /* EOF */
+ //*************finish*************
/* Time in seconds since last frame. */
if (dt < 0.0)
dt = -dt;
st->sample_time += dt;
-
- if (!next_byte (st, &n_lines))
- bad_format_exit ();
-
+
+ printf("st->sample_time = %lf\n", st->sample_time);
+
+ n_lines = (st->end - st->bp) / 8; //8 is hardware struct length
+
+
+ //if (!next_byte (st, &n_lines))
+ // bad_format_exit ();
+ printf("n_lines = %d",n_lines);
if ((unsigned int) n_lines > N_ELEMENTS (st->sliced))
- bad_format_exit ();
+ n_lines = N_ELEMENTS (st->sliced); //bad_format_exit ();
+
+
+ printf(" N_ELEMENTS (st->sliced)=%d \n", N_ELEMENTS (st->sliced));
s = st->sliced;
raw = NULL;
st->raw_valid = FALSE;
for (count = n_lines; count > 0; --count) {
int index;
+ int field_id;
+ int nbytes;
int line;
-
+
+
+
if (!next_byte (st, &index))
premature_exit ();
-
+
+ if (!next_byte (st, &field_id))
+ premature_exit ();
+
+ if (!next_byte (st, &nbytes))
+ premature_exit ();
+
+ if (!next_byte (st, &nbytes))
+ premature_exit ();
+ s->line += (line & 15) * 256;
+
if (!next_byte (st, &line))
premature_exit ();
s->line = line;
@@ -1076,38 +1115,50 @@ read_loop_old_sliced (struct stream * st)
if (!next_byte (st, &line))
premature_exit ();
s->line += (line & 15) * 256;
-
+
+ printf(" index= %d, field_id =%d ,nbytes =%d ,line = %d \n,",index,field_id,nbytes,s->line);
+ //****************************************change if 284 = 21 else ....
+ if(s->line == 284)
+ s->line = 21;
+ else
+ if(s->line == 21)
+ s->line = 284;
+ //****************************************finish **************
switch (index) {
+
case 0:
+ s->id = VBI_SLICED_CAPTION_525;
+ next_block (st, s->data, 2);
+
+ break;
+
+ case 1:
s->id = VBI_SLICED_TELETEXT_B;
next_block (st, s->data, 42);
break;
- case 1:
+ case 2:
s->id = VBI_SLICED_CAPTION_625;
next_block (st, s->data, 2);
break;
- case 2:
+ case 3:
s->id = VBI_SLICED_VPS;
next_block (st, s->data, 13);
break;
- case 3:
+ case 4:
s->id = VBI_SLICED_WSS_625;
next_block (st, s->data, 2);
break;
- case 4:
+ case 5:
s->id = VBI_SLICED_WSS_CPR1204;
next_block (st, s->data, 3);
break;
- case 7:
- s->id = VBI_SLICED_CAPTION_525;
- next_block (st, s->data, 2);
- break;
-
+
+
case 255:
raw = next_raw_data (st, &sp);
st->raw_valid = TRUE;
@@ -1124,16 +1175,25 @@ read_loop_old_sliced (struct stream * st)
st->stream_time = st->sample_time * 90000;
if (st->raw_valid && st->decode_raw) {
+ printf("st->raw_valid && st->decode_raw is true\n");
success = st->callback (st->sliced2,
st->sliced2_lines,
raw, &sp,
st->sample_time,
st->stream_time);
} else {
- success = st->callback (st->sliced, n_lines,
+ printf("st->raw_valid && st->decode_raw isnot true\n");
+ //printf(" st->sliced->line=%d \n",st->sliced->line);
+ //printf(" st->sliced->data=%c st->sliced->data[1]=%c \n",st->sliced->data,st->sliced->data[1]);
+ //printf(" s->data= %c s->data[1]=%c \n",s->data[0],s->data[1]);
+ success = st->callback (st->sliced, n_lines,
raw, &sp,
st->sample_time,
st->stream_time);
+ if(ii == 0)
+ ii ++;
+ else
+ return FALSE;
}
free (raw);
@@ -1248,7 +1308,8 @@ detect_file_format (struct stream * st)
}
struct stream *
-read_stream_new (const char * file_name,
+read_stream_new (const char * fbuffer,
+ int length,
enum file_format file_format,
unsigned int ts_pid,
stream_callback_fn * callback)
@@ -1259,7 +1320,7 @@ read_stream_new (const char * file_name,
if (NULL == st)
no_mem_exit ();
- if (NULL == file_name
+ /*if (NULL == file_name
|| 0 == strcmp (file_name, "-")) {
st->fd = STDIN_FILENO;
@@ -1273,7 +1334,9 @@ read_stream_new (const char * file_name,
}
st->close_fd = TRUE;
- }
+ }*/
+
+
if (0 == file_format)
file_format = detect_file_format (st);
@@ -1322,7 +1385,14 @@ read_stream_new (const char * file_name,
st->bp = st->buffer;
st->end = st->buffer;
-
+ printf("finish read_stream_new" );
+
+ //***************************************add buffer*********
+ memset (st->buffer, 0,sizeof (st->buffer));
+ memcpy (st->buffer,fbuffer, length);
+ st->end = st->buffer + length;
+ //printf("st->bp,st->end,length === %d %d %d",st->bp,st->end,length );
+ //***************************************finish*********
return st;
}
diff --git a/test/sliced.h b/ntsc_decode/sliced1.h
index a4541e9..6901277 100644..100755
--- a/test/sliced.h
+++ b/ntsc_decode/sliced1.h
@@ -27,12 +27,12 @@
#include <errno.h>
#include <sys/time.h>
-#include "src/macros.h"
-#include "src/sliced.h"
-#include "src/sampling_par.h"
-#include "src/bit_slicer.h"
-#include "src/version.h"
-#include "src/io-sim.h"
+#include "macros.h"
+#include "sliced.h"
+#include "sampling_par.h"
+#include "bit_slicer.h"
+#include "version.h"
+#include "io-sim.h"
/* Helper functions. */
@@ -133,7 +133,7 @@ write_stream_new (const char * file_name,
unsigned int system);
extern struct stream *
-read_stream_new (const char * file_name,
+read_stream_new (const char * pbuffer,int length,
enum file_format file_format,
unsigned int ts_pid,
stream_callback_fn * callback);
diff --git a/src/xds_demux.c b/src/xds_demux.c
index 29141b3..6324e78 100644..100755
--- a/src/xds_demux.c
+++ b/src/xds_demux.c
@@ -247,13 +247,16 @@ _vbi_xds_packet_dump (const vbi_xds_packet * xp,
if (2 != xp->buffer_size)
goto invalid;
-
+ printf("xp->buffer[0] = %d,xp->buffer[1] = %d\n ",xp->buffer[0] ,xp->buffer[1] );
r = xp->buffer[0] & 7;
g = xp->buffer[1] & 7;
-
- fprintf (fp, " (movie: %s, tv: ",
- vbi_rating_string (VBI_RATING_AUTH_MPAA, r));
-
+ printf("r = %d,g = %d \n",r,g);
+ if (( xp->buffer[0] & 0x08) == 0) {
+ if (r == 0) return;
+ //auth = VBI_RATING_AUTH_MPAA;
+ fprintf (fp, " (movie: %s, tv: ",
+ vbi_rating_string (VBI_RATING_AUTH_MPAA, r));
+ }
if (xp->buffer[0] & 0x10) {
const char *s;
@@ -862,12 +865,13 @@ vbi_xds_demux_feed (vbi_xds_demux * xd,
sp = xd->curr_sp;
log ("XDS demux %02x %02x\n", buffer[0], buffer[1]);
-
- c1 = vbi_unpar8 (buffer[0]);
- c2 = vbi_unpar8 (buffer[1]);
-
- if ((c1 | c2) < 0) {
- log ("XDS tx error, discard current packet\n");
+ printf("XDS demux %02x %02x\n", buffer[0], buffer[1]);
+
+ c1 = buffer[0] ;//c1 = vbi_unpar8 (buffer[0]);
+ c2 = buffer[1] ;//c2 = vbi_unpar8 (buffer[1]);
+ printf("XDS demux %02x %02x\n", c1, c2);
+ if(0){ //if ((c1 | c2) < 0) {
+ printf ("XDS tx error, discard current packet\n");
if (sp) {
sp->count = 0;
@@ -892,19 +896,20 @@ vbi_xds_demux_feed (vbi_xds_demux * xd,
unsigned int i;
/* Packet header. */
-
+
xds_class = (c1 - 1) >> 1;
xds_subclass = c2;
-
+ printf("xds_class = %d xds_subclass = %d\n",xds_class,xds_subclass);
i = xds_subclass;
-
+
/* MISC subclass 0x4n */
if (i >= 0x40)
i += 0x10 - 0x40;
+ printf(" %d %d %d %d \n",xds_class,VBI_XDS_CLASS_MISC,i,N_ELEMENTS (xd->subpacket[0]));
if (xds_class > VBI_XDS_CLASS_MISC
|| i > N_ELEMENTS (xd->subpacket[0])) {
- log ("XDS ignore packet 0x%x/0x%02x, "
+ printf ("XDS ignore packet 0x%x/0x%02x, "
"unknown class or subclass\n",
xds_class, xds_subclass);
goto discard;
@@ -920,10 +925,11 @@ vbi_xds_demux_feed (vbi_xds_demux * xd,
/* Start packet. */
sp->checksum = c1 + c2;
sp->count = 2;
+ printf("c1 == 1");
} else {
/* Continue packet. */
if (0 == sp->count) {
- log ("XDS can't continue packet "
+ printf ("XDS can't continue packet "
"0x%x/0x%02x, missed start\n",
xd->curr.xds_class,
xd->curr.xds_subclass);
@@ -938,28 +944,33 @@ vbi_xds_demux_feed (vbi_xds_demux * xd,
/* Packet terminator. */
if (!sp) {
- log ("XDS can't finish packet, missed start\n");
+ printf ("XDS can't finish packet, missed start\n");
break;
}
+ printf ("XDS sp->count = %d\n",sp->count);
sp->checksum += c1 + c2;
if (0 != (sp->checksum & 0x7F)) {
- log ("XDS ignore packet 0x%x/0x%02x, "
+ printf ("XDS ignore packet 0x%x/0x%02x, "
"checksum error\n",
xd->curr.xds_class, xd->curr.xds_subclass);
} else if (sp->count <= 2) {
- log ("XDS ignore empty packet 0x%x/0x%02x\n",
+ printf ("XDS ignore empty packet 0x%x/0x%02x\n",
xd->curr.xds_class, xd->curr.xds_subclass);
} else {
memcpy (xd->curr.buffer, sp->buffer, 32);
-
+ printf("sp->count = %d\n",sp->count);
+ int iiiii = 0;
+ for(iiiii = 0 ; iiiii < 20;iiiii++){
+ printf("sp->buffer = %d\n",sp->buffer[iiiii]);
+ }
xd->curr.buffer_size = sp->count - 2;
xd->curr.buffer[sp->count - 2] = 0;
-
+
if (XDS_DEMUX_LOG)
_vbi_xds_packet_dump (&xd->curr, stderr);
-
+ printf("***************xds callback***********\n");
r = xd->callback (xd, &xd->curr, xd->user_data);
}
@@ -1000,7 +1011,7 @@ vbi_xds_demux_feed (vbi_xds_demux * xd,
sp->checksum += c1 + c2;
sp->count += 1 + (0 != c2);
-
+ printf ("XDS sp->count = %d\n",sp->count);
break;
}
diff --git a/test/sliced.c b/test/sliced1.c
index f9abf0c..f9abf0c 100644..100755
--- a/test/sliced.c
+++ b/test/sliced1.c
diff --git a/test/sliced.h b/test/sliced1.h
index a4541e9..a4541e9 100644..100755
--- a/test/sliced.h
+++ b/test/sliced1.h