summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2013-04-11 20:57:49 +0100
committerFridrich Strba <fridrich@documentfoundation.org>2013-04-13 10:05:37 +0000
commit1b1fe71be534fb05a11f741375e47f552e7a8914 (patch)
tree6b3dbf56f8caf08ed42bf80b76851c55a2f47afa
parent0ac18f7d54f22c0c0d40cc4b1cfe6059ef0b56c5 (diff)
Resolves: fdo#48039 use same algorithm for assigning get/set replacement ids
i.e. use the same algorithm for assigning replacement ids for both get and set exp fields. Otherwise, consider for ex. 1. fields exists with ids of 1 and 2 in master document 2. a field exists with id of 1 in subdocument and must be reassigned a new id to not collide with the pre existing master ids In get orig algorithm assigned first unused slot of master to subdocument field i.e. 0 unused in master, so subdocument:1 converted to master:0 In set orig algorithm sorted all used master slots and assigned largest used id plus 1 (therefore unused) to subdocument field i.e. largest id used in master is 2, so subdocument:1 converted to master:3 so get can't find set and error's out with: Error: Reference source not found Change-Id: Ie8758dc22cf8deeeeff079532284e57eeaf4a9bd (cherry picked from commit 74d942fb2396a268adfcc915e75b8b32fae851dc) Reviewed-on: https://gerrit.libreoffice.org/3347 Reviewed-by: Fridrich Strba <fridrich@documentfoundation.org> Tested-by: Fridrich Strba <fridrich@documentfoundation.org>
-rw-r--r--sw/source/core/fields/reffld.cxx13
1 files changed, 4 insertions, 9 deletions
diff --git a/sw/source/core/fields/reffld.cxx b/sw/source/core/fields/reffld.cxx
index 79b076b6e72c..71b1902eac8c 100644
--- a/sw/source/core/fields/reffld.cxx
+++ b/sw/source/core/fields/reffld.cxx
@@ -1007,14 +1007,9 @@ void _RefIdsMap::Init( SwDoc& rDoc, SwDoc& rDestDoc, sal_Bool bField )
GetFieldIdsFromDoc( rDestDoc, aIds );
GetFieldIdsFromDoc( rDoc, aDstIds );
- // Define the mappings now
- sal_uInt16 nMaxDstId = -1;
- if ( !aIds.empty() )
- nMaxDstId = *aIds.rbegin();
-
- // Map all the src fields to their value + nMaxDstId
+ // Map all the new src fields to the next available unused id
for ( std::set<sal_uInt16>::iterator pIt = aDstIds.begin(); pIt != aDstIds.end(); ++pIt )
- AddId( ++nMaxDstId, *pIt );
+ AddId( GetFirstUnusedId(aIds), *pIt );
// Change the Sequence number of all the SetExp fields in the destination document
SwFieldType* pType = rDoc.GetFldType( RES_SETEXPFLD, aName, false );
@@ -1037,9 +1032,9 @@ void _RefIdsMap::Init( SwDoc& rDoc, SwDoc& rDestDoc, sal_Bool bField )
bInit = sal_True;
}
-/// Get the lowest unused ID in the passed set.
+/// Get the lowest number unused in the passed set.
/// @param[in] rIds The set of used ID numbers.
-/// @returns The lowest unused ID.
+/// @returns The lowest number unused by the passed set
sal_uInt16 _RefIdsMap::GetFirstUnusedId( std::set<sal_uInt16> &rIds )
{
sal_uInt16 num(0);
='#n1494'>1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717
/* GStreamer
 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */


#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstasfdemux.h"
#include "asfheaders.h"

/* elementfactory information */
static GstElementDetails gst_asf_demux_details = {
  "ASF Demuxer",
  "Codec/Demuxer",
  "LGPL",
  "Demultiplexes ASF Streams",
  VERSION,
  "Owen Fraser-Green <owen@discobabe.net>",
  "(C) 2002",
};

static GstCaps* asf_asf_type_find (GstBuffer *buf, gpointer private);
static GstCaps* asf_wma_type_find (GstBuffer *buf, gpointer private);
static GstCaps* asf_wax_type_find (GstBuffer *buf, gpointer private);
static GstCaps* asf_wmv_type_find (GstBuffer *buf, gpointer private);
static GstCaps* asf_wvx_type_find (GstBuffer *buf, gpointer private);
static GstCaps* asf_wm_type_find (GstBuffer *buf, gpointer private);

/* typefactory for 'asf' */
static GstTypeDefinition asf_type_definitions[] = {
  { "asfdemux_video/asf",
    "video/x-ms-asf",
    ".asf .asx",
    asf_asf_type_find },
  { "asfdemux_video/wma",
    "video/x-ms-wma",
    ".wma",
    asf_wma_type_find },
  { "asfdemux_video/wax",
    "video/x-ms-wax",
    ".wax",
    asf_wax_type_find },
  { "asfdemux_video/wmv",
    "video/x-ms-wmv",
    ".wmv",
    asf_wmv_type_find },
  { "asfdemux_video/wvx",
    "video/x-ms-wvx",
    ".wvx",
    asf_wvx_type_find },
  { "asfdemux_video/wm",
    "video/x-ms-wm",
    ".wm",
    asf_wm_type_find },
  { NULL, NULL, NULL, NULL }
};

static GstCaps*
asf_asf_type_find (GstBuffer *buf, gpointer private)
{
  GstCaps *new;

  new = gst_caps_new (
                  "asf_type_find",
                  "video/x-ms-asf",
                  gst_props_new ("asfversion",
				 GST_PROPS_INT (1),
				 NULL));
  return new;
}

static GstCaps*
asf_wma_type_find (GstBuffer *buf, gpointer private)
{
  GstCaps *new;

  new = gst_caps_new (
                  "asf_type_find",
                  "video/x-ms-asf",
                  gst_props_new ("asfversion",
				 GST_PROPS_INT (1),
				 NULL));
  return new;
}

static GstCaps*
asf_wax_type_find (GstBuffer *buf, gpointer private)
{
  GstCaps *new;

  new = gst_caps_new (
                  "asf_type_find",
                  "video/x-ms-asf",
                  gst_props_new ("asfversion",
				 GST_PROPS_INT (1),
				 NULL));
  return new;
}

static GstCaps*
asf_wmv_type_find (GstBuffer *buf, gpointer private)
{
  GstCaps *new;

  new = gst_caps_new (
                  "asf_type_find",
                  "video/x-ms-asf",
                  gst_props_new ("asfversion",
				 GST_PROPS_INT (1),
				 NULL));
  return new;
}

static GstCaps*
asf_wvx_type_find (GstBuffer *buf, gpointer private)
{
  GstCaps *new;

  new = gst_caps_new (
                  "asf_type_find",
                  "video/x-ms-asf",
                  gst_props_new ("asfversion",
				 GST_PROPS_INT (1),
				 NULL));
  return new;
}

static GstCaps*
asf_wm_type_find (GstBuffer *buf, gpointer private)
{
  GstCaps *new;

  new = gst_caps_new (
                  "asf_type_find",
                  "video/x-ms-asf",
                  gst_props_new ("asfversion",
				 GST_PROPS_INT (1),
				 NULL));
  return new;
}

GST_PAD_TEMPLATE_FACTORY (sink_factory,
  "sink",
  GST_PAD_SINK,
  GST_PAD_ALWAYS,
  GST_CAPS_NEW ("asf_asf_demux_sink",
		"video/x-asf",
		  NULL)
);
			  
static void 	gst_asf_demux_class_init	(GstASFDemuxClass *klass);
static void 	gst_asf_demux_init		(GstASFDemux *asf_demux);
static gboolean gst_asf_demux_send_event 	(GstElement *element, 
						 GstEvent *event);
static void 	gst_asf_demux_loop 		(GstElement *element);
static gboolean gst_asf_demux_process_object    (GstASFDemux *asf_demux,
						 guint64 *filepos);
static void     gst_asf_demux_get_property      (GObject *object, 
						 guint prop_id, 	
						 GValue *value, 
						 GParamSpec *pspec);
static guint32  gst_asf_demux_identify_guid     (GstASFDemux *asf_demux,
						 ASFGuidHash *guids,
						 ASFGuid *guid_raw);
static gboolean gst_asf_demux_process_chunk      (GstASFDemux *asf_demux,
						  asf_packet_info *packet_info,
						  asf_segment_info *segment_info);
static const GstEventMask* gst_asf_demux_get_src_event_mask  (GstPad *pad);
static gboolean 	   gst_asf_demux_handle_sink_event   (GstASFDemux *asf_demux);
static gboolean 	   gst_asf_demux_handle_src_event    (GstPad *pad,
							      GstEvent *event);
static const GstFormat*    gst_asf_demux_get_src_formats     (GstPad *pad); 
static const GstQueryType* gst_asf_demux_get_src_query_types (GstPad *pad);
static gboolean 	   gst_asf_demux_handle_src_query    (GstPad *pad,
							      GstQueryType type,
							      GstFormat *format, gint64 *value);
static gboolean            gst_asf_demux_add_video_stream (GstASFDemux *asf_demux,
							   asf_stream_video_format *video_format,
							   guint16 id);
static gboolean            gst_asf_demux_add_audio_stream (GstASFDemux *asf_demux,
							   asf_stream_audio *audio,
							   guint16 id);
static gboolean            gst_asf_demux_setup_pad        (GstASFDemux *asf_demux,
							   GstPad *src_pad,
							   GstCaps *caps_list,
							   guint16 id);

static GstElementStateReturn gst_asf_demux_change_state   (GstElement *element);

static GstPadTemplate *videosrctempl, *audiosrctempl;
static GstElementClass *parent_class = NULL;

GType
asf_demux_get_type (void)
{
  static GType asf_demux_type = 0;

  if (!asf_demux_type) {
    static const GTypeInfo asf_demux_info = {
      sizeof(GstASFDemuxClass),      
      NULL,
      NULL,
      (GClassInitFunc)gst_asf_demux_class_init,
      NULL,
      NULL,
      sizeof(GstASFDemux),
      0,
      (GInstanceInitFunc)gst_asf_demux_init,
    };
    asf_demux_type = g_type_register_static(GST_TYPE_ELEMENT, "GstASFDemux", &asf_demux_info, 0);
  }
  return asf_demux_type;
}

static void
gst_asf_demux_class_init (GstASFDemuxClass *klass) 
{
  GObjectClass *gobject_class;
  GstElementClass *gstelement_class;

  gobject_class = (GObjectClass*)klass;
  gstelement_class = (GstElementClass*)klass;

  parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
  
  gobject_class->get_property = gst_asf_demux_get_property;
  
  gstelement_class->change_state = gst_asf_demux_change_state;
  gstelement_class->send_event = gst_asf_demux_send_event;
}

static void
gst_asf_demux_init (GstASFDemux *asf_demux)
{
  guint i;

  asf_demux->sinkpad = gst_pad_new_from_template(
		  GST_PAD_TEMPLATE_GET (sink_factory), "sink");
  gst_element_add_pad (GST_ELEMENT (asf_demux), asf_demux->sinkpad);

  gst_element_set_loop_function (GST_ELEMENT (asf_demux), gst_asf_demux_loop);

  /* We should zero everything to be on the safe side */
  for (i = 0; i < GST_ASF_DEMUX_NUM_VIDEO_PADS; i++) {
    asf_demux->video_pad[i] = NULL;
    asf_demux->video_PTS[i] = 0;
  }

  for (i = 0; i < GST_ASF_DEMUX_NUM_AUDIO_PADS; i++) {
    asf_demux->audio_pad[i] = NULL;
    asf_demux->audio_PTS[i] = 0;
  }

  asf_demux->num_audio_streams = 0;
  asf_demux->num_video_streams = 0;
  asf_demux->num_streams = 0;
  
  GST_FLAG_SET (asf_demux, GST_ELEMENT_EVENT_AWARE);
}

static gboolean
gst_asf_demux_send_event (GstElement *element, GstEvent *event)
{
  const GList *pads;

  pads = gst_element_get_pad_list (element);

  while (pads) {
    GstPad *pad = GST_PAD (pads->data);

    if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
      /* we ref the event here as we might have to try again if the event
       * failed on this pad */
      gst_event_ref (event);
      if (gst_asf_demux_handle_src_event (pad, event)) {
	gst_event_unref (event);
	return TRUE;
      }
    }
    
    pads = g_list_next (pads);
  }
  
  gst_event_unref (event);
  return FALSE;
}

