3 * Copyright (C) 2016-2020 William Morrow
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.
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.
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
21 #if defined(__i386__) || defined(__x86_64__)
22 #if defined (__linux__)
23 #ifndef _COMMERCIALS_H_
24 #define _COMMERCIALS_H_
26 #include "arraylist.h"
28 #include "bcprogress.h"
30 #include "commercials.inc"
31 #include "condition.inc"
38 #include "mwindow.inc"
42 #include "filexml.inc"
45 class Commercials : public Garbage
51 int64_t frame_start, frame_total;
53 ArrayList<double> weights;
54 ArrayList<double> offsets;
55 ArrayList<Clips*> tracks;
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);
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);
82 int transaction() { return mdb->transaction(); }
83 int attachDb(int rw=0);
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);
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);
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);
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; }
110 Commercials(MWindow *mwindow);
114 class ScanStatusBar : public BC_ProgressBar
118 int update(int64_t position) {
119 if( --tick >= 0 ) return 0;
121 return BC_ProgressBar::update(position);
123 int update_length(int64_t length) {
124 tick = limit = length / 100;
125 return BC_ProgressBar::update_length(length);
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;
134 class ScanStatusGUI : public BC_Window
136 ScanStatus *sswindow;
139 ScanStatusBar **bars;
140 friend class ScanStatus;
142 ScanStatusGUI(ScanStatus *sswindow, int x, int y, int nlines, int nbars);
145 void create_objects(const char *text);
148 class ScanStatus : public Thread
154 Commercials *commercials;
157 ScanStatus(Commercials *commercials, int x, int y,
158 int nlines, int nbars, int &status, const char *text);
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);
167 class SdbPacket : public ListItem<SdbPacket>
170 enum sdb_packet_type { sdb_none, sdb_skim_frame, } type;
171 SkimDbThread *thread;
173 virtual void run() = 0;
175 SdbPacket(sdb_packet_type ty, SkimDbThread *tp) : type(ty), thread(tp) {}
179 class SdbPacketQueue : public List<SdbPacket>, public Mutex
182 SdbPacket *get_packet();
183 void put_packet(SdbPacket *p);
186 class SdbSkimFrame : public SdbPacket
192 uint8_t dat[SFRM_SZ];
194 void load(int pid,int64_t framenum,double framerate,
195 uint8_t *idata,int mw,int mh,int iw,int ih);
198 SdbSkimFrame(SkimDbThread *t) : SdbPacket(sdb_skim_frame, t) {}
203 class SkimDbThread : public Thread
205 SdbPacketQueue active_packets;
206 Condition *input_lock;
207 friend class SdbSkimFrame;
210 SdbPacketQueue skim_frames;
211 Commercials *commercials;
214 void start(Commercials *commercials);
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);