1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        Vob.h
3 // Purpose:     The class to store a VOB data
4 // Author:      Alex Thuering
5 // Created:	    29.01.2003
6 // RCS-ID:      $Id: Vob.h,v 1.7 2016/12/15 20:46:17 ntalex Exp $
7 // Copyright:   (c) Alex Thuering
8 // Licence:     GPL
9 /////////////////////////////////////////////////////////////////////////////
10 
11 #ifndef VOB_H
12 #define VOB_H
13 
14 #include "Stream.h"
15 #include "Cell.h"
16 #include "TextSub.h"
17 #include "Slideshow.h"
18 #include <vector>
19 
20 using namespace std;
21 
22 class wxSvgXmlNode;
23 class DVD;
24 class Menu;
25 class Cache;
26 
27 class Vob {
28 public:
29 	Vob();
30 	Vob(const wxString& filename);
31 	Vob(Menu* menu);
32 	Vob(Slideshow* slideshow);
33 	Vob(const Vob& vob);
34 	~Vob();
35 
36 	/** Sets name of video file for this vob*/
37 	bool SetFilename(const wxString& value);
38 	/** Returns name of video file */
GetFilename()39 	wxString GetFilename() { return m_filename; }
40 	/** Returns name of file to display */
41 	wxString GetFilenameDisplay();
42 
43 	/** Returns true if there are audio streams in input file(s) */
44 	bool HasAudio();
45 	/** Returns count of audio streams */
46 	unsigned int GetAudioStreamCount();
47 
48     /** Returns array with audio tracks */
GetAudioFilenames()49 	const wxArrayString& GetAudioFilenames() { return m_audioFilenames; }
50 	/** Adds the given audio file to the vob */
51 	bool AddAudioFile(wxString filename);
52 	/** Removes audio file with given index from the vob */
53 	void RemoveAudioFile(int index);
54 
55     /** Returns array with subtitles tracks */
GetSubtitles()56     TextSubArray& GetSubtitles() { return m_subtitles; }
57 	/** Adds the given subtitles file to the vob */
58 	bool AddSubtitlesFile(wxString filename);
59 	/** Returns count of subtitle streams */
60 	unsigned int GetSubtitleStreamsCount();
61 
62     /** Sets file name of temporary vob file */
SetTmpFilename(const wxString & value)63 	void SetTmpFilename(const wxString& value) { m_tmpFilename = value; }
64     /** Returns file name of temporary vob file */
GetTmpFilename()65 	const wxString& GetTmpFilename() { return m_tmpFilename; }
66 
67     /** Sets chapter list */
68 	void SetChapters(const wxString& value, bool firstVob);
69     /** Returns chapter list */
70 	wxString GetChapters();
71     /** Returns count of chapters */
72 	int GetChapterCount();
73 
74     /** Sets pause */
SetPause(int value)75 	void SetPause(int value) { m_pause = value; }
76     /** Returns pause */
GetPause()77 	int GetPause() { return m_pause; }
78 
79 	/** Sets start time (sec) */
SetStartTime(double value)80 	void SetStartTime(double value) { m_startTime = value; }
81 	/** Returns start time (sec) */
GetStartTime()82 	double GetStartTime() { return m_startTime; }
83 
84 	/** Sets recording time (sec) */
SetRecordingTime(double value)85 	void SetRecordingTime(double value) { m_recordingTime = value; }
86 	/** Returns recording time (sec) */
GetRecordingTime()87 	double GetRecordingTime() { return m_recordingTime; }
88 
89     /** Returns cells */
GetCells()90 	vector<Cell*>& GetCells() { return m_cells; }
91 
92 	/** Returns true if aspect ratio must be retained */
GetKeepAspectRatio()93 	bool GetKeepAspectRatio() { return m_keepAspectRatio; }
94 	/** Sets if aspect ratio must be retained */
SetKeepAspectRatio(bool keepAspectRatio)95 	void SetKeepAspectRatio(bool keepAspectRatio) { m_keepAspectRatio = keepAspectRatio; }
96 
97 	/** Returns true if video will be cropped to keep aspect ratio */
GetKeepAspectCrop()98 	bool GetKeepAspectCrop() { return m_keepAspectCrop; }
99 	/** Sets if video will be cropped to keep aspect ratio */
SetKeepAspectCrop(bool keepAspectCrop)100 	void SetKeepAspectCrop(bool keepAspectCrop) { m_keepAspectCrop = keepAspectCrop; }
101 
102 	/** Returns pad values: left, right, top, bottom */
GetPad()103 	vector<int>& GetPad() { return m_pad; }
104 	/** Updates pad/crop value to keep aspect ratio*/
105 	void UpdatePadCrop(AspectRatio aspectRatio);
106 	/** Calculates pad value to keep aspect ratio*/
107 	bool CalcPad(int& padx, int& pady, VideoFormat videoFormat, AspectRatio aspectRatio, const vector<int>& crop);
108 	/** Calculates crop value to keep aspect ratio*/
109 	bool CalcCrop(int& cropx, int& cropy, VideoFormat videoFormat, AspectRatio aspectRatio, const vector<int>& pad);
110 	/** Returns crop values: left, right, top, bottom */
GetCrop()111 	vector<int>& GetCrop() { return m_crop; }
112 
113 	/** Returns encode interlaced flag */
GetInterlaced()114 	bool GetInterlaced() { return m_interlaced; }
115 	/** Sets encode interlaced flag */
SetInterlaced(bool interlaced)116 	void SetInterlaced(bool interlaced) { m_interlaced = interlaced; }
117 
118 	/** Returns first field (interlacing) flag */
GetFirstField()119 	FirstField GetFirstField() { return m_firstField; }
120 	/** Sets first field (interlacing) flag */
SetFirstField(FirstField firstField)121 	void SetFirstField(FirstField firstField) { m_firstField = firstField; }
122 
123     /** Sets fade-in duration (sec) */
SetFadeIn(double value)124 	void SetFadeIn(double value) { m_fadeIn = value; }
125     /** Returns fade-in duration (sec) */
GetFadeIn()126 	double GetFadeIn() { return m_fadeIn; }
127 
128     /** Sets fade-out duration (sec) */
SetFadeOut(double value)129 	void SetFadeOut(double value) { m_fadeOut = value; }
130     /** Returns fade-out duration (sec) */
GetFadeOut()131 	double GetFadeOut() { return m_fadeOut; }
132 
133     /** Sets video filters */
SetVideoFilters(const wxString & value)134 	void SetVideoFilters(const wxString& value) { m_videoFilters = value; }
135     /** Returns video filters */
GetVideoFilters()136 	const wxString& GetVideoFilters() { return m_videoFilters; }
137     /** Returns all video filters (incl. crop, pad, fade-in and fade-out) */
138 	wxString GetAllVideoFilters();
139 
SetMenu(Menu * menu)140 	void SetMenu(Menu* menu) { m_menu = menu; }
GetMenu()141 	Menu* GetMenu() { return m_menu; }
142 
SetSlideshow(Slideshow * slideshow)143     void SetSlideshow(Slideshow* slideshow) { m_slideshow = slideshow; }
GetSlideshow()144 	Slideshow* GetSlideshow() { return m_slideshow; }
145 
146 	/** Returns duration of original video (sec) */
GetDuration()147 	inline double GetDuration() { return m_duration; }
148 	/** Returns duration of result video (sec) */
149 	double GetResultDuration();
150 	/** Returns array with stream parameters */
GetStreams()151 	vector<Stream*>& GetStreams() { return m_streams; }
152     /** Returns video stream parameters */
153     Stream* GetVideoStream();
154     /** Returns video stream index */
155     int GetVideoStreamIndex();
156 
157     /** Returns true if the source video file must not be remultiplexed/transcoded */
GetDoNotTranscode()158    	inline bool GetDoNotTranscode() { return m_doNotTranscode; }
159   	/** Sets if the source video file must not be remultiplexed/transcoded */
SetDoNotTranscode(bool doNotTranscode)160    	inline void SetDoNotTranscode(bool doNotTranscode) { m_doNotTranscode = doNotTranscode; }
161 
162 	wxSvgXmlNode* GetXML(DVDFileType type, DVD* dvd, int nextTitle);
163 	bool PutXML(wxSvgXmlNode* node, DVD* dvd, int tsi, int pgci, bool menu, bool firstVob);
164 
165 	/**
166 	 * Returns size in KB
167      * @return Size of VOB file in KB
168      */
169 	int GetSize(DVD* dvd);
170 
171 	/**
172 	 * Returns size of output file in KB
173      */
174 	int GetOutputFileSize(DVD* dvd, int fileIdx);
175 
176 	/**
177 	 * Returns bitrate in KB/s
178      */
179 	int GetBitrate(DVD* dvd, int fileIdx);
180 
181 	/**
182 	 * Returns size after transcoding in KB
183      * @return Size of VOB file in KB
184      */
185 	int GetTranscodedSize(DVD* dvd);
186 
187 	/**
188 	 * Returns size in KB required for generation
189 	 * @return Size in KB
190 	 */
191 	int GetRequiredSize(DVD* dvd, Cache* cache);
192 
193 	/** Returns file size in KB */
194 	static unsigned int GetFileSize(const wxString& filename);
195 
196 	/** Creates a VOB with blank video and silence audio */
197 	static Vob* CreateEmptyVob(VideoFormat videoFormat, AudioFormat audioFormat);
198 
199 private:
200 	wxString m_filename;
201 	wxArrayString m_audioFilenames;
202     TextSubArray m_subtitles;
203 	wxString m_tmpFilename;
204 
205 	int m_pause;
206 	vector<Cell*> m_cells;
207 
208 	Menu* m_menu;
209     Slideshow* m_slideshow;
210 
211 	double m_duration;
212 	double m_startTime;
213 	double m_recordingTime;
214 	vector<Stream*> m_streams;
215 	bool m_doNotTranscode;
216 	bool m_interlaced;
217 	FirstField m_firstField;
218 	bool m_keepAspectRatio;
219 	bool m_keepAspectCrop;
220 	vector<int> m_pad;
221 	vector<int> m_crop;
222 	double m_fadeIn; // fade-in duration (sec)
223 	double m_fadeOut; // fade-out duration (sec)
224 	wxString m_videoFilters;
225 	void Init(Menu* menu = NULL, Slideshow* slideshow = NULL);
226 };
227 
228 WX_DEFINE_ARRAY(Vob*, VobArray);
229 
230 #endif // VOB_H
231