demux: libmp4: fix regression in trun reading (fix #19170)
[vlc.git] / modules / demux / mp4 / minibox.h
blob5204ef529cae38739ea90b34292fcc3fbd4a6778
1 /*****************************************************************************
2 * minibox.h: minimal mp4 box iterator
3 *****************************************************************************
4 * Copyright (C) 2017 VideoLabs, VLC authors and VideoLAN
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
21 typedef struct
23 const uint8_t *p_buffer;
24 size_t i_buffer;
25 const uint8_t *p_payload;
26 size_t i_payload;
27 vlc_fourcc_t i_type;
28 } mp4_box_iterator_t;
30 static void mp4_box_iterator_Init( mp4_box_iterator_t *p_it,
31 const uint8_t *p_data, size_t i_data )
33 p_it->p_buffer = p_data;
34 p_it->i_buffer = i_data;
37 static bool mp4_box_iterator_Next( mp4_box_iterator_t *p_it )
39 while( p_it->i_buffer > 8 )
41 const uint8_t *p = p_it->p_buffer;
42 const size_t i_size = GetDWBE( p );
43 p_it->i_type = VLC_FOURCC(p[4], p[5], p[6], p[7]);
44 if( i_size >= 8 && i_size <= p_it->i_buffer )
46 p_it->p_payload = &p_it->p_buffer[8];
47 p_it->i_payload = i_size - 8;
48 /* update for next run */
49 p_it->p_buffer += i_size;
50 p_it->i_buffer -= i_size;
51 return true;
54 return false;