ext/mxfinfo/mxfinfo.c in mxfinfo-0.1.1 vs ext/mxfinfo/mxfinfo.c in mxfinfo-0.1.2

- old
+ new

@@ -72,12 +72,16 @@ static \ VALUE cio_get_##name (VALUE self) \ { \ AvidMXFInfo *info; \ Data_Get_Struct(self, AvidMXFInfo, info); \ - return rb_rational_new(INT2FIX((info-> attr ).numerator), \ - INT2FIX((info-> attr ).denominator)); \ + if((info->attr).denominator == 0) { \ + return Qnil; \ + } else { \ + return rb_rational_new(INT2FIX((info-> attr ).numerator), \ + INT2FIX((info-> attr ).denominator)); \ + } \ } #define CIO_INT_GETTER(name, attr) CIO_GENERIC_GETTER(INT2FIX, name, attr) #define CIO_UINT_GETTER(name, attr) CIO_GENERIC_GETTER(UINT2NUM, name, attr) #define CIO_INT64_GETTER(name, attr) CIO_GENERIC_GETTER(LL2NUM, name, attr) @@ -104,11 +108,11 @@ AmiReadInfoParams* params = (AmiReadInfoParams*) ptr; params->result = ami_read_info(params->fn, params->info, 1); return NULL; } -static +static VALUE cio_new(VALUE class, VALUE path) { Check_Type(path, T_STRING); const char *fn = StringValuePtr(path); @@ -142,11 +146,11 @@ rb_raise(rb_eStandardError, "Failed to read info."); break; } return Qnil; - } + } else { VALUE tdata = Data_Wrap_Struct(class, 0, cio_free, info); return tdata; } @@ -203,11 +207,11 @@ Data_Get_Struct(self, AvidMXFInfo, info); unsigned char *uid = (unsigned char*) &info->materialPackageUID; VALUE ary = rb_ary_new2(32); - for(unsigned int i = 0; i < 32; i++) + for(unsigned int i = 0; i < 32; i++) { rb_ary_store(ary, i, CHR2FIX(uid[i])); } return ary; @@ -236,11 +240,11 @@ AvidMXFInfo *info; Data_Get_Struct(self, AvidMXFInfo, info); if(info->isVideo && info->aspectRatio.denominator != 0) { return rb_rational_new(INT2FIX(info->aspectRatio.numerator), - INT2FIX(info->aspectRatio.denominator)); + INT2FIX(info->aspectRatio.denominator)); } else { return Qnil; } @@ -284,15 +288,15 @@ /* Module init. */ void Init_mxfinfo() { - m_mxfinfo = rb_define_module("MXFInfo"); + m_mxfinfo = rb_define_module("MXFInfo"); c_infoobject = rb_define_class_under(m_mxfinfo, "InfoObject", rb_cObject); rb_define_singleton_method(c_infoobject, "new", cio_new, 1); - + rb_define_method(c_infoobject, "clip_name", cio_get_clip_name, 0); rb_define_method(c_infoobject, "project_name", cio_get_project_name, 0); rb_define_method(c_infoobject, "clip_created", cio_get_clip_created, 0); rb_define_method(c_infoobject, "project_edit_rate", cio_get_project_edit_rate, 0); rb_define_method(c_infoobject, "clip_duration", cio_get_clip_duration, 0); @@ -300,10 +304,10 @@ /* AvidTaggedValue *userComments */ /* int numUserComments */ /* AvidTaggedValue *materialPackageAttributes */ /* int numMaterialPackageAttributes */ - + rb_define_method(c_infoobject, "num_video_tracks", cio_get_num_video_tracks, 0); rb_define_method(c_infoobject, "num_audio_tracks", cio_get_num_audio_tracks, 0); rb_define_method(c_infoobject, "tracks_string", cio_get_tracks_string, 0); rb_define_method(c_infoobject, "track_number", cio_get_track_number, 0); rb_define_method(c_infoobject, "is_video", cio_get_is_video, 0);