static void
gst_asf_demux_loop (GstElement *element)
{
  GstASFDemux *asf_demux;
  guint64 filepos = 0;

  g_return_if_fail (element != NULL);
  g_return_if_fail (GST_IS_ASF_DEMUX (element));

  asf_demux = GST_ASF_DEMUX (element);

  asf_demux->restart = FALSE;

  /* this is basically an infinite loop */
  while (gst_asf_demux_process_object (asf_demux, &filepos)) { }
  GST_DEBUG ("Ending loop");
  if (!asf_demux->restart) {
    /* if we exit the loop we are EOS */
    gst_pad_event_default (asf_demux->sinkpad, gst_event_new (GST_EVENT_EOS));
  }
}

static guint32 gst_asf_demux_read_var_length (GstASFDemux *asf_demux, guint8 type, guint32 *rsize)
{
  guint32 got_bytes;
  guint8 *var;
  guint32 ret = 0;
  GstByteStream *bs = asf_demux->bs;

  if (type == 0) {
    return 0;
  }
  
  got_bytes = gst_bytestream_peek_bytes (bs, &var, 4);

  while (got_bytes < 4) {
    guint32 remaining;
    GstEvent *event;
  
    gst_bytestream_get_status (bs, &remaining, &event);
    gst_event_unref (event);

    got_bytes = gst_bytestream_peek_bytes (bs, &var, 4);
  }
    
  switch (type) {
  case 1:
    ret = GUINT32_FROM_LE(*(guint32 *)var) & 0xff;
    gst_bytestream_flush (bs, 1);
    *rsize += 1;
    break;
  case 2:
    ret = GUINT32_FROM_LE(*(guint32 *)var) & 0xffff;
    gst_bytestream_flush (bs, 2);
    *rsize += 2;
    break;
  case 3:
    ret = GUINT32_FROM_LE(*(guint32 *)var);
    gst_bytestream_flush (bs, 4);
    *rsize += 4;
    break;
  }

  return ret;
}

