Mercurial > hg > nginx-tests
annotate mp4.t @ 1260:eadd24ccfda1
Tests: postponed startup in certain ssl certificate tests on win32.
At least, some win32 hosts exhibit a round-off error or some such in the
notBefore field of the certificate generated before starting nginx, such
that it can be set to the value one second ahead of the current time.
This manifests in spurious test failures due to certificate verify error
with a failure reason "certificate is not yet valid".
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 12 Dec 2017 12:53:53 +0300 |
parents | 766bcbb632ee |
children | 1923461981c9 |
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 | |
862
3021b44d0594
Tests: added mp4.t TODO for nginx built on i386 hosts by gcc 5.
Sergey Kandaurov <pluknet@nginx.com>
parents:
593
diff
changeset
|
16 use Config; |
3021b44d0594
Tests: added mp4.t TODO for nginx built on i386 hosts by gcc 5.
Sergey Kandaurov <pluknet@nginx.com>
parents:
593
diff
changeset
|
17 |
384 | 18 BEGIN { use FindBin; chdir($FindBin::Bin); } |
19 | |
20 use lib 'lib'; | |
21 use Test::Nginx; | |
22 | |
23 ############################################################################### | |
24 | |
25 select STDERR; $| = 1; | |
26 select STDOUT; $| = 1; | |
27 | |
389
c24d1c0b4c73
Tests: fixed invocation of has_daemon().
Sergey Kandaurov <pluknet@nginx.com>
parents:
388
diff
changeset
|
28 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
|
29 ->has_daemon('ffmpeg') |
390
7a65ebfdb02e
Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
389
diff
changeset
|
30 ->write_file_expand('nginx.conf', <<'EOF'); |
384 | 31 |
32 %%TEST_GLOBALS%% | |
33 | |
34 daemon off; | |
35 | |
36 events { | |
37 } | |
38 | |
39 http { | |
40 %%TEST_GLOBALS_HTTP%% | |
41 | |
42 server { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
43 listen 127.0.0.1:8080; |
384 | 44 server_name localhost; |
45 | |
46 location / { | |
47 mp4; | |
48 } | |
49 } | |
50 } | |
51 | |
52 EOF | |
53 | |
390
7a65ebfdb02e
Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents:
389
diff
changeset
|
54 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
|
55 unless grep /lavfi/, `ffmpeg -loglevel quiet -formats`; |
384 | 56 system('ffmpeg -loglevel quiet -y ' |
57 . '-f lavfi -i testsrc=duration=10:size=320x200:rate=15 ' | |
58 . '-f lavfi -i testsrc=duration=20:size=320x200:rate=15 ' | |
59 . '-map 0:0 -map 1:0 -pix_fmt yuv420p -g 15 -c:v libx264 ' | |
60 . "${\($t->testdir())}/test.mp4") == 0 | |
61 or die "Can't create mp4 file: $!"; | |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
62 system('ffmpeg -loglevel quiet -y ' |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
63 . '-f lavfi -i testsrc=duration=10:size=320x200:rate=15 ' |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
64 . '-f lavfi -i testsrc=duration=20:size=320x200:rate=15 ' |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
65 . '-map 0:0 -map 1:0 -pix_fmt yuv420p -g 15 -c:v libx264 ' |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
66 . '-movflags +faststart ' |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
67 . "${\($t->testdir())}/no_mdat.mp4") == 0 |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
68 or die "Can't create mp4 file: $!"; |
384 | 69 |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
70 $t->run()->plan(26); |
384 | 71 |
72 ############################################################################### | |
73 | |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
74 my $test_uri = '/test.mp4'; |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
75 |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
76 again: |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
77 |
384 | 78 is(durations($t, 0.0), '10.0 20.0', 'start zero'); |
79 is(durations($t, 2), '8.0 18.0', 'start integer'); | |
80 is(durations($t, 7.1), '2.9 12.9', 'start float'); | |
81 | |
82 is(durations($t, 6, 9), '3.0 3.0', 'start end integer'); | |
83 is(durations($t, 2.7, 5.6), '2.9 2.9', 'start end float'); | |
84 | |
85 is(durations($t, undef, 9), '9.0 9.0', 'end integer'); | |
86 is(durations($t, undef, 5.6), '5.6 5.6', 'end float'); | |
87 | |
88 # invalid range results in ignoring end argument | |
89 | |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
90 like(http_head("$test_uri?start=1&end=1"), qr/200 OK/, 'zero range'); |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
91 like(http_head("$test_uri?start=1&end=0"), qr/200 OK/, 'negative range'); |
384 | 92 |
387
ff2e9afde90d
Tests: adjusted mp4 test for end value beyond track duration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
384
diff
changeset
|
93 # start/end values exceeding track/file duration |
384 | 94 |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
95 unlike(http_head("$test_uri?end=11"), qr!HTTP/1.1 500!, |
387
ff2e9afde90d
Tests: adjusted mp4 test for end value beyond track duration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
384
diff
changeset
|
96 'end beyond short track'); |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
97 unlike(http_head("$test_uri?end=21"), qr!HTTP/1.1 500!, 'end beyond EOF'); |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
98 unlike(http_head("$test_uri?start=11"), qr!HTTP/1.1 500!, |
388
3d4506565f43
Tests: more mp4 tests for exceeding start/end values.
Sergey Kandaurov <pluknet@nginx.com>
parents:
387
diff
changeset
|
99 'start beyond short track'); |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
100 like(http_head("$test_uri?start=21"), qr!HTTP/1.1 500!, 'start beyond EOF'); |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
101 |
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
102 $test_uri = '/no_mdat.mp4', goto again unless $test_uri eq '/no_mdat.mp4'; |
384 | 103 |
104 ############################################################################### | |
105 | |
106 sub durations { | |
107 my ($t, $start, $end) = @_; | |
108 my $path = $t->{_testdir} . '/frag.mp4'; | |
109 | |
1037
92479d9429ff
Tests: added mp4 tests for moov atom before mdat atom.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
110 my $uri = $test_uri; |
384 | 111 if (defined $start) { |
112 $uri .= "?start=$start"; | |
113 if (defined $end) { | |
114 $uri .= "&end=$end"; | |
115 } | |
116 | |
117 } elsif (defined $end) { | |
118 $uri .= "?end=$end"; | |
119 } | |
120 | |
121 $t->write_file('frag.mp4', Test::Nginx::http_content(http_get($uri))); | |
122 | |
123 my $r = `ffprobe -show_streams $path 2>/dev/null`; | |
124 Test::Nginx::log_core('||', $r); | |
125 sprintf "%.1f %.1f", $r =~ /duration=(\d+\.\d+)/g; | |
126 } | |
127 | |
128 ############################################################################### |