VlcWrapper.cpp 23.3 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.28 2003/04/23 15:18:24 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
34
35
#include <vlc/vout.h>
extern "C"
{
Stephan Assmus's avatar
   
Stephan Assmus committed
36
  #include <input_ext-plugins.h>	// needed here when compiling without plugins
37
38
  #include <audio_output.h>
  #include <aout_internal.h>
39
}
40

41
#include "VlcWrapper.h"
42
#include "MsgVals.h"
43

44
45
const char * _AddEllipsis( char * string )
{
46
47
48
49
    char * temp;
    temp = (char*) calloc( strlen( string ) + 4, 1 );
    sprintf( temp, "%s%s", string, B_UTF8_ELLIPSIS );
    return temp;
50
51
}

52
/* constructor */
53
VlcWrapper::VlcWrapper( intf_thread_t *p_interface )
54
{
55
    p_intf = p_interface;
56
57
58
    p_input = NULL;
    p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                FIND_ANYWHERE );
59
60
}

61
/* destructor */
62
VlcWrapper::~VlcWrapper()
63
{
64
65
66
67
68
69
70
71
    if( p_input )
    {
        vlc_object_release( p_input );
    }
    if( p_playlist )
    {
        vlc_object_release( p_playlist );
    }
72
}
73

Eric Petit's avatar
Eric Petit committed
74
75
76
/* UpdateInput: updates p_input, returns true if the interface needs to
   be updated */
bool VlcWrapper::UpdateInput()
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{
    if( p_input == NULL )
    {
        p_input = (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
                                                     FIND_ANYWHERE );
    }
        
    if( p_input != NULL )
    {
        if( p_input->b_dead )
        {
            vlc_object_release( p_input );
            p_input = NULL;
        }
        return true;
    }
    return false;
}

96
97
98
99
100

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

101
102
bool VlcWrapper::HasInput()
{
103
    return ( p_input != NULL );
104
105
}

106
int VlcWrapper::InputStatus()
107
{
108
109
110
111
    if( !p_input )
    {
        return UNDEF_S;
    }
112
113
114
    return p_input->stream.control.i_status;
}

115
int VlcWrapper::InputRate()
116
{
117
118
119
120
    if( !p_input )
    {
        return DEFAULT_RATE;
    }
121
122
123
    return p_input->stream.control.i_rate;
}

124
void VlcWrapper::InputSlower()
125
{
126
127
128
129
    if( p_input != NULL )
    {
        input_SetStatus( p_input, INPUT_STATUS_SLOWER );
    }
130
131
}

132
void VlcWrapper::InputFaster()
133
{
134
135
136
137
    if( p_input != NULL )
    {
        input_SetStatus( p_input, INPUT_STATUS_FASTER );
    }
138
139
}

Eric Petit's avatar
Eric Petit committed
140
BList * VlcWrapper::GetChannels( int i_cat )
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
{
    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 );
185
        menuItem = new BMenuItem( _("None"), message );
186
187
188
189
190
191
192
193
194
195
196
197
198
        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
199
                    trackName = _("<unknown>");
200
201
202
203
204
205
206
207
208
209
210
211
                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;
212
213
}

214
void VlcWrapper::ToggleLanguage( int i_language )
215
{
216
217
    es_descriptor_t * p_es = NULL;
    es_descriptor_t * p_es_old = NULL;
218
219

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

248
void VlcWrapper::ToggleSubtitle( int i_subtitle )
249
{
250
251
    es_descriptor_t * p_es = NULL;
    es_descriptor_t * p_es_old = NULL;
252
253

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

Eric Petit's avatar
Eric Petit committed
282
const char * VlcWrapper::GetTimeAsString()
283
{
284
285
286
287
288
289
290
291
292
293
294
295
    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);
296
297
}

Eric Petit's avatar
Eric Petit committed
298
float VlcWrapper::GetTimeAsFloat()
299
{
300
301
302
    float f_time = 0.0;

    if( p_input != NULL )
303
    {
304
305
306
307
308
309
        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;
310
    }
311
    return( f_time );
312
313
}

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

325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
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;

}
349

Eric Petit's avatar
Eric Petit committed
350
351
352
353
/************
 * playlist *
 ************/

