Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
moving movie export into separate Exporter class
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Sep 23, 2008
1 parent 3697918 commit 48aadb0
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 25 deletions.
46 changes: 46 additions & 0 deletions ext/exporter.c
@@ -0,0 +1,46 @@
#include "rmov_ext.h"

VALUE cExporter;

static void exporter_free(struct RExporter *rExporter)
{
}

static void exporter_mark(struct RExporter *rExporter)
{
}

static VALUE exporter_new(VALUE klass)
{
struct RExporter *rExporter;
return Data_Make_Struct(klass, struct RExporter, exporter_mark, exporter_free, rExporter);
}

static VALUE exporter_export_to_file(VALUE obj, VALUE filepath)
{
OSErr err;
FSSpec fs;
Movie movie = MOVIE(rb_iv_get(obj, "@movie"));

if (rb_block_given_p())
SetMovieProgressProc(movie, (MovieProgressUPP)movie_progress_proc, rb_block_proc());

// Activate so QuickTime doesn't export a white frame
SetMovieActive(movie, TRUE);

// TODO add error handling
err = NativePathNameToFSSpec(RSTRING(filepath)->ptr, &fs, 0);
err = ConvertMovieToFile(movie, 0, &fs, 'MooV', 'TVOD', 0, 0, 0, 0);

if (rb_block_given_p())
SetMovieProgressProc(movie, 0, 0);

return Qnil;
}

void Init_quicktime_exporter()
{
cExporter = rb_define_class_under(mQuicktime, "Exporter", rb_cObject);
rb_define_alloc_func(cExporter, exporter_new);
rb_define_method(cExporter, "export", exporter_export_to_file, 1);
}
22 changes: 0 additions & 22 deletions ext/movie.c
Expand Up @@ -91,27 +91,6 @@ static VALUE movie_track_count(VALUE obj)
return INT2NUM(GetMovieTrackCount(MOVIE(obj)));
}

static VALUE movie_export_to_file(VALUE obj, VALUE filepath)
{
OSErr err;
FSSpec fs;

if (rb_block_given_p())
SetMovieProgressProc(MOVIE(obj), (MovieProgressUPP)movie_progress_proc, rb_block_proc());

// Activate so QuickTime doesn't export a white frame
SetMovieActive(MOVIE(obj), TRUE);

// TODO add error handling
err = NativePathNameToFSSpec(RSTRING(filepath)->ptr, &fs, 0);
err = ConvertMovieToFile(MOVIE(obj), 0, &fs, 'MooV', 'TVOD', 0, 0, 0, 0);

if (rb_block_given_p())
SetMovieProgressProc(MOVIE(obj), 0, 0);

return obj;
}

static VALUE movie_composite_movie(VALUE obj, VALUE src, VALUE position)
{
if (rb_block_given_p())
Expand Down Expand Up @@ -203,7 +182,6 @@ void Init_quicktime_movie()
rb_define_method(cMovie, "time_scale", movie_time_scale, 0);
rb_define_method(cMovie, "bounds", movie_bounds, 0);
rb_define_method(cMovie, "track_count", movie_track_count, 0);
rb_define_method(cMovie, "export", movie_export_to_file, 1);
rb_define_method(cMovie, "composite_movie", movie_composite_movie, 2);
rb_define_method(cMovie, "insert_movie", movie_insert_movie, 2);
rb_define_method(cMovie, "append_movie", movie_append_movie, 1);
Expand Down
1 change: 1 addition & 0 deletions ext/rmov_ext.c
Expand Up @@ -14,4 +14,5 @@ void Init_rmov_ext()
eInvalidArgument = rb_define_class_under(mQuicktime, "InvalidArgument", eQuicktime);
Init_quicktime_movie();
Init_quicktime_track();
Init_quicktime_exporter();
}
12 changes: 12 additions & 0 deletions ext/rmov_ext.h
Expand Up @@ -7,6 +7,7 @@ extern VALUE eQuicktime, eMovieLoaded, eInvalidArgument;
/*** MOVIE ***/

void Init_quicktime_movie();
OSErr movie_progress_proc(Movie movie, short message, short operation, Fixed percent, VALUE proc);

#define RMOVIE(obj) (Check_Type(obj, T_DATA), (struct RMovie*)DATA_PTR(obj))
#define MOVIE(obj) (RMOVIE(obj)->movie)
Expand All @@ -28,3 +29,14 @@ void Init_quicktime_track();
struct RTrack {
Track track;
};


/*** EXPORTER ***/

void Init_quicktime_exporter();

#define REXPORTER(obj) (Check_Type(obj, T_DATA), (struct RExporter*)DATA_PTR(obj))

struct RExporter {
QTAtomContainer atom;
};
1 change: 0 additions & 1 deletion ext/track.c
Expand Up @@ -4,7 +4,6 @@ VALUE cTrack;

static void track_free(struct RTrack *rTrack)
{
// TODO ensure I don't need to dispose the track or media here
}

static void track_mark(struct RTrack *rTrack)
Expand Down
10 changes: 10 additions & 0 deletions lib/quicktime/exporter.rb
@@ -0,0 +1,10 @@
module Quicktime
# see ext/exporter.c for additional methods
class Exporter
attr_reader :movie

def initialize(movie)
@movie = movie
end
end
end
10 changes: 9 additions & 1 deletion lib/quicktime/movie.rb
@@ -1,5 +1,5 @@
module Quicktime
# see rmov_ext for additional methods
# see ext/movie.c for additional methods
class Movie
def self.open(filepath)
new.load_from_file(filepath)
Expand Down Expand Up @@ -34,5 +34,13 @@ def audio_tracks
def video_tracks
tracks.select { |t| t.video? }
end

def exporter
Exporter.new(self)
end

def export(*args, &block)
exporter.export(*args, &block)
end
end
end
2 changes: 1 addition & 1 deletion lib/quicktime/track.rb
@@ -1,5 +1,5 @@
module Quicktime
# see rmov_ext for additional methods
# see ext/track.c for additional methods
class Track
def duration
raw_duration.to_f/time_scale
Expand Down
1 change: 1 addition & 0 deletions lib/rmov.rb
Expand Up @@ -4,3 +4,4 @@

require 'quicktime/movie'
require 'quicktime/track'
require 'quicktime/exporter'
6 changes: 6 additions & 0 deletions spec/quicktime/movie_spec.rb
Expand Up @@ -90,6 +90,12 @@
mov.duration.should == 0.6
@movie.duration.should == 2.5
end

it "should have an exporter with this movie" do
exporter = @movie.exporter
exporter.should be_kind_of(Quicktime::Exporter)
exporter.movie.should == @movie
end
end

describe "empty movie" do
Expand Down

0 comments on commit 48aadb0

Please sign in to comment.