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

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * mkv.cpp : matroska demuxer
  3.  *****************************************************************************
  4.  * Copyright (C) 2003-2004 the VideoLAN team
  5.  * $Id: 5347e75f319d689b951eaea36eed6e834ad35945 $
  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 _MATROSKA_SEGMENT_HPP_
  25. #define _MATROSKA_SEGMENT_HPP_
  26. #include "mkv.hpp"
  27. #include "Ebml_parser.hpp"
  28. class chapter_edition_c;
  29. class chapter_translation_c;
  30. class chapter_item_c;
  31. class matroska_segment_c
  32. {
  33. public:
  34.     matroska_segment_c( demux_sys_t & demuxer, EbmlStream & estream )
  35.         :segment(NULL)
  36.         ,es(estream)
  37.         ,i_timescale(MKVD_TIMECODESCALE)
  38.         ,i_duration(-1)
  39.         ,i_start_time(0)
  40.         ,i_seekhead_count(0)
  41.         ,i_seekhead_position(-1)
  42.         ,i_cues_position(-1)
  43.         ,i_tracks_position(-1)
  44.         ,i_info_position(-1)
  45.         ,i_chapters_position(-1)
  46.         ,i_tags_position(-1)
  47.         ,i_attachments_position(-1)
  48.         ,cluster(NULL)
  49.         ,i_block_pos(0)
  50.         ,i_cluster_pos(0)
  51.         ,i_start_pos(0)
  52.         ,p_segment_uid(NULL)
  53.         ,p_prev_segment_uid(NULL)
  54.         ,p_next_segment_uid(NULL)
  55.         ,b_cues(false)
  56.         ,i_index(0)
  57.         ,i_index_max(1024)
  58.         ,psz_muxing_application(NULL)
  59.         ,psz_writing_application(NULL)
  60.         ,psz_segment_filename(NULL)
  61.         ,psz_title(NULL)
  62.         ,psz_date_utc(NULL)
  63.         ,i_default_edition(0)
  64.         ,sys(demuxer)
  65.         ,ep(NULL)
  66.         ,b_preloaded(false)
  67.     {
  68.         p_indexes = (mkv_index_t*)malloc( sizeof( mkv_index_t ) * i_index_max );
  69.     }
  70.     virtual ~matroska_segment_c();
  71.     KaxSegment              *segment;
  72.     EbmlStream              & es;
  73.     /* time scale */
  74.     uint64_t                i_timescale;
  75.     /* duration of the segment */
  76.     mtime_t                 i_duration;
  77.     mtime_t                 i_start_time;
  78.     /* all tracks */
  79.     std::vector<mkv_track_t*> tracks;
  80.     /* from seekhead */
  81.     int                     i_seekhead_count;
  82.     int64_t                 i_seekhead_position;
  83.     int64_t                 i_cues_position;
  84.     int64_t                 i_tracks_position;
  85.     int64_t                 i_info_position;
  86.     int64_t                 i_chapters_position;
  87.     int64_t                 i_tags_position;
  88.     int64_t                 i_attachments_position;
  89.     KaxCluster              *cluster;
  90.     uint64                  i_block_pos;
  91.     uint64                  i_cluster_pos;
  92.     int64_t                 i_start_pos;
  93.     KaxSegmentUID           *p_segment_uid;
  94.     KaxPrevUID              *p_prev_segment_uid;
  95.     KaxNextUID              *p_next_segment_uid;
  96.     bool                    b_cues;
  97.     int                     i_index;
  98.     int                     i_index_max;
  99.     mkv_index_t             *p_indexes;
  100.     /* info */
  101.     char                    *psz_muxing_application;
  102.     char                    *psz_writing_application;
  103.     char                    *psz_segment_filename;
  104.     char                    *psz_title;
  105.     char                    *psz_date_utc;
  106.     /* !!!!! GCC 3.3 bug on Darwin !!!!! */
  107.     /* when you remove this variable the compiler issues an atomicity error */
  108.     /* this variable only works when using std::vector<chapter_edition_c> */
  109.     std::vector<chapter_edition_c*> stored_editions;
  110.     int                             i_default_edition;
  111.     std::vector<chapter_translation_c*> translations;
  112.     std::vector<KaxSegmentFamily*>  families;
  113.  
  114.     demux_sys_t                    & sys;
  115.     EbmlParser                     *ep;
  116.     bool                           b_preloaded;
  117.     bool Preload( );
  118.     bool LoadSeekHeadItem( const EbmlCallbacks & ClassInfos, int64_t i_element_position );
  119.     bool PreloadFamily( const matroska_segment_c & segment );
  120.     void ParseInfo( KaxInfo *info );
  121.     void ParseAttachments( KaxAttachments *attachments );
  122.     void ParseChapters( KaxChapters *chapters );
  123.     void ParseSeekHead( KaxSeekHead *seekhead );
  124.     void ParseTracks( KaxTracks *tracks );
  125.     void ParseChapterAtom( int i_level, KaxChapterAtom *ca, chapter_item_c & chapters );
  126.     void ParseTrackEntry( KaxTrackEntry *m );
  127.     void ParseCluster( );
  128.     void IndexAppendCluster( KaxCluster *cluster );
  129.     void LoadCues( KaxCues *cues );
  130.     void LoadTags( KaxTags *tags );
  131.     void InformationCreate( );
  132.     void Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_global_position );
  133.     int BlockGet( KaxBlock * &, KaxSimpleBlock * &, int64_t *, int64_t *, int64_t *);
  134.     int BlockFindTrackIndex( size_t *pi_track,
  135.                              const KaxBlock *, const KaxSimpleBlock * );
  136.     bool Select( mtime_t i_start_time );
  137.     void UnSelect( );
  138.     static bool CompareSegmentUIDs( const matroska_segment_c * item_a, const matroska_segment_c * item_b );
  139. };
  140. #endif