File: filter_null.c

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 (345 lines) | stat: -rw-r--r-- 9,374 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/*
 * filter_null.c -- demo filter: does nothing, and it does that very well
 * Written     by Thomas Oestreich - June 2001
 * Updated by  by Francesco Romani <fromani at gmail dot com>
 *
 * This file is part of transcode, a video stream processing tool.
 * transcode is free software, distributable under the terms of the GNU
 * General Public License (version 2 or later).  See the file COPYING
 * for details.
 */

/* public (user-visible) Name of the filter */
#define MOD_NAME    "filter_null.so"
/* version of the filter */
#define MOD_VERSION "v1.1.0 (2007-06-02)"
/* A short description */
#define MOD_CAP     "demo filter plugin; does nothing"
/* Author(s) of the filter */
#define MOD_AUTHOR  "Thomas Oestreich, Thomas Wehrspann"
/* What this plugin can do (see NMS documentation for details) */
#define MOD_FEATURES \
    TC_MODULE_FEATURE_FILTER|TC_MODULE_FEATURE_VIDEO|TC_MODULE_FEATURE_AUDIO
/* How this module can work (see NMS documentation for details) */
#define MOD_FLAGS \
    TC_MODULE_FLAG_RECONFIGURABLE


/* API reminder (mostly for OMS, but take in mind for NMS too):
 * ========================================================================
 *
 * (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
 */

 
/* -------------------------------------------------
 *
 * mandatory include files
 *
 *-------------------------------------------------*/

#include "transcode.h"
#include "filter.h"
#include "libtc/libtc.h"
#include "libtc/optstr.h"
#include "libtc/tcmodule-plugin.h"


static const char null_help[] = ""
    "Overview:\n"
    "    This filter exists for demonstration purposes only; it doesn nothing.\n"
    "Options:\n"
    "    help    produce module overview and options explanations\n";


/*************************************************************************/

typedef struct {
    uint32_t video_frames; /* dumb frame counter */
    uint32_t audio_frames; /* dumb frame counter */
} NullPrivateData;

/*************************************************************************/

/* Module interface routines and data. */

/*************************************************************************/

/**
 * null_init:  Initialize this instance of the module.  See
 * tcmodule-data.h for function details.
 */

TC_MODULE_GENERIC_INIT(null, NullPrivateData)

/*************************************************************************/

/**
 * null_fini:  Clean up after this instance of the module.  See
 * tcmodule-data.h for function details.
 */

TC_MODULE_GENERIC_FINI(null)

/*************************************************************************/

/**
 * null_configure:  Configure this instance of the module.  See
 * tcmodule-data.h for function details.
 */

static int null_configure(TCModuleInstance *self,
                          const char *options, vob_t *vob)
{
    NullPrivateData *pd = NULL;

    TC_MODULE_SELF_CHECK(self, "configure");

    pd = self->userdata;

    /* setup defaults */
    pd->video_frames = 0;
    pd->audio_frames = 0;

    if (options) {
        if (verbose >= TC_STATS) {
            tc_log_info(MOD_NAME, "options=%s", options);
        }
        /* optstr_get() them */
    }

    /* handle other options */

    return TC_OK;
}

/*************************************************************************/

/**
 * null_stop:  Reset this instance of the module.  See tcmodule-data.h
 * for function details.
 */

static int null_stop(TCModuleInstance *self)
{
    NullPrivateData *pd = NULL;

    TC_MODULE_SELF_CHECK(self, "stop");

    pd = self->userdata;

    /* this is the right place for print out summary or collected stuff */
    tc_log_info(MOD_NAME, "elapsed frames audio/video: %u/%u",
                pd->audio_frames, pd->video_frames);

    /* reverse all stuff done in _configure */

    return TC_OK;
}

/*************************************************************************/

/**
 * null_inspect:  Return the value of an option in this instance of
 * the module.  See tcmodule-data.h for function details.
 */

static int null_inspect(TCModuleInstance *self,
                        const char *param, const char **value)
{
    NullPrivateData *pd = NULL;

    TC_MODULE_SELF_CHECK(self, "inspect");
    TC_MODULE_SELF_CHECK(param, "inspect");
    TC_MODULE_SELF_CHECK(value, "inspect");

    pd = self->userdata;

    if (optstr_lookup(param, "help")) {
        *value = null_help; 
    }
    /* put back configurable options */

    return TC_OK;
}

/*************************************************************************/

