File: mpegOut.hh

package info (click to toggle)
mpgtx 1.3.1-5
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 432 kB
  • ctags: 426
  • sloc: cpp: 5,624; sh: 1,542; makefile: 107
file content (162 lines) | stat: -rw-r--r-- 3,928 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*************************************************************
 *   mpgtx an mpeg toolbox                                   *
 *   by Laurent Alacoque <laureck@users.sourceforge.net>     *   
 *   (c) 2001                                                *
 *   You may copy, modify and redistribute this              *
 *   source file under the terms of the GNU Public License   *
 ************************************************************/
#ifndef __mpegOut_hh_
#define __mpegOut_hh_

#include "common.hh"
#include "mpeg.hh"
// required by access()
// FIXME: Still needed, because we have mpgtx_access()?
#include <unistd.h>


class mpeg;


class mpegOut
{
public:
	mpegOut(char *filename);
	mpegOut(FILE *filehandle);
	virtual ~mpegOut();
	const FILE* OutFile() {return MpegOut;}
	int WriteChunk(mpeg* Mpeg, off_t from, off_t to)
			{return WriteChunk(Mpeg, from, false, to, true);};
	virtual void WriteHeader(mpeg* Mpeg) = 0;
	virtual int WriteChunk (mpeg* Mpeg,
		off_t from, bool from_included,
		off_t to, bool to_included) = 0;
	virtual void Finish() {};

protected:
	mpegOut() {};
	virtual void Copy(FILE* file, off_t from, off_t to) = 0;
	int FileType;
	bool HasAudio,HasVideo;
	FILE* MpegOut;
	byte* buffer;
};


class mpegOutWithVideo : public mpegOut
{
protected:
	mpegOutWithVideo(char* filename) : 
		mpegOut(filename) {mpeg_version = 0;};
	mpegOutWithVideo(FILE* filehandle) : 
		mpegOut(filehandle) {mpeg_version = 0;};

	mpegOutWithVideo(){};
	long CorrectTS(long bufferlength);

	void memReadTS(long offset, double* ts, bool mpeg2pack = false, bool pack = false);
	int  memReadPktTS(long* off, double* pts, double* dts, long bufferlength);
	void memWriteTS(long offset, double ts, bool mpeg2pack = false, bool pack = false);

	double currentTS;
	double ts_correction;
	bool first_TS_correction;
	
	int mpeg_version;
};

class mpegVideoOut : public mpegOutWithVideo
{
public:
	mpegVideoOut(char* filename) :
		mpegOutWithVideo(filename) {};
	mpegVideoOut(FILE* filehandle) :
		mpegOutWithVideo(filehandle) {};
		
	void WriteHeader(mpeg* Mpeg);
	int WriteChunk (mpeg* Mpeg,
		off_t from, bool from_included,
		off_t to, bool to_included );
protected:
	mpegVideoOut(){};
	void Copy(FILE* file, off_t from, off_t to);
};


class mpegSystemOut : public mpegOutWithVideo
{
public:
	mpegSystemOut(char* filename) :
		mpegOutWithVideo(filename) {partial_packet = 0;};
	mpegSystemOut(FILE* filehandle) :
		mpegOutWithVideo(filehandle) {partial_packet = 0;};

	void WriteHeader(mpeg* Mpeg);
	int WriteChunk(mpeg* Mpeg,
		off_t from, bool from_included,
		off_t to, bool to_included );
	void Finish(); 
	
protected:
	mpegSystemOut() {};
	void Copy(FILE* file, off_t from, off_t to);

	//size of data from the end of the packet header to the end of file
	off_t partial_packet_length;
	//keep the partial packet in memory (because stdout is not seekable)
	byte* partial_packet;
};

class mpegAudioOut : public mpegOut
{
public:
	mpegAudioOut(char* filename):
		mpegOut(filename){};
	mpegAudioOut(FILE* filehandle):
		mpegOut(filehandle){};

	void WriteHeader(mpeg* Mpeg){};
	int WriteChunk(mpeg* Mpeg,
		off_t from, bool from_included,
		off_t to, bool to_included );

	void Finish();
protected:
	mpegAudioOut(){};
	void Copy(FILE* file, off_t from, off_t to);
};

class mpegOutFactory
{
public:
	mpegOut* NewMpegFrom(mpeg* MpegIn, char* filename);
	mpegOut* NewMpegFrom(mpeg* MpegIn, FILE* filehandle);
};


class demuxer
{
public:
	demuxer(mpeg* _Mpeg, char* _basename, bool _confirm = true);
	~demuxer();
	int Process();
	
protected:
	int ProcessTransportStream();
	int ProcessProgramStream();
	int DemuxTrPkt(FILE* out, off_t start, off_t end);
	FILE* openfile(char* filename);
	off_t Copy(FILE* into, off_t from, off_t to);
	demuxer() {};
	FILE* AudioFile[16];
	int n_audio;
	FILE* VideoFile[16];
	int n_video;
	int n_programs;
	mpeg* Mpeg;
	char* basename;
	bool confirm;
	byte* buffer;
};

#endif //__mpegOut_hh_