Debian Codegraph @

samples/qtrecompress/recompressor.h

raw
1 #ifndef RECOMPRESSOR_H
2 #define RECOMPRESSOR_H
3
4 /*******************************************************
5
6 GUI-independent section of recompressor
7
8 *******************************************************/
9
10 #include "filters.h"
11 #include "imagecontrol.h"
12 #include "rec_cb.h"
13 #include <avifile.h>
14 #include <audioencoder.h>
15 #include <videodecoder.h>
16 #include <videoencoder.h>
17 #include <avm_locker.h>
18
19 struct AudioEncoderInfo
20 {
21 int fmt;
22 int bitrate;
23 };
24
25 class RecompressFilter: public Filter
26 {
27 friend class RecKernel;
28 public:
29 RecompressFilter(const avm::VideoEncoderInfo& in);
30 ~RecompressFilter();
31 const char* name() const { return "Recompress filter"; }
32 QString fullname() { return name(); }
33 avm::CImage* process(avm::CImage* im, int pos);
34 void about() {}
35 void config() {}
36 QString save();
37 void load(const QString&);
38 private:
39 avm::VideoEncoderInfo info;
40 char* comp_frame;
41 avm::IVideoDecoder* vd;
42 avm::IVideoEncoder* ve;
43 };
44
45 class RecKernel
46 {
47 friend class Filter;
48 public:
49 enum KernelMode { Remove = 0, Copy, Recompress };
50
51 RecKernel();
52 ~RecKernel();
53 Filter* getFilter(uint_t id); //creates filter registered under id
54 Filter* getFilterAt(uint_t id); //returns filter at pos id in current list
55 unsigned int getFilterCount() const; //size of current list
56 int addFilter(Filter* fi); //adds filter in the end of list
57 int removeFilter(uint_t id);
58 int moveUpFilter(uint_t id);
59 int moveDownFilter(uint_t id);
60
61 int openFile(const char* fn);
62 const char* getSrcFile() {return m_ReadFn.c_str();}
63 int setDestFile(const char* fn);
64 const char* getDestFile() {return m_Filename.c_str();}
65
66
67 avm::string aboutStream(uint_t id) const; //first all video streams, then audio
68
69 avm::string lastError() const;
70
71 bool isVideoStream(uint_t id) const;
72 bool isAudioStream(uint_t id) const;
73
74 avm::IStream::StreamType getStreamType(uint_t id) const;
75
76 //
77 // int getVideoInfo(int id, VideoEncoderInfo& vi) const;
78 // int getAudioInfo(int id, WAVEFORMATEX& wfmtx) const;
79 //
80 bool isStream(uint_t id) const;//nonzero if stream
81
82 int setStreamMode(uint_t id, KernelMode mode);
83 int getStreamMode(uint_t id, KernelMode& mode) const;
84 int getSelection(uint_t id, framepos_t& start, framepos_t& end) const;
85 int setSelection(uint_t id, framepos_t start, framepos_t end);
86 int setSelectionStart(uint_t id, framepos_t start);
87 int setSelectionEnd(uint_t id, framepos_t end);
88 double getFrameTime(uint_t id) const;
89 double getTime(uint_t id) const;
90 void setImageControl(IImageControl* ctl);//should set size & pictures if ctl!=0 & file is opened
91
92 avm::string getStreamName(uint_t id) const;
93 unsigned int getStreamCount() const;
94 framepos_t seek(int delta);//in frames
95 //negative seeks are very slow
96 framepos_t seekPos(framepos_t pos);//seek to nearest keyframe, return its position
97 framepos_t seekNextKeyFrame();
98 framepos_t seekPrevKeyFrame();
99 framepos_t pos() const;
100
101 int setCompress(uint_t id, const avm::VideoEncoderInfo& vi);
102 int setAudioCompress(uint_t id, const AudioEncoderInfo& wf);
103 int getCompress(uint_t id, avm::VideoEncoderInfo& vi) const;
104 int getAudioCompress(uint_t id, AudioEncoderInfo& wf) const;
105
106 unsigned int getVideoLength() const;
107
108 int setCallback(IRecompressCallback* pRecCallback);
109 int startRecompress();
110 int pauseRecompress();
111 int stopRecompress();
112
113 void redraw(bool readFrame = false);
114
115 int loadConfig(const char*);
116 int saveConfig(const char*);
117 private:
118 static void* recompressThreadStart(void* arg);
119 void* recompressThread();
120 void _destruct();
121 void swap(int x, int y) {
122 Filter* t = m_FilterList[x];
123 m_FilterList[x] = m_FilterList[y];
124 m_FilterList[y] = t;
125 }
126
127 avm::string m_Filename;
128 avm::string m_ReadFn;
129 avm::string strLastError;
130 IImageControl* _ctl;
131 RecompressFilter* m_pRecFilter;
132 IRecompressCallback* m_pRecCb;
133 avm::IWriteFile* m_pWriteFile;
134 avm::vector<avm::IReadFile*> m_ReadFiles;
135 uint_t vs, as;
136 struct full_stream
137 {
138 avm::IReadStream* stream;
139 KernelMode mode;
140 framepos_t startpos;
141 framepos_t endpos;
142 AudioEncoderInfo ai;
143 avm::VideoEncoderInfo vi;
144 int audiosz;
145 };
146 avm::vector<full_stream> m_Streams;
147 avm::vector<Filter*> m_FilterList;
148
149 int rec_status;
150 int pause_status;
151 avm::PthreadTask* rec_thread;
152 avm::PthreadMutex m_Mutex;
153 avm::PthreadCond m_Cond;
154 };
155
156 #endif // RECOMPRESSOR_H