[xiph-commits] r2978 - liboggplay/trunk/plugin
laser13 at svn.annodex.net
laser13 at svn.annodex.net
Mon Jun 18 01:11:54 PDT 2007
Author: laser13
Date: 2007-06-18 01:11:54 -0700 (Mon, 18 Jun 2007)
New Revision: 2978
Modified:
liboggplay/trunk/plugin/plugin_gui_win32.c
Log:
Update Win32 GUI implementation to fit to the new gui API.
Modified: liboggplay/trunk/plugin/plugin_gui_win32.c
===================================================================
--- liboggplay/trunk/plugin/plugin_gui_win32.c 2007-06-18 06:04:53 UTC (rev 2977)
+++ liboggplay/trunk/plugin/plugin_gui_win32.c 2007-06-18 08:11:54 UTC (rev 2978)
@@ -39,27 +39,12 @@
#include "std_semaphore.h"
#ifdef USE_AUDIO
-#include "sydney_audio.h"
+#include "sydney_audio_new.h"
#endif
#include "plugin_gui.h"
#include "plugin_oggplay.h"
-/*
- * INFO: proposition of callback related structures
- *
- * typedef struct {
- * char * type; // CMML, stream position, etc.
- * char * callback; // callback funtion name
- * } CallbackEntry;
- *
- * typedef struct {
- * NPP mInstance; // plugin instance
- * CallbackEntry * callback_list;
- * } PluginCallbacks;
- */
-
-
typedef struct {
// window related data
int width;
@@ -77,17 +62,30 @@
PluginPlaybackState playback_state;
void * new_oggplay_handle;
#ifdef USE_AUDIO
- SAAudioHandle * audio_handle;
+ sa_stream_t * audio_handle;
#endif
BOOL audio_opened;
- unsigned int playback_target;
- char * cmml_callback;
- NPP plugin_instance;
+ unsigned int playback_target;
+ nsPluginInstance * plugin_instance;
} PluginWindowInfo;
-/* forward definitions of local functions*/
-void on_cmml_data(PluginWindowInfo * info, unsigned char ** cmml_data, int cmml_size);
+static BOOL
+switch_oggplays(PluginWindowInfo *info) {
+
+ void * old_ogg_handle;
+
+ if (info->new_oggplay_handle != NULL) {
+ SEM_WAIT(info->oggplay_replace_sem);
+ old_ogg_handle = info->ogg_handle;
+ info->ogg_handle = (void *)info->new_oggplay_handle;
+ info->new_oggplay_handle = NULL;
+ SEM_SIGNAL(info->oggplay_replace_sem);
+ shut_oggplay(old_ogg_handle);
+ return TRUE;
+ }
+ return FALSE;
+}
/**
* \brief display_thread - main loop do the tread responsible for display
* \param [in] _info - PluginWindowInfo stucture
@@ -113,42 +111,21 @@
info->shutdown_gui = 0;
ExitThread(0);
}
-
- Sleep(40);
- get_oggplay_frame(info->ogg_handle, info->frame_data);
- convert_oggplay_frame(info->ogg_handle, info->frame_data, BGR);
-
- if (info->frame_data->cmml_strings != NULL) {
- //printf("Calling cmml callback %s\n", info->frame_data->cmml_strings[0]);
- on_cmml_data(info, info->frame_data->cmml_strings, info->frame_data->cmml_size);
- }
-
- if (info->frame_data->frame == NULL) {
- continue;
- }
-
+
/*
* Do not send WM_PAINT messages while waiting for GUI to shutdown.
* This is asynchronous call and can hang or crash web browser.
*/
- if (!info->shutdown_gui) {
+ if (!info->shutdown_gui) {
// force refresh
GetClientRect(hWnd, &r);
InvalidateRect(hWnd, &r, FALSE);
UpdateWindow(hWnd);
- } else {
- // but always remeber to release the frame
- free_oggplay_frame(info->ogg_handle, info->frame_data);
}
- if (info->new_oggplay_handle != NULL) {
- //void * old_ogg_handle;
- SEM_WAIT(info->oggplay_replace_sem);
- shut_oggplay(info->ogg_handle);
- info->ogg_handle = (void *)info->new_oggplay_handle;
- info->new_oggplay_handle = NULL;
- SEM_SIGNAL(info->oggplay_replace_sem);
- }
+ Sleep(40);
+ /* try switching oggplays */
+ switch_oggplays(info);
}
return 0;
@@ -162,17 +139,19 @@
* Comments: Fuction notifies the display
* */
void *
-initialise_gui(NPWindow* aWindow, void *ogg_handle) {
+initialise_gui(nsPluginInstance *instance, NPWindow *np_window,
+ void *oggplay_handle) {
DWORD disp_id;
PluginWindowInfo * info;
- HWND hWnd = (HWND)aWindow->window;
+ HWND hWnd = (HWND)np_window->window;
/* allocate structure */
info = (PluginWindowInfo*)malloc(sizeof(PluginWindowInfo));
- info->width = aWindow->width;
- info->height = aWindow->height;
- info->ogg_handle = ogg_handle;
+ info->width = np_window->width;
+ info->height = np_window->height;
+ info->plugin_instance = instance;
+ info->ogg_handle = oggplay_handle;
info->frame_data = (PluginOggFrame*)malloc(sizeof(PluginOggFrame));
info->frame_data->frame = NULL;
info->frame_data->samples = NULL;
@@ -182,7 +161,6 @@
info->new_oggplay_handle = NULL;
info->playback_state = PLAYING;
/* calback members initialisation */
- info->cmml_callback = NULL;
info->plugin_instance = NULL;
/*
@@ -267,7 +245,8 @@
* \param [in] hdc - device context
* \param [in/out] hBitmap - resulting device dependant GDI bitmap
*/
-void CreateDDBitmap(HDC hdc, HBITMAP* hBitmap, PluginWindowInfo* info) {
+static void
+CreateDDBitmap(HDC hdc, HBITMAP* hBitmap, PluginWindowInfo* info) {
BITMAPINFOHEADER bih;
BITMAPINFO bmi;
@@ -296,17 +275,16 @@
return;
}
-void
+
+static void
update_frame(PluginWindowInfo * info) {
PAINTSTRUCT ps;
RECT r;
HDC hdc, hdcMem;
HBITMAP hbmOld, hbm;
-
- // filter early and random *broken* WM_PAINT messages
- if ((info == NULL) || (info->frame_data->frame == NULL))
- return;
+
+ /* display new video frame */
hdc = BeginPaint(info->window, &ps);
GetClientRect(info->window, &r);
/* FIXME: very performance costly operations, if safe use global context? */
@@ -329,8 +307,48 @@
SelectObject(hdcMem, hbmOld);
DeleteObject(hbm);
EndPaint(info->window, &ps);
+
+ return;
+}
+
+static void
+process_frame_data(PluginWindowInfo * info) {
+
+ BOOL has_audio = FALSE;
+ BOOL has_video = FALSE;
+ BOOL has_cmml = FALSE;
+
+ // filter early and random *broken* WM_PAINT messages
+ if (info == NULL) {
+ return;
+ }
+
+ get_oggplay_frame(info->ogg_handle, info->frame_data);
+ convert_oggplay_frame(info->ogg_handle, info->frame_data, BGR);
+
+ has_video = ((info->frame_data->video_data != NULL) && (info->frame_data->frame != NULL)) ? TRUE : FALSE;
+ has_audio = ((info->frame_data->samples != NULL) && (info->frame_data->size > 0)) ? TRUE : FALSE;
+ has_cmml = ((info->frame_data->cmml_strings != NULL) && (info->frame_data->cmml_size > 0)) ? TRUE : FALSE;
+
+ /* if there is need to update plugin GUI then go to next frame */
+ if ((has_video == FALSE) && (has_audio == FALSE)
+ /* && (has_cmml) */
+ ) {
+ //goto cleanup;
+ return;
+ }
+ /* display frame */
+ update_frame(info);
+
+ /* call CMML data callback using plugin's main thread call */
+ if (has_cmml == TRUE) {
+ onCMMLData(info->plugin_instance, info->frame_data->cmml_strings, info->frame_data->cmml_size);
+ }
+
+cleanup:
// progress with decoding
free_oggplay_frame(info->ogg_handle, info->frame_data);
+ return;
}
// =================================
@@ -343,7 +361,7 @@
switch (msg) {
case WM_PAINT:
info = (PluginWindowInfo*)GetWindowLongPtr(hWnd, GWL_USERDATA);
- update_frame(info);
+ process_frame_data(info);
break;
case WM_CLOSE :
break;
@@ -377,50 +395,19 @@
}
-void pause_gui(void *handle) {
+void
+pause_gui(void *handle) {
PluginWindowInfo * info = (PluginWindowInfo *)handle;
info->playback_state = PAUSED;
}
-void start_gui(void *handle) {
+void
+start_gui(void *handle) {
PluginWindowInfo * info = (PluginWindowInfo *)handle;
info->playback_state = PLAYING;
SEM_SIGNAL(info->playback_sem);
}
-void set_gui_cmml_callback(void *handle, char * callback, NPP mInstance) {
- PluginWindowInfo * info = (PluginWindowInfo *)handle;
- info->cmml_callback = callback;
- info->plugin_instance = mInstance;
- NPN_GetURL(info->plugin_instance, "javascript:alert(\"CMML callback registered\");", NULL);
-}
-
-void on_cmml_data(PluginWindowInfo * info, unsigned char ** cmml_data, int cmml_size) {
- int i;
- char * code;
-
- if ((info->cmml_callback == NULL) || (info->plugin_instance == NULL)) {
- return;
- }
-
- for (i = 0; i < cmml_size; i++) {
- /*code = NPN_MemAlloc(strlen(cmml_data[i])
- + strlen(info->cmml_callback)
- + strlen("javascript:")
- + strlen("(\"")
- + strlen("\")")
- + 1);
- strcpy(code, "javascript:");
- strcat(code, info->cmml_callback);
- strcat(code, "(\"");
- strcat(code, cmml_data[i]);
- strcat(code, "\");");*/
-
- /*printf("Calling Javascript code: %s\n", code);
- NPN_GetURL(info->plugin_instance, code, NULL); */
- }
-}
-
short
get_gui_current_state(void *handle) {
short state;
@@ -442,4 +429,3 @@
}
return state;
}
-
More information about the commits
mailing list