comparison src/icecast/icecast.c @ 2875:9d06c6456f98

use libSAD-based converter in icecast plugin
author Andrew O. Shadoura <bugzilla@tut.by>
date Thu, 07 Aug 2008 14:00:20 +0300
parents 31d6c44ffef2
children aa6acdb93c1e
comparison
equal deleted inserted replaced
2874:11ef2164d90b 2875:9d06c6456f98
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 */ 23 */
24 24
25 #include "../filewriter/filewriter.h" 25 #include "../filewriter/filewriter.h"
26 #include "../filewriter/plugins.h" 26 #include "../filewriter/plugins.h"
27 #include "../filewriter/convert.h"
27 #include <shout/shout.h> 28 #include <shout/shout.h>
28 29
29 struct format_info input; 30 struct format_info input;
30 31
31 static GtkWidget *configure_win = NULL, *configure_vbox; 32 static GtkWidget *configure_win = NULL, *configure_vbox;
323 shout_set_metadata(shout, sm); 324 shout_set_metadata(shout, sm);
324 shout_metadata_free(sm); 325 shout_metadata_free(sm);
325 } 326 }
326 } 327 }
327 328
329 convert_init(fmt, plugin.format_required, nch);
330
328 rv = (plugin.open)(); 331 rv = (plugin.open)();
329 332
330 g_debug("ICE_OPEN"); 333 g_debug("ICE_OPEN");
331 return rv; 334 return rv;
332 } 335 }
333 336
334 static void convert_buffer(gpointer buffer, gint length)
335 {
336 gint i;
337
338 if (input.format == FMT_S8)
339 {
340 guint8 *ptr1 = buffer;
341 gint8 *ptr2 = buffer;
342
343 for (i = 0; i < length; i++)
344 *(ptr1++) = *(ptr2++) + 128;
345 }
346 if (input.format == FMT_S16_BE)
347 {
348 gint16 *ptr = buffer;
349
350 for (i = 0; i < length >> 1; i++, ptr++)
351 *ptr = GINT16_FROM_BE(*ptr);
352 }
353 if (input.format == FMT_S16_LE)
354 {
355 gint16 *ptr = buffer;
356
357 for (i = 0; i < length >> 1; i++, ptr++)
358 *ptr = GINT16_FROM_LE(*ptr);
359 }
360 if (input.format == FMT_U16_BE)
361 {
362 gint16 *ptr1 = buffer;
363 guint16 *ptr2 = buffer;
364
365 for (i = 0; i < length >> 1; i++, ptr2++)
366 *(ptr1++) = GUINT16_FROM_BE(*ptr2) - 32768;
367 }
368 if (input.format == FMT_U16_LE)
369 {
370 gint16 *ptr1 = buffer;
371 guint16 *ptr2 = buffer;
372
373 for (i = 0; i < length >> 1; i++, ptr2++)
374 *(ptr1++) = GUINT16_FROM_LE(*ptr2) - 32768;
375 }
376 if (input.format == FMT_U16_NE)
377 {
378 gint16 *ptr1 = buffer;
379 guint16 *ptr2 = buffer;
380
381 for (i = 0; i < length >> 1; i++, ptr2++)
382 *(ptr1++) = (*ptr2) - 32768;
383 }
384 }
385
386 static void ice_write(void *ptr, gint length) 337 static void ice_write(void *ptr, gint length)
387 { 338 {
388 if (input.format == FMT_S8 || input.format == FMT_U16_NE || 339 int len;
389 input.format == FMT_U16_LE || input.format == FMT_U16_BE) 340
390 convert_buffer(ptr, length); 341 len = convert_process(ptr, length);
391 #ifdef WORDS_BIGENDIAN 342
392 if (input.format == FMT_S16_LE) 343 plugin.write(convert_output, length);
393 convert_buffer(ptr, length);
394 #else
395 if (input.format == FMT_S16_BE)
396 convert_buffer(ptr, length);
397 #endif
398
399 plugin.write(ptr, length);
400 } 344 }
401 345
402 static gint ice_real_write(void* ptr, gint length) 346 static gint ice_real_write(void* ptr, gint length)
403 { 347 {
404 gint ret; 348 gint ret;
435 } 379 }
436 380
437 static gboolean ice_real_close(gpointer data) 381 static gboolean ice_real_close(gpointer data)
438 { 382 {
439 plugin.close(); 383 plugin.close();
384 convert_free();
440 385
441 if (shout) 386 if (shout)
442 { 387 {
443 written = 0; 388 written = 0;
444 shout_close(shout); 389 shout_close(shout);