Mercurial > hg > nginx-tests
annotate mp4.t @ 389:c24d1c0b4c73
Tests: fixed invocation of has_daemon().
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 08 Apr 2014 19:31:14 +0400 |
parents | 3d4506565f43 |
children | 7a65ebfdb02e |
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') |
388
3d4506565f43
Tests: more mp4 tests for exceeding start/end values.
Sergey Kandaurov <pluknet@nginx.com>
parents:
387
diff
changeset
|
28 ->plan(14)->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 | |
52 system('ffmpeg -loglevel quiet -y ' | |
53 . '-f lavfi -i testsrc=duration=10:size=320x200:rate=15 ' | |
54 . '-f lavfi -i testsrc=duration=20:size=320x200:rate=15 ' | |
55 . '-map 0:0 -map 1:0 -pix_fmt yuv420p -g 15 -c:v libx264 ' | |
56 . "${\($t->testdir())}/test.mp4") == 0 | |
57 or die "Can't create mp4 file: $!"; | |
58 | |
59 $t->run(); | |
60 | |
61 ############################################################################### | |
62 | |
63 is(durations($t, 0.0), '10.0 20.0', 'start zero'); | |
64 is(durations($t, 2), '8.0 18.0', 'start integer'); | |
65 is(durations($t, 7.1), '2.9 12.9', 'start float'); | |
66 | |
67 SKIP: { | |
388
3d4506565f43
Tests: more mp4 tests for exceeding start/end values.
Sergey Kandaurov <pluknet@nginx.com>
parents:
387
diff
changeset
|
68 skip 'no end argument support', 8 unless $t->has_version('1.5.13'); |
384 | 69 |
70 is(durations($t, 6, 9), '3.0 3.0', 'start end integer'); | |
71 is(durations($t, 2.7, 5.6), '2.9 2.9', 'start end float'); | |
72 | |
73 is(durations($t, undef, 9), '9.0 9.0', 'end integer'); | |
74 is(durations($t, undef, 5.6), '5.6 5.6', 'end float'); | |
75 | |
76 # invalid range results in ignoring end argument | |
77 | |
78 like(http_head('/test.mp4?start=1&end=1'), qr/200 OK/, 'zero range'); | |
79 like(http_head('/test.mp4?start=1&end=0'), qr/200 OK/, 'negative range'); | |
80 | |
387
ff2e9afde90d
Tests: adjusted mp4 test for end value beyond track duration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
384
diff
changeset
|
81 # start/end values exceeding track/file duration |
384 | 82 |
387
ff2e9afde90d
Tests: adjusted mp4 test for end value beyond track duration.
Sergey Kandaurov <pluknet@nginx.com>
parents:
384
diff
changeset
|
83 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
|
84 'end beyond short track'); |
388
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?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
|
86 |
3d4506565f43
Tests: more mp4 tests for exceeding start/end values.
Sergey Kandaurov <pluknet@nginx.com>
parents:
387
diff
changeset
|
87 } |
3d4506565f43
Tests: more mp4 tests for exceeding start/end values.
Sergey Kandaurov <pluknet@nginx.com>
parents:
387
diff
changeset
|
88 |
3d4506565f43
Tests: more mp4 tests for exceeding start/end values.
Sergey Kandaurov <pluknet@nginx.com>
parents:
387
diff
changeset
|
89 TODO: { |
3d4506565f43
Tests: more mp4 tests for exceeding start/end values.
Sergey Kandaurov <pluknet@nginx.com>
parents:
387
diff
changeset
|
90 local $TODO = 'not yet' unless $t->has_version('1.5.10'); |
3d4506565f43
Tests: more mp4 tests for exceeding start/end values.
Sergey Kandaurov <pluknet@nginx.com>
parents:
387
diff
changeset
|
91 |
3d4506565f43
Tests: more mp4 tests for exceeding start/end values.
Sergey Kandaurov <pluknet@nginx.com>
parents:
387
diff
changeset
|
92 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
|
93 'start beyond short track'); |
384 | 94 |
95 } | |
96 | |
97 like(http_head("/test.mp4?start=21"), qr!HTTP/1.1 500!, 'start beyond EOF'); | |
98 | |
99 # check for alerts, e.g., "zero buf in output", shouldn't be any | |
100 | |
101 like(`grep -F '[alert]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no alerts'); | |
102 | |
103 ############################################################################### | |
104 | |
105 sub durations { | |
106 my ($t, $start, $end) = @_; | |
107 my $path = $t->{_testdir} . '/frag.mp4'; | |
108 | |
109 my $uri = '/test.mp4'; | |
110 if (defined $start) { | |
111 $uri .= "?start=$start"; | |
112 if (defined $end) { | |
113 $uri .= "&end=$end"; | |
114 } | |
115 | |
116 } elsif (defined $end) { | |
117 $uri .= "?end=$end"; | |
118 } | |
119 | |
120 $t->write_file('frag.mp4', Test::Nginx::http_content(http_get($uri))); | |
121 | |
122 my $r = `ffprobe -show_streams $path 2>/dev/null`; | |
123 Test::Nginx::log_core('||', $r); | |
124 sprintf "%.1f %.1f", $r =~ /duration=(\d+\.\d+)/g; | |
125 } | |
126 | |
127 ############################################################################### |