コード例 #1
0
ファイル: player-av.c プロジェクト: bmravec/GMediaMP
static void
player_av_set_position (Player *self, guint pos)
{
    PlayerAVPrivate *priv = PLAYER_AV (self)->priv;

    int stream = priv->astream;
    int64_t seek_target = av_rescale_q (AV_TIME_BASE * pos, AV_TIME_BASE_Q,
        priv->fctx->streams[stream]->time_base);

    if (!av_seek_frame (priv->fctx, stream, seek_target, 0)) {
        g_print ("It Failed\n");
    } else {
        g_print ("Seek OK?\n");
    }

    g_mutex_lock (priv->rp_mutex);
    g_async_queue_lock (priv->apq);
    g_async_queue_lock (priv->vpq);

    while (g_async_queue_length_unlocked (priv->apq) > 0) {
        AVPacket *packet = g_async_queue_pop_unlocked (priv->apq);
        av_free_packet (packet);
        av_free (packet);
    }

    while (g_async_queue_length_unlocked (priv->vpq) > 0) {
        AVPacket *packet = g_async_queue_pop_unlocked (priv->vpq);
        av_free_packet (packet);
        av_free (packet);
    }

    avcodec_flush_buffers (priv->actx);
    if (priv->vctx) {
        avcodec_flush_buffers (priv->vctx);
    }

    g_async_queue_unlock (priv->apq);
    g_async_queue_unlock (priv->vpq);
    g_mutex_unlock (priv->rp_mutex);

    switch (priv->state) {
        case PLAYER_STATE_PLAYING:
            break;
        case PLAYER_STATE_PAUSED:
        case PLAYER_STATE_STOPPED:
            break;
        default:
            g_print ("Can not change position in current state\n");
    };

//    g_signal_emit (self, signal_pos, 0, player_av_get_position (self));
    _player_emit_position_changed (PLAYER (self),
        player_av_get_position (self));
}
コード例 #2
0
ファイル: rs-io.c プロジェクト: bgromov/rawstudio
/**
 * Cancel an idle request
 * @param request_id A request_id as returned by rs_io_idle_read_complete_file()
 */
void
rs_io_idle_cancel(RSIoJob *job)
{
	/* This behaves like rs_io_idle_cancel_class(), please see comments there */
	RSIoJob *current_job;
	RSIoJob *marker_job = rs_io_job_new();

	init();

	g_async_queue_lock(queue);

	/* Put a marker in the queue, we will rotate the complete queue, so we have to know when we're around */
	g_async_queue_push_unlocked(queue, marker_job);

	while((current_job = g_async_queue_pop_unlocked(queue)))
	{
		/* If current job matches marker, we're done */
		if (current_job == marker_job)
			break;

		if (current_job != job)
			g_async_queue_push_unlocked(queue, current_job);
	}

	/* Make sure the queue is sorted */
	g_async_queue_sort_unlocked(queue, queue_sort, NULL);

	g_async_queue_unlock(queue);

	g_object_unref(marker_job);
}
コード例 #3
0
static gpointer
g_thread_pool_wait_for_new_task (GRealThreadPool *pool)
{
  gpointer task = NULL;

  if (pool->running || (!pool->immediate &&
			g_async_queue_length_unlocked (pool->queue) > 0))
    {
      /* This thread pool is still active. */
      if (pool->num_threads > pool->max_threads && pool->max_threads != -1)
	{
	  /* This is a superfluous thread, so it goes to the global pool. */
	  DEBUG_MSG (("superfluous thread %p in pool %p.",
		      g_thread_self (), pool));
	}
      else if (pool->pool.exclusive)
	{
	  /* Exclusive threads stay attached to the pool. */
	  task = g_async_queue_pop_unlocked (pool->queue);

	  DEBUG_MSG (("thread %p in exclusive pool %p waits for task "
		      "(%d running, %d unprocessed).",
		      g_thread_self (), pool, pool->num_threads,
		      g_async_queue_length_unlocked (pool->queue)));
	}
      else
	{
	  /* A thread will wait for new tasks for at most 1/2
	   * second before going to the global pool.
	   */
	  GTimeVal end_time;

	  g_get_current_time (&end_time);
	  g_time_val_add (&end_time, G_USEC_PER_SEC / 2);	/* 1/2 second */

	  DEBUG_MSG (("thread %p in pool %p waits for up to a 1/2 second for task "
		      "(%d running, %d unprocessed).",
		      g_thread_self (), pool, pool->num_threads,
		      g_async_queue_length_unlocked (pool->queue)));

	  task = g_async_queue_timed_pop_unlocked (pool->queue, &end_time);
	}
    }
  else
    {
      /* This thread pool is inactive, it will no longer process tasks. */
      DEBUG_MSG (("pool %p not active, thread %p will go to global pool "
		  "(running: %s, immediate: %s, len: %d).",
		  pool, g_thread_self (),
		  pool->running ? "true" : "false",
		  pool->immediate ? "true" : "false",
		  g_async_queue_length_unlocked (pool->queue)));
    }

  return task;
}
コード例 #4
0
ファイル: iris-queue.c プロジェクト: antono/iris
static gpointer
iris_queue_real_pop (IrisQueue *queue)
{
	gpointer item;

	g_async_queue_lock (queue->priv->q);

	if (g_atomic_int_get (&queue->priv->open) == FALSE &&
	    g_async_queue_length_unlocked (queue->priv->q) <= 0) {
		g_async_queue_unlock (queue->priv->q);
		return NULL;
	}

	item = g_async_queue_pop_unlocked (queue->priv->q);

	if (g_atomic_int_get (&queue->priv->open) == FALSE)
		item = handle_close_token_ul (queue, item);
	g_async_queue_unlock (queue->priv->q);

	return item;
}
コード例 #5
0
ファイル: e-msgport.c プロジェクト: Codeminded/tinymail
EMsg *
e_msgport_wait (EMsgPort *msgport)
{
	EMsg *msg;

	g_return_val_if_fail (msgport != NULL, NULL);

	g_async_queue_lock (msgport->queue);

	msg = g_async_queue_pop_unlocked (msgport->queue);

	g_assert (msg != NULL);

	if (msg->flags & MSG_FLAG_SYNC_WITH_PIPE)
		msgport_sync_with_pipe (msgport->pipe[0]);
#ifdef HAVE_NSS
	if (msg->flags & MSG_FLAG_SYNC_WITH_PR_PIPE)
		msgport_sync_with_prpipe (msgport->prpipe[0]);
#endif

	g_async_queue_unlock (msgport->queue);

	return msg;
}