Mercurial > hg > nginx-tests
annotate mp4.t @ 1021:ebdf239722b9
Tests: relaxed proxy_cache_lock.t nolock tests to fix on Solaris.
Assumed that the order of responses being arrived in nolock case may be ignored.
An important part of such case is that the only last response should be cached.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 02 Sep 2016 12:17:35 +0300 |
parents | 882267679006 |
children | 92479d9429ff |
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: $!"; | |
62 | |
593
6c0a5903d0ae
Tests: cleanup now duplicating tests for no alerts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
63 $t->run()->plan(13); |
384 | 64 |
65 ############################################################################### | |
66 | |
67 is(durations($t, 0.0), '10.0 20.0', 'start zero'); | |
68 is(durations($t, 2), '8.0 18.0', 'start integer'); | |
69 is(durations($t, 7.1), '2.9 12.9', 'start float'); | |
70 | |
71 is(durations($t, 6, 9), '3.0 3.0', 'start end integer'); | |
72 is(durations($t, 2.7, 5.6), '2.9 2.9', 'start end float'); | |
73 | |
74 is(durations($t, undef, 9), '9.0 9.0', 'end integer'); | |
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
|
75 |
3021b44d0594
Tests: added mp4.t TODO for nginx built on i386 hosts by gcc 5.
Sergey Kandaurov <pluknet@nginx.com>
parents:
593
diff
changeset
|
76 TODO: { |
3021b44d0594
Tests: added mp4.t TODO for nginx built on i386 hosts by gcc 5.
Sergey Kandaurov <pluknet@nginx.com>
parents:
593
diff
changeset
|
77 local $TODO = 'not yet' |
3021b44d0594
Tests: added mp4.t TODO for nginx built on i386 hosts by gcc 5.
Sergey Kandaurov <pluknet@nginx.com>
parents:
593
diff
changeset
|
78 if $Config{myarchname} =~ /i.86/ && $t->has_module('built by gcc 5'); |
3021b44d0594
Tests: added mp4.t TODO for nginx built on i386 hosts by gcc 5.
Sergey Kandaurov <pluknet@nginx.com>
parents:
593
diff
changeset
|
79 |
384 | 80 is(durations($t, undef, 5.6), '5.6 5.6', 'end float'); |
81 | |
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
|
82 } |
3021b44d0594
Tests: added mp4.t TODO for nginx built on i386 hosts by gcc 5.
Sergey Kandaurov <pluknet@nginx.com>
parents:
593
diff
changeset
|
83 |
384 | 84 # invalid range results in ignoring end argument |
85 | |
86 like(http_head('/test.mp4?start=1&end=1'), qr/200 OK/, 'zero range'); | |
87 like(http_head('/test.mp4?start=1&end=0'), qr/200 OK/, 'negative range'); | |
88 | |
387
ff2e9afde90d
Tests: adjusted mp4 test for end value beyond track duration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
384
diff
changeset
|
89 # start/end values exceeding track/file duration |
384 | 90 |
387
ff2e9afde90d
Tests: adjusted mp4 test for end value beyond track duration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
384
diff
changeset
|
91 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
|
92 'end beyond short track'); |
388
3d4506565f43
Tests: more mp4 tests for exceeding start/end values.
Sergey Kandaurov <pluknet@nginx.com>
parents:
387
diff
changeset
|
93 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
|
94 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
|
95 'start beyond short track'); |
384 | 96 like(http_head("/test.mp4?start=21"), qr!HTTP/1.1 500!, 'start beyond EOF'); |
97 | |
98 ############################################################################### | |
99 | |
100 sub durations { | |
101 my ($t, $start, $end) = @_; | |
102 my $path = $t->{_testdir} . '/frag.mp4'; | |
103 | |
104 my $uri = '/test.mp4'; | |
105 if (defined $start) { | |
106 $uri .= "?start=$start"; | |
107 if (defined $end) { | |
108 $uri .= "&end=$end"; | |
109 } | |
110 | |
111 } elsif (defined $end) { | |
112 $uri .= "?end=$end"; | |
113 } | |
114 | |
115 $t->write_file('frag.mp4', Test::Nginx::http_content(http_get($uri))); | |
116 | |
117 my $r = `ffprobe -show_streams $path 2>/dev/null`; | |
118 Test::Nginx::log_core('||', $r); | |
119 sprintf "%.1f %.1f", $r =~ /duration=(\d+\.\d+)/g; | |
120 } | |
121 | |
122 ############################################################################### |