diff options
Diffstat (limited to 'linden/indra/llaudio/vorbisencode.cpp')
-rw-r--r-- | linden/indra/llaudio/vorbisencode.cpp | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/linden/indra/llaudio/vorbisencode.cpp b/linden/indra/llaudio/vorbisencode.cpp index c5a751e..7df1416 100644 --- a/linden/indra/llaudio/vorbisencode.cpp +++ b/linden/indra/llaudio/vorbisencode.cpp | |||
@@ -17,7 +17,8 @@ | |||
17 | * There are special exceptions to the terms and conditions of the GPL as | 17 | * There are special exceptions to the terms and conditions of the GPL as |
18 | * it is applied to this Source Code. View the full text of the exception | 18 | * it is applied to this Source Code. View the full text of the exception |
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | 19 | * in the file doc/FLOSS-exception.txt in this software distribution, or |
20 | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | 20 | * online at |
21 | * http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
21 | * | 22 | * |
22 | * By copying, modifying or distributing this software, you acknowledge | 23 | * By copying, modifying or distributing this software, you acknowledge |
23 | * that you have read and understood your obligations described above, | 24 | * that you have read and understood your obligations described above, |
@@ -85,28 +86,29 @@ S32 check_for_invalid_wav_formats(const std::string& in_fname, std::string& erro | |||
85 | 86 | ||
86 | error_msg.clear(); | 87 | error_msg.clear(); |
87 | 88 | ||
88 | apr_file_t* infp = ll_apr_file_open(in_fname,LL_APR_RB); | 89 | //******************************** |
89 | if (!infp) | 90 | LLAPRFile infile ; |
91 | infile.open(in_fname,LL_APR_RB); | ||
92 | //******************************** | ||
93 | if (!infile.getFileHandle()) | ||
90 | { | 94 | { |
91 | error_msg = "CannotUploadSoundFile"; | 95 | error_msg = "CannotUploadSoundFile"; |
92 | return(LLVORBISENC_SOURCE_OPEN_ERR); | 96 | return(LLVORBISENC_SOURCE_OPEN_ERR); |
93 | } | 97 | } |
94 | 98 | ||
95 | ll_apr_file_read(infp, wav_header, 44); | 99 | infile.read(wav_header, 44); |
96 | physical_file_size = ll_apr_file_seek(infp,APR_END,0); | 100 | physical_file_size = infile.seek(APR_END,0); |
97 | 101 | ||
98 | if (strncmp((char *)&(wav_header[0]),"RIFF",4)) | 102 | if (strncmp((char *)&(wav_header[0]),"RIFF",4)) |
99 | { | 103 | { |
100 | error_msg = "SoundFileNotRIFF"; | 104 | error_msg = "SoundFileNotRIFF"; |
101 | apr_file_close(infp); | 105 | return(LLVORBISENC_WAV_FORMAT_ERR); |
102 | return(LLVORBISENC_WAV_FORMAT_ERR); | ||
103 | } | 106 | } |
104 | 107 | ||
105 | if (strncmp((char *)&(wav_header[8]),"WAVE",4)) | 108 | if (strncmp((char *)&(wav_header[8]),"WAVE",4)) |
106 | { | 109 | { |
107 | error_msg = "SoundFileNotRIFF"; | 110 | error_msg = "SoundFileNotRIFF"; |
108 | apr_file_close(infp); | 111 | return(LLVORBISENC_WAV_FORMAT_ERR); |
109 | return(LLVORBISENC_WAV_FORMAT_ERR); | ||
110 | } | 112 | } |
111 | 113 | ||
112 | // parse the chunks | 114 | // parse the chunks |
@@ -115,8 +117,8 @@ S32 check_for_invalid_wav_formats(const std::string& in_fname, std::string& erro | |||
115 | 117 | ||
116 | while ((file_pos + 8)< physical_file_size) | 118 | while ((file_pos + 8)< physical_file_size) |
117 | { | 119 | { |
118 | ll_apr_file_seek(infp,APR_SET,file_pos); | 120 | infile.seek(APR_SET,file_pos); |
119 | ll_apr_file_read(infp, wav_header, 44); | 121 | infile.read(wav_header, 44); |
120 | 122 | ||
121 | chunk_length = ((U32) wav_header[7] << 24) | 123 | chunk_length = ((U32) wav_header[7] << 24) |
122 | + ((U32) wav_header[6] << 16) | 124 | + ((U32) wav_header[6] << 16) |
@@ -149,8 +151,9 @@ S32 check_for_invalid_wav_formats(const std::string& in_fname, std::string& erro | |||
149 | file_pos += (chunk_length + 8); | 151 | file_pos += (chunk_length + 8); |
150 | chunk_length = 0; | 152 | chunk_length = 0; |
151 | } | 153 | } |
152 | 154 | //**************** | |
153 | apr_file_close(infp); | 155 | infile.close(); |
156 | //**************** | ||
154 | 157 | ||
155 | if (!uncompressed_pcm) | 158 | if (!uncompressed_pcm) |
156 | { | 159 | { |
@@ -228,19 +231,21 @@ S32 encode_vorbis_file(const std::string& in_fname, const std::string& out_fname | |||
228 | 231 | ||
229 | S32 data_left = 0; | 232 | S32 data_left = 0; |
230 | 233 | ||
231 | apr_file_t* infp = ll_apr_file_open(in_fname,LL_APR_RB); | 234 | LLAPRFile infile ; |
232 | if (!infp) | 235 | infile.open(in_fname,LL_APR_RB); |
236 | if (!infile.getFileHandle()) | ||
233 | { | 237 | { |
234 | llwarns << "Couldn't open temporary ogg file for writing: " << in_fname | 238 | llwarns << "Couldn't open temporary ogg file for writing: " << in_fname |
235 | << llendl; | 239 | << llendl; |
236 | return(LLVORBISENC_SOURCE_OPEN_ERR); | 240 | return(LLVORBISENC_SOURCE_OPEN_ERR); |
237 | } | 241 | } |
238 | apr_file_t* outfp = ll_apr_file_open(out_fname,LL_APR_WPB); | 242 | |
239 | if (!outfp) | 243 | LLAPRFile outfile ; |
244 | outfile.open(out_fname,LL_APR_WPB); | ||
245 | if (!outfile.getFileHandle()) | ||
240 | { | 246 | { |
241 | llwarns << "Couldn't open upload sound file for reading: " << in_fname | 247 | llwarns << "Couldn't open upload sound file for reading: " << in_fname |
242 | << llendl; | 248 | << llendl; |
243 | apr_file_close (infp); | ||
244 | return(LLVORBISENC_DEST_OPEN_ERR); | 249 | return(LLVORBISENC_DEST_OPEN_ERR); |
245 | } | 250 | } |
246 | 251 | ||
@@ -248,10 +253,10 @@ S32 encode_vorbis_file(const std::string& in_fname, const std::string& out_fname | |||
248 | U32 chunk_length = 0; | 253 | U32 chunk_length = 0; |
249 | U32 file_pos = 12; // start at the first chunk (usually fmt but not always) | 254 | U32 file_pos = 12; // start at the first chunk (usually fmt but not always) |
250 | 255 | ||
251 | while (apr_file_eof(infp) != APR_EOF) | 256 | while (infile.eof() != APR_EOF) |
252 | { | 257 | { |
253 | ll_apr_file_seek(infp,APR_SET,file_pos); | 258 | infile.seek(APR_SET,file_pos); |
254 | ll_apr_file_read(infp, wav_header, 44); | 259 | infile.read(wav_header, 44); |
255 | 260 | ||
256 | chunk_length = ((U32) wav_header[7] << 24) | 261 | chunk_length = ((U32) wav_header[7] << 24) |
257 | + ((U32) wav_header[6] << 16) | 262 | + ((U32) wav_header[6] << 16) |
@@ -271,7 +276,7 @@ S32 encode_vorbis_file(const std::string& in_fname, const std::string& out_fname | |||
271 | } | 276 | } |
272 | else if (!(strncmp((char *)&(wav_header[0]),"data",4))) | 277 | else if (!(strncmp((char *)&(wav_header[0]),"data",4))) |
273 | { | 278 | { |
274 | ll_apr_file_seek(infp,APR_SET,file_pos+8); | 279 | infile.seek(APR_SET,file_pos+8); |
275 | // leave the file pointer at the beginning of the data chunk data | 280 | // leave the file pointer at the beginning of the data chunk data |
276 | data_left = chunk_length; | 281 | data_left = chunk_length; |
277 | break; | 282 | break; |
@@ -280,7 +285,6 @@ S32 encode_vorbis_file(const std::string& in_fname, const std::string& out_fname | |||
280 | chunk_length = 0; | 285 | chunk_length = 0; |
281 | } | 286 | } |
282 | 287 | ||
283 | // apr_file_close(infp); | ||
284 | 288 | ||
285 | /********** Encode setup ************/ | 289 | /********** Encode setup ************/ |
286 | 290 | ||
@@ -345,8 +349,8 @@ S32 encode_vorbis_file(const std::string& in_fname, const std::string& out_fname | |||
345 | while(!eos){ | 349 | while(!eos){ |
346 | int result=ogg_stream_flush(&os,&og); | 350 | int result=ogg_stream_flush(&os,&og); |
347 | if(result==0)break; | 351 | if(result==0)break; |
348 | ll_apr_file_write(outfp, og.header, og.header_len); | 352 | outfile.write(og.header, og.header_len); |
349 | ll_apr_file_write(outfp, og.body, og.body_len); | 353 | outfile.write(og.body, og.body_len); |
350 | } | 354 | } |
351 | 355 | ||
352 | } | 356 | } |
@@ -356,7 +360,7 @@ S32 encode_vorbis_file(const std::string& in_fname, const std::string& out_fname | |||
356 | { | 360 | { |
357 | long bytes_per_sample = bits_per_sample/8; | 361 | long bytes_per_sample = bits_per_sample/8; |
358 | 362 | ||
359 | long bytes=(long)ll_apr_file_read(infp, readbuffer,llclamp((S32)(READ_BUFFER*num_channels*bytes_per_sample),0,data_left)); /* stereo hardwired here */ | 363 | long bytes=(long)infile.read(readbuffer,llclamp((S32)(READ_BUFFER*num_channels*bytes_per_sample),0,data_left)); /* stereo hardwired here */ |
360 | 364 | ||
361 | if (bytes==0) | 365 | if (bytes==0) |
362 | { | 366 | { |
@@ -464,8 +468,8 @@ S32 encode_vorbis_file(const std::string& in_fname, const std::string& out_fname | |||
464 | if(result==0) | 468 | if(result==0) |
465 | break; | 469 | break; |
466 | 470 | ||
467 | ll_apr_file_write(outfp, og.header, og.header_len); | 471 | outfile.write(og.header, og.header_len); |
468 | ll_apr_file_write(outfp, og.body, og.body_len); | 472 | outfile.write(og.body, og.body_len); |
469 | 473 | ||
470 | /* this could be set above, but for illustrative purposes, I do | 474 | /* this could be set above, but for illustrative purposes, I do |
471 | it here (to show that vorbis does know where the stream ends) */ | 475 | it here (to show that vorbis does know where the stream ends) */ |
@@ -493,8 +497,6 @@ S32 encode_vorbis_file(const std::string& in_fname, const std::string& out_fname | |||
493 | 497 | ||
494 | // fprintf(stderr,"Vorbis encoding: Done.\n"); | 498 | // fprintf(stderr,"Vorbis encoding: Done.\n"); |
495 | llinfos << "Vorbis encoding: Done." << llendl; | 499 | llinfos << "Vorbis encoding: Done." << llendl; |
496 | apr_file_close(outfp); | ||
497 | apr_file_close(infp); | ||
498 | 500 | ||
499 | #endif | 501 | #endif |
500 | return(LLVORBISENC_NOERR); | 502 | return(LLVORBISENC_NOERR); |