[maemo-commits] [maemo-commits] r8354 - in projects/haf/trunk/osso-af-utils: debian src

From: www-data at stage.maemo.org www-data at stage.maemo.org
Date: Mon Nov 27 15:46:12 EET 2006
Author: kihamala
Date: 2006-11-27 15:46:10 +0200 (Mon, 27 Nov 2006)
New Revision: 8354

Added:
   projects/haf/trunk/osso-af-utils/src/play-sound.c
Modified:
   projects/haf/trunk/osso-af-utils/debian/changelog
   projects/haf/trunk/osso-af-utils/debian/control
   projects/haf/trunk/osso-af-utils/src/Makefile.am
   projects/haf/trunk/osso-af-utils/src/fb-progress.c
Log:
added play-sound


Modified: projects/haf/trunk/osso-af-utils/debian/changelog
===================================================================
--- projects/haf/trunk/osso-af-utils/debian/changelog	2006-11-27 13:36:48 UTC (rev 8353)
+++ projects/haf/trunk/osso-af-utils/debian/changelog	2006-11-27 13:46:10 UTC (rev 8354)
@@ -1,3 +1,11 @@
+osso-af-utils (1.12-1) unstable; urgency=low
+
+  * UNRELEASED
+  * Added play-sound utility and JPEG loading to fb-progress. Fixes: NB#47604
+    (Patches from Riku Voipio and Gabriel Schulhof.)
+
+ -- Kimmo Hämäläinen <kimmo.hamalainen at nokia.com>  Mon, 27 Nov 2006 15:40:56 +0200
+
 osso-af-utils (1.11-1) unstable; urgency=low
 
   * Loop through _all_ arguments given to xset770. Fixes: NB#38855

Modified: projects/haf/trunk/osso-af-utils/debian/control
===================================================================
--- projects/haf/trunk/osso-af-utils/debian/control	2006-11-27 13:36:48 UTC (rev 8353)
+++ projects/haf/trunk/osso-af-utils/debian/control	2006-11-27 13:46:10 UTC (rev 8354)
@@ -2,7 +2,7 @@
 Section: base
 Priority: optional
 Maintainer: Kimmo Hämäläinen <kimmo.hamalainen at nokia.com>
-Build-Depends: debhelper (>= 4.0.0), pkg-config, libx11-dev, libdbus-1-dev (>= 0.60), libosso-dev, libxsp-dev, libpng12-dev, libgtk2.0-dev, x11proto-core-dev, x11proto-input-dev, libxi-dev
+Build-Depends: debhelper (>= 4.0.0), pkg-config, libx11-dev, libdbus-1-dev (>= 0.60), libosso-dev, libxsp-dev, libpng12-dev, libgtk2.0-dev, x11proto-core-dev, x11proto-input-dev, libxi-dev, libgconf2-dev, osso-esd-dev, libjpeg62-dev
 Standards-Version: 3.6.0
 
 Package: osso-af-utils

Modified: projects/haf/trunk/osso-af-utils/src/Makefile.am
===================================================================
--- projects/haf/trunk/osso-af-utils/src/Makefile.am	2006-11-27 13:36:48 UTC (rev 8353)
+++ projects/haf/trunk/osso-af-utils/src/Makefile.am	2006-11-27 13:46:10 UTC (rev 8354)
@@ -1,8 +1,7 @@
-bin_PROGRAMS = xset770 ageoffile
+bin_PROGRAMS = xset770 ageoffile play-sound
 sbin_PROGRAMS = waitdbus waitx runas fb-progress temp-reaper anim-shower
 
-INCLUDES = `pkg-config --cflags gdk-2.0` \
-	   `pkg-config --cflags dbus-1`
+INCLUDES = `pkg-config --cflags gdk-2.0 dbus-1` 
 
 xset770_INCLUDES = \
 	`pkg-config --cflags x11 xsp xi xproto inputproto`
@@ -11,7 +10,7 @@
 	`pkg-config --libs x11 xsp xi xproto inputproto`
 
 fb_progress_LDFLAGS = \
-	`pkg-config --libs libpng12`
+	`pkg-config --libs libpng12` -ljpeg
 
 anim_shower_LDFLAGS = \
 	`pkg-config --cflags --libs gdk-2.0`
