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