Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / commercials.h
1 #if defined(__i386__) || defined(__x86_64__)
2 #if defined (__linux__)
3 #ifndef _COMMERCIALS_H_
4 #define _COMMERCIALS_H_
5
6 #include "arraylist.h"
7 #include "asset.inc"
8 #include "bcprogress.h"
9 #include "bcwindow.h"
10 #include "commercials.inc"
11 #include "condition.inc"
12 #include "edit.inc"
13 #include "edits.inc"
14 #include "file.inc"
15 #include "garbage.h"
16 #include "linklist.h"
17 #include "mediadb.h"
18 #include "mwindow.inc"
19 #include "thread.h"
20 #include "track.inc"
21 #include "vframe.inc"
22 #include "filexml.inc"
23
24
25 class Commercials : public Garbage
26 {
27         MediaDb *mdb;
28         int armed;
29         int clip_id;
30         double *clip_weights;
31         int64_t frame_start, frame_total;
32         double frame_period;
33         ArrayList<double> weights;
34         ArrayList<double> offsets;
35         ArrayList<Clips*> tracks;
36         File *scan_file;
37
38         ScanStatus *scan_status;
39         int update_cut_info(int trk, double position);
40         int update_caption(int trk, int edt, const char *path);
41         int update_status(int clip, double start, double end);
42
43         int new_clip(const char *title, int frames, double framerate);
44         Clips *find_clips(int pid);
45         int put_weight(VFrame *frame, int no);
46         int put_frame(VFrame *frame, int no, int group, double offset);
47         int skim_weights(int track, double position, double iframerate, int iframes);
48         double abs_err(Snip *snip, double *ap, int j, int len, double iframerate);
49         double abs_err(double *ap, int len, double iframerate);
50         int skim_weight(int track);
51         static int skim_weight(void *vp, int track);
52 public:
53         MWindow *mwindow;
54         int cancelled, muted;
55
56         int newDb();
57         void closeDb();
58         int openDb();
59         int resetDb();
60         void commitDb();
61         void undoDb();
62         int transaction() { return mdb->transaction(); }
63         int attachDb(int rw=0);
64         int detachDb();
65
66         int put_clip(File *file, int track, double position, double length);
67         int get_frame(File *file, int pid, double position,
68                 uint8_t *tp, int mw, int mh, int ww, int hh);
69         static double frame_weight(uint8_t *tdat, int rowsz, int width, int height);
70         int skim_frame(Snips *snips, uint8_t *dat, double position);
71         int verify_snip(Snip *snip, double weight, double position);
72         int mute_audio(Clip *clip);
73         int unmute_audio();
74         int test_clip(int clip_id, int track, double position, double &pos);
75         int verify_clip(int clip_id, int track, double position, double &pos);
76         int write_ads(const char *filename);
77         int read_ads(const char *filename);
78         void dump_ads();
79         int verify_edit(Track *track, Edit *edit, double start, double end);
80         Edit * cut_edit(Track *track, Edit *edit, int64_t clip_start, int64_t clip_end);
81         int scan_audio(int vstream, double start, double end);
82         int scan_media();
83         int scan_video();
84         int scan_asset(Asset *asset, Track *vtrack, Edit *edit);
85         int scan_clips(Track *vtrack, Edit *edit);
86         int get_image(int id, uint8_t *dat, int &w, int &h);
87         int get_clip_seq_no(int clip_id, int &seq_no, double &offset, int &frame_id);
88         MediaDb *media_db() { return mdb; }
89
90         Commercials(MWindow *mwindow);
91         ~Commercials();
92 };
93
94 class ScanStatusBar : public BC_ProgressBar
95 {
96         int tick, limit;
97 public:
98         int update(int64_t position) {
99                 if( --tick >= 0 ) return 0;
100                 tick = limit;
101                 return BC_ProgressBar::update(position);
102         }
103         int update_length(int64_t length) {
104                 tick = limit = length / 100;
105                 return BC_ProgressBar::update_length(length);
106         }
107         ScanStatusBar(int x, int y, int w, int64_t length, int do_text = 1) :
108                 BC_ProgressBar(x, y, w, length, do_text) {
109                 tick = limit = length / 100;
110         }
111         ~ScanStatusBar() {}
112 };
113
114 class ScanStatusGUI : public BC_Window
115 {
116         ScanStatus *sswindow;
117         int nbars, nlines;
118         BC_Title **texts;
119         ScanStatusBar **bars;
120         friend class ScanStatus;
121 public:
122         ScanStatusGUI(ScanStatus *sswindow, int x, int y, int nlines, int nbars);
123         ~ScanStatusGUI();
124
125         void create_objects(const char *text);
126 };
127
128 class ScanStatus : public Thread
129 {
130         int &status;
131         void stop();
132         void run();
133 public:
134         Commercials *commercials;
135         ScanStatusGUI *gui;
136
137         ScanStatus(Commercials *commercials, int x, int y,
138                 int nlines, int nbars, int &status, const char *text);
139         ~ScanStatus();
140
141         int update_length(int i, int64_t length);
142         int update_position(int i, int64_t position);
143         int update_text(int i, const char *text);
144 };
145
146
147 class SdbPacket : public ListItem<SdbPacket>
148 {
149 public:
150         enum sdb_packet_type { sdb_none, sdb_skim_frame, } type;
151         SkimDbThread *thread;
152         void start();
153         virtual void run() = 0;
154
155         SdbPacket(sdb_packet_type ty, SkimDbThread *tp) : type(ty), thread(tp) {}
156         ~SdbPacket() {}
157 };
158
159 class SdbPacketQueue : public List<SdbPacket>, public Mutex
160 {
161 public:
162         SdbPacket *get_packet();
163         void put_packet(SdbPacket *p);
164 };
165
166 class SdbSkimFrame : public SdbPacket
167 {
168 public:
169         int pid;
170         int64_t framenum;
171         double framerate;
172         uint8_t dat[SFRM_SZ];
173
174         void load(int pid,int64_t framenum,double framerate,
175                 uint8_t *idata,int mw,int mh,int iw,int ih);
176         void run();
177
178         SdbSkimFrame(SkimDbThread *t) : SdbPacket(sdb_skim_frame, t) {}
179         ~SdbSkimFrame() {}
180 };
181
182
183 class SkimDbThread : public Thread
184 {
185         SdbPacketQueue active_packets;
186         Condition *input_lock;
187         friend class SdbSkimFrame;
188 public:
189         int done;
190         SdbPacketQueue skim_frames;
191         Commercials *commercials;
192         Snips *snips;
193
194         void start(Commercials *commercials);
195         void stop();
196         void run();
197         void put_packet(SdbPacket *p);
198         int skim(int pid,int64_t framenum,double framerate,
199                 uint8_t *idata,int mw,int mh,int iw,int ih);
200
201         SkimDbThread();
202         ~SkimDbThread();
203 };
204
205
206 #endif
207 #endif // linux
208 #endif /* x86 */