File: AuFile.cc

package info (click to toggle)
steghide 0.5.1-14
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 3,432 kB
  • sloc: cpp: 13,302; ansic: 6,184; sh: 3,960; makefile: 384; yacc: 316; perl: 228; sed: 16
file content (230 lines) | stat: -rw-r--r-- 5,757 bytes parent folder | download | duplicates (3)
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
 * steghide 0.5.1 - a steganography program
 * Copyright (C) 1999-2003 Stefan Hetzl <shetzl@chello.at>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>

#include "AuData.h"
#include "AuFile.h"
#include "AuSampleValues.h"
#include "CvrStgFile.h"
#include "CvrStgObject.h"
#include "DFSAPHeuristic.h"
#include "SMDConstructionHeuristic.h"
#include "common.h"
#include "error.h"

AuFile::AuFile (BinaryIO *io)
	: CvrStgFile()
{
	setSamplesPerVertex (SamplesPerVertex) ;
	setEmbValueModulus (EmbValueModulus) ;
	read (io) ;
}

AuFile::~AuFile (void)
{
	delete Data ;
}

void AuFile::read (BinaryIO *io)
{
	CvrStgFile::read (io) ;

	try {
		Header.id[0] = '.' ;
		Header.id[1] = 's' ;
		Header.id[2] = 'n' ;
		Header.id[3] = 'd' ;

		// read header
		Header.offset = getBinIO()->read32_be() ;
		Header.size = getBinIO()->read32_be() ;
		UWORD32 encoding = getBinIO()->read32_be() ;
		Header.samplerate = getBinIO()->read32_be() ;
		Header.channels = getBinIO()->read32_be() ;

		// read infofield
		unsigned long leninfofield = Header.offset - AuHeader::HeaderSize ;
		if (leninfofield > 0) {
			Infofield.resize (leninfofield) ;
			for (unsigned long i = 0 ; i < leninfofield ; i++) {
				Infofield[i] = getBinIO()->read8() ;
			}
		}

		// read data
		switch (encoding) {
			case MULAW8:
			setRadius (Radius_MuLaw8) ;
			Data = new AuMuLawAudioData (this) ;
			break ;

			case PCM8:
			setRadius (Radius_PCM8) ;
			Data = new AuPCM8AudioData (this) ;
			break ;

			case PCM16:
			setRadius (Radius_PCM16) ;
			Data = new AuPCM16AudioData (this) ;
			break ;

			default:
			if (getBinIO()->is_std()) {
				throw NotImplementedError (_("the au file on standard input uses the unknown encoding %d."), encoding) ;
			}
			else {
				throw NotImplementedError (_("the au file \"%s\" uses the unknown encoding %d."), getBinIO()->getName().c_str(), encoding) ;
			}
			break ;
		} ;
		Header.encoding = (ENCODING) encoding ;
	}
	catch (BinaryInputError e) {
		switch (e.getType()) {
			case BinaryInputError::FILE_ERR:
			{
				throw SteghideError (_("an error occurred while reading the au headers from the file \"%s\"."), getBinIO()->getName().c_str()) ;
				break ;
			}

			case BinaryInputError::FILE_EOF:
			{
				throw SteghideError (_("premature end of file \"%s\" while reading au headers."), getBinIO()->getName().c_str()) ;
				break ;
			}

			case BinaryInputError::STDIN_ERR:
			{
				throw SteghideError (_("an error occurred while reading the au headers from standard input.")) ;
				break ;
			}

			case BinaryInputError::STDIN_EOF:
			{
				throw SteghideError (_("premature end of data from standard input while reading au headers.")) ;
				break ;
			}
		}
	}

	// if available, use size of audio data, else read until eof
	unsigned long n = AudioData::NoLimit ;
	if (Header.size != AuHeader::SizeUnknown) {
		myassert (Header.size % Header.getBytesPerSample() == 0) ;
		n = Header.size / Header.getBytesPerSample() ;
	}
	Data->read (getBinIO(), n) ;
}

void AuFile::write ()
{
	CvrStgFile::write() ;

	try {
		// write header
		getBinIO()->write8 (Header.id[0]) ;
		getBinIO()->write8 (Header.id[1]) ;
		getBinIO()->write8 (Header.id[2]) ;
		getBinIO()->write8 (Header.id[3]) ;
		getBinIO()->write32_be (Header.offset) ;
		getBinIO()->write32_be (Header.size) ;
		getBinIO()->write32_be ((UWORD32) Header.encoding) ;
		getBinIO()->write32_be (Header.samplerate) ;
		getBinIO()->write32_be (Header.channels) ;

		// write infofield
		for (unsigned long i = 0 ; i < Infofield.size() ; i++) {
			getBinIO()->write8 (Infofield[i]) ;
		}
	}
	catch (BinaryOutputError e) {
		switch (e.getType()) {
			case BinaryOutputError::FILE_ERR:
			{
				throw SteghideError (_("an error occurred while writing the au headers to the file \"%s\"."), getBinIO()->getName().c_str()) ;
				break ;
			}

			case BinaryOutputError::STDOUT_ERR:
			{
				throw SteghideError (_("an error occurred while writing the au headers to standard output.")) ;
				break ;
			}
		}
	}

	Data->write (getBinIO(), AudioData::NoLimit) ;
}

std::list<CvrStgFile::Property> AuFile::getProperties () const
{
	std::list<CvrStgFile::Property> retval ;

	// format
	std::string formatstring = "au audio" ;
	switch (Header.encoding) {
		case MULAW8:
			formatstring += _(", mu-law encoding") ;
		break ;

		case PCM8:
		case PCM16:
			formatstring += _(", PCM encoding") ;
		break ;
	}
	retval.push_back (CvrStgFile::Property (_("format"), formatstring)) ;

	return retval ;
}

unsigned short AuFile::AuHeader::getBytesPerSample () const
{
	unsigned short retval = 0 ;
	switch (encoding) {
		case MULAW8:
		retval = 1 ;
		break ;

		case PCM8:
		retval = 1 ;
		break ;

		case PCM16:
		retval = 2 ;
		break ;

		default:
		myassert(0) ;
		break ;
	}
	return retval ;
}

std::vector<MatchingAlgorithm*> AuFile::getMatchingAlgorithms (Graph* g, Matching* m) const
{
	std::vector<MatchingAlgorithm*> retval ;
	retval.push_back (new SMDConstructionHeuristic (g, m)) ;
	retval.push_back (new DFSAPHeuristic (g, m)) ;
	return retval ;
}