~ubuntu-branches/ubuntu/trusty/gst-libav1.0/trusty-proposed

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/cmdutils.h

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-09-24 17:07:00 UTC
  • mfrom: (1.1.17) (7.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20130924170700-4dg62s3pwl0pdakz
Tags: 1.2.0-1
* New upstream stable release:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.2.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
 * Fallback for options that are not explicitly handled, these will be
66
66
 * parsed through AVOptions.
67
67
 */
68
 
int opt_default(const char *opt, const char *arg);
 
68
int opt_default(void *optctx, const char *opt, const char *arg);
69
69
 
70
70
/**
71
71
 * Set the libav* libraries log level.
72
72
 */
73
 
int opt_loglevel(const char *opt, const char *arg);
 
73
int opt_loglevel(void *optctx, const char *opt, const char *arg);
74
74
 
75
75
/**
76
76
 * Limit the execution time.
77
77
 */
78
 
int opt_timelimit(const char *opt, const char *arg);
 
78
int opt_timelimit(void *optctx, const char *opt, const char *arg);
79
79
 
80
80
/**
81
81
 * Parse a string and return its corresponding value as a double.
121
121
    } u;
122
122
} SpecifierOpt;
123
123
 
124
 
typedef struct {
 
124
typedef struct OptionDef {
125
125
    const char *name;
126
126
    int flags;
127
127
#define HAS_ARG    0x0001
130
130
#define OPT_STRING 0x0008
131
131
#define OPT_VIDEO  0x0010
132
132
#define OPT_AUDIO  0x0020
133
 
#define OPT_GRAB   0x0040
134
133
#define OPT_INT    0x0080
135
134
#define OPT_FLOAT  0x0100
136
135
#define OPT_SUBTITLE 0x0200
137
136
#define OPT_INT64  0x0400
138
137
#define OPT_EXIT   0x0800
139
138
#define OPT_DATA   0x1000
140
 
#define OPT_FUNC2  0x2000
 
139
#define OPT_PERFILE  0x2000     /* the option is per-file (currently avconv-only).
 
140
                                   implied by OPT_OFFSET or OPT_SPEC */
141
141
#define OPT_OFFSET 0x4000       /* option is specified as an offset in a passed optctx */
142
142
#define OPT_SPEC   0x8000       /* option is to be stored in an array of SpecifierOpt.
143
143
                                   Implies OPT_OFFSET. Next element after the offset is
146
146
#define OPT_DOUBLE 0x20000
147
147
     union {
148
148
        void *dst_ptr;
149
 
        int (*func_arg)(const char *, const char *);
150
 
        int (*func2_arg)(void *, const char *, const char *);
 
149
        int (*func_arg)(void *, const char *, const char *);
151
150
        size_t off;
152
151
    } u;
153
152
    const char *help;
154
153
    const char *argname;
155
154
} OptionDef;
156
155
 
157
 
void show_help_options(const OptionDef *options, const char *msg, int mask,
158
 
                       int value);
 
156
/**
 
157
 * Print help for all options matching specified flags.
 
158
 *
 
159
 * @param options a list of options
 
160
 * @param msg title of this group. Only printed if at least one option matches.
 
161
 * @param req_flags print only options which have all those flags set.
 
162
 * @param rej_flags don't print options which have any of those flags set.
 
163
 * @param alt_flags print only options that have at least one of those flags set
 
164
 */
 
165
void show_help_options(const OptionDef *options, const char *msg, int req_flags,
 
166
                       int rej_flags, int alt_flags);
159
167
 
160
168
/**
161
169
 * Show help for all options with given flags in class and all its
164
172
void show_help_children(const AVClass *class, int flags);
165
173
 
166
174
/**
 
175
 * Per-avtool specific help handler. Implemented in each
 
176
 * avtool, called by show_help().
 
177
 */
 
178
void show_help_default(const char *opt, const char *arg);
 
179
 
 
180
/**
 
181
 * Generic -h handler common to all avtools.
 
182
 */
 
183
int show_help(void *optctx, const char *opt, const char *arg);
 
184
 
 
185
/**
167
186
 * Parse the command line arguments.
168
187
 *
169
188
 * @param optctx an opaque options context
 
189
 * @param argc   number of command line arguments
 
190
 * @param argv   values of command line arguments
170
191
 * @param options Array with the definitions required to interpret every
171
192
 * option of the form: -option_name [argument]
172
193
 * @param parse_arg_function Name of the function called to process every
185
206
                 const OptionDef *options);
186
207
 
187
208
/**
 
209
 * An option extracted from the commandline.
 
210
 * Cannot use AVDictionary because of options like -map which can be
 
211
 * used multiple times.
 
212
 */
 
