diff options
author | Edgard Lima <edgard.lima@indt.org.br> | 2007-11-30 12:53:13 +0000 |
---|---|---|
committer | Edgard Lima <edgard.lima@indt.org.br> | 2007-11-30 12:53:13 +0000 |
commit | 794ad7ca1bcf6d339aca85d1391e168f14aaee12 (patch) | |
tree | a910e629c6c908912b23ca633f0ffa992bd4bd70 /ext/metadata/gstmetadataparse.c | |
parent | aedf92f4741b2010512e1b9c45b4bc462b33cb86 (diff) | |
download | gst-plugins-bad-794ad7ca1bcf6d339aca85d1391e168f14aaee12.tar.gz gst-plugins-bad-794ad7ca1bcf6d339aca85d1391e168f14aaee12.tar.bz2 gst-plugins-bad-794ad7ca1bcf6d339aca85d1391e168f14aaee12.zip |
Fixed get_range bug when injecting and stripping. And mux is almost done now.
Original commit message from CVS:
Fixed get_range bug when injecting and stripping. And mux is almost done now.
Diffstat (limited to 'ext/metadata/gstmetadataparse.c')
-rw-r--r-- | ext/metadata/gstmetadataparse.c | 137 |
1 files changed, 70 insertions, 67 deletions
diff --git a/ext/metadata/gstmetadataparse.c b/ext/metadata/gstmetadataparse.c index e4adaa6c..dd4771e3 100644 --- a/ext/metadata/gstmetadataparse.c +++ b/ext/metadata/gstmetadataparse.c @@ -870,6 +870,72 @@ done: } +static void +gst_metadata_parse_calculate_offsets (GstMetadataParse * filter) +{ + int i, j; + guint32 append_size; + guint32 bytes_striped, bytes_inject; + MetadataChunk *strip = filter->parse_data.strip_chunks.chunk; + MetadataChunk *inject = filter->parse_data.inject_chunks.chunk; + const gsize strip_len = filter->parse_data.strip_chunks.len; + const gsize inject_len = filter->parse_data.inject_chunks.len; + + bytes_striped = 0; + bytes_inject = 0; + + /* calculate the new position off injected chunks */ + j = 0; + for (i = 0; i < inject_len; ++i) { + for (; j < strip_len; ++j) { + if (strip[j].offset_orig >= inject[i].offset_orig) { + break; + } + bytes_striped += strip[j].size; + } + inject[i].offset = inject[i].offset_orig - bytes_striped + bytes_inject; + bytes_inject += inject[i].size; + } + + /* calculate append (doesnt make much sense, but, anyway..) */ + append_size = 0; + for (i = inject_len - 1; i >= 0; --i) { + if (inject[i].offset_orig == filter->duration_orig) + append_size += inject[i].size; + else + break; + } + if (append_size) { + guint8 *data; + + filter->append_buffer = gst_buffer_new_and_alloc (append_size); + GST_BUFFER_FLAG_SET (filter->append_buffer, GST_BUFFER_FLAG_READONLY); + data = GST_BUFFER_DATA (filter->append_buffer); + for (i = inject_len - 1; i >= 0; --i) { + if (inject[i].offset_orig == filter->duration_orig) { + memcpy (data, inject[i].data, inject[i].size); + data += inject[i].size; + } else { + break; + } + } + } + + /* do nothing but just call for consistence */ + metadata_lazy_update (&filter->parse_data); + + if (filter->duration_orig) { + filter->duration = filter->duration_orig; + for (i = 0; i < inject_len; ++i) { + filter->duration += inject[i].size; + } + for (i = 0; i < strip_len; ++i) { + filter->duration -= strip[i].size; + } + } + +} + /* * return: * -1 -> error @@ -900,52 +966,7 @@ gst_metadata_parse_parse (GstMetadataParse * filter, const guint8 * buf, } else if (ret > 0) { filter->need_more_data = TRUE; } else { - int i, j; - guint32 append_size; - guint32 bytes_striped, bytes_inject; - MetadataChunk *strip = filter->parse_data.strip_chunks.chunk; - MetadataChunk *inject = filter->parse_data.inject_chunks.chunk; - const gsize strip_len = filter->parse_data.strip_chunks.len; - const gsize inject_len = filter->parse_data.inject_chunks.len; - - bytes_striped = 0; - bytes_inject = 0; - - /* calculate the new position off injected chunks */ - for (i = 0; i < inject_len; ++i) { - for (j = 0; j < strip_len; ++i) { - if (strip[j].offset_orig >= inject[i].offset_orig) { - break; - } - inject[i].offset = inject[i].offset_orig - bytes_striped + bytes_inject; - bytes_striped += strip[j].size; - } - bytes_inject += inject[i].size; - } - - /* calculate append (doesnt make much sense, but, anyway..) */ - append_size = 0; - for (i = inject_len - 1; i >= 0; --i) { - if (inject[i].offset_orig == filter->duration_orig) - append_size += inject[i].size; - else - break; - } - if (append_size) { - guint8 *data; - - filter->append_buffer = gst_buffer_new_and_alloc (append_size); - GST_BUFFER_FLAG_SET (filter->append_buffer, GST_BUFFER_FLAG_READONLY); - data = GST_BUFFER_DATA (filter->append_buffer); - for (i = inject_len - 1; i >= 0; --i) { - if (inject[i].offset_orig == filter->duration_orig) { - memcpy (data, inject[i].data, inject[i].size); - data += inject[i].size; - } else { - break; - } - } - } + gst_metadata_parse_calculate_offsets (filter); filter->state = MT_STATE_PARSED; filter->need_more_data = FALSE; @@ -1122,6 +1143,7 @@ gst_metadata_parse_pull_range_parse (GstMetadataParse * filter) ret = TRUE; goto done; } + filter->duration_orig = duration; if (format != GST_FORMAT_BYTES) { /* this should never happen, but try chain anyway */ ret = TRUE; @@ -1161,25 +1183,6 @@ gst_metadata_parse_pull_range_parse (GstMetadataParse * filter) } while (res > 0); - if (res == 0) { - int i; - MetadataChunk *strip = filter->parse_data.strip_chunks.chunk; - MetadataChunk *inject = filter->parse_data.inject_chunks.chunk; - const gsize strip_len = filter->parse_data.strip_chunks.len; - const gsize inject_len = filter->parse_data.inject_chunks.len; - - filter->duration = duration; - filter->duration_orig = duration; - - for (i = 0; i < inject_len; ++i) { - filter->duration += inject[i].size; - } - for (i = 0; i < strip_len; ++i) { - filter->duration -= strip[i].size; - } - - } - done: return ret; @@ -1732,7 +1735,7 @@ gst_metadata_parse_change_state (GstElement * element, gst_metadata_parse_init_members (filter); filter->adapter_parsing = gst_adapter_new (); filter->taglist = gst_tag_list_new (); - metadata_init (&filter->parse_data); + metadata_init (&filter->parse_data, TRUE); break; default: break; @@ -1756,7 +1759,7 @@ gst_metadata_parse_change_state (GstElement * element, /* cleanup parser */ /* FIXME: could be improved a bit to avoid mem allocation */ metadata_dispose (&filter->parse_data); - metadata_init (&filter->parse_data); + metadata_init (&filter->parse_data, TRUE); } break; case GST_STATE_CHANGE_READY_TO_NULL: |