annotate range_mp4.t @ 390:7a65ebfdb02e

Tests: skip mp4 if ffmpeg does not support lavfi format.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 11 Apr 2014 17:24:34 +0400
parents 0d9aaa1c01ea
children 847ea345becb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
385
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for mp4 module with range filter module.
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 ###############################################################################
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 select STDERR; $| = 1;
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDOUT; $| = 1;
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24
390
7a65ebfdb02e Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents: 385
diff changeset
25 my $t = Test::Nginx->new()->has(qw/http mp4/)->has_daemon('ffmpeg');
385
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 $t->write_file_expand('nginx.conf', <<'EOF');
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 %%TEST_GLOBALS%%
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 daemon off;
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 events {
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 }
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 http {
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 %%TEST_GLOBALS_HTTP%%
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 server {
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 listen 127.0.0.1:8080;
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 server_name localhost;
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 location / {
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 mp4;
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 }
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 }
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 }
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 EOF
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49
390
7a65ebfdb02e Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents: 385
diff changeset
50 plan(skip_all => 'no lavfi')
7a65ebfdb02e Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents: 385
diff changeset
51 unless grep /lavfi/, `ffmpeg -loglevel quiet -formats`;
385
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 system('ffmpeg -loglevel quiet -y '
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 . '-f lavfi -i testsrc=duration=10:size=320x200:rate=15 '
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 . "-pix_fmt yuv420p -c:v libx264 ${\($t->testdir())}/test.mp4") == 0
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 or die "Can't create mp4 file: $!";
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56
390
7a65ebfdb02e Tests: skip mp4 if ffmpeg does not support lavfi format.
Sergey Kandaurov <pluknet@nginx.com>
parents: 385
diff changeset
57 $t->run()->plan(13);
385
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 ###############################################################################
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 # simply ensure that mp4 start argument works, we rely on this in range tests
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 my $fsz0 = http_head('/test.mp4') =~ /Content-Length: (\d+)/ && $1;
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 my $fsz = http_head('/test.mp4?start=1') =~ /Content-Length: (\d+)/ && $1;
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 isnt($fsz0, $fsz, 'mp4 start argument works');
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 my $t1;
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 TODO: {
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 local $TODO = 'not yet' unless $t->has_version('1.5.13');
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 # MP4 has minimally 16 byte ftyp object at start
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 my $start = $fsz - 10;
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 my $last = $fsz - 1;
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 $t1 = http_get_range('/test.mp4?start=1', 'Range: bytes=0-9');
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 like($t1, qr/206/, 'first bytes - 206 partial reply');
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 like($t1, qr/Content-Length: 10/, 'first bytes - content length');
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 like($t1, qr/Content-Range: bytes 0-9\/$fsz/, 'first bytes - content range');
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 $t1 = http_get_range('/test.mp4?start=1', 'Range: bytes=-10');
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 like($t1, qr/206/, 'final bytes - 206 partial reply');
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 like($t1, qr/Content-Length: 10/, 'final bytes - content length');
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 like($t1, qr/Content-Range: bytes $start-$last\/$fsz/,
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 'final bytes - content range');
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 $t1 = http_get_range('/test.mp4?start=1', 'Range: bytes=0-99');
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 like($t1, qr/206/, 'multi buffers - 206 partial reply');
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 like($t1, qr/Content-Length: 100/, 'multi buffers - content length');
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 like($t1, qr/Content-Range: bytes 0-99\/$fsz/,
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 'multi buffers - content range');
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 }
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 TODO: {
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 local $TODO = 'multipart range on mp4';
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 $t1 = http_get_range('/test.mp4?start=1', 'Range: bytes=0-10,11-99');
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100 like($t1, qr/206/, 'multipart range - 206 partial reply');
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 like($t1, qr/Content-Length: 100/, 'multipart range - content length');
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102 like($t1, qr/Content-Range: bytes 0-10,11-99\/$fsz/,
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 'multipart range - content range');
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 }
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 ###############################################################################
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 sub http_get_range {
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 my ($url, $extra) = @_;
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 return http(<<EOF);
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 HEAD $url HTTP/1.1
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 Host: localhost
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 Connection: close
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115 $extra
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 EOF
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 }
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119
0d9aaa1c01ea Tests: mp4 tests with range requests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120 ###############################################################################