Skip to content

EFFALO/ruby-shout

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ruby-Shout

Compatibility note

If you have installed a previous version of ruby-shout you have to make shure the shout.o files aren’t there any more. Otherwise the build will fail.

Purpose

ruby-shout lets you send compressed audio over the network to an Icecast streaming media server.

Requirements

libshout 2.0, available from icecast.org. libshout 2 requires the ogg and vorbis libraries.

Summary of usage

This extension follows python-shout fairly closely. You make a Shout object with Shout.new, set its properties, tell it to connect, then send blocks of data, sync and repeat. Disconnect when done.

Usage

See example.rb. Run it like

./example.rb spec/test.mp3

Ruby 1.9 and encoding

Ruby 1.9 features really good encoding support: Each string has it’s own explicit encoding. The default encoding for Icecast is ISO-8859-1 for station data and meta data.

In order to make ruby-shout play nice with ruby 1.9 I added a Shout#charset setter and all string accessors for station data are wrapped:

  • setters convert the given string to the given charset
  • and store the original string, available under #original_…, for example #original_description. This is done because converting may alter your string (characters incompatible with conversion are just swallowed). That way you are able to get your original string back (should you need it) and the getter is enabled to:
  • getters convert the value back to the original encoding, determined by the #original_… method.

The idea is: We want to guaranty that strings keep their encoding when assigning them via a Shout accessor. In case strings are not compatible with Icecasts charset we want to degrade as gracefully as possible. IMHO just dropping incompatible characters does this best (when being listed in an external YP directory these “???br?” things just look awful). If you want to make sure this doesn’t happen you have to compare the value before and after assigning it (or just compare for example #description with #original_description).

Synopsis:

s = Shout.new
s.charset = 'UTF-8'
s.description = 'dikşîne MUSłϾ'
puts s.description              # => 'dikşîne MUSłϾ'

s = Shout.new
s.charset = 'ISO-8859-1'        # this is the default
s.description = 'dikşîne MUSłϾ'
puts s.description              # => 'dikîne MUSłϾ'
puts s.original_description     # => 'dikşîne MUSłϾ'

Icecast charset config

If you use s/th else than ISO-8859-1 you should configure your icecast accordingly: In the mount section set the charset:

<mount>
  <mount-name>/your_station</mount-name>
  <charset>UTF-8</charset>
  ...
</mount>

or (in the latest icecast builds)

<mount>
  <mount-name>/*</mount-name>
  <charset>UTF-8</charset>
  ...
</mount>

to set UTF-8 for all mountpoints.

Running the spec

General note: use rake spec:build

Before each run you have to run the build specs first as the other specs use its output (the built gem).

rake spec:build && rake spec

For the integration spec

You need to have an icecast server running. Perhaps you want to adopt the server setting quite at the top of the intergration_spec.rb

Todo

  • proper unit tests (blush) ; working on that

History & Credits

  • 2001 Jared Jenning built the initial version for libshout 1
  • 2003 Jared Jenning rebuilt ruby-shout for libshout 2 and maintained it to until 2005
  • Yauhen Kharuzhy helped with bugfixes and initial metadata support
  • 2010 “Overlay” (real name unknown to me) patched ruby-shout for ruby 1.9 support, Diego Elio “Flameeyes” Pettenò incorporated patch into the gentoo package. It got removed later on due to some issues.
  • 2010 Niko Dittman re-added the patch and fixed the issues. See “Recent Changes” for details.

Recent Changes

  • Included the ruby 1.9 patch although it seems to have some issues. I hope to have fixed the issues with this:
  • Replaced STR2CSTR for StringValuePtr as STR2CSTR doesn’t work for 1.9 any more
  • Added format = Shout::MP3 to the example as this is absolutely needed by the latest versions of libshout.
  • Added a build test which builds and installs the gem and an integration test that plays some sound on a local icecast server. Be sure to adopt the server setting before running. I mainly did that because the old version of ruby-shout didn’t even compile for ruby 1.9.
  • Added Ruby 1.9 encoding support.

State

I tested this version of ruby-shout to build and run on

  • ruby-1.8.7-p174 [x86_64] OSX 10.6
  • ruby-1.9.1-p378 [x86_64] OSX 10.6
  • ruby-1.9.2-rc1 [x86_64] OSX 10.6
  • ruby-1.9.2-p0 [x86_64] OSX 10.6
  • ruby-1.8.7-p299 [i386] ubuntu 2.6.32
  • ruby-1.9.2-rc2 [i386] ubuntu 2.6.32

License
This is a BSD license.

Copyright © 2003-2005, Jared Jennings
Copyright © 2010, Niko Dittmann

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this
    list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.
  • Neither the names of the authors nor the names of contributors may
    be used to endorse or promote products derived from this software without
    specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Packages

No packages published

Languages

  • C 67.8%
  • Ruby 32.2%