1 /*
2  * @(#)StreamInfo
3  *
4  * Copyright (c) 2005-2008 by dvb.matt, All Rights Reserved.
5  *
6  * This file is part of ProjectX, a free Java based demux utility.
7  * By the authors, ProjectX is intended for educational purposes only,
8  * as a non-commercial test project.
9  *
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  *
25  */
26 
27 package net.sourceforge.dvb.projectx.xinput;
28 
29 import net.sourceforge.dvb.projectx.common.Resource;
30 import net.sourceforge.dvb.projectx.common.Keys;
31 
32 /**
33  *
34  */
35 public class StreamInfo extends Object {
36 
37 	private Object[] videostreams;
38 	private Object[] audiostreams;
39 	private Object[] teletextstreams;
40 	private Object[] subpicturestreams;
41 
42 	private String file_name;
43 	private String file_date;
44 	private String file_size;
45 	private String file_type;
46 	private String file_location;
47 	private String file_playtime;
48 	private String file_source;
49 
50 	private String additionals;
51 
52 	private int streamtype;
53 	private Object[] pids;
54 	private byte[] videoheader;
55 
56 	private int[] thumbnail;
57 
58 	private long scanposition = 0;
59 
60 	private String line_separator = System.getProperty("line.separator");
61 
62 	/**
63 	 *
64 	 */
StreamInfo()65 	public StreamInfo()
66 	{
67 		setStreamInfo("", "", "", "", "", "", "");
68 	}
69 
70 	/**
71 	 *
72 	 */
StreamInfo(String _file_source, String _file_type, String _file_name, String _file_location, String _file_date, String _file_size, String _file_playtime)73 	public StreamInfo(String _file_source, String _file_type, String _file_name, String _file_location, String _file_date, String _file_size, String _file_playtime)
74 	{
75 		setStreamInfo(_file_source, _file_type, _file_name, _file_location, _file_date, _file_size, _file_playtime);
76 	}
77 
78 	/**
79 	 *
80 	 */
StreamInfo(String _file_source, String _file_type, String _file_name, String _file_location, String _file_date, String _file_size, String _file_playtime, Object[] _videostreams, Object[] _audiostreams, Object[] _teletextstreams, Object[] _subpicturestreams)81 	public StreamInfo(String _file_source, String _file_type, String _file_name, String _file_location, String _file_date, String _file_size, String _file_playtime, Object[] _videostreams, Object[] _audiostreams, Object[] _teletextstreams, Object[] _subpicturestreams)
82 	{
83 		setStreamInfo(_file_source, _file_type, _file_name, _file_location, _file_date, _file_size, _file_playtime, _videostreams, _audiostreams, _teletextstreams, _subpicturestreams);
84 	}
85 
86 	/**
87 	 *
88 	 */
StreamInfo(int _streamtype, String _file_source, String _file_type, String _file_name, String _file_location, String _file_date, String _file_size, String _file_playtime, Object[] _videostreams, Object[] _audiostreams, Object[] _teletextstreams, Object[] _subpicturestreams, Object[] _pids, byte[] _videoheader, int[] _thumbnail)89 	public StreamInfo(int _streamtype, String _file_source, String _file_type, String _file_name, String _file_location, String _file_date, String _file_size, String _file_playtime, Object[] _videostreams, Object[] _audiostreams, Object[] _teletextstreams, Object[] _subpicturestreams, Object[] _pids, byte[] _videoheader, int[] _thumbnail)
90 	{
91 		streamtype = _streamtype;
92 		pids = _pids;
93 		videoheader = _videoheader;
94 		thumbnail = _thumbnail;
95 
96 		setStreamInfo(_file_source, _file_type, _file_name, _file_location, _file_date, _file_size, _file_playtime, _videostreams, _audiostreams, _teletextstreams, _subpicturestreams);
97 	}
98 
99 	/**
100 	 *
101 	 */
setStreamInfo(String _file_source, String _file_type, String _file_name, String _file_location, String _file_date, String _file_size, String _file_playtime)102 	public void setStreamInfo(String _file_source, String _file_type, String _file_name, String _file_location, String _file_date, String _file_size, String _file_playtime)
103 	{
104 		setStreamInfo(_file_source, _file_type, _file_name, _file_location, _file_date, _file_size, _file_playtime, null, null, null, null);
105 	}
106 
107 	/**
108 	 *
109 	 */
setStreamInfo(String _file_source, String _file_type, String _file_name, String _file_location, String _file_date, String _file_size, String _file_playtime, Object[] _videostreams, Object[] _audiostreams, Object[] _teletextstreams, Object[] _subpicturestreams)110 	public void setStreamInfo(String _file_source, String _file_type, String _file_name, String _file_location, String _file_date, String _file_size, String _file_playtime, Object[] _videostreams, Object[] _audiostreams, Object[] _teletextstreams, Object[] _subpicturestreams)
111 	{
112 		videostreams = _videostreams;
113 		audiostreams = _audiostreams;
114 		teletextstreams = _teletextstreams;
115 		subpicturestreams = _subpicturestreams;
116 
117 		file_name = _file_name;
118 		file_date = _file_date;
119 		file_size = _file_size;
120 		file_type = _file_type;
121 		file_location = _file_location;
122 		file_playtime = _file_playtime;
123 		file_source = _file_source;
124 	}
125 
126 	/**
127 	 *
128 	 */
getThumbnail()129 	public int[] getThumbnail()
130 	{
131 		return thumbnail;
132 	}
133 
134 	/**
135 	 *
136 	 */
setThumbnail(int[] pic)137 	public void setThumbnail(int[] pic)
138 	{
139 		thumbnail = new int[pic.length];
140 		System.arraycopy(pic, 0, thumbnail, 0, pic.length);
141 	}
142 
143 	/**
144 	 *
145 	 */
getFileName()146 	public String getFileName()
147 	{
148 		return file_name;
149 	}
150 
151 	/**
152 	 *
153 	 */
getFileSourceBase()154 	public String getFileSourceBase()
155 	{
156 		return file_source;
157 	}
158 
159 	/**
160 	 *
161 	 */
getFileSource()162 	public String getFileSource()
163 	{
164 		return "[" + getFileSourceBase() + "]";
165 	}
166 
167 	/**
168 	 *
169 	 */
getFileSourceAndName()170 	public String getFileSourceAndName()
171 	{
172 		return getFileSource() + " - " + getFileName();
173 	}
174 
175 	/**
176 	 *
177 	 */
getFileDate()178 	public String getFileDate()
179 	{
180 		return file_date;
181 	}
182 
183 	/**
184 	 *
185 	 */
getFileSize()186 	public String getFileSize()
187 	{
188 		return file_size;
189 	}
190 
191 	/**
192 	 *
193 	 */
getFileType()194 	public String getFileType()
195 	{
196 		return file_type;
197 	}
198 
199 	/**
200 	 *
201 	 */
getFileLocation()202 	public String getFileLocation()
203 	{
204 		return file_location;
205 	}
206 
207 	/**
208 	 *
209 	 */
getPlaytime()210 	public String getPlaytime()
211 	{
212 		return file_playtime;
213 	}
214 
215 	/**
216 	 *
217 	 */
getVideoStreams()218 	public Object[] getVideoStreams()
219 	{
220 		return videostreams;
221 	}
222 
223 	/**
224 	 *
225 	 */
getAudioStreams()226 	public Object[] getAudioStreams()
227 	{
228 		return audiostreams;
229 	}
230 
231 	/**
232 	 *
233 	 */
getTeletextStreams()234 	public Object[] getTeletextStreams()
235 	{
236 		return teletextstreams;
237 	}
238 
239 	/**
240 	 *
241 	 */
getSubpictureStreams()242 	public Object[] getSubpictureStreams()
243 	{
244 		return subpicturestreams;
245 	}
246 
247 	/**
248 	 *
249 	 */
getVideo()250 	public String getVideo()
251 	{
252 		return getString(getVideoStreams());
253 	}
254 
255 	/**
256 	 *
257 	 */
getAudio()258 	public String getAudio()
259 	{
260 		return getString(getAudioStreams());
261 	}
262 
263 	/**
264 	 *
265 	 */
getTeletext()266 	public String getTeletext()
267 	{
268 		return getString(getTeletextStreams());
269 	}
270 
271 	/**
272 	 *
273 	 */
getSubpicture()274 	public String getSubpicture()
275 	{
276 		return getString(getSubpictureStreams());
277 	}
278 
279 	/**
280 	 *
281 	 */
getAdditionals()282 	public String getAdditionals()
283 	{
284 		return additionals;
285 	}
286 
287 	/**
288 	 *
289 	 */
getString(Object[] obj)290 	private String getString(Object[] obj)
291 	{
292 		String str = "";
293 
294 		if (obj == null || obj.length == 0)
295 			return "n/a";
296 
297 		str = obj[0].toString();
298 
299 		for (int i = 1; i < obj.length; i++)
300 			str += line_separator + obj[i].toString();
301 
302 		return str;
303 	}
304 
305 	/**
306 	 *
307 	 */
getFullInfo()308 	public String getFullInfo()
309 	{
310 		String str = "";
311 
312 		str += Resource.getString("ScanInfo.Location") + line_separator;
313 		str += getFileSource() + " @ " + getFileLocation() + line_separator;
314 		str += Resource.getString("ScanInfo.Name") + line_separator;
315 		str += getFileName() + line_separator;
316 		str += Resource.getString("ScanInfo.Size") + line_separator;
317 		str += getFileSize() + line_separator;
318 		str += Resource.getString("ScanInfo.Date") + line_separator;
319 		str += getFileDate() + line_separator;
320 		str += line_separator;
321 		str += Resource.getString("ScanInfo.Type") + line_separator;
322 		str += getFileType() + line_separator;
323 		str += Resource.getString("ScanInfo.Video") + line_separator;
324 		str += getVideo() + line_separator;
325 		str += Resource.getString("ScanInfo.Audio") + line_separator;
326 		str += getAudio() + line_separator;
327 		str += Resource.getString("ScanInfo.Teletext") + line_separator;
328 		str += getTeletext() + line_separator;
329 		str += Resource.getString("ScanInfo.Subpicture") + line_separator;
330 		str += getSubpicture() + line_separator;
331 		str += Resource.getString("ScanInfo.Playtime") + line_separator;
332 		str += getPlaytime();
333 
334 		return str;
335 	}
336 
337 	/**
338 	 *
339 	 */
getScanPosition()340 	public long getScanPosition()
341 	{
342 		return scanposition;
343 	}
344 
345 	/**
346 	 *
347 	 */
setScanPosition(long value)348 	public void setScanPosition(long value)
349 	{
350 		scanposition = value;
351 	}
352 
353 	/**
354 	 *
355 	 */
setStreamType(int _streamtype)356 	public void setStreamType(int _streamtype)
357 	{
358 		streamtype = _streamtype;
359 		file_type = Keys.ITEMS_FileTypes[getStreamType()].toString();
360 	}
361 
362 	/**
363 	 *
364 	 */
setStreamType(int _streamtype, String str)365 	public void setStreamType(int _streamtype, String str)
366 	{
367 		streamtype = _streamtype;
368 		file_type = "[" + getStreamSubType() + "] " + Keys.ITEMS_FileTypes[getStreamType()].toString() + " " + str;
369 	}
370 
371 	/**
372 	 *
373 	 */
getStreamType()374 	public int getStreamType()
375 	{
376 		return (0xFF & streamtype);
377 	}
378 
379 	/**
380 	 *
381 	 */
getStreamSubType()382 	public int getStreamSubType()
383 	{
384 		return (0xFF & streamtype>>>8);
385 	}
386 
387 	/**
388 	 *
389 	 */
getStreamFullType()390 	public int getStreamFullType()
391 	{
392 		return streamtype;
393 	}
394 
395 	/**
396 	 *
397 	 */
setPIDs(Object[] _pids)398 	public void setPIDs(Object[] _pids)
399 	{
400 		pids = _pids;
401 	}
402 
403 	/**
404 	 *
405 	 */
getPIDs()406 	public int[] getPIDs()
407 	{
408 		int len = pids == null ? 0 : pids.length;
409 
410 		int[] array = new int[len];
411 
412 		for (int i = 0; i < len; i++)
413 			array[i] = Integer.parseInt(pids[i].toString());
414 
415 		return array;
416 	}
417 
418 	/**
419 	 *
420 	 */
getMediaPIDs()421 	public int[] getMediaPIDs()
422 	{
423 		int len = pids == null || pids.length == 0 ? 0 : pids.length - 1;
424 
425 		int[] array = new int[len];
426 
427 		for (int i = 0; i < len; i++)
428 			array[i] = Integer.parseInt(pids[1 + i].toString());
429 
430 		return array;
431 	}
432 
433 	/**
434 	 *
435 	 */
setVideoHeader(byte[] _videoheader)436 	public void setVideoHeader(byte[] _videoheader)
437 	{
438 		if (_videoheader == null)
439 			videoheader = null;
440 
441 		else
442 		{
443 			videoheader = new byte[12];
444 			System.arraycopy(_videoheader, 0, videoheader, 0, _videoheader.length);
445 		}
446 	}
447 
448 	/**
449 	 *
450 	 */
getVideoHeader()451 	public byte[] getVideoHeader()
452 	{
453 		return videoheader;
454 	}
455 
456 	/**
457 	 *
458 	 */
copyContent(Object[] _obj)459 	private Object[] copyContent(Object[] _obj)
460 	{
461 		if (_obj == null)
462 			return null;
463 
464 		Object[] obj = new Object[_obj.length];
465 
466 		System.arraycopy(_obj, 0, obj, 0, obj.length);
467 
468 		return obj;
469 	}
470 
471 	/**
472 	 *
473 	 */
copyContent(byte[] _array)474 	private byte[] copyContent(byte[] _array)
475 	{
476 		if (_array == null)
477 			return null;
478 
479 		byte[] array = new byte[_array.length];
480 
481 		System.arraycopy(_array, 0, array, 0, array.length);
482 
483 		return array;
484 	}
485 
486 	/**
487 	 *
488 	 */
copyContent(int[] _array)489 	private int[] copyContent(int[] _array)
490 	{
491 		if (_array == null)
492 			return null;
493 
494 		int[] array = new int[_array.length];
495 
496 		System.arraycopy(_array, 0, array, 0, array.length);
497 
498 		return array;
499 	}
500 
501 	/**
502 	 *
503 	 */
getNewInstance()504 	public StreamInfo getNewInstance()
505 	{
506 		return new StreamInfo(streamtype, file_source, file_type, file_name, file_location, file_date, file_size, file_playtime, copyContent(videostreams), copyContent(audiostreams), copyContent(teletextstreams), copyContent(subpicturestreams), copyContent(pids), copyContent(videoheader), copyContent(thumbnail));
507 	}
508 
509 }
510