[ previous ] [ next ] [ threads ]
 To :  yate@v...
 From :  Maciek Kaminski <maciejka@t...>
 Subject :  small bugs in wavefile.cpp
 Date :  Wed, 17 Aug 2005 13:16:31 +0200
This is a patch for two small bugs in wavefile.cpp.

Although first bug occurence posiibility is very low it may happen if 
wave source thread finishes before setNotify is called by chan.attach 
thread, it that case chan.notify wont be send at all.

Another problem is that chan.notify is not send if there are problems 
with opening sound files.

mk



Index: wavefile.cpp
===================================================================
RCS file: /home/cvsroot/private/yate/modules/wavefile.cpp,v
retrieving revision 1.33
diff -r1.33 wavefile.cpp
54a55
>     String m_file;
65a67
>   void init();
72a75
>     String m_file;
121c124
<       m_total(0), m_time(0), m_autoclose(autoclose)
---
>       m_total(0), m_time(0), m_file(file), m_autoclose(autoclose)
123,132c126,128
<     Debug(&__plugin,DebugAll,"WaveSource::WaveSource(\"%s\",%p) [%p]",file.c_str(),chan,this);
<     if (file == "-") {
< 	start("WaveSource");
< 	return;
<     }
<     m_fd = ::open(file.safe(),O_RDONLY|O_NOCTTY);
<     if (m_fd < 0) {
< 	Debug(DebugGoOn,"Opening '%s': error %d: %s",
< 	    file.c_str(), errno, ::strerror(errno));
< 	m_format.clear();
---
>     Debug(&__plugin,DebugAll,"WaveSource::WaveSource(\"%s\",%p) [%p]",m_file.c_str(),chan,this);
> 
>     if (m_file == "-") {
135c131
<     if (file.endsWith(".gsm")) {
---
>     if (m_file.endsWith(".gsm")) {
139c135
<     else if (file.endsWith(".alaw") || file.endsWith(".A")) {
---
>     else if (m_file.endsWith(".alaw") || m_file.endsWith(".A")) {
143c139
<     else if (file.endsWith(".mulaw") || file.endsWith(".u")) {
---
>     else if (m_file.endsWith(".mulaw") || m_file.endsWith(".u")) {
147c143
<     else if (file.endsWith(".au"))
---
>     else if (m_file.endsWith(".au"))
149c145
<     else if (file.endsWith(".wav"))
---
>     else if (m_file.endsWith(".wav"))
151,153c147,149
<     else if (!file.endsWith(".slin"))
< 	Debug(DebugMild,"Unknown format for file '%s', assuming signed linear",file.c_str());
<     start("WaveSource");
---
>     else if (!m_file.endsWith(".slin"))
> 	Debug(DebugMild,"Unknown format for m_file '%s', assuming signed linear", m_file.c_str());
> 
221a218,229
>     m_fd = ::open(m_file.safe(),O_RDONLY|O_NOCTTY);
>     if (m_fd < 0) {
> 	Debug(DebugGoOn,"Opening '%s': error %d: %s", m_file.c_str(), errno, ::strerror(errno));
> 	m_format.clear();
> 	if(!m_id.null()) {
> 	  Message *m = new Message("chan.notify");
> 	  m->addParam("targetid",m_id);
> 	  Engine::enqueue(m);
> 	}
> 	return;
>     }
> 
271c279
<     : m_chan(chan), m_fd(-1), m_total(0), m_maxlen(maxlen), m_time(0)
---
>   : m_chan(chan), m_fd(-1), m_total(0), m_maxlen(maxlen), m_time(0), m_file(file)
283,284c291,295
<     m_fd = ::creat(file.safe(),S_IRUSR|S_IWUSR);
<     if (m_fd < 0)
---
> }
> 
> void WaveConsumer::init() {
>     m_fd = ::creat(m_file.safe(),S_IRUSR|S_IWUSR);
>     if (m_fd < 0) {
286c297,303
< 	    file.c_str(), errno, ::strerror(errno));
---
> 	    m_file.c_str(), errno, ::strerror(errno));
> 	if(!m_id.null()) {
> 	  Message *m = new Message("chan.notify");
> 	  m->addParam("targetid",m_id);
> 	  Engine::enqueue(m);
> 	}
>     }
333a351
> 
339,342c357,361
< 	Message *m = new Message("chan.notify");
< 	m->addParam("targetid",m_id);
< 	m->userData(m_chan);
< 	Engine::enqueue(m);
---
> 	if(!m_id.null()) {
> 	  Message *m = new Message("chan.notify");
> 	  m->addParam("targetid",m_id);
> 	  Engine::enqueue(m);
> 	}
353,354c372,375
< 	setConsumer(new WaveConsumer(file,this,maxlen));
< 	getConsumer()->deref();
---
>       WaveConsumer *consumer = new WaveConsumer(file,this,maxlen);
>       consumer->init();
>       setConsumer(consumer);
>       consumer->deref();
357,358c378,381
< 	setSource(new WaveSource(file,this));
< 	getSource()->deref();
---
>       WaveSource *source = new WaveSource(file,this);
>       source->start("WaveSource");
>       setSource(source);
>       source->deref();
427a451
> 	s->start("WaveSource");
432a457
> 	c->init();
506a532
> 	c->init();
513a540
> 	c->init();