Author: bnickel
Date: 2007-12-27 02:11:19 -0500 (Thu, 27 Dec 2007)
New Revision: 91915
Modified:
trunk/taglib-sharp/ChangeLog
trunk/taglib-sharp/configure.ac
trunk/taglib-sharp/src/TagLib/Ape/Item.cs
trunk/taglib-sharp/src/TagLib/Ape/Tag.cs
trunk/taglib-sharp/src/TagLib/Flac/File.cs
trunk/taglib-sharp/src/TagLib/Mpeg4/AppleTag.cs
trunk/taglib-sharp/src/TagLib/NonContainer/EndTag.cs
trunk/taglib-sharp/src/TagLib/NonContainer/File.cs
trunk/taglib-sharp/src/TagLib/NonContainer/StartTag.cs
trunk/taglib-sharp/src/TagLib/Ogg/Bitstream.cs
trunk/taglib-sharp/src/TagLib/Ogg/File.cs
trunk/taglib-sharp/src/TagLib/Ogg/Page.cs
trunk/taglib-sharp/src/TagLib/Ogg/PageHeader.cs
trunk/taglib-sharp/src/TagLib/Ogg/Paginator.cs
trunk/taglib-sharp/src/TagLib/Picture.cs
trunk/taglib-sharp/src/TagLib/Riff/File.cs
trunk/taglib-sharp/src/TagLib/Tag.cs
Log:
2007-12-27 Brian Nickel <[EMAIL PROTECTED]>
This commit does the following:
- Adds support for .divx extension. (Just an AVI)
- Adds Tag.CopyTo to obsolete Tag.Duplicate. The difference is
that Tag.CopyTo is overridable, so tags and implement their
own, better, copying.
- Several small bugfixes correcting Mpeg4.Tag.IsCompilation,
GIF images, reading Mpeg4 pictures without flags, and
NonContainer.EndTag reading small files.
- COMPLETE REWORK of OGG pagination to handle multipage comments
and saving that results in the creation of new pages. This
fixes a bug posted by kurros on the forum and Banshee bug
#502628.
* src/TagLib/Riff/File.cs: Recognize the .divx extension. (Thanks to
sukhjinder for the feature request and jocker for confirming the fix.)
Use Tag.CopyTo instead of Tag.Duplicate.
* src/TagLib/Flac/File.cs: Use Tag.CopyTo instead of Tag.Duplicate.
* src/TagLib/Ape/Tag.cs: Add first real implementation of Tag.CopyTo.
* src/TagLib/Ape/Item.cs: Make clonable.
* src/TagLib/Mpeg4/AppleTag.cs: Don't check for image format flags, just
use data to identify the image type. iTunes apparently doesn't use the
flags anymore. (Thanks to [EMAIL PROTECTED] for the bug report.) Use 1
byte
rather than 4 to store the compilation setting. (Thanks to [EMAIL
PROTECTED]
for the fix.)
* src/TagLib/Picture.cs: Was setting mime-type to "image/png" for GIF.
* src/TagLib/Tag.cs: Mark Tag.Duplicate as obsolete and replace with
overridable Tag.CopyTo. This will provide the option for better copying
from one tag to another if their types match rather than just doing the
simply copy available in Tag.Duplicate. See Ape.Tag for an
implemenation. More coming soon.
* src/TagLib/NonContainer/File.cs: Don't read tags at the end of the
file if the tags at the start of the file are the entire file. (No
double dipping.)
* src/TagLib/NonContainer/EndTag.cs: Don't crash if start < 128 when
reading. (Thanks to jonx for the bug report.) Use Tag.CopyTo instead of
Tag.Duplicate.
* src/TagLib/NonContainer/StartTag.cs: Use Tag.CopyTo instead of
Tag.Duplicate.
* src/TagLib/Ogg/File.cs: Use changes in Page and Paginator classes to
handle situations where the number of pages in the stream changes.
* src/TagLib/Ogg/Page.cs: Add method for updating all Ogg pages after a
certain position with new page numbers. This is necessary if new pages
are inserted to avoid corrupting the file. Part of sweeping changes to
Ogg support.
* src/TagLib/Ogg/Paginator.cs: Instead of just saving a single page,
properly paginate using a single page for the first packet in the file.
Optimally, produce the same number of pages as were in the file before,
but allow for creating more pages if the situation warrents it.
* src/TagLib/Ogg/PageHeader.cs: Add a constructor which clones a header
but offsets page sequence by a specified number.
* src/TagLib/Ogg/Bitstream.cs: Fix typo that was preventing multi-page
packets from reading correctly. What a difference a negation makes.
* configure.ac: Now 2.0.2.19.
Modified: trunk/taglib-sharp/ChangeLog
===================================================================
--- trunk/taglib-sharp/ChangeLog 2007-12-27 04:59:38 UTC (rev 91914)
+++ trunk/taglib-sharp/ChangeLog 2007-12-27 07:11:19 UTC (rev 91915)
@@ -1,3 +1,75 @@
+2007-12-27 Brian Nickel <[EMAIL PROTECTED]>
+
+ This commit does the following:
+ - Adds support for .divx extension. (Just an AVI)
+ - Adds Tag.CopyTo to obsolete Tag.Duplicate. The difference is
+ that Tag.CopyTo is overridable, so tags and implement their
+ own, better, copying.
+ - Several small bugfixes correcting Mpeg4.Tag.IsCompilation,
+ GIF images, reading Mpeg4 pictures without flags, and
+ NonContainer.EndTag reading small files.
+
+ - COMPLETE REWORK of OGG pagination to handle multipage comments
+ and saving that results in the creation of new pages. This
+ fixes a bug posted by kurros on the forum and Banshee bug
+ #502628.
+
+ * src/TagLib/Riff/File.cs: Recognize the .divx extension. (Thanks to
+ sukhjinder for the feature request and jocker for confirming the fix.)
+ Use Tag.CopyTo instead of Tag.Duplicate.
+
+ * src/TagLib/Flac/File.cs: Use Tag.CopyTo instead of Tag.Duplicate.
+
+ * src/TagLib/Ape/Tag.cs: Add first real implementation of Tag.CopyTo.
+
+ * src/TagLib/Ape/Item.cs: Make clonable.
+
+ * src/TagLib/Mpeg4/AppleTag.cs: Don't check for image format flags, just
+ use data to identify the image type. iTunes apparently doesn't use the
+ flags anymore. (Thanks to [EMAIL PROTECTED] for the bug report.) Use 1
byte
+ rather than 4 to store the compilation setting. (Thanks to [EMAIL
PROTECTED]
+ for the fix.)
+
+ * src/TagLib/Picture.cs: Was setting mime-type to "image/png" for GIF.
+
+ * src/TagLib/Tag.cs: Mark Tag.Duplicate as obsolete and replace with
+ overridable Tag.CopyTo. This will provide the option for better copying
+ from one tag to another if their types match rather than just doing the
+ simply copy available in Tag.Duplicate. See Ape.Tag for an
+ implemenation. More coming soon.
+
+ * src/TagLib/NonContainer/File.cs: Don't read tags at the end of the
+ file if the tags at the start of the file are the entire file. (No
+ double dipping.)
+
+ * src/TagLib/NonContainer/EndTag.cs: Don't crash if start < 128 when
+ reading. (Thanks to jonx for the bug report.) Use Tag.CopyTo instead of
+ Tag.Duplicate.
+
+ * src/TagLib/NonContainer/StartTag.cs: Use Tag.CopyTo instead of
+ Tag.Duplicate.
+
+ * src/TagLib/Ogg/File.cs: Use changes in Page and Paginator classes to
+ handle situations where the number of pages in the stream changes.
+
+ * src/TagLib/Ogg/Page.cs: Add method for updating all Ogg pages after a
+ certain position with new page numbers. This is necessary if new pages
+ are inserted to avoid corrupting the file. Part of sweeping changes to
+ Ogg support.
+
+ * src/TagLib/Ogg/Paginator.cs: Instead of just saving a single page,
+ properly paginate using a single page for the first packet in the file.
+ Optimally, produce the same number of pages as were in the file before,
+ but allow for creating more pages if the situation warrents it.
+
+ * src/TagLib/Ogg/PageHeader.cs: Add a constructor which clones a header
+ but offsets page sequence by a specified number.
+
+ * src/TagLib/Ogg/Bitstream.cs: Fix typo that was preventing multi-page
+ packets from reading correctly. What a difference a negation makes.
+
+ * configure.ac: Now 2.0.2.19.
+
2007-12-25 Brian Nickel <[EMAIL PROTECTED]>
* src/TagLib/Riff/File.cs:
Modified: trunk/taglib-sharp/configure.ac
===================================================================
--- trunk/taglib-sharp/configure.ac 2007-12-27 04:59:38 UTC (rev 91914)
+++ trunk/taglib-sharp/configure.ac 2007-12-27 07:11:19 UTC (rev 91915)
@@ -3,7 +3,7 @@
ASSEMBLY_NAME="taglib-sharp"
-VERSION="2.0.2.18"
+VERSION="2.0.2.19"
ASSEMBLY_VERSION="$VERSION"
POLICY_2_0_VERSIONS="2.0.0.0-$ASSEMBLY_VERSION"
Modified: trunk/taglib-sharp/src/TagLib/Ape/Item.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Ape/Item.cs 2007-12-27 04:59:38 UTC (rev
91914)
+++ trunk/taglib-sharp/src/TagLib/Ape/Item.cs 2007-12-27 07:11:19 UTC (rev
91915)
@@ -55,7 +55,7 @@
/// This class provides a representation of an APEv2 tag item which
/// can be read from and written to disk.
/// </summary>
- public class Item
+ public class Item : ICloneable
{
#region Private Fields
@@ -243,6 +243,18 @@
data = new ReadOnlyByteVector (value);
}
+ private Item (Item item)
+ {
+ type = item.type;
+ key = item.key;
+ if (item.data != null)
+ data = new ReadOnlyByteVector (item.data);
+ if (item.text != null)
+ text = (string[]) item.text.Clone ();
+ read_only = item.read_only;
+ size_on_disk = item.size_on_disk;
+ }
+
#endregion
@@ -492,6 +504,22 @@
StringType.UTF8, 0);
}
- #endregion
+#endregion
+
+
+
+#region IClonable
+
+ public Item Clone ()
+ {
+ return new Item (this);
+ }
+
+ object ICloneable.Clone()
+ {
+ return Clone();
+ }
+
+#endregion
}
}
Modified: trunk/taglib-sharp/src/TagLib/Ape/Tag.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Ape/Tag.cs 2007-12-27 04:59:38 UTC (rev
91914)
+++ trunk/taglib-sharp/src/TagLib/Ape/Tag.cs 2007-12-27 07:11:19 UTC (rev
91915)
@@ -1192,6 +1192,49 @@
items.Clear ();
}
+ /// <summary>
+ /// Copies the values from the current instance to another
+ /// <see cref="TagLib.Tag" />, optionally overwriting
+ /// existing values.
+ /// </summary>
+ /// <param name="target">
+ /// A <see cref="Tag" /> object containing the target tag to
+ /// copy values to.
+ /// </param>
+ /// <param name="overwrite">
+ /// A <see cref="bool" /> specifying whether or not to copy
+ /// values over existing one.
+ /// </param>
+ /// <remarks>
+ /// <para>If <paramref name="target" /> is of type <see
+ /// cref="Tag" /> a complete copy of all values will be
+ /// performed. Otherwise, only standard values will be
+ /// copied.</para>
+ /// </remarks>
+ /// <exception cref="ArgumentNullException">
+ /// <paramref name="target" /> is <see langword="null" />.
+ /// </exception>
+ public virtual void CopyTo (Tag target, bool overwrite)
+ {
+ if (target == null)
+ throw new ArgumentNullException ("target");
+
+ TagLib.Ape.Tag match = target as TagLib.Ape.Tag;
+
+ if (match == null) {
+ base.CopyTo (target, overwrite);
+ return;
+ }
+
+ foreach (Item item in items) {
+ if (!overwrite &&
+ target.GetItem (item.Key) != null)
+ continue;
+
+ target.items.Add (item.Clone ());
+ }
+ }
+
#endregion
}
}
Modified: trunk/taglib-sharp/src/TagLib/Flac/File.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Flac/File.cs 2007-12-27 04:59:38 UTC (rev
91914)
+++ trunk/taglib-sharp/src/TagLib/Flac/File.cs 2007-12-27 07:11:19 UTC (rev
91915)
@@ -623,7 +623,7 @@
Ogg.XiphComment c = new Ogg.XiphComment ();
if (copy != null)
- TagLib.Tag.Duplicate (copy, c, true);
+ copy.CopyTo (c, true);
AddTag (c);
Modified: trunk/taglib-sharp/src/TagLib/Mpeg4/AppleTag.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Mpeg4/AppleTag.cs 2007-12-27 04:59:38 UTC
(rev 91914)
+++ trunk/taglib-sharp/src/TagLib/Mpeg4/AppleTag.cs 2007-12-27 07:11:19 UTC
(rev 91915)
@@ -106,8 +106,8 @@
return false;
}
set {
- SetData (BoxType.Cpil, ByteVector.FromUInt (
- (uint) (value ? 1 : 0)),
+ SetData (BoxType.Cpil, new ByteVector(
+ (byte) (value ? 1 : 0)),
(uint) AppleDataBox.FlagType.ForTempo);
}
}
@@ -960,25 +960,9 @@
get {
List<Picture> l = new List<Picture> ();
- foreach (AppleDataBox box in
DataBoxes(BoxType.Covr)) {
- string type = null;
- string desc = null;
-
- if (box.Flags == (int)
-
AppleDataBox.FlagType.ContainsJpegData) {
- type = "image/jpeg";
- desc = "cover.jpg";
- } else if (box.Flags == (int)
-
AppleDataBox.FlagType.ContainsPngData) {
- type = "image/png";
- desc = "cover.png";
- } else continue;
-
- Picture p = new Picture ();
+ foreach (AppleDataBox box in
DataBoxes(BoxType.Covr)) {
+ Picture p = new Picture (box.Data);
p.Type = PictureType.FrontCover;
- p.Data = box.Data;
- p.MimeType = type;
- p.Description = desc;
l.Add (p);
}
Modified: trunk/taglib-sharp/src/TagLib/NonContainer/EndTag.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/NonContainer/EndTag.cs 2007-12-27
04:59:38 UTC (rev 91914)
+++ trunk/taglib-sharp/src/TagLib/NonContainer/EndTag.cs 2007-12-27
07:11:19 UTC (rev 91915)
@@ -221,7 +221,7 @@
/// </param>
/// <param name="copy">
/// A <see cref="TagLib.Tag" /> to copy values from using
- /// <see cref="TagLib.Tag.Duplicate" />, or <see
+ /// <see cref="TagLib.Tag.CopyTo" />, or <see
/// langword="null" /> if no tag is to be copied.
/// </param>
/// <returns>
@@ -250,7 +250,7 @@
if (tag != null) {
if (copy != null)
- Tag.Duplicate (copy, tag, true);
+ copy.CopyTo (tag, true);
if (type == TagTypes.Id3v1)
AddTag (tag);
@@ -326,6 +326,9 @@
/// </returns>
private TagTypes ReadTagInfo (ref long position)
{
+ if (position - read_size < 0)
+ return TagTypes.None;
+
file.Seek (position - read_size);
ByteVector data = file.ReadBlock (read_size);
@@ -373,4 +376,4 @@
#endregion
}
-}
\ No newline at end of file
+}
Modified: trunk/taglib-sharp/src/TagLib/NonContainer/File.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/NonContainer/File.cs 2007-12-27 04:59:38 UTC
(rev 91914)
+++ trunk/taglib-sharp/src/TagLib/NonContainer/File.cs 2007-12-27 07:11:19 UTC
(rev 91915)
@@ -380,7 +380,9 @@
// Read the tags and property data at the end
of the
// file.
- InvariantEndPosition = tag.ReadEnd ();
+ InvariantEndPosition =
+ (InvariantStartPosition == Length) ?
+ Length : tag.ReadEnd ();
TagTypesOnDisk |= EndTag.TagTypes;
ReadEnd (InvariantEndPosition, propertiesStyle);
Modified: trunk/taglib-sharp/src/TagLib/NonContainer/StartTag.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/NonContainer/StartTag.cs 2007-12-27
04:59:38 UTC (rev 91914)
+++ trunk/taglib-sharp/src/TagLib/NonContainer/StartTag.cs 2007-12-27
07:11:19 UTC (rev 91915)
@@ -212,7 +212,7 @@
/// </param>
/// <param name="copy">
/// A <see cref="TagLib.Tag" /> to copy values from using
- /// <see cref="TagLib.Tag.Duplicate" />, or <see
+ /// <see cref="TagLib.Tag.CopyTo" />, or <see
/// langword="null" /> if no tag is to be copied.
/// </param>
/// <returns>
@@ -237,7 +237,7 @@
if (tag != null) {
if (copy != null)
- Tag.Duplicate (copy, tag, true);
+ copy.CopyTo (tag, true);
AddTag (tag);
}
@@ -334,4 +334,4 @@
#endregion
}
-}
\ No newline at end of file
+}
Modified: trunk/taglib-sharp/src/TagLib/Ogg/Bitstream.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Ogg/Bitstream.cs 2007-12-27 04:59:38 UTC
(rev 91914)
+++ trunk/taglib-sharp/src/TagLib/Ogg/Bitstream.cs 2007-12-27 07:11:19 UTC
(rev 91915)
@@ -64,7 +64,7 @@
// If we're at the first packet of the page, and we're continuing
an
// old packet, combine the old with the new.
- if (i == 0 && (page.Header.Flags & PageFlags.FirstPacketContinued)
== 0 && _previous_packet != null)
+ if (i == 0 && (page.Header.Flags & PageFlags.FirstPacketContinued)
!= 0 && _previous_packet != null)
{
_previous_packet.Add (packet);
packet = _previous_packet;
Modified: trunk/taglib-sharp/src/TagLib/Ogg/File.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Ogg/File.cs 2007-12-27 04:59:38 UTC (rev
91914)
+++ trunk/taglib-sharp/src/TagLib/Ogg/File.cs 2007-12-27 07:11:19 UTC (rev
91915)
@@ -121,21 +121,25 @@
new Dictionary<uint, Paginator> ();
List<List<Page>> new_pages =
new List<List<Page>> ();
-
+ Dictionary<uint, int> shifts =
+ new Dictionary<uint, int> ();
+
foreach (Page page in pages) {
uint id =
page.Header.StreamSerialNumber;
if (!paginators.ContainsKey (id))
- paginators.Add (id, new Paginator (
- streams [id].Codec));
-
+ paginators.Add (id, new
Paginator (
+ streams [id].Codec));
+
paginators [id].AddPage (page);
}
foreach (uint id in paginators.Keys) {
paginators [id].SetComment (
tag.GetComment (id));
+ int shift;
new_pages.Add (new List<Page> (
- paginators [id].Paginate ()));
+ paginators [id].Paginate (out
shift)));
+ shifts.Add (id, shift);
}
ByteVector output = new ByteVector ();
@@ -160,6 +164,9 @@
InvariantEndPosition = Length;
TagTypesOnDisk = TagTypes;
+
+ Page.OverwriteSequenceNumbers (this,
+ output.Count, shifts);
} finally {
Mode = AccessMode.Closed;
}
Modified: trunk/taglib-sharp/src/TagLib/Ogg/Page.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Ogg/Page.cs 2007-12-27 04:59:38 UTC (rev
91914)
+++ trunk/taglib-sharp/src/TagLib/Ogg/Page.cs 2007-12-27 07:11:19 UTC (rev
91915)
@@ -89,6 +89,48 @@
return data;
}
+
+ public static void OverwriteSequenceNumbers (File file,
+ long position,
+ IDictionary<uint,
int> shiftTable)
+ {
+ bool done = true;
+ foreach (KeyValuePair<uint, int> pair in shiftTable)
+ if (pair.Value != 0) {
+ done = false;
+ break;
+ }
+
+ if (done)
+ return;
+
+ while (position < file.Length) {
+ PageHeader header = new PageHeader (file,
position);
+ int size = (int) (header.Size +
header.DataSize);
+
+ if (shiftTable.ContainsKey
(header.StreamSerialNumber)
+ && shiftTable
[header.StreamSerialNumber] != 0) {
+ file.Seek (position);
+ ByteVector page_data = file.ReadBlock
(size);
+
+ ByteVector new_data =
ByteVector.FromUInt (
+
(uint)(header.PageSequenceNumber +
+ shiftTable
[header.StreamSerialNumber]),
+ false);
+
+ for (int i = 18; i < 22; i ++)
+ page_data [i] = new_data [i -
18];
+ for (int i = 22; i < 26; i++)
+ page_data [i] = 0;
+
+ new_data.Add (ByteVector.FromUInt (
+ page_data.Checksum, false));
+ file.Seek (position + 18);
+ file.WriteBlock (new_data);
+ }
+ position += size;
+ }
+ }
//////////////////////////////////////////////////////////////////////////
// public properties
Modified: trunk/taglib-sharp/src/TagLib/Ogg/PageHeader.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Ogg/PageHeader.cs 2007-12-27 04:59:38 UTC
(rev 91914)
+++ trunk/taglib-sharp/src/TagLib/Ogg/PageHeader.cs 2007-12-27 07:11:19 UTC
(rev 91915)
@@ -59,14 +59,15 @@
{
_version = 0;
_flags = flags;
- if (pageNumber == 0 && (flags & PageFlags.FirstPacketContinued) == 0)
- _flags |= PageFlags.FirstPageOfStream;
_absolute_granular_position = 0;
_stream_serial_number = streamSerialNumber;
_page_sequence_number = pageNumber;
_size = 0;
_data_size = 0;
_packet_sizes = new List<int> ();
+
+ if (pageNumber == 0 && (flags & PageFlags.FirstPacketContinued) == 0)
+ _flags |= PageFlags.FirstPageOfStream;
}
public PageHeader (File file, long position)
@@ -118,6 +119,22 @@
if (packet_size > 0)
_packet_sizes.Add (packet_size);
}
+
+ public PageHeader (PageHeader original, uint offset, PageFlags
flags)
+ {
+ _version = original._version;
+ _flags = flags;
+ _absolute_granular_position =
original._absolute_granular_position;
+ _stream_serial_number = original._stream_serial_number;
+ _page_sequence_number = original._page_sequence_number
+ offset;
+ _size = original._size;
+ _data_size = original._data_size;
+ _packet_sizes = new List<int> ();
+
+ if (_page_sequence_number == 0 && (flags &
PageFlags.FirstPacketContinued) == 0)
+ _flags |= PageFlags.FirstPageOfStream;
+ }
+
#endregion
@@ -195,14 +212,18 @@
- #region IEquatable
- public override int GetHashCode ()
- {
- unchecked
- {
- return (int) (LacingValues.GetHashCode () ^ _version ^ (int)
_flags ^ (int) _absolute_granular_position ^ _stream_serial_number ^
_page_sequence_number ^ _size ^ _data_size);
- }
- }
+#region IEquatable
+
+ public override int GetHashCode ()
{
+ unchecked {
+ return (int) (LacingValues.GetHashCode () ^
+ _version ^ (int) _flags ^
+ (int) _absolute_granular_position ^
+ _stream_serial_number ^
+ _page_sequence_number ^ _size ^
+ _data_size);
+ }
+ }
public override bool Equals (object obj)
{
Modified: trunk/taglib-sharp/src/TagLib/Ogg/Paginator.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Ogg/Paginator.cs 2007-12-27 04:59:38 UTC
(rev 91914)
+++ trunk/taglib-sharp/src/TagLib/Ogg/Paginator.cs 2007-12-27 07:11:19 UTC
(rev 91915)
@@ -32,58 +32,167 @@
{
public class Paginator
{
- private ByteVectorCollection packets;
- private PageHeader? first_page_header;
- private Codec codec;
-
+#region Private Fields
+
+ /// <summary>
+ /// Contains the packets to paginate.
+ /// </summary>
+ private ByteVectorCollection packets =
+ new ByteVectorCollection ();
+
+ /// <summary>
+ /// Contains the first page header.
+ /// </summary>
+ private PageHeader? first_page_header = null;
+
+ /// <summary>
+ /// Contains the codec to use.
+ /// </summary>
+ private Codec codec;
+
+ /// <summary>
+ /// contains the number of pages read.
+ /// </summary>
+ private int pages_read = 0;
+#endregion
+
+
+
+#region Constructors
+
public Paginator (Codec codec)
{
- packets = new ByteVectorCollection ();
- first_page_header = null;
- this.codec = codec;
+ this.codec = codec;
}
-
- public void AddPage (Page page)
- {
- if (first_page_header == null)
- first_page_header = page.Header;
-
- if (page.Packets.Length == 0)
- return;
-
- ByteVector[] page_packets = page.Packets;
-
- for (int i = 0; i < page_packets.Length; i ++)
- {
- if ((page.Header.Flags & PageFlags.FirstPacketContinued) != 0 && i
== 0 && packets.Count > 0)
- packets [packets.Count - 1].Add (page_packets [0]);
- else
- packets.Add (page_packets [i]);
- }
- }
-
- public void SetComment (XiphComment comment)
- {
- codec.SetCommentPacket (packets, comment);
- }
-
-
- public Page [] Paginate ()
- {
- List<Page> pages = new List<Page> ();
-
- int total_size = packets.Count;
-
- foreach (ByteVector b in packets)
- total_size += b.Count;
+#endregion
+
+
+
+
+ public void AddPage (Page page)
+ {
+ pages_read ++;
+
+ if (first_page_header == null)
+ first_page_header = page.Header;
+
+ if (page.Packets.Length == 0)
+ return;
+
+ ByteVector[] page_packets = page.Packets;
+
+ for (int i = 0; i < page_packets.Length; i ++) {
+ if ((page.Header.Flags & PageFlags
+ .FirstPacketContinued) != 0 && i == 0 &&
+ packets.Count > 0)
+ packets [packets.Count - 1].Add
(page_packets [0]);
+ else
+ packets.Add (page_packets [i]);
+ }
+ }
- // TODO: Handle creation of multiple pages here with appropriate
pagination.
- if (total_size > 0xFF00)
- throw new NotImplementedException ("Repagination is not yet
implemented.");
-
+ public void SetComment (XiphComment comment)
+ {
+ codec.SetCommentPacket (packets, comment);
+ }
- pages.Add (new Page (packets, (PageHeader) first_page_header));
- return pages.ToArray ();
- }
+ [Obsolete("Use Paginator.Paginate(out int)")]
+ public Page [] Paginate ()
+ {
+ int dummy;
+ return Paginate (out dummy);
+ }
+
+ public Page [] Paginate (out int change)
+ {
+ // Ogg Pagination: Welcome to sucksville!
+ // If you don't understand this, you're not alone.
+ // It is confusing as Hell.
+
+ // TODO: Document this method, in the mean time, there
+ // is always http://xiph.org/ogg/doc/framing.html
+
+ if (pages_read == 0) {
+ change = 0;
+ return new Page [0];
+ }
+
+ int count = pages_read;
+ ByteVectorCollection packets = new ByteVectorCollection
(
+ this.packets);
+ PageHeader first_header = (PageHeader)
first_page_header;
+ List<Page> pages = new List<Page> ();
+ uint index = 0;
+ bool bos = first_header.PageSequenceNumber == 0;
+
+ if (bos) {
+ pages.Add (new Page (new ByteVectorCollection
(packets [0]), first_header));
+ index ++;
+ packets.RemoveAt (0);
+ count --;
+ }
+
+ int lacing_per_page = 0xfc;
+ if (count > 0) {
+ int total_lacing_bytes = 0;
+
+ for (int i = 0; i < packets.Count; i ++)
+ total_lacing_bytes +=
GetLacingValueLength (
+ packets, i);
+
+ lacing_per_page = Math.Min (total_lacing_bytes
/ count + 1, lacing_per_page);
+ }
+
+ int lacing_bytes_used = 0;
+ ByteVectorCollection page_packets = new
ByteVectorCollection ();
+ bool first_packet_continued = false;
+
+ while (packets.Count > 0) {
+ int packet_bytes = GetLacingValueLength
(packets, 0);
+ int remaining = lacing_per_page -
lacing_bytes_used;
+ bool whole_packet = packet_bytes <= remaining;
+ if (whole_packet) {
+ page_packets.Add (packets [0]);
+ lacing_bytes_used += packet_bytes;
+ packets.RemoveAt (0);
+ } else {
+ page_packets.Add (packets [0].Mid (0,
remaining * 0xff));
+ packets [0] = packets [0].Mid
(remaining * 0xff);
+ lacing_bytes_used += remaining;
+ }
+
+ if (lacing_bytes_used == lacing_per_page) {
+ pages.Add (new Page (page_packets,
+ new PageHeader (first_header,
+ index,
first_packet_continued ?
+
PageFlags.FirstPacketContinued :
+ PageFlags.None)));
+ page_packets = new ByteVectorCollection
();
+ lacing_bytes_used = 0;
+ index ++;
+ count --;
+ first_packet_continued = !whole_packet;
+ }
+ }
+
+ if (page_packets.Count > 0) {
+ pages.Add (new Page (page_packets,
+ new PageHeader (
+ first_header.StreamSerialNumber,
+ index, first_packet_continued ?
+ PageFlags.FirstPacketContinued :
+ PageFlags.None)));
+ index ++;
+ count --;
+ }
+ change = -count;
+ return pages.ToArray ();
+ }
+
+ private int GetLacingValueLength (ByteVectorCollection packets,
int index)
+ {
+ int size = packets [index].Count;
+ return size / 0xff + ((index + 1 < packets.Count ||
size % 0xff > 0) ? 1 : 0);
+ }
}
}
Modified: trunk/taglib-sharp/src/TagLib/Picture.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Picture.cs 2007-12-27 04:59:38 UTC (rev
91914)
+++ trunk/taglib-sharp/src/TagLib/Picture.cs 2007-12-27 07:11:19 UTC (rev
91915)
@@ -385,7 +385,7 @@
(Data[0] == 'G' &&
Data[1] == 'I' &&
Data[2] == 'F')) {
- mimetype = "image/png";
+ mimetype = "image/gif";
ext = "gif";
} else if (Data.Count >= 2 &&
(Data[0] == 'B' &&
Modified: trunk/taglib-sharp/src/TagLib/Riff/File.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Riff/File.cs 2007-12-27 04:59:38 UTC (rev
91914)
+++ trunk/taglib-sharp/src/TagLib/Riff/File.cs 2007-12-27 07:11:19 UTC (rev
91915)
@@ -29,6 +29,7 @@
{
[SupportedMimeType("taglib/avi", "avi")]
[SupportedMimeType("taglib/wav", "wav")]
+ [SupportedMimeType("taglib/divx", "divx")]
[SupportedMimeType("video/avi")]
[SupportedMimeType("video/msvideo")]
[SupportedMimeType("video/x-msvideo")]
@@ -215,7 +216,7 @@
id32_tag = new Id3v2.Tag ();
id32_tag.Version = 4;
id32_tag.Flags |= Id3v2.HeaderFlags.FooterPresent;
- TagLib.Tag.Duplicate (this.tag, id32_tag, true);
+ this.tag.CopyTo (id32_tag, true);
}
tag = id32_tag;
break;
@@ -223,7 +224,7 @@
if (info_tag == null && create)
{
info_tag = new InfoTag ();
- TagLib.Tag.Duplicate (this.tag, info_tag, true);
+ this.tag.CopyTo (info_tag, true);
}
tag = info_tag;
break;
@@ -231,7 +232,7 @@
if (mid_tag == null && create)
{
mid_tag = new MovieIdTag ();
- TagLib.Tag.Duplicate (this.tag, mid_tag, true);
+ this.tag.CopyTo (mid_tag, true);
}
tag = mid_tag;
break;
@@ -239,7 +240,7 @@
if (divx_tag == null && create)
{
divx_tag = new DivXTag ();
- TagLib.Tag.Duplicate (this.tag, divx_tag, true);
+ this.tag.CopyTo (divx_tag, true);
}
tag = divx_tag;
break;
Modified: trunk/taglib-sharp/src/TagLib/Tag.cs
===================================================================
--- trunk/taglib-sharp/src/TagLib/Tag.cs 2007-12-27 04:59:38 UTC (rev
91914)
+++ trunk/taglib-sharp/src/TagLib/Tag.cs 2007-12-27 07:11:19 UTC (rev
91915)
@@ -804,6 +804,7 @@
/// <paramref name="source" /> or <paramref name="target" />
/// is <see langword="null" />.
/// </exception>
+ [Obsolete("Use Tag.CopyTo(Tag,bool)")]
public static void Duplicate (Tag source, Tag target,
bool overwrite)
{
@@ -813,53 +814,85 @@
if (target == null)
throw new ArgumentNullException ("target");
+ source.CopyTo (target, overwrite);
+ }
+
+ /// <summary>
+ /// Copies the values from the current instance to another
+ /// <see cref="TagLib.Tag" />, optionally overwriting
+ /// existing values.
+ /// </summary>
+ /// <param name="target">
+ /// A <see cref="Tag" /> object containing the target tag to
+ /// copy values to.
+ /// </param>
+ /// <param name="overwrite">
+ /// A <see cref="bool" /> specifying whether or not to copy
+ /// values over existing one.
+ /// </param>
+ /// <remarks>
+ /// <para>This method only copies the most basic values when
+ /// copying between different tag formats, however, if
+ /// <paramref name="target" /> is of the same type as the
+ /// current instance, more advanced copying may be done.
+ /// For example, <see cref="TagLib.Id3v2.Tag" /> will copy
+ /// all of its frames to another tag.</para>
+ /// </remarks>
+ /// <exception cref="ArgumentNullException">
+ /// <paramref name="target" /> is <see langword="null" />.
+ /// </exception>
+ public virtual void CopyTo (Tag target, bool overwrite)
+ {
+ if (target == null)
+ throw new ArgumentNullException ("target");
+
if (overwrite || IsNullOrLikeEmpty (target.Title))
- target.Title = source.Title;
+ target.Title = Title;
if (overwrite || IsNullOrLikeEmpty
(target.AlbumArtists))
- target.AlbumArtists = source.AlbumArtists;
+ target.AlbumArtists = AlbumArtists;
if (overwrite || IsNullOrLikeEmpty (target.Performers))
- target.Performers = source.Performers;
+ target.Performers = Performers;
if (overwrite || IsNullOrLikeEmpty (target.Composers))
- target.Composers = source.Composers;
+ target.Composers = Composers;
if (overwrite || IsNullOrLikeEmpty (target.Album))
- target.Album = source.Album;
+ target.Album = Album;
if (overwrite || IsNullOrLikeEmpty (target.Comment))
- target.Comment = source.Comment;
+ target.Comment = Comment;
if (overwrite || IsNullOrLikeEmpty (target.Genres))
- target.Genres = source.Genres;
+ target.Genres = Genres;
if (overwrite || target.Year == 0)
- target.Year = source.Year;
+ target.Year = Year;
if (overwrite || target.Track == 0)
- target.Track = source.Track;
+ target.Track = Track;
if (overwrite || target.TrackCount == 0)
- target.TrackCount = source.TrackCount;
+ target.TrackCount = TrackCount;
if (overwrite || target.Disc == 0)
- target.Disc = source.Disc;
+ target.Disc = Disc;
if (overwrite || target.DiscCount == 0)
- target.DiscCount = source.DiscCount;
+ target.DiscCount = DiscCount;
if (overwrite || target.BeatsPerMinute == 0)
- target.BeatsPerMinute = source.BeatsPerMinute;
+ target.BeatsPerMinute = BeatsPerMinute;
if (overwrite || IsNullOrLikeEmpty (target.Grouping))
- target.Grouping = source.Grouping;
+ target.Grouping = Grouping;
if (overwrite || IsNullOrLikeEmpty (target.Conductor))
- target.Conductor = source.Conductor;
+ target.Conductor = Conductor;
if (overwrite || IsNullOrLikeEmpty (target.Copyright))
- target.Conductor = source.Copyright;
+ target.Conductor = Copyright;
}
/// <summary>
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches