1
/***************************************************************************
2
copyright : (C) 2005 by Brian Nickel
3
email : brian.nickel@gmail.com
4
***************************************************************************/
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. *
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. *
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 *
20
***************************************************************************/
2
// StreamPropertiesObject.cs: Provides a representation of an ASF Stream
3
// Properties object which can be read from and written to disk.
6
// Brian Nickel (brian.nickel@gmail.com)
8
// Copyright (C) 2006-2007 Brian Nickel
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.
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.
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
27
public class StreamPropertiesObject : Object
29
#region Private Properties
30
private System.Guid stream_type;
31
private System.Guid error_correction_type;
32
private ulong time_offset;
34
private uint reserved;
35
private ByteVector type_specific_data;
36
private ByteVector error_correction_data;
40
public StreamPropertiesObject (Asf.File file, long position) : base (file, position)
43
throw new ArgumentNullException ("file");
45
if (!Guid.Equals (Asf.Guid.AsfStreamPropertiesObject))
46
throw new CorruptFileException ("Object GUID incorrect.");
48
if (OriginalSize < 78)
49
throw new CorruptFileException ("Object size too small.");
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);
63
#region Public Methods
64
public override ByteVector Render ()
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);
76
return Render (output);
83
if (stream_type == Asf.Guid.AsfAudioMedia)
84
return new Riff.WaveFormatEx (type_specific_data, 0);
86
if (stream_type == Asf.Guid.AsfVideoMedia)
87
return new TagLib.Riff.BitmapInfoHeader (type_specific_data, 11);
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;}}
28
namespace TagLib.Asf {
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.
34
public class StreamPropertiesObject : Object
36
#region Private Fields
39
/// Contains the stream type GUID.
41
private System.Guid stream_type;
44
/// Contains the error correction type GUID.
46
private System.Guid error_correction_type;
49
/// Contains the time offset of the stream.
51
private ulong time_offset;
54
/// Contains the stream flags.
59
/// Contains the reserved data.
61
private uint reserved;
64
/// Contains the type specific data.
66
private ByteVector type_specific_data;
69
/// Contains the error correction data.
71
private ByteVector error_correction_data;
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.
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.
88
/// <param name="position">
89
/// A <see cref="long" /> value specify at what position to
92
/// <exception cref="ArgumentNullException">
93
/// <paramref name="file" /> is <see langref="null" />.
95
/// <exception cref="ArgumentOutOfRangeException">
96
/// <paramref name="position" /> is less than zero or greater
97
/// than the size of the file.
99
/// <exception cref="CorruptFileException">
100
/// The object read from disk does not have the correct GUID
101
/// or smaller than the minimum size.
103
public StreamPropertiesObject (Asf.File file, long position)
104
: base (file, position)
106
if (!Guid.Equals (Asf.Guid.AsfStreamPropertiesObject))
107
throw new CorruptFileException (
108
"Object GUID incorrect.");
110
if (OriginalSize < 78)
111
throw new CorruptFileException (
112
"Object size too small.");
114
stream_type = file.ReadGuid ();
115
error_correction_type = file.ReadGuid ();
116
time_offset = file.ReadQWord ();
118
int type_specific_data_length = (int) file.ReadDWord ();
119
int error_correction_data_length = (int)
122
flags = file.ReadWord ();
123
reserved = file.ReadDWord ();
125
file.ReadBlock (type_specific_data_length);
126
error_correction_data =
127
file.ReadBlock (error_correction_data_length);
134
#region Public Properties
137
/// Gets the codec information contained in the current
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.
145
public ICodec Codec {
147
if (stream_type == Asf.Guid.AsfAudioMedia)
148
return new Riff.WaveFormatEx (
149
type_specific_data, 0);
151
if (stream_type == Asf.Guid.AsfVideoMedia)
152
return new TagLib.Riff.BitmapInfoHeader (
153
type_specific_data, 11);
160
/// Gets the stream type GUID of the current instance.
163
/// A <see cref="System.Guid" /> object containing the stream
164
/// type GUID of the current instance.
166
public System.Guid StreamType {
167
get {return stream_type;}
171
/// Gets the error correction type GUID of the current
175
/// A <see cref="System.Guid" /> object containing the error
176
/// correction type GUID of the current instance.
178
public System.Guid ErrorCorrectionType {
179
get {return error_correction_type;}
183
/// Gets the time offset at which the stream described by the
184
/// current instance begins.
187
/// A <see cref="TimeSpan" /> value containing the time
188
/// offset at which the stream described by the current
191
public TimeSpan TimeOffset {
192
get {return new TimeSpan ((long)time_offset);}
196
/// Gets the flags that apply to the current instance.
199
/// A <see cref="ushort" /> value containing the flags that
200
/// apply to the current instance.
202
public ushort Flags {
207
/// Gets the type specific data contained in the current
211
/// A <see cref="ByteVector" /> object containing the type
212
/// specific data contained in the current instance.
215
/// The contents of this value are dependant on the type
216
/// contained in <see cref="StreamType" />.
218
public ByteVector TypeSpecificData {
219
get {return type_specific_data;}
223
/// Gets the error correction data contained in the current
227
/// A <see cref="ByteVector" /> object containing the error
228
/// correction data contained in the current instance.
231
/// The contents of this value are dependant on the type
232
/// contained in <see cref="ErrorCorrectionType" />.
234
public ByteVector ErrorCorrectionData {
235
get {return error_correction_data;}
242
#region Public Methods
245
/// Renders the current instance as a raw ASF object.
248
/// A <see cref="ByteVector" /> object containing the
249
/// rendered version of the current instance.
251
public override ByteVector Render ()
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);
265
return Render (output);