2004-08-28 02:46:05 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "config.h"
|
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "edl.h"
|
2004-09-17 04:28:44 +02:00
|
|
|
#include "help_mp.h"
|
2004-08-28 02:46:05 +02:00
|
|
|
|
2005-01-29 13:24:43 +01:00
|
|
|
char *edl_filename; // file to extract EDL entries from (-edl)
|
|
|
|
char *edl_output_filename; // file to put EDL entries in (-edlout)
|
|
|
|
|
2005-02-25 05:30:53 +01:00
|
|
|
/**
|
|
|
|
* Allocates a new EDL record and makes sure allocation was successful.
|
|
|
|
*
|
|
|
|
* \return New allocated EDL record.
|
|
|
|
* \brief Allocate new EDL record
|
2004-09-17 04:28:44 +02:00
|
|
|
*/
|
|
|
|
|
2005-02-25 05:30:53 +01:00
|
|
|
static edl_record_ptr edl_alloc_new(edl_record_ptr next_edl_record)
|
2004-08-28 02:46:05 +02:00
|
|
|
{
|
2005-02-25 05:30:53 +01:00
|
|
|
edl_record_ptr new_record = calloc(1, sizeof(struct edl_record));
|
|
|
|
if (!new_record) {
|
|
|
|
mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_EdlOutOfMem);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (next_edl_record) // if this isn't the first record, tell the previous one what the new one is.
|
|
|
|
next_edl_record->next = new_record;
|
|
|
|
new_record->prev = next_edl_record;
|
2006-03-10 22:34:54 +01:00
|
|
|
new_record->next = NULL;
|
2005-02-25 05:30:53 +01:00
|
|
|
|
|
|
|
return new_record;
|
|
|
|
}
|
2004-08-28 02:46:05 +02:00
|
|
|
|
2005-02-25 05:30:53 +01:00
|
|
|
/**
|
|
|
|
* Goes through entire EDL records and frees all memory.
|
|
|
|
* Assumes next_edl_record is valid or NULL.
|
|
|
|
*
|
|
|
|
* \brief Free EDL memory
|
|
|
|
*/
|
2004-08-28 02:46:05 +02:00
|
|
|
|
2005-02-25 05:30:53 +01:00
|
|
|
void free_edl(edl_record_ptr next_edl_record)
|
|
|
|
{
|
|
|
|
edl_record_ptr tmp;
|
|
|
|
while (next_edl_record) {
|
|
|
|
tmp = next_edl_record->next;
|
|
|
|
free(next_edl_record);
|
|
|
|
next_edl_record = tmp;
|
2004-08-28 02:46:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-17 04:28:44 +02:00
|
|
|
/** Parses edl_filename to fill EDL operations queue.
|
2005-02-25 05:30:53 +01:00
|
|
|
* Prints out how many EDL operations recorded total.
|
2004-09-17 04:28:44 +02:00
|
|
|
* \brief Fills EDL operations queue.
|
|
|
|
*/
|
|
|
|
|
2006-02-09 15:08:03 +01:00
|
|
|
edl_record_ptr edl_parse_file(void)
|
2004-08-28 02:46:05 +02:00
|
|
|
{
|
|
|
|
FILE *fd;
|
|
|
|
char line[100];
|
|
|
|
float start, stop;
|
|
|
|
int action;
|
|
|
|
int record_count = 0;
|
|
|
|
int lineCount = 0;
|
2006-03-10 22:34:54 +01:00
|
|
|
edl_record_ptr edl_records = NULL;
|
|
|
|
edl_record_ptr next_edl_record = NULL;
|
2004-08-28 02:46:05 +02:00
|
|
|
|
|
|
|
if (edl_filename)
|
|
|
|
{
|
|
|
|
if ((fd = fopen(edl_filename, "r")) == NULL)
|
|
|
|
{
|
2005-02-25 05:30:53 +01:00
|
|
|
return NULL;
|
2006-07-05 08:54:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
while (fgets(line, 99, fd) != NULL)
|
2004-08-28 02:46:05 +02:00
|
|
|
{
|
2006-07-05 08:54:58 +02:00
|
|
|
lineCount++;
|
|
|
|
|
|
|
|
if ((sscanf(line, "%f %f %d", &start, &stop, &action))
|
|
|
|
!= 3)
|
2004-08-28 02:46:05 +02:00
|
|
|
{
|
2006-07-05 08:54:58 +02:00
|
|
|
mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdlBadlyFormattedLine,
|
|
|
|
lineCount);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (next_edl_record && start <= next_edl_record->stop_sec)
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdlNOValidLine, line);
|
|
|
|
mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdlBadLineOverlap,
|
|
|
|
next_edl_record->stop_sec, start);
|
|
|
|
continue;
|
2004-08-28 02:46:05 +02:00
|
|
|
}
|
2006-07-05 08:54:58 +02:00
|
|
|
|
|
|
|
if (stop <= start)
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdlNOValidLine,
|
|
|
|
line);
|
|
|
|
mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdlBadLineBadStop);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
next_edl_record = edl_alloc_new(next_edl_record);
|
|
|
|
|
|
|
|
if (!edl_records) edl_records = next_edl_record;
|
|
|
|
|
|
|
|
next_edl_record->action = action;
|
|
|
|
|
|
|
|
if (action == EDL_MUTE)
|
|
|
|
{
|
|
|
|
next_edl_record->length_sec = 0;
|
|
|
|
next_edl_record->start_sec = start;
|
|
|
|
next_edl_record->stop_sec = start;
|
|
|
|
|
|
|
|
next_edl_record = edl_alloc_new(next_edl_record);
|
|
|
|
|
|
|
|
next_edl_record->action = action;
|
|
|
|
next_edl_record->length_sec = 0;
|
|
|
|
next_edl_record->start_sec = stop;
|
|
|
|
next_edl_record->stop_sec = stop;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
next_edl_record->length_sec = stop - start;
|
|
|
|
next_edl_record->start_sec = start;
|
|
|
|
next_edl_record->stop_sec = stop;
|
|
|
|
}
|
|
|
|
|
|
|
|
record_count++;
|
2004-08-28 02:46:05 +02:00
|
|
|
}
|
2006-07-05 08:54:58 +02:00
|
|
|
|
2004-08-28 02:46:05 +02:00
|
|
|
fclose(fd);
|
2005-02-25 05:30:53 +01:00
|
|
|
}
|
2006-07-05 08:54:58 +02:00
|
|
|
|
|
|
|
if (edl_records)
|
|
|
|
mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdlRecordsNo, record_count);
|
|
|
|
else
|
|
|
|
mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdlQueueEmpty);
|
2006-03-10 22:34:54 +01:00
|
|
|
|
2005-02-25 05:30:53 +01:00
|
|
|
return edl_records;
|
2004-08-28 02:46:05 +02:00
|
|
|
}
|