VlcWrapper.cpp 19.5 KB
Newer Older
1
/*****************************************************************************
2
 * VlcWrapper.cpp: BeOS plugin for vlc (derived from MacOS X port)
3
4
 *****************************************************************************
 * Copyright (C) 2001 VideoLAN
5
 * $Id: VlcWrapper.cpp,v 1.22 2003/01/27 10:29:22 titer Exp $
6
7
8
9
 *
 * Authors: Florian G. Pflug <fgp@phlo.org>
 *          Jon Lech Johansen <jon-vl@nanocrew.net>
 *          Tony Casltey <tony@castley.net>
10
 *          Stephan Aßmus <stippi@yellowbites.com>
11
 *          Eric Petit <titer@videolan.org>
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 *
 * This program is free software{} you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation{} either version 2 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program{} if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/
27
28
#include <AppKit.h>
#include <InterfaceKit.h>
29
30
31
32
#include <SupportKit.h>

#include <vlc/vlc.h>
#include <vlc/intf.h>
33
extern "C" {
34
35
#include <audio_output.h>
#include <aout_internal.h>
36
}
37

38
#include "VlcWrapper.h"
39
#include "MsgVals.h"
40

41
/* constructor */
42
VlcWrapper::VlcWrapper( intf_thread_t *p_interface )
43
{
44
    p_intf = p_interface;
45
46
47
48
    p_input = NULL;
    p_aout = NULL;
    p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                FIND_ANYWHERE );
49
50
}

51
/* destructor */
52
VlcWrapper::~VlcWrapper()
53
{
54
55
56
57
58
59
60
61
62
63
64
65
    if( p_input )
    {
        vlc_object_release( p_input );
    }
    if( p_playlist )
    {
        vlc_object_release( p_playlist );
    }
    if( p_aout )
    {
        vlc_object_release( p_aout );
    }
66
}
67
68
69

/* UpdateInputAndAOut: updates p_input and p_aout, returns true if the
   interface needs to be updated */
70
bool VlcWrapper::UpdateInputAndAOut()
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
{
    if( p_input == NULL )
    {
        p_input = (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
                                                     FIND_ANYWHERE );
    }
    if( p_aout == NULL )
    {
        p_aout = (aout_instance_t*)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
                                                    FIND_ANYWHERE );
    }
        
    if( p_input != NULL )
    {
        if( p_input->b_dead )
        {
            vlc_object_release( p_input );
            p_input = NULL;
            
            if( p_aout )
            {
                vlc_object_release( p_aout );
                p_aout = NULL;
            }
        }
        return true;
    }
    return false;
}

101
102
103
104
105

/***************************
 * input infos and control *
 ***************************/

106
107
bool VlcWrapper::HasInput()
{
108
    return ( p_input != NULL );
109
110
}

111
int VlcWrapper::InputStatus()
112
{
113
114
115
116
    if( !p_input )
    {
        return UNDEF_S;
    }
117
118
119
    return p_input->stream.control.i_status;
}

120
int VlcWrapper::InputRate()
121
{
122
123
124
125
    if( !p_input )
    {
        return DEFAULT_RATE;
    }
126
127
128
    return p_input->stream.control.i_rate;
}

129
void VlcWrapper::InputSlower()
130
{
131
132
133
134
    if( p_input != NULL )
    {
        input_SetStatus( p_input, INPUT_STATUS_SLOWER );
    }
135
136
}

137
void VlcWrapper::InputFaster()
138
{
139
140
141
142
    if( p_input != NULL )
    {
        input_SetStatus( p_input, INPUT_STATUS_FASTER );
    }
143
144
}

