File: filter-API.txt

package info (click to toggle)
transcode 3%3A1.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 11,644 kB
  • sloc: ansic: 116,927; sh: 11,468; xml: 2,849; makefile: 1,891; perl: 1,492; pascal: 526; php: 191; python: 144; sed: 43
file content (136 lines) | stat: -rw-r--r-- 4,370 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

  // ================
  // API explanation:
  // ================
  //
  // (1) need more infos, than get pointer to transcode global
  //     information structure vob_t as defined in transcode.h.
  //
  // (2) 'tc_get_vob' and 'verbose' are exported by transcode.
  //
  // (3) filter is called first time with TC_FILTER_INIT flag set.
  //
  // (4) make sure to exit immediately if context (video/audio) or
  //     placement of call (pre/post) is not compatible with the filters
  //     intended purpose, since the filter is called 4 times per frame.
  //
  // (5) see framebuffer.h for a complete list of frame_list_t variables.
  //
  // (6) filter is last time with TC_FILTER_CLOSE flag set. This is important.
  //     The filter should be left in a state so that it could be called again
  //     with TC_FILTER_INIT.
  //
  // (Anytime) A filter may be called with TC_FILTER_GET_CONFIG to read  the
  //           current config (optional) See /src/optstr.h for explanation


  Notes and Hints about filter programming:
  * Statics: All information and data you have calculated at INIT time and you
    want to reuse later must be declared static (tables, flags, etc)
  * The optstr_get function provides a convenient way for a developer to parse
    human readable option strings. You are encouraged to use this function.
  * If your filter shall be called multiple times during and encode session
    (maybe first as a pre fileter and than as a post process filter) _you_ have
    to take care to not overwrite your own data. A frame_list_t element has a
    field called `instance' which will help you to keep your adress space clean.
    See 32detect for an implementation.
  * When TC_FILER_GET_CONFIG flag is set, the filter should return its
    available parameters using the optstr_param and optstr_filter_desc funtions.
    The last parameters of optstr_param are ranges with valid arguments for
    this paramter. Sometimes it does not make sense to set the ranges, (e.g. if
    the parameter "foo" is valid from 0 to "all frames in this file", so it is
    considered good practice to use "oo" - the mathematical symbol for infinity
    as the upper limit.

Example filter code:

#define MOD_NAME    "filter_null.so"
#define MOD_VERSION "v0.1 (2003-10-12)"
#define MOD_CAP     "demo filter plugin"
#define MOD_AUTHOR  "Jon Doe <me@there>"

#include "filter.h"
#include "optstr.h"

int tc_filter(frame_list_t *ptr, char *options)
{

  int pre, vid;
  static int dummy_option = 0;

  static vob_t *vob=NULL;

  //----------------------------------
  //
  // filter get config
  //
  //----------------------------------

  if(ptr->tag & TC_FILTER_GET_CONFIG) {
    if (options) {
      optstr_filter_desc (MOD_NAME, MOP_CAP, MOD_VERSION, MOD_AUTHOR, "VARY", "1");

      optstr_param (options, "dummy_options",   // name
                             "This options does nothing",  // comment
                             "%d",  // format
                             "0",   // default value
                             "0",   // valid from
                             "255"  // valid to
                             );
    }
    return (0);
  }

  //----------------------------------
  //
  // filter init
  //
  //----------------------------------

  if(ptr->tag & TC_FILTER_INIT) {

    if((vob = tc_get_vob())==NULL) return(-1);

    if (options) {
      optstr_get (options, "dummy_option", "%d", &dummy_option);
    }

    // filter init ok.
    if(verbose) printf("[%s] %s %s\n", MOD_NAME, MOD_VERSION, MOD_CAP);

    return(0);
  }

  //----------------------------------
  //
  // filter close
  //
  //----------------------------------


  if(ptr->tag & TC_FILTER_CLOSE) {
    // free memory, etc ..
    return(0);
  }

  //----------------------------------
  //
  // filter frame routine
  //
  //----------------------------------

  // tag variable indicates, if we are called before
  // transcodes internal video/audo frame processing routines
  // or after and determines video/audio context


      if(ptr->tag & TC_PRE_M_PROCESS)  pre=1;
      if(ptr->tag & TC_POST_M_PROCESS) pre=0;

      if(ptr->tag & TC_VIDEO) vid=1;
      if(ptr->tag & TC_AUDIO) vid=0;

      printf("[%s] frame [%06d] %s %16s call\n", MOD_NAME, ptr->id, (vid)?"(video)":"(audio)", (pre)?"pre-process filter":"post-process filter");

      return(0);
}