static void gst_asf_demux_read_object_header_rest (GstASFDemux *asf_demux, guint8 **buf, guint32 size) {
  guint32       got_bytes;
  GstByteStream *bs = asf_demux->bs;

  do {
    got_bytes = gst_bytestream_peek_bytes (bs, buf, size);
    if (got_bytes == size) {
      gst_bytestream_flush (bs, size);
      return;
    }
  } while (gst_asf_demux_handle_sink_event (asf_demux));
}

static gboolean
gst_asf_demux_process_file (GstASFDemux *asf_demux, guint64 *filepos, guint64 *obj_size)
{
  asf_obj_file *object;
  guint8 *ptr;
  guint64 packets;
  
  /* Get the rest of the header's header */
  gst_asf_demux_read_object_header_rest (asf_demux, &ptr, 80);
  object = (asf_obj_file *)ptr;
  packets = GUINT64_FROM_LE (object->packets_count);
  asf_demux->packet_size = GUINT32_FROM_LE (object->max_pktsize);
  asf_demux->play_time = (guint32) GUINT64_FROM_LE (object->play_time) / 10;
  asf_demux->preroll = GUINT64_FROM_LE (object->preroll);
  
  GST_INFO ( "Object is a file with %" G_GUINT64_FORMAT " data packets", packets);

  return TRUE;
}

