Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 39
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
File_Ogg_Speex
0.00% covered (danger)
0.00%
0 / 39
0.00% covered (danger)
0.00%
0 / 5
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
6
 getType
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 _decodeHeader
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 1
6
 getHeader
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 _decodeCommentsHeader
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/* vim: set expandtab tabstop=4 shiftwidth=4: */
3// +----------------------------------------------------------------------------+
4// | File_Ogg PEAR Package for Accessing Ogg Bitstreams                         |
5// | Copyright (c) 2005-2007                                                    |
6// | David Grant <david@grant.org.uk>                                           |
7// | Tim Starling <tstarling@wikimedia.org>                                     |
8// +----------------------------------------------------------------------------+
9// | This library is free software; you can redistribute it and/or              |
10// | modify it under the terms of the GNU Lesser General Public                 |
11// | License as published by the Free Software Foundation; either               |
12// | version 2.1 of the License, or (at your option) any later version.         |
13// |                                                                            |
14// | This library is distributed in the hope that it will be useful,            |
15// | but WITHOUT ANY WARRANTY; without even the implied warranty of             |
16// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU          |
17// | Lesser General Public License for more details.                            |
18// |                                                                            |
19// | You should have received a copy of the GNU Lesser General Public           |
20// | License along with this library; if not, write to the Free Software        |
21// | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA |
22// +----------------------------------------------------------------------------+
23use MediaWiki\TimedMediaHandler\Handlers\OggHandler\OggException;
24
25/**
26 * @author      David Grant <david@grant.org.uk>, Tim Starling <tstarling@wikimedia.org>
27 * @category    File
28 * @copyright   David Grant <david@grant.org.uk>, Tim Starling <tstarling@wikimedia.org>
29 * @license     http://www.gnu.org/copyleft/lesser.html GNU LGPL
30 * @link        http://pear.php.net/package/File_Ogg
31 * @link        http://www.speex.org/docs.html
32 * @package     File_Ogg
33 * @version     CVS: $Id: Speex.php,v 1.10 2005/11/16 20:43:27 djg Exp $
34 */
35class File_Ogg_Speex extends File_Ogg_Media
36{
37    /**
38     * @var     array
39     * @access  private
40     */
41    var $_header;
42
43    /**
44     * @access  private
45     * @var     string
46     */
47    var $_version;
48
49    /**
50     * @access  private
51     */
52    function __construct($streamSerial, $streamData, $filePointer)
53    {
54        parent::__construct($streamSerial, $streamData, $filePointer);
55        $this->_decodeHeader();
56        $this->_decodeCommentsHeader();
57        $endSec =
58            (intval(substr( $this->_lastGranulePos, 0, 8 ), 16 ) * pow(2, 32)
59            + intval(substr( $this->_lastGranulePos, 8, 8 ), 16 ))
60            / $this->_header['rate'];
61
62         $startSec     =
63            (intval(substr( $this->_firstGranulePos, 0, 8 ), 16 ) * pow(2, 32)
64            + intval(substr( $this->_firstGranulePos, 8, 8 ), 16 ))
65            / $this->_header['rate'];
66
67         //make sure the offset is worth taking into account oggz_chop related hack
68        if( $startSec > 1){
69            $this->_streamLength = $endSec - $startSec;
70            $this->_startOffset = $startSec;
71        }else{
72            $this->_streamLength = $endSec;
73        }
74      }
75
76    /**
77     * Get a short string describing the type of the stream
78     * @return string
79     */
80    function getType()
81    {
82        return 'Speex';
83    }
84
85    /**
86     * Decode the stream header
87     * @access  private
88     */
89    function _decodeHeader()
90    {
91        fseek($this->_filePointer, $this->_streamData['pages'][0]['body_offset'], SEEK_SET);
92        // The first 8 characters should be "Speex   ".
93        if (fread($this->_filePointer, 8) != 'Speex   ')
94            throw new OggException("Stream is undecodable due to a malformed header.", OGG_ERROR_UNDECODABLE);
95
96        $this->_version = fread($this->_filePointer, 20);
97        $this->_header = File_Ogg::_readLittleEndian($this->_filePointer, array(
98            'speex_version_id'      => 32,
99            'header_size'           => 32,
100            'rate'                  => 32,
101            'mode'                  => 32,
102            'mode_bitstream_version'=> 32,
103            'nb_channels'           => 32,
104            'bitrate'               => 32,
105            'frame_size'            => 32,
106            'vbr'                   => 32,
107            'frames_per_packet'     => 32,
108            'extra_headers'         => 32,
109            'reserved1'             => 32,
110            'reserved2'             => 32
111        ));
112        $this->_header['speex_version'] = $this->_version;
113    }
114
115    /**
116     * Get an associative array containing header information about the stream
117     * @access  public
118     * @return  array
119     */
120    function getHeader() {
121        return $this->_header;
122    }
123
124    /**
125     * Decode the comments header
126     * @access  private
127     */
128    function _decodeCommentsHeader()
129    {
130        fseek($this->_filePointer, $this->_streamData['pages'][1]['body_offset'], SEEK_SET);
131        $this->_decodeBareCommentsHeader();
132    }
133}
134?>