Eric Petit's avatar
Eric Petit committed
145
BList * VlcWrapper::GetChannels( int i_cat )
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
{
    if( p_input )
    {
        unsigned int i;
        uint32 what;
        const char* fieldName;

        switch( i_cat )
        {
            case AUDIO_ES:
            {
                what = SELECT_CHANNEL;
                fieldName = "channel";
                break;
            }
            case SPU_ES:
            {
                what = SELECT_SUBTITLE;
                fieldName = "subtitle";
                break;
            }
            default:
            return NULL;
       }

        vlc_mutex_lock( &p_input->stream.stream_lock );
      
        /* find which track is currently playing */
        es_descriptor_t *p_es = NULL;
        for( i = 0; i < p_input->stream.i_selected_es_number; i++ )
        {
            if( p_input->stream.pp_selected_es[i]->i_cat == i_cat )
                p_es = p_input->stream.pp_selected_es[i];
        }
        
        /* build a list of all tracks */
        BList *list = new BList( p_input->stream.i_es_number );
        BMenuItem *menuItem;
        BMessage *message;
        char *trackName;
        
        /* "None" */
        message = new BMessage( what );
        message->AddInt32( fieldName, -1 );
        menuItem = new BMenuItem( "None", message );
        if( !p_es )
            menuItem->SetMarked( true );
        list->AddItem( menuItem );
        
        for( i = 0; i < p_input->stream.i_es_number; i++ )
        {
            if( p_input->stream.pp_es[i]->i_cat == i_cat )
            {
                message = new BMessage( what );
                message->AddInt32( fieldName, i );
                if( strlen( p_input->stream.pp_es[i]->psz_desc ) )
                    trackName = strdup( p_input->stream.pp_es[i]->psz_desc );
                else
                    trackName = "<unknown>";
                menuItem = new BMenuItem( trackName, message );
                if( p_input->stream.pp_es[i] == p_es )
                    menuItem->SetMarked( true );
                list->AddItem( menuItem );
            }
        }
        
        vlc_mutex_unlock( &p_input->stream.stream_lock );

        return list;
    }
    return NULL;
217
218
}

219
void VlcWrapper::ToggleLanguage( int i_language )
220
{
221
222
    es_descriptor_t * p_es = NULL;
    es_descriptor_t * p_es_old = NULL;
223
224

    vlc_mutex_lock( &p_input->stream.stream_lock );
225
    for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
226
    {
227
        if( p_input->stream.pp_selected_es[i]->i_cat == AUDIO_ES )
228
        {
229
            p_es_old = p_input->stream.pp_selected_es[i];
230
231
232
233
            break;
        }
    }
    vlc_mutex_unlock( &p_input->stream.stream_lock );
234
    
235
236
    if( i_language != -1 )
    {
237
        p_es = p_input->stream.pp_es[i_language];
238
    }
239
240
241
242
243
244
245
246
247
    if( p_es == p_es_old )
    {
        return;
    }
    if( p_es_old )
    {
        input_ToggleES( p_input, p_es_old, VLC_FALSE );
    }
    if( p_es )
248
    {
249
        input_ToggleES( p_input, p_es, VLC_TRUE );
250
251
252
    }
}

253
void VlcWrapper::ToggleSubtitle( int i_subtitle )
254
{
255
256
    es_descriptor_t * p_es = NULL;
    es_descriptor_t * p_es_old = NULL;
257
258

    vlc_mutex_lock( &p_input->stream.stream_lock );
259
    for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
260
    {
261
        if( p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
262
        {
263
            p_es_old = p_input->stream.pp_selected_es[i];
264
265
266
267
268
269
270
            break;
        }
    }
    vlc_mutex_unlock( &p_input->stream.stream_lock );
    
    if( i_subtitle != -1 )
    {
271
        p_es = p_input->stream.pp_es[i_subtitle];
272
    }
273
274
275
276
277
    if( p_es == p_es_old )
    {
        return;
    }
    if( p_es_old )
278
    {
279
280
281
282
283
        input_ToggleES( p_input, p_es_old, VLC_FALSE );
    }
    if( p_es )
    {
        input_ToggleES( p_input, p_es, VLC_TRUE );
284
285
286
    }
}

Eric Petit's avatar
Eric Petit committed
287
const char * VlcWrapper::GetTimeAsString()
288
{
289
290
291
292
293
294
295
296
297
298
299
300
    static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ];
        
    if( p_input == NULL )
    {
        return ("-:--:--");
    }     
   
    input_OffsetToTime( p_input, 
                        psz_currenttime, 
                        p_input->stream.p_selected_area->i_tell );        

    return(psz_currenttime);
301
302
}

Eric Petit's avatar
Eric Petit committed
303
float VlcWrapper::GetTimeAsFloat()
304
{
305
306
307
    float f_time = 0.0;

    if( p_input != NULL )
308
    {
309
310
311
312
313
314
        f_time = (float)p_input->stream.p_selected_area->i_tell / 
                 (float)p_input->stream.p_selected_area->i_size;
    }    
    else
    {
        f_time = 0.0;
315
    }
316
    return( f_time );
317
318
}