354
void VlcWrapper::OpenFiles( BList* o_files, bool replace, int32 index )
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
392
393
394
	if ( o_files && o_files->CountItems() > 0)
	{
	    int size = PlaylistSize();
		bool wasEmpty = ( size < 1 );
		if ( index == -1 )
			index = PLAYLIST_END;
		int mode = index == PLAYLIST_END ? PLAYLIST_APPEND : PLAYLIST_INSERT;
	
	    /* delete current playlist */
	    if( replace )
	    {
	        for( int i = 0; i < size; i++ )
	        {
	            playlist_Delete( p_playlist, 0 );
	        }
	    }
	
	    /* insert files */
	    int32 count = o_files->CountItems();
	    for ( int32 i = count - 1; i >= 0; i-- )
	    {
	    	if ( BString* o_file = (BString *)o_files->RemoveItem( i ) )
	    	{
		        playlist_Add( p_playlist, o_file->String(),
		                      mode, index );
		        if ( mode == PLAYLIST_INSERT )
		        	index++;
		        delete o_file;
	    	}
	    }
	    // TODO: implement a user setting
	    // if to start automatically
	    /* eventually restart playing */
	    if( replace || wasEmpty )
	    {
	        playlist_Stop( p_playlist );
	        playlist_Play( p_playlist );
	    }
	}
Eric Petit's avatar
Eric Petit committed
395
396
397
398
}
 
