1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
|
/*****************************************************************************
* chapters.cpp : matroska demuxer
*****************************************************************************
* Copyright (C) 2003-2004 VLC authors and VideoLAN
* $Id: b8dab0c7d6021502cae873097c36f6381b86e254 $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Steve Lhomme <steve.lhomme@free.fr>
*
* 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 "chapters.hpp"
#include "chapter_command.hpp"
chapter_item_c::~chapter_item_c()
{
if( p_segment_uid )
delete p_segment_uid;
if( p_segment_edition_uid )
delete p_segment_edition_uid;
vlc_delete_all( codecs );
vlc_delete_all( sub_chapters );
}
chapter_item_c *chapter_item_c::BrowseCodecPrivate( unsigned int codec_id,
bool (*match)(const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size ),
const void *p_cookie,
size_t i_cookie_size )
{
VLC_UNUSED( codec_id );
// this chapter
std::vector<chapter_codec_cmds_c*>::const_iterator index = codecs.begin();
while ( index != codecs.end() )
{
if ( match( **index ,p_cookie, i_cookie_size ) )
return this;
++index;
}
return NULL;
}
void chapter_item_c::Append( const chapter_item_c & chapter )
{
// we are appending content for the same chapter UID
size_t i;
chapter_item_c *p_chapter;
for ( i=0; i<chapter.sub_chapters.size(); i++ )
{
p_chapter = FindChapter( chapter.sub_chapters[i]->i_uid );
if ( p_chapter != NULL )
{
p_chapter->Append( *chapter.sub_chapters[i] );
}
else
{
sub_chapters.push_back( chapter.sub_chapters[i] );
}
}
}
chapter_item_c * chapter_item_c::FindChapter( int64_t i_find_uid )
{
size_t i;
chapter_item_c *p_result = NULL;
if ( i_uid == i_find_uid )
return this;
for ( i=0; i<sub_chapters.size(); i++)
{
p_result = sub_chapters[i]->FindChapter( i_find_uid );
if ( p_result != NULL )
break;
}
return p_result;
}
std::string chapter_item_c::GetCodecName( bool f_for_title ) const
{
std::string result;
std::vector<chapter_codec_cmds_c*>::const_iterator index = codecs.begin();
while ( index != codecs.end() )
{
result = (*index)->GetCodecName( f_for_title );
if ( result != "" )
break;
++index;
}
return result;
}
int16 chapter_item_c::GetTitleNumber( ) const
{
int result = -1;
std::vector<chapter_codec_cmds_c*>::const_iterator index = codecs.begin();
while ( index != codecs.end() )
{
result = (*index)->GetTitleNumber( );
if ( result >= 0 )
break;
++index;
}
return result;
}
bool chapter_item_c::ParentOf( const chapter_item_c & item ) const
{
if ( &item == this )
return true;
std::vector<chapter_item_c*>::const_iterator index = sub_chapters.begin();
while ( index != sub_chapters.end() )
{
if ( (*index)->ParentOf( item ) )
return true;
++index;
}
return false;
}
bool chapter_item_c::Enter( bool b_do_subs )
{
bool f_result = false;
std::vector<chapter_codec_cmds_c*>::iterator index = codecs.begin();
while ( index != codecs.end() )
{
f_result |= (*index)->Enter();
++index;
}
if ( b_do_subs )
{
// sub chapters
std::vector<chapter_item_c*>::iterator index_ = sub_chapters.begin();
while ( index_ != sub_chapters.end() )
{
f_result |= (*index_)->Enter( true );
++index_;
}
}
return f_result;
}
bool chapter_item_c::Leave( bool b_do_subs )
{
bool f_result = false;
b_is_leaving = true;
std::vector<chapter_codec_cmds_c*>::iterator index = codecs.begin();
while ( index != codecs.end() )
{
f_result |= (*index)->Leave();
++index;
}
if ( b_do_subs )
{
// sub chapters
std::vector<chapter_item_c*>::iterator index_ = sub_chapters.begin();
while ( index_ != sub_chapters.end() )
{
f_result |= (*index_)->Leave( true );
++index_;
}
}
b_is_leaving = false;
return f_result;
}
bool chapter_item_c::EnterAndLeave( chapter_item_c *p_item, bool b_final_enter )
{
chapter_item_c *p_common_parent = p_item;
// leave, up to a common parent
while ( p_common_parent != NULL && !p_common_parent->ParentOf( *this ) )
{
if ( !p_common_parent->b_is_leaving && p_common_parent->Leave( false ) )
return true;
p_common_parent = p_common_parent->p_parent;
}
// enter from the parent to <this>
if ( p_common_parent != NULL )
{
do
{
if ( p_common_parent == this )
return Enter( true );
for ( size_t i = 0; i<p_common_parent->sub_chapters.size(); i++ )
{
if ( p_common_parent->sub_chapters[i]->ParentOf( *this ) )
{
p_common_parent = p_common_parent->sub_chapters[i];
if ( p_common_parent != this )
if ( p_common_parent->Enter( false ) )
return true;
break;
}
}
} while ( 1 );
}
if ( b_final_enter )
return Enter( true );
else
return false;
}
/* Chapter Edition Class */
std::string chapter_edition_c::GetMainName() const
{
if ( sub_chapters.size() )
{
return sub_chapters[0]->GetCodecName( true );
}
return "";
}
|