|
| 1 | +/*************************************************************************** |
| 2 | + * This library is free software; you can redistribute it and/or modify * |
| 3 | + * it under the terms of the GNU Lesser General Public License version * |
| 4 | + * 2.1 as published by the Free Software Foundation. * |
| 5 | + * * |
| 6 | + * This library is distributed in the hope that it will be useful, but * |
| 7 | + * WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 8 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 9 | + * Lesser General Public License for more details. * |
| 10 | + * * |
| 11 | + * You should have received a copy of the GNU Lesser General Public * |
| 12 | + * License along with this library; if not, write to the Free Software * |
| 13 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * |
| 14 | + * 02110-1301 USA * |
| 15 | + * * |
| 16 | + * Alternatively, this file is available under the Mozilla Public * |
| 17 | + * License Version 1.1. You may obtain a copy of the License at * |
| 18 | + * http://www.mozilla.org/MPL/ * |
| 19 | + ***************************************************************************/ |
| 20 | + |
| 21 | +#include "ebmlmkseekhead.h" |
| 22 | +#include "matroskaseekhead.h" |
| 23 | +#include "ebmluintelement.h" |
| 24 | +#include "ebmlbinaryelement.h" |
| 25 | + |
| 26 | +using namespace TagLib; |
| 27 | + |
| 28 | +Matroska::SeekHead* EBML::MkSeekHead::parse() |
| 29 | +{ |
| 30 | + auto seekHead = new Matroska::SeekHead(); |
| 31 | + seekHead->setOffset(offset); |
| 32 | + seekHead->setSize(getSize() + padding); |
| 33 | + |
| 34 | + for(auto element : elements) { |
| 35 | + if(element->getId() != ElementIDs::MkSeek) |
| 36 | + continue; |
| 37 | + auto seekElement = static_cast<MasterElement*>(element); |
| 38 | + Matroska::Element::ID entryId = 0; |
| 39 | + offset_t offset = 0; |
| 40 | + for(auto seekElementChild : *seekElement) { |
| 41 | + Id id = seekElementChild->getId(); |
| 42 | + if(id == ElementIDs::MkSeekID && !entryId) { |
| 43 | + auto data = static_cast<BinaryElement*>(seekElementChild)->getValue(); |
| 44 | + if(data.size() == 4) |
| 45 | + entryId = data.toUInt(true); |
| 46 | + } |
| 47 | + else if(id == ElementIDs::MkSeekPosition && !offset) |
| 48 | + offset = static_cast<UIntElement*>(seekElementChild)->getValue(); |
| 49 | + } |
| 50 | + if(entryId && offset) |
| 51 | + seekHead->addEntry(entryId, offset); |
| 52 | + else { |
| 53 | + delete seekHead; |
| 54 | + return nullptr; |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + return seekHead; |
| 59 | +} |
0 commit comments