void VlcWrapper::OpenDisc(BString o_type, BString o_device, int i_title, int i_chapter)
{
399
400
401
    if( p_intf->p_sys->b_dvdmenus )
        o_device.Prepend( "dvd:" );
    else
Eric Petit's avatar
Eric Petit committed
402
403
404
405
406
        o_device.Prepend( "dvdold:" );
    playlist_Add( p_playlist, o_device.String(),
                  PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
}

407
int VlcWrapper::PlaylistSize()
408
409
{
    vlc_mutex_lock( &p_playlist->object_lock );
410
411
412
413
414
    int i_size = p_playlist->i_size;
    vlc_mutex_unlock( &p_playlist->object_lock );
    return i_size;
}

Eric Petit's avatar
Eric Petit committed
415
char * VlcWrapper::PlaylistItemName( int i )
416
417
418
419
420
421
422
423
424
425
426
427
{
   return p_playlist->pp_items[i]->psz_name;
}

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

bool VlcWrapper::PlaylistPlay()
{
    if( PlaylistSize() )
428
429
430
431
432
433
    {
        playlist_Play( p_playlist );
    }
    return( true );
}

434
void VlcWrapper::PlaylistPause()
435
{
436
    if( p_input )
437
    {
438
        input_SetStatus( p_input, INPUT_STATUS_PAUSE );
439
    }
440
441
}

442
void VlcWrapper::PlaylistStop()
443
444
445
446
{
    playlist_Stop( p_playlist );
}

447
void VlcWrapper::PlaylistNext()
448
449
450
451
{
    playlist_Next( p_playlist );
}

452
void VlcWrapper::PlaylistPrev()
453
454
455
456
{
    playlist_Prev( p_playlist );
}

Eric Petit's avatar
Eric Petit committed
457
void VlcWrapper::GetPlaylistInfo( int32& currentIndex, int32& maxIndex )
458
459
460
461
462
{
	currentIndex = -1;
	maxIndex = -1;
	if ( p_playlist )
	{
463
464
	    vlc_mutex_lock( &p_playlist->object_lock );

465
466
		maxIndex = p_playlist->i_size;
		if ( maxIndex > 0 )
467
			currentIndex = p_playlist->i_index/* + 1 -> why?!?*/;
468
469
		else
			maxIndex = -1;
470
471

	    vlc_mutex_unlock( &p_playlist->object_lock );
472
473
474
475
	}
}

void VlcWrapper::PlaylistJumpTo( int pos )
476
{
Eric Petit's avatar
Eric Petit committed
477
478
479
480
    playlist_Goto( p_playlist, pos );
}

void VlcWrapper::GetNavCapabilities( bool *canSkipPrev, bool *canSkipNext )
481
482
483
484
485
486
487
{
	if ( canSkipPrev && canSkipNext )
	{
		// init the parameters
		*canSkipPrev = false;
		*canSkipNext = false;
		// get playlist info
488
489
		int pos = PlaylistCurrent();
		int size = PlaylistSize();
490
491

		// see if we have got a stream going		
492
		if ( p_input )
493
		{
494
			vlc_mutex_lock( &p_input->stream.stream_lock );
495

496
497
			bool hasTitles = p_input->stream.i_area_nb > 1;
			int numChapters = p_input->stream.p_selected_area->i_part_nb;
498
499
500
501
			bool hasChapters = numChapters > 1;
			// first, look for chapters
			if ( hasChapters )
			{
502
503
504
				*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;
505
506
507
508
			}
			// if one of the skip capabilities is false,
			// make it depend on titles instead
			if ( !*canSkipPrev && hasTitles )
509
				*canSkipPrev = p_input->stream.p_selected_area->i_id > 1;
510
			if ( !*canSkipNext && hasTitles )
511
512
				*canSkipNext = p_input->stream.p_selected_area->i_id <
				                   p_input->stream.i_area_nb - 1;
513

514
			vlc_mutex_unlock( &p_input->stream.stream_lock );
515
516
517
518
519
520
521
522
523
		}
		// 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
524
void VlcWrapper::NavigatePrev()
525
526
527
528
{
	bool hasSkiped = false;

	// see if we have got a stream going		
529
	if ( p_input )
530
531
	{
		// get information from stream (lock it while looking at it)
532
		vlc_mutex_lock( &p_input->stream.stream_lock );
533

534
535
536
		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;
537
		bool hasTitles = numTitles > 1;
538
		int numChapters = p_input->stream.p_selected_area->i_part_nb;
539
540
		bool hasChapters = numChapters > 1;

541
		vlc_mutex_unlock( &p_input->stream.stream_lock );
542
543
544
545
546
547
548
549
550

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

			if ( currentChapter >= 0 )
			{
Eric Petit's avatar
Eric Petit committed
551
				ToggleChapter( currentChapter );
552
553
554
555
556
557
558
559
560
561
562
				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
563
				ToggleTitle(currentTitle);
564
565
566
567
568
569
570
				hasSkiped = true;
			}
		}

	}
	// last but not least, skip to previous file
	if ( !hasSkiped )
571
		PlaylistPrev();
572
573
}

Eric Petit's avatar
Eric Petit committed
574
void VlcWrapper::NavigateNext()
575
576
577
578
{
	bool hasSkiped = false;

	// see if we have got a stream going		
579
	if ( p_input )
580
581
	{
		// get information from stream (lock it while looking at it)
582
		vlc_mutex_lock( &p_input->stream.stream_lock );
583

584
585
586
		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;
587
		bool hasTitles = numTitles > 1;
588
		int numChapters = p_input->stream.p_selected_area->i_part_nb;
589
590
		bool hasChapters = numChapters > 1;

591
		vlc_mutex_unlock( &p_input->stream.stream_lock );
592
593
594
595
596
597
598
599

		// first, look for chapters
		if ( hasChapters )
		{
			// skip to the next chapter
			currentChapter++;
			if ( currentChapter < numChapters )
			{
Eric Petit's avatar
Eric Petit committed
600
				ToggleChapter( currentChapter );
601
602
603
604
605
606
607
608
609
610
611
				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
612
				ToggleTitle(currentTitle);
613
614
615
616
617
618
619
				hasSkiped = true;
			}
		}

	}
	// last but not least, skip to next file
	if ( !hasSkiped )
620
		PlaylistNext();
621
622
}

623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
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
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
/*************************
 * Playlist manipulation *
 *************************/

// PlaylistLock
bool
VlcWrapper::PlaylistLock() const
{
// TODO: search and destroy -> deadlock!
return true;
	if ( p_playlist )
	{
 		vlc_mutex_lock( &p_playlist->object_lock );
 		return true;
 	}
 	return false;
}

// PlaylistUnlock
void
VlcWrapper::PlaylistUnlock() const
{
// TODO: search and destroy -> deadlock!
return;
	vlc_mutex_unlock( &p_playlist->object_lock );
}

// PlaylistItemAt
void*
VlcWrapper::PlaylistItemAt( int index ) const
{
	playlist_item_t* item = NULL;
	if ( index >= 0 && index < p_playlist->i_size )
		item = p_playlist->pp_items[index];
	return (void*)item;
}

// PlaylistRemoveItem
void*
VlcWrapper::PlaylistRemoveItem( int index ) const
{
	playlist_item_t* copy = NULL;
	// check if item exists at the provided index
	if ( index >= 0 && index < p_playlist->i_size )
	{
		playlist_item_t* item = p_playlist->pp_items[index];
		if ( item )
		{
			// make a copy of the removed item
			copy = (playlist_item_t*)PlaylistCloneItem( (void*)item );
			// remove item from playlist (unfortunately, this frees it)
			playlist_Delete( p_playlist, index );
		}
	}
	return (void*)copy;
}

// PlaylistRemoveItem
void*
VlcWrapper::PlaylistRemoveItem( void* item ) const
{
	playlist_item_t* copy = NULL;
	for ( int32 i = 0; i < p_playlist->i_size; i++ )
	{
		if ( p_playlist->pp_items[i] == item )
		{
			copy = (playlist_item_t*)PlaylistRemoveItem( i );
			break;
		}
	}
	return (void*)copy;
}

// PlaylistAddItem
bool
VlcWrapper::PlaylistAddItem( void* item, int index ) const
{
	if ( item )
	{
		playlist_AddItem( p_playlist, (playlist_item_t*)item,
						  PLAYLIST_INSERT, index );
	}
	// TODO: once playlist is returning useful info, return that instead
	return true;
}

// PlaylistCloneItem
void*
VlcWrapper::PlaylistCloneItem( void* castToItem ) const
{
	playlist_item_t* copy = NULL;
	playlist_item_t* item = (playlist_item_t*)castToItem;
	if ( item )
	{
		copy = (playlist_item_t*)malloc( sizeof( playlist_item_t ) );
		if ( copy )
		{
			// make a copy of the item at index
			copy->psz_name = strdup( item->psz_name );
			copy->psz_uri  = strdup( item->psz_uri );
			copy->i_type = item->i_type;
			copy->i_status = item->i_status;
			copy->b_autodeletion = item->b_autodeletion;
		}
	}
	return (void*)copy;
}

// Careful! You need to know what you're doing here!
// The reason for having it, is to be able to deal with
// the rather lame list implementation of the playlist.
// It is meant to help manipulate the playlist with the above
// methods while keeping it valid.
//
// PlaylistSetPlaying
void
VlcWrapper::PlaylistSetPlaying( int index ) const
{
	if ( index < 0 )
		index = 0;
	if ( index >= p_playlist->i_size )
		index = p_playlist->i_size - 1;
	p_playlist->i_index = index;
}

748

Eric Petit's avatar
Eric Petit committed
749
750
751
752
/*********
 * audio *
 *********/

753
754
unsigned short VlcWrapper::GetVolume()
{
Eric Petit's avatar
Eric Petit committed
755
756
757
    unsigned short i_volume;
    aout_VolumeGet( p_intf, (audio_volume_t*)&i_volume );
    return i_volume;
758
759
}

Eric Petit's avatar
Eric Petit committed
760
void VlcWrapper::SetVolume( int value )
761
{
Eric Petit's avatar
Eric Petit committed
762
    if ( p_intf->p_sys->b_mute )
763
    {
Eric Petit's avatar
Eric Petit committed
764
        p_intf->p_sys->b_mute = 0;
765
    }
Eric Petit's avatar
Eric Petit committed
766
    aout_VolumeSet( p_intf, value );
767
}
768

769
void VlcWrapper::VolumeMute()
770
{
Eric Petit's avatar
Eric Petit committed
771
772
773
   	aout_VolumeGet( p_intf, &p_intf->p_sys->i_saved_volume );
    aout_VolumeMute( p_intf, NULL );
    p_intf->p_sys->b_mute = 1;
774
775
}

776
void VlcWrapper::VolumeRestore()
777
{
Eric Petit's avatar
Eric Petit committed
778
779
    aout_VolumeSet( p_intf, p_intf->p_sys->i_saved_volume );
    p_intf->p_sys->b_mute = 0;
780
}
781

782
bool VlcWrapper::IsMuted()
783
{
784
    return p_intf->p_sys->b_mute;
785
786
}

787
788
789
/*******
 * DVD *
 *******/
Eric Petit's avatar
Eric Petit committed
790

791
bool VlcWrapper::HasTitles()
792
{
793
    if( !p_input )
794
    {
795
796
797
        return false;
    }
    return ( p_input->stream.i_area_nb > 1 );
798
799
}

Eric Petit's avatar
Eric Petit committed
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
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;
}

828
void VlcWrapper::PrevTitle()
829
{
830
831
832
    int i_id;
    i_id = p_input->stream.p_selected_area->i_id - 1;
    if( i_id > 0 )
833
    {
Eric Petit's avatar
Eric Petit committed
834
        ToggleTitle(i_id);
835
836
837
    }
}

838
void VlcWrapper::NextTitle()
839
{
840
    unsigned int i_id;
841
842
    i_id = p_input->stream.p_selected_area->i_id + 1;
    if( i_id < p_input->stream.i_area_nb )
843
    {
Eric Petit's avatar
Eric Petit committed
844
845
846
847
848
849
850
851
852
853
854
855
856
857
        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 );
858
859
860
    }
}

