/src/vlc/modules/demux/mkv/util.hpp
Line | Count | Source |
1 | | |
2 | | /***************************************************************************** |
3 | | * mkv.cpp : matroska demuxer |
4 | | ***************************************************************************** |
5 | | * Copyright (C) 2003-2004 VLC authors and VideoLAN |
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 it |
11 | | * under the terms of the GNU Lesser General Public License as published by |
12 | | * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details. |
19 | | * |
20 | | * You should have received a copy of the GNU Lesser General Public License |
21 | | * along with this program; if not, write to the Free Software Foundation, |
22 | | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
23 | | *****************************************************************************/ |
24 | | |
25 | | #include "mkv.hpp" |
26 | | |
27 | | namespace mkv { |
28 | | |
29 | | #ifdef HAVE_ZLIB_H |
30 | | int32_t zlib_decompress_extra( demux_t * p_demux, mkv_track_t & tk ); |
31 | | block_t *block_zlib_decompress( vlc_object_t *p_this, block_t *p_in_block ); |
32 | | #endif |
33 | | bool lzo1x_decompress_extra( demux_t * p_demux, mkv_track_t & tk ); |
34 | | block_t *block_lzo1x_decompress( vlc_object_t *p_this, block_t *p_in_block ); |
35 | | |
36 | | block_t *MemToBlock( uint8_t *p_mem, size_t i_mem, size_t offset); |
37 | | void handle_real_audio(demux_t * p_demux, mkv_track_t * p_tk, block_t * p_blk, vlc_tick_t i_pts); |
38 | | block_t *WEBVTT_Repack_Sample(block_t *p_block, bool b_webm = false, |
39 | | const uint8_t * = NULL, size_t = 0); |
40 | | void send_Block( demux_t * p_demux, mkv_track_t * p_tk, block_t * p_block, unsigned int i_number_frames, int64_t i_duration ); |
41 | | int UpdatePCR( demux_t * p_demux ); |
42 | | |
43 | | class ByteReader |
44 | | { |
45 | | public: |
46 | | ByteReader(const uint8_t *reader_, size_t reader_len_): |
47 | 80 | reader(reader_), reader_left(reader_len_) {} |
48 | | |
49 | 785 | bool skip(size_t bytes) { |
50 | 785 | if (error) return false; |
51 | 785 | if (reader_left < bytes) { |
52 | 0 | reader_left = 0; |
53 | 0 | error = true; |
54 | 0 | return false; |
55 | 0 | } |
56 | 785 | reader_left -= bytes; |
57 | 785 | reader += bytes; |
58 | 785 | return true; |
59 | 785 | } |
60 | | |
61 | 557 | uint16_t GetBE16() { |
62 | 557 | if (error) return 0; |
63 | 556 | if (reader_left < 2) { |
64 | 6 | reader_left = 0; |
65 | 6 | error = true; |
66 | 6 | return 0; |
67 | 6 | } |
68 | 550 | uint16_t v = GetWBE(reader); |
69 | 550 | reader_left -= 2; |
70 | 550 | reader += 2; |
71 | 550 | return v; |
72 | 556 | } |
73 | | |
74 | 80 | uint32_t GetBE32() { |
75 | 80 | if (error) return 0; |
76 | 80 | if (reader_left < 4) { |
77 | 0 | reader_left = 0; |
78 | 0 | error = true; |
79 | 0 | return 0; |
80 | 0 | } |
81 | 80 | uint16_t v = GetDWBE(reader); |
82 | 80 | reader_left -= 4; |
83 | 80 | reader += 4; |
84 | 80 | return v; |
85 | 80 | } |
86 | | |
87 | 79 | bool hasErrors() const { return error; } |
88 | | |
89 | | private: |
90 | | const uint8_t *reader; |
91 | | size_t reader_left; |
92 | | bool error = false; |
93 | | }; |
94 | | |
95 | 80 | #define SIZEOF_REALAUDIO_PRIVATE (4+2+2+12+2+2+4+(3*4)+2+2+2+2) |
96 | | |
97 | | class Cook_PrivateTrackData : public PrivateTrackData |
98 | | { |
99 | | public: |
100 | | Cook_PrivateTrackData(const uint8_t *reader, size_t reader_len): |
101 | 80 | bytes(reader, reader_len) {} |
102 | | ~Cook_PrivateTrackData(); |
103 | | bool Init() override; |
104 | | |
105 | | uint32_t coded_frame_size; |
106 | | uint16_t i_sub_packet_h; |
107 | | uint16_t i_frame_size; |
108 | | uint16_t i_subpacket_size; |
109 | | |
110 | | uint16_t i_rate; |
111 | | uint16_t i_bitspersample; |
112 | | uint16_t i_channels; |
113 | | |
114 | | std::vector<block_t *> p_subpackets; |
115 | | size_t i_subpacket = 0; |
116 | | private: |
117 | | ByteReader bytes; |
118 | | }; |
119 | | |
120 | | block_t * packetize_wavpack( const mkv_track_t &, uint8_t *, size_t); |
121 | | |
122 | | /* helper functions to print the mkv parse tree */ |
123 | | void MkvTree_va( demux_t& demuxer, int i_level, const char* fmt, va_list args); |
124 | | void MkvTree( demux_t & demuxer, int i_level, const char *psz_format, ... ); |
125 | | |
126 | | } // namespace |