@@ -50,6 +49,15 @@
 temp_reaper_SOURCES = \
 	temp-reaper.c
 
+play_sound_LDFLAGS = \
+     `pkg-config --libs gconf-2.0 esound`
+
+play_sound_CFLAGS = \
+     `pkg-config --cflags gconf-2.0 esound`
+
+play_sound_SOURCES = \
+	play-sound.c
+
 CURSOR_NAMES = \
 	00008160000006810000408080010102 \
 	028006030e0e7ebffc7f7070c0600140 \

Modified: projects/haf/trunk/osso-af-utils/src/fb-progress.c
===================================================================
--- projects/haf/trunk/osso-af-utils/src/fb-progress.c	2006-11-27 13:36:48 UTC (rev 8353)
+++ projects/haf/trunk/osso-af-utils/src/fb-progress.c	2006-11-27 13:46:10 UTC (rev 8354)
@@ -90,6 +90,7 @@
 #include <linux/vt.h>
 #include <linux/kd.h>
 #include <png.h>
+#include <jpeglib.h>
 /* stuff needed by fb_flush().
  */
 #include "omapfb.h"
@@ -637,6 +638,7 @@
 	/* image and screen same size */
 	if (Fb.wd == image.wd && Fb.ht == image.ht) {
 		memcpy(Fb.mem, image.pixel_buffer, Fb.size);
+		fb_dirty(0, 0, Fb.wd, Fb.ht);
 		return;
 	}
 
@@ -697,6 +699,74 @@
 	return;
 }
 
