AtomsReader.cpp 2.09 KB
Newer Older
1 2 3
/*
 * AtomsReader.cpp
 *****************************************************************************
4
 * Copyright (C) 2014 - VideoLAN and VLC authors
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/
#include "AtomsReader.hpp"
21
#include <new>
22

23
using namespace adaptative::mp4;
24

25
AtomsReader::AtomsReader(vlc_object_t *object_)
26
{
27
    object = object_;
28 29 30 31
    rootbox = NULL;
}

AtomsReader::~AtomsReader()
32 33 34 35 36
{
    clean();
}

void AtomsReader::clean()
37 38 39 40
{
    while(rootbox && rootbox->p_first)
    {
        MP4_Box_t *p_next = rootbox->p_first->p_next;
41
        MP4_BoxFree( rootbox->p_first );
42 43 44
        rootbox->p_first = p_next;
    }
    delete rootbox;
45
    rootbox = NULL;
46 47
}

48
bool AtomsReader::parseBlock(block_t *p_block)
49
{
50 51
    if(rootbox)
        clean();
52

53
    stream_t *stream = stream_MemoryNew( object, p_block->p_buffer, p_block->i_buffer, true);
54 55
    if (stream)
    {
56
        rootbox = new (std::nothrow) MP4_Box_t;
57 58 59 60 61 62 63
        if(!rootbox)
        {
            stream_Delete(stream);
            return false;
        }
        memset(rootbox, 0, sizeof(*rootbox));
        rootbox->i_type = ATOM_root;
64
        rootbox->i_size = p_block->i_buffer;
65
        if ( MP4_ReadBoxContainerChildren( stream, rootbox, NULL ) == 1 )
66 67 68 69 70 71 72 73 74 75
        {
#ifndef NDEBUG
            MP4_BoxDumpStructure(stream, rootbox);
#endif
        }
        stream_Delete(stream);
    }

    return true;
}