/**
 * null_filter_video:  show something on given frame of the video
 * stream.  See tcmodule-data.h for function details.
 */

static int null_filter_video(TCModuleInstance *self, vframe_list_t *frame)
{
    NullPrivateData *pd = NULL;
    int pre = 0;

    TC_MODULE_SELF_CHECK(self, "filer_video");
    TC_MODULE_SELF_CHECK(frame, "filer_video");

    pd = self->userdata;
    pre = (frame->tag & TC_PRE_M_PROCESS);

    if (verbose & TC_STATS) {

        /*
         * tag variable indicates, if we are called before
         * transcodes internal video/audo frame processing routines
         * or after and determines video/audio context
         */
        tc_log_info(MOD_NAME, "frame [%06d] video %16s call",
                    frame->id, 
                    (pre) ?"pre-process filter" :"post-process filter");
    }

    if (!pre) {
        /* do not count frames twice */
        pd->video_frames++;
    }

    return TC_OK;
}

/*************************************************************************/

/**
 * null_filter_audio:  show something on given frame of the audio
 * stream.  See tcmodule-data.h for function details.
 */

static int null_filter_audio(TCModuleInstance *self, aframe_list_t *frame)
{
    NullPrivateData *pd = NULL;
    int pre = 0;

    TC_MODULE_SELF_CHECK(self, "filer_audio");
    TC_MODULE_SELF_CHECK(frame, "filer_audio");

    pd = self->userdata;
    pre = (frame->tag & TC_PRE_M_PROCESS);

    if (verbose & TC_STATS) {

        /*
         * tag variable indicates, if we are called before
         * transcodes internal video/audo frame processing routines
         * or after and determines video/audio context
         */
        tc_log_info(MOD_NAME, "frame [%06d] audio %16s call",
                    frame->id, 
                    (pre) ?"pre-process filter" :"post-process filter");
    }

    if (!pre) {
        /* do not count frames twice */
        pd->audio_frames++;
    }

    return TC_OK;
}

/*************************************************************************/

static const TCCodecID null_codecs_in[] = { 
    TC_CODEC_ANY, TC_CODEC_ERROR
};
static const TCCodecID null_codecs_out[] = {
    TC_CODEC_ANY, TC_CODEC_ERROR
};
TC_MODULE_FILTER_FORMATS(null);

TC_MODULE_INFO(null);

static const TCModuleClass null_class = {
    TC_MODULE_CLASS_HEAD(null),

    .init         = null_init,
    .fini         = null_fini,
    .configure    = null_configure,
    .stop         = null_stop,
    .inspect      = null_inspect,

    .filter_video = null_filter_video,
    .filter_audio = null_filter_audio,
};

TC_MODULE_ENTRY_POINT(null)

/*************************************************************************/

static int null_get_config(TCModuleInstance *self, char *options)
{
    NullPrivateData *pd = NULL;

    TC_MODULE_SELF_CHECK(self, "get_config");

    pd = self->userdata;

    /*
     * Valid flags for the string of filter capabilities:
     *  "V" :  Can do Video
     *  "A" :  Can do Audio
     *  "R" :  Can do RGB
     *  "Y" :  Can do YUV
     *  "4" :  Can do YUV422
     *  "M" :  Can do Multiple Instances
     *  "E" :  Is a PRE filter
     *  "O" :  Is a POST filter
     */
    optstr_filter_desc(options, MOD_NAME, MOD_CAP, MOD_VERSION,
                       MOD_AUTHOR, "VAMEO", "1");

    /* can be omitted */
    optstr_param (options, "help", "Prints out a short help", "", "0");
 
    /* use optstr_param to do introspection */

    return TC_OK;
}

static int null_process(TCModuleInstance *self, 
                            frame_list_t *frame)
{
    TC_MODULE_SELF_CHECK(self, "process");

    /* choose what to do by frame->tag */
    if (frame->tag & TC_VIDEO) {
        return null_filter_video(self, (vframe_list_t*)frame);
    }
    if (frame->tag & TC_AUDIO) {
        return null_filter_audio(self, (aframe_list_t*)frame);
    }
    return TC_OK;
}

/*************************************************************************/

/* Old-fashioned module interface. */

TC_FILTER_OLDINTERFACE(null)

/*************************************************************************/

/*
 * Local variables:
 *   c-file-style: "stroustrup"
 *   c-file-offsets: ((case-label . *) (statement-case-intro . *))
 *   indent-tabs-mode: nil
 * End:
 *
 * vim: expandtab shiftwidth=4:
 */