Skip to content

Commit

Permalink
Added Frames#size_of method
Browse files Browse the repository at this point in the history
  • Loading branch information
ucnv committed Apr 7, 2014
1 parent ecf4bff commit 64626a6
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/aviglitch/frames.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ def size
@meta.size
end

##
# Returns the number of the specific +frame_type+.
def size_of frame_type
detection = "is_#{frame_type.to_s.sub(/frames$/, 'frame')}?"
@meta.select { |m|
Frame.new(nil, m[:id], m[:flag]).send detection
}.size
end

def frames_data_as_io io = nil, block = nil #:nodoc:
io = Tempfile.new('tmep') if io.nil?
@meta = @meta.select do |m|
Expand Down
17 changes: 17 additions & 0 deletions spec/aviglitch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,23 @@
a.has_keyframe?.should be true
a.remove_all_keyframes!
a.has_keyframe?.should be false
end

it 'should count same number of specific frames' do
a = AviGlitch.open @in
dc1 = 0
dc2 = 0
a.frames.each do |f|
dc1 += 1 if f.is_deltaframe?
end
a.glitch(:deltaframe) do |d|
dc2 += 1
d
end

expect(dc1).to eq(dc2)



end

Expand Down
47 changes: 47 additions & 0 deletions spec/frames_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -510,4 +510,51 @@
expect(File.size(@out)).to be < File.size(@in)
end

it 'should count the size of specific frames' do
a = AviGlitch.open @in
f = a.frames

kc1 = f.size_of :keyframes
kc2 = f.size_of :keyframe
kc3 = f.size_of :iframes
kc4 = f.size_of :iframe

dc1 = f.size_of :deltaframes
dc2 = f.size_of :deltaframe
dc3 = f.size_of :pframes
dc4 = f.size_of :pframe

vc1 = f.size_of :videoframes
vc2 = f.size_of :videoframe

ac1 = f.size_of :audioframes
ac2 = f.size_of :audioframe

kc = dc = vc = ac = 0
a.frames.each do |x|
vc += x.is_videoframe? ? 1 : 0
kc += x.is_keyframe? ? 1 : 0
dc += x.is_deltaframe? ? 1 : 0
ac += x.is_audioframe? ? 1 : 0
end

a.close

expect(kc1).to eq(kc)
expect(kc2).to eq(kc)
expect(kc3).to eq(kc)
expect(kc4).to eq(kc)

expect(dc1).to eq(dc)
expect(dc2).to eq(dc)
expect(dc3).to eq(dc)
expect(dc4).to eq(dc)

expect(vc1).to eq(vc)
expect(vc2).to eq(vc)

expect(ac1).to eq(ac)
expect(ac2).to eq(ac)
end

end

0 comments on commit 64626a6

Please sign in to comment.