⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swfdec_player.c

📁 Swfdec is a decoder/renderer for Macromedia Flash animations. The decoding and rendering engine is
💻 C
📖 第 1 页 / 共 5 页
字号:
}voidswfdec_player_lock (SwfdecPlayer *player){  g_return_if_fail (SWFDEC_IS_PLAYER (player));  g_assert (swfdec_ring_buffer_get_n_elements (player->actions) == 0);  g_object_ref (player);  swfdec_player_lock_soft (player);}/* used for breakpoints */voidswfdec_player_unlock_soft (SwfdecPlayer *player){  g_return_if_fail (SWFDEC_IS_PLAYER (player));  SWFDEC_DEBUG ("UNLOCK");  swfdec_player_update_mouse_cursor (player);  g_object_thaw_notify (G_OBJECT (player));  swfdec_player_emit_signals (player);}voidswfdec_player_unlock (SwfdecPlayer *player){  g_return_if_fail (SWFDEC_IS_PLAYER (player));  g_assert (swfdec_ring_buffer_get_n_elements (player->actions) == 0);  swfdec_as_context_maybe_gc (SWFDEC_AS_CONTEXT (player));  swfdec_player_unlock_soft (player);  g_object_unref (player);}static gbooleanswfdec_accumulate_or (GSignalInvocationHint *ihint, GValue *return_accu,     const GValue *handler_return, gpointer data){  if (g_value_get_boolean (handler_return))    g_value_set_boolean (return_accu, TRUE);  return TRUE;}static voidswfdec_player_mark_string_object (gpointer key, gpointer value, gpointer data){  swfdec_as_string_mark (key);  swfdec_as_object_mark (value);}static voidswfdec_player_mark (SwfdecAsContext *context){  SwfdecPlayer *player = SWFDEC_PLAYER (context);  g_hash_table_foreach (player->registered_classes, swfdec_player_mark_string_object, NULL);  swfdec_as_object_mark (player->MovieClip);  swfdec_as_object_mark (player->Video);  g_list_foreach (player->roots, (GFunc) swfdec_as_object_mark, NULL);  g_list_foreach (player->intervals, (GFunc) swfdec_as_object_mark, NULL);  g_list_foreach (player->load_objects, (GFunc) swfdec_as_object_mark, NULL);  SWFDEC_AS_CONTEXT_CLASS (swfdec_player_parent_class)->mark (context);}static voidswfdec_player_get_time (SwfdecAsContext *context, GTimeVal *tv){  *tv = context->start_time;  /* FIXME: what granularity do we want? Currently it's milliseconds */  g_time_val_add (tv, SWFDEC_TICKS_TO_MSECS (SWFDEC_PLAYER (context)->time) * 1000);}static voidswfdec_player_class_init (SwfdecPlayerClass *klass){  GObjectClass *object_class = G_OBJECT_CLASS (klass);  SwfdecAsContextClass *context_class = SWFDEC_AS_CONTEXT_CLASS (klass);  object_class->get_property = swfdec_player_get_property;  object_class->set_property = swfdec_player_set_property;  object_class->dispose = swfdec_player_dispose;  g_object_class_install_property (object_class, PROP_INITIALIZED,      g_param_spec_boolean ("initialized", "initialized", "TRUE when the player has initialized its basic values",	  FALSE, G_PARAM_READABLE));  g_object_class_install_property (object_class, PROP_MOUSE_CURSOR,      g_param_spec_enum ("mouse-cursor", "mouse cursor", "how the mouse pointer should be presented",	  SWFDEC_TYPE_MOUSE_CURSOR, SWFDEC_MOUSE_CURSOR_NONE, G_PARAM_READABLE));  g_object_class_install_property (object_class, PROP_NEXT_EVENT,      g_param_spec_uint ("next-event", "next event", "how many milliseconds until the next event or 0 when no event pending",	  0, G_MAXUINT, 0, G_PARAM_READABLE));  g_object_class_install_property (object_class, PROP_CACHE_SIZE,      g_param_spec_uint ("cache-size", "cache size", "maximum cache size in bytes",	  0, G_MAXUINT, 50 * 1024 * 1024, G_PARAM_READABLE));  g_object_class_install_property (object_class, PROP_BACKGROUND_COLOR,      g_param_spec_uint ("background-color", "background color", "ARGB color used to draw the background",	  0, G_MAXUINT, SWFDEC_COLOR_COMBINE (0xFF, 0xFF, 0xFF, 0xFF), G_PARAM_READWRITE));  g_object_class_install_property (object_class, PROP_WIDTH,      g_param_spec_int ("width", "width", "current width of the movie",	  -1, G_MAXINT, -1, G_PARAM_READWRITE));  g_object_class_install_property (object_class, PROP_HEIGHT,      g_param_spec_int ("height", "height", "current height of the movie",	  -1, G_MAXINT, -1, G_PARAM_READWRITE));  g_object_class_install_property (object_class, PROP_ALIGNMENT,      g_param_spec_enum ("alignment", "alignment", "point of the screen to align the output to",	  SWFDEC_TYPE_ALIGNMENT, SWFDEC_ALIGNMENT_CENTER, G_PARAM_READWRITE));  g_object_class_install_property (object_class, PROP_SCALE,      g_param_spec_enum ("scale-mode", "scale mode", "method used to scale the movie",	  SWFDEC_TYPE_SCALE_MODE, SWFDEC_SCALE_SHOW_ALL, G_PARAM_READWRITE));  /**   * SwfdecPlayer::invalidate:   * @player: the #SwfdecPlayer affected   * @x: x coordinate of invalid region   * @y: y coordinate of invalid region   * @width: width of invalid region   * @height: height of invalid region   *   * This signal is emitted whenever graphical elements inside the player have    * changed. The coordinates describe the smallest rectangle that includes all   * changes.   */  signals[INVALIDATE] = g_signal_new ("invalidate", G_TYPE_FROM_CLASS (klass),      G_SIGNAL_RUN_LAST, 0, NULL, NULL, swfdec_marshal_VOID__DOUBLE_DOUBLE_DOUBLE_DOUBLE,      G_TYPE_NONE, 4, G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_DOUBLE);  /**   * SwfdecPlayer::advance:   * @player: the #SwfdecPlayer affected   * @msecs: the amount of milliseconds the player will advance   * @audio_samples: number of frames the audio is advanced (in 44100Hz steps)   *   * Emitted whenever the player advances.   */  signals[ADVANCE] = g_signal_new ("advance", G_TYPE_FROM_CLASS (klass),      G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (SwfdecPlayerClass, advance),       NULL, NULL, swfdec_marshal_VOID__UINT_UINT,      G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);  /**   * SwfdecPlayer::handle-key:   * @player: the #SwfdecPlayer affected   * @key: #SwfdecKey that was pressed or released   * @pressed: %TRUE if the @key was pressed or %FALSE if it was released   *   * This signal is emitted whenever @player should respond to a key event. If   * any of the handlers returns TRUE, swfdec_player_key_press() or    * swfdec_player_key_release() will return TRUE. Note that unlike many event    * handlers in gtk, returning TRUE will not stop further event handlers from    * being invoked. Use g_signal_stop_emission() in that case.   *   * Returns: TRUE if this handler handles the event.    **/  signals[HANDLE_KEY] = g_signal_new ("handle-key", G_TYPE_FROM_CLASS (klass),      G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (SwfdecPlayerClass, handle_key),       swfdec_accumulate_or, NULL, swfdec_marshal_BOOLEAN__UINT_UINT_BOOLEAN,      G_TYPE_BOOLEAN, 3, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_BOOLEAN);  /**   * SwfdecPlayer::handle-mouse:   * @player: the #SwfdecPlayer affected   * @x: new x coordinate of the mouse   * @y: new y coordinate of the mouse   * @button: 1 if the button is pressed, 0 if not   *   * This signal is emitted whenever @player should respond to a mouse event. If   * any of the handlers returns TRUE, swfdec_player_handle_mouse() will return    * TRUE. Note that unlike many event handlers in gtk, returning TRUE will not    * stop further event handlers from being invoked. Use g_signal_stop_emission()   * in that case.   *   * Returns: TRUE if this handler handles the event.    **/  signals[HANDLE_MOUSE] = g_signal_new ("handle-mouse", G_TYPE_FROM_CLASS (klass),      G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (SwfdecPlayerClass, handle_mouse),       swfdec_accumulate_or, NULL, swfdec_marshal_BOOLEAN__DOUBLE_DOUBLE_INT,      G_TYPE_BOOLEAN, 3, G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_INT);  /**   * SwfdecPlayer::audio-added:   * @player: the #SwfdecPlayer affected   * @audio: the audio stream that was added   *   * Emitted whenever a new audio stream was added to @player.   */  signals[AUDIO_ADDED] = g_signal_new ("audio-added", G_TYPE_FROM_CLASS (klass),      G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT,      G_TYPE_NONE, 1, SWFDEC_TYPE_AUDIO);  /**   * SwfdecPlayer::audio-removed:   * @player: the #SwfdecPlayer affected   * @audio: the audio stream that was removed   *   * Emitted whenever an audio stream was removed from @player. The stream will    * have been added with the SwfdecPlayer::audio-added signal previously.    */  signals[AUDIO_REMOVED] = g_signal_new ("audio-removed", G_TYPE_FROM_CLASS (klass),      G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT,      G_TYPE_NONE, 1, SWFDEC_TYPE_AUDIO);  /**   * SwfdecPlayer::fscommand:   * @player: the #SwfdecPlayer affected   * @command: the command to execute   * @paramter: parameter to pass to the command. The parameter depends on the    *            function.   *   * This signal is emited whenever a Flash script command (also known as    * fscommand) is encountered. This method is ued by the Flash file to   * communicate with the hosting environment. In web browsers it is used to    * call Javascript functions. Standalone Flash players understand a limited    * set of functions. They vary from player to player, but the most common are    * listed here: <itemizedlist>   * <listitem><para>"quit": quits the player.</para></listitem>   * <listitem><para>"fullscreen": A boolean setting (parameter is "true" or    * "false") that sets the player into fullscreen mode.</para></listitem>   * <listitem><para>"allowscale": A boolean setting that tells the player to   * not scale the Flash application.</para></listitem>   * <listitem><para>"showmenu": A boolean setting that tells the Flash player   * to not show its own entries in the right-click menu.</para></listitem>   * <listitem><para>"exec": Run an external executable. The parameter    * specifies the path.</para></listitem>   * <listitem><para>"trapallkeys": A boolean setting that tells the Flash    * player to pass all key events to the Flash application instead of using it   * for keyboard shortcuts or similar.</para></listitem>   * </itemizedlist>   */  signals[FSCOMMAND] = g_signal_new ("fscommand", G_TYPE_FROM_CLASS (klass),      G_SIGNAL_RUN_LAST, 0, NULL, NULL, swfdec_marshal_VOID__STRING_STRING,      G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);  /**   * SwfdecPlayer::launch:   * @player: the #SwfdecPlayer affected   * @url: URL to open   * @target: target to load the URL into   *   * Emitted whenever the @player encounters an URL that should be loaded into    * a target the Flash player does not recognize. In most cases this happens    * when the user clicks a link in an embedded Flash movie that should open a   * new web page.   * The effect of calling any swfdec functions on the emitting @player is undefined.   */  signals[LAUNCH] = g_signal_new ("launch", G_TYPE_FROM_CLASS (klass),      G_SIGNAL_RUN_LAST, 0, NULL, NULL, swfdec_marshal_VOID__STRING_STRING,      G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);  context_class->mark = swfdec_player_mark;  context_class->get_time = swfdec_player_get_time;  klass->advance = swfdec_player_do_advance;  klass->handle_key = swfdec_player_do_handle_key;  klass->handle_mouse = swfdec_player_do_handle_mouse;}static voidswfdec_player_init (SwfdecPlayer *player){  player->registered_classes = g_hash_table_new (g_direct_hash, g_direct_equal);  player->actions = swfdec_ring_buffer_new_for_type (SwfdecPlayerAction, 16);  player->external_actions = swfdec_ring_buffer_new_for_type (SwfdecPlayerAction, 8);  player->cache = swfdec_cache_new (50 * 1024 * 1024); /* 100 MB */  player->bgcolor = SWFDEC_COLOR_COMBINE (0xFF, 0xFF, 0xFF, 0xFF);  player->mouse_visible = TRUE;  player->mouse_cursor = SWFDEC_MOUSE_CURSOR_NORMAL;  player->iterate_timeout.callback = swfdec_player_iterate;  player->init_queue = g_queue_new ();  player->construct_queue = g_queue_new ();  player->stage_width = -1;  player->stage_height = -1;}voidswfdec_player_stop_all_sounds (SwfdecPlayer *player){  g_return_if_fail (SWFDEC_IS_PLAYER (player));  while (player->audio) {    swfdec_audio_remove (player->audio->data);  }}/* rect is in global coordinates */voidswfdec_player_invalidate (SwfdecPlayer *player, const SwfdecRect *rect){  if (swfdec_rect_is_empty (rect)) {    g_assert_not_reached ();    return;  }  swfdec_rect_union (&player->invalid, &player->invalid, rect);  SWFDEC_DEBUG ("toplevel invalidation of %g %g  %g %g - invalid region now %g %g  %g %g",      rect->x0, rect->y0, rect->x1, rect->y1,      player->invalid.x0, player->invalid.y0, player->invalid.x1, player->invalid.y1);}SwfdecMovie *swfdec_player_add_level_from_loader (SwfdecPlayer *player, guint depth,    SwfdecLoader *loader, const char *variables){  SwfdecMovie *movie;  const char *name;  swfdec_player_remove_level (player, depth);  name = swfdec_as_context_give_string (SWFDEC_AS_CONTEXT (player), g_strdup_printf ("_level%u", depth));  movie = swfdec_movie_new (player, depth - 16384, NULL, NULL, name);  movie->name = SWFDEC_AS_STR_EMPTY;  swfdec_swf_instance_new (SWFDEC_SPRITE_MOVIE (movie), loader, variables);  g_object_unref (loader);  return movie;}voidswfdec_player_remove_level (SwfdecPlayer *player, guint depth){  GList *walk;  int real_depth;  real_depth = (int) depth - 16384;  for (walk = player->roots; walk; walk = walk->next) {    SwfdecMovie *movie = walk->data;    if (movie->depth < real_depth)      continue;    if (movie->depth == real_depth) {      SWFDEC_DEBUG ("remove existing movie _level%u", depth);      swfdec_movie_remove (movie);      return;    }    break;  }  SWFDEC_LOG ("no movie to remove at level %u", depth);}SwfdecLoader *swfdec_player_load (SwfdecPlayer *player, const char *url){  g_return_val_if_fail (SWFDEC_IS_PLAYER (player), NULL);  g_return_val_if_fail (url != NULL, NULL);  g_assert (player->loader);  return swfdec_loader_load (player->loader, url, SWFDEC_LOADER_REQUEST_DEFAULT, NULL, 0);}voidswfdec_player_launch (SwfdecPlayer *player, const char *url, const char *target){  g_return_if_fail (SWFDEC_IS_PLAYER (player));  g_return_if_fail (url != NULL);  g_return_if_fail (target != NULL);  if (g_str_has_prefix (url, "FSCommand:")) {    const char *command = url + strlen ("FSCommand:");    g_signal_emit (player, signals[FSCOMMAND], 0, command, target);    return;  }  g_signal_emit (player, signals[LAUNCH], 0, url, target);}/** * swfdec_player_initialize: * @player: a #SwfdecPlayer * @version: Flash version to use * @rate: framerate in 256th or 0 for undefined * @width: width of movie * @height: height of movie * * Initializes the player to the given @version, @width, @height and @rate. If  * the player is already initialized, this function does nothing. **/voidswfdec_player_initialize (SwfdecPlayer *player, guint version,     guint rate, guint width, guint height){  SwfdecAsContext *context;  g_return_if_fail (SWFDEC_IS_PLAYER (player));  if (swfdec_player_is_initialized (player))    return;    context = SWFDEC_AS_CONTEXT (player);  swfdec_as_context_startup (context, version);  /* reset state for initialization */  /* FIXME: have a better way to do this */  if (context->state == SWFDEC_AS_CONTEXT_RUNNING) {    context->state = SWFDEC_AS_CONTEXT_NEW;    swfdec_player_init_global (player, version);    swfdec_sprite_movie_init_context (player, version);    swfdec_video_movie_init_context (player, version);    swfdec_movie_color_init_context (player, version);    swfdec_net_connection_init_context (player, version);    swfdec_net_stream_init_context (player, version);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -