Mercurial > hg > nginx-tests
annotate mp4.t @ 540:481d705b8610
Tests: SSL support in mail backends.
Socket is now embedded into every mail module.
Socket methods are wrapped where appropriate.
The new "SSL" extra flag specifies to accept connection over SSL.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 03 Apr 2015 00:11:38 +0300 |
parents | 847ea345becb |
children | 6c0a5903d0ae |
rev | line source |
---|---|
384 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for mp4 module. | |
7 # Ensures that requested stream duration is given with sane accuracy. | |
8 | |
9 ############################################################################### | |
10 | |
11 use warnings; | |
12 use strict; | |
13 | |
14 use Test::More; | |
15 | |
16 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
17 | |
18 use lib 'lib'; | |
19 use Test::Nginx; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
389
c24d1c0b4c73
Tests: fixed invocation of has_daemon().
Sergey Kandaurov <pluknet@nginx.com>
parents:
388
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http mp4/)->has_daemon('ffprobe') |
c24d1c0b4c73
Tests: fixed invocation of has_daemon().
Sergey Kandaurov <pluknet@nginx.com>
parents:
388
diff
changeset
|
27 ->has_daemon('ffmpeg') |
390
7a65ebfdb02e
Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
389
diff
changeset
|
28 ->write_file_expand('nginx.conf', <<'EOF'); |
384 | 29 |
30 %%TEST_GLOBALS%% | |
31 | |
32 daemon off; | |
33 | |
34 events { | |
35 } | |
36 | |
37 http { | |
38 %%TEST_GLOBALS_HTTP%% | |
39 | |
40 server { | |
41 listen 127.0.0.1:8080; | |
42 server_name localhost; | |
43 | |
44 location / { | |
45 mp4; | |
46 } | |
47 } | |
48 } | |
49 | |
50 EOF | |
51 | |
390
7a65ebfdb02e
Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
389
diff
changeset
|
52 plan(skip_all => 'no lavfi') |
7a65ebfdb02e
Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
389
diff
changeset
|
53 unless grep /lavfi/, `ffmpeg -loglevel quiet -formats`; |
384 | 54 system('ffmpeg -loglevel quiet -y ' |
55 . '-f lavfi -i testsrc=duration=10:size=320x200:rate=15 ' | |
56 . '-f lavfi -i testsrc=duration=20:size=320x200:rate=15 ' | |
57 . '-map 0:0 -map 1:0 -pix_fmt yuv420p -g 15 -c:v libx264 ' | |
58 . "${\($t->testdir())}/test.mp4") == 0 | |
59 or die "Can't create mp4 file: $!"; | |
60 | |
390
7a65ebfdb02e
Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
389
diff
changeset
|
61 $t->run()->plan(14); |
384 | 62 |
63 ############################################################################### | |
64 | |
65 is(durations($t, 0.0), '10.0 20.0', 'start zero'); | |
66 is(durations($t, 2), '8.0 18.0', 'start integer'); | |
67 is(durations($t, 7.1), '2.9 12.9', 'start float'); | |
68 | |
69 is(durations($t, 6, 9), '3.0 3.0', 'start end integer'); | |
70 is(durations($t, 2.7, 5.6), '2.9 2.9', 'start end float'); | |
71 | |
72 is(durations($t, undef, 9), '9.0 9.0', 'end integer'); | |
73 is(durations($t, undef, 5.6), '5.6 5.6', 'end float'); | |
74 | |
75 # invalid range results in ignoring end argument | |
76 | |
77 like(http_head('/test.mp4?start=1&end=1'), qr/200 OK/, 'zero range'); | |
78 like(http_head('/test.mp4?start=1&end=0'), qr/200 OK/, 'negative range'); | |
79 | |
387
ff2e9afde90d
Tests: adjusted mp4 test for end value beyond track duration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
384
diff
changeset
|
80 # start/end values exceeding track/file duration |
384 | 81 |
387
ff2e9afde90d
Tests: adjusted mp4 test for end value beyond track duration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
384
diff
changeset
|
82 unlike(http_head("/test.mp4?end=11"), qr!HTTP/1.1 500!, |
ff2e9afde90d
Tests: adjusted mp4 test for end value beyond track duration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
384
diff
changeset
|
83 'end beyond short track'); |
388
3d4506565f43
Tests: more mp4 tests for exceeding start/end values.
Sergey Kandaurov <pluknet@nginx.com>
parents:
387
diff
changeset
|
84 unlike(http_head("/test.mp4?end=21"), qr!HTTP/1.1 500!, 'end beyond EOF'); |
3d4506565f43
Tests: more mp4 tests for exceeding start/end values.
Sergey Kandaurov <pluknet@nginx.com>
parents:
387
diff
changeset
|
85 unlike(http_head("/test.mp4?start=11"), qr!HTTP/1.1 500!, |
3d4506565f43
Tests: more mp4 tests for exceeding start/end values.
Sergey Kandaurov <pluknet@nginx.com>
parents:
387
diff
changeset
|
86 'start beyond short track'); |
384 | 87 like(http_head("/test.mp4?start=21"), qr!HTTP/1.1 500!, 'start beyond EOF'); |
88 | |
89 # check for alerts, e.g., "zero buf in output", shouldn't be any | |
90 | |
91 like(`grep -F '[alert]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no alerts'); | |
92 | |
93 ############################################################################### | |
94 | |
95 sub durations { | |
96 my ($t, $start, $end) = @_; | |
97 my $path = $t->{_testdir} . '/frag.mp4'; | |
98 | |
99 my $uri = '/test.mp4'; | |
100 if (defined $start) { | |
101 $uri .= "?start=$start"; | |
102 if (defined $end) { | |
103 $uri .= "&end=$end"; | |
104 } | |
105 | |
106 } elsif (defined $end) { | |
107 $uri .= "?end=$end"; | |
108 } | |
109 | |
110 $t->write_file('frag.mp4', Test::Nginx::http_content(http_get($uri))); | |
111 | |
112 my $r = `ffprobe -show_streams $path 2>/dev/null`; | |
113 Test::Nginx::log_core('||', $r); | |
114 sprintf "%.1f %.1f", $r =~ /duration=(\d+\.\d+)/g; | |
115 } | |
116 | |
117 ############################################################################### |