2008-04-07 09:29:30 +02:00
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* Copyright (C) 2008 Jonathan Moore Liles */
|
|
|
|
/* */
|
|
|
|
/* This program is free software; you can redistribute it and/or modify it */
|
|
|
|
/* under the terms of the GNU General Public License as published by the */
|
|
|
|
/* Free Software Foundation; either version 2 of the License, or (at your */
|
|
|
|
/* option) any later version. */
|
|
|
|
/* */
|
|
|
|
/* This program is distributed in the hope that it will be useful, but WITHOUT */
|
|
|
|
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
|
|
|
|
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
|
|
|
|
/* more details. */
|
|
|
|
/* */
|
|
|
|
/* You should have received a copy of the GNU General Public License along */
|
|
|
|
/* with This program; see the file COPYING. If not,write to the Free Software */
|
|
|
|
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2008-04-16 10:44:31 +02:00
|
|
|
#include "types.h"
|
2008-04-07 12:00:16 +02:00
|
|
|
|
2008-04-07 09:29:30 +02:00
|
|
|
#include <jack/ringbuffer.h>
|
|
|
|
#include <semaphore.h>
|
2008-04-07 12:00:16 +02:00
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <pthread.h>
|
2008-04-07 09:29:30 +02:00
|
|
|
|
2008-04-12 21:13:30 +02:00
|
|
|
#include "Mutex.H"
|
|
|
|
|
2008-04-07 10:12:01 +02:00
|
|
|
#include <vector>
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
class Track_Header;
|
2008-04-07 12:00:16 +02:00
|
|
|
class Audio_Track;
|
2008-04-07 10:00:33 +02:00
|
|
|
|
2008-04-12 21:13:30 +02:00
|
|
|
class Disk_Stream : public Mutex
|
2008-04-07 09:29:30 +02:00
|
|
|
{
|
|
|
|
|
2008-04-16 10:44:31 +02:00
|
|
|
protected:
|
2008-04-07 12:00:16 +02:00
|
|
|
|
2008-04-16 10:44:31 +02:00
|
|
|
pthread_t _thread; /* io thread */
|
2008-04-07 09:29:30 +02:00
|
|
|
|
2008-04-16 10:44:31 +02:00
|
|
|
Track_Header *_th; /* Track_Header we belong to */
|
2008-04-07 09:29:30 +02:00
|
|
|
|
2008-04-16 10:44:31 +02:00
|
|
|
nframes_t _nframes; /* buffer size */
|
2008-04-07 09:29:30 +02:00
|
|
|
|
2008-04-16 10:44:31 +02:00
|
|
|
nframes_t _frame; /* location of disk read */
|
2008-04-07 09:29:30 +02:00
|
|
|
|
2008-04-16 10:44:31 +02:00
|
|
|
vector < jack_ringbuffer_t * >_rb; /* one ringbuffer for each channel */
|
2008-04-07 09:29:30 +02:00
|
|
|
|
2008-04-16 10:44:31 +02:00
|
|
|
sem_t _blocks; /* semaphore to wake the IO thread with */
|
2008-04-12 21:13:30 +02:00
|
|
|
|
2008-04-16 10:44:31 +02:00
|
|
|
int _total_blocks; /* total number of blocks that we can buffer */
|
2008-04-12 21:13:30 +02:00
|
|
|
|
2008-04-16 10:44:31 +02:00
|
|
|
volatile nframes_t _pending_seek; /* absolute transport position to seek to */
|
2008-04-12 21:13:30 +02:00
|
|
|
volatile int _terminate;
|
2008-04-10 05:44:02 +02:00
|
|
|
|
2008-04-07 09:29:30 +02:00
|
|
|
int channels ( void ) const { return _rb.size(); }
|
|
|
|
|
2008-04-07 12:00:16 +02:00
|
|
|
Audio_Track * track ( void );
|
|
|
|
|
2008-04-16 10:44:31 +02:00
|
|
|
static void *disk_thread ( void *arg );
|
2008-04-07 10:00:33 +02:00
|
|
|
|
2008-04-07 09:29:30 +02:00
|
|
|
protected:
|
|
|
|
|
|
|
|
void block_processed ( void ) { sem_post( &_blocks ); }
|
2008-04-12 21:13:30 +02:00
|
|
|
bool wait_for_block ( void )
|
|
|
|
{
|
|
|
|
if ( _terminate )
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while ( sem_wait( &_blocks ) == EINTR );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-16 10:44:31 +02:00
|
|
|
virtual void disk_thread ( void ) = 0;
|
2008-04-07 09:29:30 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2008-04-07 10:00:33 +02:00
|
|
|
/* must be set before any Disk_Streams are created */
|
2008-04-07 09:29:30 +02:00
|
|
|
static float seconds_to_buffer;
|
|
|
|
|
2008-04-07 12:00:16 +02:00
|
|
|
Disk_Stream ( Track_Header *th, float frame_rate, nframes_t nframes, int channels );
|
2008-04-07 09:29:30 +02:00
|
|
|
|
2008-04-07 10:00:33 +02:00
|
|
|
virtual ~Disk_Stream ( );
|
2008-04-07 09:29:30 +02:00
|
|
|
|
2008-04-12 21:13:30 +02:00
|
|
|
void resize ( nframes_t nframes );
|
2008-04-16 10:44:31 +02:00
|
|
|
|
|
|
|
/* void seek ( nframes_t frame ); */
|
|
|
|
/* bool seek_pending ( void ); */
|
2008-04-07 09:29:30 +02:00
|
|
|
|
|
|
|
void run ( void );
|
2008-04-16 17:35:25 +02:00
|
|
|
void shutdown ( void );
|
2008-04-07 09:29:30 +02:00
|
|
|
|
2008-04-16 10:44:31 +02:00
|
|
|
virtual nframes_t process ( nframes_t nframes ) = 0;
|
|
|
|
|
|
|
|
int buffer_percent ( void );
|
|
|
|
|
2008-04-07 09:29:30 +02:00
|
|
|
};
|