[Asterisk-Dev] Perl AGI + MySql Audio
Tim Mattison
tim at marocon.com
Tue Nov 23 17:50:47 MST 2004
[opinion on BLOBs]
I used to feel the same way about files in databases but have recently
changed my mind. One good reason to keep files in a database is
consistency. It's nice to have your database logic not have to fool
with external files and if a transaction fails the DB takes care of it
for you. It's not laziness, it's just a way to avoid reinventing the
wheel. I won't go into specifics but I deal with a project that
involves keeping binary data in a database and manipulating it. It
works really well and if something breaks I know my data stays
consistent no matter what. Transactions and replication being built
into the DB saved me a lot of development time. We also benefit from a
somewhat more finely grained security model than typical Unix UGO style
permissions doing things the way we do them.
Also, an intelligent database will store BLOBs efficiently. Maybe MySQL
isn't that smart but PostgreSQL does a great job of it.
[/opinion on BLOBs]
Unfortunately I'm not sure that using BLOBs makes complete sense in this
application but maybe I don't understand it fully. If you really want
to use large objects in a DB I highly recommend PostgreSQL. I think
that in order to do what you want to do you'll need to write your own
app_record that uses your database's native API. Well, at least I'd try
doing it that way to avoid as many intermediate steps as possible.
On Tue, 2004-11-23 at 14:56 -0600, Steven Critchfield wrote:
> On Tue, 2004-11-23 at 14:49 -0500, Darren Sessions wrote:
> > I know there is a patch you can get for MPG123 that lets it query a MySQL
> > database for audio files to play.
> >
> > Is there a way to have Asterisks internal WAV49 player grab the binary data
> > (of an audio file) from a blog field and play it without writing the audio
> > file to disk?
> >
> > Right now the way I do it, is once an audio file is created (lets say by
> > using record), an AGI script reads the contents of the wav49 file into a
> > variable and then dumps the contents of that variable into an blob field via
> > an sql insert.
> >
> > While this makes the AGI audio dynamic, it hammers the local hard drive.
> >
> > Any ideas? I think the concept is very sound (no pun intended), but my
> > experience with C is very limited and Perl AGI only lets you do so much.
> >
> > I realize you can't "stream" wav files, so it'd need to load the audio bin
> > contents into memory, then spit it out to whatever caller.
> >
> > Ideally, I think it would be nice to have something like this:
>
> All that message shows is that you don't understand the proper usage of
> a database. You really should do something like store the filename
> reference to the audio file in the database. Then your perl script can
> tell asterisk where the file is and tell it to stream it in place and
> not hammer your drive or your netork if the mysql DB is properly placed
> off of the asterisk machine.
>
> More of the example of why your DB skills aren't yet ready for the task
> is that mysql will get stupid slow as you store those blobs. Don't use a
> DB in place of a filesystem.
More information about the asterisk-dev
mailing list