1 /* 2 mediastreamer2 library - modular sound and video processing and streaming 3 Copyright (C) 2006 Simon MORLAT (simon.morlat@linphone.org) 4 5 This program is free software; you can redistribute it and/or 6 modify it under the terms of the GNU General Public License 7 as published by the Free Software Foundation; either version 2 8 of the License, or (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 */ 19 20 #ifndef _MKV_PARSER_H 21 #define _MKV_PARSER_H 22 23 #include "mediastreamer2/mscommon.h" 24 25 #define MAX_MKV_STRING_LENGTH 256 26 27 typedef struct _MKVReader MKVReader; 28 29 typedef struct { 30 int64_t timecode_scale; 31 double duration; 32 char muxing_app[MAX_MKV_STRING_LENGTH]; 33 char writing_app[MAX_MKV_STRING_LENGTH]; 34 } MKVSegmentInfo; 35 36 typedef struct { 37 uint8_t track_num; 38 uint32_t timestamp; // ms 39 bool_t keyframe; 40 uint8_t *data; 41 size_t data_length; 42 uint8_t *codec_state_data; 43 size_t codec_state_size; 44 } MKVBlock; 45 46 #define MKV_TRACK_TYPE_VIDEO 0x01 47 #define MKV_TRACK_TYPE_AUDIO 0x02 48 #define MKV_TRACK_TYPE_COMPLEX 0x03 49 #define MKV_TRACK_TYPE_LOGO 0x10 50 #define MKV_TRACK_TYPE_SUBTITLE 0x11 51 #define MKV_TRACK_TYPE_BUTTONS 0x12 52 #define MKV_TRACK_TYPE_CONTROL 0x20 53 54 typedef struct { 55 uint8_t num; 56 uint64_t UID; 57 uint8_t type; 58 bool_t enabled; 59 bool_t def; 60 bool_t forced; 61 bool_t lacing; 62 int min_cache; 63 int max_block_addition_id; 64 char codec_id[MAX_MKV_STRING_LENGTH]; 65 uint8_t *codec_private; 66 int codec_private_length; 67 int seek_preroll; 68 } MKVTrack; 69 70 typedef struct { 71 MKVTrack base; 72 bool_t interlaced; 73 int width; 74 int height; 75 double frame_rate; 76 } MKVVideoTrack; 77 78 typedef struct { 79 MKVTrack base; 80 int sampling_freq; 81 uint8_t channels; 82 } MKVAudioTrack; 83 84 typedef struct _MKVTrackReader MKVTrackReader; 85 86 /** 87 * @brief Open a MKV file for reading 88 * @param filename Name of the file to open 89 * @return A pointer on a MKVReader. NULL if opening fails 90 */ 91 MKVReader *mkv_reader_open(const char *filename); 92 93 /** 94 * @brief Close a MKV file. 95 * All associated track readers will be automatically destroyed 96 * @param obj MKVReader 97 */ 98 void mkv_reader_close(MKVReader *obj); 99 100 /** 101 * @brief Get information about the Matroska segment 102 * @param reader MKVReader 103 * @return Matroska segment information 104 */ 105 const MKVSegmentInfo *mkv_reader_get_segment_info(const MKVReader *reader); 106 107 /** 108 * @brief Get the default track for a specified track type 109 * @param r MKVReader object 110 * @param track_type Type of the track 111 * @return A pointer on a track descriptor 112 */ 113 const MKVTrack *mkv_reader_get_default_track(MKVReader *r, int track_type); 114 115 /** 116 * @brief Get the first track of the specified type 117 * @param r MKVReader object 118 * @param track_type Type of the track 119 * @return A track descriptor 120 */ 121 const MKVTrack *mkv_reader_get_first_track(MKVReader *r, int track_type); 122 123 /** 124 * @brief Create a track reader from its track number 125 * @param reader MKVReader 126 * @param track_num Track number 127 * @return A pointer on a track reader 128 */ 129 MKVTrackReader *mkv_reader_get_track_reader(MKVReader *reader, int track_num); 130 131 /** 132 * @brief Set the reading head of each assocated track reader at a specific position 133 * @param reader MKVReader 134 * @param pos_ms Position of the head in miliseconds 135 * @return The effective position of the head after the operation 136 */ 137 int mkv_reader_seek(MKVReader *reader, int pos_ms); 138 139 /** 140 * @brief Get the next block 141 * @param reader MKVReader 142 * @param block Block data 143 * @param end_of_track Return TRUE when the end of the track has been reached 144 */ 145 void mkv_track_reader_next_block(MKVTrackReader *reader, MKVBlock **block, bool_t *end_of_track); 146 147 /** 148 * @brief Reset the track reader. 149 * The reading head is set at the start of the track 150 * @param reader MKVReader 151 */ 152 void mkv_track_reader_reset(MKVTrackReader *reader); 153 154 /** 155 * @brief Destroy a track reader 156 * @param reader Track reader to destroy 157 */ 158 void mkv_track_reader_destroy(MKVTrackReader *reader); 159 160 /** 161 * @brief Free block data 162 * @param block MKV block to free 163 */ 164 void mkv_block_free(MKVBlock *block); 165 166 #endif 167