213
typedef struct Option {
 
214
    const OptionDef  *opt;
 
215
    const char       *key;
 
216
    const char       *val;
 
217
} Option;
 
218
 
 
219
typedef struct OptionGroupDef {
 
220
    /**< group name */
 
221
    const char *name;
 
222
    /**
 
223
     * Option to be used as group separator. Can be NULL for groups which
 
224
     * are terminated by a non-option argument (e.g. avconv output files)
 
225
     */
 
226
    const char *sep;
 
227
} OptionGroupDef;
 
228
 
 
229
typedef struct OptionGroup {
 
230
    const OptionGroupDef *group_def;
 
231
    const char *arg;
 
232
 
 
233
    Option *opts;
 
234
    int  nb_opts;
 
235
 
 
236
    AVDictionary *codec_opts;
 
237
    AVDictionary *format_opts;
 
238
    struct SwsContext *sws_opts;
 
239
} OptionGroup;
 
240
 
 
241
/**
 
242
 * A list of option groups that all have the same group type
 
243
 * (e.g. input files or output files)
 
244
 */
 
245
typedef struct OptionGroupList {
 
246
    const OptionGroupDef *group_def;
 
247
 
 
248
    OptionGroup *groups;
 
249
    int       nb_groups;
 
250
} OptionGroupList;
 
251
 
 
252
typedef struct OptionParseContext {
 
253
    OptionGroup global_opts;
 
254
 
 
255
    OptionGroupList *groups;
 
256
    int           nb_groups;
 
257
 
 
258
    /* parsing state */
 
259
    OptionGroup cur_group;
 
260
} OptionParseContext;
 
261
 
 
262
/**
 
263
 * Parse an options group and write results into optctx.
 
264
 *
 
265
 * @param optctx an app-specific options context. NULL for global options group
 
266
 */
 
267
int parse_optgroup(void *optctx, OptionGroup *g);
 
268
 
 
269
/**
 
270
 * Split the commandline into an intermediate form convenient for further
 
271
 * processing.
 
272
 *
 
273
 * The commandline is assumed to be composed of options which either belong to a
 
274
 * group (those with OPT_SPEC, OPT_OFFSET or OPT_PERFILE) or are global
 
275
 * (everything else).
 
276
 *
 
277
 * A group (defined by an OptionGroupDef struct) is a sequence of options
 
278
 * terminated by either a group separator option (e.g. -i) or a parameter that
 
279
 * is not an option (doesn't start with -). A group without a separator option
 
280
 * must always be first in the supplied groups list.
 
281
 *
 
282
 * All options within the same group are stored in one OptionGroup struct in an
 
283
 * OptionGroupList, all groups with the same group definition are stored in one
 
284
 * OptionGroupList in OptionParseContext.groups. The order of group lists is the
 
285
 * same as the order of group definitions.
 
286
 */
 
287
int split_commandline(OptionParseContext *octx, int argc, char *argv[],
 
288
                      const OptionDef *options,
 
289
                      const OptionGroupDef *groups, int nb_groups);
 
290
 
 
291
/**
 
292
 * Free all allocated memory in an OptionParseContext.
 
293
 */
 
294
void uninit_parse_context(OptionParseContext *octx);
 
295
 
 
296
/**
188
297
 * Find the '-loglevel' option in the command line args and apply it.
189
298
 */
190
299
void parse_loglevel(int argc, char **argv, const OptionDef *options);
191
300
 
192
301
/**
 
302
 * Return index of option opt in argv or 0 if not found.
 
303
 */
 
304
int locate_option(int argc, char **argv, const OptionDef *options,
 
305
                  const char *optname);
 
306
 
 
307
/**
193
308
 * Check if the given stream matches a stream specifier.
194
309
 *
195
310
 * @param s  Corresponding format context.
206
321
 * Create a new options dictionary containing only the options from
207
322
 * opts which apply to the codec with ID codec_id.
208
323
 *
 
324
 * @param opts     dictionary to place options in
 
325
 * @param codec_id ID of the codec that should be filtered for
209
326
 * @param s Corresponding format context.
210
327
 * @param st A stream from s for which the options should be filtered.
 
328
 * @param codec The particular codec for which the options should be filtered.
 
329
 *              If null, the default one is looked up according to the codec id.
211
330
 * @return a pointer to the created dictionary
212
331
 */
