comparison edl.c @ 13168:ce046ef860da

EDL enhancement/fixes: *Some edl's code moved from mplayer.c to edl.c (mencoder will use the same functions) * slighty faster * removed MAX_EDL_ENTRIES limit (just reserve the memory we really need) * really treat edl_records as a linked list (coz it is) * edl now 'remembers' pending operations after a manual _seek_ * better way of handling Mute/Umute eliminates some nasty bugs when manual seeking (scrwed up mute/unmute order, no audio after seek, etc) * seeking while on -edl mode now _WORKS_ Patch by Reynaldo H. Verdejo Pinochet (reynaldo at opendot dot cl)
author rtognimp
date Sat, 28 Aug 2004 00:46:05 +0000
parents
children 567875b88aab
comparison
equal deleted inserted replaced
13167:a6f958139ab8 13168:ce046ef860da
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "config.h"
4 #include "mp_msg.h"
5 #include "edl.h"
6
7 #ifdef USE_EDL
8
9 int edl_check_mode(void)
10 {
11 if (edl_filename && edl_output_filename)
12 {
13 return (EDL_ERROR);
14 }
15
16 return (1);
17 }
18
19 int edl_count_entries(void)
20 {
21 FILE *fd = NULL;
22 int entries = 0;
23 int action = 0;
24 float start = 0;
25 float stop = 0;
26 char line[100];
27
28 if (edl_filename)
29 {
30 if ((fd = fopen(edl_filename, "r")) == NULL)
31 {
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
37 {
38 while (fgets(line, 99, fd) != NULL)
39 {
40 if ((sscanf(line, "%f %f %d", &start, &stop, &action)) ==
41 3)
42 {
43 if (action == EDL_SKIP)
44 entries += 1;
45 if (action == EDL_MUTE)
46 entries += 2;
47 } else
48 {
49 mp_msg(MSGT_CPLAYER, MSGL_WARN,
50 "Invalid EDL line: %s\n", line);
51 return (EDL_ERROR);
52 }
53
54 }
55 }
56 } else
57 {
58 return (EDL_ERROR);
59 }
60
61 return (entries);
62 }
63
64 int edl_parse_file(edl_record_ptr edl_records)
65 {
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;
73
74 if (edl_filename)
75 {
76 if ((fd = fopen(edl_filename, "r")) == NULL)
77 {
78 return (EDL_ERROR);
79 } else
80 {
81 while (fgets(line, 99, fd) != NULL)
82 {
83 lineCount++;
84 if ((sscanf(line, "%f %f %d", &start, &stop, &action))
85 != 3)
86 {
87 mp_msg(MSGT_CPLAYER, MSGL_WARN,
88 "Badly formated EDL line [%d]. Discarding!\n",
89 lineCount + 1, line);
90 continue;
91 } else
92 {
93 if (record_count > 0)
94 {
95 if (start <= (next_edl_record - 1)->stop_sec)
96 {
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;
104 }
105 }
106 if (stop <= start)
107 {
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;
114 }
115 next_edl_record->action = action;
116 if (action == EDL_MUTE)
117 {
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;
129
130 } else
131 {
132 next_edl_record->length_sec = stop - start;
133 next_edl_record->start_sec = start;
134 next_edl_record->stop_sec = stop;
135 }
136 next_edl_record++;
137
138 if (record_count >= 0)
139 {
140 (next_edl_record - 1)->next = next_edl_record;
141 }
142
143 record_count++;
144 }
145 }
146
147 if (record_count > 0)
148 {
149 (next_edl_record - 1)->next = NULL;
150 }
151 }
152 fclose(fd);
153 } else
154 {
155 return (EDL_ERROR);
156 }
157
158 return (record_count);
159 }
160
161 #endif