Skip to content

Commit

Permalink
Add setting/getting bitrate to audio_info.
Browse files Browse the repository at this point in the history
  • Loading branch information
Roel van Dijk committed Nov 15, 2011
1 parent a612cfa commit 15bce8f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 37 deletions.
23 changes: 23 additions & 0 deletions ext/shout_ext.c
Expand Up @@ -437,6 +437,15 @@ VALUE _sh_description(VALUE self) {
return rb_str_new2(value); return rb_str_new2(value);
} }


VALUE _sh_bitrate(VALUE self) {
const char *value;

shout_connection *s; GET_SC(self, s);

value = shout_get_audio_info(s->conn, SHOUT_AI_BITRATE);
return rb_str_new2(value);
}

/* Unimplemented: audio_info */ /* Unimplemented: audio_info */


/* audio_info and metadata should both be objects that always exist, and have /* audio_info and metadata should both be objects that always exist, and have
Expand Down Expand Up @@ -662,6 +671,18 @@ VALUE _sh_metadata_eq(VALUE self, VALUE meta) {
return meta; return meta;
} }


/* Set the 'bitrate' in the audio_info of the stream. */
VALUE _sh_bitrate_eq(VALUE self, VALUE value) {
int err;
shout_connection *s; GET_SC(self, s);

Check_Type(value, T_STRING);
err = shout_set_audio_info(s->conn, SHOUT_AI_BITRATE, RSTRING_PTR(value));
if(err != SHOUTERR_SUCCESS) {
raise_shout_error(s->conn);
}
return value;
}




/* /*
Expand Down Expand Up @@ -716,6 +737,7 @@ void Init_shout_ext()
rb_define_method(cShout, "url", _sh_url, 0); rb_define_method(cShout, "url", _sh_url, 0);
rb_define_method(cShout, "genre", _sh_genre, 0); rb_define_method(cShout, "genre", _sh_genre, 0);
rb_define_method(cShout, "description",_sh_description,0); rb_define_method(cShout, "description",_sh_description,0);
rb_define_method(cShout, "bitrate", _sh_bitrate, 0);
/* metadata getting is still unsupported. */ /* metadata getting is still unsupported. */
/* audio info thingy. */ /* audio info thingy. */
/* leave for version 2.2 */ /* leave for version 2.2 */
Expand All @@ -739,6 +761,7 @@ void Init_shout_ext()
rb_define_method(cShout, "genre=", _sh_genre_eq, 1); rb_define_method(cShout, "genre=", _sh_genre_eq, 1);
rb_define_method(cShout, "description=", _sh_description_eq,1); rb_define_method(cShout, "description=", _sh_description_eq,1);
rb_define_method(cShout, "metadata=", _sh_metadata_eq, 1); rb_define_method(cShout, "metadata=", _sh_metadata_eq, 1);
rb_define_method(cShout, "bitrate=", _sh_bitrate_eq, 1);


rb_define_const(cShout, "HTTP", INT2FIX(SHOUT_PROTOCOL_HTTP)); rb_define_const(cShout, "HTTP", INT2FIX(SHOUT_PROTOCOL_HTTP));
rb_define_const(cShout, "XAUDIOCAST", INT2FIX(SHOUT_PROTOCOL_XAUDIOCAST)); rb_define_const(cShout, "XAUDIOCAST", INT2FIX(SHOUT_PROTOCOL_XAUDIOCAST));
Expand Down
28 changes: 14 additions & 14 deletions lib/shout.rb
Expand Up @@ -3,53 +3,53 @@


class Shout class Shout
attr_writer :charset attr_writer :charset

INT_ACCESSORS = :port, :format INT_ACCESSORS = :port, :format
STRING_ACCESSORS = :host, :user, :username, :pass, :password, :protocol, :mount, :dumpfile, STRING_ACCESSORS = :host, :user, :username, :pass, :password, :protocol, :mount, :dumpfile,
:agent, :user_agent, :public, :name, :url, :genre, :description :agent, :user_agent, :public, :name, :url, :genre, :description, :bitrate

alias :ext_initialize :initialize alias :ext_initialize :initialize
def initialize(opts={}) def initialize(opts={})
ext_initialize ext_initialize

(STRING_ACCESSORS + INT_ACCESSORS + [:charset]).each do |a| (STRING_ACCESSORS + INT_ACCESSORS + [:charset]).each do |a|
self.__send__ :"#{a}=", opts[a] if opts[a] self.__send__ :"#{a}=", opts[a] if opts[a]
end end
end end

STRING_ACCESSORS.each do |accessor| STRING_ACCESSORS.each do |accessor|
attr_accessor :"original_#{accessor}" attr_accessor :"original_#{accessor}"

alias :"raw_#{accessor}" :"#{accessor}" alias :"raw_#{accessor}" :"#{accessor}"
define_method accessor do define_method accessor do
return nil unless orig_acc = self.__send__("original_#{accessor}") return nil unless orig_acc = self.__send__("original_#{accessor}")

decode self.__send__(:"raw_#{accessor}"), orig_acc decode self.__send__(:"raw_#{accessor}"), orig_acc
end end

