id3lib 3.8.3

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

header_frame.cpp
Go to the documentation of this file.
1 // $Id: header_frame.cpp,v 1.22 2002/07/02 22:13:10 t1mpy Exp $
2
3 // id3lib: a C++ library for creating and manipulating id3v1/v2 tags
4 // Copyright 1999, 2000 Scott Thomas Haug
5
6 // This library is free software; you can redistribute it and/or modify it
7 // under the terms of the GNU Library General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or (at your
9 // option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 // License for more details.
15 //
16 // You should have received a copy of the GNU Library General Public License
17 // along with this library; if not, write to the Free Software Foundation,
18 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 // The id3lib authors encourage improvements and optimisations to be sent to
21 // the id3lib coordinator. Please see the README file for details on where to
22 // send such submissions. See the AUTHORS file for a list of people who have
23 // contributed to id3lib. See the ChangeLog file for a list of changes to
24 // id3lib. These files are distributed with id3lib at
25 // http://download.sourceforge.net/id3lib/
26
27
28 #include <memory.h>
29 #include "header_frame.h"
30 #include "id3/utils.h" // has <config.h> "id3/id3lib_streams.h" "id3/globals.h" "id3/id3lib_strings.h"
31 #include "frame_def.h"
32 #include "field_def.h"
33 #include "field_impl.h"
34 #include "io_helpers.h"
35
36 using namespace dami;
37
38 void ID3_FrameHeader::SetUnknownFrame(const char* id)
39 {
40 Clear();
41 _frame_def = new ID3_FrameDef;
42 if (NULL == _frame_def)
43 {
44 // log this;
45 return;
46 }
47 _frame_def->eID = ID3FID_NOFRAME;
48 _frame_def->bTagDiscard = false;
49 _frame_def->bFileDiscard = false;
50 _frame_def->aeFieldDefs = ID3_FieldDef::DEFAULT;
51 _frame_def->sDescription = NULL;
52 if (strlen(id) <= 3)
53 {
54 strcpy(_frame_def->sShortTextID, id);
55 strcpy(_frame_def->sLongTextID, "");
56 }
57 else
58 {
59 strcpy(_frame_def->sLongTextID, id);
60 strcpy(_frame_def->sShortTextID, "");
61 }
62 _dyn_frame_def = true;
63 }
64
65 bool ID3_FrameHeader::SetFrameID(ID3_FrameID id)
66 {
67 if (id == ID3FID_NOFRAME || id == this->GetFrameID())
68 {
69 return false;
70 }
71 _frame_def = ID3_FindFrameDef(id);
72 _flags.set(TAGALTER, _frame_def->bTagDiscard);
73 _flags.set(FILEALTER, _frame_def->bFileDiscard);
74
75 _changed = true;
76 return true;
77 }
78
79 size_t ID3_FrameHeader::Size() const
80 {
81 if (!_info)
82 {
83 return 0;
84 }
85 return
86 _info->frame_bytes_id +
87 _info->frame_bytes_size +
88 _info->frame_bytes_flags;
89 }
90
91 bool ID3_FrameHeader::Parse(ID3_Reader& reader)
92 {
93 ID3D_NOTICE( "ID3_FrameHeader::Parse(): getCur() = " << reader.getCur() );
94 io::ExitTrigger et(reader);
95 if (!_info)
96 {
97 return false;
98 }
99 if (reader.getEnd() < reader.getCur() + 10)
100 {
101 return false;
102 }
103
104 String textID = io::readText(reader, _info->frame_bytes_id);
105
106 ID3D_NOTICE( "ID3_FrameHeader::Parse: textID = " << textID );
107 ID3D_NOTICE( "ID3_FrameHeader::Parse: getCur() = " << reader.getCur() );
108
109 ID3_FrameID fid = ID3_FindFrameID(textID.c_str());
110 if (ID3FID_NOFRAME == fid)
111 {
112 this->SetUnknownFrame(textID.c_str());
113 ID3D_NOTICE( "ID3_FrameHeader::Parse: unknown frame id" );
114 }
115 else
116 {
117 this->SetFrameID(fid);
118 }
119
120 uint32 dataSize = io::readBENumber(reader, _info->frame_bytes_size);
121 ID3D_NOTICE( "ID3_FrameHeader::Parse: dataSize = " << dataSize );
122 ID3D_NOTICE( "ID3_FrameHeader::Parse: getCur() = " << reader.getCur() );
123 this->SetDataSize(dataSize);
124
125 uint32 flags = io::readBENumber(reader, _info->frame_bytes_flags);
126 _flags.add(flags);
127
128 ID3D_NOTICE( "ID3_FrameHeader::Parse: flags = " << flags );
129 ID3D_NOTICE( "ID3_FrameHeader::Parse: getCur() = " << reader.getCur() );
130 et.setExitPos(reader.getCur());
131
132 return true;
133 }
134
135 void ID3_FrameHeader::Render(ID3_Writer& writer) const
136 {
137 size_t size = 0;
138
139 if (NULL == _frame_def)
140 {
141 // TODO: log this
142 ID3D_WARNING( "ID3_FrameHeader::Render(): _frame_def is NULL!" );
143 return;
144 //ID3_THROW(ID3E_InvalidFrameID);
145 }
146 char *textID;
147 if (_info->frame_bytes_id == strlen(_frame_def->sShortTextID))
148 {
149 textID = _frame_def->sShortTextID;
150 }
151 else
152 {
153 textID = _frame_def->sLongTextID;
154 }
155
156 ID3D_NOTICE( "ID3_FrameHeader::Render(): writing " << textID << ", " << (int) _info->frame_bytes_size << " bytes");
157 writer.writeChars((uchar *) textID, _info->frame_bytes_id);
158
159 io::writeBENumber(writer, _data_size, _info->frame_bytes_size);
160 io::writeBENumber(writer, _flags.get(), _info->frame_bytes_flags);
161 }
162
163 const char* ID3_FrameHeader::GetTextID() const
164 {
165 char *textID = "";
166 if (_info && _frame_def)
167 {
168 if (_info->frame_bytes_id == strlen(_frame_def->sShortTextID))
169 {
170 textID = _frame_def->sShortTextID;
171 }
172 else
173 {
174 textID = _frame_def->sLongTextID;
175 }
176 }
177 return textID;
178 }
179
180 ID3_FrameHeader& ID3_FrameHeader::operator=(const ID3_FrameHeader& hdr)
181 {
182 if (this != &hdr)
183 {
184 this->Clear();
185 this->ID3_Header::operator=(hdr);
186 if (!hdr._dyn_frame_def)
187 {
188 _frame_def = hdr._frame_def;
189 }
190 else
191 {
192 _frame_def = new ID3_FrameDef;
193 if (NULL == _frame_def)
194 {
195 // TODO: throw something here...
196 }
197 _frame_def->eID = hdr._frame_def->eID;
198 _frame_def->bTagDiscard = hdr._frame_def->bTagDiscard;
199 _frame_def->bFileDiscard = hdr._frame_def->bFileDiscard;
200 _frame_def->aeFieldDefs = hdr._frame_def->aeFieldDefs;
201 strcpy(_frame_def->sShortTextID, hdr._frame_def->sShortTextID);
202 strcpy(_frame_def->sLongTextID, hdr._frame_def->sLongTextID);
203 _dyn_frame_def = true;
204 }
205 }
206 return *this;
207 }
208
209 ID3_FrameID ID3_FrameHeader::GetFrameID() const
210 {
211 ID3_FrameID eID = ID3FID_NOFRAME;
212 if (NULL != _frame_def)
213 {
214 eID = _frame_def->eID;
215 }
216
217 return eID;
218 }
219
220 const ID3_FrameDef *ID3_FrameHeader::GetFrameDef() const
221 {
222 return _frame_def;
223 }
224
225 bool ID3_FrameHeader::Clear()
226 {
227 bool changed = this->ID3_Header::Clear();
228 if (_dyn_frame_def)
229 {
230 delete _frame_def;
231 _dyn_frame_def = false;
232 changed = true;
233 }
234 if (_frame_def)
235 {
236 _frame_def = NULL;
237 changed = true;
238 }
239 return changed;
240 }
241
ID3_FrameHeader::SetFrameID
bool SetFrameID(ID3_FrameID id)
Definition: header_frame.cpp:65
ID3_Writer::writeChars
virtual size_type writeChars(const char_type buf[], size_type len)=0
Write up to len characters into buf and advance the internal position accordingly.
ID3_FindFrameDef
ID3_FrameDef * ID3_FindFrameDef(ID3_FrameID id)
Definition: field.cpp:1077
ID3_FrameDef::aeFieldDefs
const ID3_FieldDef * aeFieldDefs
Definition: frame_def.h:43
ID3_FrameDef
Definition: frame_def.h:36
dami::String
std::basic_string< char > String
Definition: id3lib_strings.h:198
ID3_FrameHeader::operator=
ID3_FrameHeader & operator=(const ID3_FrameHeader &)
Definition: header_frame.cpp:180
ID3_FrameDef::bTagDiscard
bool bTagDiscard
Definition: frame_def.h:41
ID3_FrameHeader::GetFrameID
ID3_FrameID GetFrameID() const
Definition: header_frame.cpp:209
ID3_Reader::getCur
virtual pos_type getCur()=0
Return the current position in the reader.
ID3_FrameHeader::Size
size_t Size() const
Definition: header_frame.cpp:79
ID3_FrameHeader::Clear
bool Clear()
Definition: header_frame.cpp:225
ID3_FrameHeader::Parse
bool Parse(ID3_Reader &)
Definition: header_frame.cpp:91
ID3FID_NOFRAME
No known frame.
Definition: globals.h:231
ID3_FrameID
ID3_FrameID
Enumeration of the different types of frames recognized by id3lib.
Definition: globals.h:229
uchar
unsigned char uchar
Definition: globals.h:114
utils.h
ID3_Header::Clear
virtual bool Clear()
Definition: header.h:73
field_def.h
field_impl.h
ID3_FrameDef::bFileDiscard
bool bFileDiscard
Definition: frame_def.h:42
ID3_Reader
Definition: reader.h:33
ID3_FrameDef::sLongTextID
char sLongTextID[4+1]
Definition: frame_def.h:40
ID3_FieldDef::DEFAULT
static const ID3_FieldDef * DEFAULT
Definition: field_def.h:42
ID3_FindFrameID
ID3_FrameID ID3_FindFrameID(const char *id)
Definition: field.cpp:1094
ID3_Reader::getEnd
virtual pos_type getEnd()
Return the ending position in the reader.
Definition: reader.h:51
ID3_FrameHeader
Definition: header_frame.h:36
ID3_FrameDef::eID
ID3_FrameID eID
Definition: frame_def.h:38
ID3_FrameDef::sShortTextID
char sShortTextID[3+1]
Definition: frame_def.h:39
ID3_FrameHeader::Render
void Render(ID3_Writer &) const
Definition: header_frame.cpp:135
header_frame.h
ID3_FrameHeader::GetFrameDef
const ID3_FrameDef * GetFrameDef() const
Definition: header_frame.cpp:220
frame_def.h
NULL
#define NULL
Definition: globals.h:743
ID3_FrameHeader::SetUnknownFrame
void SetUnknownFrame(const char *)
Definition: header_frame.cpp:38
ID3_Writer
Definition: writer.h:33
ID3_Header::operator=
ID3_Header & operator=(const ID3_Header &rhs)
Definition: header.h:90
ID3_FrameHeader::GetTextID
const char * GetTextID() const
Definition: header_frame.cpp:163