213
 
AVDictionary *filter_codec_opts(AVDictionary *opts, enum CodecID codec_id,
214
 
                                AVFormatContext *s, AVStream *st);
 
332
AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
 
333
                                AVFormatContext *s, AVStream *st, AVCodec *codec);
215
334
 
216
335
/**
217
336
 * Setup AVCodecContext options for avformat_find_stream_info().
250
369
 * depends on the current versions of the repository and of the libav*
251
370
 * libraries.
252
371
 */
253
 
void show_version(void);
 
372
int show_version(void *optctx, const char *opt, const char *arg);
254
373
 
255
374
/**
256
375
 * Print the license of the program to stdout. The license depends on
257
376
 * the license of the libraries compiled into the program.
258
377
 */
259
 
void show_license(void);
 
378
int show_license(void *optctx, const char *opt, const char *arg);
260
379
 
261
380
/**
262
381
 * Print a listing containing all the formats supported by the
263
382
 * program.
264
383
 */
265
 
void show_formats(void);
 
384
int show_formats(void *optctx, const char *opt, const char *arg);
266
385
 
267
386
/**
268
387
 * Print a listing containing all the codecs supported by the
269
388
 * program.
270
389
 */
271
 
void show_codecs(void);
 
390
int show_codecs(void *optctx, const char *opt, const char *arg);
 
391
 
 
392
/**
 
393
 * Print a listing containing all the decoders supported by the
 
394
 * program.
 
395
 */
 
396
int show_decoders(void *optctx, const char *opt, const char *arg);
 
397
 
 
398
/**
 
399
 * Print a listing containing all the encoders supported by the
 
400
 * program.
 
401
 */
 
402
int show_encoders(void *optctx, const char *opt, const char *arg);
272
403
 
273
404
/**
274
405
 * Print a listing containing all the filters supported by the
275
406
 * program.
276
407
 */
277
 
void show_filters(void);
 
408
int show_filters(void *optctx, const char *opt, const char *arg);
278
409
 
279
410
/**
280
411
 * Print a listing containing all the bit stream filters supported by the
281
412
 * program.
282
413
 */
283
 
void show_bsfs(void);
 
414
int show_bsfs(void *optctx, const char *opt, const char *arg);
284
415
 
285
416
/**
286
417
 * Print a listing containing all the protocols supported by the
287
418
 * program.
288
419
 */
289
 
void show_protocols(void);
 
420
int show_protocols(void *optctx, const char *opt, const char *arg);
290
421
 
291
422
/**
292
423
 * Print a listing containing all the pixel formats supported by the
293
424
 * program.
294
425
 */
295
 
void show_pix_fmts(void);
 
426
int show_pix_fmts(void *optctx, const char *opt, const char *arg);
296
427
 
297
428
/**
298
429
 * Print a listing containing all the sample formats supported by the
299
430
 * program.
300
431
 */
301
 
int show_sample_fmts(const char *opt, const char *arg);
 
432
int show_sample_fmts(void *optctx, const char *opt, const char *arg);
302
433
 
303
434
/**
304
435
 * Return a positive value if a line read from standard input
310
441
 * Read the file with name filename, and put its content in a newly
311
442
 * allocated 0-terminated buffer.
312
443
 *
 
444
 * @param filename file to read from
313
445
 * @param bufptr location where pointer to buffer is returned
314
446
 * @param size   location where size of buffer is returned
315
447
 * @return 0 in case of success, a negative value corresponding to an
317
449
 */
318
450
int cmdutils_read_file(const char *filename, char **bufptr, size_t *size);
319
451
 
320
 
