adding the code documentation guide lines
[mplayer/glamo.git] / edl.c
blob78360bf4f6795f7678be92c1e0186233b0ad71de
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "config.h"
4 #include "mp_msg.h"
5 #include "edl.h"
7 #ifdef USE_EDL
9 int edl_check_mode(void)
11 if (edl_filename && edl_output_filename)
13 return (EDL_ERROR);
16 return (1);
19 int edl_count_entries(void)
21 FILE *fd = NULL;
22 int entries = 0;
23 int action = 0;
24 float start = 0;
25 float stop = 0;
26 char line[100];
28 if (edl_filename)
30 if ((fd = fopen(edl_filename, "r")) == NULL)
32 mp_msg(MSGT_CPLAYER, MSGL_WARN,
33 "Invalid EDL file, cant open '%s' for reading!\n",
34 edl_filename);
35 return (EDL_ERROR);
36 } else
38 while (fgets(line, 99, fd) != NULL)
40 if ((sscanf(line, "%f %f %d", &start, &stop, &action)) ==
43 if (action == EDL_SKIP)
44 entries += 1;
45 if (action == EDL_MUTE)
46 entries += 2;
47 } else
49 mp_msg(MSGT_CPLAYER, MSGL_WARN,
50 "Invalid EDL line: %s\n", line);
51 return (EDL_ERROR);
56 } else
58 return (EDL_ERROR);
61 return (entries);
64 int edl_parse_file(edl_record_ptr edl_records)
66 FILE *fd;
67 char line[100];
68 float start, stop;
69 int action;
70 int record_count = 0;
71 int lineCount = 0;
72 struct edl_record *next_edl_record = edl_records;
74 if (edl_filename)
76 if ((fd = fopen(edl_filename, "r")) == NULL)
78 return (EDL_ERROR);
79 } else
81 while (fgets(line, 99, fd) != NULL)
83 lineCount++;
84 if ((sscanf(line, "%f %f %d", &start, &stop, &action))
85 != 3)
87 mp_msg(MSGT_CPLAYER, MSGL_WARN,
88 "Badly formated EDL line [%d]. Discarding!\n",
89 lineCount + 1, line);
90 continue;
91 } else
93 if (record_count > 0)
95 if (start <= (next_edl_record - 1)->stop_sec)
97 mp_msg(MSGT_CPLAYER, MSGL_WARN,
98 "Invalid EDL line [%d]: %s",
99 lineCount, line);
100 mp_msg(MSGT_CPLAYER, MSGL_WARN,
101 "Last stop position was [%f]; next start is [%f]. Entries must be in chronological order and cannot overlap. Discarding!\n",
102 (next_edl_record - 1)->stop_sec, start);
103 continue;
106 if (stop <= start)
108 mp_msg(MSGT_CPLAYER, MSGL_WARN,
109 "Invalid EDL line [%d]: %s", lineCount,
110 line);
111 mp_msg(MSGT_CPLAYER, MSGL_WARN,
112 "Stop time must follow start time. Discarding!\n");
113 continue;
115 next_edl_record->action = action;
116 if (action == EDL_MUTE)
118 next_edl_record->length_sec = 0;
119 next_edl_record->start_sec = start;
120 next_edl_record->stop_sec = start;
121 next_edl_record->mute_state = EDL_MUTE_START;
122 next_edl_record++;
123 (next_edl_record - 1)->next = next_edl_record;
124 next_edl_record->action = action;
125 next_edl_record->length_sec = 0;
126 next_edl_record->start_sec = stop;
127 next_edl_record->stop_sec = stop;
128 next_edl_record->mute_state = EDL_MUTE_END;
130 } else
132 next_edl_record->length_sec = stop - start;
133 next_edl_record->start_sec = start;
134 next_edl_record->stop_sec = stop;
136 next_edl_record++;
138 if (record_count >= 0)
140 (next_edl_record - 1)->next = next_edl_record;
143 record_count++;
147 if (record_count > 0)
149 (next_edl_record - 1)->next = NULL;
152 fclose(fd);
153 } else
155 return (EDL_ERROR);
158 return (record_count);
161 #endif