mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-09-18 17:20:57 +02:00
2016-08-02 Fred Gleason <fredg@paravelsystems.com>
* Added wav_chunk_test(1) in 'tests/wav_chunk_test/'.
This commit is contained in:
parent
a6066fe39a
commit
dac2f489c7
1
.gitignore
vendored
1
.gitignore
vendored
@ -82,6 +82,7 @@ tests/stringcode_test
|
|||||||
tests/test_pam
|
tests/test_pam
|
||||||
tests/timer_test
|
tests/timer_test
|
||||||
tests/upload_test
|
tests/upload_test
|
||||||
|
tests/wav_chunk_test
|
||||||
utils/rdhpiinfo/rdhpiinfo
|
utils/rdhpiinfo/rdhpiinfo
|
||||||
utils/rddgimport/rddgimport
|
utils/rddgimport/rddgimport
|
||||||
utils/rddiscimport/rddiscimport
|
utils/rddiscimport/rddiscimport
|
||||||
|
@ -15439,3 +15439,5 @@
|
|||||||
* Fixed a bug in 'rdadmin/createdb.cpp' that caused the
|
* Fixed a bug in 'rdadmin/createdb.cpp' that caused the
|
||||||
'SERVICE_CLOCKS' table to fail to be created when generating
|
'SERVICE_CLOCKS' table to fail to be created when generating
|
||||||
a new database.
|
a new database.
|
||||||
|
2016-08-02 Fred Gleason <fredg@paravelsystems.com>
|
||||||
|
* Added wav_chunk_test(1) in 'tests/wav_chunk_test/'.
|
||||||
|
@ -40,7 +40,8 @@ noinst_PROGRAMS = audio_convert_test\
|
|||||||
stringcode_test\
|
stringcode_test\
|
||||||
test_pam\
|
test_pam\
|
||||||
timer_test\
|
timer_test\
|
||||||
upload_test
|
upload_test\
|
||||||
|
wav_chunk_test
|
||||||
|
|
||||||
dist_audio_convert_test_SOURCES = audio_convert_test.cpp audio_convert_test.h
|
dist_audio_convert_test_SOURCES = audio_convert_test.cpp audio_convert_test.h
|
||||||
audio_convert_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@
|
audio_convert_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@
|
||||||
@ -81,10 +82,12 @@ dist_timer_test_SOURCES = timer_test.cpp timer_test.h
|
|||||||
nodist_timer_test_SOURCES = moc_timer_test.cpp
|
nodist_timer_test_SOURCES = moc_timer_test.cpp
|
||||||
timer_test_LDADD = -lqui
|
timer_test_LDADD = -lqui
|
||||||
|
|
||||||
|
|
||||||
dist_upload_test_SOURCES = upload_test.cpp upload_test.h
|
dist_upload_test_SOURCES = upload_test.cpp upload_test.h
|
||||||
upload_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@
|
upload_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@
|
||||||
|
|
||||||
|
dist_wav_chunk_test_SOURCES = wav_chunk_test.cpp wav_chunk_test.h
|
||||||
|
wav_chunk_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@
|
||||||
|
|
||||||
EXTRA_DIST = rivendell_standard.txt\
|
EXTRA_DIST = rivendell_standard.txt\
|
||||||
visualtraffic.txt
|
visualtraffic.txt
|
||||||
|
|
||||||
|
169
tests/wav_chunk_test.cpp
Normal file
169
tests/wav_chunk_test.cpp
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
// wav_chunk_test.cpp
|
||||||
|
//
|
||||||
|
// Test Rivendell file uploading.
|
||||||
|
//
|
||||||
|
// (C) Copyright 2010,2016 Fred Gleason <fredg@paravelsystems.com>
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License version 2 as
|
||||||
|
// published by the Free Software Foundation.
|
||||||
|
//
|
||||||
|
// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <qapplication.h>
|
||||||
|
|
||||||
|
#include <rdcmd_switch.h>
|
||||||
|
|
||||||
|
#include "wav_chunk_test.h"
|
||||||
|
|
||||||
|
MainObject::MainObject(QObject *parent)
|
||||||
|
:QObject(parent)
|
||||||
|
{
|
||||||
|
file_fd=-1;
|
||||||
|
payload_length=0;
|
||||||
|
chunk_length=0;
|
||||||
|
|
||||||
|
QString filename;
|
||||||
|
char buffer[1024];
|
||||||
|
|
||||||
|
//
|
||||||
|
// Read Command Options
|
||||||
|
//
|
||||||
|
RDCmdSwitch *cmd=
|
||||||
|
new RDCmdSwitch(qApp->argc(),qApp->argv(),"wav_chunk_test",
|
||||||
|
WAV_CHUNK_TEST_USAGE);
|
||||||
|
for(unsigned i=0;i<cmd->keys();i++) {
|
||||||
|
if(cmd->key(i)=="--filename") {
|
||||||
|
filename=cmd->value(i);
|
||||||
|
cmd->setProcessed(i,true);
|
||||||
|
}
|
||||||
|
if(!cmd->processed(i)) {
|
||||||
|
fprintf(stderr,"wav_chunk_test: invalid option\n");
|
||||||
|
exit(256);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(filename.isEmpty()) {
|
||||||
|
fprintf(stderr,"wav_chunk_test: missing filename\n");
|
||||||
|
exit(256);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Open File
|
||||||
|
//
|
||||||
|
if((file_fd=open(filename,O_RDONLY))<0) {
|
||||||
|
fprintf(stderr,"wav_chunk_test: unable to open file [%s]\n",
|
||||||
|
strerror(errno));
|
||||||
|
exit(256);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Get File Stats
|
||||||
|
//
|
||||||
|
struct stat stat;
|
||||||
|
memset(&stat,0,sizeof(stat));
|
||||||
|
if(fstat(file_fd,&stat)!=0) {
|
||||||
|
fprintf(stderr,"wav_chunk_test: unable to stat file [%s]\n",
|
||||||
|
strerror(errno));
|
||||||
|
exit(256);
|
||||||
|
}
|
||||||
|
file_length=stat.st_size;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Read Header
|
||||||
|
//
|
||||||
|
memset(buffer,0,1024);
|
||||||
|
if(read(file_fd,buffer,4)!=4) {
|
||||||
|
fprintf(stderr,"wav_chunk_test: file truncated\n");
|
||||||
|
exit(256);
|
||||||
|
}
|
||||||
|
if(strncmp(buffer,"RIFF",4)!=0) {
|
||||||
|
fprintf(stderr,"wav_chunk_test: not a RIFF file\n");
|
||||||
|
exit(256);
|
||||||
|
}
|
||||||
|
if(read(file_fd,buffer,4)!=4) {
|
||||||
|
fprintf(stderr,"wav_chunk_test: file truncated\n");
|
||||||
|
exit(256);
|
||||||
|
}
|
||||||
|
payload_length=((((uint32_t)buffer[3])&0xFF)<<24)+
|
||||||
|
((((uint32_t)buffer[2])&0xFF)<<16)+
|
||||||
|
((((uint32_t)buffer[1])&0xFF)<<8)+
|
||||||
|
((((uint32_t)buffer[0])&0xFF)<<0);
|
||||||
|
if(read(file_fd,buffer,4)!=4) {
|
||||||
|
fprintf(stderr,"wav_chunk_test: file truncated\n");
|
||||||
|
exit(256);
|
||||||
|
}
|
||||||
|
if(strncmp(buffer,"WAVE",4)!=0) {
|
||||||
|
fprintf(stderr,"wav_chunk_test: not a WAVE file\n");
|
||||||
|
exit(256);
|
||||||
|
}
|
||||||
|
printf(" File Length: %u\n",file_length);
|
||||||
|
printf(" Payload Length: %u\n",payload_length);
|
||||||
|
if(file_length!=(payload_length+8)) {
|
||||||
|
printf("WARNING: Payload and file sizes disagree!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Enumerate Chunks
|
||||||
|
//
|
||||||
|
QString name;
|
||||||
|
uint32_t start_pos;
|
||||||
|
while((start_pos=NextChunk(name,&chunk_length))>0) {
|
||||||
|
printf("Chunk: %s Start: %u Length: %u\n",(const char *)name,start_pos,chunk_length);
|
||||||
|
lseek(file_fd,chunk_length,SEEK_CUR);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Clean Up
|
||||||
|
//
|
||||||
|
close(file_fd);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t MainObject::NextChunk(QString &name,uint32_t *len)
|
||||||
|
{
|
||||||
|
char buffer[8];
|
||||||
|
uint32_t pos;
|
||||||
|
|
||||||
|
if((pos=lseek(file_fd,0,SEEK_CUR))>file_length) {
|
||||||
|
printf("WARNING: chunk size points beyond end of file!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(read(file_fd,buffer,8)!=8) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
*len=((((uint32_t)buffer[7])&0xFF)<<24)+
|
||||||
|
((((uint32_t)buffer[6])&0xFF)<<16)+
|
||||||
|
((((uint32_t)buffer[5])&0xFF)<<8)+
|
||||||
|
((((uint32_t)buffer[4])&0xFF)<<0);
|
||||||
|
buffer[4]=0;
|
||||||
|
name=buffer;
|
||||||
|
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc,char *argv[])
|
||||||
|
{
|
||||||
|
QApplication a(argc,argv,false);
|
||||||
|
new MainObject();
|
||||||
|
return a.exec();
|
||||||
|
}
|
44
tests/wav_chunk_test.h
Normal file
44
tests/wav_chunk_test.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// wav_chunk_test.h
|
||||||
|
//
|
||||||
|
// Check consistency of chunk layout in a WAV file
|
||||||
|
//
|
||||||
|
// (C) Copyright 2016 Fred Gleason <fredg@paravelsystems.com>
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License version 2 as
|
||||||
|
// published by the Free Software Foundation.
|
||||||
|
//
|
||||||
|
// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef WAV_CHUNK_TEST_H
|
||||||
|
#define WAV_CHUNK_TEST_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include <qobject.h>
|
||||||
|
|
||||||
|
#define WAV_CHUNK_TEST_USAGE "--filename=<filename>\n\n"
|
||||||
|
|
||||||
|
class MainObject : public QObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MainObject(QObject *parent=0);
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32_t NextChunk(QString &name,uint32_t *len);
|
||||||
|
int file_fd;
|
||||||
|
uint32_t file_length;
|
||||||
|
uint32_t payload_length;
|
||||||
|
uint32_t chunk_length;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // WAV_CHUNK_TEST_H
|
Loading…
x
Reference in New Issue
Block a user