static gboolean
gst_asf_demux_process_bitrate_props_object (GstASFDemux *asf_demux, guint64 *filepos, guint64 *obj_size)
{
  guint32            got_bytes;
  GstBuffer          *buf;
  guint16            num_streams;
  guint8             stream_id;
  guint16            i;
  guint8             *ptr;
  asf_bitrate_record *bitrate_record;

  got_bytes = gst_bytestream_read (asf_demux->bs, &buf, 2);
  num_streams = GUINT16_FROM_LE (*GST_BUFFER_DATA (buf));

  GST_INFO ( "Object is a bitrate properties object with %u streams.", num_streams);

  for (i = 0; i < num_streams; i++) {
    gst_asf_demux_read_object_header_rest (asf_demux, &ptr, 6);
    bitrate_record = (asf_bitrate_record *)ptr;
    stream_id = GUINT16_FROM_LE (bitrate_record->stream_id) & 0x7f;
    asf_demux->bitrate[stream_id] = GUINT32_FROM_LE (bitrate_record->bitrate);
  }

  return TRUE;
}

static gboolean
gst_asf_demux_process_comment (GstASFDemux *asf_demux, guint64 *filepos, guint64 *obj_size)
{
  asf_obj_comment *object;
  guint16 title_length;
  guint16 author_length;
  guint16 copyright_length;
  guint16 description_length;
  guint16 rating_length;
  guint8 *ptr;
  GstByteStream *bs = asf_demux->bs;

  GST_INFO ( "Object is a comment.");  

  /* Get the rest of the comment's header */
  gst_asf_demux_read_object_header_rest (asf_demux, &ptr, 10);
  object = (asf_obj_comment *)ptr;
  title_length = GUINT16_FROM_LE (object->title_length);
  author_length = GUINT16_FROM_LE (object->author_length);
  copyright_length = GUINT16_FROM_LE (object->copyright_length);
  description_length = GUINT16_FROM_LE (object->description_length);
  rating_length = GUINT16_FROM_LE (object->rating_length);
  GST_DEBUG ("Comment lengths: title=%d author=%d copyright=%d description=%d rating=%d", title_length, author_length, copyright_length, description_length, rating_length); 

  /* We don't do anything with them at the moment so just skip them */
  gst_bytestream_flush (bs, title_length);
  gst_bytestream_flush (bs, author_length);
  gst_bytestream_flush (bs, copyright_length);
  gst_bytestream_flush (bs, description_length);
  gst_bytestream_flush (bs, rating_length);

  return TRUE;
}


