]> git.sesse.net Git - vlc/blobdiff - modules/demux/mkv/mkv.hpp
demux: mkv: enforce valid frame rate
[vlc] / modules / demux / mkv / mkv.hpp
index 0b8964e416fda70b18eb44e462e20cbfe64f9b47..063891462fe164830b02a39675f74bbefd5c2f58 100644 (file)
@@ -1,25 +1,25 @@
 /*****************************************************************************
- * mkv.cpp : matroska demuxer
+ * mkv.hpp : matroska demuxer
  *****************************************************************************
- * Copyright (C) 2003-2004 the VideoLAN team
+ * Copyright (C) 2003-2005, 2008 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Steve Lhomme <steve.lhomme@free.fr>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #ifndef _MKV_H_
  * early enough. */
 #define __STDC_FORMAT_MACROS 1
 #define __STDC_CONSTANT_MACROS 1
+#define __STDC_LIMIT_MACROS 1
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
-#undef gettext
 
 #include <inttypes.h>
 
 #   include <time.h>                                               /* time() */
 #endif
 
-
-#include <vlc_codecs.h>               /* BITMAPINFOHEADER, WAVEFORMATEX */
-#include <vlc_iso_lang.h>
-#include "vlc_meta.h"
+#include <vlc_meta.h>
 #include <vlc_charset.h>
 #include <vlc_input.h>
 #include <vlc_demux.h>
+#include <vlc_aout.h> /* For reordering */
 
 #include <iostream>
 #include <cassert>
 #include <vector>
 #include <algorithm>
 
-#ifdef HAVE_DIRENT_H
-#   include <dirent.h>
-#endif
-
 /* libebml and matroska */
 #include "ebml/EbmlHead.h"
 #include "ebml/EbmlSubHead.h"
@@ -93,7 +87,7 @@
 #include "matroska/KaxSegment.h"
 #include "matroska/KaxTag.h"
 #include "matroska/KaxTags.h"
-#include "matroska/KaxTagMulti.h"
+//#include "matroska/KaxTagMulti.h"
 #include "matroska/KaxTracks.h"
 #include "matroska/KaxTrackAudio.h"
 #include "matroska/KaxTrackVideo.h"
 
 #include "ebml/StdIOCallback.h"
 
-#include "vlc_keys.h"
-
 extern "C" {
    #include "../mp4/libmp4.h"
 }
@@ -112,91 +104,104 @@ extern "C" {
 #   include <zlib.h>
 #endif
 
+#define MKV_DEBUG 0
+
 #define MATROSKA_COMPRESSION_NONE  -1
 #define MATROSKA_COMPRESSION_ZLIB   0
 #define MATROSKA_COMPRESSION_BLIB   1
 #define MATROSKA_COMPRESSION_LZOX   2
 #define MATROSKA_COMPRESSION_HEADER 3
 
-#define MKVD_TIMECODESCALE 1000000
-
-/**
- * What's between a directory and a filename?
- */
-#if defined( WIN32 )
-    #define DIRECTORY_SEPARATOR '\\'
-#else
-    #define DIRECTORY_SEPARATOR '/'
-#endif
+enum
+{
+    MATROSKA_ENCODING_SCOPE_ALL_FRAMES = 1,
+    MATROSKA_ENCODING_SCOPE_PRIVATE = 2,
+    MATROSKA_ENCODING_SCOPE_NEXT = 4 /* unsupported */
+};
 
+#define MKVD_TIMECODESCALE 1000000
 
-#define MKV_IS_ID( el, C ) ( EbmlId( (*el) ) == C::ClassInfos.GlobalId )
+#define MKV_IS_ID( el, C ) ( el != NULL && typeid( *el ) == typeid( C ) )
 
 
 using namespace LIBMATROSKA_NAMESPACE;
 using namespace std;
 
+void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock,
+                         mtime_t i_pts, mtime_t i_duration, bool f_mandatory );
+
 class attachment_c
 {
 public:
-    attachment_c()
-        :p_data(NULL)
-        ,i_size(0)
-    {}
-    virtual ~attachment_c()
+    attachment_c( const std::string& _psz_file_name, const std::string& _psz_mime_type, int _i_size )
+        :i_size(_i_size)
+        ,psz_file_name( _psz_file_name)
+        ,psz_mime_type( _psz_mime_type)
     {
-        free( p_data );
+        p_data = NULL;
     }
+    ~attachment_c() { free( p_data ); }
+
+    /* Allocs the data space. Returns true if allocation went ok */
+    bool init()
+    {
+        p_data = malloc( i_size );
+        return (p_data != NULL);
+    }
+
+    const char* fileName() const { return psz_file_name.c_str(); }
+    const char* mimeType() const { return psz_mime_type.c_str(); }
+    int         size() const    { return i_size; }
 
-    std::string    psz_file_name;
-    std::string    psz_mime_type;
     void          *p_data;
+private:
     int            i_size;
+    std::string    psz_file_name;
+    std::string    psz_mime_type;
 };
 
 class matroska_segment_c;
