comparison range_mp4.t @ 385:0d9aaa1c01ea

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