annotate test/testpower.c @ 5080:6d94060d16a9

Fixed bug #1011 Daniel Ellis 2010-06-25 15:20:31 PDT SDL based applications sometimes display the wrong application name in the Sound Preferences dialog when using pulseaudio. I can see from the code that the SDL pulse module is initiating a new pulse audio context and passing an application name using the function get_progname(). The get_progname() function returns the name of the current process. However, the process name is often not a suitable name to use. For example, the OpenShot video editor is a python application, and so "python" is displayed in the Sound Preferences window (see Bug #596504), when it should be displaying "OpenShot". PulseAudio allows applications to specify the application name, either at the time the context is created (as SDL does currently), or by special environment variables (see http://www.pulseaudio.org/wiki/ApplicationProperties). If no name is specified, then pulseaudio will determine the name based on the process. If you specify the application name when initiating the pulseaudio context, then that will override any application name specified using an environment variable. As libsdl is a library, I believe the solution is for libsdl to not specify any application name when initiating a pulseaudio context, which will enable applications to specify the application name using environment variables. In the case that the applications do not specify anything, pulseaudio will fall back to using the process name anyway. The attached patch removes the get_progname() function and passes NULL as the application name when creating the pulseaudio context, which fixes the issue.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 23 Jan 2011 21:55:04 -0800 (2011-01-24)
parents 51750b7a966f
children
rev   line source
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /* Simple test of power subsystem. */
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
3 #include <stdio.h>
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4 #include "SDL.h"
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
6 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
7 report_power(void)
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
8 {
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9 int seconds, percent;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 char *statestr = NULL;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
13 printf("SDL-reported power info...\n");
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
14 switch (state) {
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
15 case SDL_POWERSTATE_UNKNOWN:
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
16 statestr = "Unknown";
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
17 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
18 case SDL_POWERSTATE_ON_BATTERY:
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
19 statestr = "On battery";
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
20 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
21 case SDL_POWERSTATE_NO_BATTERY:
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
22 statestr = "No battery";
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
23 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
24 case SDL_POWERSTATE_CHARGING:
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
25 statestr = "Charging";
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
26 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
27 case SDL_POWERSTATE_CHARGED:
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
28 statestr = "Charged";
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
29 break;
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
30 default:
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
31 statestr = "!!API ERROR!!";
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
32 break;
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 }
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35 printf("State: %s\n", statestr);
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
37 if (percent == -1) {
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
38 printf("Percent left: unknown\n");
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
39 } else {
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40 printf("Percent left: %d%%\n", percent);
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 }
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 if (seconds == -1) {
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 printf("Time left: unknown\n");
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 } else {
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
46 printf("Time left: %d minutes, %d seconds\n", (int) (seconds / 60),
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
47 (int) (seconds % 60));
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 }
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 }
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51
3186
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
52 int
Sam Lantinga <slouken@libsdl.org>
parents: 3170
diff changeset
53 main(int argc, char *argv[])
3170
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54 {
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 if (SDL_Init(SDL_INIT_VIDEO) == -1) {
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
56 fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 return 1;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 }
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 report_power();
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 SDL_Quit();
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 return 0;
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 }
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65
b7a48f533966 Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 /* end of testpower.c ... */