2008-12-09 19:46:00 +00:00
|
|
|
/* vim: set sw=3 ts=3 sts=3 expandtab: */
|
2008-04-01 21:30:41 +00:00
|
|
|
#include "ecdb.h"
|
|
|
|
|
|
|
|
typedef struct Burn_Data Burn_Data;
|
|
|
|
struct Burn_Data
|
|
|
|
{
|
2008-12-09 05:47:59 +00:00
|
|
|
BurnDisc *disc;
|
|
|
|
BurnSession *session;
|
2008-12-18 18:54:50 +00:00
|
|
|
Eina_List *sources;
|
|
|
|
Eina_List *tracks;
|
2009-02-17 22:48:11 +00:00
|
|
|
Ecdb_Project *proj;
|
2009-02-17 19:16:38 +00:00
|
|
|
Ecdb_Page *page;
|
2008-04-01 21:30:41 +00:00
|
|
|
};
|
|
|
|
|
2008-04-07 01:04:15 +00:00
|
|
|
int ecdb_burn_finished(void *data, int type, void *event);
|
2008-05-15 00:14:33 +00:00
|
|
|
int ecdb_erase_project_init(Ecdb_Erase_Project *proj);
|
2008-11-12 16:06:29 +00:00
|
|
|
static void ecdb_burn_progress_handler(void *data, void *buffer,
|
2008-12-09 05:47:59 +00:00
|
|
|
unsigned int nbyte);
|
2008-12-18 18:54:50 +00:00
|
|
|
void ecdb_sources_list_free(Eina_List *list);
|
|
|
|
void ecdb_tracks_list_free(Eina_List *list);
|
2008-12-09 02:38:04 +00:00
|
|
|
|
2008-04-01 21:30:41 +00:00
|
|
|
int
|
2009-02-17 19:16:38 +00:00
|
|
|
ecdb_burn_project(Ecdb_Burn_Project *proj, Ecdb_Page *page)
|
2008-04-01 21:30:41 +00:00
|
|
|
{
|
2008-12-09 05:47:59 +00:00
|
|
|
char reasons[BURN_REASONS_LEN];
|
|
|
|
int padding, i;
|
|
|
|
Burn_Data *data;
|
|
|
|
BurnTrack *track;
|
|
|
|
BurnSource *source;
|
|
|
|
BurnWriteOpts *opts;
|
|
|
|
pthread_t progress_update;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
data = calloc(1, sizeof(Burn_Data));
|
|
|
|
if (!data)
|
|
|
|
{
|
|
|
|
printf("Error: Cannot create burn data structure!\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-02-17 22:48:11 +00:00
|
|
|
data->proj = ECDB_PROJECT(proj);
|
2009-02-17 19:16:38 +00:00
|
|
|
data->page = page;
|
2008-12-09 05:47:59 +00:00
|
|
|
|
|
|
|
if (proj->burn_mode != BURN_AUDIO)
|
|
|
|
padding = 300*1024;
|
|
|
|
|
|
|
|
data->disc = burn_disc_create();
|
|
|
|
data->session = burn_session_create();
|
|
|
|
burn_disc_add_session(data->disc, data->session, BURN_POS_END);
|
|
|
|
|
|
|
|
track = burn_track_create();
|
|
|
|
burn_track_define_data(track, 0, padding, 1, proj->burn_mode);
|
|
|
|
|
|
|
|
source = ecdb_image_project(proj);
|
|
|
|
if (!source)
|
|
|
|
{
|
|
|
|
printf("Failed to add any files to burn disc!\n");
|
|
|
|
burn_session_free(data->session);
|
|
|
|
burn_disc_free(data->disc);
|
2008-12-18 18:54:50 +00:00
|
|
|
ecdb_sources_list_free(data->sources);
|
|
|
|
ecdb_tracks_list_free(data->tracks);
|
2008-12-09 05:47:59 +00:00
|
|
|
FREE(data);
|
|
|
|
return ECDB_ERROR_IMAGE_CREATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (burn_track_set_source(track, source) != BURN_SOURCE_OK)
|
|
|
|
{
|
|
|
|
printf("Error: Cannot attach source object to track object!\n");
|
|
|
|
burn_session_free(data->session);
|
|
|
|
burn_disc_free(data->disc);
|
2008-12-18 18:54:50 +00:00
|
|
|
ecdb_sources_list_free(data->sources);
|
|
|
|
ecdb_tracks_list_free(data->tracks);
|
2008-12-09 05:47:59 +00:00
|
|
|
FREE(data);
|
|
|
|
return ECDB_ERROR_SOURCE_ATTACH;
|
|
|
|
}
|
|
|
|
|
|
|
|
burn_session_add_track(data->session, track, BURN_POS_END);
|
2008-12-18 18:54:50 +00:00
|
|
|
data->sources = eina_list_append(data->sources, source);
|
|
|
|
data->tracks = eina_list_append(data->tracks, track);
|
2008-12-09 05:47:59 +00:00
|
|
|
|
|
|
|
opts = burn_write_opts_new(ECDB_PROJECT(proj)->drive->tangible[0].drive);
|
|
|
|
burn_write_opts_set_perform_opc(opts, proj->opc);
|
|
|
|
burn_write_opts_set_multi(opts, proj->multi);
|
|
|
|
if (proj->simulate)
|
|
|
|
{
|
|
|
|
printf("Simulating Burn!\n");
|
|
|
|
}
|
|
|
|
burn_write_opts_set_simulate(opts, proj->simulate);
|
|
|
|
burn_drive_set_speed(ECDB_PROJECT(proj)->drive->tangible->drive, 0,
|
|
|
|
proj->speed);
|
|
|
|
burn_write_opts_set_underrun_proof(opts, proj->underrun_proof);
|
|
|
|
|
|
|
|
printf("Searching for burn mode\n");
|
|
|
|
if (burn_write_opts_auto_write_type(opts, data->disc, reasons, 0)
|
|
|
|
== BURN_WRITE_NONE)
|
|
|
|
{
|
|
|
|
printf("Error: Failed to find a suitable write mode for disc!\n");
|
|
|
|
burn_session_free(data->session);
|
|
|
|
burn_disc_free(data->disc);
|
|
|
|
burn_write_opts_free(opts);
|
2008-12-18 18:54:50 +00:00
|
|
|
ecdb_sources_list_free(data->sources);
|
|
|
|
ecdb_tracks_list_free(data->tracks);
|
2008-12-18 22:16:55 +00:00
|
|
|
FREE(data);
|
2008-12-09 05:47:59 +00:00
|
|
|
return ECDB_ERROR_WRITE_MODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
burn_disc_write(opts, data->disc);
|
|
|
|
burn_write_opts_free(opts);
|
|
|
|
|
|
|
|
printf("Disc now burning\n");
|
2009-02-17 19:16:38 +00:00
|
|
|
ECDB_PROJECT(proj)->pipe = ecore_pipe_add(ecdb_burn_progress_handler, data);
|
2008-12-09 05:47:59 +00:00
|
|
|
pthread_create(&progress_update, NULL, ecdb_drive_progress_update, proj);
|
|
|
|
pthread_detach(progress_update);
|
|
|
|
ECDB_PROJECT(proj)->ev_handler = ecore_event_handler_add
|
|
|
|
(ECDB_DRIVE_ACTION_FINISHED, ecdb_burn_finished, data);
|
|
|
|
|
|
|
|
return ECDB_ERROR_NONE;
|
2008-05-15 00:14:33 +00:00
|
|
|
}
|
|
|
|
|
2008-11-03 15:56:34 +00:00
|
|
|
/* This function is pretty naive... Should probably update it at some time */
|
2008-04-01 21:30:41 +00:00
|
|
|
void *
|
2008-11-03 15:56:34 +00:00
|
|
|
ecdb_drive_progress_update(void *data)
|
2008-04-01 21:30:41 +00:00
|
|
|
{
|
2008-12-09 05:47:59 +00:00
|
|
|
const Ecdb_Project *proj;
|
|
|
|
BurnProgress p;
|
|
|
|
struct burn_drive *drive;
|
|
|
|
|
|
|
|
proj = data;
|
|
|
|
|
|
|
|
if (!proj->drive->tangible)
|
|
|
|
{
|
|
|
|
printf("No tangible drive!\n");
|
|
|
|
ecore_pipe_del(proj->pipe);
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
drive = proj->drive->tangible[0].drive;
|
|
|
|
|
|
|
|
printf("Progress update active\n");
|
|
|
|
while (burn_drive_get_status(drive, NULL) == BURN_DRIVE_SPAWNING)
|
|
|
|
{
|
|
|
|
usleep(100000);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (burn_drive_get_status(drive, &p) != BURN_DRIVE_IDLE)
|
|
|
|
{
|
|
|
|
if (p.sectors > 0)
|
|
|
|
{
|
|
|
|
ecore_pipe_write(proj->pipe, &p, sizeof(p));
|
|
|
|
}
|
|
|
|
usleep(100000);
|
|
|
|
}
|
|
|
|
|
2008-12-26 16:41:27 +00:00
|
|
|
printf("Closing pipe\n");
|
|
|
|
ecore_pipe_write(proj->pipe, proj->pipe, sizeof(Ecore_Pipe));
|
2008-12-09 05:47:59 +00:00
|
|
|
pthread_exit(NULL);
|
2008-04-01 21:30:41 +00:00
|
|
|
}
|
|
|
|
|
2008-11-03 15:56:34 +00:00
|
|
|
static void
|
2008-11-12 16:06:29 +00:00
|
|
|
ecdb_burn_progress_handler(void *data, void *buffer, unsigned int nbyte)
|
2008-04-07 01:04:15 +00:00
|
|
|
{
|
2008-12-09 05:47:59 +00:00
|
|
|
BurnProgress *p;
|
2009-02-17 22:48:11 +00:00
|
|
|
Evas_Object *swallow;
|
2009-02-17 19:16:38 +00:00
|
|
|
Burn_Data *bdata;
|
2008-12-09 05:47:59 +00:00
|
|
|
static int last_sector = 0;
|
2008-12-09 23:58:51 +00:00
|
|
|
int percent;
|
2008-12-26 16:41:27 +00:00
|
|
|
Edje_Message_Int_Set *progress_msg;
|
2008-12-26 05:52:47 +00:00
|
|
|
Edje_Message_String finalize;
|
2008-12-09 05:47:59 +00:00
|
|
|
|
2008-12-26 16:41:27 +00:00
|
|
|
if (nbyte != sizeof(BurnProgress))
|
2008-12-09 05:47:59 +00:00
|
|
|
{
|
|
|
|
ecore_event_add(ECDB_DRIVE_ACTION_FINISHED, NULL, NULL, NULL);
|
2008-12-26 16:41:27 +00:00
|
|
|
printf("Adding event to queue.\n");
|
2008-12-09 05:47:59 +00:00
|
|
|
last_sector = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p = buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Libburn reports p->sector as being 0 right at the end of the job,
|
|
|
|
* so store the last sector and use that to determine the proper
|
|
|
|
* percentage/sector to set
|
|
|
|
*/
|
|
|
|
if (last_sector <= p->sector)
|
|
|
|
{
|
|
|
|
last_sector = p->sector;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
last_sector = p->sectors;
|
2009-02-17 22:48:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bdata = data;
|
|
|
|
if (!bdata)
|
|
|
|
{
|
|
|
|
printf("ecdb_burn_progress_handler: NULL bdata!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((!bdata->page) || (!bdata->proj))
|
|
|
|
{
|
|
|
|
printf("ecdb_burn_progress_handler: NULL page or proj!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (bdata->proj->type)
|
|
|
|
{
|
|
|
|
case ECDB_AUDIO_PROJECT:
|
|
|
|
swallow = bdata->page->audio;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ECDB_DATA_PROJECT:
|
|
|
|
swallow = bdata->page->data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ECDB_IMAGE_PROJECT:
|
|
|
|
swallow = bdata->page->image;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("ecdb_burn_progress_handler: Unrecognized project type!\n");
|
|
|
|
return;
|
2008-12-09 05:47:59 +00:00
|
|
|
}
|
|
|
|
|
2008-12-09 23:58:51 +00:00
|
|
|
percent = (int)((double)(last_sector + 1) / (double)p->sectors * 100.0);
|
|
|
|
if (percent >= 100)
|
|
|
|
{
|
2008-12-26 05:52:47 +00:00
|
|
|
finalize.str = "Finalizing disc...";
|
|
|
|
edje_object_message_send(swallow, EDJE_MESSAGE_STRING, 1, &finalize);
|
2008-12-09 23:58:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-26 05:52:47 +00:00
|
|
|
progress_msg = alloca(sizeof(Edje_Message_Int_Set) + (4 * sizeof(int)));
|
|
|
|
progress_msg->count = 5;
|
|
|
|
progress_msg->val[0] = percent;
|
|
|
|
progress_msg->val[1] = last_sector;
|
|
|
|
progress_msg->val[2] = p->sectors;
|
|
|
|
progress_msg->val[3] = (int)p->buffer_available;
|
|
|
|
progress_msg->val[4] = (int)p->buffer_capacity;
|
|
|
|
edje_object_message_send(swallow, EDJE_MESSAGE_INT_SET, 0, progress_msg);
|
2008-12-09 23:58:51 +00:00
|
|
|
}
|
2008-04-07 01:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ecdb_burn_finished(void *data, int type, void *event)
|
|
|
|
{
|
2008-12-09 05:47:59 +00:00
|
|
|
Burn_Data *proj;
|
2008-04-07 01:04:15 +00:00
|
|
|
|
2008-12-09 05:47:59 +00:00
|
|
|
proj = data;
|
2008-04-07 01:04:15 +00:00
|
|
|
|
2008-12-09 05:47:59 +00:00
|
|
|
printf("Freeing source and tracks\n");
|
2008-12-18 18:54:50 +00:00
|
|
|
ecdb_sources_list_free(proj->sources);
|
|
|
|
ecdb_tracks_list_free(proj->tracks);
|
2008-04-07 01:04:15 +00:00
|
|
|
|
2008-12-09 05:47:59 +00:00
|
|
|
printf("Freeing session and disc\n");
|
|
|
|
burn_session_free(proj->session);
|
|
|
|
burn_disc_free(proj->disc);
|
2008-04-07 01:04:15 +00:00
|
|
|
|
2008-12-09 05:47:59 +00:00
|
|
|
printf("Releasing drive\n");
|
|
|
|
burn_drive_release(proj->proj->drive->tangible[0].drive, 1);
|
|
|
|
burn_drive_info_free(proj->proj->drive->tangible);
|
|
|
|
printf("Burn Complete\n");
|
2008-04-07 01:04:15 +00:00
|
|
|
|
2009-02-17 22:48:11 +00:00
|
|
|
ecore_event_handler_del(proj->proj->ev_handler);
|
2009-02-17 19:16:38 +00:00
|
|
|
proj->proj->ev_handler = NULL;
|
2009-02-17 22:48:11 +00:00
|
|
|
ecore_pipe_del(proj->proj->pipe);
|
2009-02-17 19:16:38 +00:00
|
|
|
proj->proj->pipe = NULL;
|
2008-06-05 19:20:29 +00:00
|
|
|
|
2008-12-09 05:47:59 +00:00
|
|
|
switch (proj->proj->type)
|
|
|
|
{
|
2009-02-17 22:48:11 +00:00
|
|
|
case ECDB_AUDIO_PROJECT:
|
|
|
|
printf("How in the world did you get here?\n");
|
2009-02-17 19:16:38 +00:00
|
|
|
//ecdb_burn_audio_cleanup(proj->page);
|
2008-12-09 05:47:59 +00:00
|
|
|
break;
|
2008-12-09 01:12:16 +00:00
|
|
|
|
2008-12-23 22:42:15 +00:00
|
|
|
case ECDB_BURN_PROJECT:
|
2009-02-17 19:16:38 +00:00
|
|
|
ecdb_burn_data_cleanup(proj->page);
|
2008-12-23 22:42:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ECDB_IMAGE_PROJECT:
|
2009-02-17 22:48:11 +00:00
|
|
|
ecdb_burn_image_cleanup(proj->page);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-02-17 19:16:38 +00:00
|
|
|
printf("ecdb_burn_finished: unknown project type!\n");
|
2008-12-09 05:47:59 +00:00
|
|
|
}
|
|
|
|
FREE(proj);
|
2008-12-09 02:38:04 +00:00
|
|
|
|
2008-12-09 05:47:59 +00:00
|
|
|
return TRUE;
|
2008-12-09 02:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-12-18 18:54:50 +00:00
|
|
|
ecdb_sources_list_free(Eina_List *list)
|
2008-12-09 02:38:04 +00:00
|
|
|
{
|
2008-12-18 18:54:50 +00:00
|
|
|
Eina_List *l;
|
|
|
|
void *data;
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH(list, l, data)
|
|
|
|
burn_source_free(data);
|
|
|
|
|
|
|
|
list = eina_list_free(list);
|
2008-12-09 02:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-12-18 18:54:50 +00:00
|
|
|
ecdb_tracks_list_free(Eina_List *list)
|
2008-12-09 02:38:04 +00:00
|
|
|
{
|
2008-12-18 18:54:50 +00:00
|
|
|
Eina_List *l;
|
|
|
|
void *data;
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH(list, l, data)
|
|
|
|
burn_track_free(data);
|
|
|
|
|
|
|
|
list = eina_list_free(list);
|
2008-12-09 02:38:04 +00:00
|
|
|
}
|