virtual_segment.hpp

Go to the documentation of this file.
00001 
00002 /*****************************************************************************
00003  * mkv.cpp : matroska demuxer
00004  *****************************************************************************
00005  * Copyright (C) 2003-2004 the VideoLAN team
00006  * $Id$
00007  *
00008  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
00009  *          Steve Lhomme <steve.lhomme@free.fr>
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00024  *****************************************************************************/
00025 
00026 #ifndef _VIRTUAL_SEGMENT_HPP_
00027 #define _VIRTUAL_SEGMENT_HPP_
00028 
00029 #include "mkv.hpp"
00030 
00031 #include "matroska_segment.hpp"
00032 #include "chapters.hpp"
00033 
00034 // class holding hard-linked segment together in the playback order
00035 class virtual_segment_c
00036 {
00037 public:
00038     virtual_segment_c( matroska_segment_c *p_segment )
00039         :p_editions(NULL)
00040         ,i_sys_title(0)
00041         ,i_current_segment(0)
00042         ,i_current_edition(-1)
00043         ,psz_current_chapter(NULL)
00044     {
00045         linked_segments.push_back( p_segment );
00046 
00047         AppendUID( p_segment->p_segment_uid );
00048         AppendUID( p_segment->p_prev_segment_uid );
00049         AppendUID( p_segment->p_next_segment_uid );
00050     }
00051 
00052     void Sort();
00053     size_t AddSegment( matroska_segment_c *p_segment );
00054     void PreloadLinked( );
00055     mtime_t Duration( ) const;
00056     void Seek( demux_t & demuxer, mtime_t i_date, mtime_t i_time_offset, chapter_item_c *psz_chapter, int64_t i_global_position );
00057 
00058     inline chapter_edition_c *Edition()
00059     {
00060         if ( i_current_edition >= 0 && size_t(i_current_edition) < p_editions->size() )
00061             return (*p_editions)[i_current_edition];
00062         return NULL;
00063     }
00064 
00065     matroska_segment_c * Segment() const
00066     {
00067         if ( linked_segments.size() == 0 || i_current_segment >= linked_segments.size() )
00068             return NULL;
00069         return linked_segments[i_current_segment];
00070     }
00071 
00072     inline chapter_item_c *CurrentChapter() {
00073         return psz_current_chapter;
00074     }
00075 
00076     bool SelectNext()
00077     {
00078         if ( i_current_segment < linked_segments.size()-1 )
00079         {
00080             i_current_segment++;
00081             return true;
00082         }
00083         return false;
00084     }
00085 
00086     bool FindUID( KaxSegmentUID & uid ) const
00087     {
00088         for ( size_t i=0; i<linked_uids.size(); i++ )
00089         {
00090             if ( linked_uids[i] == uid )
00091                 return true;
00092         }
00093         return false;
00094     }
00095 
00096     bool UpdateCurrentToChapter( demux_t & demux );
00097     void PrepareChapters( );
00098 
00099     chapter_item_c *BrowseCodecPrivate( unsigned int codec_id,
00100                                         bool (*match)(const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size ),
00101                                         const void *p_cookie,
00102                                         size_t i_cookie_size );
00103     chapter_item_c *FindChapter( int64_t i_find_uid );
00104 
00105     std::vector<chapter_edition_c*>  *p_editions;
00106     int                              i_sys_title;
00107 
00108 protected:
00109     std::vector<matroska_segment_c*> linked_segments;
00110     std::vector<KaxSegmentUID>       linked_uids;
00111     size_t                           i_current_segment;
00112 
00113     int                              i_current_edition;
00114     chapter_item_c                   *psz_current_chapter;
00115 
00116     void                             AppendUID( const EbmlBinary * UID );
00117 };
00118 
00119 #endif

Generated on Tue May 25 08:04:55 2010 for VLC by  doxygen 1.5.6