Eric Petit's avatar
Eric Petit committed
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
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 );
	}
}

879
880
881
bool VlcWrapper::HasChapters()
{
    if( !p_input )
882
    {
883
        return false;
884
    }
885
886
    return ( p_input->stream.p_selected_area->i_part_nb > 1 );
}
887

Eric Petit's avatar
Eric Petit committed
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
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;
}

917
918
919
920
921
922
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
923
        ToggleChapter(i_id);
924
    }
925
926
}

927
void VlcWrapper::NextChapter()
Eric Petit's avatar
Eric Petit committed
928
{
929
930
931
932
    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
933
        ToggleChapter(i_id);
934
    }
Eric Petit's avatar
Eric Petit committed
935
936
}

Eric Petit's avatar
Eric Petit committed
937
void VlcWrapper::ToggleChapter(int i_chapter)
Eric Petit's avatar
Eric Petit committed
938
{
Eric Petit's avatar
Eric Petit committed
939
940
941
942
943
    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
944

Eric Petit's avatar
Eric Petit committed
945
946
947
        vlc_mutex_lock( &p_input->stream.stream_lock );
        vlc_mutex_unlock( &p_input->stream.stream_lock );
    }
Eric Petit's avatar
Eric Petit committed
948
949
}

950
void VlcWrapper::ChapterInfo( int32 &currentIndex, int32 &maxIndex )
Eric Petit's avatar
Eric Petit committed
951
952
953
{
	currentIndex = -1;
	maxIndex = -1;
954
	if ( p_input )
Eric Petit's avatar
Eric Petit committed
955
	{
956
		vlc_mutex_lock( &p_input->stream.stream_lock );
Eric Petit's avatar
Eric Petit committed
957

958
		maxIndex = p_input->stream.p_selected_area->i_part_nb - 1;
Eric Petit's avatar
Eric Petit committed
959
		if ( maxIndex > 0)
960
			currentIndex = p_input->stream.p_selected_area->i_part;
Eric Petit's avatar
Eric Petit committed
961
962
963
		else
			maxIndex = -1;

964
		vlc_mutex_unlock( &p_input->stream.stream_lock );
Eric Petit's avatar
Eric Petit committed
965
966
967
	}
}