alias :"raw_#{accessor}=" :"#{accessor}=" alias :"raw_#{accessor}=" :"#{accessor}="
define_method :"#{accessor}=" do |value| define_method :"#{accessor}=" do |value|
self.__send__ "original_#{accessor}=", value self.__send__ "original_#{accessor}=", value

self.__send__ :"raw_#{accessor}=", encode(value) self.__send__ :"raw_#{accessor}=", encode(value)
end end
end end

def charset def charset
@charset || ((format && format==Shout::MP3) ? 'ISO-8859-1' : 'UTF-8') @charset || ((format && format==Shout::MP3) ? 'ISO-8859-1' : 'UTF-8')
end end

private private
def encode(s) def encode(s)
return s unless s.is_a? String return s unless s.is_a? String

s.encode(charset, :invalid => :replace, :undef => :replace, :replace => '') s.encode(charset, :invalid => :replace, :undef => :replace, :replace => '')
end end
def decode(s, orig_string) def decode(s, orig_string)
return s unless s.is_a? String return s unless s.is_a? String

orig_charset = orig_string.encoding.name orig_charset = orig_string.encoding.name
s.encode(orig_charset, charset, :invalid => :replace, :undef => :replace, :replace => '') s.encode(orig_charset, charset, :invalid => :replace, :undef => :replace, :replace => '')
end end

end end
32 changes: 12 additions & 20 deletions ruby-shout.gemspec
@@ -1,44 +1,36 @@
# Generated by jeweler # Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY # DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-


Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = %q{ruby-shout} s.name = %q{ruby-shout}
s.version = "2.2.0" s.version = "2.2.1"


s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Jared Jennings", "Niko Dittmann"] s.authors = [%q{Jared Jennings}, %q{Niko Dittmann}]
s.date = %q{2011-01-05} s.date = %q{2011-11-15}
s.description = %q{Ruby bindings for libshout 2, a "Library which can be used to write a source client like ices" for Icecast (http://www.icecast.org/download.php).} s.description = %q{Ruby bindings for libshout 2, a "Library which can be used to write a source client like ices" for Icecast (http://www.icecast.org/download.php).}
s.email = %q{mail@niko-dittmann.com} s.email = %q{mail@niko-dittmann.com}
s.extensions = ["ext/extconf.rb"] s.extensions = [%q{ext/extconf.rb}]
s.extra_rdoc_files = [ s.extra_rdoc_files = [
"README.textile" "README.textile"
] ]
s.files = [ s.files = [
"README.textile", "README.textile",
"Rakefile", "Rakefile",
"VERSION", "VERSION",
"ext/extconf.rb", "ext/extconf.rb",
"ext/shout_ext.c", "ext/shout_ext.c",
"lib/shout.rb" "lib/shout.rb"
] ]
s.homepage = %q{http://github.com/niko/ruby-shout} s.homepage = %q{http://github.com/niko/ruby-shout}
s.rdoc_options = ["--charset=UTF-8"] s.require_paths = [%q{lib}]
s.require_paths = ["lib"]
s.rubyforge_project = %q{ruby-shout} s.rubyforge_project = %q{ruby-shout}
s.rubygems_version = %q{1.3.7} s.rubygems_version = %q{1.8.6}
s.summary = %q{Send audio over the network to an Icecast server} s.summary = %q{Send audio over the network to an Icecast server}
s.test_files = [
"spec/accessors_spec.rb",
"spec/build_spec.rb",
"spec/integration_spec.rb",
"spec/spec_helper.rb"
]


if s.respond_to? :specification_version then if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3 s.specification_version = 3


if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
Expand Down
4 changes: 4 additions & 0 deletions spec/accessors_spec.rb
Expand Up @@ -21,6 +21,10 @@
@shout.original_genre.should == @genre @shout.original_genre.should == @genre
end end
end end
it "should get and set the bitrate in audio_info" do
@shout.bitrate = "128"
@shout.bitrate.should == "128"
end
describe "#initialize" do describe "#initialize" do
it "should set the properies from the opts" do it "should set the properies from the opts" do
s = Shout.new :user => 'heinz' s = Shout.new :user => 'heinz'
Expand Down
6 changes: 3 additions & 3 deletions spec/build_spec.rb
Expand Up @@ -30,17 +30,17 @@ def install_gem
command = %Q{ command = %Q{
cd #{BASE_DIR} cd #{BASE_DIR}
rake build rake build
gem install --no-test --no-rdoc --no-ri --install-dir spec/test_gem_installation --bindir spec/test_gem_installation pkg/ruby-shout-#{VERSION}.gem gem install --no-rdoc --no-ri --install-dir spec/test_gem_installation --bindir spec/test_gem_installation pkg/ruby-shout-#{VERSION}.gem
} }
c = `#{command}` c = `#{command}`
puts c puts c
return c return c
end end

it "should build" do it "should build" do
clean_test_gem.should be_true clean_test_gem.should be_true
install_gem.should be_true install_gem.should be_true
remove_pkg.should be_true remove_pkg.should be_true
end end

end end

0 comments on commit 15bce8f

Please sign in to comment.