Permalink
Browse files

Test FFMPEG::StreamMap

  • Loading branch information...
1 parent eae7660 commit 0ed5415520a919e649fb26a2331f3ae4ac7d3960 @drbrain committed Sep 9, 2009
@@ -454,6 +454,10 @@ def inspect
]
end
+ def input?
+ @input
+ end
+
def encode_fifo(output_context, output_stream)
encoder = output_stream.codec_context
View
@@ -1,7 +1,15 @@
+##
+# Creates a Stream from a FormatContext. Streams may not be created without a
+# FormatContext.
+
class FFMPEG::Stream
inline :C do |builder|
FFMPEG.builder_defaults builder
+ builder.add_to_init <<-C
+ rb_undef_alloc_func(c);
+ C
+
##
# :singleton-method: from
@@ -129,6 +137,8 @@ class FFMPEG::Stream
builder.accessor :quality, 'double'
end
+ private_class_method :new
+
##
# FIFO for audio streams
@@ -1,17 +1,8 @@
-class FFMPEG::InvalidMap < FFMPEG::Error
-end
-
-#--
-# stream_map = StreamMap.new(input_format)
-# stream_map.map(input_format.video_stream, output_format.out_stream)
-# stream_map.map(input_format.audio_stream, output_format2.audio_stream)
-# stream_map.map(input_format.video_stream, output_format3.video_stream)
-# stream_map.map(input_format.audio_stream, output_format3.audio_stream)
-#++
-
class FFMPEG::StreamMap
- attr_reader :map, :input_format_context, :output_format_contexts
+ attr_reader :input_format_context
+ attr_reader :map
+ attr_reader :output_format_contexts
def initialize(input_format_context)
@input_format_context = input_format_context
@@ -20,24 +11,27 @@ def initialize(input_format_context)
end
def add(in_stream, out_stream)
- raise FFMPEG::InvalidMap, 'input and output stream types differ' unless
+ raise ArgumentError, 'input and output stream types differ' unless
in_stream.type == out_stream.type
- raise FFMPEG::InvalidMap, 'no format context for output stream' unless
- out_stream.format_context
unless in_stream.format_context == @input_format_context then
- raise FFMPEG::InvalidMap,
+ raise ArgumentError,
'input stream must belong to input format context'
end
+ if out_stream.format_context.input? then
+ raise ArgumentError,
+ 'output stream must belong to an output format context'
+ end
+
@output_format_contexts << out_stream.format_context unless
- @output_format_contexts.include?(out_stream.format_context)
+ @output_format_contexts.include? out_stream.format_context
(@map[in_stream.stream_index] ||= []) << out_stream
end
def empty?
- @map.keys.empty?
+ @map.empty?
end
end
@@ -21,6 +21,14 @@ def test_file_size
assert_equal 29998, @fc.file_size
end
+ def test_input_eh
+ assert @fc.input?
+
+ output = @FC.new @thumbs_out, true
+
+ refute output.input?
+ end
+
def test_input_format
assert_equal 'mov,mp4,m4a,3gp,3g2,mj2', @fc.input_format.name
end
@@ -0,0 +1,72 @@
+require 'ffmpeg/test_case'
+
+class TestFFMPEGStreamMap < FFMPEG::TestCase
+
+ def setup
+ super
+
+ @input_fc = FFMPEG::FormatContext.new @thumbs_up
+ @output_fc = FFMPEG::FormatContext.new @thumbs_out, true
+
+ @video = @output_fc.output_stream(FFMPEG::Codec::VIDEO, 'wmv',
+ :bit_rate => 202_396,
+ :width => 196, :height => 144,
+ :fps => FFMPEG.Rational(25, 1))
+
+ @audio = @output_fc.output_stream(FFMPEG::Codec::AUDIO, nil,
+ :bit_rate => 64_000,
+ :sample_rate => 16_000,
+ :channels => 1)
+
+ @sm = FFMPEG::StreamMap.new @input_fc
+ end
+
+ def test_add
+ @sm.add @input_fc.video_stream, @video
+ @sm.add @input_fc.audio_stream, @audio
+
+ expected = {
+ 0 => [@video],
+ 1 => [@audio],
+ }
+
+ assert_equal expected, @sm.map
+ end
+
+ def test_add_mismatch
+ e = assert_raises ArgumentError do
+ @sm.add @input_fc.video_stream, @audio
+ end
+
+ assert_equal 'input and output stream types differ', e.message
+ end
+
+ def test_add_not_output
+ e = assert_raises ArgumentError do
+ @sm.add @input_fc.video_stream, @input_fc.video_stream
+ end
+
+ assert_equal 'output stream must belong to an output format context',
+ e.message
+ end
+
+ def test_add_wrong_input_file
+ thumb = FFMPEG::FormatContext.new @thumbs_up
+
+ e = assert_raises ArgumentError do
+ @sm.add thumb.video_stream, @video
+ end
+
+ assert_equal 'input stream must belong to input format context', e.message
+ end
+
+ def test_empty_eh
+ assert @sm.empty?
+
+ @sm.add @input_fc.video_stream, @video
+
+ refute @sm.empty?
+ end
+
+end
+

0 comments on commit 0ed5415

Please sign in to comment.