virtual_segment.hpp
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:4k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * mkv.cpp : matroska demuxer
  3.  *****************************************************************************
  4.  * Copyright (C) 2003-2004 the VideoLAN team
  5.  * $Id: bafbb580d6cc3858cc23439787f29a86cf43f0be $
  6.  *
  7.  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  8.  *          Steve Lhomme <steve.lhomme@free.fr>
  9.  *
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * (at your option) any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23.  *****************************************************************************/
  24. #ifndef _VIRTUAL_SEGMENT_HPP_
  25. #define _VIRTUAL_SEGMENT_HPP_
  26. #include "mkv.hpp"
  27. #include "matroska_segment.hpp"
  28. #include "chapters.hpp"
  29. // class holding hard-linked segment together in the playback order
  30. class virtual_segment_c
  31. {
  32. public:
  33.     virtual_segment_c( matroska_segment_c *p_segment )
  34.         :p_editions(NULL)
  35.         ,i_sys_title(0)
  36.         ,i_current_segment(0)
  37.         ,i_current_edition(-1)
  38.         ,psz_current_chapter(NULL)
  39.     {
  40.         linked_segments.push_back( p_segment );
  41.         AppendUID( p_segment->p_segment_uid );
  42.         AppendUID( p_segment->p_prev_segment_uid );
  43.         AppendUID( p_segment->p_next_segment_uid );
  44.     }
  45.     void Sort();
  46.     size_t AddSegment( matroska_segment_c *p_segment );
  47.     void PreloadLinked( );
  48.     mtime_t Duration( ) const;
  49.     void Seek( demux_t & demuxer, mtime_t i_date, mtime_t i_time_offset, chapter_item_c *psz_chapter, int64_t i_global_position );
  50.     inline chapter_edition_c *Edition()
  51.     {
  52.         if ( i_current_edition >= 0 && size_t(i_current_edition) < p_editions->size() )
  53.             return (*p_editions)[i_current_edition];
  54.         return NULL;
  55.     }
  56.     matroska_segment_c * Segment() const
  57.     {
  58.         if ( linked_segments.size() == 0 || i_current_segment >= linked_segments.size() )
  59.             return NULL;
  60.         return linked_segments[i_current_segment];
  61.     }
  62.     inline chapter_item_c *CurrentChapter() {
  63.         return psz_current_chapter;
  64.     }
  65.     bool SelectNext()
  66.     {
  67.         if ( i_current_segment < linked_segments.size()-1 )
  68.         {
  69.             i_current_segment++;
  70.             return true;
  71.         }
  72.         return false;
  73.     }
  74.     bool FindUID( KaxSegmentUID & uid ) const
  75.     {
  76.         for ( size_t i=0; i<linked_uids.size(); i++ )
  77.         {
  78.             if ( linked_uids[i] == uid )
  79.                 return true;
  80.         }
  81.         return false;
  82.     }
  83.     bool UpdateCurrentToChapter( demux_t & demux );
  84.     void PrepareChapters( );
  85.     chapter_item_c *BrowseCodecPrivate( unsigned int codec_id,
  86.                                         bool (*match)(const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size ),
  87.                                         const void *p_cookie,
  88.                                         size_t i_cookie_size );
  89.     chapter_item_c *FindChapter( int64_t i_find_uid );
  90.     std::vector<chapter_edition_c*>  *p_editions;
  91.     int                              i_sys_title;
  92. protected:
  93.     std::vector<matroska_segment_c*> linked_segments;
  94.     std::vector<KaxSegmentUID>       linked_uids;
  95.     size_t                           i_current_segment;
  96.     int                              i_current_edition;
  97.     chapter_item_c                   *psz_current_chapter;
  98.     void                             AppendUID( const EbmlBinary * UID );
  99. };
  100. #endif