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

📄 swfdec_player.c

📁 Swfdec still is development software, but has also followed a rigid no-crashes-allowed policy. I b
💻 C
📖 第 1 页 / 共 3 页
字号:
    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);}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);  g_signal_emit (player, signals[LAUNCH], 0, url, target);}/** * swfdec_player_initialize: * @player: a #SwfdecPlayer * @rate: framerate in 256th or 0 for undefined * @width: width of movie * @height: height of movie * * Initializes the player to the given @width, @height and @rate. If the player * is already initialized, this function does nothing. **/voidswfdec_player_initialize (SwfdecPlayer *player, guint rate, guint width, guint height){  g_return_if_fail (SWFDEC_IS_PLAYER (player));  g_return_if_fail (width > 0);  g_return_if_fail (height > 0);  if (swfdec_player_is_initialized (player))    return;    SWFDEC_INFO ("initializing player to size %ux%u", width, height);  player->rate = rate;  player->width = width;  player->height = height;  if (rate) {    player->iterate_timeout.timestamp = player->time + SWFDEC_TICKS_PER_SECOND * 256 / rate;    swfdec_player_add_timeout (player, &player->iterate_timeout);    SWFDEC_LOG ("initialized iterate timeout %p to %"G_GUINT64_FORMAT" (now %"G_GUINT64_FORMAT")",	&player->iterate_timeout, player->iterate_timeout.timestamp, player->time);  }  g_object_notify (G_OBJECT (player), "initialized");}jsvalswfdec_player_get_export_class (SwfdecPlayer *player, const char *name){  jsval *val = g_hash_table_lookup (player->registered_classes, name);  if (val)    return *val;  else    return JSVAL_NULL;}voidswfdec_player_set_export_class (SwfdecPlayer *player, const char *name, jsval val){  jsval *insert;  g_return_if_fail (SWFDEC_IS_PLAYER (player));  g_return_if_fail (name != NULL);  g_return_if_fail (JSVAL_IS_OBJECT (val));  insert = g_hash_table_lookup (player->registered_classes, name);  if (insert) {    JS_RemoveRoot (player->jscx, insert);    g_free (insert);    g_hash_table_remove (player->registered_classes, name);  }  if (val != JSVAL_NULL) {    insert = g_new (jsval, 1);    *insert = val;    if (!JS_AddRoot (player->jscx, insert)) {      g_free (insert);      return;    }    g_hash_table_insert (player->registered_classes, g_strdup (name), insert);  }}/** PUBLIC API ***//** * swfdec_player_new: * * Creates a new player. * This function calls swfdec_init () for you if it wasn't called before. * * Returns: The new player **/SwfdecPlayer *swfdec_player_new (void){  SwfdecPlayer *player;  swfdec_init ();  player = g_object_new (SWFDEC_TYPE_PLAYER, NULL);  return player;}/** * swfdec_player_set_loader: * @player: a #SwfdecPlayer * @loader: the loader to use for this player. Takes ownership of the given loader. * * Sets the loader for the main data. This function only works if no loader has  * been set on @player yet. * For details, see swfdec_player_set_loader_with_variables(). **/voidswfdec_player_set_loader (SwfdecPlayer *player, SwfdecLoader *loader){  g_return_if_fail (SWFDEC_IS_PLAYER (player));  g_return_if_fail (player->roots == NULL);  g_return_if_fail (SWFDEC_IS_LOADER (loader));  swfdec_player_set_loader_with_variables (player, loader, NULL);}/** * swfdec_player_set_loader_with_variables: * @player: a #SwfdecPlayer * @loader: the loader to use for this player. Takes ownership of the given loader. * @variables: a string that is checked to be in 'application/x-www-form-urlencoded' *             syntax describing the arguments to set on the new player or NULL for *             none. * * Sets the loader for the main data. This function only works if no loader has  * been set on @player yet. * If the @variables are set and validate, they will be set as properties on the  * root movie.  * <note>If you want to capture events during the setup process, you want to  * connect your signal handlers before calling swfdec_player_set_loader() and * not use conveniencse functions such as swfdec_player_new_from_file().</note> **/voidswfdec_player_set_loader_with_variables (SwfdecPlayer *player, SwfdecLoader *loader,    const char *variables){  SwfdecRootMovie *movie;  g_return_if_fail (SWFDEC_IS_PLAYER (player));  g_return_if_fail (player->roots == NULL);  g_return_if_fail (SWFDEC_IS_LOADER (loader));  player->loader = loader;  g_object_ref (loader);  movie = swfdec_player_add_level_from_loader (player, 0, loader, variables);  swfdec_loader_parse (loader);}/** * swfdec_player_new_from_file: * @filename: name of the file to play * @error: return location for error or NULL * * Tries to create a player to play back the given file. If the file does not * exist or another error occurs, NULL is returned. * This function calls swfdec_init () for you if it wasn't called before. * * Returns: a new player or NULL on error. **/SwfdecPlayer *swfdec_player_new_from_file (const char *filename, GError **error){  SwfdecLoader *loader;  SwfdecPlayer *player;  g_return_val_if_fail (filename != NULL, NULL);  loader = swfdec_loader_new_from_file (filename, error);  if (loader == NULL)    return NULL;  player = swfdec_player_new ();  swfdec_player_set_loader (player, loader);  return player;}/** * swfdec_init: * * Initializes the Swfdec library. **/voidswfdec_init (void){  static gboolean _inited = FALSE;  const char *s;  if (_inited)    return;  _inited = TRUE;  g_type_init ();  oil_init ();  s = g_getenv ("SWFDEC_DEBUG");  if (s && s[0]) {    char *end;    int level;    level = strtoul (s, &end, 0);    if (end[0] == 0) {      swfdec_debug_set_level (level);    }  }  swfdec_js_init (0);}/** * swfdec_player_handle_mouse: * @player: a #SwfdecPlayer * @x: x coordinate of mouse * @y: y coordinate of mouse * @button: 1 for pressed, 0 for not pressed * * Updates the current mouse status. If the mouse has left the area of @player, * you should pass values outside the movie size for @x and @y. You will  * probably want to call swfdec_player_advance() before to update the player to * the correct time when calling this function. * * Returns: TRUE if the mouse event was handled. A mouse event may not be  *          handled if the user clicked on a translucent area for example. **/gbooleanswfdec_player_handle_mouse (SwfdecPlayer *player,     double x, double y, int button){  gboolean ret;  g_return_val_if_fail (SWFDEC_IS_PLAYER (player), FALSE);  g_return_val_if_fail (button == 0 || button == 1, FALSE);  g_signal_emit (player, signals[HANDLE_MOUSE], 0, x, y, button, &ret);  return ret;}/** * swfdec_player_render: * @player: a #SwfdecPlayer * @cr: #cairo_t to render to * @x: x coordinate of top left position to render * @y: y coordinate of top left position to render * @width: width of area to render or 0 for full width * @height: height of area to render or 0 for full height * * Renders the given area of the current frame to @cr. **/voidswfdec_player_render (SwfdecPlayer *player, cairo_t *cr,     double x, double y, double width, double height){  static const SwfdecColorTransform trans = { 256, 0, 256, 0, 256, 0, 256, 0 };  GList *walk;  SwfdecRect real;  g_return_if_fail (SWFDEC_IS_PLAYER (player));  g_return_if_fail (cr != NULL);  g_return_if_fail (width >= 0.0);  g_return_if_fail (height >= 0.0);  /* FIXME: fail when !initialized? */  if (!swfdec_player_is_initialized (player))    return;  if (width == 0.0)    width = player->width;  if (height == 0.0)    height = player->height;  real.x0 = floor (x * SWFDEC_TWIPS_SCALE_FACTOR);  real.y0 = floor (y * SWFDEC_TWIPS_SCALE_FACTOR);  real.x1 = ceil ((x + width) * SWFDEC_TWIPS_SCALE_FACTOR);  real.y1 = ceil ((y + height) * SWFDEC_TWIPS_SCALE_FACTOR);  SWFDEC_INFO ("=== %p: START RENDER, area %g %g  %g %g ===", player,       real.x0, real.y0, real.x1, real.y1);  cairo_save (cr);  cairo_rectangle (cr, x, y, width, height);  cairo_clip (cr);  cairo_scale (cr, 1.0 / SWFDEC_TWIPS_SCALE_FACTOR, 1.0 / SWFDEC_TWIPS_SCALE_FACTOR);  swfdec_color_set_source (cr, player->bgcolor);  cairo_paint (cr);  for (walk = player->roots; walk; walk = walk->next) {    swfdec_movie_render (walk->data, cr, &trans, &real, TRUE);  }  SWFDEC_INFO ("=== %p: END RENDER ===", player);  cairo_restore (cr);}/** * swfdec_player_advance: * @player: the #SwfdecPlayer to advance * @msecs: number of milliseconds to advance * * Advances @player by @msecs. You should make sure to call this function as * often as the SwfdecPlayer::next-event property indicates. **/voidswfdec_player_advance (SwfdecPlayer *player, guint msecs){  guint frames;  g_return_if_fail (SWFDEC_IS_PLAYER (player));  g_return_if_fail (msecs > 0);#if 0  while (TRUE)    swfdec_js_run (player, "i = new Object(); i.foo = 7", NULL);  //swfdec_js_run (player, "s=\"/A/B:foo\"; t=s.indexOf (\":\"); if (t) t=s.substring(0,s.indexOf (\":\")); else t=s;", NULL);#endif  frames = SWFDEC_TICKS_TO_SAMPLES (player->time + SWFDEC_MSECS_TO_TICKS (msecs))    - SWFDEC_TICKS_TO_SAMPLES (player->time);  g_signal_emit (player, signals[ADVANCE], 0, msecs, frames);}/** * swfdec_player_is_initialized: * @player: a #SwfdecPlayer * * Determines if the @player is initalized yet. An initialized player is able * to provide basic values like width, height or rate. A player may not be  * initialized if the loader it was started with does not reference a Flash * resources or it did not provide enough data yet. If a player is initialized, * it will never be uninitialized again. * * Returns: TRUE if the basic values are known. **/gbooleanswfdec_player_is_initialized (SwfdecPlayer *player){  g_return_val_if_fail (SWFDEC_IS_PLAYER (player), FALSE);  return player->width > 0 && player->height > 0;}/** * swfdec_player_get_next_event: * @player: ia #SwfdecPlayer * * Queries how long to the next event. This is the next time when you should  * call swfdec_player_advance() to forward to. * * Returns: number of milliseconds until next event or 0 if no outstanding event **/guintswfdec_player_get_next_event (SwfdecPlayer *player){  SwfdecTick time;  guint ret;  g_return_val_if_fail (SWFDEC_IS_PLAYER (player), 0);  time = swfdec_player_get_next_event_time (player);  ret = SWFDEC_TICKS_TO_MSECS (time);  if (time % (SWFDEC_TICKS_PER_SECOND / 1000))    ret++;  return ret;}/** * swfdec_player_get_rate: * @player: a #SwfdecPlayer * * Queries the framerate of this movie. This number specifies the number * of frames that are supposed to pass per second. It is a  * multiple of 1/256. It is possible that the movie has no framerate if it does * not display a Flash movie but an FLV video for example. This does not mean * it will not change however. * * Returns: The framerate of this movie or 0 if it isn't known yet or the *          movie doesn't have a framerate. **/doubleswfdec_player_get_rate (SwfdecPlayer *player){  g_return_val_if_fail (SWFDEC_IS_PLAYER (player), 0.0);  return player->rate / 256.0;}/** * swfdec_player_get_image_size: * @player: a #SwfdecPlayer * @width: integer to store the width in or NULL * @height: integer to store the height in or NULL * * If the size of the movie is already known, fills in @width and @height with * the size. Otherwise @width and @height are set to 0. **/voidswfdec_player_get_image_size (SwfdecPlayer *player, int *width, int *height){  g_return_if_fail (SWFDEC_IS_PLAYER (player));  if (width)    *width = player->width;  if (height)    *height = player->height;}/** * swfdec_player_get_audio: * @player: a #SwfdecPlayer * * Returns a list of all currently active audio streams in @player. * * Returns: A #GList of #SwfdecAudio. You must not modify or free this list. **//* FIXME: I don't like this function */const GList *swfdec_player_get_audio (SwfdecPlayer *	player){  g_return_val_if_fail (SWFDEC_IS_PLAYER (player), NULL);  return player->audio;}/** * swfdec_player_get_background_color: * @player: a #SwfdecPlayer * * Gets the current background color. The color will be an ARGB-quad, with the  * MSB being the alpha value. * * Returns: the background color as an ARGB value **/unsigned intswfdec_player_get_background_color (SwfdecPlayer *player){  g_return_val_if_fail (SWFDEC_IS_PLAYER (player), SWFDEC_COLOR_COMBINE (0xFF, 0xFF, 0xFF, 0xFF));  return player->bgcolor;}/** * swfdec_player_set_background_color: * @player: a #SwfdecPlayer * @color: new color to use as background color * * Sets a new background color as an ARGB value. To get transparency, set the  * value to 0. To get a black beackground, use 0xFF000000. **/voidswfdec_player_set_background_color (SwfdecPlayer *player, unsigned int color){  g_return_if_fail (SWFDEC_IS_PLAYER (player));  player->bgcolor_set = TRUE;  if (player->bgcolor == color)    return;  g_object_notify (G_OBJECT (player), "background-color");  if (swfdec_player_is_initialized (player)) {    g_signal_emit (player, signals[INVALIDATE], 0, 0.0, 0.0, 	(double) player->width, (double) player->height);  }}

⌨️ 快捷键说明

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