summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreynaldo <reynaldo@b3059339-0415-0410-9bf9-f77b7e298cf2>2005-02-25 04:30:53 +0000
committerreynaldo <reynaldo@b3059339-0415-0410-9bf9-f77b7e298cf2>2005-02-25 04:30:53 +0000
commitc49c161ace7cc5a6bbd754ddd16002668ccc36f7 (patch)
tree2792af77619911d12f4e818760c70285e862e141
parent21c0a01f3aefd4785a9d43ed87e850e08897812c (diff)
downloadmpv-c49c161ace7cc5a6bbd754ddd16002668ccc36f7.tar.bz2
mpv-c49c161ace7cc5a6bbd754ddd16002668ccc36f7.tar.xz
Some to-be-redundant EDL code moved to edl.c with mencoder's edl in mind. Stack handling improvements, Patch by Oded Shimon
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@14808 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r--edl.c133
-rw-r--r--edl.h9
-rw-r--r--mplayer.c30
3 files changed, 61 insertions, 111 deletions
diff --git a/edl.c b/edl.c
index 86c1b00f82..0433b68bc1 100644
--- a/edl.c
+++ b/edl.c
@@ -28,62 +28,51 @@ int edl_check_mode(void)
return (1);
}
-/** Calculates the total amount of edl_records we will need
- * to hold the EDL operations queue, we need one edl_record
- * for each SKIP and two for each MUTE.
- * \return Number of necessary EDL entries, EDL_ERROR when file can't be read.
- * \brief Counts needed EDL entries.
+/**
+ * Allocates a new EDL record and makes sure allocation was successful.
+ *
+ * \return New allocated EDL record.
+ * \brief Allocate new EDL record
*/
-int edl_count_entries(void)
+static edl_record_ptr edl_alloc_new(edl_record_ptr next_edl_record)
{
- FILE *fd = NULL;
- int entries = 0;
- int action = 0;
- float start = 0;
- float stop = 0;
- char line[100];
+ 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;
+
+ return new_record;
+}
- if (edl_filename)
- {
- if ((fd = fopen(edl_filename, "r")) == NULL)
- {
- mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdlCantOpenForRead,
- edl_filename);
- return (EDL_ERROR);
- } else
- {
- while (fgets(line, 99, fd) != NULL)
- {
- if ((sscanf(line, "%f %f %d", &start, &stop, &action)) ==
- 3)
- {
- if (action == EDL_SKIP)
- entries += 1;
- if (action == EDL_MUTE)
- entries += 2;
- } else
- {
- mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdlNOValidLine, line);
- return (EDL_ERROR);
- }
+/**
+ * Goes through entire EDL records and frees all memory.
+ * Assumes next_edl_record is valid or NULL.
+ *
+ * \brief Free EDL memory
+ */
- }
- }
- } else
- {
- return (EDL_ERROR);
+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;
}
-
- return (entries);
}
/** Parses edl_filename to fill EDL operations queue.
- * \return Number of stored EDL records or EDL_ERROR when file can't be read.
+ * Prints out how many EDL operations recorded total.
* \brief Fills EDL operations queue.
*/
-int edl_parse_file(edl_record_ptr edl_records)
+edl_record_ptr edl_parse_file()
{
FILE *fd;
char line[100];
@@ -91,13 +80,14 @@ int edl_parse_file(edl_record_ptr edl_records)
int action;
int record_count = 0;
int lineCount = 0;
- struct edl_record *next_edl_record = edl_records;
+ edl_record_ptr edl_records = edl_alloc_new(NULL);
+ edl_record_ptr next_edl_record = edl_records;
if (edl_filename)
{
if ((fd = fopen(edl_filename, "r")) == NULL)
{
- return (EDL_ERROR);
+ return NULL;
} else
{
while (fgets(line, 99, fd) != NULL)
@@ -111,17 +101,12 @@ int edl_parse_file(edl_record_ptr edl_records)
continue;
} else
{
- if (record_count > 0)
+ if (next_edl_record->prev && start <= next_edl_record->prev->stop_sec)
{
- if (start <= (next_edl_record - 1)->stop_sec)
- {
- mp_msg(MSGT_CPLAYER, MSGL_WARN,
- MSGTR_EdlNOValidLine, line);
- mp_msg(MSGT_CPLAYER, MSGL_WARN,
- MSGTR_EdlBadLineOverlap,
- (next_edl_record - 1)->stop_sec, start);
- continue;
- }
+ mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdlNOValidLine, line);
+ mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdlBadLineOverlap,
+ next_edl_record->prev->stop_sec, start);
+ continue;
}
if (stop <= start)
{
@@ -136,44 +121,36 @@ int edl_parse_file(edl_record_ptr edl_records)
next_edl_record->length_sec = 0;
next_edl_record->start_sec = start;
next_edl_record->stop_sec = start;
- next_edl_record->mute_state = EDL_MUTE_START;
- next_edl_record++;
- (next_edl_record - 1)->next = next_edl_record;
+
+ 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;
- next_edl_record->mute_state = EDL_MUTE_END;
-
} else
{
next_edl_record->length_sec = stop - start;
next_edl_record->start_sec = start;
next_edl_record->stop_sec = stop;
}
- next_edl_record++;
-
- if (record_count >= 0)
- {
- (next_edl_record - 1)->next = next_edl_record;
- }
-
+ next_edl_record = edl_alloc_new(next_edl_record);
record_count++;
}
}
-
- if (record_count > 0)
- {
- (next_edl_record - 1)->next = NULL;
- }
}
fclose(fd);
- } else
- {
- return (EDL_ERROR);
+ }
+ if (next_edl_record->prev) {
+ next_edl_record->prev->next = NULL; // a record was before me, i don't want them thinking i'm a real record.
+ mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdlRecordsNo, record_count);
}
-
- return (record_count);
+ else {
+ mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdlQueueEmpty);
+ edl_records = NULL; // there was no previous record, we only had one record, the empty one.
+ }
+ free(next_edl_record);
+ return edl_records;
}
#endif
diff --git a/edl.h b/edl.h
index 508c8b18be..3593227e94 100644
--- a/edl.h
+++ b/edl.h
@@ -11,14 +11,11 @@
struct edl_record {
float start_sec;
- long start_frame;
float stop_sec;
- long stop_frame;
float length_sec;
- long length_frame;
short action;
- short mute_state;
struct edl_record* next;
+ struct edl_record* prev;
};
typedef struct edl_record* edl_record_ptr;
@@ -27,7 +24,7 @@ extern char *edl_filename; // file to extract EDL entries from (-edl)
extern char *edl_output_filename; // file to put EDL entries in (-edlout)
int edl_check_mode(void); // we cannot do -edl and -edlout at the same time
-int edl_count_entries(void); // returns total number of entries needed
-int edl_parse_file(edl_record_ptr edl_records); // fills EDL stack
+void free_edl(edl_record_ptr next_edl_record); // free's entire EDL list.
+edl_record_ptr edl_parse_file(); // fills EDL stack
#endif
diff --git a/mplayer.c b/mplayer.c
index 53753fc298..73d350e4e6 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -363,8 +363,6 @@ static char* rtc_device;
#ifdef USE_EDL
edl_record_ptr edl_records = NULL; ///< EDL entries memory area
edl_record_ptr next_edl_record = NULL; ///< only for traversing edl_records
-int edl_memory_slots = 0; ///< number of EDL entries (1 for skip + 2 for each mute)
-int edl_operations = 0; ///< number of EDL operations, skip + mute
short user_muted = 0; ///< Stores whether User wanted muted mode.
short edl_muted = 0; ///< Stores whether EDL is currently in muted mode.
short edl_decision = 0; ///< 1 when an EDL operation has been made
@@ -1249,30 +1247,8 @@ if (edl_check_mode() == EDL_ERROR && edl_filename)
exit_player(NULL);
} else if (edl_filename)
{
- edl_memory_slots = edl_count_entries();
- if (edl_memory_slots > 0)
- {
- edl_records = calloc(edl_memory_slots, sizeof(struct edl_record));
- if (edl_records == NULL)
- {
- mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_EdlOutOfMem);
- exit_player(NULL);
- } else
- {
- if ((edl_operations = edl_parse_file(edl_records)) > 0)
- {
- mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdlRecordsNo,
- edl_operations);
- } else
- {
-
- mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdlQueueEmpty);
- }
- }
- }
-
- next_edl_record = edl_records;
-
+ if (edl_records) free_edl(edl_records);
+ next_edl_record = edl_records = edl_parse_file();
} else if (edl_output_filename)
{
if ((edl_fd = fopen(edl_output_filename, "w")) == NULL)
@@ -2718,7 +2694,7 @@ if (stream->type==STREAMTYPE_DVDNAV && dvd_nav_still)
if( next_edl_record ) { // Are we (still?) doing EDL?
if ( !sh_video ) {
mp_msg( MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlNOsh_video );
- free(edl_records);
+ free_edl(edl_records);
next_edl_record = NULL;
edl_records = NULL;
} else {