typedef struct {
 
452
typedef struct PtsCorrectionContext {
321
453
    int64_t num_faulty_pts; /// Number of incorrect PTS values so far
322
454
    int64_t num_faulty_dts; /// Number of incorrect DTS values so far
323
455
    int64_t last_pts;       /// PTS of the last frame
334
466
 * which might have incorrect times. Input timestamps may wrap around, in
335
467
 * which case the output will as well.
336
468
 *
 
469
 * @param ctx the PtsCorrectionContext carrying stream pts information
337
470
 * @param pts the pts field of the decoded AVPacket, as passed through
338
471
 * AVCodecContext.reordered_opaque
339
472
 * @param dts the dts field of the decoded AVPacket
361
494
FILE *get_preset_file(char *filename, size_t filename_size,
362
495
                      const char *preset_name, int is_path, const char *codec_name);
363
496
 
364
 
typedef struct {
365
 
    enum PixelFormat pix_fmt;
366
 
} AVSinkContext;
367
 
 
368
 
extern AVFilter avsink;
369
 
 
370
 
/**
371
 
 * Extract a frame from sink.
372
 
 *
373
 
 * @return a negative error in case of failure, 1 if one frame has
374
 
 * been extracted successfully.
375
 
 */
376
 
int get_filtered_video_frame(AVFilterContext *sink, AVFrame *frame,
377
 
                             AVFilterBufferRef **picref, AVRational *pts_tb);
378
 
 
379
 
/**
380
 
 * Do all the necessary cleanup and abort.
381
 
 * This function is implemented in the avtools, not cmdutils.
382
 
 */
383
 
void exit_program(int ret);
384
 
 
385
497
/**
386
498
 * Realloc array to hold new_size elements of elem_size.
387
 
 * Calls exit_program() on failure.
 
499
 * Calls exit() on failure.
388
500
 *
 
501
 * @param array array to reallocate
389
502
 * @param elem_size size in bytes of each element
390
503
 * @param size new element count will be written here
 
504
 * @param new_size number of elements to place in reallocated array
391
505
 * @return reallocated array
392
506
 */
393
507
void *grow_array(void *array, int elem_size, int *size, int new_size);
394
508
 
 
509
#define GROW_ARRAY(array, nb_elems)\
 
510
    array = grow_array(array, sizeof(*array), &nb_elems, nb_elems + 1)
 
511
 
 
512
typedef struct FrameBuffer {
 
513
    uint8_t *base[4];
 
514
    uint8_t *data[4];
 
515
    int  linesize[4];
 
516
 
 
517
    int h, w;
 
518
    enum AVPixelFormat pix_fmt;
 
519
 
 
520
    int refcount;
 
521
    struct FrameBuffer **pool;  ///< head of the buffer pool
 
522
    struct FrameBuffer *next;
 
523
} FrameBuffer;
 
524
 
 
525
/**
 
526
 * Get a frame from the pool. This is intended to be used as a callback for
 
527
 * AVCodecContext.get_buffer.
 
528
 *
 
529
 * @param s codec context. s->opaque must be a pointer to the head of the
 
530
 *          buffer pool.
 
531
 * @param frame frame->opaque will be set to point to the FrameBuffer
 
532
 *              containing the frame data.
 
533
 */
 
534
int codec_get_buffer(AVCodecContext *s, AVFrame *frame);
 
535
 
 
536
/**
 
537
 * A callback to be used for AVCodecContext.release_buffer along with
 
538
 * codec_get_buffer().
 
539
 */
 
540
void codec_release_buffer(AVCodecContext *s, AVFrame *frame);
 
541
 
 
542
/**
 
543
 * A callback to be used for AVFilterBuffer.free.
 
544
 * @param fb buffer to free. fb->priv must be a pointer to the FrameBuffer
 
545
 *           containing the buffer data.
 
546
 */
 
547
void filter_release_buffer(AVFilterBuffer *fb);
 
548
 
 
549
/**
 
550
 * Free all the buffers in the pool. This must be called after all the
 
551
 * buffers have been released.
 
552
 */
 
553
void free_buffer_pool(FrameBuffer **pool);
 
554
 
 
555
#define GET_PIX_FMT_NAME(pix_fmt)\
 
556
    const char *name = av_get_pix_fmt_name(pix_fmt);
 
557
 
 
558
#define GET_SAMPLE_FMT_NAME(sample_fmt)\
 
559
    const char *name = av_get_sample_fmt_name(sample_fmt)
 
560
 
 
561
#define GET_SAMPLE_RATE_NAME(rate)\
 
562
    char name[16];\
 
563
    snprintf(name, sizeof(name), "%d", rate);
 
564
 
 
565
#define GET_CH_LAYOUT_NAME(ch_layout)\
 
566
    char name[16];\
 
567
    snprintf(name, sizeof(name), "0x%"PRIx64, ch_layout);
 
568
 
 
569
#define GET_CH_LAYOUT_DESC(ch_layout)\
 
570
    char name[128];\
 
571
    av_get_channel_layout_string(name, sizeof(name), 0, ch_layout);
 
572
 
395
573
#endif /* LIBAV_CMDUTILS_H */