2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 /*#define DEBUG_ENABLED */
25 #include <wine/winbase.h>
26 #include <wine/winerror.h>
27 #include <wine/driver.h>
28 #include <wine/msacm.h>
30 #include <gstavidecoder.h>
32 typedef struct _GstWinLoaderAudioData GstWinLoaderAudioData;
34 struct _GstWinLoaderAudioData {
42 static GstPad *gst_avi_decoder_get_audio_srcpad_MPEG(GstAviDecoder *avi_decoder, guint pad_nr, GstPadTemplate *temp);
43 static GstPad *gst_avi_decoder_get_audio_srcpad_winloader(GstAviDecoder *avi_decoder, guint pad_nr, gst_riff_strf_auds *strf, GstPadTemplate *temp);
44 static void gst_avi_decoder_winloader_audio_chain(GstPad *pad, GstBuffer *buf);
46 GstPad *gst_avi_decoder_get_audio_srcpad(GstAviDecoder *avi_decoder, guint pad_nr, gst_riff_strf_auds *strf, GstPadTemplate *temp)
50 switch (strf->format) {
51 case GST_RIFF_WAVE_FORMAT_PCM:
52 newpad = gst_pad_new("audio_00", GST_PAD_SRC);
53 gst_pad_try_set_caps (newpad,
57 "format", GST_PROPS_STRING ("int"),
58 "law", GST_PROPS_INT (0),
59 "endianness", GST_PROPS_INT (G_BYTE_ORDER),
60 "signed", GST_PROPS_BOOLEAN (TRUE),
61 "width", GST_PROPS_INT ((gint)strf->size),
62 "depth", GST_PROPS_INT ((gint)strf->size),
63 "rate", GST_PROPS_INT ((gint)strf->rate),
64 "channels", GST_PROPS_INT ((gint)strf->channels)
67 avi_decoder->audio_pad[pad_nr] = newpad;
69 case GST_RIFF_WAVE_FORMAT_MPEGL12:
70 case GST_RIFF_WAVE_FORMAT_MPEGL3:
71 return gst_avi_decoder_get_audio_srcpad_MPEG(avi_decoder, pad_nr, temp);
73 newpad = gst_avi_decoder_get_audio_srcpad_winloader(avi_decoder, pad_nr, strf, temp);
74 if (newpad) return newpad;
75 printf("audio format %04x not supported\n", strf->format);
81 static GstPad *gst_avi_decoder_get_audio_srcpad_MPEG(GstAviDecoder *avi_decoder, guint pad_nr, GstPadTemplate *temp)
83 GstElement *parse_audio, *decode;
84 GstPad *srcpad, *sinkpad, *newpad;
86 parse_audio = gst_elementfactory_make("mp3parse", "parse_audio");
87 g_return_val_if_fail(parse_audio != NULL, NULL);
88 decode = gst_elementfactory_make("mpg123", "decode_audio");
89 g_return_val_if_fail(decode != NULL, NULL);
91 gst_element_set_state(GST_ELEMENT(gst_object_get_parent(GST_OBJECT(avi_decoder))), GST_STATE_PAUSED);
93 gst_bin_add(GST_BIN(gst_object_get_parent(GST_OBJECT(avi_decoder))), parse_audio);
94 gst_bin_add(GST_BIN(gst_object_get_parent(GST_OBJECT(avi_decoder))), decode);
96 newpad = gst_pad_new("video", GST_PAD_SRC);
97 gst_pad_set_parent(newpad, GST_OBJECT(avi_decoder));
99 sinkpad = gst_element_get_pad(parse_audio,"sink");
100 gst_pad_connect(gst_element_get_pad(parse_audio,"src"),
101 gst_element_get_pad(decode,"sink"));
102 gst_pad_set_chain_function (gst_element_get_pad(parse_audio,"src"),
103 GST_RPAD_CHAINFUNC (gst_element_get_pad(decode,"sink")));
104 srcpad = gst_element_get_pad(decode,"src");
106 gst_pad_connect(newpad, sinkpad);
107 gst_pad_set_name(srcpad, "audio_00");
108 gst_pad_set_chain_function (newpad, GST_RPAD_CHAINFUNC (sinkpad));
110 avi_decoder->audio_pad[pad_nr] = newpad;
111 gst_element_set_state(GST_ELEMENT(gst_object_get_parent(GST_OBJECT(avi_decoder))), GST_STATE_PLAYING);
116 static GstPad *gst_avi_decoder_get_audio_srcpad_winloader(GstAviDecoder *avi_decoder, guint pad_nr, gst_riff_strf_auds *strf, GstPadTemplate *temp)
119 GstWinLoaderAudioData *data;
120 GstPad *sinkpad, *newpad;
122 if (!gst_library_load("winloader")) {
123 gst_info("audiocodecs: could not load support library: 'winloader'\n");
126 gst_info("audiocodecs: winloader loaded\n");
128 avi_decoder->extra_data = g_malloc0(sizeof(GstWinLoaderAudioData));
130 data = (GstWinLoaderAudioData *)avi_decoder->extra_data;
132 memcpy(data->ext_info, strf, sizeof(WAVEFORMATEX));
133 memset(data->ext_info+18, 0, 32);
138 data->wf.nChannels=strf->channels;
139 data->wf.nSamplesPerSec=strf->rate;
140 data->wf.nAvgBytesPerSec=2*data->wf.nSamplesPerSec*data->wf.nChannels;
141 data->wf.wFormatTag=strf->format;
142 data->wf.nBlockAlign=strf->blockalign;
143 data->wf.wBitsPerSample=strf->av_bps;
146 gst_info("audiocodecs: trying to open library %p\n", data);
150 (WAVEFORMATEX*)data->ext_info,
151 (WAVEFORMATEX*)&data->wf,
159 if(h == ACMERR_NOTPOSSIBLE) {
160 printf("audiocodecs:: Unappropriate audio format\n");
162 printf("audiocodecs:: acmStreamOpen error\n");
166 newpad = gst_pad_new("audio", GST_PAD_SINK);
167 gst_pad_set_parent(newpad, GST_OBJECT(avi_decoder));
168 gst_pad_set_chain_function(newpad, gst_avi_decoder_winloader_audio_chain);
170 sinkpad = gst_pad_new("audio_00", GST_PAD_SRC);
171 gst_pad_set_parent(sinkpad, GST_OBJECT(avi_decoder));
172 gst_pad_connect(newpad, sinkpad);
173 gst_pad_set_chain_function (newpad, GST_RPAD_CHAINFUNC (sinkpad));
175 /*gst_pad_connect(newpad, sinkpad); */
176 avi_decoder->audio_pad[pad_nr] = newpad;
180 GST_DEBUG (0,"gst_avi_decoder: pads created");
184 static void gst_avi_decoder_winloader_audio_chain(GstPad *pad, GstBuffer *buf)
187 GST_DEBUG (0,"gst_avi_decoder: got buffer %08lx %p", *(gulong *)GST_BUFFER_DATA(buf), GST_BUFFER_DATA(buf));
188 gst_buffer_unref(buf);