Eric Petit's avatar
Eric Petit committed
968
969
970
971
/****************
 * Miscellanous *
 ****************/
 
972
void VlcWrapper::LoadSubFile( const char * psz_file )
973
{
Eric Petit's avatar
Eric Petit committed
974
    config_PutPsz( p_intf, "sub-file", strdup( psz_file ) );
975
}
976
977
978
979
980
981
982
983
984

void VlcWrapper::FilterChange()
{
    if( !p_input )
        return;
    
    vout_thread_t * p_vout;
    vlc_mutex_lock( &p_input->stream.stream_lock );

Stephan Assmus's avatar
   
Stephan Assmus committed
985
    // Warn the vout we are about to change the filter chain
986
987
988
989
990
991
992
993
    p_vout = (vout_thread_t*)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
                                              FIND_ANYWHERE );
    if( p_vout )
    {
        p_vout->b_filter_change = VLC_TRUE;
        vlc_object_release( p_vout );
    }

Stephan Assmus's avatar
   
Stephan Assmus committed
994
    // restart all video stream
995
996
997
998
999
1000
    for( unsigned int i = 0; i < p_input->stream.i_es_number; i++ )
    {
        if( ( p_input->stream.pp_es[i]->i_cat == VIDEO_ES ) &&
            ( p_input->stream.pp_es[i]->p_decoder_fifo != NULL ) )
        {
            input_UnselectES( p_input, p_input->stream.pp_es[i] );