2008-09-12 15:02:57 +02:00
|
|
|
/* the Music Player Daemon (MPD)
|
|
|
|
* Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
|
|
|
|
* This project's homepage is: http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* 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 "audioOutput_shout.h"
|
|
|
|
|
shout: introduce pluggable encoder API
I've perhaps gone a bit overboard, but here's the current rundown:
Both Ogg and MP3 use the "shout" audio output plugin. The shout audio
output plugin itself has two new plugins, one for the Ogg encoder,
and another for the MP3 (LAME) encoder.
Configuration for an Ogg stream doesn't change. For an MP3 stream,
configuration is the same as Ogg, with two exceptions. First, you must
specify the optional "encoding" parameter, which should be set to "mp3".
See mpd.conf(5) for more details. Second, the "quality" parameter is
reversed for LAME, such that 1 is high quality for LAME, whereas 10 is
high quality for Ogg.
I've decomposed the code so that all libshout related operations
are done in audioOutput_shout.c, all Ogg specific functions are in
audioOutput_shout_ogg.c, and of course then all LAME specific functions
are handled in audioOutput_shout_mp3.c.
To develop encoder plugins for the shout audio output plugin, I basically
just mimicked the plugin system used for audio outputs. This might be
overkill, but hopefully if anyone ever wants to support some other sort
of stream, like maybe AAC, FLAC, or WMA (hey it could happen), they will
hopefully be all set.
The Ogg encoder is slightly less optimal under this configuration.
It used to send shout data directly out of its ogg_page structures. Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin (see
audioOutput_shout_ogg.c, line 77.) I suspect the performance impact
is negligible.
As for metadata, I'm pretty sure they'll both work. I wrote up a test
scaffold that would create a fake tag, and tell the plugin to send it
out to the stream every few seconds. It seemed to work fine. Of course,
if something does break, I'll be glad to fix it.
Lastly, I've renamed lots of things into snake_case, in keeping with
normalperson's wishes in that regard.
[mk: moved the MP3 patch after this one. Splitted this patch into
several parts; the others were already applied before this one. Fixed
a bunch GCC warnings and wrong whitespace modifications. Made it
compile with mpd-mk by adapting to its prototypes]
2008-09-12 16:04:40 +02:00
|
|
|
#ifdef HAVE_SHOUT_OGG
|
2008-09-12 15:02:57 +02:00
|
|
|
|
|
|
|
#include "../utils.h"
|
shout: introduce pluggable encoder API
I've perhaps gone a bit overboard, but here's the current rundown:
Both Ogg and MP3 use the "shout" audio output plugin. The shout audio
output plugin itself has two new plugins, one for the Ogg encoder,
and another for the MP3 (LAME) encoder.
Configuration for an Ogg stream doesn't change. For an MP3 stream,
configuration is the same as Ogg, with two exceptions. First, you must
specify the optional "encoding" parameter, which should be set to "mp3".
See mpd.conf(5) for more details. Second, the "quality" parameter is
reversed for LAME, such that 1 is high quality for LAME, whereas 10 is
high quality for Ogg.
I've decomposed the code so that all libshout related operations
are done in audioOutput_shout.c, all Ogg specific functions are in
audioOutput_shout_ogg.c, and of course then all LAME specific functions
are handled in audioOutput_shout_mp3.c.
To develop encoder plugins for the shout audio output plugin, I basically
just mimicked the plugin system used for audio outputs. This might be
overkill, but hopefully if anyone ever wants to support some other sort
of stream, like maybe AAC, FLAC, or WMA (hey it could happen), they will
hopefully be all set.
The Ogg encoder is slightly less optimal under this configuration.
It used to send shout data directly out of its ogg_page structures. Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin (see
audioOutput_shout_ogg.c, line 77.) I suspect the performance impact
is negligible.
As for metadata, I'm pretty sure they'll both work. I wrote up a test
scaffold that would create a fake tag, and tell the plugin to send it
out to the stream every few seconds. It seemed to work fine. Of course,
if something does break, I'll be glad to fix it.
Lastly, I've renamed lots of things into snake_case, in keeping with
normalperson's wishes in that regard.
[mk: moved the MP3 patch after this one. Splitted this patch into
several parts; the others were already applied before this one. Fixed
a bunch GCC warnings and wrong whitespace modifications. Made it
compile with mpd-mk by adapting to its prototypes]
2008-09-12 16:04:40 +02:00
|
|
|
#include <vorbis/vorbisenc.h>
|
|
|
|
|
2008-09-12 16:38:54 +02:00
|
|
|
struct ogg_vorbis_data {
|
shout: introduce pluggable encoder API
I've perhaps gone a bit overboard, but here's the current rundown:
Both Ogg and MP3 use the "shout" audio output plugin. The shout audio
output plugin itself has two new plugins, one for the Ogg encoder,
and another for the MP3 (LAME) encoder.
Configuration for an Ogg stream doesn't change. For an MP3 stream,
configuration is the same as Ogg, with two exceptions. First, you must
specify the optional "encoding" parameter, which should be set to "mp3".
See mpd.conf(5) for more details. Second, the "quality" parameter is
reversed for LAME, such that 1 is high quality for LAME, whereas 10 is
high quality for Ogg.
I've decomposed the code so that all libshout related operations
are done in audioOutput_shout.c, all Ogg specific functions are in
audioOutput_shout_ogg.c, and of course then all LAME specific functions
are handled in audioOutput_shout_mp3.c.
To develop encoder plugins for the shout audio output plugin, I basically
just mimicked the plugin system used for audio outputs. This might be
overkill, but hopefully if anyone ever wants to support some other sort
of stream, like maybe AAC, FLAC, or WMA (hey it could happen), they will
hopefully be all set.
The Ogg encoder is slightly less optimal under this configuration.
It used to send shout data directly out of its ogg_page structures. Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin (see
audioOutput_shout_ogg.c, line 77.) I suspect the performance impact
is negligible.
As for metadata, I'm pretty sure they'll both work. I wrote up a test
scaffold that would create a fake tag, and tell the plugin to send it
out to the stream every few seconds. It seemed to work fine. Of course,
if something does break, I'll be glad to fix it.
Lastly, I've renamed lots of things into snake_case, in keeping with
normalperson's wishes in that regard.
[mk: moved the MP3 patch after this one. Splitted this patch into
several parts; the others were already applied before this one. Fixed
a bunch GCC warnings and wrong whitespace modifications. Made it
compile with mpd-mk by adapting to its prototypes]
2008-09-12 16:04:40 +02:00
|
|
|
ogg_stream_state os;
|
|
|
|
ogg_page og;
|
|
|
|
ogg_packet op;
|
|
|
|
ogg_packet header_main;
|
|
|
|
ogg_packet header_comments;
|
|
|
|
ogg_packet header_codebooks;
|
|
|
|
|
|
|
|
vorbis_dsp_state vd;
|
|
|
|
vorbis_block vb;
|
|
|
|
vorbis_info vi;
|
|
|
|
vorbis_comment vc;
|
2008-09-12 16:38:54 +02:00
|
|
|
};
|
2008-09-12 15:02:57 +02:00
|
|
|
|
2008-09-12 16:38:54 +02:00
|
|
|
static void add_tag(struct ogg_vorbis_data *od, const char *name, char *value)
|
2008-09-12 15:02:57 +02:00
|
|
|
{
|
|
|
|
if (value) {
|
2008-09-29 15:51:31 +02:00
|
|
|
union {
|
|
|
|
const char *in;
|
|
|
|
char *out;
|
|
|
|
} u = { .in = name };
|
2008-09-12 15:59:55 +02:00
|
|
|
vorbis_comment_add_tag(&od->vc, u.out, value);
|
2008-09-12 15:02:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
shout: introduce pluggable encoder API
I've perhaps gone a bit overboard, but here's the current rundown:
Both Ogg and MP3 use the "shout" audio output plugin. The shout audio
output plugin itself has two new plugins, one for the Ogg encoder,
and another for the MP3 (LAME) encoder.
Configuration for an Ogg stream doesn't change. For an MP3 stream,
configuration is the same as Ogg, with two exceptions. First, you must
specify the optional "encoding" parameter, which should be set to "mp3".
See mpd.conf(5) for more details. Second, the "quality" parameter is
reversed for LAME, such that 1 is high quality for LAME, whereas 10 is
high quality for Ogg.
I've decomposed the code so that all libshout related operations
are done in audioOutput_shout.c, all Ogg specific functions are in
audioOutput_shout_ogg.c, and of course then all LAME specific functions
are handled in audioOutput_shout_mp3.c.
To develop encoder plugins for the shout audio output plugin, I basically
just mimicked the plugin system used for audio outputs. This might be
overkill, but hopefully if anyone ever wants to support some other sort
of stream, like maybe AAC, FLAC, or WMA (hey it could happen), they will
hopefully be all set.
The Ogg encoder is slightly less optimal under this configuration.
It used to send shout data directly out of its ogg_page structures. Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin (see
audioOutput_shout_ogg.c, line 77.) I suspect the performance impact
is negligible.
As for metadata, I'm pretty sure they'll both work. I wrote up a test
scaffold that would create a fake tag, and tell the plugin to send it
out to the stream every few seconds. It seemed to work fine. Of course,
if something does break, I'll be glad to fix it.
Lastly, I've renamed lots of things into snake_case, in keeping with
normalperson's wishes in that regard.
[mk: moved the MP3 patch after this one. Splitted this patch into
several parts; the others were already applied before this one. Fixed
a bunch GCC warnings and wrong whitespace modifications. Made it
compile with mpd-mk by adapting to its prototypes]
2008-09-12 16:04:40 +02:00
|
|
|
static void copy_tag_to_vorbis_comment(struct shout_data *sd)
|
2008-09-12 15:02:57 +02:00
|
|
|
{
|
2008-09-12 16:38:54 +02:00
|
|
|
struct ogg_vorbis_data *od = (struct ogg_vorbis_data *)sd->encoder_data;
|
2008-09-12 15:59:55 +02:00
|
|
|
|
2008-09-12 15:02:57 +02:00
|
|
|
if (sd->tag) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sd->tag->numOfItems; i++) {
|
|
|
|
switch (sd->tag->items[i]->type) {
|
|
|
|
case TAG_ITEM_ARTIST:
|
2008-09-12 15:59:55 +02:00
|
|
|
add_tag(od, "ARTIST", sd->tag->items[i]->value);
|
2008-09-12 15:02:57 +02:00
|
|
|
break;
|
|
|
|
case TAG_ITEM_ALBUM:
|
2008-09-12 15:59:55 +02:00
|
|
|
add_tag(od, "ALBUM", sd->tag->items[i]->value);
|
2008-09-12 15:02:57 +02:00
|
|
|
break;
|
|
|
|
case TAG_ITEM_TITLE:
|
2008-09-12 15:59:55 +02:00
|
|
|
add_tag(od, "TITLE", sd->tag->items[i]->value);
|
2008-09-12 15:02:57 +02:00
|
|
|
break;
|
shout: introduce pluggable encoder API
I've perhaps gone a bit overboard, but here's the current rundown:
Both Ogg and MP3 use the "shout" audio output plugin. The shout audio
output plugin itself has two new plugins, one for the Ogg encoder,
and another for the MP3 (LAME) encoder.
Configuration for an Ogg stream doesn't change. For an MP3 stream,
configuration is the same as Ogg, with two exceptions. First, you must
specify the optional "encoding" parameter, which should be set to "mp3".
See mpd.conf(5) for more details. Second, the "quality" parameter is
reversed for LAME, such that 1 is high quality for LAME, whereas 10 is
high quality for Ogg.
I've decomposed the code so that all libshout related operations
are done in audioOutput_shout.c, all Ogg specific functions are in
audioOutput_shout_ogg.c, and of course then all LAME specific functions
are handled in audioOutput_shout_mp3.c.
To develop encoder plugins for the shout audio output plugin, I basically
just mimicked the plugin system used for audio outputs. This might be
overkill, but hopefully if anyone ever wants to support some other sort
of stream, like maybe AAC, FLAC, or WMA (hey it could happen), they will
hopefully be all set.
The Ogg encoder is slightly less optimal under this configuration.
It used to send shout data directly out of its ogg_page structures. Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin (see
audioOutput_shout_ogg.c, line 77.) I suspect the performance impact
is negligible.
As for metadata, I'm pretty sure they'll both work. I wrote up a test
scaffold that would create a fake tag, and tell the plugin to send it
out to the stream every few seconds. It seemed to work fine. Of course,
if something does break, I'll be glad to fix it.
Lastly, I've renamed lots of things into snake_case, in keeping with
normalperson's wishes in that regard.
[mk: moved the MP3 patch after this one. Splitted this patch into
several parts; the others were already applied before this one. Fixed
a bunch GCC warnings and wrong whitespace modifications. Made it
compile with mpd-mk by adapting to its prototypes]
2008-09-12 16:04:40 +02:00
|
|
|
|
2008-09-12 15:02:57 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-12 15:57:43 +02:00
|
|
|
static int copy_ogg_buffer_to_shout_buffer(ogg_page *og,
|
2008-09-12 16:38:54 +02:00
|
|
|
struct shout_buffer *buf)
|
2008-09-12 15:57:43 +02:00
|
|
|
{
|
2008-09-12 16:41:20 +02:00
|
|
|
if (sizeof(buf->data) - buf->len >= (size_t)og->header_len) {
|
2008-09-12 15:57:43 +02:00
|
|
|
memcpy(buf->data + buf->len,
|
|
|
|
og->header, og->header_len);
|
|
|
|
buf->len += og->header_len;
|
|
|
|
} else {
|
|
|
|
ERROR("%s: not enough buffer space!\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-09-12 16:41:20 +02:00
|
|
|
if (sizeof(buf->data) - buf->len >= (size_t)og->body_len) {
|
2008-09-12 15:57:43 +02:00
|
|
|
memcpy(buf->data + buf->len,
|
|
|
|
og->body, og->body_len);
|
|
|
|
buf->len += og->body_len;
|
|
|
|
} else {
|
|
|
|
ERROR("%s: not enough buffer space!\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int flush_ogg_buffer(struct shout_data *sd)
|
|
|
|
{
|
2008-09-12 16:38:54 +02:00
|
|
|
struct shout_buffer *buf = &sd->buf;
|
|
|
|
struct ogg_vorbis_data *od = (struct ogg_vorbis_data *)sd->encoder_data;
|
2008-09-12 15:57:43 +02:00
|
|
|
int ret = 0;
|
|
|
|
|
2008-09-12 15:59:55 +02:00
|
|
|
if (ogg_stream_flush(&od->os, &od->og))
|
|
|
|
ret = copy_ogg_buffer_to_shout_buffer(&od->og, buf);
|
2008-09-12 15:57:43 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
shout: introduce pluggable encoder API
I've perhaps gone a bit overboard, but here's the current rundown:
Both Ogg and MP3 use the "shout" audio output plugin. The shout audio
output plugin itself has two new plugins, one for the Ogg encoder,
and another for the MP3 (LAME) encoder.
Configuration for an Ogg stream doesn't change. For an MP3 stream,
configuration is the same as Ogg, with two exceptions. First, you must
specify the optional "encoding" parameter, which should be set to "mp3".
See mpd.conf(5) for more details. Second, the "quality" parameter is
reversed for LAME, such that 1 is high quality for LAME, whereas 10 is
high quality for Ogg.
I've decomposed the code so that all libshout related operations
are done in audioOutput_shout.c, all Ogg specific functions are in
audioOutput_shout_ogg.c, and of course then all LAME specific functions
are handled in audioOutput_shout_mp3.c.
To develop encoder plugins for the shout audio output plugin, I basically
just mimicked the plugin system used for audio outputs. This might be
overkill, but hopefully if anyone ever wants to support some other sort
of stream, like maybe AAC, FLAC, or WMA (hey it could happen), they will
hopefully be all set.
The Ogg encoder is slightly less optimal under this configuration.
It used to send shout data directly out of its ogg_page structures. Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin (see
audioOutput_shout_ogg.c, line 77.) I suspect the performance impact
is negligible.
As for metadata, I'm pretty sure they'll both work. I wrote up a test
scaffold that would create a fake tag, and tell the plugin to send it
out to the stream every few seconds. It seemed to work fine. Of course,
if something does break, I'll be glad to fix it.
Lastly, I've renamed lots of things into snake_case, in keeping with
normalperson's wishes in that regard.
[mk: moved the MP3 patch after this one. Splitted this patch into
several parts; the others were already applied before this one. Fixed
a bunch GCC warnings and wrong whitespace modifications. Made it
compile with mpd-mk by adapting to its prototypes]
2008-09-12 16:04:40 +02:00
|
|
|
static int send_ogg_vorbis_header(struct shout_data *sd)
|
2008-09-12 15:02:57 +02:00
|
|
|
{
|
2008-09-12 16:38:54 +02:00
|
|
|
struct ogg_vorbis_data *od = (struct ogg_vorbis_data *)sd->encoder_data;
|
2008-09-12 15:59:55 +02:00
|
|
|
|
|
|
|
vorbis_analysis_headerout(&od->vd, &od->vc,
|
|
|
|
&od->header_main,
|
|
|
|
&od->header_comments,
|
|
|
|
&od->header_codebooks);
|
2008-09-12 15:02:57 +02:00
|
|
|
|
2008-09-12 15:59:55 +02:00
|
|
|
ogg_stream_packetin(&od->os, &od->header_main);
|
|
|
|
ogg_stream_packetin(&od->os, &od->header_comments);
|
|
|
|
ogg_stream_packetin(&od->os, &od->header_codebooks);
|
2008-09-12 15:57:43 +02:00
|
|
|
|
|
|
|
return flush_ogg_buffer(sd);
|
2008-09-12 15:02:57 +02:00
|
|
|
}
|
|
|
|
|
2008-09-12 16:38:54 +02:00
|
|
|
static void finish_encoder(struct ogg_vorbis_data *od)
|
2008-09-12 15:02:57 +02:00
|
|
|
{
|
2008-09-12 15:59:55 +02:00
|
|
|
vorbis_analysis_wrote(&od->vd, 0);
|
2008-09-12 15:02:57 +02:00
|
|
|
|
2008-09-12 15:59:55 +02:00
|
|
|
while (vorbis_analysis_blockout(&od->vd, &od->vb) == 1) {
|
|
|
|
vorbis_analysis(&od->vb, NULL);
|
|
|
|
vorbis_bitrate_addblock(&od->vb);
|
|
|
|
while (vorbis_bitrate_flushpacket(&od->vd, &od->op)) {
|
|
|
|
ogg_stream_packetin(&od->os, &od->op);
|
2008-09-12 15:02:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
shout: introduce pluggable encoder API
I've perhaps gone a bit overboard, but here's the current rundown:
Both Ogg and MP3 use the "shout" audio output plugin. The shout audio
output plugin itself has two new plugins, one for the Ogg encoder,
and another for the MP3 (LAME) encoder.
Configuration for an Ogg stream doesn't change. For an MP3 stream,
configuration is the same as Ogg, with two exceptions. First, you must
specify the optional "encoding" parameter, which should be set to "mp3".
See mpd.conf(5) for more details. Second, the "quality" parameter is
reversed for LAME, such that 1 is high quality for LAME, whereas 10 is
high quality for Ogg.
I've decomposed the code so that all libshout related operations
are done in audioOutput_shout.c, all Ogg specific functions are in
audioOutput_shout_ogg.c, and of course then all LAME specific functions
are handled in audioOutput_shout_mp3.c.
To develop encoder plugins for the shout audio output plugin, I basically
just mimicked the plugin system used for audio outputs. This might be
overkill, but hopefully if anyone ever wants to support some other sort
of stream, like maybe AAC, FLAC, or WMA (hey it could happen), they will
hopefully be all set.
The Ogg encoder is slightly less optimal under this configuration.
It used to send shout data directly out of its ogg_page structures. Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin (see
audioOutput_shout_ogg.c, line 77.) I suspect the performance impact
is negligible.
As for metadata, I'm pretty sure they'll both work. I wrote up a test
scaffold that would create a fake tag, and tell the plugin to send it
out to the stream every few seconds. It seemed to work fine. Of course,
if something does break, I'll be glad to fix it.
Lastly, I've renamed lots of things into snake_case, in keeping with
normalperson's wishes in that regard.
[mk: moved the MP3 patch after this one. Splitted this patch into
several parts; the others were already applied before this one. Fixed
a bunch GCC warnings and wrong whitespace modifications. Made it
compile with mpd-mk by adapting to its prototypes]
2008-09-12 16:04:40 +02:00
|
|
|
static int shout_ogg_encoder_clear_encoder(struct shout_data *sd)
|
2008-09-12 15:02:57 +02:00
|
|
|
{
|
2008-09-12 16:38:54 +02:00
|
|
|
struct ogg_vorbis_data *od = (struct ogg_vorbis_data *)sd->encoder_data;
|
2008-09-12 15:57:43 +02:00
|
|
|
int ret;
|
2008-09-12 15:02:57 +02:00
|
|
|
|
2008-09-12 15:59:55 +02:00
|
|
|
finish_encoder(od);
|
|
|
|
if ((ret = ogg_stream_pageout(&od->os, &od->og)))
|
|
|
|
copy_ogg_buffer_to_shout_buffer(&od->og, &sd->buf);
|
2008-09-12 15:02:57 +02:00
|
|
|
|
2008-09-12 15:59:55 +02:00
|
|
|
vorbis_comment_clear(&od->vc);
|
|
|
|
ogg_stream_clear(&od->os);
|
|
|
|
vorbis_block_clear(&od->vb);
|
|
|
|
vorbis_dsp_clear(&od->vd);
|
|
|
|
vorbis_info_clear(&od->vi);
|
2008-09-12 15:57:43 +02:00
|
|
|
|
|
|
|
return ret;
|
2008-09-12 15:02:57 +02:00
|
|
|
}
|
|
|
|
|
shout: introduce pluggable encoder API
I've perhaps gone a bit overboard, but here's the current rundown:
Both Ogg and MP3 use the "shout" audio output plugin. The shout audio
output plugin itself has two new plugins, one for the Ogg encoder,
and another for the MP3 (LAME) encoder.
Configuration for an Ogg stream doesn't change. For an MP3 stream,
configuration is the same as Ogg, with two exceptions. First, you must
specify the optional "encoding" parameter, which should be set to "mp3".
See mpd.conf(5) for more details. Second, the "quality" parameter is
reversed for LAME, such that 1 is high quality for LAME, whereas 10 is
high quality for Ogg.
I've decomposed the code so that all libshout related operations
are done in audioOutput_shout.c, all Ogg specific functions are in
audioOutput_shout_ogg.c, and of course then all LAME specific functions
are handled in audioOutput_shout_mp3.c.
To develop encoder plugins for the shout audio output plugin, I basically
just mimicked the plugin system used for audio outputs. This might be
overkill, but hopefully if anyone ever wants to support some other sort
of stream, like maybe AAC, FLAC, or WMA (hey it could happen), they will
hopefully be all set.
The Ogg encoder is slightly less optimal under this configuration.
It used to send shout data directly out of its ogg_page structures. Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin (see
audioOutput_shout_ogg.c, line 77.) I suspect the performance impact
is negligible.
As for metadata, I'm pretty sure they'll both work. I wrote up a test
scaffold that would create a fake tag, and tell the plugin to send it
out to the stream every few seconds. It seemed to work fine. Of course,
if something does break, I'll be glad to fix it.
Lastly, I've renamed lots of things into snake_case, in keeping with
normalperson's wishes in that regard.
[mk: moved the MP3 patch after this one. Splitted this patch into
several parts; the others were already applied before this one. Fixed
a bunch GCC warnings and wrong whitespace modifications. Made it
compile with mpd-mk by adapting to its prototypes]
2008-09-12 16:04:40 +02:00
|
|
|
static void shout_ogg_encoder_finish(struct shout_data *sd)
|
|
|
|
{
|
2008-09-12 16:38:54 +02:00
|
|
|
struct ogg_vorbis_data *od = (struct ogg_vorbis_data *)sd->encoder_data;
|
shout: introduce pluggable encoder API
I've perhaps gone a bit overboard, but here's the current rundown:
Both Ogg and MP3 use the "shout" audio output plugin. The shout audio
output plugin itself has two new plugins, one for the Ogg encoder,
and another for the MP3 (LAME) encoder.
Configuration for an Ogg stream doesn't change. For an MP3 stream,
configuration is the same as Ogg, with two exceptions. First, you must
specify the optional "encoding" parameter, which should be set to "mp3".
See mpd.conf(5) for more details. Second, the "quality" parameter is
reversed for LAME, such that 1 is high quality for LAME, whereas 10 is
high quality for Ogg.
I've decomposed the code so that all libshout related operations
are done in audioOutput_shout.c, all Ogg specific functions are in
audioOutput_shout_ogg.c, and of course then all LAME specific functions
are handled in audioOutput_shout_mp3.c.
To develop encoder plugins for the shout audio output plugin, I basically
just mimicked the plugin system used for audio outputs. This might be
overkill, but hopefully if anyone ever wants to support some other sort
of stream, like maybe AAC, FLAC, or WMA (hey it could happen), they will
hopefully be all set.
The Ogg encoder is slightly less optimal under this configuration.
It used to send shout data directly out of its ogg_page structures. Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin (see
audioOutput_shout_ogg.c, line 77.) I suspect the performance impact
is negligible.
As for metadata, I'm pretty sure they'll both work. I wrote up a test
scaffold that would create a fake tag, and tell the plugin to send it
out to the stream every few seconds. It seemed to work fine. Of course,
if something does break, I'll be glad to fix it.
Lastly, I've renamed lots of things into snake_case, in keeping with
normalperson's wishes in that regard.
[mk: moved the MP3 patch after this one. Splitted this patch into
several parts; the others were already applied before this one. Fixed
a bunch GCC warnings and wrong whitespace modifications. Made it
compile with mpd-mk by adapting to its prototypes]
2008-09-12 16:04:40 +02:00
|
|
|
|
|
|
|
if (od) {
|
|
|
|
free(od);
|
|
|
|
sd->encoder_data = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int shout_ogg_encoder_init(struct shout_data *sd)
|
|
|
|
{
|
2008-09-12 16:38:54 +02:00
|
|
|
struct ogg_vorbis_data *od;
|
shout: introduce pluggable encoder API
I've perhaps gone a bit overboard, but here's the current rundown:
Both Ogg and MP3 use the "shout" audio output plugin. The shout audio
output plugin itself has two new plugins, one for the Ogg encoder,
and another for the MP3 (LAME) encoder.
Configuration for an Ogg stream doesn't change. For an MP3 stream,
configuration is the same as Ogg, with two exceptions. First, you must
specify the optional "encoding" parameter, which should be set to "mp3".
See mpd.conf(5) for more details. Second, the "quality" parameter is
reversed for LAME, such that 1 is high quality for LAME, whereas 10 is
high quality for Ogg.
I've decomposed the code so that all libshout related operations
are done in audioOutput_shout.c, all Ogg specific functions are in
audioOutput_shout_ogg.c, and of course then all LAME specific functions
are handled in audioOutput_shout_mp3.c.
To develop encoder plugins for the shout audio output plugin, I basically
just mimicked the plugin system used for audio outputs. This might be
overkill, but hopefully if anyone ever wants to support some other sort
of stream, like maybe AAC, FLAC, or WMA (hey it could happen), they will
hopefully be all set.
The Ogg encoder is slightly less optimal under this configuration.
It used to send shout data directly out of its ogg_page structures. Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin (see
audioOutput_shout_ogg.c, line 77.) I suspect the performance impact
is negligible.
As for metadata, I'm pretty sure they'll both work. I wrote up a test
scaffold that would create a fake tag, and tell the plugin to send it
out to the stream every few seconds. It seemed to work fine. Of course,
if something does break, I'll be glad to fix it.
Lastly, I've renamed lots of things into snake_case, in keeping with
normalperson's wishes in that regard.
[mk: moved the MP3 patch after this one. Splitted this patch into
several parts; the others were already applied before this one. Fixed
a bunch GCC warnings and wrong whitespace modifications. Made it
compile with mpd-mk by adapting to its prototypes]
2008-09-12 16:04:40 +02:00
|
|
|
|
2008-09-12 16:38:54 +02:00
|
|
|
if (NULL == (od = xmalloc(sizeof(*od))))
|
shout: introduce pluggable encoder API
I've perhaps gone a bit overboard, but here's the current rundown:
Both Ogg and MP3 use the "shout" audio output plugin. The shout audio
output plugin itself has two new plugins, one for the Ogg encoder,
and another for the MP3 (LAME) encoder.
Configuration for an Ogg stream doesn't change. For an MP3 stream,
configuration is the same as Ogg, with two exceptions. First, you must
specify the optional "encoding" parameter, which should be set to "mp3".
See mpd.conf(5) for more details. Second, the "quality" parameter is
reversed for LAME, such that 1 is high quality for LAME, whereas 10 is
high quality for Ogg.
I've decomposed the code so that all libshout related operations
are done in audioOutput_shout.c, all Ogg specific functions are in
audioOutput_shout_ogg.c, and of course then all LAME specific functions
are handled in audioOutput_shout_mp3.c.
To develop encoder plugins for the shout audio output plugin, I basically
just mimicked the plugin system used for audio outputs. This might be
overkill, but hopefully if anyone ever wants to support some other sort
of stream, like maybe AAC, FLAC, or WMA (hey it could happen), they will
hopefully be all set.
The Ogg encoder is slightly less optimal under this configuration.
It used to send shout data directly out of its ogg_page structures. Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin (see
audioOutput_shout_ogg.c, line 77.) I suspect the performance impact
is negligible.
As for metadata, I'm pretty sure they'll both work. I wrote up a test
scaffold that would create a fake tag, and tell the plugin to send it
out to the stream every few seconds. It seemed to work fine. Of course,
if something does break, I'll be glad to fix it.
Lastly, I've renamed lots of things into snake_case, in keeping with
normalperson's wishes in that regard.
[mk: moved the MP3 patch after this one. Splitted this patch into
several parts; the others were already applied before this one. Fixed
a bunch GCC warnings and wrong whitespace modifications. Made it
compile with mpd-mk by adapting to its prototypes]
2008-09-12 16:04:40 +02:00
|
|
|
FATAL("error initializing ogg vorbis encoder data\n");
|
|
|
|
sd->encoder_data = od;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-12 15:57:43 +02:00
|
|
|
static int reinit_encoder(struct shout_data *sd)
|
2008-09-12 15:02:57 +02:00
|
|
|
{
|
2008-09-12 16:38:54 +02:00
|
|
|
struct ogg_vorbis_data *od = (struct ogg_vorbis_data *)sd->encoder_data;
|
2008-09-12 15:59:55 +02:00
|
|
|
|
|
|
|
vorbis_info_init(&od->vi);
|
2008-09-12 15:02:57 +02:00
|
|
|
|
|
|
|
if (sd->quality >= -1.0) {
|
2008-09-12 15:59:55 +02:00
|
|
|
if (0 != vorbis_encode_init_vbr(&od->vi,
|
2008-09-12 15:02:57 +02:00
|
|
|
sd->audio_format.channels,
|
2008-10-10 14:40:54 +02:00
|
|
|
sd->audio_format.sample_rate,
|
2008-09-12 15:02:57 +02:00
|
|
|
sd->quality * 0.1)) {
|
shout: introduce pluggable encoder API
I've perhaps gone a bit overboard, but here's the current rundown:
Both Ogg and MP3 use the "shout" audio output plugin. The shout audio
output plugin itself has two new plugins, one for the Ogg encoder,
and another for the MP3 (LAME) encoder.
Configuration for an Ogg stream doesn't change. For an MP3 stream,
configuration is the same as Ogg, with two exceptions. First, you must
specify the optional "encoding" parameter, which should be set to "mp3".
See mpd.conf(5) for more details. Second, the "quality" parameter is
reversed for LAME, such that 1 is high quality for LAME, whereas 10 is
high quality for Ogg.
I've decomposed the code so that all libshout related operations
are done in audioOutput_shout.c, all Ogg specific functions are in
audioOutput_shout_ogg.c, and of course then all LAME specific functions
are handled in audioOutput_shout_mp3.c.
To develop encoder plugins for the shout audio output plugin, I basically
just mimicked the plugin system used for audio outputs. This might be
overkill, but hopefully if anyone ever wants to support some other sort
of stream, like maybe AAC, FLAC, or WMA (hey it could happen), they will
hopefully be all set.
The Ogg encoder is slightly less optimal under this configuration.
It used to send shout data directly out of its ogg_page structures. Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin (see
audioOutput_shout_ogg.c, line 77.) I suspect the performance impact
is negligible.
As for metadata, I'm pretty sure they'll both work. I wrote up a test
scaffold that would create a fake tag, and tell the plugin to send it
out to the stream every few seconds. It seemed to work fine. Of course,
if something does break, I'll be glad to fix it.
Lastly, I've renamed lots of things into snake_case, in keeping with
normalperson's wishes in that regard.
[mk: moved the MP3 patch after this one. Splitted this patch into
several parts; the others were already applied before this one. Fixed
a bunch GCC warnings and wrong whitespace modifications. Made it
compile with mpd-mk by adapting to its prototypes]
2008-09-12 16:04:40 +02:00
|
|
|
ERROR("error initializing vorbis vbr\n");
|
2008-09-12 15:59:55 +02:00
|
|
|
vorbis_info_clear(&od->vi);
|
2008-09-12 15:02:57 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2008-09-12 15:59:55 +02:00
|
|
|
if (0 != vorbis_encode_init(&od->vi,
|
2008-09-12 15:02:57 +02:00
|
|
|
sd->audio_format.channels,
|
2008-10-10 14:40:54 +02:00
|
|
|
sd->audio_format.sample_rate, -1.0,
|
2008-09-12 15:02:57 +02:00
|
|
|
sd->bitrate * 1000, -1.0)) {
|
shout: introduce pluggable encoder API
I've perhaps gone a bit overboard, but here's the current rundown:
Both Ogg and MP3 use the "shout" audio output plugin. The shout audio
output plugin itself has two new plugins, one for the Ogg encoder,
and another for the MP3 (LAME) encoder.
Configuration for an Ogg stream doesn't change. For an MP3 stream,
configuration is the same as Ogg, with two exceptions. First, you must
specify the optional "encoding" parameter, which should be set to "mp3".
See mpd.conf(5) for more details. Second, the "quality" parameter is
reversed for LAME, such that 1 is high quality for LAME, whereas 10 is
high quality for Ogg.
I've decomposed the code so that all libshout related operations
are done in audioOutput_shout.c, all Ogg specific functions are in
audioOutput_shout_ogg.c, and of course then all LAME specific functions
are handled in audioOutput_shout_mp3.c.
To develop encoder plugins for the shout audio output plugin, I basically
just mimicked the plugin system used for audio outputs. This might be
overkill, but hopefully if anyone ever wants to support some other sort
of stream, like maybe AAC, FLAC, or WMA (hey it could happen), they will
hopefully be all set.
The Ogg encoder is slightly less optimal under this configuration.
It used to send shout data directly out of its ogg_page structures. Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin (see
audioOutput_shout_ogg.c, line 77.) I suspect the performance impact
is negligible.
As for metadata, I'm pretty sure they'll both work. I wrote up a test
scaffold that would create a fake tag, and tell the plugin to send it
out to the stream every few seconds. It seemed to work fine. Of course,
if something does break, I'll be glad to fix it.
Lastly, I've renamed lots of things into snake_case, in keeping with
normalperson's wishes in that regard.
[mk: moved the MP3 patch after this one. Splitted this patch into
several parts; the others were already applied before this one. Fixed
a bunch GCC warnings and wrong whitespace modifications. Made it
compile with mpd-mk by adapting to its prototypes]
2008-09-12 16:04:40 +02:00
|
|
|
ERROR("error initializing vorbis encoder\n");
|
2008-09-12 15:59:55 +02:00
|
|
|
vorbis_info_clear(&od->vi);
|
2008-09-12 15:02:57 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-12 15:59:55 +02:00
|
|
|
vorbis_analysis_init(&od->vd, &od->vi);
|
|
|
|
vorbis_block_init(&od->vd, &od->vb);
|
|
|
|
ogg_stream_init(&od->os, rand());
|
|
|
|
vorbis_comment_init(&od->vc);
|
2008-09-12 15:02:57 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
shout: introduce pluggable encoder API
I've perhaps gone a bit overboard, but here's the current rundown:
Both Ogg and MP3 use the "shout" audio output plugin. The shout audio
output plugin itself has two new plugins, one for the Ogg encoder,
and another for the MP3 (LAME) encoder.
Configuration for an Ogg stream doesn't change. For an MP3 stream,
configuration is the same as Ogg, with two exceptions. First, you must
specify the optional "encoding" parameter, which should be set to "mp3".
See mpd.conf(5) for more details. Second, the "quality" parameter is
reversed for LAME, such that 1 is high quality for LAME, whereas 10 is
high quality for Ogg.
I've decomposed the code so that all libshout related operations
are done in audioOutput_shout.c, all Ogg specific functions are in
audioOutput_shout_ogg.c, and of course then all LAME specific functions
are handled in audioOutput_shout_mp3.c.
To develop encoder plugins for the shout audio output plugin, I basically
just mimicked the plugin system used for audio outputs. This might be
overkill, but hopefully if anyone ever wants to support some other sort
of stream, like maybe AAC, FLAC, or WMA (hey it could happen), they will
hopefully be all set.
The Ogg encoder is slightly less optimal under this configuration.
It used to send shout data directly out of its ogg_page structures. Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin (see
audioOutput_shout_ogg.c, line 77.) I suspect the performance impact
is negligible.
As for metadata, I'm pretty sure they'll both work. I wrote up a test
scaffold that would create a fake tag, and tell the plugin to send it
out to the stream every few seconds. It seemed to work fine. Of course,
if something does break, I'll be glad to fix it.
Lastly, I've renamed lots of things into snake_case, in keeping with
normalperson's wishes in that regard.
[mk: moved the MP3 patch after this one. Splitted this patch into
several parts; the others were already applied before this one. Fixed
a bunch GCC warnings and wrong whitespace modifications. Made it
compile with mpd-mk by adapting to its prototypes]
2008-09-12 16:04:40 +02:00
|
|
|
static int shout_ogg_encoder_init_encoder(struct shout_data *sd)
|
2008-09-12 15:57:43 +02:00
|
|
|
{
|
|
|
|
if (reinit_encoder(sd))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (send_ogg_vorbis_header(sd)) {
|
|
|
|
ERROR("error sending ogg vorbis header for shout\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
shout: introduce pluggable encoder API
I've perhaps gone a bit overboard, but here's the current rundown:
Both Ogg and MP3 use the "shout" audio output plugin. The shout audio
output plugin itself has two new plugins, one for the Ogg encoder,
and another for the MP3 (LAME) encoder.
Configuration for an Ogg stream doesn't change. For an MP3 stream,
configuration is the same as Ogg, with two exceptions. First, you must
specify the optional "encoding" parameter, which should be set to "mp3".
See mpd.conf(5) for more details. Second, the "quality" parameter is
reversed for LAME, such that 1 is high quality for LAME, whereas 10 is
high quality for Ogg.
I've decomposed the code so that all libshout related operations
are done in audioOutput_shout.c, all Ogg specific functions are in
audioOutput_shout_ogg.c, and of course then all LAME specific functions
are handled in audioOutput_shout_mp3.c.
To develop encoder plugins for the shout audio output plugin, I basically
just mimicked the plugin system used for audio outputs. This might be
overkill, but hopefully if anyone ever wants to support some other sort
of stream, like maybe AAC, FLAC, or WMA (hey it could happen), they will
hopefully be all set.
The Ogg encoder is slightly less optimal under this configuration.
It used to send shout data directly out of its ogg_page structures. Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin (see
audioOutput_shout_ogg.c, line 77.) I suspect the performance impact
is negligible.
As for metadata, I'm pretty sure they'll both work. I wrote up a test
scaffold that would create a fake tag, and tell the plugin to send it
out to the stream every few seconds. It seemed to work fine. Of course,
if something does break, I'll be glad to fix it.
Lastly, I've renamed lots of things into snake_case, in keeping with
normalperson's wishes in that regard.
[mk: moved the MP3 patch after this one. Splitted this patch into
several parts; the others were already applied before this one. Fixed
a bunch GCC warnings and wrong whitespace modifications. Made it
compile with mpd-mk by adapting to its prototypes]
2008-09-12 16:04:40 +02:00
|
|
|
static int shout_ogg_encoder_send_metadata(struct shout_data *sd,
|
|
|
|
mpd_unused char * song,
|
|
|
|
mpd_unused size_t size)
|
2008-09-12 15:02:57 +02:00
|
|
|
{
|
2008-09-12 16:38:54 +02:00
|
|
|
struct ogg_vorbis_data *od = (struct ogg_vorbis_data *)sd->encoder_data;
|
2008-09-12 15:59:55 +02:00
|
|
|
|
2008-09-12 15:02:57 +02:00
|
|
|
shout_ogg_encoder_clear_encoder(sd);
|
2008-09-12 15:57:43 +02:00
|
|
|
if (reinit_encoder(sd))
|
2008-09-12 15:02:57 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
copy_tag_to_vorbis_comment(sd);
|
|
|
|
|
2008-09-12 15:59:55 +02:00
|
|
|
vorbis_analysis_headerout(&od->vd, &od->vc,
|
|
|
|
&od->header_main,
|
|
|
|
&od->header_comments,
|
|
|
|
&od->header_codebooks);
|
2008-09-12 15:02:57 +02:00
|
|
|
|
2008-09-12 15:59:55 +02:00
|
|
|
ogg_stream_packetin(&od->os, &od->header_main);
|
|
|
|
ogg_stream_packetin(&od->os, &od->header_comments);
|
|
|
|
ogg_stream_packetin(&od->os, &od->header_codebooks);
|
2008-09-12 15:02:57 +02:00
|
|
|
|
2008-09-12 15:57:43 +02:00
|
|
|
flush_ogg_buffer(sd);
|
2008-09-12 15:02:57 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
shout: introduce pluggable encoder API
I've perhaps gone a bit overboard, but here's the current rundown:
Both Ogg and MP3 use the "shout" audio output plugin. The shout audio
output plugin itself has two new plugins, one for the Ogg encoder,
and another for the MP3 (LAME) encoder.
Configuration for an Ogg stream doesn't change. For an MP3 stream,
configuration is the same as Ogg, with two exceptions. First, you must
specify the optional "encoding" parameter, which should be set to "mp3".
See mpd.conf(5) for more details. Second, the "quality" parameter is
reversed for LAME, such that 1 is high quality for LAME, whereas 10 is
high quality for Ogg.
I've decomposed the code so that all libshout related operations
are done in audioOutput_shout.c, all Ogg specific functions are in
audioOutput_shout_ogg.c, and of course then all LAME specific functions
are handled in audioOutput_shout_mp3.c.
To develop encoder plugins for the shout audio output plugin, I basically
just mimicked the plugin system used for audio outputs. This might be
overkill, but hopefully if anyone ever wants to support some other sort
of stream, like maybe AAC, FLAC, or WMA (hey it could happen), they will
hopefully be all set.
The Ogg encoder is slightly less optimal under this configuration.
It used to send shout data directly out of its ogg_page structures. Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin (see
audioOutput_shout_ogg.c, line 77.) I suspect the performance impact
is negligible.
As for metadata, I'm pretty sure they'll both work. I wrote up a test
scaffold that would create a fake tag, and tell the plugin to send it
out to the stream every few seconds. It seemed to work fine. Of course,
if something does break, I'll be glad to fix it.
Lastly, I've renamed lots of things into snake_case, in keeping with
normalperson's wishes in that regard.
[mk: moved the MP3 patch after this one. Splitted this patch into
several parts; the others were already applied before this one. Fixed
a bunch GCC warnings and wrong whitespace modifications. Made it
compile with mpd-mk by adapting to its prototypes]
2008-09-12 16:04:40 +02:00
|
|
|
static int shout_ogg_encoder_encode(struct shout_data *sd,
|
|
|
|
const char *chunk, size_t size)
|
2008-09-12 15:02:57 +02:00
|
|
|
{
|
2008-09-12 16:38:54 +02:00
|
|
|
struct shout_buffer *buf = &sd->buf;
|
2008-09-12 15:02:57 +02:00
|
|
|
unsigned int i;
|
|
|
|
int j;
|
|
|
|
float **vorbbuf;
|
|
|
|
unsigned int samples;
|
2008-09-23 23:59:54 +02:00
|
|
|
int bytes = audio_format_sample_size(&sd->audio_format);
|
2008-09-12 16:38:54 +02:00
|
|
|
struct ogg_vorbis_data *od = (struct ogg_vorbis_data *)sd->encoder_data;
|
2008-09-12 15:02:57 +02:00
|
|
|
|
|
|
|
samples = size / (bytes * sd->audio_format.channels);
|
2008-09-12 15:59:55 +02:00
|
|
|
vorbbuf = vorbis_analysis_buffer(&od->vd, samples);
|
2008-09-12 15:02:57 +02:00
|
|
|
|
|
|
|
/* this is for only 16-bit audio */
|
|
|
|
|
|
|
|
for (i = 0; i < samples; i++) {
|
|
|
|
for (j = 0; j < sd->audio_format.channels; j++) {
|
2008-09-29 15:49:29 +02:00
|
|
|
vorbbuf[j][i] = (*((const int16_t *) chunk)) / 32768.0;
|
2008-09-12 15:02:57 +02:00
|
|
|
chunk += bytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-12 15:59:55 +02:00
|
|
|
vorbis_analysis_wrote(&od->vd, samples);
|
2008-09-12 15:02:57 +02:00
|
|
|
|
2008-09-12 15:59:55 +02:00
|
|
|
while (1 == vorbis_analysis_blockout(&od->vd, &od->vb)) {
|
|
|
|
vorbis_analysis(&od->vb, NULL);
|
|
|
|
vorbis_bitrate_addblock(&od->vb);
|
2008-09-12 15:02:57 +02:00
|
|
|
|
2008-09-12 15:59:55 +02:00
|
|
|
while (vorbis_bitrate_flushpacket(&od->vd, &od->op)) {
|
|
|
|
ogg_stream_packetin(&od->os, &od->op);
|
2008-09-12 15:02:57 +02:00
|
|
|
}
|
|
|
|
}
|
2008-09-12 15:57:43 +02:00
|
|
|
|
2008-09-12 15:59:55 +02:00
|
|
|
if (ogg_stream_pageout(&od->os, &od->og))
|
|
|
|
copy_ogg_buffer_to_shout_buffer(&od->og, buf);
|
shout: introduce pluggable encoder API
I've perhaps gone a bit overboard, but here's the current rundown:
Both Ogg and MP3 use the "shout" audio output plugin. The shout audio
output plugin itself has two new plugins, one for the Ogg encoder,
and another for the MP3 (LAME) encoder.
Configuration for an Ogg stream doesn't change. For an MP3 stream,
configuration is the same as Ogg, with two exceptions. First, you must
specify the optional "encoding" parameter, which should be set to "mp3".
See mpd.conf(5) for more details. Second, the "quality" parameter is
reversed for LAME, such that 1 is high quality for LAME, whereas 10 is
high quality for Ogg.
I've decomposed the code so that all libshout related operations
are done in audioOutput_shout.c, all Ogg specific functions are in
audioOutput_shout_ogg.c, and of course then all LAME specific functions
are handled in audioOutput_shout_mp3.c.
To develop encoder plugins for the shout audio output plugin, I basically
just mimicked the plugin system used for audio outputs. This might be
overkill, but hopefully if anyone ever wants to support some other sort
of stream, like maybe AAC, FLAC, or WMA (hey it could happen), they will
hopefully be all set.
The Ogg encoder is slightly less optimal under this configuration.
It used to send shout data directly out of its ogg_page structures. Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin (see
audioOutput_shout_ogg.c, line 77.) I suspect the performance impact
is negligible.
As for metadata, I'm pretty sure they'll both work. I wrote up a test
scaffold that would create a fake tag, and tell the plugin to send it
out to the stream every few seconds. It seemed to work fine. Of course,
if something does break, I'll be glad to fix it.
Lastly, I've renamed lots of things into snake_case, in keeping with
normalperson's wishes in that regard.
[mk: moved the MP3 patch after this one. Splitted this patch into
several parts; the others were already applied before this one. Fixed
a bunch GCC warnings and wrong whitespace modifications. Made it
compile with mpd-mk by adapting to its prototypes]
2008-09-12 16:04:40 +02:00
|
|
|
|
|
|
|
return 0;
|
2008-09-12 15:02:57 +02:00
|
|
|
}
|
|
|
|
|
2008-09-12 16:39:53 +02:00
|
|
|
const struct shout_encoder_plugin shout_ogg_encoder = {
|
shout: introduce pluggable encoder API
I've perhaps gone a bit overboard, but here's the current rundown:
Both Ogg and MP3 use the "shout" audio output plugin. The shout audio
output plugin itself has two new plugins, one for the Ogg encoder,
and another for the MP3 (LAME) encoder.
Configuration for an Ogg stream doesn't change. For an MP3 stream,
configuration is the same as Ogg, with two exceptions. First, you must
specify the optional "encoding" parameter, which should be set to "mp3".
See mpd.conf(5) for more details. Second, the "quality" parameter is
reversed for LAME, such that 1 is high quality for LAME, whereas 10 is
high quality for Ogg.
I've decomposed the code so that all libshout related operations
are done in audioOutput_shout.c, all Ogg specific functions are in
audioOutput_shout_ogg.c, and of course then all LAME specific functions
are handled in audioOutput_shout_mp3.c.
To develop encoder plugins for the shout audio output plugin, I basically
just mimicked the plugin system used for audio outputs. This might be
overkill, but hopefully if anyone ever wants to support some other sort
of stream, like maybe AAC, FLAC, or WMA (hey it could happen), they will
hopefully be all set.
The Ogg encoder is slightly less optimal under this configuration.
It used to send shout data directly out of its ogg_page structures. Now,
in the interest of encapsulation, it copies the data from its ogg_page
structures into a buffer provided by the shout audio output plugin (see
audioOutput_shout_ogg.c, line 77.) I suspect the performance impact
is negligible.
As for metadata, I'm pretty sure they'll both work. I wrote up a test
scaffold that would create a fake tag, and tell the plugin to send it
out to the stream every few seconds. It seemed to work fine. Of course,
if something does break, I'll be glad to fix it.
Lastly, I've renamed lots of things into snake_case, in keeping with
normalperson's wishes in that regard.
[mk: moved the MP3 patch after this one. Splitted this patch into
several parts; the others were already applied before this one. Fixed
a bunch GCC warnings and wrong whitespace modifications. Made it
compile with mpd-mk by adapting to its prototypes]
2008-09-12 16:04:40 +02:00
|
|
|
"ogg",
|
|
|
|
SHOUT_FORMAT_VORBIS,
|
|
|
|
|
|
|
|
shout_ogg_encoder_clear_encoder,
|
|
|
|
shout_ogg_encoder_encode,
|
|
|
|
shout_ogg_encoder_finish,
|
|
|
|
shout_ogg_encoder_init,
|
|
|
|
shout_ogg_encoder_init_encoder,
|
|
|
|
shout_ogg_encoder_send_metadata,
|
|
|
|
};
|
|
|
|
|
2008-09-12 15:02:57 +02:00
|
|
|
#endif
|