hornetseye-ffmpeg 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +1 -0
- data/COPYING +679 -0
- data/README.md +4 -0
- data/Rakefile +178 -0
- data/ext/avinput.cc +159 -0
- data/ext/avinput.hh +52 -0
- data/ext/error.hh +50 -0
- data/ext/frame.cc +32 -0
- data/ext/frame.hh +34 -0
- data/ext/init.cc +38 -0
- data/lib/hornetseye_ffmpeg_ext.rb +18 -0
- metadata +129 -0
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'date'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/packagetask'
|
6
|
+
require 'rbconfig'
|
7
|
+
|
8
|
+
PKG_NAME = 'hornetseye-ffmpeg'
|
9
|
+
PKG_VERSION = '0.1.0'
|
10
|
+
CXX = ENV[ 'CXX' ] || 'g++'
|
11
|
+
STRIP = ENV[ 'STRIP' ] || 'strip'
|
12
|
+
RB_FILES = FileList[ 'lib/**/*.rb' ]
|
13
|
+
CC_FILES = FileList[ 'ext/*.cc' ]
|
14
|
+
HH_FILES = FileList[ 'ext/*.hh' ]
|
15
|
+
TC_FILES = FileList[ 'test/tc_*.rb' ]
|
16
|
+
TS_FILES = FileList[ 'test/ts_*.rb' ]
|
17
|
+
SO_FILE = "ext/#{PKG_NAME.tr '\-', '_'}.so"
|
18
|
+
PKG_FILES = [ 'Rakefile', 'README.md', 'COPYING', '.document' ] +
|
19
|
+
RB_FILES + CC_FILES + HH_FILES + TS_FILES + TC_FILES
|
20
|
+
BIN_FILES = [ 'README.md', 'COPYING', '.document', SO_FILE ] +
|
21
|
+
RB_FILES + TS_FILES + TC_FILES
|
22
|
+
SUMMARY = %q{Read video frames using libffmpeg}
|
23
|
+
DESCRIPTION = %q{This Ruby extension defines the class Hornetseye::AVInput for reading frames from video files.}
|
24
|
+
AUTHOR = %q{Jan Wedekind}
|
25
|
+
EMAIL = %q{jan@wedesoft.de}
|
26
|
+
HOMEPAGE = %q{http://wedesoft.github.com/hornetseye-ffmpeg/}
|
27
|
+
|
28
|
+
OBJ = CC_FILES.ext 'o'
|
29
|
+
$CXXFLAGS = ENV[ 'CXXFLAGS' ] || ''
|
30
|
+
$CXXFLAGS = "#{$CXXFLAGS} -fPIC"
|
31
|
+
if Config::CONFIG[ 'rubyhdrdir' ]
|
32
|
+
$CXXFLAGS += "#{$CXXFLAGS} -I#{Config::CONFIG[ 'rubyhdrdir' ]} " +
|
33
|
+
"-I#{Config::CONFIG[ 'rubyhdrdir' ]}/#{Config::CONFIG[ 'arch' ]}"
|
34
|
+
else
|
35
|
+
$CXXFLAGS += "#{$CXXFLAGS} -I#{Config::CONFIG[ 'archdir' ]}"
|
36
|
+
end
|
37
|
+
$LIBRUBYARG = Config::CONFIG[ 'LIBRUBYARG' ]
|
38
|
+
$SITELIBDIR = Config::CONFIG[ 'sitelibdir' ]
|
39
|
+
$SITEARCHDIR = Config::CONFIG[ 'sitearchdir' ]
|
40
|
+
|
41
|
+
task :default => :all
|
42
|
+
|
43
|
+
desc 'Compile Ruby extension (default)'
|
44
|
+
task :all => [ SO_FILE ]
|
45
|
+
|
46
|
+
file SO_FILE => OBJ do |t|
|
47
|
+
sh "#{CXX} -shared -o #{t.name} #{OBJ} -lavformat -lswscale #{$LIBRUBYARG}"
|
48
|
+
# sh "#{STRIP} --strip-all #{t.name}"
|
49
|
+
end
|
50
|
+
|
51
|
+
task :test => [ SO_FILE ]
|
52
|
+
|
53
|
+
desc 'Install Ruby extension'
|
54
|
+
task :install => :all do
|
55
|
+
verbose true do
|
56
|
+
for f in RB_FILES do
|
57
|
+
FileUtils.mkdir_p "#{$SITELIBDIR}/#{File.dirname f.gsub( /^lib\//, '' )}"
|
58
|
+
FileUtils.cp_r f, "#{$SITELIBDIR}/#{f.gsub( /^lib\//, '' )}"
|
59
|
+
end
|
60
|
+
FileUtils.mkdir_p $SITEARCHDIR
|
61
|
+
FileUtils.cp SO_FILE, "#{$SITEARCHDIR}/#{File.basename SO_FILE}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
desc 'Uninstall Ruby extension'
|
66
|
+
task :uninstall do
|
67
|
+
verbose true do
|
68
|
+
for f in RB_FILES do
|
69
|
+
FileUtils.rm_f "#{$SITELIBDIR}/#{f.gsub /^lib\//, ''}"
|
70
|
+
end
|
71
|
+
FileUtils.rm_f "#{$SITEARCHDIR}/#{File.basename SO_FILE}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
Rake::TestTask.new do |t|
|
76
|
+
t.libs << 'ext'
|
77
|
+
t.test_files = TC_FILES
|
78
|
+
end
|
79
|
+
|
80
|
+
begin
|
81
|
+
require 'yard'
|
82
|
+
YARD::Rake::YardocTask.new :yard do |y|
|
83
|
+
y.options << '--no-private'
|
84
|
+
y.files << FileList[ 'lib/**/*.rb' ]
|
85
|
+
end
|
86
|
+
rescue LoadError
|
87
|
+
STDERR.puts 'Please install \'yard\' if you want to generate documentation'
|
88
|
+
end
|
89
|
+
|
90
|
+
Rake::PackageTask.new PKG_NAME, PKG_VERSION do |p|
|
91
|
+
p.need_tar = true
|
92
|
+
p.package_files = PKG_FILES
|
93
|
+
end
|
94
|
+
|
95
|
+
begin
|
96
|
+
require 'rubygems/builder'
|
97
|
+
$SPEC = Gem::Specification.new do |s|
|
98
|
+
s.name = PKG_NAME
|
99
|
+
s.version = PKG_VERSION
|
100
|
+
s.platform = Gem::Platform::RUBY
|
101
|
+
s.date = Date.today.to_s
|
102
|
+
s.summary = SUMMARY
|
103
|
+
s.description = DESCRIPTION
|
104
|
+
s.author = AUTHOR
|
105
|
+
s.email = EMAIL
|
106
|
+
s.homepage = HOMEPAGE
|
107
|
+
s.files = PKG_FILES
|
108
|
+
s.test_files = TC_FILES
|
109
|
+
s.require_paths = [ 'lib', 'ext' ]
|
110
|
+
s.rubyforge_project = %q{hornetseye}
|
111
|
+
s.extensions = %w{Rakefile}
|
112
|
+
s.has_rdoc = 'yard'
|
113
|
+
s.extra_rdoc_files = []
|
114
|
+
s.rdoc_options = %w{--no-private}
|
115
|
+
s.add_dependency %<malloc>, [ '~> 1.1' ]
|
116
|
+
s.add_dependency %<multiarray>, [ '~> 0.5' ]
|
117
|
+
s.add_dependency %<hornetseye-frame>, [ '~> 0.1' ]
|
118
|
+
s.add_development_dependency %q{rake}
|
119
|
+
end
|
120
|
+
GEM_SOURCE = "#{PKG_NAME}-#{PKG_VERSION}.gem"
|
121
|
+
$BINSPEC = Gem::Specification.new do |s|
|
122
|
+
s.name = PKG_NAME
|
123
|
+
s.version = PKG_VERSION
|
124
|
+
s.platform = Gem::Platform::CURRENT
|
125
|
+
s.date = Date.today.to_s
|
126
|
+
s.summary = SUMMARY
|
127
|
+
s.description = DESCRIPTION
|
128
|
+
s.author = AUTHOR
|
129
|
+
s.email = EMAIL
|
130
|
+
s.homepage = HOMEPAGE
|
131
|
+
s.files = BIN_FILES
|
132
|
+
s.test_files = TC_FILES
|
133
|
+
s.require_paths = [ 'lib', 'ext' ]
|
134
|
+
s.rubyforge_project = %q{hornetseye}
|
135
|
+
s.has_rdoc = 'yard'
|
136
|
+
s.extra_rdoc_files = []
|
137
|
+
s.rdoc_options = %w{--no-private}
|
138
|
+
s.add_dependency %<malloc>, [ '~> 1.1' ]
|
139
|
+
s.add_dependency %<multiarray>, [ '~> 0.5' ]
|
140
|
+
s.add_dependency %<hornetseye-frame>, [ '~> 0.1' ]
|
141
|
+
end
|
142
|
+
GEM_BINARY = "#{PKG_NAME}-#{PKG_VERSION}-#{$BINSPEC.platform}.gem"
|
143
|
+
desc "Build the gem file #{GEM_SOURCE}"
|
144
|
+
task :gem => [ "pkg/#{GEM_SOURCE}" ]
|
145
|
+
file "pkg/#{GEM_SOURCE}" => [ 'pkg' ] + $SPEC.files do
|
146
|
+
when_writing 'Creating GEM' do
|
147
|
+
Gem::Builder.new( $SPEC ).build
|
148
|
+
verbose true do
|
149
|
+
FileUtils.mv GEM_SOURCE, "pkg/#{GEM_SOURCE}"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
desc "Build the gem file #{GEM_BINARY}"
|
154
|
+
task :gem_binary => [ "pkg/#{GEM_BINARY}" ]
|
155
|
+
file "pkg/#{GEM_BINARY}" => [ 'pkg' ] + $BINSPEC.files do
|
156
|
+
when_writing 'Creating binary GEM' do
|
157
|
+
Gem::Builder.new( $BINSPEC ).build
|
158
|
+
verbose true do
|
159
|
+
FileUtils.mv GEM_BINARY, "pkg/#{GEM_BINARY}"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
rescue LoadError
|
164
|
+
STDERR.puts 'Please install \'rubygems\' if you want to create Gem packages'
|
165
|
+
end
|
166
|
+
|
167
|
+
rule '.o' => '.cc' do |t|
|
168
|
+
sh "#{CXX} #{$CXXFLAGS} -c -o #{t.name} #{t.source}"
|
169
|
+
end
|
170
|
+
|
171
|
+
file 'ext/avinput.o' => [ 'ext/avinput.cc', 'ext/avinput.hh', 'ext/error.hh',
|
172
|
+
'ext/frame.hh' ]
|
173
|
+
file 'ext/frame.o' => [ 'ext/frame.cc', 'ext/frame.hh' ]
|
174
|
+
file 'ext/init.o' => [ 'ext/init.cc', 'ext/avinput.hh' ]
|
175
|
+
|
176
|
+
CLEAN.include 'ext/*.o'
|
177
|
+
CLOBBER.include SO_FILE, 'doc', '.yardoc'
|
178
|
+
|
data/ext/avinput.cc
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
/* HornetsEye - Computer Vision with Ruby
|
2
|
+
Copyright (C) 2006, 2007, 2008, 2009, 2010 Jan Wedekind
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
16
|
+
#include "avinput.hh"
|
17
|
+
|
18
|
+
using namespace std;
|
19
|
+
|
20
|
+
VALUE AVInput::cRubyClass = Qnil;
|
21
|
+
|
22
|
+
AVInput::AVInput( const string &mrl ) throw (Error):
|
23
|
+
m_mrl( mrl ), m_ic( NULL ), m_enc( NULL ), m_codec( NULL ), m_idx( -1 ),
|
24
|
+
m_frame( NULL )
|
25
|
+
{
|
26
|
+
try {
|
27
|
+
int err = av_open_input_file( &m_ic, mrl.c_str(), NULL, 0, NULL );
|
28
|
+
ERRORMACRO( err >= 0, Error, , "Error opening file \"" << mrl << "\": "
|
29
|
+
<< strerror( -err ) );
|
30
|
+
err = av_find_stream_info( m_ic );
|
31
|
+
ERRORMACRO( err >= 0, Error, , "Error finding stream info for file \""
|
32
|
+
<< mrl << "\": " << strerror( -err ) );
|
33
|
+
for ( int i=0; i<m_ic->nb_streams; i++ )
|
34
|
+
if ( m_ic->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO ) {
|
35
|
+
m_idx = i;
|
36
|
+
break;
|
37
|
+
};
|
38
|
+
ERRORMACRO( m_idx >= 0, Error, , "Could not find video stream in file \""
|
39
|
+
<< mrl << "\"" );
|
40
|
+
m_enc = m_ic->streams[ m_idx ]->codec;
|
41
|
+
m_codec = avcodec_find_decoder( m_enc->codec_id );
|
42
|
+
ERRORMACRO( m_codec != NULL, Error, , "Could not find decoder for file \""
|
43
|
+
<< mrl << "\"" );
|
44
|
+
err = avcodec_open( m_enc, m_codec );
|
45
|
+
ERRORMACRO( err >= 0, Error, , "Error opening codec for file \""
|
46
|
+
<< mrl << "\": " << strerror( -err ) );
|
47
|
+
m_frame = avcodec_alloc_frame();
|
48
|
+
ERRORMACRO( m_frame, Error, , "Error allocating frame" );
|
49
|
+
} catch ( Error &e ) {
|
50
|
+
close();
|
51
|
+
throw e;
|
52
|
+
};
|
53
|
+
}
|
54
|
+
|
55
|
+
AVInput::~AVInput(void)
|
56
|
+
{
|
57
|
+
close();
|
58
|
+
}
|
59
|
+
|
60
|
+
void AVInput::close(void)
|
61
|
+
{
|
62
|
+
if ( m_frame ) {
|
63
|
+
av_free( m_frame );
|
64
|
+
m_frame = NULL;
|
65
|
+
};
|
66
|
+
if ( m_codec ) {
|
67
|
+
avcodec_close( m_enc );
|
68
|
+
m_codec = NULL;
|
69
|
+
};
|
70
|
+
m_enc = NULL;
|
71
|
+
m_idx = -1;
|
72
|
+
if ( m_ic ) {
|
73
|
+
av_close_input_file( m_ic );
|
74
|
+
m_ic = NULL;
|
75
|
+
};
|
76
|
+
}
|
77
|
+
|
78
|
+
FramePtr AVInput::read(void) throw (Error)
|
79
|
+
{
|
80
|
+
FramePtr retVal;
|
81
|
+
AVPacket packet;
|
82
|
+
while ( av_read_frame( m_ic, &packet ) >= 0 ) {
|
83
|
+
if ( packet.stream_index == m_idx ) {
|
84
|
+
int frameFinished;
|
85
|
+
int err = avcodec_decode_video( m_enc, m_frame, &frameFinished,
|
86
|
+
packet.data, packet.size );
|
87
|
+
ERRORMACRO( err >= 0, Error, ,
|
88
|
+
"Error decoding frame of video \"" << m_mrl << "\"" );
|
89
|
+
if ( frameFinished ) {
|
90
|
+
av_free_packet( &packet );
|
91
|
+
AVFrame frame;
|
92
|
+
m_data = boost::shared_array< char >( new char[ m_enc->width *
|
93
|
+
m_enc->height *
|
94
|
+
3 / 2 ] );
|
95
|
+
frame.data[0] = (uint8_t *)m_data.get();
|
96
|
+
frame.data[1] = (uint8_t *)m_data.get() +
|
97
|
+
m_enc->width * m_enc->height * 5 / 4;
|
98
|
+
frame.data[2] = (uint8_t *)m_data.get() + m_enc->width * m_enc->height;
|
99
|
+
frame.linesize[0] = m_enc->width;
|
100
|
+
frame.linesize[1] = m_enc->width / 2;
|
101
|
+
frame.linesize[2] = m_enc->width / 2;
|
102
|
+
struct SwsContext *swsContext =
|
103
|
+
sws_getContext( m_enc->width, m_enc->height, m_enc->pix_fmt,
|
104
|
+
m_enc->width, m_enc->height, PIX_FMT_YUV420P,
|
105
|
+
SWS_BILINEAR, 0, 0, 0 );
|
106
|
+
sws_scale( swsContext, m_frame->data, m_frame->linesize, 0,
|
107
|
+
m_enc->height, frame.data, frame.linesize );
|
108
|
+
sws_freeContext( swsContext );
|
109
|
+
retVal = FramePtr( new Frame( "YV12", m_enc->width, m_enc->height,
|
110
|
+
m_data.get() ) );
|
111
|
+
break;
|
112
|
+
};
|
113
|
+
};
|
114
|
+
av_free_packet( &packet );
|
115
|
+
};
|
116
|
+
ERRORMACRO( retVal.get(), Error, , "No more frames available" );
|
117
|
+
return retVal;
|
118
|
+
}
|
119
|
+
|
120
|
+
VALUE AVInput::registerRubyClass( VALUE rbModule )
|
121
|
+
{
|
122
|
+
av_register_all();
|
123
|
+
cRubyClass = rb_define_class_under( rbModule, "AVInput", rb_cObject );
|
124
|
+
rb_define_singleton_method( cRubyClass, "new",
|
125
|
+
RUBY_METHOD_FUNC( wrapNew ), 1 );
|
126
|
+
rb_define_method( cRubyClass, "read", RUBY_METHOD_FUNC( wrapRead ), 0 );
|
127
|
+
}
|
128
|
+
|
129
|
+
void AVInput::deleteRubyObject( void *ptr )
|
130
|
+
{
|
131
|
+
delete (AVInputPtr *)ptr;
|
132
|
+
}
|
133
|
+
|
134
|
+
VALUE AVInput::wrapNew( VALUE rbClass, VALUE rbMRL )
|
135
|
+
{
|
136
|
+
VALUE retVal = Qnil;
|
137
|
+
try {
|
138
|
+
rb_check_type( rbMRL, T_STRING );
|
139
|
+
AVInputPtr ptr( new AVInput( StringValuePtr( rbMRL ) ) );
|
140
|
+
retVal = Data_Wrap_Struct( rbClass, 0, deleteRubyObject,
|
141
|
+
new AVInputPtr( ptr ) );
|
142
|
+
} catch ( exception &e ) {
|
143
|
+
rb_raise( rb_eRuntimeError, "%s", e.what() );
|
144
|
+
};
|
145
|
+
return retVal;
|
146
|
+
}
|
147
|
+
|
148
|
+
VALUE AVInput::wrapRead( VALUE rbSelf )
|
149
|
+
{
|
150
|
+
VALUE retVal = Qnil;
|
151
|
+
try {
|
152
|
+
AVInputPtr *self; Data_Get_Struct( rbSelf, AVInputPtr, self );
|
153
|
+
FramePtr frame( (*self)->read() );
|
154
|
+
retVal = frame->rubyObject();
|
155
|
+
} catch ( exception &e ) {
|
156
|
+
rb_raise( rb_eRuntimeError, "%s", e.what() );
|
157
|
+
};
|
158
|
+
return retVal;
|
159
|
+
}
|
data/ext/avinput.hh
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
/* HornetsEye - Computer Vision with Ruby
|
2
|
+
Copyright (C) 2006, 2007, 2008, 2009, 2010 Jan Wedekind
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
16
|
+
#ifndef AVFORMAT_HH
|
17
|
+
#define AVFORMAT_HH
|
18
|
+
|
19
|
+
#include <boost/shared_ptr.hpp>
|
20
|
+
#include <ruby.h>
|
21
|
+
extern "C" {
|
22
|
+
#include <libswscale/swscale.h>
|
23
|
+
#include <libavformat/avformat.h>
|
24
|
+
}
|
25
|
+
#include "error.hh"
|
26
|
+
#include "frame.hh"
|
27
|
+
|
28
|
+
class AVInput
|
29
|
+
{
|
30
|
+
public:
|
31
|
+
AVInput( const std::string &mrl ) throw (Error);
|
32
|
+
virtual ~AVInput(void);
|
33
|
+
void close(void);
|
34
|
+
FramePtr read(void) throw (Error);
|
35
|
+
static VALUE cRubyClass;
|
36
|
+
static VALUE registerRubyClass( VALUE rbModule );
|
37
|
+
static void deleteRubyObject( void *ptr );
|
38
|
+
static VALUE wrapNew( VALUE rbClass, VALUE rbMRL );
|
39
|
+
static VALUE wrapRead( VALUE rbSelf );
|
40
|
+
protected:
|
41
|
+
std::string m_mrl;
|
42
|
+
AVFormatContext *m_ic;
|
43
|
+
AVCodecContext *m_enc;
|
44
|
+
AVCodec *m_codec;
|
45
|
+
int m_idx;
|
46
|
+
AVFrame *m_frame;
|
47
|
+
boost::shared_array< char > m_data;
|
48
|
+
};
|
49
|
+
|
50
|
+
typedef boost::shared_ptr< AVInput > AVInputPtr;
|
51
|
+
|
52
|
+
#endif
|
data/ext/error.hh
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
/* HornetsEye - Computer Vision with Ruby
|
2
|
+
Copyright (C) 2006, 2007, 2008, 2009, 2010 Jan Wedekind
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
16
|
+
#ifndef ERROR_HH
|
17
|
+
#define ERROR_HH
|
18
|
+
|
19
|
+
#include <exception>
|
20
|
+
#include <sstream>
|
21
|
+
|
22
|
+
class Error: public std::exception
|
23
|
+
{
|
24
|
+
public:
|
25
|
+
Error(void) {}
|
26
|
+
Error( Error &e ): std::exception( e )
|
27
|
+
{ m_message << e.m_message.str(); }
|
28
|
+
virtual ~Error(void) throw() {}
|
29
|
+
template< typename T >
|
30
|
+
std::ostream &operator<<( const T &t )
|
31
|
+
{ m_message << t; return m_message; }
|
32
|
+
std::ostream &operator<<( std::ostream& (*__pf)(std::ostream&) )
|
33
|
+
{ (*__pf)( m_message ); return m_message; }
|
34
|
+
virtual const char* what(void) const throw() {
|
35
|
+
temp = m_message.str();
|
36
|
+
return temp.c_str();
|
37
|
+
}
|
38
|
+
protected:
|
39
|
+
std::ostringstream m_message;
|
40
|
+
mutable std::string temp;
|
41
|
+
};
|
42
|
+
|
43
|
+
#define ERRORMACRO( condition, class, params, message ) \
|
44
|
+
if ( !( condition ) ) { \
|
45
|
+
class _e params; \
|
46
|
+
_e << message; \
|
47
|
+
throw _e; \
|
48
|
+
};
|
49
|
+
|
50
|
+
#endif
|
data/ext/frame.cc
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
/* HornetsEye - Computer Vision with Ruby
|
2
|
+
Copyright (C) 2006, 2007, 2008, 2009, 2010 Jan Wedekind
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
16
|
+
#include <iostream>
|
17
|
+
#include "frame.hh"
|
18
|
+
|
19
|
+
using namespace std;
|
20
|
+
|
21
|
+
Frame::Frame( const char *typecode, int width, int height, char *data ):
|
22
|
+
m_frame( Qnil )
|
23
|
+
{
|
24
|
+
VALUE mModule = rb_define_module( "Hornetseye" );
|
25
|
+
VALUE cMalloc = rb_define_class_under( mModule, "Malloc", rb_cObject );
|
26
|
+
VALUE cFrame = rb_define_class_under( mModule, "Frame", rb_cObject );
|
27
|
+
VALUE memory = Data_Wrap_Struct( cMalloc, 0, 0, (void *)data );
|
28
|
+
m_frame = rb_funcall( cFrame, rb_intern( "import" ), 4,
|
29
|
+
rb_const_get( mModule, rb_intern( typecode ) ),
|
30
|
+
INT2NUM( width ), INT2NUM( height ),
|
31
|
+
memory );
|
32
|
+
}
|
data/ext/frame.hh
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
/* HornetsEye - Computer Vision with Ruby
|
2
|
+
Copyright (C) 2006, 2007, 2008, 2009, 2010 Jan Wedekind
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
16
|
+
#ifndef FRAME_HH
|
17
|
+
#define FRAME_HH
|
18
|
+
|
19
|
+
#include <boost/smart_ptr.hpp>
|
20
|
+
#include <ruby.h>
|
21
|
+
|
22
|
+
class Frame
|
23
|
+
{
|
24
|
+
public:
|
25
|
+
Frame( const char *typecode, int width, int height, char *data );
|
26
|
+
virtual ~Frame(void) {}
|
27
|
+
VALUE rubyObject(void) { return m_frame; }
|
28
|
+
protected:
|
29
|
+
VALUE m_frame;
|
30
|
+
};
|
31
|
+
|
32
|
+
typedef boost::shared_ptr< Frame > FramePtr;
|
33
|
+
|
34
|
+
#endif
|
data/ext/init.cc
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
/* HornetsEye - Computer Vision with Ruby
|
2
|
+
Copyright (C) 2006, 2007, 2008, 2009, 2010 Jan Wedekind
|
3
|
+
|
4
|
+
This program is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
16
|
+
#include "avinput.hh"
|
17
|
+
|
18
|
+
#ifdef WIN32
|
19
|
+
#define DLLEXPORT __declspec(dllexport)
|
20
|
+
#define DLLLOCAL
|
21
|
+
#else
|
22
|
+
#define DLLEXPORT __attribute__ ((visibility("default")))
|
23
|
+
#define DLLLOCAL __attribute__ ((visibility("hidden")))
|
24
|
+
#endif
|
25
|
+
|
26
|
+
extern "C" DLLEXPORT void Init_hornetseye_ffmpeg(void);
|
27
|
+
|
28
|
+
extern "C" {
|
29
|
+
|
30
|
+
void Init_hornetseye_ffmpeg(void)
|
31
|
+
{
|
32
|
+
rb_require( "hornetseye_frame" );
|
33
|
+
VALUE rbHornetseye = rb_define_module( "Hornetseye" );
|
34
|
+
AVInput::registerRubyClass( rbHornetseye );
|
35
|
+
rb_require( "hornetseye_ffmpeg_ext.rb" );
|
36
|
+
}
|
37
|
+
|
38
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# hornetseye-frame - Colourspace conversions and compression
|
2
|
+
# Copyright (C) 2010 Jan Wedekind
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
require 'hornetseye_frame'
|
18
|
+
|