00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #if defined HAVE_CONFIG_H
00028 #include <config.h>
00029 #endif
00030
00031
00032
00033 #include <string.h>
00034 #include <memory.h>
00035 #include "header_frame.h"
00036 #include "utils.h"
00037 #include "frame_def.h"
00038 #include "field_def.h"
00039 #include "field_impl.h"
00040 #include "io_helpers.h"
00041
00042 using namespace dami;
00043
00044 void ID3_FrameHeader::SetUnknownFrame(const char* id)
00045 {
00046 Clear();
00047 _frame_def = new ID3_FrameDef;
00048 if (NULL == _frame_def)
00049 {
00050
00051 return;
00052 }
00053 _frame_def->eID = ID3FID_NOFRAME;
00054 _frame_def->bTagDiscard = false;
00055 _frame_def->bFileDiscard = false;
00056 _frame_def->aeFieldDefs = ID3_FieldDef::DEFAULT;
00057 _frame_def->sDescription = NULL;
00058 if (strlen(id) <= 3)
00059 {
00060 strcpy(_frame_def->sShortTextID, id);
00061 strcpy(_frame_def->sLongTextID, "");
00062 }
00063 else
00064 {
00065 strcpy(_frame_def->sLongTextID, id);
00066 strcpy(_frame_def->sShortTextID, "");
00067 }
00068 _dyn_frame_def = true;
00069 }
00070
00071 bool ID3_FrameHeader::SetFrameID(ID3_FrameID id)
00072 {
00073 if (id == ID3FID_NOFRAME || id == this->GetFrameID())
00074 {
00075 return false;
00076 }
00077 _frame_def = ID3_FindFrameDef(id);
00078 _flags.set(TAGALTER, _frame_def->bTagDiscard);
00079 _flags.set(FILEALTER, _frame_def->bFileDiscard);
00080
00081 _changed = true;
00082 return true;
00083 }
00084
00085 size_t ID3_FrameHeader::Size() const
00086 {
00087 if (!_info)
00088 {
00089 return 0;
00090 }
00091 return
00092 _info->frame_bytes_id +
00093 _info->frame_bytes_size +
00094 _info->frame_bytes_flags;
00095 }
00096
00097 bool ID3_FrameHeader::Parse(ID3_Reader& reader)
00098 {
00099 ID3D_NOTICE( "ID3_FrameHeader::Parse(): getCur() = " << reader.getCur() );
00100 io::ExitTrigger et(reader);
00101 if (!_info)
00102 {
00103 return false;
00104 }
00105 if (reader.getEnd() < reader.getCur() + 10)
00106 {
00107 return false;
00108 }
00109
00110 String textID = io::readText(reader, _info->frame_bytes_id);
00111
00112 ID3D_NOTICE( "ID3_FrameHeader::Parse: textID = " << textID );
00113 ID3D_NOTICE( "ID3_FrameHeader::Parse: getCur() = " << reader.getCur() );
00114
00115 ID3_FrameID fid = ID3_FindFrameID(textID.c_str());
00116 if (ID3FID_NOFRAME == fid)
00117 {
00118 this->SetUnknownFrame(textID.c_str());
00119 ID3D_NOTICE( "ID3_FrameHeader::Parse: unknown frame id" );
00120 }
00121 else
00122 {
00123 this->SetFrameID(fid);
00124 }
00125
00126 uint32 dataSize = io::readBENumber(reader, _info->frame_bytes_size);
00127 ID3D_NOTICE( "ID3_FrameHeader::Parse: dataSize = " << dataSize );
00128 ID3D_NOTICE( "ID3_FrameHeader::Parse: getCur() = " << reader.getCur() );
00129 this->SetDataSize(dataSize);
00130
00131 uint32 flags = io::readBENumber(reader, _info->frame_bytes_flags);
00132 _flags.add(flags);
00133
00134 ID3D_NOTICE( "ID3_FrameHeader::Parse: flags = " << flags );
00135 ID3D_NOTICE( "ID3_FrameHeader::Parse: getCur() = " << reader.getCur() );
00136 et.setExitPos(reader.getCur());
00137
00138 return true;
00139 }
00140
00141 void ID3_FrameHeader::Render(ID3_Writer& writer) const
00142 {
00143 size_t size = 0;
00144
00145 if (NULL == _frame_def)
00146 {
00147
00148 ID3D_WARNING( "ID3_FrameHeader::Render(): _frame_def is NULL!" );
00149 return;
00150
00151 }
00152 char *textID;
00153 if (_info->frame_bytes_id == strlen(_frame_def->sShortTextID))
00154 {
00155 textID = _frame_def->sShortTextID;
00156 }
00157 else
00158 {
00159 textID = _frame_def->sLongTextID;
00160 }
00161
00162 ID3D_NOTICE( "ID3_FrameHeader::Render(): writing " << textID << ", " << (int) _info->frame_bytes_size << " bytes");
00163 writer.writeChars((uchar *) textID, _info->frame_bytes_id);
00164
00165 io::writeBENumber(writer, _data_size, _info->frame_bytes_size);
00166 io::writeBENumber(writer, _flags.get(), _info->frame_bytes_flags);
00167 }
00168
00169 const char* ID3_FrameHeader::GetTextID() const
00170 {
00171 char *textID = "";
00172 if (_info && _frame_def)
00173 {
00174 if (_info->frame_bytes_id == strlen(_frame_def->sShortTextID))
00175 {
00176 textID = _frame_def->sShortTextID;
00177 }
00178 else
00179 {
00180 textID = _frame_def->sLongTextID;
00181 }
00182 }
00183 return textID;
00184 }
00185
00186 ID3_FrameHeader& ID3_FrameHeader::operator=(const ID3_FrameHeader& hdr)
00187 {
00188 if (this != &hdr)
00189 {
00190 this->Clear();
00191 this->ID3_Header::operator=(hdr);
00192 if (!hdr._dyn_frame_def)
00193 {
00194 _frame_def = hdr._frame_def;
00195 }
00196 else
00197 {
00198 _frame_def = new ID3_FrameDef;
00199 if (NULL == _frame_def)
00200 {
00201
00202 }
00203 _frame_def->eID = hdr._frame_def->eID;
00204 _frame_def->bTagDiscard = hdr._frame_def->bTagDiscard;
00205 _frame_def->bFileDiscard = hdr._frame_def->bFileDiscard;
00206 _frame_def->aeFieldDefs = hdr._frame_def->aeFieldDefs;
00207 strcpy(_frame_def->sShortTextID, hdr._frame_def->sShortTextID);
00208 strcpy(_frame_def->sLongTextID, hdr._frame_def->sLongTextID);
00209 _dyn_frame_def = true;
00210 }
00211 }
00212 return *this;
00213 }
00214
00215 ID3_FrameID ID3_FrameHeader::GetFrameID() const
00216 {
00217 ID3_FrameID eID = ID3FID_NOFRAME;
00218 if (NULL != _frame_def)
00219 {
00220 eID = _frame_def->eID;
00221 }
00222
00223 return eID;
00224 }
00225
00226 const ID3_FrameDef *ID3_FrameHeader::GetFrameDef() const
00227 {
00228 return _frame_def;
00229 }
00230
00231 bool ID3_FrameHeader::Clear()
00232 {
00233 bool changed = this->ID3_Header::Clear();
00234 if (_dyn_frame_def)
00235 {
00236 delete _frame_def;
00237 _dyn_frame_def = false;
00238 changed = true;
00239 }
00240 if (_frame_def)
00241 {
00242 _frame_def = NULL;
00243 changed = true;
00244 }
00245 return changed;
00246 }