no longer need ffmpeg patch0 which was for Termux
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / commercials.h
1 /*
2  * CINELERRA
3  * Copyright (C) 2016-2020 William Morrow
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published
7  * by the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA
19  */
20
21 #if defined(__i386__) || defined(__x86_64__)
22 #if defined (__linux__)
23 #ifndef _COMMERCIALS_H_
24 #define _COMMERCIALS_H_
25
26 #include "arraylist.h"
27 #include "asset.inc"
28 #include "bcprogress.h"
29 #include "bcwindow.h"
30 #include "commercials.inc"
31 #include "condition.inc"
32 #include "edit.inc"
33 #include "edits.inc"
34 #include "file.inc"
35 #include "garbage.h"
36 #include "linklist.h"
37 #include "mediadb.h"
38 #include "mwindow.inc"
39 #include "thread.h"
40 #include "track.inc"
41 #include "vframe.inc"
42 #include "filexml.inc"
43
44
45 class Commercials : public Garbage
46 {
47         MediaDb *mdb;
48         int armed;
49         int clip_id;
50         double *clip_weights;
51         int64_t frame_start, frame_total;
52         double frame_period;
53         ArrayList<double> weights;
54         ArrayList<double> offsets;
55         ArrayList<Clips*> tracks;
56         File *scan_file;
57
58         ScanStatus *scan_status;
59         int update_cut_info(int trk, double position);
60         int update_caption(int trk, int edt, const char *path);
61         int update_status(int clip, double start, double end);
62
63         int new_clip(const char *title, int frames, double framerate);
64         Clips *find_clips(int pid);
65         int put_weight(VFrame *frame, int no);
66         int put_frame(VFrame *frame, int no, int group, double offset);
67         int skim_weights(int track, double position, double iframerate, int iframes);
68         double abs_err(Snip *snip, double *ap, int j, int len, double iframerate);
69         double abs_err(double *ap, int len, double iframerate);
70         int skim_weight(int track);
71         static int skim_weight(void *vp, int track);
72 public:
73         MWindow *mwindow;
74         int cancelled, muted;
75
76         int newDb();
77         void closeDb();
78         int openDb();
79         int resetDb();
80         void commitDb();
81         void undoDb();
82         int transaction() { return mdb->transaction(); }
83         int attachDb(int rw=0);
84         int detachDb();
85
86         int put_clip(File *file, int track, double position, double length);
87         int get_frame(File *file, int pid, double position,
88                 uint8_t *tp, int mw, int mh, int ww, int hh);
89         static double frame_weight(uint8_t *tdat, int rowsz, int width, int height);
90         int skim_frame(Snips *snips, uint8_t *dat, double position);
91         int verify_snip(Snip *snip, double weight, double position);
92         int mute_audio(Clip *clip);
93         int unmute_audio();
94         int test_clip(int clip_id, int track, double position, double &pos);
95         int verify_clip(int clip_id, int track, double position, double &pos);
96         int write_ads(const char *filename);
97         int read_ads(const char *filename);
98         void dump_ads();
99         int verify_edit(Track *track, Edit *edit, double start, double end);
100         Edit * cut_edit(Track *track, Edit *edit, int64_t clip_start, int64_t clip_end);
101         int scan_audio(int vstream, double start, double end);
102         int scan_media();
103         int scan_video();
104         int scan_asset(Asset *asset, Track *vtrack, Edit *edit);
105         int scan_clips(Track *vtrack, Edit *edit);
106         int get_image(int id, uint8_t *dat, int &w, int &h);
107         int get_clip_seq_no(int clip_id, int &seq_no, double &offset, int &frame_id);
108         MediaDb *media_db() { return mdb; }
109
110         Commercials(MWindow *mwindow);
111         ~Commercials();
112 };
113
114 class ScanStatusBar : public BC_ProgressBar
115 {
116         int tick, limit;
117 public:
118         int update(int64_t position) {
119                 if( --tick >= 0 ) return 0;
120                 tick = limit;
121                 return BC_ProgressBar::update(position);
122         }
123         int update_length(int64_t length) {
124                 tick = limit = length / 100;
125                 return BC_ProgressBar::update_length(length);
126         }
127         ScanStatusBar(int x, int y, int w, int64_t length, int do_text = 1) :
128                 BC_ProgressBar(x, y, w, length, do_text) {
129                 tick = limit = length / 100;
130         }
131         ~ScanStatusBar() {}
132 };
133
134 class ScanStatusGUI : public BC_Window
135 {
136         ScanStatus *sswindow;
137         int nbars, nlines;
138         BC_Title **texts;
139         ScanStatusBar **bars;
140         friend class ScanStatus;
141 public:
142         ScanStatusGUI(ScanStatus *sswindow, int x, int y, int nlines, int nbars);
143         ~ScanStatusGUI();
144
145         void create_objects(const char *text);
146 };
147
148 class ScanStatus : public Thread
149 {
150         int &status;
151         void stop();
152         void run();
153 public:
154         Commercials *commercials;
155         ScanStatusGUI *gui;
156
157         ScanStatus(Commercials *commercials, int x, int y,
158                 int nlines, int nbars, int &status, const char *text);
159         ~ScanStatus();
160
161         int update_length(int i, int64_t length);
162         int update_position(int i, int64_t position);
163         int update_text(int i, const char *text);
164 };
165
166
167 class SdbPacket : public ListItem<SdbPacket>
168 {
169 public:
170         enum sdb_packet_type { sdb_none, sdb_skim_frame, } type;
171         SkimDbThread *thread;
172         void start();
173         virtual void run() = 0;
174
175         SdbPacket(sdb_packet_type ty, SkimDbThread *tp) : type(ty), thread(tp) {}
176         ~SdbPacket() {}
177 };
178
179 class SdbPacketQueue : public List<SdbPacket>, public Mutex
180 {
181 public:
182         SdbPacket *get_packet();
183         void put_packet(SdbPacket *p);
184 };
185
186 class SdbSkimFrame : public SdbPacket
187 {
188 public:
189         int pid;
190         int64_t framenum;
191         double framerate;
192         uint8_t dat[SFRM_SZ];
193
194         void load(int pid,int64_t framenum,double framerate,
195                 uint8_t *idata,int mw,int mh,int iw,int ih);
196         void run();
197
198         SdbSkimFrame(SkimDbThread *t) : SdbPacket(sdb_skim_frame, t) {}
199         ~SdbSkimFrame() {}
200 };
201
202
203 class SkimDbThread : public Thread
204 {
205         SdbPacketQueue active_packets;
206         Condition *input_lock;
207         friend class SdbSkimFrame;
208 public:
209         int done;
210         SdbPacketQueue skim_frames;
211         Commercials *commercials;
212         Snips *snips;
213
214         void start(Commercials *commercials);
215         void stop();
216         void run();
217         void put_packet(SdbPacket *p);
218         int skim(int pid,int64_t framenum,double framerate,
219                 uint8_t *idata,int mw,int mh,int iw,int ih);
220
221         SkimDbThread();
222         ~SkimDbThread();
223 };
224
225
226 #endif
227 #endif // linux
228 #endif /* x86 */