<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="generator" content="pandoc" />
<title></title>
<style type="text/css">code{white-space: pre;}</style>
</head>
<body>
<p>Hi Francois,</p>
<p>On 2017-01-12 15:51, Francois Cartegnie wrote:</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<pre><code> vlc | branch: master | Francois Cartegnie <fcvlcdev@free.fr> |
Thu Jan 12 15:46:36 2017 +0100| [d9d6893b17c83b7d92c57a3d1ed966023f74a8fb] |
committer: Francois Cartegnie
demux: ttml: replace timings on output
timings must be relative to document, which is no
longer true after splitting document.</code></pre>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<h3 id="httpgit.videolan.orggitweb.cgivlc.gitacommithd9d6893b17c83b7d92c57a3d1ed966023f74a8fb">http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d9d6893b17c83b7d92c57a3d1ed966023f74a8fb</h3>
</blockquote>
<pre><code> modules/demux/ttml.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 51 insertions(+), 4 deletions(-)
diff --git a/modules/demux/ttml.c b/modules/demux/ttml.c
index d887f02..32a3090 100644
--- a/modules/demux/ttml.c
+++ b/modules/demux/ttml.c
@@ -66,7 +66,27 @@ struct demux_sys_t
} times;
};
-static void tt_node_AttributesToText( struct vlc_memstream *p_stream, const tt_node_t* p_node )
+static char *tt_genTiming( int64_t i_time )
+{
+ if( i_time < 0 )
+ i_time = 0;
+ char *psz;
+ unsigned h, m, s, f;
+ f = (i_time % CLOCK_FREQ) / 10000;
+ i_time /= CLOCK_FREQ;</code></pre>
</blockquote>
<p>Why is <code>CLOCK_FREQ</code> used above?</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<pre><code> + h = i_time / 3600;
+ m = (i_time - h) / 3600;
+ s = (i_time - h - m);</code></pre>
</blockquote>
<p>The above looks very very odd. Given that it looks like you are trying to extract hours, minutes, and seconds, something like the below would be correct:</p>
<pre><code>h = i_time / 3600;
m = i_time % 3600 / 60;
s = i_time % 60;</code></pre>
<p>It is also worth noting that I personally feel that readability is harmed when variable declarations are separated from their initialization for no apparent reason.</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<pre><code> + if( asprintf( &psz, "%2.2u:%2.2u:%2.2u.%2.2u",
+ h, m, s, f ) < 0 )
+ psz = NULL;
+
+ return psz;
+}
+
+static void tt_node_AttributesToText( struct vlc_memstream *p_stream, const tt_node_t* p_node,
+ int64_t i_splicetime )
{
const vlc_dictionary_t* p_attr_dict = &p_node->attr_dict;
for( int i = 0; i < p_attr_dict->i_size; ++i )
@@ -74,9 +94,36 @@ static void tt_node_AttributesToText( struct vlc_memstream *p_stream, const tt_n
for ( vlc_dictionary_entry_t* p_entry = p_attr_dict->p_entries[i];
p_entry != NULL; p_entry = p_entry->p_next )
{
+ const char *psz_value = NULL;
+ char *psz_alloc = NULL;
+
+ if( !strcmp(p_entry->psz_key, "begin") )
+ {
+ if( p_node->timings.i_begin != -1 )
+ psz_value = psz_alloc = tt_genTiming( p_node->timings.i_begin - i_splicetime );
+ }
+ else if( !strcmp(p_entry->psz_key, "end") )
+ {
+ if( p_node->timings.i_end != -1 )
+ psz_value = psz_alloc = tt_genTiming( p_node->timings.i_end - i_splicetime );
+ }
+ else if( !strcmp(p_entry->psz_key, "dur") )
+ {
+ /* remove */
+ continue;
+ }</code></pre>
</blockquote>
<p>For all cases where <code>strcmp</code> is used above, <code>strcasecmp</code> might make more sense (given that the case of the attributes are not strictly limited to lower-case, afaik)?</p>
<blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;color:#500050">
<pre><code> + else
+ {
+ psz_value = (char const*)p_entry->p_value;
+ }
+
+ if( psz_value == NULL )
+ continue;
+
vlc_memstream_printf( p_stream, " %s=\"%s\"",
- p_entry->psz_key,
- (char const*)p_entry->p_value );
+ p_entry->psz_key, psz_value );
+
+ free( psz_alloc );
}
}
}
@@ -95,7 +142,7 @@ static void tt_node_ToText( struct vlc_memstream *p_stream, const tt_basenode_t
vlc_memstream_putc( p_stream, '<' );
vlc_memstream_puts( p_stream, p_node->psz_node_name );
- tt_node_AttributesToText( p_stream, p_node );
+ tt_node_AttributesToText( p_stream, p_node, i_playbacktime );
if( tt_node_HasChild( p_node ) )
{
_______________________________________________
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits</code></pre>
</blockquote>
</body>
</html>