📄 hxplayer.cpp
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: hxplayer.cpp,v 1.21.2.9 2004/10/18 18:55:17 rggammon Exp $ * * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved. * * The contents of this file, and the files included with this file, * are subject to the current version of the RealNetworks Public * Source License (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the current version of the RealNetworks Community * Source License (the "RCSL") available at * http://www.helixcommunity.org/content/rcsl, in which case the RCSL * will apply. You may also obtain the license terms directly from * RealNetworks. You may not use this file except in compliance with * the RPSL or, if you have a valid RCSL with RealNetworks applicable * to this file, the RCSL. Please see the applicable RPSL or RCSL for * the rights, obligations and limitations governing use of the * contents of the file. * * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL") in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your version of * this file only under the terms of the GPL, and not to allow others * to use your version of this file under the terms of either the RPSL * or RCSL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient may * use your version of this file under the terms of any one of the * RPSL, the RCSL or the GPL. * * This file is part of the Helix DNA Technology. RealNetworks is the * developer of the Original Code and owns the copyrights in the * portions it created. * * This file, and the files included with this file, is distributed * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET * ENJOYMENT OR NON-INFRINGEMENT. * * Technology Compatibility Kit Test Suite(s) Location: * http://www.helixcommunity.org/content/tck * * Contributor(s): * * ***** END LICENSE BLOCK ***** */#include "hxtypes.h"#include "hxplayer.h"#include "hxgerror.h"#include "hlxclib/string.h"#include "hxwintyp.h"#ifdef G_OS_UNIX#include <X11/extensions/XShm.h>#include <X11/Xlib.h>#include <X11/Xatom.h>#endif#include <gtk/gtkmain.h>#include <memory.h>#include <stdlib.h>#include <stdio.h>#include <time.h>/* hxclientkit includes */#include "HXClientTypes.h"#include "HXClientCFuncs.h"#include "HXClientCallbacks.h"#include "HXClientConstants.h"#include "HXClientCOMAccess.h"#include "hx-i18n.h"extern "C"{#include "hxmarshal.h"}#define SLEEP_TIME 10#define INFINITE_DURATION 1981342000 /* 1981342000 is 22d+22h+22m+22s */enum { PLAY_SIGNAL, STOP_SIGNAL, PAUSE_SIGNAL, CONTACTING_SIGNAL, BUFFERING_SIGNAL, LENGTH_CHANGED_SIGNAL, SEEK_SIGNAL, ERROR_SIGNAL, HXERROR_SIGNAL, IDEAL_SIZE_CHANGED_SIGNAL, VOLUME_CHANGED_SIGNAL, MUTE_CHANGED_SIGNAL, GOTO_URL_SIGNAL, OPEN_WINDOW_SIGNAL, CLIP_BANDWIDTH_CHANGED_SIGNAL, REQUEST_UPGRADE_SIGNAL, GROUPS_CHANGED_SIGNAL, GROUP_STARTED_SIGNAL, TITLE_CHANGED_SIGNAL, REQUEST_AUTHENTICATION_SIGNAL, STATUS_CHANGED_SIGNAL, CONTENT_CONCLUDED_SIGNAL, CONTENT_STATE_CHANGED_SIGNAL, HAS_FEATURE_SIGNAL, START_SEEKING_SIGNAL, STOP_SEEKING_SIGNAL, VISUAL_STATE_CHANGED_SIGNAL, LAST_SIGNAL};enum { PROP_0, PROP_LOOP, PROP_LOOP_COUNT, PROP_SHUFFLE,};static guint signals[LAST_SIGNAL] = { 0 }; /* info for the timeout callback */static guint g_pump_timer_id = 0;static guint g_engine_ref_count = 0;static GList* g_players_list = NULL;static Display* g_dpy = NULL;/* extension info */static gboolean g_xshm_present = FALSE;static gint g_xshm_event_base = -1;/* GObject, GtkObject methods */static void hx_player_class_init (HXPlayerClass* klass);static void hx_player_init (HXPlayer* hxplayer, HXPlayerClass* klass);static void hx_player_finalize (GObject* object);static void hx_player_unrealize (GtkWidget* widget);static void hx_player_realize (GtkWidget* widget);static gboolean hx_player_expose (GtkWidget* widget, GdkEventExpose* event);static void hx_player_size_allocate (GtkWidget* widget, GtkAllocation* allocation);static gboolean hx_player_motion_notify_event (GtkWidget* widget, GdkEventMotion* event);static void hx_player_set_property (GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec);static void hx_player_get_property (GObject* object, guint prop_id, GValue* value, GParamSpec* pspec);static void hx_player_shuffle (HXPlayer* player);#ifdef G_OS_UNIX// We use an event filter here rather than overriding the events// in the widget class. This gives us access to raw XEvents, suitable// for passing into the core.static GdkFilterReturn hx_player_event_filter (GdkXEvent* gxevent, GdkEvent* gevent, gpointer player);static gboolean hx_player_pump (gpointer user_data);#endifvoidOnContentStateChanged(void* userInfo, int oldContentState, int newContentState){ HXPlayer* player; HXContentStateType new_state, old_state; player = HX_PLAYER(userInfo); g_return_if_fail(player != NULL); new_state = (HXContentStateType) newContentState; old_state = (HXContentStateType) oldContentState; if(G_OBJECT(player)->ref_count == 0) { /* XXXRGG: hx_player_finalize calls stop, which in turn calls this function. Emitting signals while being finalized doesn't seem to work with the version of glib I'm using now, so handle this case here. */ return; } int signal = -1; switch (newContentState) { case kContentStatePlaying: signal = signals[PLAY_SIGNAL]; break; case kContentStateStopped: signal = signals[STOP_SIGNAL]; break; case kContentStatePaused: signal = signals[PAUSE_SIGNAL]; break; case kContentStateLoading: case kContentStateContacting: case kContentStateNotLoaded: break; default: // unknown/unhandled event g_assert_not_reached(); } if(signal >= 0) { g_signal_emit(G_OBJECT(player), signal, 0); } g_signal_emit(G_OBJECT(player), signals[CONTENT_STATE_CHANGED_SIGNAL], 0, old_state, new_state);}voidOnVisualStateChanged(void* userInfo, bool hasVisualContent){ HXPlayer* player; GtkWidget* widget; widget = GTK_WIDGET(userInfo); player = HX_PLAYER(userInfo); g_return_if_fail(player != NULL); g_signal_emit(G_OBJECT(player), signals[VISUAL_STATE_CHANGED_SIGNAL], 0, (gboolean) hasVisualContent); gdk_window_invalidate_rect(widget->window, &widget->allocation, FALSE);}voidOnIdealSizeChanged(void* userInfo, SInt32 idealWidth, SInt32 idealHeight){ HXPlayer* player; player = HX_PLAYER(userInfo); g_return_if_fail(player != NULL); g_signal_emit(G_OBJECT(player), signals[IDEAL_SIZE_CHANGED_SIGNAL], 0, idealWidth, idealHeight);}voidOnLengthChanged(void* userInfo, UInt32 length){ HXPlayer* player; player = HX_PLAYER(userInfo); g_return_if_fail(player != NULL); g_signal_emit (G_OBJECT (player), signals[LENGTH_CHANGED_SIGNAL], 0, (guint)length);}voidOnTitleChanged(void* userInfo, const char* pTitle){ HXPlayer* player; gsize in; gsize out; gchar* title = NULL; player = HX_PLAYER(userInfo); g_return_if_fail(player != NULL); if(pTitle) { in = strlen(pTitle) + 1; out = 0; title = g_convert(pTitle, in - 1, "UTF-8", "ISO-8859-1", &in, &out, NULL); } g_signal_emit (G_OBJECT (player), signals[TITLE_CHANGED_SIGNAL], 0, title); g_free(title);}voidOnGroupsChanged(void* userInfo){ HXPlayer* player; player = HX_PLAYER(userInfo); g_return_if_fail(player != NULL); g_signal_emit(G_OBJECT(player), signals[GROUPS_CHANGED_SIGNAL], 0);}voidOnGroupStarted(void* userInfo, UInt16 groupIndex){ HXPlayer* player; player = HX_PLAYER(userInfo); g_return_if_fail(player != NULL); g_signal_emit(G_OBJECT(player), signals[GROUP_STARTED_SIGNAL], 0, (guint)groupIndex);}voidOnContacting( void* userInfo, const char* pContactingText){ HXPlayer* player; player = HX_PLAYER(userInfo); g_return_if_fail(player != NULL); g_signal_emit(G_OBJECT(player), signals[CONTACTING_SIGNAL], 0, pContactingText); }voidOnBuffering(void* userInfo, UInt32 bufferingReason, UInt16 bufferPercent){ HXPlayer* player; player = HX_PLAYER(userInfo); g_return_if_fail(player != NULL); g_signal_emit(G_OBJECT(player), signals[BUFFERING_SIGNAL], 0, bufferingReason, (guint)bufferPercent);}voidOnContentConcluded(void* userInfo){ HXPlayer* player; guint cur_group; guint group_count; player = HX_PLAYER(userInfo); g_return_if_fail(player != NULL); g_signal_emit(G_OBJECT(player), signals[CONTENT_CONCLUDED_SIGNAL], 0); if(player->shuffle) { hx_player_shuffle(player); } else { if(player->loop || player->loop_count > 0) { cur_group = hx_player_get_current_group(player); group_count = hx_player_get_group_count(player); if(cur_group == group_count) { if(!player->loop_count || player->cur_loop < player->loop_count) { hx_player_set_current_group(player, 0); hx_player_play(player); player->cur_loop++; } else { player->cur_loop = 0; } } } }}voidOnStatusChanged(void* userInfo, const char* pStatus){ HXPlayer* player; player = HX_PLAYER(userInfo); g_return_if_fail(player != NULL); g_signal_emit(G_OBJECT(player), signals[STATUS_CHANGED_SIGNAL], 0, pStatus);}voidOnVolumeChanged(void* userInfo, UInt16 volume){ HXPlayer* player; player = HX_PLAYER(userInfo); g_return_if_fail(player != NULL); g_signal_emit(G_OBJECT(player), signals[VOLUME_CHANGED_SIGNAL], 0, (guint)volume);}voidOnMuteChanged(void* userInfo, bool hasMuted){ HXPlayer* player; player = HX_PLAYER(userInfo); g_return_if_fail(player != NULL); g_signal_emit(G_OBJECT(player), signals[MUTE_CHANGED_SIGNAL], 0, (gboolean)hasMuted);}voidOnClipBandwidthChanged(void* userInfo, SInt32 clipBandwidth){ HXPlayer* player; player = HX_PLAYER(userInfo); g_return_if_fail(player != NULL); g_signal_emit(G_OBJECT(player), signals[CLIP_BANDWIDTH_CHANGED_SIGNAL], 0, (gint)clipBandwidth);}voidOnErrorOccurred(void* userInfo, UInt32 hxCode, UInt32 userCode, const char* pErrorString, const char* pUserString, const char* pMoreInfoURL){ HXPlayer* player; GError* error; guint hxerror_id; guint error_id; player = HX_PLAYER(userInfo); g_return_if_fail(player != NULL); error = hx_error_new(hxCode, userCode, pErrorString, pUserString, pMoreInfoURL); error_id = g_signal_handler_find(G_OBJECT(player), G_SIGNAL_MATCH_ID, signals[ERROR_SIGNAL], 0, // detail NULL, // closure NULL, // func NULL // data ); hxerror_id = g_signal_handler_find(G_OBJECT(player),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -