hornetseye-ffmpeg 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -7,12 +7,12 @@ require 'rake/loaders/makefile'
7
7
  require 'rbconfig'
8
8
 
9
9
  PKG_NAME = 'hornetseye-ffmpeg'
10
- PKG_VERSION = '0.4.0'
10
+ PKG_VERSION = '0.4.1'
11
11
  CXX = ENV[ 'CXX' ] || 'g++'
12
12
  STRIP = ENV[ 'STRIP' ] || 'strip'
13
13
  RB_FILES = FileList[ 'lib/**/*.rb' ]
14
14
  CC_FILES = FileList[ 'ext/*.cc' ]
15
- HH_FILES = FileList[ 'ext/*.hh' ]
15
+ HH_FILES = FileList[ 'ext/*.hh' ] + FileList[ 'ext/*.tcc' ]
16
16
  TC_FILES = FileList[ 'test/tc_*.rb' ]
17
17
  TS_FILES = FileList[ 'test/ts_*.rb' ]
18
18
  SO_FILE = "ext/#{PKG_NAME.tr '\-', '_'}.so"
@@ -28,7 +28,7 @@ HOMEPAGE = %q{http://wedesoft.github.com/hornetseye-ffmpeg/}
28
28
 
29
29
  OBJ = CC_FILES.ext 'o'
30
30
  $CXXFLAGS = ENV[ 'CXXFLAGS' ] || ''
31
- $CXXFLAGS = "#{$CXXFLAGS} -fPIC -DNDEBUG"
31
+ $CXXFLAGS = "#{$CXXFLAGS} -fPIC -DNDEBUG -DHAVE_CONFIG_H"
32
32
  if RbConfig::CONFIG[ 'rubyhdrdir' ]
33
33
  $CXXFLAGS = "#{$CXXFLAGS} -I#{RbConfig::CONFIG[ 'rubyhdrdir' ]} " +
34
34
  "-I#{RbConfig::CONFIG[ 'rubyhdrdir' ]}/#{RbConfig::CONFIG[ 'arch' ]}"
@@ -73,6 +73,99 @@ task :uninstall do
73
73
  end
74
74
  end
75
75
 
76
+ desc 'Create config.h'
77
+ task :config_h => 'ext/config.h'
78
+
79
+ def check_program
80
+ f_base_name = 'rakeconf'
81
+ begin
82
+ File.open( "#{f_base_name}.cc", 'w' ) { |f| yield f }
83
+ `#{CXX} -S #{$CXXFLAGS} -c -o #{f_base_name}.o #{f_base_name}.cc 2>&1 >> rake.log`
84
+ $?.exitstatus == 0
85
+ ensure
86
+ File.delete *Dir.glob( "#{f_base_name}.*" )
87
+ end
88
+ end
89
+
90
+ def check_c_header( name )
91
+ check_program do |c|
92
+ c.puts <<EOS
93
+ extern "C" {
94
+ #include <#{name}>
95
+ }
96
+ int main(void) { return 0; }
97
+ EOS
98
+ end
99
+ end
100
+
101
+ file 'ext/config.h' do |t|
102
+ s = "/* config.h. Generated from Rakefile by rake. */\n"
103
+ if check_c_header 'libswscale/swscale.h'
104
+ s << "#define HAVE_LIBSWSCALE_INCDIR 1\n"
105
+ elsif check_c_header 'ffmpeg/swscale.h'
106
+ s << "#undef HAVE_LIBSWSCALE_INCDIR\n"
107
+ else
108
+ raise 'Cannot find swscale.h header file'
109
+ end
110
+ have_libavformat_incdir = check_c_header 'libavformat/avformat.h'
111
+ if have_libavformat_incdir
112
+ s << "#define HAVE_LIBAVFORMAT_INCDIR 1\n"
113
+ elsif check_c_header 'ffmpeg/avformat.h'
114
+ s << "#undef HAVE_LIBAVFORMAT_INCDIR\n"
115
+ else
116
+ raise 'Cannot find swscale.h header file'
117
+ end
118
+ have_libavformat_alloc_context = check_program do |c|
119
+ c.puts <<EOS
120
+ extern "C" {
121
+ #include <#{have_libavformat_incdir ? 'libavformat' : 'ffmpeg'}/avformat.h>
122
+ }
123
+ int main(void) { avformat_alloc_context(); return 0; }
124
+ EOS
125
+ end
126
+ if have_libavformat_alloc_context
127
+ s << "#define HAVE_LIBAVFORMAT_ALLOC_CONTEXT 1\n"
128
+ else
129
+ have_alloc_format_context = check_program do |c|
130
+ c.puts <<EOS
131
+ extern "C" {
132
+ #include <#{have_libavformat_incdir ? 'libavformat' : 'ffmpeg'}/avformat.h>
133
+ }
134
+ int main(void) { av_alloc_format_context(); return 0; }
135
+ EOS
136
+ end
137
+ unless have_alloc_format_context
138
+ raise 'Cannot find constructor for AVFormatContext'
139
+ end
140
+ s << "#undef HAVE_LIBAVFORMAT_ALLOC_CONTEXT\n"
141
+ end
142
+ have_byteio_ptr = check_program do |c|
143
+ c.puts <<EOS
144
+ extern "C" {
145
+ #include <#{have_libavformat_incdir ? 'libavformat' : 'ffmpeg'}/avformat.h>
146
+ }
147
+ int main(void) { AVFormatContext *c; url_fclose( c->pb ); return 0; }
148
+ EOS
149
+ end
150
+ if have_byteio_ptr
151
+ s << "#define HAVE_BYTEIO_PTR 1\n"
152
+ else
153
+ have_byteio_inst = check_program do |c|
154
+ c.puts <<EOS
155
+ extern "C" {
156
+ #include <#{have_libavformat_incdir ? 'libavformat' : 'ffmpeg'}/avformat.h>
157
+ }
158
+ int main(void) { AVFormatContext *c; url_fclose( &c->pb ); return 0; }
159
+ EOS
160
+ end
161
+ unless have_byteio_inst
162
+ raise 'Cannot find ByteIOContext member variable'
163
+ end
164
+ s << "#undef HAVE_BYTEIO_PTR\n"
165
+ end
166
+ File.open( t.name, 'w' ) { |f| f.puts s }
167
+ end
168
+
76
169
  Rake::TestTask.new do |t|
77
170
  t.libs << 'ext'
78
171
  t.test_files = TC_FILES
@@ -170,7 +263,7 @@ rule '.o' => '.cc' do |t|
170
263
  sh "#{CXX} #{$CXXFLAGS} -c -o #{t.name} #{t.source}"
171
264
  end
172
265
 
173
- file ".depends.mf" do |t|
266
+ file ".depends.mf" => :config_h do |t|
174
267
  sh "g++ -MM #{$CXXFLAGS} #{CC_FILES.join ' '} | " +
175
268
  "sed -e :a -e N -e 's/\\n/\\$/g' -e ta | " +
176
269
  "sed -e 's/ *\\\\\\$ */ /g' -e 's/\\$/\\n/g' | sed -e 's/^/ext\\//' > #{t.name}"
@@ -181,5 +274,5 @@ end
181
274
  import ".depends.mf"
182
275
 
183
276
  CLEAN.include 'ext/*.o'
184
- CLOBBER.include SO_FILE, 'doc', '.yardoc', '.depends.mf'
277
+ CLOBBER.include SO_FILE, 'doc', '.yardoc', '.depends.mf', 'ext/config.h'
185
278
 
data/ext/avinput.cc CHANGED
@@ -131,6 +131,11 @@ FramePtr AVInput::read(void) throw (Error)
131
131
  return retVal;
132
132
  }
133
133
 
134
+ bool AVInput::status(void) const
135
+ {
136
+ return m_ic != NULL;
137
+ }
138
+
134
139
  int AVInput::width(void) const throw (Error)
135
140
  {
136
141
  ERRORMACRO( m_dec != NULL, Error, , "Video \"" << m_mrl << "\" is not open. "
@@ -197,6 +202,7 @@ VALUE AVInput::registerRubyClass( VALUE rbModule )
197
202
  rb_define_const( cRubyClass, "AV_TIME_BASE", INT2NUM( AV_TIME_BASE ) );
198
203
  rb_define_method( cRubyClass, "close", RUBY_METHOD_FUNC( wrapClose ), 0 );
199
204
  rb_define_method( cRubyClass, "read", RUBY_METHOD_FUNC( wrapRead ), 0 );
205
+ rb_define_method( cRubyClass, "status?", RUBY_METHOD_FUNC( wrapStatus ), 0 );
200
206
  rb_define_method( cRubyClass, "time_base", RUBY_METHOD_FUNC( wrapTimeBase ), 0 );
201
207
  rb_define_method( cRubyClass, "frame_rate", RUBY_METHOD_FUNC( wrapFrameRate ), 0 );
202
208
  rb_define_method( cRubyClass, "duration", RUBY_METHOD_FUNC( wrapDuration ), 0 );
@@ -246,6 +252,12 @@ VALUE AVInput::wrapRead( VALUE rbSelf )
246
252
  return retVal;
247
253
  }
248
254
 
255
+ VALUE AVInput::wrapStatus( VALUE rbSelf )
256
+ {
257
+ AVInputPtr *self; Data_Get_Struct( rbSelf, AVInputPtr, self );
258
+ return (*self)->status() ? Qtrue : Qfalse;
259
+ }
260
+
249
261
  VALUE AVInput::wrapTimeBase( VALUE rbSelf )
250
262
  {
251
263
  VALUE retVal = Qnil;
data/ext/avinput.hh CHANGED
@@ -16,10 +16,22 @@
16
16
  #ifndef AVINPUT_HH
17
17
  #define AVINPUT_HH
18
18
 
19
+ #ifdef HAVE_CONFIG_H
20
+ #include "config.h"
21
+ #endif
22
+
19
23
  #include <boost/shared_ptr.hpp>
20
24
  extern "C" {
25
+ #ifdef HAVE_LIBSWSCALE_INCDIR
21
26
  #include <libswscale/swscale.h>
27
+ #else
28
+ #include <ffmpeg/swscale.h>
29
+ #endif
30
+ #ifdef HAVE_LIBAVFORMAT_INCDIR
22
31
  #include <libavformat/avformat.h>
32
+ #else
33
+ #include <ffmpeg/avformat.h>
34
+ #endif
23
35
  }
24
36
  #include "rubyinc.hh"
25
37
  #include "error.hh"
@@ -32,6 +44,7 @@ public:
32
44
  virtual ~AVInput(void);
33
45
  void close(void);
34
46
  FramePtr read(void) throw (Error);
47
+ bool status(void) const;
35
48
  int width(void) const throw (Error);
36
49
  int height(void) const throw (Error);
37
50
  AVRational timeBase(void) throw (Error);
@@ -46,6 +59,7 @@ public:
46
59
  static VALUE wrapNew( VALUE rbClass, VALUE rbMRL );
47
60
  static VALUE wrapClose( VALUE rbSelf );
48
61
  static VALUE wrapRead( VALUE rbSelf );
62
+ static VALUE wrapStatus( VALUE rbSelf );
49
63
  static VALUE wrapTimeBase( VALUE rbSelf );
50
64
  static VALUE wrapFrameRate( VALUE rbSelf );
51
65
  static VALUE wrapDuration( VALUE rbSelf );
data/ext/avoutput.cc CHANGED
@@ -37,7 +37,11 @@ AVOutput::AVOutput( const string &mrl, int bitrate, int width, int height,
37
37
  if ( format == NULL ) format = guess_format( "mpeg", NULL, NULL );
38
38
  ERRORMACRO( format != NULL, Error, ,
39
39
  "Could not find suitable output format for \"" << mrl << "\"" );
40
+ #ifdef HAVE_LIBAVFORMAT_ALLOC_CONTEXT
40
41
  m_oc = avformat_alloc_context();
42
+ #else
43
+ m_oc = av_alloc_format_context();
44
+ #endif
41
45
  ERRORMACRO( m_oc != NULL, Error, , "Failure allocating format context" );
42
46
  m_oc->oformat = format;
43
47
  snprintf( m_oc->filename, sizeof( m_oc->filename ), "%s", mrl.c_str() );
@@ -131,7 +135,11 @@ void AVOutput::close(void)
131
135
  };
132
136
  m_video_st = NULL;
133
137
  if ( m_file_open ) {
138
+ #ifdef HAVE_BYTEIO_PTR
134
139
  url_fclose( m_oc->pb );
140
+ #else
141
+ url_fclose( &m_oc->pb );
142
+ #endif
135
143
  m_file_open = false;
136
144
  };
137
145
  av_free( m_oc );
data/ext/avoutput.hh CHANGED
@@ -16,10 +16,22 @@
16
16
  #ifndef AVOUTPUT_HH
17
17
  #define AVOUTPUT_HH
18
18
 
19
+ #ifdef HAVE_CONFIG_H
20
+ #include "config.h"
21
+ #endif
22
+
19
23
  #include <boost/shared_ptr.hpp>
20
24
  extern "C" {
25
+ #ifdef HAVE_LIBSWSCALE_INCDIR
21
26
  #include <libswscale/swscale.h>
27
+ #else
28
+ #include <ffmpeg/swscale.h>
29
+ #endif
30
+ #ifdef HAVE_LIBAVFORMAT_INCDIR
22
31
  #include <libavformat/avformat.h>
32
+ #else
33
+ #include <ffmpeg/avformat.h>
34
+ #endif
23
35
  }
24
36
  #include "rubyinc.hh"
25
37
  #include "error.hh"
data/ext/frame.cc CHANGED
@@ -23,9 +23,7 @@ Frame::Frame( const string &typecode, int width, int height, char *data ):
23
23
  VALUE mModule = rb_define_module( "Hornetseye" );
24
24
  VALUE cMalloc = rb_define_class_under( mModule, "Malloc", rb_cObject );
25
25
  VALUE cFrame = rb_define_class_under( mModule, "Frame", rb_cObject );
26
- VALUE rbSize = rb_funcall( cFrame, rb_intern( "storage_size" ), 3,
27
- rb_const_get( mModule, rb_intern( typecode.c_str() ) ),
28
- INT2NUM( width ), INT2NUM( height ) );
26
+ VALUE rbSize = INT2NUM( storageSize( typecode, width, height ) );
29
27
  VALUE rbMemory;
30
28
  if ( data != NULL ) {
31
29
  rbMemory = Data_Wrap_Struct( cMalloc, 0, 0, (void *)data );
@@ -67,3 +65,12 @@ void Frame::markRubyMember(void)
67
65
  rb_gc_mark( m_frame );
68
66
  }
69
67
 
68
+ int Frame::storageSize( const std::string &typecode, int width, int height )
69
+ {
70
+ VALUE mModule = rb_define_module( "Hornetseye" );
71
+ VALUE cFrame = rb_define_class_under( mModule, "Frame", rb_cObject );
72
+ return NUM2INT( rb_funcall( cFrame, rb_intern( "storage_size" ), 3,
73
+ rb_const_get( mModule, rb_intern( typecode.c_str() ) ),
74
+ INT2NUM( width ), INT2NUM( height ) ) );
75
+ }
76
+
data/ext/frame.hh CHANGED
@@ -32,6 +32,7 @@ public:
32
32
  char *data(void);
33
33
  VALUE rubyObject(void) { return m_frame; }
34
34
  void markRubyMember(void);
35
+ static int storageSize( const std::string &typecode, int width, int height );
35
36
  protected:
36
37
  VALUE m_frame;
37
38
  };
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 0
9
- version: 0.4.0
8
+ - 1
9
+ version: 0.4.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jan Wedekind
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-06 00:00:00 +01:00
17
+ date: 2010-10-08 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency