"Streaming" FLV through MogileFS

Eric Lambrecht eml at guba.com
Fri Apr 13 21:58:13 UTC 2007


...
> We've got a perlbal in front of our web servers that proxy out mogile 
> content. We made an update to perlbal so that if a cgi script returns an 
> 'X-REPROXY-FLV-START' header to perlbal (in addition to the 
> 'X-REPROXY-URL' header that points to the actual video in mogile), 
> perlbal makes a partial GET request against the backend mogile server 
> (lighttpd, in this case), and prefixes the response back to the client 
> with the 13 byte FLV header information.

... bah! I feel bad just leaving a tease like that. ;-)

Here's a patch against perlbal 1.52 that implements this. There might be 
an extraneous line or two in there - review it and understand it before 
you run it.

Credit to Giao Phan (casret at pobox.com) for the code.

Eric...
-------------- next part --------------
49a50,51
> use constant FLV_HEADER => 'FLV' . pack('CCNN', 1, 1, 9, 9);
> 
417a420
>     my $write_flv_header = 0;
429c432,440
<         $thd->header('Content-Length', $hd->header('Content-Length'));
---
>         #If this is a partial flv request we must clean up the ranges
>         #and pretend it was a non range request
>         if($client->{primary_res_hdrs}->header('X-REPROXY-FLV-START')) {
>             $write_flv_header = 1;
>             #13 bytes for the flv header
>             $thd->header('Content-Length', $hd->header('Content-Length') + 13);
>         } else {
>             $thd->header('Content-Length', $hd->header('Content-Length'));
>         } 
432a444
>         $thd->header('X-REPROXY-FLV-START', undef);
437c449,453
<         $thd->code($rescode) if $rescode == 206 || $rescode == 416;
---
>         if (($rescode == 416) || ($rescode == 206) and !$write_flv_header) {
>             $thd->code($rescode);
>             $thd->header('Accept-Ranges', $hd->header('Accept-Ranges')) if $hd->header('Accept-Ranges');
>             $thd->header('Content-Range', $hd->header('Content-Range')) if $hd->header('Content-Range');
>         } 
441c457,459
<     $client->write($thd->to_string_ref);
---
>     my $response_header = $thd->to_string_ref;
>     $client->write($response_header);
>     $client->write(FLV_HEADER) if $write_flv_header;


More information about the mogilefs mailing list