Organized ecdb source code in structure
This commit is contained in:
158
experimental/ecdb/trunk/src/ecdb_burn.c
Normal file
158
experimental/ecdb/trunk/src/ecdb_burn.c
Normal file
@@ -0,0 +1,158 @@
|
||||
#include "ecdb.h"
|
||||
|
||||
typedef struct Burn_Data Burn_Data;
|
||||
struct Burn_Data
|
||||
{
|
||||
BurnDisc *disc;
|
||||
BurnSession *session;
|
||||
Ecore_List *sources;
|
||||
Ecore_List *tracks;
|
||||
Ecdb_Project *proj;
|
||||
};
|
||||
|
||||
void *_progress_update(void *d);
|
||||
|
||||
/* Event handlers */
|
||||
int
|
||||
ecdb_burn_project(Ecdb_Project *proj)
|
||||
{
|
||||
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));
|
||||
data->sources = ecore_list_new();
|
||||
data->tracks = ecore_list_new();
|
||||
data->proj = proj;
|
||||
|
||||
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);
|
||||
|
||||
while ((source = ecdb_image_project(proj)))
|
||||
{
|
||||
if (burn_track_set_source(track, source) != BURN_SOURCE_OK)
|
||||
{
|
||||
printf("Error: Cannot attach source object to track "
|
||||
"object!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
burn_session_add_track(data->session, track, BURN_POS_END);
|
||||
ecore_list_append(data->sources, source);
|
||||
ecore_list_append(data->tracks, track);
|
||||
i++;
|
||||
}
|
||||
|
||||
if (!i)
|
||||
{
|
||||
printf("Failed to add any files to burn disc!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
opts = burn_write_opts_new(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!\n");
|
||||
burn_write_opts_set_simulate(opts, proj->simulate);
|
||||
burn_drive_set_speed(proj->drive->tangible->drive, 0, proj->speed);
|
||||
burn_write_opts_set_underrun_proof(opts, proj->underrun_proof);
|
||||
|
||||
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");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Not sure where to put this for now */
|
||||
burn_disc_write(opts, data->disc);
|
||||
burn_write_opts_free(opts);
|
||||
|
||||
pthread_create(&progress_update, NULL, _progress_update, data);
|
||||
pthread_detach(progress_update);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
_progress_update(void *d)
|
||||
{
|
||||
Burn_Data *data;
|
||||
BurnProgress p;
|
||||
BurnDriveStatus stat;
|
||||
struct burn_drive *drive;
|
||||
|
||||
data = d;
|
||||
|
||||
if (!data->proj->drive->tangible)
|
||||
{
|
||||
printf("No tangible drive!\n");
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
drive = data->proj->drive->tangible[0].drive;
|
||||
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
stat = burn_drive_get_status(drive, &p);
|
||||
if (stat == BURN_DRIVE_SPAWNING)
|
||||
{
|
||||
sleep(3);
|
||||
continue;
|
||||
}
|
||||
else if (stat == BURN_DRIVE_IDLE)
|
||||
{
|
||||
BurnTrack *track;
|
||||
BurnSource *source;
|
||||
|
||||
ecore_list_first_goto(data->sources);
|
||||
ecore_list_first_goto(data->tracks);
|
||||
|
||||
while ((source = ecore_list_remove(data->sources)))
|
||||
{
|
||||
burn_source_free(source);
|
||||
track = ecore_list_remove(data->tracks);
|
||||
burn_track_free(track);
|
||||
}
|
||||
|
||||
ecore_list_destroy(data->sources);
|
||||
ecore_list_destroy(data->tracks);
|
||||
burn_session_free(data->session);
|
||||
burn_disc_free(data->disc);
|
||||
burn_drive_release(drive, 0);
|
||||
burn_drive_info_free(data->proj->drive->tangible);
|
||||
|
||||
/* Don't keep in here */
|
||||
printf("fail\n");
|
||||
ecore_list_destroy(data->proj->files);
|
||||
FREE(data->proj);
|
||||
|
||||
/* End testing */
|
||||
printf("here\n");
|
||||
FREE(data);
|
||||
|
||||
pthread_exit(NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
//printf("Total sectors: %d, on sector: %d\n", p.sectors,
|
||||
// p.sector);
|
||||
data->proj->progress = p;
|
||||
sleep(5);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user