Eric Petit's avatar
Eric Petit committed
319
void VlcWrapper::SetTimeAsFloat( float f_position )
320
{
321
    if( p_input != NULL )
322
    {
323
324
325
326
        input_Seek( p_input, 
                   (long long int)(p_input->stream.p_selected_area->i_size
                       * f_position / SEEKSLIDER_RANGE ), 
                   INPUT_SEEK_SET);
327
328
329
    }
}

330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
bool VlcWrapper::IsPlaying()
{

	bool playing = false;
	if ( p_input )
	{
		switch ( p_input->stream.control.i_status )
		{
			case PLAYING_S:
			case FORWARD_S:
			case BACKWARD_S:
			case START_S:
				playing = true;
	            break;
			case PAUSE_S:
			case UNDEF_S:
			case NOT_STARTED_S:
			default:
				break;
		}
	}
	return playing;

}
354

Eric Petit's avatar
Eric Petit committed
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
/************
 * playlist *
 ************/

void VlcWrapper::OpenFiles( BList* o_files, bool replace )
{
    BString *o_file;
    int size = PlaylistSize();
	bool wasEmpty = ( size < 1 );

    /* delete current playlist */
    if( replace )
    {
        for( int i = 0; i < size; i++ )
        {
            playlist_Delete( p_playlist, 0 );
        }
    }

    /* append files */
    while( ( o_file = (BString *)o_files->LastItem() ) )
    {
        playlist_Add( p_playlist, o_file->String(),
                      PLAYLIST_APPEND, PLAYLIST_END );
        o_files->RemoveItem(o_files->CountItems() - 1);
    }
    
    /* eventually restart playing */
    if( replace || wasEmpty )
    {
        playlist_Stop( p_playlist );
        playlist_Play( p_playlist );
    }
}
 
void VlcWrapper::OpenDisc(BString o_type, BString o_device, int i_title, int i_chapter)
{
392
393
394
    if( p_intf->p_sys->b_dvdmenus )
        o_device.Prepend( "dvd:" );
    else
Eric Petit's avatar
Eric Petit committed
395
396
397
398
399
        o_device.Prepend( "dvdold:" );
    playlist_Add( p_playlist, o_device.String(),
                  PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
}

400
int VlcWrapper::PlaylistSize()
401
402
{
    vlc_mutex_lock( &p_playlist->object_lock );
403
404
405
406
407
    int i_size = p_playlist->i_size;
    vlc_mutex_unlock( &p_playlist->object_lock );
    return i_size;
}

Eric Petit's avatar
Eric Petit committed
408
char * VlcWrapper::PlaylistItemName( int i )
409
410
411
412
413
414
415
416
417
418
419
420
{
   return p_playlist->pp_items[i]->psz_name;
}

int VlcWrapper::PlaylistCurrent()
{
    return p_playlist->i_index;
}

bool VlcWrapper::PlaylistPlay()
{
    if( PlaylistSize() )
421
422
423
424
425
426
    {
        playlist_Play( p_playlist );
    }
    return( true );
}

427
void VlcWrapper::PlaylistPause()
428
{
429
    if( p_input )
430
    {
431
        input_SetStatus( p_input, INPUT_STATUS_PAUSE );
432
    }
433
434
}

435
void VlcWrapper::PlaylistStop()
436
437
438
439
{
    playlist_Stop( p_playlist );
}

440
void VlcWrapper::PlaylistNext()
441
442
443
444
{
    playlist_Next( p_playlist );
}

445
void VlcWrapper::PlaylistPrev()
446
447
448
449
{
    playlist_Prev( p_playlist );
}

Eric Petit's avatar
Eric Petit committed
450
void VlcWrapper::GetPlaylistInfo( int32& currentIndex, int32& maxIndex )
451
452
453
454
455
456
457
458
459
460
461
462
463
464
{
	currentIndex = -1;
	maxIndex = -1;
	if ( p_playlist )
	{
		maxIndex = p_playlist->i_size;
		if ( maxIndex > 0 )
			currentIndex = p_playlist->i_index + 1;
		else
			maxIndex = -1;
	}
}

void VlcWrapper::PlaylistJumpTo( int pos )
465
{
Eric Petit's avatar
Eric Petit committed
466
467
468
469
    playlist_Goto( p_playlist, pos );
}

void VlcWrapper::GetNavCapabilities( bool *canSkipPrev, bool *canSkipNext )
470
471
472
473
474
475
476
{
	if ( canSkipPrev && canSkipNext )
	{
		// init the parameters
		*canSkipPrev = false;
		*canSkipNext = false;
		// get playlist info
477
478
		int pos = PlaylistCurrent();
		int size = PlaylistSize();
479
480

		// see if we have got a stream going		
481
		if ( p_input )
482
		{
483
			vlc_mutex_lock( &p_input->stream.stream_lock );
484

485
486
			bool hasTitles = p_input->stream.i_area_nb > 1;
			int numChapters = p_input->stream.p_selected_area->i_part_nb;
487
488
489
490
			bool hasChapters = numChapters > 1;
			// first, look for chapters
			if ( hasChapters )
			{
491
492
493
				*canSkipPrev = p_input->stream.p_selected_area->i_part > 0;
				*canSkipNext = p_input->stream.p_selected_area->i_part <
									 p_input->stream.p_selected_area->i_part_nb - 1;
494
495
496
497
			}
			// if one of the skip capabilities is false,
			// make it depend on titles instead
			if ( !*canSkipPrev && hasTitles )
498
				*canSkipPrev = p_input->stream.p_selected_area->i_id > 1;
499
			if ( !*canSkipNext && hasTitles )
500
501
				*canSkipNext = p_input->stream.p_selected_area->i_id <
				                   p_input->stream.i_area_nb - 1;
502

503
			vlc_mutex_unlock( &p_input->stream.stream_lock );
504
505
506
507
508
509
510
511
512
		}
		// last but not least, make capabilities depend on playlist
		if ( !*canSkipPrev )
			*canSkipPrev = pos > 0;
		if ( !*canSkipNext )
			*canSkipNext = pos < size - 1;
	}
}

Eric Petit's avatar
Eric Petit committed
513
void VlcWrapper::NavigatePrev()
514
515
516
517
{
	bool hasSkiped = false;

	// see if we have got a stream going		
518
	if ( p_input )
519
520
	{
		// get information from stream (lock it while looking at it)
521
		vlc_mutex_lock( &p_input->stream.stream_lock );
522

523
524
525
		int currentTitle = p_input->stream.p_selected_area->i_id;
		int currentChapter = p_input->stream.p_selected_area->i_part;
		int numTitles = p_input->stream.i_area_nb;
526
		bool hasTitles = numTitles > 1;
527
		int numChapters = p_input->stream.p_selected_area->i_part_nb;
528
529
		bool hasChapters = numChapters > 1;

530
		vlc_mutex_unlock( &p_input->stream.stream_lock );
531
532
533
534
535
536
537
538
539

		// first, look for chapters
		if ( hasChapters )
		{
			// skip to the previous chapter
			currentChapter--;

			if ( currentChapter >= 0 )
			{
Eric Petit's avatar
Eric Petit committed
540
				ToggleChapter( currentChapter );
541
542
543
544
545
546
547
548
549
550
551
				hasSkiped = true;
			}
		}
		// if we couldn't skip chapters, try titles instead
		if ( !hasSkiped && hasTitles )
		{
			// skip to the previous title
			currentTitle--;
			// disallow area 0 since it is used for video_ts.vob
			if( currentTitle > 0 )
			{
Eric Petit's avatar
Eric Petit committed
552
				ToggleTitle(currentTitle);
553
554
555
556
557
558
559
				hasSkiped = true;
			}
		}

	}
	// last but not least, skip to previous file
	if ( !hasSkiped )
560
		PlaylistPrev();
561
562
}

Eric Petit's avatar
Eric Petit committed
563
void VlcWrapper::NavigateNext()
564
565
566
567
{
	bool hasSkiped = false;

	// see if we have got a stream going		
568
	if ( p_input )
569
570
	{
		// get information from stream (lock it while looking at it)
571
		vlc_mutex_lock( &p_input->stream.stream_lock );
572

573
574
575
		int currentTitle = p_input->stream.p_selected_area->i_id;
		int currentChapter = p_input->stream.p_selected_area->i_part;
		int numTitles = p_input->stream.i_area_nb;
576
		bool hasTitles = numTitles > 1;
577
		int numChapters = p_input->stream.p_selected_area->i_part_nb;
578
579
		bool hasChapters = numChapters > 1;

580
		vlc_mutex_unlock( &p_input->stream.stream_lock );
581
582
583
584
585
586
587
588

		// first, look for chapters
		if ( hasChapters )
		{
			// skip to the next chapter
			currentChapter++;
			if ( currentChapter < numChapters )
			{
Eric Petit's avatar
Eric Petit committed
589
				ToggleChapter( currentChapter );
590
591
592
593
594
595
596
597
598
599
600
				hasSkiped = true;
			}
		}
		// if we couldn't skip chapters, try titles instead
		if ( !hasSkiped && hasTitles )
		{
			// skip to the next title
			currentTitle++;
			// disallow area 0 since it is used for video_ts.vob
			if ( currentTitle < numTitles - 1 )
			{
Eric Petit's avatar
Eric Petit committed
601
				ToggleTitle(currentTitle);
602
603
604
605
606
607
608
				hasSkiped = true;
			}
		}

	}
	// last but not least, skip to next file
	if ( !hasSkiped )
609
		PlaylistNext();
610
611
612
}


Eric Petit's avatar
Eric Petit committed
613
614
615
616
617
618
619
620
/*********
 * audio *
 *********/

bool VlcWrapper::HasAudio()
{
    return( p_aout != NULL );
}
621

622
623
624
625
626
627
628
629
630
631
632
unsigned short VlcWrapper::GetVolume()
{
    if( p_aout != NULL )
    {
        unsigned short i_volume;
        aout_VolumeGet( p_aout, (audio_volume_t*)&i_volume );
        return i_volume;
    }
    return 0;
}

633
void VlcWrapper::SetVolume(int value)
634
{
635
    if( p_aout != NULL )
636
    {
637
638
639
640
		if ( p_intf->p_sys->b_mute )
		{
			p_intf->p_sys->b_mute = 0;
		}
641
        aout_VolumeSet( p_aout, value );
642
    }
643
}
644

645
void VlcWrapper::VolumeMute()
646
{
647
    if( p_aout != NULL )
648
   	{
649
650
651
652
   	    aout_VolumeGet( p_aout, &p_intf->p_sys->i_saved_volume );
	    aout_VolumeMute( p_aout, NULL );
	    p_intf->p_sys->b_mute = 1;
   	}
653
654
}

655
void VlcWrapper::VolumeRestore()
656
{
657
    if( p_aout != NULL )
658
659
660
   	{
        aout_VolumeSet( p_aout, p_intf->p_sys->i_saved_volume );
        p_intf->p_sys->b_mute = 0;
661
662
	}
}
663

664
bool VlcWrapper::IsMuted()
665
{
666
    return p_intf->p_sys->b_mute;
667
668
}

669
670
671
/*******
 * DVD *
 *******/
Eric Petit's avatar
Eric Petit committed
672

673
bool VlcWrapper::HasTitles()
674
{
675
    if( !p_input )
676
    {
677
678
679
        return false;
    }
    return ( p_input->stream.i_area_nb > 1 );
680
681
}

Eric Petit's avatar
Eric Petit committed
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
BList * VlcWrapper::GetTitles()
{
    if( p_input )
    {
        vlc_mutex_lock( &p_input->stream.stream_lock );
      
        BList *list = new BList( p_input->stream.i_area_nb );
        BMenuItem *menuItem;
        BMessage *message;
        
        for( unsigned int i = 1; i < p_input->stream.i_area_nb; i++ )
        {
            message = new BMessage( TOGGLE_TITLE );
            message->AddInt32( "index", i );
            BString helper( "" );
            helper << i;
            menuItem = new BMenuItem( helper.String(), message );
            menuItem->SetMarked( p_input->stream.p_selected_area->i_id == i );
            list->AddItem( menuItem );
        }
        
        vlc_mutex_unlock( &p_input->stream.stream_lock );

        return list;
    }
    return NULL;
}

710
void VlcWrapper::PrevTitle()
711
{
712
713
714
    int i_id;
    i_id = p_input->stream.p_selected_area->i_id - 1;
    if( i_id > 0 )
715
    {
Eric Petit's avatar
Eric Petit committed
716
        ToggleTitle(i_id);
717
718
719
    }
}

720
void VlcWrapper::NextTitle()
721
{
722
    unsigned int i_id;
723
724
    i_id = p_input->stream.p_selected_area->i_id + 1;
    if( i_id < p_input->stream.i_area_nb )
725
    {
Eric Petit's avatar
Eric Petit committed
726
727
728
729
730
731
732
733
734
735
736
737
738
739
        ToggleTitle(i_id);
    }
}

void VlcWrapper::ToggleTitle(int i_title)
{
    if( p_input != NULL )
    {
        input_ChangeArea( p_input,
                          p_input->stream.pp_areas[i_title] );

        vlc_mutex_lock( &p_input->stream.stream_lock );

        vlc_mutex_unlock( &p_input->stream.stream_lock );
740
741
742
    }
}

Eric Petit's avatar
Eric Petit committed
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
void VlcWrapper::TitleInfo( int32 &currentIndex, int32 &maxIndex )
{
	currentIndex = -1;
	maxIndex = -1;
	if ( p_input )
	{
		vlc_mutex_lock( &p_input->stream.stream_lock );

		maxIndex = p_input->stream.i_area_nb - 1;
		if ( maxIndex > 0)
			currentIndex = p_input->stream.p_selected_area->i_id;
		else
			maxIndex = -1;

		vlc_mutex_unlock( &p_input->stream.stream_lock );
	}
}

761
762
763
bool VlcWrapper::HasChapters()
{
    if( !p_input )
764
    {
765
        return false;
766
    }
767
768
    return ( p_input->stream.p_selected_area->i_part_nb > 1 );
}
769

Eric Petit's avatar
Eric Petit committed
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
BList * VlcWrapper::GetChapters()
{
    if( p_input )
    {
        vlc_mutex_lock( &p_input->stream.stream_lock );
      
        BList *list = new BList( p_input->stream.p_selected_area->i_part_nb );
        BMenuItem *menuItem;
        BMessage *message;
        
        for( unsigned int i = 1;
             i < p_input->stream.p_selected_area->i_part_nb + 1; i++ )
        {
            message = new BMessage( TOGGLE_CHAPTER );
            message->AddInt32( "index", i );
            BString helper( "" );
            helper << i;
            menuItem = new BMenuItem( helper.String(), message );
            menuItem->SetMarked( p_input->stream.p_selected_area->i_part == i );
            list->AddItem( menuItem );
        }
        
        vlc_mutex_unlock( &p_input->stream.stream_lock );

        return list;
    }
    return NULL;
}

799
800
801
802
803
804
void VlcWrapper::PrevChapter()
{
    int i_id;
    i_id = p_input->stream.p_selected_area->i_part - 1;
    if( i_id >= 0 )
    {
Eric Petit's avatar
Eric Petit committed
805
        ToggleChapter(i_id);
806
    }
807
808
}

809
void VlcWrapper::NextChapter()
Eric Petit's avatar
Eric Petit committed
810
{
811
812
813
814
    int i_id;
    i_id = p_input->stream.p_selected_area->i_part + 1;
    if( i_id >= 0 )
    {
Eric Petit's avatar
Eric Petit committed
815
        ToggleChapter(i_id);
816
    }
Eric Petit's avatar
Eric Petit committed
817
818
}

Eric Petit's avatar
Eric Petit committed
819
void VlcWrapper::ToggleChapter(int i_chapter)
Eric Petit's avatar
Eric Petit committed
820
{
Eric Petit's avatar
Eric Petit committed
821
822
823
824
825
    if( p_input != NULL )
    {
        p_input->stream.p_selected_area->i_part = i_chapter;
        input_ChangeArea( p_input,
                          p_input->stream.p_selected_area );
Eric Petit's avatar
Eric Petit committed
826

Eric Petit's avatar
Eric Petit committed
827
828
829
        vlc_mutex_lock( &p_input->stream.stream_lock );
        vlc_mutex_unlock( &p_input->stream.stream_lock );
    }
Eric Petit's avatar
Eric Petit committed
830
831
}

832
void VlcWrapper::ChapterInfo( int32 &currentIndex, int32 &maxIndex )
Eric Petit's avatar
Eric Petit committed
833
834
835
{
	currentIndex = -1;
	maxIndex = -1;
836
	if ( p_input )
Eric Petit's avatar
Eric Petit committed
837
	{
838
		vlc_mutex_lock( &p_input->stream.stream_lock );
Eric Petit's avatar
Eric Petit committed
839

840
		maxIndex = p_input->stream.p_selected_area->i_part_nb - 1;
Eric Petit's avatar
Eric Petit committed
841
		if ( maxIndex > 0)
842
			currentIndex = p_input->stream.p_selected_area->i_part;
Eric Petit's avatar
Eric Petit committed
843
844
845
		else
			maxIndex = -1;

846
		vlc_mutex_unlock( &p_input->stream.stream_lock );
Eric Petit's avatar
Eric Petit committed
847
848
849
	}
}

Eric Petit's avatar
Eric Petit committed
850
851
852
853
854
/****************
 * Miscellanous *
 ****************/
 
void VlcWrapper::LoadSubFile( char * psz_file )
855
{
Eric Petit's avatar
Eric Petit committed
856
    config_PutPsz( p_intf, "sub-file", strdup( psz_file ) );
857
}