示例#1
0
void PipelinedModCodec::process_thread()
{
    set_thread_name(name());
    set_realtime_prio(1);

    while (m_running) {
        Buffer dataIn;
        m_input_queue.wait_and_pop(dataIn);

        if (dataIn.getLength() == 0) {
            break;
        }

        Buffer dataOut;
        dataOut.setLength(dataIn.getLength());

        if (internal_process(&dataIn, &dataOut) == 0) {
            m_running = false;
        }

        m_output_queue.push(std::move(dataOut));
    }

    m_running = false;
}
示例#2
0
文件: out_buf.c 项目: Manishearth/moc
/* Reading thread of the buffer. */
static void *read_thread (void *arg)
{
	struct out_buf *buf = (struct out_buf *)arg;
	int audio_dev_closed = 0;

	logit ("entering output buffer thread");

	set_realtime_prio ();

	LOCK (buf->mutex);

	while (1) {
		int played = 0;
		char play_buf[AUDIO_MAX_PLAY_BYTES];
		int play_buf_fill;
		int play_buf_pos = 0;

		if (buf->reset_dev && !audio_dev_closed) {
			audio_reset ();
			buf->reset_dev = 0;
		}

		if (buf->stop)
			fifo_buf_clear (&buf->buf);

		if (buf->free_callback) {

			/* unlock the mutex to make calls to out_buf functions
			 * possible in the callback */
			UNLOCK (buf->mutex);
			buf->free_callback ();
			LOCK (buf->mutex);
		}

		debug ("sending the signal");
		pthread_cond_broadcast (&buf->ready_cond);

		if ((fifo_buf_get_fill(&buf->buf) == 0 || buf->pause
					|| buf->stop)
				&& !buf->exit) {
			if (buf->pause && !audio_dev_closed) {
				logit ("Closing the device due to pause");
				audio_close ();
				audio_dev_closed = 1;
			}

			debug ("waiting for something in the buffer");
			buf->read_thread_waiting = 1;
			pthread_cond_wait (&buf->play_cond, &buf->mutex);
			debug ("something appeared in the buffer");

		}

		buf->read_thread_waiting = 0;

		if (audio_dev_closed && !buf->pause) {
			logit ("Opening the device again after pause");
			if (!audio_open(NULL)) {
				logit ("Can't reopen the device! sleeping...");
				sleep (1); /* there is no way to exit :( */
			}
			else
				audio_dev_closed = 0;
		}

		if (fifo_buf_get_fill(&buf->buf) == 0) {
			if (buf->exit) {
				logit ("exit");
				break;
			}

			logit ("buffer empty");
			continue;
		}

		if (buf->pause) {
			logit ("paused");
			continue;
		}

		if (buf->stop) {
			logit ("stopped");
			continue;
		}

		if (!audio_dev_closed) {
			int audio_bpf;
			size_t play_buf_frames;

			audio_bpf = audio_get_bpf();
			play_buf_frames = MIN(audio_get_bps() * AUDIO_MAX_PLAY,
			                      AUDIO_MAX_PLAY_BYTES) / audio_bpf;
			play_buf_fill = fifo_buf_get(&buf->buf, play_buf,
			                             play_buf_frames * audio_bpf);
			UNLOCK (buf->mutex);

			debug ("playing %d bytes", play_buf_fill);

			while (play_buf_pos < play_buf_fill) {
				played = audio_send_pcm (
						play_buf + play_buf_pos,
						play_buf_fill - play_buf_pos);
				play_buf_pos += played;
			}

			/*logit ("done sending PCM");*/
			/*write (fd, buf->buf + buf->pos, to_play);*/

			LOCK (buf->mutex);

			/* Update time */
			if (played && audio_get_bps())
				buf->time += played / (float)audio_get_bps();
			buf->hardware_buf_fill = audio_get_buf_fill();
		}
	}

	UNLOCK (buf->mutex);

	logit ("exiting");

	return NULL;
}