mkv.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * mkv.cpp : matroska demuxer
00003  *****************************************************************************
00004  * Copyright (C) 2003-2004 the VideoLAN team
00005  * $Id: 9928dc54cd06a9e5fa6de6bef9558a149e3e2d22 $
00006  *
00007  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
00008  *          Steve Lhomme <steve.lhomme@free.fr>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00023  *****************************************************************************/
00024 
00025 #ifndef _MKV_H_
00026 #define _MKV_H_
00027 
00028 /*****************************************************************************
00029  * Preamble
00030  *****************************************************************************/
00031 
00032 
00033 /* config.h may include inttypes.h, so make sure we define that option
00034  * early enough. */
00035 #define __STDC_FORMAT_MACROS 1
00036 #define __STDC_CONSTANT_MACROS 1
00037 #define __STDC_LIMIT_MACROS 1
00038 
00039 #ifdef HAVE_CONFIG_H
00040 # include "config.h"
00041 #endif
00042 
00043 #include <inttypes.h>
00044 
00045 #include <vlc_common.h>
00046 #include <vlc_plugin.h>
00047 
00048 #ifdef HAVE_TIME_H
00049 #   include <time.h>                                               /* time() */
00050 #endif
00051 
00052 #include <vlc_iso_lang.h>
00053 #include <vlc_meta.h>
00054 #include <vlc_charset.h>
00055 #include <vlc_input.h>
00056 #include <vlc_demux.h>
00057 
00058 #include <iostream>
00059 #include <cassert>
00060 #include <typeinfo>
00061 #include <string>
00062 #include <vector>
00063 #include <algorithm>
00064 
00065 #ifdef HAVE_DIRENT_H
00066 #   include <dirent.h>
00067 #endif
00068 
00069 /* libebml and matroska */
00070 #include "ebml/EbmlHead.h"
00071 #include "ebml/EbmlSubHead.h"
00072 #include "ebml/EbmlStream.h"
00073 #include "ebml/EbmlContexts.h"
00074 #include "ebml/EbmlVoid.h"
00075 #include "ebml/EbmlVersion.h"
00076 #include "ebml/StdIOCallback.h"
00077 
00078 #include "matroska/KaxAttachments.h"
00079 #include "matroska/KaxAttached.h"
00080 #include "matroska/KaxBlock.h"
00081 #include "matroska/KaxBlockData.h"
00082 #include "matroska/KaxChapters.h"
00083 #include "matroska/KaxCluster.h"
00084 #include "matroska/KaxClusterData.h"
00085 #include "matroska/KaxContexts.h"
00086 #include "matroska/KaxCues.h"
00087 #include "matroska/KaxCuesData.h"
00088 #include "matroska/KaxInfo.h"
00089 #include "matroska/KaxInfoData.h"
00090 #include "matroska/KaxSeekHead.h"
00091 #include "matroska/KaxSegment.h"
00092 #include "matroska/KaxTag.h"
00093 #include "matroska/KaxTags.h"
00094 #include "matroska/KaxTagMulti.h"
00095 #include "matroska/KaxTracks.h"
00096 #include "matroska/KaxTrackAudio.h"
00097 #include "matroska/KaxTrackVideo.h"
00098 #include "matroska/KaxTrackEntryData.h"
00099 #include "matroska/KaxContentEncoding.h"
00100 #include "matroska/KaxVersion.h"
00101 
00102 #include "ebml/StdIOCallback.h"
00103 
00104 #include <vlc_keys.h>
00105 
00106 extern "C" {
00107    #include "../mp4/libmp4.h"
00108 }
00109 #ifdef HAVE_ZLIB_H
00110 #   include <zlib.h>
00111 #endif
00112 
00113 #define MATROSKA_COMPRESSION_NONE  -1
00114 #define MATROSKA_COMPRESSION_ZLIB   0
00115 #define MATROSKA_COMPRESSION_BLIB   1
00116 #define MATROSKA_COMPRESSION_LZOX   2
00117 #define MATROSKA_COMPRESSION_HEADER 3
00118 
00119 #define MKVD_TIMECODESCALE 1000000
00120 
00121 #define MKV_IS_ID( el, C ) ( EbmlId( (*el) ) == C::ClassInfos.GlobalId )
00122 
00123 
00124 using namespace LIBMATROSKA_NAMESPACE;
00125 using namespace std;
00126 
00127 void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock,
00128                          mtime_t i_pts, mtime_t i_duration, bool f_mandatory );
00129 
00130 class attachment_c
00131 {
00132 public:
00133     attachment_c()
00134         :p_data(NULL)
00135         ,i_size(0)
00136     {}
00137     virtual ~attachment_c()
00138     {
00139         free( p_data );
00140     }
00141 
00142     std::string    psz_file_name;
00143     std::string    psz_mime_type;
00144     void          *p_data;
00145     int            i_size;
00146 };
00147 
00148 class matroska_segment_c;
00149 
00150 class matroska_stream_c
00151 {
00152 public:
00153     matroska_stream_c( demux_sys_t & demuxer )
00154         :p_in(NULL)
00155         ,p_es(NULL)
00156         ,sys(demuxer)
00157     {}
00158 
00159     virtual ~matroska_stream_c()
00160     {
00161         delete p_in;
00162         delete p_es;
00163     }
00164 
00165     IOCallback         *p_in;
00166     EbmlStream         *p_es;
00167 
00168     std::vector<matroska_segment_c*> segments;
00169 
00170     demux_sys_t                      & sys;
00171 };
00172 
00173 
00174 /*****************************************************************************
00175  * definitions of structures and functions used by this plugins
00176  *****************************************************************************/
00177 typedef struct
00178 {
00179 //    ~mkv_track_t();
00180 
00181     bool         b_default;
00182     bool         b_enabled;
00183     unsigned int i_number;
00184 
00185     int          i_extra_data;
00186     uint8_t      *p_extra_data;
00187 
00188     char         *psz_codec;
00189     bool         b_dts_only;
00190     bool         b_pts_only;
00191 
00192     uint64_t     i_default_duration;
00193     float        f_timecodescale;
00194     mtime_t      i_last_dts;
00195 
00196     /* video */
00197     es_format_t fmt;
00198     float       f_fps;
00199     es_out_id_t *p_es;
00200 
00201     /* audio */
00202     unsigned int i_original_rate;
00203 
00204     bool            b_inited;
00205     /* data to be send first */
00206     int             i_data_init;
00207     uint8_t         *p_data_init;
00208 
00209     /* hack : it's for seek */
00210     bool            b_search_keyframe;
00211     bool            b_silent;
00212 
00213     /* informative */
00214     const char   *psz_codec_name;
00215     const char   *psz_codec_settings;
00216     const char   *psz_codec_info_url;
00217     const char   *psz_codec_download_url;
00218 
00219     /* encryption/compression */
00220     int                    i_compression_type;
00221     KaxContentCompSettings *p_compression_data;
00222 
00223 } mkv_track_t;
00224 
00225 typedef struct
00226 {
00227     int     i_track;
00228     int     i_block_number;
00229 
00230     int64_t i_position;
00231     int64_t i_time;
00232 
00233     bool       b_key;
00234 } mkv_index_t;
00235 
00236 
00237 #endif /* _MKV_HPP_ */

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