~ubuntu-branches/ubuntu/wily/gmerlin-encoders/wily-proposed

« back to all changes in this revision

Viewing changes to plugins/ogg/e_theora.c

  • Committer: Bazaar Package Importer
  • Author(s): IOhannes m zmoelnig (gpg-key at iem)
  • Date: 2011-01-15 20:19:05 UTC
  • Revision ID: james.westby@ubuntu.com-20110115201905-qign5pihv1b977ct
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************
 
2
 * gmerlin-encoders - encoder plugins for gmerlin
 
3
 *
 
4
 * Copyright (c) 2001 - 2011 Members of the Gmerlin project
 
5
 * gmerlin-general@lists.sourceforge.net
 
6
 * http://gmerlin.sourceforge.net
 
7
 *
 
8
 * This program is free software: you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation, either version 2 of the License, or
 
11
 * (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
 * *****************************************************************/
 
21
 
 
22
#include <string.h>
 
23
#include <stdlib.h>
 
24
#include <config.h>
 
25
#include <gmerlin_encoders.h>
 
26
 
 
27
#include <gmerlin/plugin.h>
 
28
#include <gmerlin/utils.h>
 
29
#include <gmerlin/translation.h>
 
30
 
 
31
#include <theora/theora.h>
 
32
 
 
33
#include "ogg_common.h"
 
34
 
 
35
extern const bg_ogg_codec_t bg_theora_codec;
 
36
extern const bg_ogg_codec_t bg_vorbis_codec;
 
37
 
 
38
#ifdef HAVE_SPEEX
 
39
extern const bg_ogg_codec_t bg_speex_codec;
 
40
#endif
 
41
 
 
42
#ifdef HAVE_FLAC
 
43
extern const bg_ogg_codec_t bg_flacogg_codec;
 
44
#endif
 
45
 
 
46
static bg_ogg_codec_t const * const audio_codecs[] =
 
47
  {
 
48
    &bg_vorbis_codec,
 
49
#ifdef HAVE_SPEEX
 
50
    &bg_speex_codec,
 
51
#endif
 
52
#ifdef HAVE_FLAC
 
53
    &bg_flacogg_codec,
 
54
#endif
 
55
    NULL,
 
56
  };
 
57
 
 
58
 
 
59
static const bg_parameter_info_t * get_audio_parameters_theora(void * data)
 
60
  {
 
61
  return bg_ogg_encoder_get_audio_parameters(data, audio_codecs);
 
62
  }
 
63
 
 
64
static const bg_parameter_info_t * get_video_parameters_theora(void * data)
 
65
  {
 
66
  return bg_theora_codec.get_parameters();
 
67
  }
 
68
 
 
69
static int add_audio_stream_theora(void * data,
 
70
                                   const char * language,
 
71
                                   const gavl_audio_format_t * format)
 
72
  {
 
73
  int ret;
 
74
  ret = bg_ogg_encoder_add_audio_stream(data, format);
 
75
  return ret;
 
76
  }
 
77
 
 
78
static int add_audio_stream_compressed_theora(void * data,
 
79
                                              const char * language,
 
80
                                              const gavl_audio_format_t * format,
 
81
                                              const gavl_compression_info_t * ci)
 
82
  {
 
83
  int ret;
 
84
  ret = bg_ogg_encoder_add_audio_stream_compressed(data, format, ci);
 
85
  if(ci->id == GAVL_CODEC_ID_VORBIS)
 
86
    bg_ogg_encoder_init_audio_stream(data, ret, &bg_vorbis_codec);
 
87
  return ret;
 
88
  }
 
89
 
 
90
static int add_video_stream_theora(void * data, const gavl_video_format_t * format)
 
91
  {
 
92
  int ret;
 
93
  ret = bg_ogg_encoder_add_video_stream(data, format);
 
94
  bg_ogg_encoder_init_video_stream(data, ret, &bg_theora_codec);
 
95
  return ret;
 
96
  }
 
97
 
 
98
static int add_video_stream_compressed_theora(void * data,
 
99
                                              const gavl_video_format_t * format,
 
100
                                              const gavl_compression_info_t * ci)
 
101
  {
 
102
  int ret;
 
103
  ret = bg_ogg_encoder_add_video_stream_compressed(data, format, ci);
 
104
  bg_ogg_encoder_init_video_stream(data, ret, &bg_theora_codec);
 
105
  return ret;
 
106
  }
 
107
 
 
108
 
 
109
static void set_audio_parameter_theora(void * data, int stream,
 
110
                                       const char * name, const bg_parameter_value_t * val)
 
111
  {
 
112
  int i;
 
113
  if(!name)
 
114
    return;
 
115
  if(!strcmp(name, "codec"))
 
116
    {
 
117
    i = 0;
 
118
    
 
119
    while(audio_codecs[i])
 
120
      {
 
121
      if(!strcmp(audio_codecs[i]->name, val->val_str))
 
122
        {
 
123
        bg_ogg_encoder_init_audio_stream(data, stream, audio_codecs[i]);
 
124
        break;
 
125
        }
 
126
      i++;
 
127
      }
 
128
    }
 
129
  else
 
130
    bg_ogg_encoder_set_audio_parameter(data, stream, name, val);
 
131
  }
 
132
 
 
133
static int
 
134
open_theora(void * data, const char * file,
 
135
            const bg_metadata_t * metadata, const bg_chapter_list_t * chapter_list)
 
136
  {
 
137
  return bg_ogg_encoder_open(data, file, metadata, chapter_list,
 
138
                             "ogv");
 
139
  }
 
140
 
 
141
static int writes_compressed_audio_theora(void* data,
 
142
                                   const gavl_audio_format_t * format,
 
143
                                   const gavl_compression_info_t * ci)
 
144
  {
 
145
  if(ci->id == GAVL_CODEC_ID_VORBIS)
 
146
    return 1;
 
147
  else
 
148
    return 0;
 
149
  }
 
150
 
 
151
static int writes_compressed_video_theora(void * data,
 
152
                                   const gavl_video_format_t * format,
 
153
                                   const gavl_compression_info_t * ci)
 
154
  {
 
155
  if(ci->id == GAVL_CODEC_ID_THEORA)
 
156
    return 1;
 
157
  else
 
158
    return 0;
 
159
  }
 
160
 
 
161
const bg_encoder_plugin_t the_plugin =
 
162
  {
 
163
    .common =
 
164
    {
 
165
      BG_LOCALE,
 
166
      .name =            "e_theora",       /* Unique short name */
 
167
      .long_name =       TRS("Theora encoder"),
 
168
      .description =     TRS("Encoder for Theora files. Audio can be Vorbis, Flac or Speex."),
 
169
      .type =            BG_PLUGIN_ENCODER,
 
170
      .flags =           BG_PLUGIN_FILE,
 
171
      .priority =        5,
 
172
      .create =            bg_ogg_encoder_create,
 
173
      .destroy =           bg_ogg_encoder_destroy,
 
174
#if 0
 
175
      .get_parameters =    get_parameters_theora,
 
176
      .set_parameter =     set_parameter_theora,
 
177
#endif
 
178
    },
 
179
    .max_audio_streams =   -1,
 
180
    .max_video_streams =   -1,
 
181
    
 
182
    .set_callbacks =       bg_ogg_encoder_set_callbacks,
 
183
    .writes_compressed_audio = writes_compressed_audio_theora,
 
184
    .writes_compressed_video = writes_compressed_video_theora,
 
185
    
 
186
    .open =                open_theora,
 
187
    
 
188
    .get_audio_parameters =    get_audio_parameters_theora,
 
189
    .get_video_parameters =    get_video_parameters_theora,
 
190
 
 
191
    .add_audio_stream =        add_audio_stream_theora,
 
192
    .add_video_stream =        add_video_stream_theora,
 
193
 
 
194
    .add_audio_stream_compressed = add_audio_stream_compressed_theora,
 
195
    .add_video_stream_compressed = add_video_stream_compressed_theora,
 
196
    
 
197
    .set_audio_parameter =     set_audio_parameter_theora,
 
198
    .set_video_parameter =     bg_ogg_encoder_set_video_parameter,
 
199
    .set_video_pass      =     bg_ogg_encoder_set_video_pass,
 
200
    
 
201
    .start =                  bg_ogg_encoder_start,
 
202
 
 
203
    .get_audio_format =        bg_ogg_encoder_get_audio_format,
 
204
    .get_video_format =        bg_ogg_encoder_get_video_format,
 
205
    
 
206
    .write_audio_frame =   bg_ogg_encoder_write_audio_frame,
 
207
    .write_video_frame =   bg_ogg_encoder_write_video_frame,
 
208
 
 
209
    .write_audio_packet =   bg_ogg_encoder_write_audio_packet,
 
210
    .write_video_packet =   bg_ogg_encoder_write_video_packet,
 
211
 
 
212
    .close =               bg_ogg_encoder_close,
 
213
  };
 
214
 
 
215
/* Include this into all plugin modules exactly once
 
216
   to let the plugin loader obtain the API version */
 
217
BG_GET_PLUGIN_API_VERSION;