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