Psvbi
From M1Research
(→Demembedding of data) |
(→API interface for own analizator) |
||
Line 64: | Line 64: | ||
===API interface for own analizator=== | ===API interface for own analizator=== | ||
+ | |||
+ | Demebedder (<b>psvbid</b>) application perform all operation on "transport" level. To operate on higher level (application) software use plugins set. Each new task required new plugin developing (depends on application level data usage). | ||
+ | |||
+ | Basic plugin structure: | ||
+ | |||
+ | Include required headers: | ||
+ | <pre> | ||
+ | #include <stdio.h> | ||
+ | #include "psvbi.h" | ||
+ | #include "psvbid-plugins.h" | ||
+ | </pre> | ||
+ | |||
+ | Plugins is dynamic loadable library. You can use <code>my_init</code> and <code>my_fini</code> to initialize data structures: | ||
+ | <pre> | ||
+ | void __attribute__ ((constructor)) my_init(void) | ||
+ | { | ||
+ | printf("debug::my_init\n"); | ||
+ | }; | ||
+ | |||
+ | void __attribute__ ((destructor)) my_fini(void) | ||
+ | { | ||
+ | printf("debug::my_fini\n"); | ||
+ | }; | ||
+ | </pre> | ||
+ | |||
+ | After detecting of code block (or fail to detect) main program calls function <code>detect_ok</code> (or <code>detect_ok</code>, that you can make empty) of all plugins chain loaded: | ||
+ | <pre> | ||
+ | static int detect_ok(struct psvbi_block* block) | ||
+ | { | ||
+ | // some code to operate with block | ||
+ | // calc checksum, check data is correct | ||
+ | return 0; | ||
+ | }; | ||
+ | static int detect_fail(struct psvbi_block* block) | ||
+ | { | ||
+ | return 0; | ||
+ | }; | ||
+ | </pre> | ||
+ | |||
+ | Argument supplied to functions is <code>struct psvbi_block</code>: | ||
+ | <pre> | ||
+ | struct psvbi_block | ||
+ | { | ||
+ | // in/out datas | ||
+ | unsigned char decoded[PSVBI_DATA_LEN]; // data block to coded/restored | ||
+ | unsigned char encoded[PSVBI_PACKET_LEN_PACKED]; // coded data block | ||
+ | |||
+ | // statistic | ||
+ | unsigned char decode_errors[PSVBI_DATA_LEN]; // errors numbers for bytes | ||
+ | unsigned char decode_corrections[PSVBI_DATA_LEN]; // number of corrected bit | ||
+ | int errors; // total errors count during decoding | ||
+ | int corrections; // total count of corrected bits | ||
+ | |||
+ | // decoding/coding controls | ||
+ | int _h; // horizontal and vertical positions of | ||
+ | int _v; // found block | ||
+ | /* | ||
+ | int state; // state-machine controls | ||
+ | void* data; // input - output data | ||
+ | int offset; // offset from begining | ||
+ | */ | ||
+ | }; | ||
+ | </pre> | ||
+ | |||
+ | At last you should create a plugin description struct, that define methods and name (classic): | ||
+ | <pre> | ||
+ | /* --------------------------------------------------------------------------- | ||
+ | |||
+ | Define plugin attributest | ||
+ | |||
+ | ----------------------------------------------------------------------------*/ | ||
+ | |||
+ | struct psvbid_plugin PLUGIN = | ||
+ | { | ||
+ | .name = "test1", | ||
+ | .ok = detect_ok, | ||
+ | .fail = NULL // detect_fail | ||
+ | }; | ||
+ | </pre> | ||
==Software== | ==Software== | ||
==Real example== | ==Real example== |
Revision as of 17:26, 7 January 2006
psvbi - Pseudo VBI
Contents |
Overview
psvbi software complex was developed for trasmitting control commands in TV video signal. Data block coded into some lines of video signal and could be used as marks for remote stations or analytic system. It much easy to implement and control (and diag) instead of real VBI due to high cost of equipment.
How does it works
Base Theory
Data to transmit coded by 14 bytes block. Each block transmitted in one video frame. Data encoded as luminance part of video signal (most stable to MPEG encoding/decoding) in some video lines (in our case we prefer to use top 2..4 lines - not visible on home equipment, only professional monitors with turned on underscan area could be used to SEE if data real present). During coding data used Hamming Error Correction Code and permutations alorithms to make more stable transmitting data, but some times it was noticed false data detection :-(((, use control sum algorithms in analizator to check if it's your real data packed :-))).
Embedding data
Embedding data performed by VirtualDub software (real greate program). Embedding and encoding data performed by our plug-in.
Make sure you have VirtualDub and copied pseudovbi.vdf
to VirtualDub's plugin folder.
Start VirtualDub, open desired video file (in our case we use Matrox Digisuite for capturing and playback). Open Video -> Filters and select pseudovbi plugin. As result you can see plugin dialog window:
Encoding/Embeding parametes:
- Start encoding from - define start frame number of video to insert data;
- Frames to encode - number of frames (duration on frames) of encoded data block;
- Data block - hexadiminal presentation of 14 bytes lenght data block;
- Setup/"Luma" level - defines value is used to encode data (0...255);
- Inserting Position - this blocks define where data will be inserted (position on screen). We prefer use top 2 rows (video lines) to insert;
- BLOCK - enable/disable insert block;
- COLUMN - start position (from left) where data begin to inserts
- ROW - row/line number where data begin to inserts;
Result of plugin: (fragment of VirtualDub program interface)
As result you can see a dot sequence in first 2 lines of frame. Now data block embedded. You can print this video to tape or video server.
Demembedding of data
Dembedding of data performed by another part of software.
This software capture video using V4L2 base interface (we use bttv878 based capture card) perform alization and in a case of detection datablock it call plugins method that perform higher level data decoding (application level).
Application startup parameters:
[root@dev-2 decoder]# ./psvbid --help Usage: psvbid <args> args: --demonize=N 0-no daemon mode, 1-demonize (default 0) --white-level=N White level of signal (default 96) --pos-x-start=N left 'x' position of search block (default 10) --pos-x-stop=N right 'x' position of search block (default 30) --pos-y-start=N top 'y' position of search block (default 0) --pos-y-stop=N bottom 'y' position of search block (default 10) --video-dev=S video device to grab video from (default '/dev/video0') --load-plugin=S load handler plugin (multiple allowed, max 10) --verbose-video-init show more info during init v4l2 device (default 0) --help Show program usage
Real application startup:
[root@dev-2 decoder]# ./psvbid --load-plugin=m1cmds --verbose-video-init --pos-y-stop=5
API interface for own analizator
Demebedder (psvbid) application perform all operation on "transport" level. To operate on higher level (application) software use plugins set. Each new task required new plugin developing (depends on application level data usage).
Basic plugin structure:
Include required headers:
#include <stdio.h> #include "psvbi.h" #include "psvbid-plugins.h"
Plugins is dynamic loadable library. You can use my_init
and my_fini
to initialize data structures:
void __attribute__ ((constructor)) my_init(void) { printf("debug::my_init\n"); }; void __attribute__ ((destructor)) my_fini(void) { printf("debug::my_fini\n"); };
After detecting of code block (or fail to detect) main program calls function detect_ok
(or detect_ok
, that you can make empty) of all plugins chain loaded:
static int detect_ok(struct psvbi_block* block) { // some code to operate with block // calc checksum, check data is correct return 0; }; static int detect_fail(struct psvbi_block* block) { return 0; };
Argument supplied to functions is struct psvbi_block
:
struct psvbi_block { // in/out datas unsigned char decoded[PSVBI_DATA_LEN]; // data block to coded/restored unsigned char encoded[PSVBI_PACKET_LEN_PACKED]; // coded data block // statistic unsigned char decode_errors[PSVBI_DATA_LEN]; // errors numbers for bytes unsigned char decode_corrections[PSVBI_DATA_LEN]; // number of corrected bit int errors; // total errors count during decoding int corrections; // total count of corrected bits // decoding/coding controls int _h; // horizontal and vertical positions of int _v; // found block /* int state; // state-machine controls void* data; // input - output data int offset; // offset from begining */ };
At last you should create a plugin description struct, that define methods and name (classic):
/* --------------------------------------------------------------------------- Define plugin attributest ----------------------------------------------------------------------------*/ struct psvbid_plugin PLUGIN = { .name = "test1", .ok = detect_ok, .fail = NULL // detect_fail };