FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bitstream_filter.c
Go to the documentation of this file.
1 /*
2  * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <string.h>
22 
23 #include "avcodec.h"
24 #include "libavutil/atomic.h"
25 #include "libavutil/mem.h"
26 
28 
30 {
31  if (f)
32  return f->next;
33  else
35 }
36 
38 {
39  do {
41  } while(bsf->next != avpriv_atomic_ptr_cas((void * volatile *)&first_bitstream_filter, bsf->next, bsf));
42 }
43 
45 {
46  AVBitStreamFilter *bsf = NULL;
47 
48  while (bsf = av_bitstream_filter_next(bsf)) {
49  if (!strcmp(name, bsf->name)) {
52  if (!bsfc)
53  return NULL;
54  bsfc->filter = bsf;
55  bsfc->priv_data = NULL;
56  if (bsf->priv_data_size) {
57  bsfc->priv_data = av_mallocz(bsf->priv_data_size);
58  if (!bsfc->priv_data) {
59  av_freep(&bsfc);
60  return NULL;
61  }
62  }
63  return bsfc;
64  }
65  }
66  return NULL;
67 }
68 
70 {
71  if (!bsfc)
72  return;
73  if (bsfc->filter->close)
74  bsfc->filter->close(bsfc);
75  av_freep(&bsfc->priv_data);
76  av_parser_close(bsfc->parser);
77  av_free(bsfc);
78 }
79 
81  AVCodecContext *avctx, const char *args,
82  uint8_t **poutbuf, int *poutbuf_size,
83  const uint8_t *buf, int buf_size, int keyframe)
84 {
85  *poutbuf = (uint8_t *)buf;
86  *poutbuf_size = buf_size;
87  return bsfc->filter->filter(bsfc, avctx, args, poutbuf, poutbuf_size,
88  buf, buf_size, keyframe);
89 }
#define NULL
Definition: coverity.c:32
memory handling functions
struct AVBitStreamFilter * next
Definition: avcodec.h:5089
AVCodecParserContext * parser
Definition: avcodec.h:5076
uint8_t
static AVBitStreamFilter * first_bitstream_filter
const char * name
Definition: avcodec.h:5082
#define avpriv_atomic_ptr_cas
Definition: atomic_gcc.h:60
void av_bitstream_filter_close(AVBitStreamFilterContext *bsfc)
Release bitstream filter context.
Libavcodec external API header.
AVBitStreamFilter * av_bitstream_filter_next(const AVBitStreamFilter *f)
If f is NULL, return the first registered bitstream filter, if f is non-NULL, return the next registe...
AVBitStreamFilterContext * av_bitstream_filter_init(const char *name)
Create and initialize a bitstream filter context given a bitstream filter name.
void av_parser_close(AVCodecParserContext *s)
Definition: parser.c:221
void av_register_bitstream_filter(AVBitStreamFilter *bsf)
Register a bitstream filter.
int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe)
Filter bitstream.
main external API structure.
Definition: avcodec.h:1241
void * buf
Definition: avisynth_c.h:553
struct AVBitStreamFilter * filter
Definition: avcodec.h:5075
void(* close)(AVBitStreamFilterContext *bsfc)
Definition: avcodec.h:5088
int(* filter)(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe)
Definition: avcodec.h:5084
#define av_free(p)
#define av_freep(p)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:250
const char * name
Definition: opengl_enc.c:103