static gboolean
gst_asf_demux_process_header (GstASFDemux *asf_demux, guint64 *filepos, guint64 *obj_size)
{
  guint32 num_objects;
  asf_obj_header *object;
  guint32 i;
  guint8 *ptr;

  /* Get the rest of the header's header */
  gst_asf_demux_read_object_header_rest (asf_demux, &ptr, 6);
  object = (asf_obj_header *)ptr;
  num_objects = GUINT32_FROM_LE (object->num_objects);

  GST_INFO ( "Object is a header with %u parts", num_objects);  

  /* Loop through the header's objects, processing those */  
  for (i = 0; i < num_objects; i++) {
    if (!gst_asf_demux_process_object (asf_demux, filepos)) {
      return FALSE;
    }
  }

  return TRUE;
}

static gboolean
gst_asf_demux_process_segment (GstASFDemux       *asf_demux, 
			       asf_packet_info   *packet_info)
{
  guint8   *byte;
  gboolean key_frame;
  guint32  replic_size;
  guint8   time_delta;
  guint32  time_start;
  guint32  frag_size;
  guint32  rsize;
  asf_segment_info segment_info;

  gst_asf_demux_read_object_header_rest (asf_demux, (guint8**)&byte, 1); rsize = 1;
  segment_info.stream_number = *byte & 0x7f;
  key_frame = (*byte & 0x80) >> 7;
  
  GST_INFO ( "Processing segment for stream %u", segment_info.stream_number);
  segment_info.sequence = gst_asf_demux_read_var_length (asf_demux, packet_info->seqtype, &rsize);
  segment_info.frag_offset = gst_asf_demux_read_var_length (asf_demux, packet_info->fragoffsettype, &rsize);
  replic_size = gst_asf_demux_read_var_length (asf_demux, packet_info->replicsizetype, &rsize);
  GST_DEBUG ("sequence = %x, frag_offset = %x, replic_size = %x", segment_info.sequence, segment_info.frag_offset, replic_size);
  
  if (replic_size > 1) {
    asf_replicated_data *replicated_data_header;
    guint8              **replicated_data = NULL;
    guint8              *ptr;

    segment_info.compressed = FALSE;
    
    /* It's uncompressed with replic data*/
    if (replic_size < 8) {
      gst_element_error (GST_ELEMENT (asf_demux), "The payload has replicated data but the size is less than 8");
      return FALSE;
    }
    gst_asf_demux_read_object_header_rest (asf_demux, &ptr, 8);
    replicated_data_header = (asf_replicated_data *)ptr;
    segment_info.frag_timestamp = GUINT32_FROM_LE (replicated_data_header->frag_timestamp);
    segment_info.segment_size = GUINT32_FROM_LE (replicated_data_header->object_size);

    if (replic_size > 8) {
      gst_asf_demux_read_object_header_rest (asf_demux, replicated_data, replic_size - 8);
    }

    rsize += replic_size;
  } else {
    if (replic_size == 1) {
      /* It's compressed */
      segme