~ubuntu-branches/ubuntu/intrepid/banshee/intrepid

« back to all changes in this revision

Viewing changes to ext/taglib-sharp/TagLib/Asf/StreamPropertiesObject.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2008-01-09 08:06:38 UTC
  • mfrom: (1.3.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20080109080638-x5x0h3bd92nht0n9
Tags: 0.13.2+dfsg-2
* debian/control:
  + Build depend on mono-mcs to fix FTBFS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
    copyright            : (C) 2005 by Brian Nickel
3
 
    email                : brian.nickel@gmail.com
4
 
 ***************************************************************************/
5
 
 
6
 
/***************************************************************************
7
 
 *   This library is free software; you can redistribute it and/or modify  *
8
 
 *   it  under the terms of the GNU Lesser General Public License version  *
9
 
 *   2.1 as published by the Free Software Foundation.                     *
10
 
 *                                                                         *
11
 
 *   This library is distributed in the hope that it will be useful, but   *
12
 
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
13
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
14
 
 *   Lesser General Public License for more details.                       *
15
 
 *                                                                         *
16
 
 *   You should have received a copy of the GNU Lesser General Public      *
17
 
 *   License along with this library; if not, write to the Free Software   *
18
 
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
19
 
 *   USA                                                                   *
20
 
 ***************************************************************************/
 
1
//
 
2
// StreamPropertiesObject.cs: Provides a representation of an ASF Stream
 
3
// Properties object which can be read from and written to disk.
 
4
//
 
5
// Author:
 
6
//   Brian Nickel (brian.nickel@gmail.com)
 
7
//
 
8
// Copyright (C) 2006-2007 Brian Nickel
 
9
// 
 
10
// This library is free software; you can redistribute it and/or modify
 
11
// it  under the terms of the GNU Lesser General Public License version
 
12
// 2.1 as published by the Free Software Foundation.
 
13
//
 
14
// This library is distributed in the hope that it will be useful, but
 
15
// WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
// Lesser General Public License for more details.
 
18
//
 
19
// You should have received a copy of the GNU Lesser General Public
 
20
// License along with this library; if not, write to the Free Software
 
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 
22
// USA
 
23
//
21
24
 
22
25
using System;
23
26
using System.Text;
24
27
 
25
 
namespace TagLib.Asf
26
 
{
27
 
   public class StreamPropertiesObject : Object
28
 
   {
29
 
#region Private Properties
30
 
      private System.Guid stream_type;
31
 
      private System.Guid error_correction_type;
32
 
      private ulong time_offset;
33
 
      private ushort flags;
34
 
      private uint reserved;
35
 
      private ByteVector type_specific_data;
36
 
      private ByteVector error_correction_data;
37
 
#endregion
38
 
      
39
 
#region Constructors
40
 
      public StreamPropertiesObject (Asf.File file, long position) : base (file, position)
41
 
      {
42
 
         if (file == null)
43
 
            throw new ArgumentNullException ("file");
44
 
         
45
 
         if (!Guid.Equals (Asf.Guid.AsfStreamPropertiesObject))
46
 
            throw new CorruptFileException ("Object GUID incorrect.");
47
 
         
48
 
         if (OriginalSize < 78)
49
 
            throw new CorruptFileException ("Object size too small.");
50
 
         
51
 
         stream_type                       = file.ReadGuid  ();
52
 
         error_correction_type             = file.ReadGuid  ();
53
 
         time_offset                       = file.ReadQWord ();
54
 
         int type_specific_data_length     = (int) file.ReadDWord ();
55
 
         int error_correction_data_length  = (int) file.ReadDWord ();
56
 
         flags                                                                           = file.ReadWord  ();
57
 
         reserved                          = file.ReadDWord ();
58
 
         type_specific_data                = file.ReadBlock (type_specific_data_length);
59
 
         error_correction_data             = file.ReadBlock (error_correction_data_length);
60
 
      }
61
 
#endregion
62
 
      
63
 
#region Public Methods
64
 
      public override ByteVector Render ()
65
 
      {
66
 
         ByteVector output = stream_type.ToByteArray ();
67
 
         output.Add (error_correction_type.ToByteArray ());
68
 
         output.Add (RenderQWord (time_offset));
69
 
         output.Add (RenderDWord ((uint) type_specific_data.Count));
70
 
         output.Add (RenderDWord ((uint) error_correction_data.Count));
71
 
         output.Add (RenderWord  (flags));
72
 
         output.Add (RenderDWord (reserved));
73
 
         output.Add (type_specific_data);
74
 
         output.Add (error_correction_data);
75
 
         
76
 
         return Render (output);
77
 
      }
78
 
      
79
 
      public ICodec Codec
80
 
      {
81
 
         get
82
 
         {
83
 
            if (stream_type == Asf.Guid.AsfAudioMedia)
84
 
               return new Riff.WaveFormatEx (type_specific_data, 0);
85
 
            
86
 
            if (stream_type == Asf.Guid.AsfVideoMedia)
87
 
               return new TagLib.Riff.BitmapInfoHeader (type_specific_data, 11);
88
 
            
89
 
            return null;
90
 
         }
91
 
      }
92
 
      #endregion
93
 
      
94
 
      
95
 
      
96
 
      #region Public Properties
97
 
      public System.Guid StreamType          {get {return stream_type;}}
98
 
      public System.Guid ErrorCorrectionType {get {return error_correction_type;}}
99
 
      public TimeSpan    TimeOffset          {get {return new TimeSpan ((long)time_offset);}}
100
 
      public ushort      Flags               {get {return flags;}}
101
 
      public ByteVector  TypeSpecificData    {get {return type_specific_data;}}
102
 
      public ByteVector  ErrorCorrectionData {get {return error_correction_data;}}
103
 
      #endregion
104
 
   }
 
28
namespace TagLib.Asf {
 
29
        /// <summary>
 
30
        ///    This class extends <see cref="Object" /> to provide a
 
31
        ///    representation of an ASF Stream Properties object which can be
 
32
        ///    read from and written to disk.
 
33
        /// </summary>
 
34
        public class StreamPropertiesObject : Object
 
35
        {
 
36
                #region Private Fields
 
37
                
 
38
                /// <summary>
 
39
                ///    Contains the stream type GUID.
 
40
                /// </summary>
 
41
                private System.Guid stream_type;
 
42
                
 
43
                /// <summary>
 
44
                ///    Contains the error correction type GUID.
 
45
                /// </summary>
 
46
                private System.Guid error_correction_type;
 
47
                
 
48
                /// <summary>
 
49
                ///    Contains the time offset of the stream.
 
50
                /// </summary>
 
51
                private ulong time_offset;
 
52
                
 
53
                /// <summary>
 
54
                ///    Contains the stream flags.
 
55
                /// </summary>
 
56
                private ushort flags;
 
57
                
 
58
                /// <summary>
 
59
                ///    Contains the reserved data.
 
60
                /// </summary>
 
61
                private uint reserved;
 
62
                
 
63
                /// <summary>
 
64
                ///    Contains the type specific data.
 
65
                /// </summary>
 
66
                private ByteVector type_specific_data;
 
67
                
 
68
                /// <summary>
 
69
                ///    Contains the error correction data.
 
70
                /// </summary>
 
71
                private ByteVector error_correction_data;
 
72
                
 
73
                #endregion
 
74
                
 
75
                
 
76
                
 
77
                #region Constructors
 
78
                
 
79
                /// <summary>
 
80
                ///    Constructs and initializes a new instance of <see
 
81
                ///    cref="PaddingObject" /> by reading the contents from a
 
82
                ///    specified position in a specified file.
 
83
                /// </summary>
 
84
                /// <param name="file">
 
85
                ///    A <see cref="Asf.File" /> object containing the file from
 
86
                ///    which the contents of the new instance are to be read.
 
87
                /// </param>
 
88
                /// <param name="position">
 
89
                ///    A <see cref="long" /> value specify at what position to
 
90
                ///    read the object.
 
91
                /// </param>
 
92
                /// <exception cref="ArgumentNullException">
 
93
                ///    <paramref name="file" /> is <see langref="null" />.
 
94
                /// </exception>
 
95
                /// <exception cref="ArgumentOutOfRangeException">
 
96
                ///    <paramref name="position" /> is less than zero or greater
 
97
                ///    than the size of the file.
 
98
                /// </exception>
 
99
                /// <exception cref="CorruptFileException">
 
100
                ///    The object read from disk does not have the correct GUID
 
101
                ///    or smaller than the minimum size.
 
102
                /// </exception>
 
103
                public StreamPropertiesObject (Asf.File file, long position)
 
104
                        : base (file, position)
 
105
                {
 
106
                        if (!Guid.Equals (Asf.Guid.AsfStreamPropertiesObject))
 
107
                                throw new CorruptFileException (
 
108
                                        "Object GUID incorrect.");
 
109
                        
 
110
                        if (OriginalSize < 78)
 
111
                                throw new CorruptFileException (
 
112
                                        "Object size too small.");
 
113
                        
 
114
                        stream_type = file.ReadGuid ();
 
115
                        error_correction_type = file.ReadGuid ();
 
116
                        time_offset = file.ReadQWord ();
 
117
                        
 
118
                        int type_specific_data_length = (int) file.ReadDWord ();
 
119
                        int error_correction_data_length = (int)
 
120
                                file.ReadDWord ();
 
121
                        
 
122
                        flags = file.ReadWord ();
 
123
                        reserved = file.ReadDWord ();
 
124
                        type_specific_data =
 
125
                                file.ReadBlock (type_specific_data_length);
 
126
                        error_correction_data =
 
127
                                file.ReadBlock (error_correction_data_length);
 
128
                }
 
129
                
 
130
                #endregion
 
131
                
 
132
                
 
133
                
 
134
                #region Public Properties
 
135
                
 
136
                /// <summary>
 
137
                ///    Gets the codec information contained in the current
 
138
                ///    instance.
 
139
                /// </summary>
 
140
                /// <value>
 
141
                ///    A <see cref="ICodec" /> object containing the codec
 
142
                ///    information read from <see cref="TypeSpecificData" /> or
 
143
                ///    <see langword="null" /> if the data could not be decoded.
 
144
                /// </value>
 
145
                public ICodec Codec {
 
146
                        get {
 
147
                                if (stream_type == Asf.Guid.AsfAudioMedia)
 
148
                                        return new Riff.WaveFormatEx (
 
149
                                                type_specific_data, 0);
 
150
                                
 
151
                                if (stream_type == Asf.Guid.AsfVideoMedia)
 
152
                                        return new TagLib.Riff.BitmapInfoHeader (
 
153
                                                type_specific_data, 11);
 
154
                                
 
155
                                return null;
 
156
                        }
 
157
                }
 
158
                
 
159
                /// <summary>
 
160
                ///    Gets the stream type GUID of the current instance.
 
161
                /// </summary>
 
162
                /// <summary>
 
163
                ///    A <see cref="System.Guid" /> object containing the stream
 
164
                ///    type GUID of the current instance.
 
165
                /// </summary>
 
166
                public System.Guid StreamType {
 
167
                        get {return stream_type;}
 
168
                }
 
169
                
 
170
                /// <summary>
 
171
                ///    Gets the error correction type GUID of the current
 
172
                ///    instance.
 
173
                /// </summary>
 
174
                /// <summary>
 
175
                ///    A <see cref="System.Guid" /> object containing the error
 
176
                ///    correction type GUID of the current instance.
 
177
                /// </summary>
 
178
                public System.Guid ErrorCorrectionType {
 
179
                        get {return error_correction_type;}
 
180
                }
 
181
                
 
182
                /// <summary>
 
183
                ///    Gets the time offset at which the stream described by the
 
184
                ///    current instance begins.
 
185
                /// </summary>
 
186
                /// <value>
 
187
                ///    A <see cref="TimeSpan" /> value containing the time
 
188
                ///    offset at which the stream described by the current
 
189
                ///    instance begins.
 
190
                /// </value>
 
191
                public TimeSpan TimeOffset {
 
192
                        get {return new TimeSpan ((long)time_offset);}
 
193
                }
 
194
                
 
195
                /// <summary>
 
196
                ///    Gets the flags that apply to the current instance.
 
197
                /// </summary>
 
198
                /// <value>
 
199
                ///    A <see cref="ushort" /> value containing the flags that
 
200
                ///    apply to the current instance.
 
201
                /// </value>
 
202
                public ushort Flags {
 
203
                        get {return flags;}
 
204
                }
 
205
                
 
206
                /// <summary>
 
207
                ///    Gets the type specific data contained in the current
 
208
                ///    instance.
 
209
                /// </summary>
 
210
                /// <value>
 
211
                ///    A <see cref="ByteVector" /> object containing the type
 
212
                ///    specific data contained in the current instance.
 
213
                /// </value>
 
214
                /// <remarks>
 
215
                ///    The contents of this value are dependant on the type
 
216
                ///    contained in <see cref="StreamType" />.
 
217
                /// </remarks>
 
218
                public ByteVector TypeSpecificData {
 
219
                        get {return type_specific_data;}
 
220
                }
 
221
                
 
222
                /// <summary>
 
223
                ///    Gets the error correction data contained in the current
 
224
                ///    instance.
 
225
                /// </summary>
 
226
                /// <value>
 
227
                ///    A <see cref="ByteVector" /> object containing the error
 
228
                ///    correction data contained in the current instance.
 
229
                /// </value>
 
230
                /// <remarks>
 
231
                ///    The contents of this value are dependant on the type
 
232
                ///    contained in <see cref="ErrorCorrectionType" />.
 
233
                /// </remarks>
 
234
                public ByteVector ErrorCorrectionData {
 
235
                        get {return error_correction_data;}
 
236
                }
 
237
                
 
238
                #endregion
 
239
                
 
240
                
 
241
                
 
242
                #region Public Methods
 
243
                
 
244
                /// <summary>
 
245
                ///    Renders the current instance as a raw ASF object.
 
246
                /// </summary>
 
247
                /// <returns>
 
248
                ///    A <see cref="ByteVector" /> object containing the
 
249
                ///    rendered version of the current instance.
 
250
                /// </returns>
 
251
                public override ByteVector Render ()
 
252
                {
 
253
                        ByteVector output = stream_type.ToByteArray ();
 
254
                        output.Add (error_correction_type.ToByteArray ());
 
255
                        output.Add (RenderQWord (time_offset));
 
256
                        output.Add (RenderDWord ((uint)
 
257
                                type_specific_data.Count));
 
258
                        output.Add (RenderDWord ((uint)
 
259
                                error_correction_data.Count));
 
260
                        output.Add (RenderWord  (flags));
 
261
                        output.Add (RenderDWord (reserved));
 
262
                        output.Add (type_specific_data);
 
263
                        output.Add (error_correction_data);
 
264
                        
 
265
                        return Render (output);
 
266
                }
 
267
                
 
268
                #endregion
 
269
        }
105
270
}