2 /*****************************************************************************
3 * mkv.cpp : matroska demuxer
4 *****************************************************************************
5 * Copyright (C) 2003-2004 the VideoLAN team
8 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * Steve Lhomme <steve.lhomme@free.fr>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
27 #include "stream_io_callback.hpp"
28 #include "Ebml_parser.hpp"
30 event_thread_t::event_thread_t(demux_t *p_demux) : p_demux(p_demux)
32 vlc_mutex_init( &lock );
33 vlc_cond_init( &wait );
36 event_thread_t::~event_thread_t()
39 vlc_cond_destroy( &wait );
40 vlc_mutex_destroy( &lock );
43 void event_thread_t::SetPci(const pci_t *data)
45 vlc_mutex_locker l(&lock);
49 #ifndef WORDS_BIGENDIAN
50 for( uint8_t button = 1; button <= pci_packet.hli.hl_gi.btn_ns; button++) {
51 btni_t *button_ptr = &(pci_packet.hli.btnit[button-1]);
52 binary *p_data = (binary*) button_ptr;
54 uint16 i_x_start = ((p_data[0] & 0x3F) << 4 ) + ( p_data[1] >> 4 );
55 uint16 i_x_end = ((p_data[1] & 0x03) << 8 ) + p_data[2];
56 uint16 i_y_start = ((p_data[3] & 0x3F) << 4 ) + ( p_data[4] >> 4 );
57 uint16 i_y_end = ((p_data[4] & 0x03) << 8 ) + p_data[5];
58 button_ptr->x_start = i_x_start;
59 button_ptr->x_end = i_x_end;
60 button_ptr->y_start = i_y_start;
61 button_ptr->y_end = i_y_end;
64 for ( uint8_t i = 0; i<3; i++ )
65 for ( uint8_t j = 0; j<2; j++ )
66 pci_packet.hli.btn_colit.btn_coli[i][j] = U32_AT( &pci_packet.hli.btn_colit.btn_coli[i][j] );
71 is_running = !vlc_clone( &thread, EventThread, this, VLC_THREAD_PRIORITY_LOW );
74 void event_thread_t::ResetPci()
79 vlc_mutex_lock( &lock );
81 vlc_cond_signal( &wait );
82 vlc_mutex_unlock( &lock );
84 vlc_join( thread, NULL );
87 int event_thread_t::EventMouse( vlc_object_t *p_this, char const *psz_var,
88 vlc_value_t oldval, vlc_value_t newval, void *p_data )
90 VLC_UNUSED( oldval ); VLC_UNUSED( newval );
91 event_thread_t *p_ev = (event_thread_t *) p_data;
92 vlc_mutex_lock( &p_ev->lock );
93 if( psz_var[6] == 'c' )
95 p_ev->b_clicked = true;
96 msg_Dbg( p_this, "Event Mouse: clicked");
98 else if( psz_var[6] == 'm' )
100 vlc_cond_signal( &p_ev->wait );
101 vlc_mutex_unlock( &p_ev->lock );
106 int event_thread_t::EventKey( vlc_object_t *p_this, char const *,
107 vlc_value_t, vlc_value_t newval, void *p_data )
109 event_thread_t *p_ev = (event_thread_t *) p_data;
110 vlc_mutex_lock( &p_ev->lock );
111 p_ev->i_key_action = newval.i_int;
112 vlc_cond_signal( &p_ev->wait );
113 vlc_mutex_unlock( &p_ev->lock );
114 msg_Dbg( p_this, "Event Key");
119 int event_thread_t::EventInput( vlc_object_t *p_this, char const *,
120 vlc_value_t, vlc_value_t newval, void *p_data )
122 VLC_UNUSED( p_this );
123 event_thread_t *p_ev = (event_thread_t *) p_data;
124 vlc_mutex_lock( &p_ev->lock );
125 if( newval.i_int == INPUT_EVENT_VOUT )
127 p_ev->b_vout |= true;
128 vlc_cond_signal( &p_ev->wait );
130 vlc_mutex_unlock( &p_ev->lock );
135 void event_thread_t::EventThread()
137 demux_sys_t *p_sys = p_demux->p_sys;
138 vlc_object_t *p_vout = NULL;
139 int canc = vlc_savecancel ();
146 /* catch all key event */
147 var_AddCallback( p_demux->p_libvlc, "key-action", EventKey, this );
148 /* catch input event */
149 var_AddCallback( p_sys->p_input, "intf-event", EventInput, this );
154 vlc_mutex_lock( &lock );
155 while( !b_abort && !i_key_action && !b_moved && !b_clicked && !b_vout)
156 vlc_cond_wait( &wait, &lock );
160 vlc_mutex_unlock( &lock );
167 msg_Dbg( p_demux, "Handle Key Event");
169 pci_t *pci = &pci_packet;
171 uint16 i_curr_button = p_sys->dvd_interpretor.GetSPRM( 0x88 );
173 switch( i_key_action )
175 case ACTIONID_NAV_LEFT:
176 if ( i_curr_button > 0 && i_curr_button <= pci->hli.hl_gi.btn_ns )
178 btni_t *p_button_ptr = &(pci->hli.btnit[i_curr_button-1]);
179 if ( p_button_ptr->left > 0 && p_button_ptr->left <= pci->hli.hl_gi.btn_ns )
181 i_curr_button = p_button_ptr->left;
182 p_sys->dvd_interpretor.SetSPRM( 0x88, i_curr_button );
183 btni_t button_ptr = pci->hli.btnit[i_curr_button-1];
184 if ( button_ptr.auto_action_mode )
186 vlc_mutex_unlock( &lock );
187 vlc_mutex_lock( &p_sys->lock_demuxer );
189 // process the button action
190 p_sys->dvd_interpretor.Interpret( button_ptr.cmd.bytes, 8 );
192 vlc_mutex_unlock( &p_sys->lock_demuxer );
193 vlc_mutex_lock( &lock );
198 case ACTIONID_NAV_RIGHT:
199 if ( i_curr_button > 0 && i_curr_button <= pci->hli.hl_gi.btn_ns )
201 btni_t *p_button_ptr = &(pci->hli.btnit[i_curr_button-1]);
202 if ( p_button_ptr->right > 0 && p_button_ptr->right <= pci->hli.hl_gi.btn_ns )
204 i_curr_button = p_button_ptr->right;
205 p_sys->dvd_interpretor.SetSPRM( 0x88, i_curr_button );
206 btni_t button_ptr = pci->hli.btnit[i_curr_button-1];
207 if ( button_ptr.auto_action_mode )
209 vlc_mutex_unlock( &lock );
210 vlc_mutex_lock( &p_sys->lock_demuxer );
212 // process the button action
213 p_sys->dvd_interpretor.Interpret( button_ptr.cmd.bytes, 8 );
215 vlc_mutex_unlock( &p_sys->lock_demuxer );
216 vlc_mutex_lock( &lock );
221 case ACTIONID_NAV_UP:
222 if ( i_curr_button > 0 && i_curr_button <= pci->hli.hl_gi.btn_ns )
224 btni_t *p_button_ptr = &(pci->hli.btnit[i_curr_button-1]);
225 if ( p_button_ptr->up > 0 && p_button_ptr->up <= pci->hli.hl_gi.btn_ns )
227 i_curr_button = p_button_ptr->up;
228 p_sys->dvd_interpretor.SetSPRM( 0x88, i_curr_button );
229 btni_t button_ptr = pci->hli.btnit[i_curr_button-1];
230 if ( button_ptr.auto_action_mode )
232 vlc_mutex_unlock( &lock );
233 vlc_mutex_lock( &p_sys->lock_demuxer );
235 // process the button action
236 p_sys->dvd_interpretor.Interpret( button_ptr.cmd.bytes, 8 );
238 vlc_mutex_unlock( &p_sys->lock_demuxer );
239 vlc_mutex_lock( &lock );
244 case ACTIONID_NAV_DOWN:
245 if ( i_curr_button > 0 && i_curr_button <= pci->hli.hl_gi.btn_ns )
247 btni_t *p_button_ptr = &(pci->hli.btnit[i_curr_button-1]);
248 if ( p_button_ptr->down > 0 && p_button_ptr->down <= pci->hli.hl_gi.btn_ns )
250 i_curr_button = p_button_ptr->down;
251 p_sys->dvd_interpretor.SetSPRM( 0x88, i_curr_button );
252 btni_t button_ptr = pci->hli.btnit[i_curr_button-1];
253 if ( button_ptr.auto_action_mode )
255 vlc_mutex_unlock( &lock );
256 vlc_mutex_lock( &p_sys->lock_demuxer );
258 // process the button action
259 p_sys->dvd_interpretor.Interpret( button_ptr.cmd.bytes, 8 );
261 vlc_mutex_unlock( &p_sys->lock_demuxer );
262 vlc_mutex_lock( &lock );
267 case ACTIONID_NAV_ACTIVATE:
268 if ( i_curr_button > 0 && i_curr_button <= pci->hli.hl_gi.btn_ns )
270 btni_t button_ptr = pci->hli.btnit[i_curr_button-1];
272 vlc_mutex_unlock( &lock );
273 vlc_mutex_lock( &p_sys->lock_demuxer );
275 // process the button action
276 p_sys->dvd_interpretor.Interpret( button_ptr.cmd.bytes, 8 );
278 vlc_mutex_unlock( &p_sys->lock_demuxer );
279 vlc_mutex_lock( &lock );
289 if( p_vout && ( b_moved || b_clicked ) )
293 var_GetCoords( p_vout, "mouse-moved", &x, &y );
294 pci_t *pci = &pci_packet;
302 msg_Dbg( p_demux, "Handle Mouse Event: Mouse clicked x(%d)*y(%d)", x, y);
304 // get current button
306 dist = 0x08000000; /* >> than (720*720)+(567*567); */
307 for(button = 1; button <= pci->hli.hl_gi.btn_ns; button++)
309 btni_t *button_ptr = &(pci->hli.btnit[button-1]);
311 if(((unsigned)x >= button_ptr->x_start)
312 && ((unsigned)x <= button_ptr->x_end)
313 && ((unsigned)y >= button_ptr->y_start)
314 && ((unsigned)y <= button_ptr->y_end))
316 mx = (button_ptr->x_start + button_ptr->x_end)/2;
317 my = (button_ptr->y_start + button_ptr->y_end)/2;
320 d = (dx*dx) + (dy*dy);
321 /* If the mouse is within the button and the mouse is closer
322 * to the center of this button then it is the best choice. */
332 btni_t button_ptr = pci->hli.btnit[best-1];
333 uint16 i_curr_button = p_sys->dvd_interpretor.GetSPRM( 0x88 );
335 msg_Dbg( &p_sys->demuxer, "Clicked button %d", best );
336 vlc_mutex_unlock( &lock );
337 vlc_mutex_lock( &p_sys->lock_demuxer );
339 // process the button action
340 p_sys->dvd_interpretor.SetSPRM( 0x88, best );
341 p_sys->dvd_interpretor.Interpret( button_ptr.cmd.bytes, 8 );
343 msg_Dbg( &p_sys->demuxer, "Processed button %d", best );
346 if ( best != i_curr_button )
350 if(button_ptr.btn_coln != 0) {
351 i_palette = pci->hli.btn_colit.btn_coli[button_ptr.btn_coln-1][1];
356 for( int i = 0; i < 4; i++ )
358 uint32_t i_yuv = 0xFF;//p_sys->clut[(hl.palette>>(16+i*4))&0x0f];
359 uint8_t i_alpha = (i_palette>>(i*4))&0x0f;
360 i_alpha = i_alpha == 0xf ? 0xff : i_alpha << 4;
362 p_sys->palette[i][0] = (i_yuv >> 16) & 0xff;
363 p_sys->palette[i][1] = (i_yuv >> 0) & 0xff;
364 p_sys->palette[i][2] = (i_yuv >> 8) & 0xff;
365 p_sys->palette[i][3] = i_alpha;
368 vlc_global_lock( VLC_HIGHLIGHT_MUTEX );
369 var_SetInteger( p_sys->p_input, "x-start",
370 button_ptr.x_start );
371 var_SetInteger( p_sys->p_input, "x-end",
373 var_SetInteger( p_sys->p_input, "y-start",
374 button_ptr.y_start );
375 var_SetInteger( p_sys->p_input, "y-end",
377 var_SetAddress( p_sys->p_input, "menu-palette",
379 var_SetBool( p_sys->p_input, "highlight", true );
380 vlc_global_unlock( VLC_HIGHLIGHT_MUTEX );
382 vlc_mutex_unlock( &p_sys->lock_demuxer );
383 vlc_mutex_lock( &lock );
388 // dvdnav_mouse_select( NULL, pci, x, y );
396 vlc_mutex_unlock( &lock );
398 /* Always check vout */
399 if( p_vout && !vlc_object_alive (p_vout) )
401 var_DelCallback( p_vout, "mouse-moved", EventMouse, this );
402 var_DelCallback( p_vout, "mouse-clicked", EventMouse, this );
403 vlc_object_release( p_vout );
407 else if( p_vout == NULL )
409 p_vout = (vlc_object_t*) input_GetVout(p_sys->p_input);
412 var_AddCallback( p_vout, "mouse-moved", EventMouse, this );
413 var_AddCallback( p_vout, "mouse-clicked", EventMouse, this );
418 /* Release callback */
421 var_DelCallback( p_vout, "mouse-moved", EventMouse, this );
422 var_DelCallback( p_vout, "mouse-clicked", EventMouse, this );
423 vlc_object_release( p_vout );
425 var_DelCallback( p_sys->p_input, "intf-event", EventInput, this );
426 var_DelCallback( p_demux->p_libvlc, "key-action", EventKey, this );
428 vlc_restorecancel (canc);
431 void *event_thread_t::EventThread(void *data)
433 static_cast<event_thread_t*>(data)->EventThread();
438 demux_sys_t::~demux_sys_t()
442 for ( i=0; i<streams.size(); i++ )
444 for ( i=0; i<opened_segments.size(); i++ )
445 delete opened_segments[i];
446 for ( i=0; i<used_segments.size(); i++ )
447 delete used_segments[i];
448 for ( i=0; i<stored_attachments.size(); i++ )
449 delete stored_attachments[i];
450 if( meta ) vlc_meta_Delete( meta );
452 while( titles.size() )
453 { vlc_input_title_Delete( titles.back() ); titles.pop_back();}
455 vlc_mutex_destroy( &lock_demuxer );
459 matroska_stream_c *demux_sys_t::AnalyseAllSegmentsFound( demux_t *p_demux, EbmlStream *p_estream, bool b_initial )
462 EbmlElement *p_l0, *p_l1, *p_l2;
463 bool b_keep_stream = false, b_keep_segment = false;
465 // verify the EBML Header
466 vlc_stream_io_callback & io_stream = (vlc_stream_io_callback &) p_estream->I_O();
467 p_l0 = p_estream->FindNextID(EBML_INFO(EbmlHead), io_stream.toRead());
470 msg_Err( p_demux, "No EBML header found" );
474 // verify we can read this Segment, we only support Matroska version 1 for now
475 p_l0->Read(*p_estream, EBML_CLASS_CONTEXT(EbmlHead), i_upper_lvl, p_l0, true);
477 EDocType doc_type = GetChild<EDocType>(*static_cast<EbmlHead*>(p_l0));
478 if (std::string(doc_type) != "matroska" && std::string(doc_type) != "webm" )
480 msg_Err( p_demux, "Not a Matroska file : DocType = %s ", std::string(doc_type).c_str());
484 EDocTypeReadVersion doc_read_version = GetChild<EDocTypeReadVersion>(*static_cast<EbmlHead*>(p_l0));
485 if (uint64(doc_read_version) > 2)
487 msg_Err( p_demux, "matroska file needs version %"PRId64" but only versions 1 & 2 supported", uint64(doc_read_version));
494 // find all segments in this file
495 p_l0 = p_estream->FindNextID(EBML_INFO(KaxSegment), io_stream.toRead());
501 matroska_stream_c *p_stream1 = new matroska_stream_c();
505 if ( MKV_IS_ID( p_l0, KaxSegment) )
508 matroska_segment_c *p_segment1 = new matroska_segment_c( *this, *p_estream );
510 ep = new EbmlParser(p_estream, p_l0, &demuxer );
512 p_segment1->segment = (KaxSegment*)p_l0;
514 while ((p_l1 = ep->Get()))
516 if (MKV_IS_ID(p_l1, KaxInfo))
518 // find the families of this segment
519 KaxInfo *p_info = static_cast<KaxInfo*>(p_l1);
520 b_keep_segment = b_initial;
522 p_info->Read(*p_estream, EBML_CLASS_CONTEXT(KaxInfo), i_upper_lvl, p_l2, true);
523 for( size_t i = 0; i < p_info->ListSize(); i++ )
525 EbmlElement *l = (*p_info)[i];
527 if( MKV_IS_ID( l, KaxSegmentUID ) )
529 KaxSegmentUID *p_uid = static_cast<KaxSegmentUID*>(l);
530 b_keep_segment = (FindSegment( *p_uid ) == NULL);
531 if ( !b_keep_segment )
532 break; // this segment is already known
533 delete p_segment1->p_segment_uid;
534 p_segment1->p_segment_uid = new KaxSegmentUID(*p_uid);
536 else if( MKV_IS_ID( l, KaxPrevUID ) )
538 p_segment1->p_prev_segment_uid = new KaxPrevUID( *static_cast<KaxPrevUID*>(l) );
540 else if( MKV_IS_ID( l, KaxNextUID ) )
542 p_segment1->p_next_segment_uid = new KaxNextUID( *static_cast<KaxNextUID*>(l) );
544 else if( MKV_IS_ID( l, KaxSegmentFamily ) )
546 KaxSegmentFamily *p_fam = new KaxSegmentFamily( *static_cast<KaxSegmentFamily*>(l) );
547 p_segment1->families.push_back( p_fam );
550 if( b_keep_segment || !p_segment1->p_segment_uid )
551 opened_segments.push_back( p_segment1 );
555 if ( b_keep_segment )
557 b_keep_stream = true;
558 p_stream1->segments.push_back( p_segment1 );
562 p_segment1->segment = NULL;
566 if (p_l0->IsFiniteSize() )
568 p_l0->SkipData(*p_estream, KaxMatroska_Context);
569 p_l0 = p_estream->FindNextID(EBML_INFO(KaxSegment), io_stream.toRead());
577 if ( !b_keep_stream )
586 void demux_sys_t::InitUi()
588 msg_Dbg( &demuxer, "Starting the UI Hook" );
590 /* FIXME hack hack hack hack FIXME */
591 /* Get p_input and create variable */
592 p_input = demux_GetParentInput( &demuxer );
595 var_Create( p_input, "x-start", VLC_VAR_INTEGER );
596 var_Create( p_input, "y-start", VLC_VAR_INTEGER );
597 var_Create( p_input, "x-end", VLC_VAR_INTEGER );
598 var_Create( p_input, "y-end", VLC_VAR_INTEGER );
599 var_Create( p_input, "color", VLC_VAR_ADDRESS );
600 var_Create( p_input, "menu-palette", VLC_VAR_ADDRESS );
601 var_Create( p_input, "highlight", VLC_VAR_BOOL );
604 /* Now create our event thread catcher */
605 p_ev = new event_thread_t(&demuxer);
608 void demux_sys_t::CleanUi()
615 var_Destroy( p_input, "highlight" );
616 var_Destroy( p_input, "x-start" );
617 var_Destroy( p_input, "x-end" );
618 var_Destroy( p_input, "y-start" );
619 var_Destroy( p_input, "y-end" );
620 var_Destroy( p_input, "color" );
621 var_Destroy( p_input, "menu-palette" );
623 vlc_object_release( p_input );
626 msg_Dbg( &demuxer, "Stopping the UI Hook" );
629 void demux_sys_t::PreloadFamily( const matroska_segment_c & of_segment )
631 for (size_t i=0; i<opened_segments.size(); i++)
633 opened_segments[i]->PreloadFamily( of_segment );
637 // preload all the linked segments for all preloaded segments
638 bool demux_sys_t::PreloadLinked()
641 virtual_segment_c *p_seg;
643 p_current_segment = VirtualFromSegments( &opened_segments );
644 if ( !p_current_segment )
647 used_segments.push_back( p_current_segment );
649 // publish all editions of all usable segment
650 for ( i=0; i< used_segments.size(); i++ )
652 p_seg = used_segments[i];
653 if ( p_seg->Editions() != NULL )
655 input_title_t *p_title = vlc_input_title_New();
656 p_seg->i_sys_title = i;
659 // TODO use a name for each edition, let the TITLE deal with a codec name
660 for ( j=0; j<p_seg->Editions()->size(); j++ )
662 if ( p_title->psz_name == NULL )
664 const char* psz_tmp = (*p_seg->Editions())[j]->GetMainName().c_str();
665 if( *psz_tmp != '\0' )
666 p_title->psz_name = strdup( psz_tmp );
670 ( *p_seg->Editions() )[j]->PublishChapters( *p_title, i_chapters, 0 );
672 // Input duration into i_length
673 p_title->i_length = ( *p_seg->Editions() )[j]->i_duration;
676 // create a name if there is none
677 if ( p_title->psz_name == NULL )
679 if( asprintf(&(p_title->psz_name), "%s %d", N_("Segment"), (int)i) == -1 )
680 p_title->psz_name = NULL;
683 titles.push_back( p_title );
687 // TODO decide which segment should be first used (VMG for DVD)
692 virtual_segment_c *demux_sys_t::VirtualFromSegments( std::vector<matroska_segment_c*> *p_segments ) const
694 if ( p_segments->empty() )
696 virtual_segment_c *p_result = new virtual_segment_c( p_segments );
700 bool demux_sys_t::PreparePlayback( virtual_segment_c *p_new_segment )
702 if ( p_new_segment != NULL && p_new_segment != p_current_segment )
704 if ( p_current_segment != NULL && p_current_segment->CurrentSegment() != NULL )
705 p_current_segment->CurrentSegment()->UnSelect();
707 p_current_segment = p_new_segment;
708 i_current_title = p_new_segment->i_sys_title;
710 if( !p_current_segment->CurrentSegment() )
712 if( !p_current_segment->CurrentSegment()->b_cues )
713 msg_Warn( &p_current_segment->CurrentSegment()->sys.demuxer, "no cues/empty cues found->seek won't be precise" );
715 f_duration = p_current_segment->Duration();
717 /* add information */
718 p_current_segment->CurrentSegment()->InformationCreate( );
719 p_current_segment->CurrentSegment()->Select( 0 );
724 void demux_sys_t::JumpTo( virtual_segment_c & vsegment, virtual_chapter_c * p_chapter )
726 // if the segment is not part of the current segment, select the new one
727 if ( &vsegment != p_current_segment )
729 PreparePlayback( &vsegment );
734 if ( !p_chapter->p_chapter || !p_chapter->p_chapter->Enter( true ) )
736 // jump to the location in the found segment
737 vsegment.Seek( demuxer, p_chapter->i_virtual_start_time, -1, p_chapter, -1 );
743 matroska_segment_c *demux_sys_t::FindSegment( const EbmlBinary & uid ) const
745 for (size_t i=0; i<opened_segments.size(); i++)
747 if ( *opened_segments[i]->p_segment_uid == uid )
748 return opened_segments[i];
753 virtual_chapter_c *demux_sys_t::BrowseCodecPrivate( unsigned int codec_id,
754 bool (*match)(const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size ),
755 const void *p_cookie,
756 size_t i_cookie_size,
757 virtual_segment_c * &p_segment_found )
759 virtual_chapter_c *p_result = NULL;
760 for (size_t i=0; i<used_segments.size(); i++)
762 p_result = used_segments[i]->BrowseCodecPrivate( codec_id, match, p_cookie, i_cookie_size );
763 if ( p_result != NULL )
765 p_segment_found = used_segments[i];
772 virtual_chapter_c *demux_sys_t::FindChapter( int64_t i_find_uid, virtual_segment_c * & p_segment_found )
774 virtual_chapter_c *p_result = NULL;
775 for (size_t i=0; i<used_segments.size(); i++)
777 p_result = used_segments[i]->FindChapter( i_find_uid );
778 if ( p_result != NULL )
780 p_segment_found = used_segments[i];