New API call burn_fifo_peek_data()
This commit is contained in:
parent
38f0399fff
commit
9d48bb6892
@ -1 +1 @@
|
|||||||
#define Cdrskin_timestamP "2008.07.14.113152"
|
#define Cdrskin_timestamP "2008.07.14.113903"
|
||||||
|
@ -43,7 +43,15 @@
|
|||||||
#include "libdax_msgs.h"
|
#include "libdax_msgs.h"
|
||||||
extern struct libdax_msgs *libdax_messenger;
|
extern struct libdax_msgs *libdax_messenger;
|
||||||
|
|
||||||
#define SCAN_GOING() (workers && !workers->drive)
|
/* ts A80714 : introduced type codes for the worker list */
|
||||||
|
#define Burnworker_type_scaN 0
|
||||||
|
#define Burnworker_type_erasE 1
|
||||||
|
#define Burnworker_type_formaT 2
|
||||||
|
#define Burnworker_type_writE 3
|
||||||
|
#define Burnworker_type_fifO 4
|
||||||
|
|
||||||
|
#define SCAN_GOING() (workers != NULL && \
|
||||||
|
workers->w_type == Burnworker_type_scaN)
|
||||||
|
|
||||||
typedef void *(*WorkerFunc) (void *);
|
typedef void *(*WorkerFunc) (void *);
|
||||||
|
|
||||||
@ -85,6 +93,9 @@ struct fifo_opts
|
|||||||
|
|
||||||
struct w_list
|
struct w_list
|
||||||
{
|
{
|
||||||
|
/* ts A80714 */
|
||||||
|
int w_type; /* see above define Burnworker_type_* */
|
||||||
|
|
||||||
struct burn_drive *drive;
|
struct burn_drive *drive;
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
|
|
||||||
@ -113,7 +124,8 @@ static struct w_list *find_worker(struct burn_drive *d)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_worker(struct burn_drive *d, WorkerFunc f, void *data)
|
static void add_worker(int w_type, struct burn_drive *d,
|
||||||
|
WorkerFunc f, void *data)
|
||||||
{
|
{
|
||||||
struct w_list *a;
|
struct w_list *a;
|
||||||
struct w_list *tmp;
|
struct w_list *tmp;
|
||||||
@ -124,6 +136,7 @@ static void add_worker(struct burn_drive *d, WorkerFunc f, void *data)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
a = malloc(sizeof(struct w_list));
|
a = malloc(sizeof(struct w_list));
|
||||||
|
a->w_type = w_type;
|
||||||
a->drive = d;
|
a->drive = d;
|
||||||
a->u = *(union w_list_data *)data;
|
a->u = *(union w_list_data *)data;
|
||||||
|
|
||||||
@ -259,7 +272,8 @@ drive_is_active:;
|
|||||||
o.drives = drives;
|
o.drives = drives;
|
||||||
o.n_drives = n_drives;
|
o.n_drives = n_drives;
|
||||||
o.done = 0;
|
o.done = 0;
|
||||||
add_worker(NULL, (WorkerFunc) scan_worker_func, &o);
|
add_worker(Burnworker_type_scaN, NULL,
|
||||||
|
(WorkerFunc) scan_worker_func, &o);
|
||||||
} else if (workers->u.scan.done) {
|
} else if (workers->u.scan.done) {
|
||||||
/* its done */
|
/* its done */
|
||||||
ret = workers->u.scan.done;
|
ret = workers->u.scan.done;
|
||||||
@ -303,7 +317,7 @@ void burn_disc_erase(struct burn_drive *drive, int fast)
|
|||||||
"NULL pointer caught in burn_disc_erase", 0, 0);
|
"NULL pointer caught in burn_disc_erase", 0, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((SCAN_GOING()) || find_worker(drive)) {
|
if ((SCAN_GOING()) || find_worker(drive) != NULL) {
|
||||||
libdax_msgs_submit(libdax_messenger, drive->global_index,
|
libdax_msgs_submit(libdax_messenger, drive->global_index,
|
||||||
0x00020102,
|
0x00020102,
|
||||||
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
|
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
|
||||||
@ -343,7 +357,8 @@ void burn_disc_erase(struct burn_drive *drive, int fast)
|
|||||||
|
|
||||||
o.drive = drive;
|
o.drive = drive;
|
||||||
o.fast = fast;
|
o.fast = fast;
|
||||||
add_worker(drive, (WorkerFunc) erase_worker_func, &o);
|
add_worker(Burnworker_type_erasE, drive,
|
||||||
|
(WorkerFunc) erase_worker_func, &o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -364,7 +379,7 @@ void burn_disc_format(struct burn_drive *drive, off_t size, int flag)
|
|||||||
int ok = 0;
|
int ok = 0;
|
||||||
char msg[160];
|
char msg[160];
|
||||||
|
|
||||||
if ((SCAN_GOING()) || find_worker(drive)) {
|
if ((SCAN_GOING()) || find_worker(drive) != NULL) {
|
||||||
libdax_msgs_submit(libdax_messenger, drive->global_index,
|
libdax_msgs_submit(libdax_messenger, drive->global_index,
|
||||||
0x00020102,
|
0x00020102,
|
||||||
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
|
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
|
||||||
@ -411,7 +426,8 @@ void burn_disc_format(struct burn_drive *drive, off_t size, int flag)
|
|||||||
o.drive = drive;
|
o.drive = drive;
|
||||||
o.size = size;
|
o.size = size;
|
||||||
o.flag = flag;
|
o.flag = flag;
|
||||||
add_worker(drive, (WorkerFunc) format_worker_func, &o);
|
add_worker(Burnworker_type_formaT, drive,
|
||||||
|
(WorkerFunc) format_worker_func, &o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -441,7 +457,7 @@ void burn_disc_write(struct burn_write_opts *opts, struct burn_disc *disc)
|
|||||||
/* ts A61006 */
|
/* ts A61006 */
|
||||||
/* a ssert(!SCAN_GOING()); */
|
/* a ssert(!SCAN_GOING()); */
|
||||||
/* a ssert(!find_worker(opts->drive)); */
|
/* a ssert(!find_worker(opts->drive)); */
|
||||||
if ((SCAN_GOING()) || find_worker(opts->drive)) {
|
if ((SCAN_GOING()) || find_worker(opts->drive) != NULL) {
|
||||||
libdax_msgs_submit(libdax_messenger, opts->drive->global_index,
|
libdax_msgs_submit(libdax_messenger, opts->drive->global_index,
|
||||||
0x00020102,
|
0x00020102,
|
||||||
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
|
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
|
||||||
@ -495,7 +511,8 @@ void burn_disc_write(struct burn_write_opts *opts, struct burn_disc *disc)
|
|||||||
|
|
||||||
opts->refcount++;
|
opts->refcount++;
|
||||||
|
|
||||||
add_worker(opts->drive, (WorkerFunc) write_disc_worker_func, &o);
|
add_worker(Burnworker_type_writE, opts->drive,
|
||||||
|
(WorkerFunc) write_disc_worker_func, &o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -523,7 +540,8 @@ int burn_fifo_start(struct burn_source *source, int flag)
|
|||||||
|
|
||||||
o.source = source;
|
o.source = source;
|
||||||
o.flag = flag;
|
o.flag = flag;
|
||||||
add_worker(NULL, (WorkerFunc) fifo_worker_func, &o);
|
add_worker(Burnworker_type_fifO, NULL,
|
||||||
|
(WorkerFunc) fifo_worker_func, &o);
|
||||||
fs->is_started = 1;
|
fs->is_started = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -540,3 +540,64 @@ int burn_fifo_inquire_status(struct burn_source *source,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int burn_fifo_peek_data(struct burn_source *source, char *buf, int bufsize,
|
||||||
|
int flag)
|
||||||
|
{
|
||||||
|
int size, free_bytes, ret, wait_count= 0;
|
||||||
|
char *status_text;
|
||||||
|
struct burn_source_fifo *fs = source->data;
|
||||||
|
|
||||||
|
/* Eventually start fifo thread by reading 0 bytes */
|
||||||
|
ret = fifo_read(source, (unsigned char *) NULL, 0);
|
||||||
|
if (ret<0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* wait for at least bufsize bytes being ready */
|
||||||
|
while (1) {
|
||||||
|
ret= burn_fifo_inquire_status(source,
|
||||||
|
&size, &free_bytes, &status_text);
|
||||||
|
if (size < bufsize) {
|
||||||
|
libdax_msgs_submit(libdax_messenger, -1, 0x0002015c,
|
||||||
|
LIBDAX_MSGS_SEV_FAILURE, LIBDAX_MSGS_PRIO_HIGH,
|
||||||
|
"Fifo size is smaller than desired peek buffer", 0, 0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (fs->out_counter > 0 || (ret & 4) || fs->buf == NULL) {
|
||||||
|
libdax_msgs_submit(libdax_messenger, -1, 0x0002015e,
|
||||||
|
LIBDAX_MSGS_SEV_FATAL, LIBDAX_MSGS_PRIO_HIGH,
|
||||||
|
"Fifo is already under consumption when peeking is desired",
|
||||||
|
0, 0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(size - free_bytes >= bufsize) {
|
||||||
|
|
||||||
|
/* <<<
|
||||||
|
fprintf(stderr,
|
||||||
|
"libburn_DEBUG: after waiting cycle %d : fifo %s , %d bytes\n",
|
||||||
|
wait_count, status_text, size - free_bytes);
|
||||||
|
*/
|
||||||
|
|
||||||
|
memcpy(buf, fs->buf, bufsize);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (ret&2) { /* input has ended, not enough data arrived */
|
||||||
|
libdax_msgs_submit(libdax_messenger, -1, 0x0002015d,
|
||||||
|
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
|
||||||
|
"Fifo input ended short of desired peek buffer size",
|
||||||
|
0, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
usleep(100000);
|
||||||
|
wait_count++;
|
||||||
|
|
||||||
|
/* <<<
|
||||||
|
if(wait_count%10==0)
|
||||||
|
fprintf(stderr,
|
||||||
|
"libburn_DEBUG: waiting cycle %d : fifo %s , %d bytes\n",
|
||||||
|
wait_count, status_text, size - free_bytes);
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
@ -1619,6 +1619,30 @@ int burn_fifo_inquire_status(struct burn_source *fifo, int *size,
|
|||||||
int *free_bytes, char **status_text);
|
int *free_bytes, char **status_text);
|
||||||
|
|
||||||
|
|
||||||
|
/* ts A80713 */
|
||||||
|
/** Obtain a preview of the first input data of a fifo which was created
|
||||||
|
by burn_fifo_source_new(). The data will later be delivered normally to
|
||||||
|
the consumer track of the fifo.
|
||||||
|
bufsize may not be larger than the fifo size (chunk_size * chunks).
|
||||||
|
This call will succeed only if data consumption by the track has not
|
||||||
|
started yet, i.e. best before the call to burn_disc_write().
|
||||||
|
It will start the worker thread of the fifo with the expectable side
|
||||||
|
effects on the external data source. Then it waits either until enough
|
||||||
|
data have arrived or until it becomes clear that this will not happen.
|
||||||
|
The call may be repeated with increased bufsize. It will always yield
|
||||||
|
the bytes beginning from the first one in the fifo.
|
||||||
|
@param fifo The fifo object to inquire
|
||||||
|
@param buf Pointer to memory of at least bufsize bytes where to
|
||||||
|
deliver the peeked data
|
||||||
|
@param bufsize Number of bytes to peek from the start of the fifo data
|
||||||
|
@param flag Bitfield for control purposes (unused yet, submit 0).
|
||||||
|
@return <0 on severe error, 0 if not enough data, 1 if bufsize bytes read
|
||||||
|
@since 0.5.0
|
||||||
|
*/
|
||||||
|
int burn_fifo_peek_data(struct burn_source *source, char *buf, int bufsize,
|
||||||
|
int flag);
|
||||||
|
|
||||||
|
|
||||||
/* ts A70328 */
|
/* ts A70328 */
|
||||||
/** Sets a fixed track size after the data source object has already been
|
/** Sets a fixed track size after the data source object has already been
|
||||||
created.
|
created.
|
||||||
|
Loading…
Reference in New Issue
Block a user