Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 547 lines (442 sloc) 18.587 kb
b946f17 @cassiomarques Job XML generation
authored
1 require 'spec_helper'
2
e298462 @cassiomarques Request and response parsing
authored
3 describe UEncode::Medium do
4 let(:medium) { UEncode::Medium.new }
b946f17 @cassiomarques Job XML generation
authored
5
6 before :each do
7 medium.configure_video do |c|
8 c.bitrate = 10000
9 c.codec = "mp4"
10 c.cbr = false
11 c.crop = nil
12 c.deinterlace = true
e298462 @cassiomarques Request and response parsing
authored
13 c.framerate = UEncode::FrameRate.new :numerator => 1000, :denominator => 1001
b946f17 @cassiomarques Job XML generation
authored
14 c.height = 500
15 c.keyframe_interval = 0
16 c.maxbitrate = 10000
17 c.par = nil
18 c.profile = "baseline"
19 c.passes = 1
20 c.stretch = false
21 c.width = 400
22 end
23
24 medium.configure_audio do |c|
25 c.codec = "aac"
26 c.bitrate = 15000
27 c.channels = 2
28 c.samplerate = 10000
29 end
30 end
31
32 describe "#configure_video" do
e298462 @cassiomarques Request and response parsing
authored
33 let(:medium) { UEncode::Medium.new }
3228e1c @cassiomarques Adds configuration for transcoding using hashes
authored
34 let(:config) { YAML::load_file("spec/fixtures/configuration.yaml") }
35 let(:video_config) { config["video"] }
36 let(:audio_config) { config["audio"] }
b946f17 @cassiomarques Job XML generation
authored
37
38 it { medium.video.bitrate.should == 10000 }
39 it { medium.video.codec.should == "mp4" }
40 it { medium.video.cbr.should == false }
41 it { medium.video.crop.should be_nil }
42 it { medium.video.deinterlace.should == true }
43 it { medium.video.framerate.numerator.should == 1000 }
44 it { medium.video.height.should == 500 }
45 it { medium.video.keyframe_interval.should == 0 }
46 it { medium.video.maxbitrate.should == 10000 }
47 it { medium.video.par.should be_nil }
48 it { medium.video.profile.should == "baseline" }
49 it { medium.video.passes.should == 1 }
50 it { medium.video.stretch.should == false }
51 it { medium.video.width.should == 400 }
3228e1c @cassiomarques Adds configuration for transcoding using hashes
authored
52
53 context "from a hash (video parameters)" do
54 subject { medium.video_config }
55
97f0566 @cassiomarques Fix framerate and par configuration through hashes
authored
56 before { medium.configure config }
57
3228e1c @cassiomarques Adds configuration for transcoding using hashes
authored
58 its(:bitrate) { should == video_config["bitrate"] }
59 its(:codec) { should == video_config["codec"] }
60 its(:cbr) { should == video_config["cbr"] }
61 its(:crop) { should == video_config["crop"] }
62 its(:deinterlace) { should == video_config["deinterlace"] }
97f0566 @cassiomarques Fix framerate and par configuration through hashes
authored
63 its(:framerate) { should == UEncode::FrameRate.new(video_config["framerate"]) }
3228e1c @cassiomarques Adds configuration for transcoding using hashes
authored
64 its(:height) { should == video_config["height"] }
65 its(:keyframe_interval) { should == video_config["keyframe_interval"] }
66 its(:maxbitrate) { should == video_config["maxbitrate"] }
97f0566 @cassiomarques Fix framerate and par configuration through hashes
authored
67 its(:par) { should == UEncode::Par.new(video_config["par"]) }
3228e1c @cassiomarques Adds configuration for transcoding using hashes
authored
68 its(:profile) { should == video_config["profile"] }
69 its(:passes) { should == video_config["passes"] }
70 its(:stretch) { should == video_config["stretch"] }
71 its(:width) { should == video_config["width"] }
72 end
73
74 context "from a hash (audio parameters)" do
75 before { medium.configure config }
76 subject { medium.audio_config }
77
78 its(:codec) { should == audio_config["codec"] }
79 its(:bitrate) { should == audio_config["bitrate"] }
80 its(:channels) { should == audio_config["channels"] }
81 its(:samplerate) { should == audio_config["samplerate"] }
82 end
b946f17 @cassiomarques Job XML generation
authored
83 end
84
85 describe "#configure_audio" do
e298462 @cassiomarques Request and response parsing
authored
86 let(:medium) { UEncode::Medium.new }
b946f17 @cassiomarques Job XML generation
authored
87
88 it { medium.audio.codec.should == "aac" }
89 it { medium.audio.bitrate.should == 15000 }
90 it { medium.audio.channels.should == 2 }
91 it { medium.audio.samplerate.should == 10000 }
92 end
93
94 context "video config default values" do
95 let(:medium_without_configuration) { described_class.new }
96
97 it { medium_without_configuration.video.cbr.should == false }
98 it { medium_without_configuration.video.deinterlace.should == false }
99 it { medium_without_configuration.video.profile.should == "main" }
100 it { medium_without_configuration.video.passes.should == 1 }
101 it { medium_without_configuration.video.stretch.should == false }
102 end
103
104 describe "#to_xml" do
105 let(:xml) { Nokogiri::XML medium.to_xml }
106
107 before :each do
108 medium.configure_video do |c|
e298462 @cassiomarques Request and response parsing
authored
109 c.crop = UEncode::Crop.new :width => 125, :height => 150, :x => 100, :y => 200
110 c.par = UEncode::Par.new :numerator => 10, :denominator => 11
b946f17 @cassiomarques Job XML generation
authored
111 end
112 end
113
114 it "has a root element named 'media'" do
115 xml.root.name.should == 'medium'
116 end
117
118 it "has the correct video configs" do
119 config = xml.xpath("//video")
120 config.xpath("//video/bitrate").text.should == "10000"
121 config.xpath("//video/codec").text.should == "mp4"
122 config.xpath("//cbr").text.should == "false"
123 config.xpath("//crop/width").text.should == "125"
124 config.xpath("//crop/height").text.should == "150"
125 config.xpath("//crop/x").text.should == "100"
126 config.xpath("//crop/y").text.should == "200"
127 config.xpath("//deinterlace").text.should == "true"
128 config.xpath("//framerate/numerator").text.should == "1000"
129 config.xpath("//framerate/denominator").text.should == "1001"
130 config.xpath("//video/height").text.should == "500"
131 config.xpath("//keyframe_interval").text.should == "0"
132 config.xpath("//maxbitrate").text.should == "10000"
133 config.xpath("//par/numerator").text.should == "10"
134 config.xpath("//par/denominator").text.should == "11"
135 config.xpath("//profile").text.should == "baseline"
136 config.xpath("//passes").text.should == "1"
137 config.xpath("//video/width").text.should == "400"
138 end
139
140 it "does not include the cbr video config when it's null" do
141 medium.configure_video { |c| c.cbr = nil }
142 Nokogiri::XML(medium.to_xml).xpath("//video/cbr").should be_empty
143 end
144
145 it "does not include the crop video config when it's null" do
146 medium.configure_video { |c| c.crop = nil }
147 Nokogiri::XML(medium.to_xml).xpath("//video/crop").should be_empty
148 end
149
150 it "does not include the deinterlace video config when it's null" do
151 medium.configure_video { |c| c.deinterlace = nil }
152 Nokogiri::XML(medium.to_xml).xpath("//video/deinterlace").should be_empty
153 end
154
155 it "does not include the framerate video config when it's null" do
156 medium.configure_video { |c| c.framerate = nil }
157 Nokogiri::XML(medium.to_xml).xpath("//video/framerate").should be_empty
158 end
159
160 it "does not include the height video config when it's null" do
161 medium.configure_video { |c| c.height = nil }
162 Nokogiri::XML(medium.to_xml).xpath("//video/height").should be_empty
163 end
164
165 it "does not include the keyframe_interval video config when it's null" do
166 medium.configure_video { |c| c.keyframe_interval = nil }
167 Nokogiri::XML(medium.to_xml).xpath("//video/keyframe_interval").should be_empty
168 end
169
170 it "does not include the maxbitrate video config when it's null" do
171 medium.configure_video { |c| c.maxbitrate = nil }
172 Nokogiri::XML(medium.to_xml).xpath("//video/maxbitrate").should be_empty
173 end
174
175 it "does not include the par video config when it's null" do
176 medium.configure_video { |c| c.par = nil }
177 Nokogiri::XML(medium.to_xml).xpath("//video/par").should be_empty
178 end
179
180 it "does not include the profile video config when it's null" do
181 medium.configure_video { |c| c.profile = nil }
182 Nokogiri::XML(medium.to_xml).xpath("//video/profile").should be_empty
183 end
184
185 it "does not include the passes video config when it's null" do
186 medium.configure_video { |c| c.passes = nil }
187 Nokogiri::XML(medium.to_xml).xpath("//video/passes").should be_empty
188 end
189
190 it "does not include the stretch video config when it's null" do
191 medium.configure_video { |c| c.stretch = nil }
192 Nokogiri::XML(medium.to_xml).xpath("//video/stretch").should be_empty
193 end
194
195 it "does not include the width video config when it's null" do
196 medium.configure_video { |c| c.width = nil }
197 Nokogiri::XML(medium.to_xml).xpath("//video/width").should be_empty
198 end
199
fa3d7de @cassiomarques Do not include the stretch video parameter if it's false
authored
200 it "does not include the stretch video config when it's false" do
201 medium.configure_video { |c| c.stretch = false }
202 Nokogiri::XML(medium.to_xml) .xpath("//video/stretch").should be_empty
203 end
204
b946f17 @cassiomarques Job XML generation
authored
205 it "has the correct audio configs" do
206 xml.xpath("//audio/codec").text.should == "aac"
207 xml.xpath("//audio/bitrate").text.should == "15000"
208 xml.xpath("//audio/channels").text.should == "2"
209 xml.xpath("//audio/samplerate").text.should == "10000"
210 end
211
212 it "does not include the bitrate audio config when it's null" do
213 medium.configure_audio { |c| c.bitrate = nil }
214 Nokogiri::XML(medium.to_xml).xpath("//audio/bitrate").should be_empty
215 end
216
217 it "does not include the channels audio config when it's null" do
218 medium.configure_audio { |c| c.channels = nil }
219 Nokogiri::XML(medium.to_xml).xpath("//audio/channels").should be_empty
220 end
221
222 it "does not include the samplerate audio config when it's null" do
223 medium.configure_audio { |c| c.samplerate = nil }
224 Nokogiri::XML(medium.to_xml).xpath("//audio/samplerate").should be_empty
225 end
226 end
227 end
228
e298462 @cassiomarques Request and response parsing
authored
229 describe UEncode::VideoOutput do
b946f17 @cassiomarques Job XML generation
authored
230 subject { described_class.new :destination => "http://foobar.com/bla.avi", :container => "mpeg4" }
231
232 its(:destination) { should == "http://foobar.com/bla.avi" }
233 its(:container) { should == "mpeg4" }
234
235
236 describe "#to_xml" do
237 let(:video_output) { described_class.new :destination => "http://foo.com/bar.mp4", :container => "mpeg4" }
238 let(:xml) { Nokogiri::XML video_output.to_xml }
239
240
241 it "has a root element named 'output'" do
242 xml.root.name.should == 'output'
243 end
244
245 it "has the correct destination value" do
246 xml.xpath("//output/video/destination").text.should == "http://foo.com/bar.mp4"
247 end
248
249 it "has the correct container value" do
250 xml.xpath("//output/video/container").text.should == "mpeg4"
251 end
252 end
253 end
254
e298462 @cassiomarques Request and response parsing
authored
255 describe UEncode::CaptureOutput do
b946f17 @cassiomarques Job XML generation
authored
256 subject { described_class.new({
257 :destination => "http://whatever.com/foo.jpg",
258 :rate => "at 20s",
259 :stretch => false
260 }) }
261
262 its(:destination) { should == "http://whatever.com/foo.jpg" }
263 its(:rate) { should == "at 20s" }
264 its(:stretch) { should == false }
265
266 context "default values" do
267 let(:capture) { described_class.new :rate => "every 10s" }
268
269 it { capture.stretch.should == false }
270 end
271
272 describe "#to_xml" do
e298462 @cassiomarques Request and response parsing
authored
273 let(:crop) { UEncode::Crop.new :width => 125, :height => 140, :x => 100, :y => 200 }
274 let(:size) { UEncode::Size.new :width => 400, :height => 500 }
b946f17 @cassiomarques Job XML generation
authored
275 let(:xml) {
276 Nokogiri::XML described_class.new(
277 :destination => "http://foo.com/bla.mp4",
278 :stretch => false,
279 :rate => 'every 10s',
280 :crop => crop,
281 :size => size
282 ).to_xml
283 }
284
285 it "has a root element named capture" do
286 xml.root.name.should == 'output'
287 end
288
289 it "has the correct value for the rate attribute" do
290 xml.xpath("//output/capture/rate").text.should == "every 10s"
291 end
292
293 it "has the correct value for the destination attribute" do
294 xml.xpath("//output/capture/destination").text.should == "http://foo.com/bla.mp4"
295 end
296
297 it "has the correct value for the crop attribute" do
298 xml.xpath("//output/capture/crop/width").text.should == "125"
299 xml.xpath("//output/capture/crop/height").text.should == "140"
300 end
301
302 it "has the correct value for the size attribute" do
303 xml.xpath("//output/capture/size/width").text.should == "400"
304 xml.xpath("//output/capture/size/height").text.should == "500"
305 end
306 end
307 end
308
e298462 @cassiomarques Request and response parsing
authored
309 describe UEncode::Crop do
b946f17 @cassiomarques Job XML generation
authored
310 subject { described_class.new :width => 100, :height => 200, :x => 100, :y => 150 }
311
312 its(:width) { should == 100 }
313 its(:height) { should == 200 }
314 its(:x) { should == 100 }
315 its(:y) { should = 150 }
316
317 describe "#to_xml" do
318 let(:xml) { Nokogiri::XML described_class.new(:width => 100, :height => 200, :x => 100, :y => 150).to_xml }
319
320 it "has a root element named 'crop'" do
321 xml.root.name.should == 'crop'
322 end
323
324 it "has the correct value for the width attribute" do
325 xml.xpath("//width").text.should == "100"
326 end
327
328 it "has the correct value for the height attribute" do
329 xml.xpath("//height").text.should == "200"
330 end
331
332 it "has the correct value for the x attribute" do
333 xml.xpath("//x").text.should == "100"
334 end
335
336 it "has the correct value for the y attribute" do
337 xml.xpath("//y").text.should == "150"
338 end
339 end
340 end
341
342 shared_examples_for "an element that represents a rate number" do
343 subject { described_class.new :numerator => numerator, :denominator => denominator }
344
345 its(:numerator) { should == numerator }
346 its(:denominator) { should == denominator }
347
348 describe "#to_xml" do
349 let(:xml) { Nokogiri::XML described_class.new(:numerator => numerator, :denominator => denominator).to_xml }
350
351 it "has a root element named '#{name}'" do
352 xml.root.name.should == name
353 end
354
355 it "has the correct value for the numerator attribute" do
356 xml.xpath("//numerator").text.should == numerator.to_s
357 end
358
359 it "has the correct value for the denominator attribute" do
360 xml.xpath("//denominator").text.should == denominator.to_s
361 end
362 end
363 end
364
97f0566 @cassiomarques Fix framerate and par configuration through hashes
authored
365 describe UEncode::VideoConfig do
366 let(:config) { described_class.new }
367
368 context "receiving a hash as the framerate" do
369 before { config.framerate = {:numerator => 123, :denominator => 345} }
370
371 it "converts it to a UEncode::FrameRate" do
372 config.framerate.should be_an_instance_of(UEncode::FrameRate)
373 end
374
375 it "the framerate has the correct numerator" do
376 config.framerate.numerator.should == 123
377 end
378
379 it "the framerate has the correct denominator" do
380 config.framerate.denominator.should == 345
381 end
382 end
383 end
384
e298462 @cassiomarques Request and response parsing
authored
385 describe UEncode::FrameRate do
b946f17 @cassiomarques Job XML generation
authored
386 let(:name) { "framerate" }
387 let(:numerator) { 1000 }
388 let(:denominator) { 1001 }
389
390 it_should_behave_like "an element that represents a rate number"
391 end
392
e298462 @cassiomarques Request and response parsing
authored
393 describe UEncode::Par do
b946f17 @cassiomarques Job XML generation
authored
394 let(:name) { "par" }
395 let(:numerator) { 10 }
396 let(:denominator) { 11 }
397
398 it_should_behave_like "an element that represents a rate number"
399 end
400
e298462 @cassiomarques Request and response parsing
authored
401 describe UEncode::Size do
b946f17 @cassiomarques Job XML generation
authored
402 subject { described_class.new :width => 100, :height => 200 }
403
404 its(:height) { should == 200 }
405 its(:width) { should == 100 }
406
407 describe "#to_xml" do
408 let(:xml) { Nokogiri::XML described_class.new(:width => 200, :height => 250).to_xml }
409
410 it "has a root element named 'size'" do
411 xml.root.name.should == 'size'
412 end
413
414 it "has the correct value for the width attribute" do
415 xml.xpath("//width").text.should == "200"
416 end
417
418 it "has the correct value for the height attribute" do
419 xml.xpath("//height").text.should == "250"
420 end
421 end
422 end
423
e298462 @cassiomarques Request and response parsing
authored
424 describe UEncode::Job do
b946f17 @cassiomarques Job XML generation
authored
425 subject { described_class.new :source => "http://foo.com/bar.avi", :userdata => "some text", :notify => "http://my_url.com" }
426
427 its(:source) { should == "http://foo.com/bar.avi" }
428 its(:userdata) { should == "some text" }
429 its(:notify) { should == "http://my_url.com" }
430 its(:items) { should == [] }
431
432 describe "#<<" do
433 it "adds new elements to items" do
434 subject << "foo"
435 subject.items.should == ["foo"]
436 end
437 end
438
439 it "is enumerable" do
440 subject << "foo"
441 subject << "bar"
442 subject.map { |item| item }.should == ["foo", "bar"]
443 end
444
445 describe "#to_xml" do
446 let(:xml) { Nokogiri::XML job.to_xml }
447
448 before :each do
4e98aff @chrisumbel added ability to specify customer key at job level
chrisumbel authored
449 video1 = UEncode::Medium.new
450 video1.configure_video do |c|
b946f17 @cassiomarques Job XML generation
authored
451 c.bitrate = 1000
452 c.codec = 'mp4'
453 end
454 video1.configure_audio do |c|
455 c.codec = 'aac'
456 end
e298462 @cassiomarques Request and response parsing
authored
457 video2 = UEncode::Medium.new
b946f17 @cassiomarques Job XML generation
authored
458 video2.configure_video do |c|
459 c.bitrate = 1500
460 c.codec = 'mpeg2'
461 end
462 video2.configure_audio do |c|
463 c.codec = 'passthru'
464 end
465 job << video1
466 job << video2
467
468 job.configure_video_output do |c|
469 c.destination = "http://whatever.com/foo1.mp4"
470 c.container = "mpeg4"
471 end
472
e298462 @cassiomarques Request and response parsing
authored
473 capture1 = UEncode::CaptureOutput.new :destination => "http://whatever.com/foo.zip", :rate => "every 30s"
b946f17 @cassiomarques Job XML generation
authored
474 job.add_capture capture1
e298462 @cassiomarques Request and response parsing
authored
475 capture2 = UEncode::CaptureOutput.new :destination => "http://whatever.com/bar.zip", :rate => "every 10s"
b946f17 @cassiomarques Job XML generation
authored
476 job.add_capture capture2
477 end
478
4e98aff @chrisumbel added ability to specify customer key at job level
chrisumbel authored
479 context 'overridden customer' do
480 let(:job) { UEncode::Job.new({
481 :customerkey => "0123456789",
482 :source => "http://whatever.com/foo.avi",
483 :userdata => "some text",
484 :notify => "http://notify.me/meh"
485 })}
486
487 it "has the correct overridden customer key value" do
488 xml.xpath("//job/customerkey").text.should == "0123456789"
489 end
490 end
491
492 context 'default customer' do
493 let(:job) { UEncode::Job.new({
494 :source => "http://whatever.com/foo.avi",
495 :userdata => "some text",
496 :notify => "http://notify.me/meh"
497 })}
498
499 it "has a root element named 'job'" do
500 xml.root.name.should == 'job'
501 end
502
503 it "has the correct default configured customer key value" do
504 xml.xpath("//job/customerkey").text.should == "1q2w3e4r5t"
505 end
506
507 it "has the correct source attribute" do
508 xml.xpath("//job/source").text.should == "http://whatever.com/foo.avi"
509 end
510
511 it "has the correct user data value" do
512 xml.xpath("//job/userdata").text.should == 'some text'
513 end
514
515 it "has the correct notify value" do
516 xml.xpath("//job/notify").text.should == "http://notify.me/meh"
517 end
518
519 it "does not include the userdata attribute when it's null" do
520 job.instance_variable_set :@userdata, nil
521 xml.xpath("//job/userdata").should be_empty
522 end
523
524 it "does not include the notify attribute when it's null" do
525 job.instance_variable_set :@notify, nil
526 xml.xpath("//job/notify").should be_empty
527 end
528
529 it "contains the correct content to represent each video output item" do
530 xml.xpath("//job/outputs/output/video/media/medium").length.should == 2
531 end
532
533 it "has the correct video output destination" do
534 xml.xpath("//job/outputs/output/video/destination").text.should == "http://whatever.com/foo1.mp4"
535 end
536
537 it "has the correct video output container" do
538 xml.xpath("//job/outputs/output/video/container").text.should == "mpeg4"
539 end
540
541 it "contains the correct content to represent the video captures" do
542 xml.xpath("//job/outputs/output/capture").length.should == 2
543 end
b946f17 @cassiomarques Job XML generation
authored
544 end
545 end
546 end
Something went wrong with that request. Please try again.