demux: heif: send extradata with avif
[vlc.git] / modules / codec / ttml / ttml.h
blobd37559763241c30fda409295773f4de29ccd92c3
1 /*****************************************************************************
2 * ttml.h : TTML helpers
3 *****************************************************************************
4 * Copyright (C) 2017 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 int tt_OpenDemux( vlc_object_t* p_this );
22 void tt_CloseDemux( demux_t* p_demux );
24 int tt_OpenDecoder ( vlc_object_t * );
25 void tt_CloseDecoder ( vlc_object_t * );
27 enum
29 TT_TIMINGS_UNSPEC = 0,
30 TT_TIMINGS_PARALLEL,
31 TT_TIMINGS_SEQUENTIAL,
34 #define TT_FRAME_RATE 30
36 typedef struct
38 vlc_tick_t base;
39 unsigned frames;
40 //unsigned ticks;
41 } tt_time_t;
43 typedef struct
45 uint8_t i_type;
46 tt_time_t begin;
47 tt_time_t end;
48 tt_time_t dur;
49 } tt_timings_t;
51 struct tt_searchkey
53 tt_time_t time;
54 tt_time_t *p_last;
57 enum
59 TT_NODE_TYPE_ELEMENT,
60 TT_NODE_TYPE_TEXT,
63 typedef struct tt_basenode_t tt_basenode_t;
64 typedef struct tt_node_t tt_node_t;
66 #define TT_NODE_BASE_MEMBERS \
67 uint8_t i_type;\
68 tt_node_t *p_parent;\
69 tt_basenode_t *p_next;
71 struct tt_basenode_t
73 TT_NODE_BASE_MEMBERS
76 struct tt_node_t
78 TT_NODE_BASE_MEMBERS
79 tt_basenode_t *p_child;
80 char *psz_node_name;
81 tt_timings_t timings;
82 vlc_dictionary_t attr_dict;
85 typedef struct
87 TT_NODE_BASE_MEMBERS
88 char *psz_text;
89 } tt_textnode_t;
91 tt_node_t * tt_node_New( xml_reader_t* reader, tt_node_t* p_parent, const char* psz_node_name );
92 void tt_node_RecursiveDelete( tt_node_t *p_node );
93 int tt_node_NameCompare( const char* psz_tagname, const char* psz_pattern );
94 bool tt_node_HasChild( const tt_node_t *p_node );
96 int tt_nodes_Read( xml_reader_t *p_reader, tt_node_t *p_root_node );
98 void tt_timings_Resolve( tt_basenode_t *p_child, const tt_timings_t *p_container_timings,
99 tt_time_t **pp_array, size_t *pi_count );
100 bool tt_timings_Contains( const tt_timings_t *p_range, const tt_time_t * );
101 size_t tt_timings_FindLowerIndex( const tt_time_t *p_times, size_t i_times, tt_time_t time, bool *pb_found );
103 static inline void tt_time_Init( tt_time_t *t )
105 t->base = -1;
106 t->frames = 0;
109 static inline tt_time_t tt_time_Create( vlc_tick_t i )
111 tt_time_t t;
112 t.base = i;
113 t.frames = 0;
114 return t;
117 static inline bool tt_time_Valid( const tt_time_t *t )
119 return t->base != -1;
122 static inline vlc_tick_t tt_time_Convert( const tt_time_t *t )
124 if( !tt_time_Valid( t ) )
125 return VLC_TICK_INVALID;
126 else
127 return t->base + vlc_tick_from_samples( t->frames, TT_FRAME_RATE);
130 static inline int tt_time_Compare( const tt_time_t *t1, const tt_time_t *t2 )
132 vlc_tick_t ttt1 = tt_time_Convert( t1 );
133 vlc_tick_t ttt2 = tt_time_Convert( t2 );
134 if (ttt1 < ttt2)
135 return -1;
136 return ttt1 > ttt2;
139 static inline tt_time_t tt_time_Add( tt_time_t t1, tt_time_t t2 )
141 t1.base += t2.base;
142 t1.frames += t2.frames;
143 t1.base += vlc_tick_from_samples( t1.frames, TT_FRAME_RATE );
144 t1.frames = t1.frames % TT_FRAME_RATE;
145 return t1;
148 static inline tt_time_t tt_time_Sub( tt_time_t t1, tt_time_t t2 )
150 if( t2.frames > t1.frames )
152 unsigned diff = 1 + (t2.frames - t1.frames) / TT_FRAME_RATE;
153 t1.base -= vlc_tick_from_sec( diff );
154 t1.frames += diff * TT_FRAME_RATE;
156 t1.frames -= t2.frames;
157 t1.base -= t2.base;
158 return t1;