-
-class matroska_stream_c
+struct matroska_stream_c
 {
-public:
-    matroska_stream_c( demux_sys_t & demuxer )
-        :p_in(NULL)
-        ,p_es(NULL)
-        ,sys(demuxer)
-    {}
-
-    virtual ~matroska_stream_c()
+    matroska_stream_c() :p_io_callback(NULL) ,p_estream(NULL) {}
+    ~matroska_stream_c()
     {
-        delete p_in;
-        delete p_es;
+        delete p_io_callback;
+        delete p_estream;
     }
 
-    IOCallback         *p_in;
-    EbmlStream         *p_es;
+    IOCallback         *p_io_callback;
+    EbmlStream         *p_estream;
 
     std::vector<matroska_segment_c*> segments;
-
-    demux_sys_t                      & sys;
 };
 
 
 /*****************************************************************************
  * definitions of structures and functions used by this plugins
  *****************************************************************************/
-typedef struct
+class PrivateTrackData
 {
-//    ~mkv_track_t();
+public:
+    virtual ~PrivateTrackData() {}
+    virtual int32_t Init() { return 0; }
+};
 
+struct mkv_track_t
+{
     bool         b_default;
     bool         b_enabled;
+    bool         b_forced;
     unsigned int i_number;
 
-    int          i_extra_data;
+    unsigned int i_extra_data;
     uint8_t      *p_extra_data;
 
     char         *psz_codec;
     bool         b_dts_only;
+    bool         b_pts_only;
 
+    bool         b_no_duration;
     uint64_t     i_default_duration;
     float        f_timecodescale;
     mtime_t      i_last_dts;
@@ -208,6 +213,12 @@ typedef struct
 
     /* audio */
     unsigned int i_original_rate;
+    uint8_t i_chans_to_reorder;            /* do we need channel reordering */
+    uint8_t pi_chan_table[AOUT_CHAN_MAX];
+
+
+    /* Private track paramters */
+    PrivateTrackData *p_sys;
 
     bool            b_inited;
     /* data to be send first */
@@ -226,11 +237,16 @@ typedef struct
 
     /* encryption/compression */
     int                    i_compression_type;
+    uint32_t               i_encoding_scope;
     KaxContentCompSettings *p_compression_data;
 
-} mkv_track_t;
+    /* Matroska 4 new elements used by Opus */
+    mtime_t i_seek_preroll;
+    mtime_t i_codec_delay;
+
+};
 
-typedef struct
+struct mkv_index_t
 {
     int     i_track;
     int     i_block_number;
@@ -239,7 +255,7 @@ typedef struct
     int64_t i_time;
 
     bool       b_key;
-} mkv_index_t;
+};
 
 
 #endif /* _MKV_HPP_ */