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
|
/*
* Copyright (C) 2000-2004 the xine project
*
* This file is part of xine, a free video player.
*
* xine 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.
*
* xine 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
* $Id: vdr.c,v 1.20 2004/04/17 19:54:32 mroi Exp $
*/
/*
* select audio channel plugin for VDR
*/
#define LOG_MODULE "vdr_audio"
#define LOG_VERBOSE
/*
#define LOG
*/
#include "xine_internal.h"
#include "post.h"
#include "post_vdr.h"
typedef struct vdr_audio_post_plugin_s
{
post_plugin_t post_plugin;
xine_event_queue_t *event_queue;
xine_stream_t *vdr_stream;
uint8_t audio_channels;
int num_channels;
}
vdr_audio_post_plugin_t;
static void vdr_audio_select_audio(vdr_audio_post_plugin_t *this, uint8_t channels)
{
this->audio_channels = channels;
}
/* plugin class functions */
static post_plugin_t *vdr_audio_open_plugin(post_class_t *class_gen, int inputs,
xine_audio_port_t **audio_target,
xine_video_port_t **video_target);
static char *vdr_audio_get_identifier(post_class_t *class_gen);
static char *vdr_audio_get_description(post_class_t *class_gen);
static void vdr_audio_class_dispose(post_class_t *class_gen);
/* plugin instance functions */
static void vdr_audio_dispose(post_plugin_t *this_gen);
/* replaced ao_port functions */
static int vdr_audio_port_open(xine_audio_port_t *port_gen, xine_stream_t *stream,
uint32_t bits, uint32_t rate, int mode);
static void vdr_audio_port_put_buffer(xine_audio_port_t *port_gen, audio_buffer_t *buf, xine_stream_t *stream);
void *vdr_audio_init_plugin(xine_t *xine, void *data)
{
post_class_t *class = (post_class_t *)malloc(sizeof (post_class_t));
if (!class)
return NULL;
class->open_plugin = vdr_audio_open_plugin;
class->get_identifier = vdr_audio_get_identifier;
class->get_description = vdr_audio_get_description;
class->dispose = vdr_audio_class_dispose;
return class;
}
static post_plugin_t *vdr_audio_open_plugin(post_class_t *class_gen, int inputs,
xine_audio_port_t **audio_target,
xine_video_port_t **video_target)
{
vdr_audio_post_plugin_t *this = (vdr_audio_post_plugin_t *)xine_xmalloc(sizeof (vdr_audio_post_plugin_t));
post_in_t *input;
post_out_t *output;
post_audio_port_t *port;
/*
fprintf(stderr, "~~~~~~~~~~ vdr open plugin\n");
*/
if (!this || !audio_target || !audio_target[ 0 ])
{
free(this);
return NULL;
}
_x_post_init(&this->post_plugin, 1, 0);
this->post_plugin.dispose = vdr_audio_dispose;
port = _x_post_intercept_audio_port(&this->post_plugin, audio_target[ 0 ], &input, &output);
port->new_port.open = vdr_audio_port_open;
port->new_port.put_buffer = vdr_audio_port_put_buffer;
this->post_plugin.xine_post.audio_input[ 0 ] = &port->new_port;
this->audio_channels = 0;
return &this->post_plugin;
}
static char *vdr_audio_get_identifier(post_class_t *class_gen)
{
return "vdr_audio";
}
static char *vdr_audio_get_description(post_class_t *class_gen)
{
return "modifies every audio frame as requested by VDR";
}
static void vdr_audio_class_dispose(post_class_t *class_gen)
{
free(class_gen);
}
static void vdr_audio_dispose(post_plugin_t *this_gen)
{
/*
fprintf(stderr, "~~~~~~~~~~ vdr dispose\n");
*/
if (_x_post_dispose(this_gen))
{
vdr_audio_post_plugin_t *this = (vdr_audio_post_plugin_t *)this_gen;
if (this->vdr_stream)
xine_event_dispose_queue(this->event_queue);
free(this_gen);
}
}
static int vdr_audio_port_open(xine_audio_port_t *port_gen, xine_stream_t *stream,
uint32_t bits, uint32_t rate, int mode) {
post_audio_port_t *port = (post_audio_port_t *)port_gen;
vdr_audio_post_plugin_t *this = (vdr_audio_post_plugin_t *)port->post;
_x_post_rewire(&this->post_plugin);
_x_post_inc_usage(port);
/*
fprintf(stderr, "~~~~~~~~~~ vdr port open\n");
*/
port->stream = stream;
port->bits = bits;
port->rate = rate;
port->mode = mode;
this->num_channels = _x_ao_mode2channels(mode);
return port->original_port->open(port->original_port, stream, bits, rate, mode );
}
static void vdr_audio_port_put_buffer(xine_audio_port_t *port_gen, audio_buffer_t *buf, xine_stream_t *stream)
{
post_audio_port_t *port = (post_audio_port_t *)port_gen;
vdr_audio_post_plugin_t *this = (vdr_audio_post_plugin_t *)port->post;
xine_event_t *event;
/*
fprintf(stderr, "~~~~~~ vdr_audio\n");
*/
if (this->vdr_stream
&& !_x_continue_stream_processing(this->vdr_stream))
{
this->vdr_stream = 0;
xine_event_dispose_queue(this->event_queue);
this->event_queue = 0;
this->audio_channels = 0;
}
if (!this->vdr_stream
&& vdr_is_vdr_stream(stream))
{
this->event_queue = xine_event_new_queue(stream);
if (this->event_queue)
{
this->vdr_stream = stream;
{
xine_event_t event;
event.type = XINE_EVENT_VDR_PLUGINSTARTED;
event.data = 0;
event.data_length = 1; /* vdr_audio */
xine_event_send(this->vdr_stream, &event);
}
}
}
if (this->event_queue)
{
while ((event = xine_event_get(this->event_queue)))
{
if (event->type == XINE_EVENT_VDR_SELECTAUDIO)
{
vdr_select_audio_data_t *data = (vdr_select_audio_data_t *)event->data;
vdr_audio_select_audio(this, data->channels);
}
xine_event_free(event);
}
}
if (this->num_channels == 2
&& this->audio_channels != 0
&& this->audio_channels != 3)
{
audio_buffer_t *vdr_buf = port->original_port->get_buffer(port->original_port);
vdr_buf->num_frames = buf->num_frames;
vdr_buf->vpts = buf->vpts;
vdr_buf->frame_header_count = buf->frame_header_count;
vdr_buf->first_access_unit = buf->first_access_unit;
/* FIXME: The audio buffer should contain this info.
* We should not have to get it from the open call.
*/
vdr_buf->format.bits = buf->format.bits;
vdr_buf->format.rate = buf->format.rate;
vdr_buf->format.mode = buf->format.mode;
_x_extra_info_merge(vdr_buf->extra_info, buf->extra_info);
{
int step = buf->format.bits / 8;
uint8_t *src = (uint8_t *)buf->mem;
uint8_t *dst = (uint8_t *)vdr_buf->mem;
if (this->audio_channels == 2)
src += step;
/*
fprintf(stderr, "~~~~~~~~~~ vdr port put buffer: channels: %d, %d\n"
, this->audio_channels
, buf->format.bits);
*/
int i, k;
for (i = 0; i < buf->num_frames; i++)
{
for (k = 0; k < step; k++)
*dst++ = *src++;
src -= step;
for (k = 0; k < step; k++)
*dst++ = *src++;
src += step;
}
}
/* pass data to original port */
port->original_port->put_buffer(port->original_port, vdr_buf, stream);
/* free data from origial buffer */
buf->num_frames = 0; /* UNDOCUMENTED, but hey, it works! Force old audio_out buffer free. */
}
port->original_port->put_buffer(port->original_port, buf, stream);
return;
}
|