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
* );
29 TT_TIMINGS_UNSPEC
= 0,
31 TT_TIMINGS_SEQUENTIAL
,
34 #define TT_FRAME_RATE 30
63 typedef struct tt_basenode_t tt_basenode_t
;
64 typedef struct tt_node_t tt_node_t
;
66 #define TT_NODE_BASE_MEMBERS \
69 tt_basenode_t *p_next;
79 tt_basenode_t
*p_child
;
82 vlc_dictionary_t attr_dict
;
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
)
109 static inline tt_time_t
tt_time_Create( vlc_tick_t i
)
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
;
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
);
139 static inline tt_time_t
tt_time_Add( tt_time_t t1
, tt_time_t t2
)
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
;
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
;