File: _codec_plugin.c

package info (click to toggle)
gmerlin-encoders 2.0.0~svn6278-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,076 kB
  • sloc: ansic: 15,264; sh: 662; makefile: 364; sed: 16
file content (135 lines) | stat: -rw-r--r-- 3,944 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
/*****************************************************************
 * gmerlin-encoders - encoder plugins for gmerlin
 *
 * Copyright (c) 2001 - 2012 Members of the Gmerlin project
 * gmerlin-general@lists.sourceforge.net
 * http://gmerlin.sourceforge.net
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * *****************************************************************/

typedef struct
  {
  bg_ffmpeg_codec_context_t * codec;
  } stream_codec_t;

static void * create_codec()
  {
  stream_codec_t * ret = calloc(1, sizeof(*ret));

  ret->codec = bg_ffmpeg_codec_create(
#ifdef IS_AUDIO
                                      AVMEDIA_TYPE_AUDIO,
#else
                                      AVMEDIA_TYPE_VIDEO,
#endif
                                      NULL,
                                      CODEC_ID,
                                      NULL);
  return ret;
  }

static void destroy_codec(void * priv)
  {
  stream_codec_t * c = priv;
  if(c->codec)
    bg_ffmpeg_codec_destroy(c->codec);
  free(c);
  }

#ifndef NO_PARAMS
static const bg_parameter_info_t * get_parameters(void * priv)
  {
  stream_codec_t * c = priv;
  return bg_ffmpeg_codec_get_parameters(c->codec);
  }

static void set_parameter(void * priv, const char * name,
                          const gavl_value_t * val)
  {
  stream_codec_t * c = priv;
  bg_ffmpeg_codec_set_parameter(c->codec, name, val);
  }
#endif

#ifdef IS_AUDIO
static gavl_audio_sink_t * open_audio(void * priv,
                                      gavl_compression_info_t * ci,
                                      gavl_audio_format_t * fmt,
                                      gavl_dictionary_t * m)
  {
  stream_codec_t * c = priv;
  return bg_ffmpeg_codec_open_audio(c->codec, ci, fmt, m);
  }
#else
static gavl_video_sink_t * open_video(void * priv,
                                      gavl_compression_info_t * ci,
                                      gavl_video_format_t * fmt,
                                      gavl_dictionary_t * m)
  {
  stream_codec_t * c = priv;
  return bg_ffmpeg_codec_open_video(c->codec, ci, fmt, m);
  }
#endif

static void set_packet_sink(void * priv, gavl_packet_sink_t * s)
  {
  stream_codec_t * c = priv;
  bg_ffmpeg_codec_set_packet_sink(c->codec, s);
  }

gavl_codec_id_t compressions[] =
  {
    COMPRESSION,
    GAVL_CODEC_ID_NONE
  };

static const gavl_codec_id_t * get_compressions(void * priv)
  {
  return compressions;
  }

const bg_codec_plugin_t the_plugin =
  {
    .common =
    {
      BG_LOCALE,
      .name =            CODEC_NAME,       /* Unique short name */
      .long_name =       CODEC_LONG_NAME,
      .description =     CODEC_DESC,
#ifdef IS_AUDIO
      .type =           BG_PLUGIN_COMPRESSOR_AUDIO,
#else
      .type =           BG_PLUGIN_COMPRESSOR_VIDEO,
#endif
      .priority =        5,
      .create =          create_codec,
      .destroy =         destroy_codec,
#ifndef NO_PARAMS
      .get_parameters =    get_parameters,
      .set_parameter =     set_parameter,
#endif
    },
#ifdef IS_AUDIO
    .open_encode_audio = open_audio,
#else 
    .open_encode_video = open_video,
#endif
    .set_packet_sink = set_packet_sink,
    .get_compressions  = get_compressions,

  };
/* Include this into all plugin modules exactly once
   to let the plugin loader obtain the API version */
BG_GET_PLUGIN_API_VERSION;