~ubuntu-dev/mplayer/ubuntu-feisty

« back to all changes in this revision

Viewing changes to edl.c

  • Committer: Reinhard Tartler
  • Date: 2006-07-08 08:45:33 UTC
  • Revision ID: siretart@tauware.de-20060708084533-dbc155bde7122e78
imported mplayer_0.99+1.0pre7try2+cvs20060117

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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"
 
7
 
 
8
char *edl_filename; // file to extract EDL entries from (-edl)
 
9
char *edl_output_filename; // file to put EDL entries in (-edlout)
 
10
 
 
11
#ifdef USE_EDL
 
12
 
 
13
/**
 
14
 *  Allocates a new EDL record and makes sure allocation was successful.
 
15
 *
 
16
 *  \return New allocated EDL record.
 
17
 *  \brief Allocate new EDL record
 
18
 */
 
19
 
 
20
static edl_record_ptr edl_alloc_new(edl_record_ptr next_edl_record)
 
21
{
 
22
    edl_record_ptr new_record = calloc(1, sizeof(struct edl_record));
 
23
    if (!new_record) {
 
24
        mp_msg(MSGT_CPLAYER, MSGL_FATAL, MSGTR_EdlOutOfMem);
 
25
        exit(1);
 
26
    }
 
27
    
 
28
    if (next_edl_record) // if this isn't the first record, tell the previous one what the new one is.
 
29
        next_edl_record->next = new_record;
 
30
    new_record->prev = next_edl_record;
 
31
    
 
32
    return new_record;
 
33
}
 
34
 
 
35
/**
 
36
 *  Goes through entire EDL records and frees all memory.
 
37
 *  Assumes next_edl_record is valid or NULL.
 
38
 *
 
39
 *  \brief Free EDL memory
 
40
 */
 
41
 
 
42
void free_edl(edl_record_ptr next_edl_record)
 
43
{
 
44
    edl_record_ptr tmp;
 
45
    while (next_edl_record) {
 
46
        tmp = next_edl_record->next;
 
47
        free(next_edl_record);
 
48
        next_edl_record = tmp;
 
49
    }
 
50
}
 
51
 
 
52
/** Parses edl_filename to fill EDL operations queue.
 
53
 * Prints out how many EDL operations recorded total.
 
54
 *  \brief Fills EDL operations queue.
 
55
 */
 
56
 
 
57
edl_record_ptr edl_parse_file()
 
58
{
 
59
    FILE *fd;
 
60
    char line[100];
 
61
    float start, stop;
 
62
    int action;
 
63
    int record_count = 0;
 
64
    int lineCount = 0;
 
65
    edl_record_ptr edl_records = edl_alloc_new(NULL);
 
66
    edl_record_ptr next_edl_record = edl_records;
 
67
 
 
68
    if (edl_filename)
 
69
    {
 
70
        if ((fd = fopen(edl_filename, "r")) == NULL)
 
71
        {
 
72
            return NULL;
 
73
        } else
 
74
        {
 
75
            while (fgets(line, 99, fd) != NULL)
 
76
            {
 
77
                lineCount++;
 
78
                if ((sscanf(line, "%f %f %d", &start, &stop, &action))
 
79
                    != 3)
 
80
                {
 
81
                    mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdlBadlyFormattedLine,
 
82
                           lineCount + 1);
 
83
                    continue;
 
84
                } else
 
85
                {
 
86
                    if (next_edl_record->prev && start <= next_edl_record->prev->stop_sec)
 
87
                    {
 
88
                        mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdlNOValidLine, line);
 
89
                        mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdlBadLineOverlap,
 
90
                               next_edl_record->prev->stop_sec, start);
 
91
                        continue;    
 
92
                    }
 
93
                    if (stop <= start)
 
94
                    {
 
95
                        mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdlNOValidLine,
 
96
                               line);
 
97
                        mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_EdlBadLineBadStop);
 
98
                        continue;
 
99
                    }
 
100
                    next_edl_record->action = action;
 
101
                    if (action == EDL_MUTE)
 
102
                    {
 
103
                        next_edl_record->length_sec = 0;
 
104
                        next_edl_record->start_sec = start;
 
105
                        next_edl_record->stop_sec = start;
 
106
                        
 
107
                        next_edl_record = edl_alloc_new(next_edl_record);
 
108
                        
 
109
                        next_edl_record->action = action;
 
110
                        next_edl_record->length_sec = 0;
 
111
                        next_edl_record->start_sec = stop;
 
112
                        next_edl_record->stop_sec = stop;
 
113
                    } else
 
114
                    {
 
115
                        next_edl_record->length_sec = stop - start;
 
116
                        next_edl_record->start_sec = start;
 
117
                        next_edl_record->stop_sec = stop;
 
118
                    }
 
119
                    next_edl_record = edl_alloc_new(next_edl_record);
 
120
                    record_count++;
 
121
                }
 
122
            }
 
123
        }
 
124
        fclose(fd);
 
125
    }        
 
126
    if (next_edl_record->prev) {
 
127
        next_edl_record->prev->next = NULL; // a record was before me, i don't want them thinking i'm a real record.
 
128
        mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdlRecordsNo, record_count);
 
129
    }
 
130
    else {
 
131
        mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_EdlQueueEmpty);
 
132
        edl_records = NULL; // there was no previous record, we only had one record, the empty one.
 
133
    }
 
134
    free(next_edl_record);
 
135
    return edl_records;
 
136
}
 
137
 
 
138
#endif