+static void rgb_to_16(uint8_t *buf, uint16_t *result, const unsigned int width)
+{
+	uint16_t *end=result+width;
+        for (; result < end; result++) {
+		uint8_t red, green, blue;
+		red = (*buf++ >> 3);
+		green = (*buf++ >> 2);
+		blue = (*buf++ >> 3);
+		*result = red << 11 | green << 5 | blue;
+        }
+}
+
+/* based on jpeglib.h example.c */
+static image_info_t *decompress_jpeg(const char *filename)
+{
+	struct jpeg_decompress_struct cinfo;
+        struct jpeg_error_mgr jerr;
+	uint16_t *tmp;
+	FILE *fp;
+	image_info_t image, *ret;
+	uint8_t *buf;
+	int a;
+	
+	cinfo.err = jpeg_std_error(&jerr);
+	jpeg_create_decompress(&cinfo);
+
+	fp = fopen(filename, "rb");
+
+	if (!fp){
+		perror("JPEG file open");
+		return NULL;
+	}
+	
+	jpeg_stdio_src(&cinfo,fp);
+	jpeg_read_header(&cinfo, TRUE);
+	jpeg_start_decompress(&cinfo);
+
+	/* If we need scaling, implement it here*/
+        image.wd = cinfo.output_width;
+        image.ht = cinfo.output_height;
+	
+	buf = malloc(cinfo.output_width * cinfo.output_components * sizeof(char));
+	if (!buf) {
+		return NULL;
+	}
+	
+	image.pixel_buffer = malloc(image.wd * image.ht *  sizeof(uint16_t));
+        if (!image.pixel_buffer) {
+                return NULL;
+	}
+	tmp=image.pixel_buffer;
+	for (a = 0; a < cinfo.output_height; a++) {
+		jpeg_read_scanlines(&cinfo, (JSAMPARRAY) &buf, 1);
+		rgb_to_16(buf, tmp, cinfo.output_width );
+		tmp+=cinfo.output_width;
+	}
+	
+	jpeg_finish_decompress(&cinfo);
+	jpeg_destroy_decompress(&cinfo);
+	fclose(fp);
+
+	free(buf);
+
+        ret = malloc (sizeof(image_info_t));
+        *ret = image;
+	return ret;
+}
+
 static image_info_t *decompress_png(const char *filename)
 {
 	FILE *fp;
@@ -713,7 +783,6 @@
 	fread(header, 1, 8, fp);
 	int is_png = !png_sig_cmp(header, 0, 8);
 	if (!is_png) {
-		fprintf(stderr, "image is not a PNG!\n");
 		return NULL;
 	}
 	
@@ -838,7 +907,7 @@
 	       "-t <vt>\t\tswitch to given virtual terminal while showing the progress\n"
 	       "-i <step>\tinitial seconds (< all secs)\n\n"
 	       "Examples:\n"
-	       "\t%s -s -c -t 3 -b ffffff -l logo.png 30\n"
+	       "\t%s -c -t 3 -b ffffff -l logo.png 30\n"
 	       "\tsleep 30\n"
 	       "\t%s -n -i 1 3\n\n"
 	       "NOTE: this program need to be run as root (for VT ioctls)!\n",
@@ -897,12 +966,16 @@
 			}
 			Options.img_logo = decompress_png(argv[i]);
 			if (!Options.img_logo) {
-				usage(*argv, "logo image loading failed");
+				/* If png fails, try jpeg */
+				Options.img_logo = decompress_jpeg(argv[i]);
+				if (!Options.img_logo) {
+					usage(*argv, "logo image loading failed");
+				}
 			}
 			break;
 		case 'g':
 			if (++i >= argc) {
-				usage(*argv, "-l <progressbar image> image file name missing");
+				usage(*argv, "-g <progressbar image> image file name missing");
 			}
 			Options.img_progress = decompress_png(argv[i]);
 			if (!Options.img_progress) {

Added: projects/haf/trunk/osso-af-utils/src/play-sound.c
===================================================================
--- projects/haf/trunk/osso-af-utils/src/play-sound.c	2006-11-27 13:36:48 UTC (rev 8353)
+++ projects/haf/trunk/osso-af-utils/src/play-sound.c	2006-11-27 13:46:10 UTC (rev 8354)
@@ -0,0 +1,221 @@
+/*
+  Copyright (C) 2006 Nokia Corporation. All rights reserved.
+ 
+  This program is free software; you can redistribute it and/or
+  modify it under the terms of the GNU General Public License
+  version 2 as published by the Free Software Foundation.
+ 
+  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, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  02110-1301 USA
+*/
+
+#include <gconf/gconf-client.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <esd.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <unistd.h>
+
+#define ALARM_GCONF_PATH "/apps/osso/sound/system_alert_volume"
+/* The full volume should be about 30% of maximum, that is 0x4C out of 0xFF.
+   The full volume is marked as 2 in gconf, divide and we get 0x26. */
+#define SCALE_MULTIPLIER 0x26
+
+/* Based on hildon_play_system_sound */
+
+/* Copypaste from esdfile.c and xmms mixer.c with (very) minor alterations. */
+/* Plays a file with esd and with scaled channels. */
+static int 
+esd_play_file_with_pan( int esd, const char *name_prefix,
+                        const char *filename, 
+                        int left_scale, 
+                        int right_scale )
+{
+    /* input from libaudiofile... */
+    AFfilehandle in_file;
+    int in_format, in_width, in_channels, frame_count;
+    double in_rate;
+    int bytes_per_frame;
+
+    /* output to esound... */
+    int out_sock, out_bits, out_channels, out_rate;
+    int out_mode = ESD_STREAM, out_func = ESD_PLAY;
+    esd_format_t out_format;
+    char name[ ESD_NAME_MAX ] = "";
+
+    esd_player_info_t *info;
+    esd_info_t *all_info = NULL;
+
+    /* open the audio file */
+    in_file = afOpenFile( filename, "rb", NULL );
+    if ( !in_file )
+	return 0;
+
+    /* get audio file parameters */
+    frame_count = afGetFrameCount( in_file, AF_DEFAULT_TRACK );
+    in_channels = afGetChannels( in_file, AF_DEFAULT_TRACK );
+    in_rate = afGetRate( in_file, AF_DEFAULT_TRACK );
+    afGetSampleFormat( in_file, AF_DEFAULT_TRACK, &in_format, &in_width );
+
+    if(getenv("ESDBG")) 
+    {
+        printf ("frames: %i channels: %i rate: %f format: %i width: %i\n",
+                frame_count, in_channels, in_rate, in_format, in_width);
+    }
+
+    /* convert audiofile parameters to EsounD parameters */
+    if ( in_width == 8 )
+        out_bits = ESD_BITS8;
+    else if ( in_width == 16 )
+        out_bits = ESD_BITS16;
+    else
+	return 0;
+
+    bytes_per_frame = ( in_width  * in_channels ) / 8;
+
+    if ( in_channels == 1 )
+	out_channels = ESD_MONO;
+    else if ( in_channels == 2 )
+	out_channels = ESD_STEREO;
+    else
+	return 0;
+
+    out_format = out_bits | out_channels | out_mode | out_func;
+    out_rate = (int) in_rate;
+
+    /* construct name */
+    if ( name_prefix ) 
+    {
+        strncpy( name, name_prefix, ESD_NAME_MAX - 2 );
+        strcat( name, ":" );
+    }
+    strncpy( name + strlen( name ), filename, ESD_NAME_MAX - strlen( name ) );
+
+    /* connect to server and play stream */
+    out_sock = esd_play_stream( out_format, out_rate, NULL, filename );
+
+    if ( out_sock <= 0 ) {
+        /* Close the AF filehandle too */
+        afCloseFile ( in_file );
+        return 0;
+    }
+
+    all_info = esd_get_all_info(esd);
+    for (info = all_info->player_list; info != NULL; info = info->next) 
+    {
+      if (!strcmp(filename, info->name)) 
+      {
+	break;
+      }
+    }
+    if (info != NULL) 
+    {
+      esd_set_stream_pan(esd, info->source_id,
+	  left_scale, right_scale);
+    }
+    esd_free_all_info(all_info);
+    
+    /* play */
+    esd_send_file( out_sock, in_file, bytes_per_frame );
+
+    /* close up and go home */
+    close( out_sock );
+    if ( afCloseFile ( in_file ) )
+    {
+	return 0;
+    }
+
+    return 1;
+}
+
+
+static void
+wait_for_esd_server_to_quiesce (int esd_fd)
+{
+    char *buf = NULL ;
+    esd_server_info_t *esd_server_info = NULL ;
+    int monitor_fd = -1, read_return = -1, available_bytes = 1, max_avail = 1 ;
+
+    if (NULL != (esd_server_info = esd_get_server_info (esd_fd)))
+    {
+        if ((monitor_fd = esd_monitor_stream (esd_server_info->format, esd_server_info->rate, NULL, NULL)) > 0)
+        {
+            buf = malloc (available_bytes) ;
+            while (TRUE)
+            {
+                ioctl (monitor_fd, FIONREAD, &available_bytes) ;
+                if (available_bytes > max_avail)
+                {
+                    buf = realloc (buf, max_avail) ;
+					max_avail = available_bytes ;
+                }
+                read_return = read (monitor_fd, &buf, available_bytes) ;
+                if (read_return <= 0) break ;
+            }
+			free (buf) ;
+            close (monitor_fd) ;
+        }
+        esd_free_server_info (esd_server_info) ;
+    }
+}
+
+static gpointer 
+play_sound(gchar *sound_filename,
+           gchar *data) 
+{
+    gint sock, pan;
+    GConfClient *gc;
+    GConfValue *value;
+
+	g_type_init () ;
+
+    gc = gconf_client_get_default();
+    value = gconf_client_get(gc, ALARM_GCONF_PATH, NULL);
+
+    if (value && value->type == GCONF_VALUE_INT) 
+    {
+      pan = gconf_value_get_int(value);
+    } 
+    else 
+    {
+      pan = 2;
+    }
+
+    if (value) 
+    {
+        gconf_value_free(value);
+    }
+    g_object_unref(G_OBJECT(gc));
+
+    pan *= SCALE_MULTIPLIER;
+    sock = esd_open_sound(NULL);
+
+    esd_play_file_with_pan(sock, data,
+		  sound_filename, pan, pan);
+
+    wait_for_esd_server_to_quiesce (sock) ;
+
+    esd_close(sock);
+
+    return NULL;
+}
+
+int main(int argc, char **argv) {
+  
+   if (argc < 2) {
+    fprintf(stderr, "usage: %s sound.wav\n",argv[0]);	
+    return 1;
+   }
+   else 
+     return play_sound(argv[1], NULL);
+}


More information about the maemo-commits mailing list