[xiph-commits] r3096 - liboggplay/trunk/plugin
tahn at svn.annodex.net
tahn at svn.annodex.net
Wed Jun 27 02:56:48 PDT 2007
Author: tahn
Date: 2007-06-27 02:56:48 -0700 (Wed, 27 Jun 2007)
New Revision: 3096
Modified:
liboggplay/trunk/plugin/plugin_gui_mac.c
Log:
Added volume control.
Modified: liboggplay/trunk/plugin/plugin_gui_mac.c
===================================================================
--- liboggplay/trunk/plugin/plugin_gui_mac.c 2007-06-27 09:47:54 UTC (rev 3095)
+++ liboggplay/trunk/plugin/plugin_gui_mac.c 2007-06-27 09:56:48 UTC (rev 3096)
@@ -39,11 +39,6 @@
#include "sydney_audio_new.h"
#include <oggplay/oggplay_tools.h>
-/*
- * PluginWindowInfo is used by both the main thread and the display thread.
- * ThreadData is used only by the display thread.
- */
-
typedef enum {
NO_CHANGE,
SET_PAUSE,
@@ -51,6 +46,7 @@
} PluginStateChange;
typedef struct {
+ nsPluginInstance * plugin_instance;
CGrafPtr port;
int media_x;
int media_y;
@@ -71,7 +67,8 @@
PluginStateChange playback_state_change;
bool playback_finished;
semaphore playback_sem;
- nsPluginInstance * plugin_instance;
+ float volume;
+ int set_volume;
} PluginWindowInfo;
typedef struct {
@@ -391,6 +388,7 @@
info->oggplay_handle = info->new_oggplay_handle;
info->new_oggplay_handle = NULL;
shutdown_audio(info, &td);
+ info->set_volume = 1;
playback_target = 0;
info->playback_finished = FALSE;
if (paused) {
@@ -422,6 +420,7 @@
* Flush the audio buffers when the user seeks.
*/
shutdown_audio(info, &td);
+ info->set_volume = 1;
playback_target = 0;
break;
case OGGPLAY_STREAM_LAST_DATA:
@@ -513,6 +512,10 @@
audio_ok = init_audio(info, &td);
}
if (td.audio_handle != NULL) {
+ if (info->set_volume) {
+ sa_stream_set_volume_abs(td.audio_handle, info->volume);
+ info->set_volume = 0;
+ }
if (sa_stream_write(td.audio_handle, td.frame_data.samples,
td.frame_data.size) != SA_SUCCESS) {
/*
@@ -595,6 +598,7 @@
PluginWindowInfo * info;
info = malloc(sizeof(PluginWindowInfo));
+ info->plugin_instance = plugin_instance;
info->port = ((NP_Port *)np_window->window)->port;
info->media_x = np_window->x;
info->media_y = np_window->y;
@@ -611,7 +615,8 @@
info->playback_state = PLAYING;
info->playback_finished = FALSE;
info->playback_state_change = NO_CHANGE;
- info->plugin_instance = plugin_instance;
+ info->volume = 1;
+ info->set_volume = 1;
/*
* Create semaphores to coordinate window resizing, replacement of the
@@ -682,9 +687,7 @@
SEM_CLOSE(info->display_resize_sem);
SEM_CLOSE(info->oggplay_replace_sem);
SEM_CLOSE(info->playback_sem);
-
shut_oggplay(info->oggplay_handle);
-
free(info);
}
@@ -695,7 +698,7 @@
PluginWindowInfo * info = gui_handle;
SEM_WAIT(info->playback_sem);
- info->playback_state = PLAYING;
+ info->playback_state = PLAYING;
info->playback_state_change = SET_PLAY;
SEM_SIGNAL(info->playback_sem);
}
@@ -707,7 +710,7 @@
PluginWindowInfo * info = gui_handle;
SEM_WAIT(info->playback_sem);
- info->playback_state = PAUSED;
+ info->playback_state = PAUSED;
info->playback_state_change = SET_PAUSE;
SEM_SIGNAL(info->playback_sem);
}
@@ -730,20 +733,36 @@
void
gui_set_volume(void *gui_handle, float volume) {
-//!todo
+
+ PluginWindowInfo * info = gui_handle;
+
+ /*
+ * We don't need a semaphore for the volume because the display thread only
+ * ever reads info->volume, and only once info->set_volume has been flagged.
+ */
+ if (volume < 0) {
+ info->volume = 0;
+ } else if (volume > 1) {
+ info->volume = 1;
+ } else {
+ info->volume = volume;
+ }
+ info->set_volume = 1;
}
+
float
gui_get_volume(void *gui_handle) {
-//!todo
- return 0.0f;
+ return ((PluginWindowInfo *)gui_handle)->volume;
}
+
long
gui_get_window_width(void *gui_handle) {
return ((PluginWindowInfo *)gui_handle)->media_width;
}
+
long
gui_get_window_height(void *gui_handle) {
return ((PluginWindowInfo *)gui_handle)->media_height;
More information about the commits
mailing list