switch_ratio may not work with some filter chains
[mplayer/greg.git] / edl.c
blob162de1e03ce05ce7413af680d062aadc1be5f6e4
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "config.h"
4 #include "mp_msg.h"
5 #include "edl.h"
6 #include "help_mp.h"
8 #ifdef USE_EDL
10 /**
11 * We can't do -edl and -edlout at the same time
12 * so we check that here.
14 * \return EDL_ERROR on error and 1 otherwise.
15 * \brief Makes sure EDL has been called correctly.
18 int edl_check_mode(void)
20 if (edl_filename && edl_output_filename)
22 return (EDL_ERROR);
25 return (1);
28 /** Calculates the total amount of edl_records we will need
29 * to hold the EDL operations queue, we need one edl_record
30 * for each SKIP and two for each MUTE.
31 * \return Number of necessary EDL entries, EDL_ERROR when file can't be read.
32 * \brief Counts needed EDL entries.
35 int edl_count_entries(void)
37 FILE *fd = NULL;
38 int entries = 0;
39 int action = 0;
40 float start = 0;
41 float stop = 0;
42 char line[100];
44 if (edl_filename)
46 if ((fd = fopen(edl_filename, "r")) == NULL)
48 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdlCantOpenForRead,
49 edl_filename);
50 return (EDL_ERROR);
51 } else
53 while (fgets(line, 99, fd) != NULL)
55 if ((sscanf(line, "%f %f %d", &start, &stop, &action)) ==
58 if (action == EDL_SKIP)
59 entries += 1;
60 if (action == EDL_MUTE)
61 entries += 2;
62 } else
64 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdlNOValidLine, line);
65 return (EDL_ERROR);
70 } else
72 return (EDL_ERROR);
75 return (entries);
78 /** Parses edl_filename to fill EDL operations queue.
79 * \return Number of stored EDL records or EDL_ERROR when file can't be read.
80 * \brief Fills EDL operations queue.
83 int edl_parse_file(edl_record_ptr edl_records)
85 FILE *fd;
86 char line[100];
87 float start, stop;
88 int action;
89 int record_count = 0;
90 int lineCount = 0;
91 struct edl_record *next_edl_record = edl_records;
93 if (edl_filename)
95 if ((fd = fopen(edl_filename, "r")) == NULL)
97 return (EDL_ERROR);
98 } else
100 while (fgets(line, 99, fd) != NULL)
102 lineCount++;
103 if ((sscanf(line, "%f %f %d", &start, &stop, &action))
104 != 3)
106 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdlBadlyFormattedLine,
107 lineCount + 1);
108 continue;
109 } else
111 if (record_count > 0)
113 if (start <= (next_edl_record - 1)->stop_sec)
115 mp_msg(MSGT_CPLAYER, MSGL_WARN,
116 MSGTR_EdlNOValidLine, line);
117 mp_msg(MSGT_CPLAYER, MSGL_WARN,
118 MSGTR_EdlBadLineOverlap,
119 (next_edl_record - 1)->stop_sec, start);
120 continue;
123 if (stop <= start)
125 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdlNOValidLine,
126 line);
127 mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdlBadLineBadStop);
128 continue;
130 next_edl_record->action = action;
131 if (action == EDL_MUTE)
133 next_edl_record->length_sec = 0;
134 next_edl_record->start_sec = start;
135 next_edl_record->stop_sec = start;
136 next_edl_record->mute_state = EDL_MUTE_START;
137 next_edl_record++;
138 (next_edl_record - 1)->next = next_edl_record;
139 next_edl_record->action = action;
140 next_edl_record->length_sec = 0;
141 next_edl_record->start_sec = stop;
142 next_edl_record->stop_sec = stop;
143 next_edl_record->mute_state = EDL_MUTE_END;
145 } else
147 next_edl_record->length_sec = stop - start;
148 next_edl_record->start_sec = start;
149 next_edl_record->stop_sec = stop;
151 next_edl_record++;
153 if (record_count >= 0)
155 (next_edl_record - 1)->next = next_edl_record;
158 record_count++;
162 if (record_count > 0)
164 (next_edl_record - 1)->next = NULL;
167 fclose(fd);
168 } else
170 return (EDL_ERROR);
173 return (record_count);
176 #endif