VlcWrapper.cpp 16.9 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.13 2002/12/09 07:57:04 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
27
28
29
30
 *
 * 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.
 *****************************************************************************/
#include <SupportKit.h>

#include <vlc/vlc.h>
#include <vlc/intf.h>
31
32
#include <audio_output.h>
#include <aout_internal.h>
33

34
#include "VlcWrapper.h"
35

36
/* constructor */
37
VlcWrapper::VlcWrapper( intf_thread_t *p_interface )
38
{
39
    p_intf = p_interface;
40
41
42
43
    p_input = NULL;
    p_aout = NULL;
    p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                FIND_ANYWHERE );
44
45
}

46
/* destructor */
47
VlcWrapper::~VlcWrapper()
48
{
49
50
51
52
53
54
55
56
57
58
59
60
    if( p_input )
    {
        vlc_object_release( p_input );
    }
    if( p_playlist )
    {
        vlc_object_release( p_playlist );
    }
    if( p_aout )
    {
        vlc_object_release( p_aout );
    }
61
}
62
63
64

/* UpdateInputAndAOut: updates p_input and p_aout, returns true if the
   interface needs to be updated */
65
bool VlcWrapper::UpdateInputAndAOut()
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
{
    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;
}

96
97
98
99
100
101
102
103

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

/* status (UNDEF_S, PLAYING_S, PAUSE_S, FORWARD_S, BACKWARD_S,
   REWIND_S, NOT_STARTED_S, START_S) */
int VlcWrapper::InputStatus()
104
{
105
106
107
108
    if( !p_input )
    {
        return UNDEF_S;
    }
109
110
111
    return p_input->stream.control.i_status;
}

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

121
122
/* tell: location in the current stream (in arbitrary units) */
int VlcWrapper::InputTell()
123
{
124
125
126
127
    if( !p_input )
    {
        return -1;
    }
128
129
130
    return p_input->stream.p_selected_area->i_tell;
}

131
132
/* size: total size of the current stream (in arbitrary units) */
int VlcWrapper::InputSize()
133
{
134
135
136
137
    if( !p_input )
    {
        return -1;
    }
138
139
140
    return p_input->stream.p_selected_area->i_size;
}

141
void VlcWrapper::InputSlower()
142
{
143
144
145
146
    if( p_input != NULL )
    {
        input_SetStatus( p_input, INPUT_STATUS_SLOWER );
    }
147
    //VolumeMute();
148
149
}

150
void VlcWrapper::InputFaster()
151
{
152
153
154
155
    if( p_input != NULL )
    {
        input_SetStatus( p_input, INPUT_STATUS_FASTER );
    }
156
    //VolumeMute();
157
158
}

159
void VlcWrapper::openFiles( BList* o_files, bool replace )
160
{
161
162
163
164
165
166
167
168
169
    BString *o_file;

    while( ( o_file = (BString *)o_files->LastItem() ) )
    {
        o_files->RemoveItem(o_files->CountItems() - 1);
        playlist_Add( p_playlist, o_file->String(),
                  PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
        delete o_file;
    }
170
171
}

172
void VlcWrapper::openDisc(BString o_type, BString o_device, int i_title, int i_chapter)
173
{
174
175
176
177
178
    BString o_source("");
    o_source << o_type << ":" << o_device ;

    playlist_Add( p_playlist, o_source.String(),
                  PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
179
180
}

181
182
183


void VlcWrapper::toggleLanguage(int i_language)
184
{
185
186
187
188
189

    int32 i_old = -1;
    int i_cat = AUDIO_ES;

    vlc_mutex_lock( &p_input->stream.stream_lock );
190
    for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
191
    {
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
        if( p_input->stream.pp_selected_es[i]->i_cat == i_cat )
        {
            i_old = i;
            break;
        }
    }
    vlc_mutex_unlock( &p_input->stream.stream_lock );

    msg_Info( p_intf, "Old: %d,  New: %d", i_old, i_language);
    if( i_language != -1 )
    {
        input_ToggleES( p_input, 
                        p_input->stream.pp_selected_es[i_language],
                        VLC_TRUE );
    }

    if( (i_old != -1) && (i_old != i_language) )
    {
        input_ToggleES( p_input, 
                        p_input->stream.pp_selected_es[i_old],
                        VLC_FALSE );
213
214
215
    }
}

216
void VlcWrapper::toggleSubtitle(int i_subtitle)
217
{
218
219
220
221
    int32 i_old = -1;
    int i_cat = SPU_ES;

    vlc_mutex_lock( &p_input->stream.stream_lock );
222
    for( unsigned int i = 0; i < p_input->stream.i_selected_es_number ; i++ )
223
    {
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
        if( p_input->stream.pp_selected_es[i]->i_cat == i_cat )
        {
            i_old = i;
            break;
        }
    }
    vlc_mutex_unlock( &p_input->stream.stream_lock );
    
    msg_Info( p_intf, "Old: %d,  New: %d", i_old, i_subtitle);
    if( i_subtitle != -1 )
    {
        input_ToggleES( p_input, 
                        p_input->stream.pp_selected_es[i_subtitle],
                        VLC_TRUE );
    }

    if( (i_old != -1) && (i_old != i_subtitle) )
    {
        input_ToggleES( p_input, 
                        p_input->stream.pp_selected_es[i_old],
                        VLC_FALSE );
245
246
247
    }
}

248
const char*  VlcWrapper::getTimeAsString()
249
{
250
251
252
253
254
255
256
257
258
259
260
261
    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);
262
263
}

264
float  VlcWrapper::getTimeAsFloat()
265
{
266
267
268
    float f_time = 0.0;

    if( p_input != NULL )
269
    {
270
271
272
273
274
275
        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;
276
    }
277
    return( f_time );
278
279
}

280
void VlcWrapper::setTimeAsFloat(float f_position)
281
{
282
    if( p_input != NULL )
283
    {
284
285
286
287
        input_Seek( p_input, 
                   (long long int)(p_input->stream.p_selected_area->i_size
                       * f_position / SEEKSLIDER_RANGE ), 
                   INPUT_SEEK_SET);
288
289
290
    }
}

291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
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;

}
315
316
317
318
319

/******************************
 * playlist infos and control *
 ******************************/
int VlcWrapper::PlaylistSize()
320
321
{
    vlc_mutex_lock( &p_playlist->object_lock );
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
    int i_size = p_playlist->i_size;
    vlc_mutex_unlock( &p_playlist->object_lock );
    return i_size;
}

char *VlcWrapper::PlaylistItemName( int i )
{
   return p_playlist->pp_items[i]->psz_name;
}

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

int  VlcWrapper::PlaylistStatus()
{
    return p_playlist->i_status;
}

bool VlcWrapper::PlaylistPlay()
{
    if( PlaylistSize() )
345
346
    {
        playlist_Play( p_playlist );
347
        //VolumeRestore();
348
349
350
351
    }
    return( true );
}

352
void VlcWrapper::PlaylistPause()
353
{
354
    if( p_input )
355
    {
356
        input_SetStatus( p_input, INPUT_STATUS_PAUSE );
357
    }
358
359
}

360
void VlcWrapper::PlaylistStop()
361
362
363
364
{
    playlist_Stop( p_playlist );
}

365
void VlcWrapper::PlaylistNext()
366
367
368
369
{
    playlist_Next( p_playlist );
}

370
void VlcWrapper::PlaylistPrev()
371
372
373
374
{
    playlist_Prev( p_playlist );
}

375
void VlcWrapper::PlaylistSkip( int i )
376
377
378
379
{
    playlist_Skip( p_playlist, i );
}

380
void VlcWrapper::PlaylistGoto( int i )
381
382
383
384
{
    playlist_Goto( p_playlist, i );
}

385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
void VlcWrapper::PlaylistLoop()
{
    if ( p_intf->p_sys->b_loop )
    {
        playlist_Delete( p_playlist, p_playlist->i_size - 1 );
    }
    else
    {
        playlist_Add( p_playlist, "vlc:loop",
                      PLAYLIST_APPEND | PLAYLIST_GO,
                      PLAYLIST_END );
    }
    p_intf->p_sys->b_loop = !p_intf->p_sys->b_loop;
}

BList * VlcWrapper::PlaylistAsArray()
{ 
    int i;
    BList* p_list = new BList(p_playlist->i_size);
    
    vlc_mutex_lock( &p_playlist->object_lock );

    for( i = 0; i < p_playlist->i_size; i++ )
    {
        p_list->AddItem(new BString(p_playlist->pp_items[i]->psz_name));
    }

    vlc_mutex_unlock( &p_playlist->object_lock );
    return( p_list );
}

void VlcWrapper::getPlaylistInfo( int32& currentIndex, int32& maxIndex )
{
	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 )
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
{
#if 0
	// sanity checks
	if ( pos < 0 )
		pos = 0;
	int size = playlistSize();
	if (pos >= size)
		pos = size - 1;
	// weird hack
    if( p_input_bank->pp_input[0] != NULL )
		pos--;
	// stop current stream
	playlistStop();
	// modify current position in playlist
	playlistLock();
	p_main->p_playlist->i_index = pos;
	playlistUnlock();
	// start playing
	playlistPlay();
#endif
}

454
void VlcWrapper::getNavCapabilities( bool *canSkipPrev, bool *canSkipNext )
455
456
457
458
459
460
461
{
	if ( canSkipPrev && canSkipNext )
	{
		// init the parameters
		*canSkipPrev = false;
		*canSkipNext = false;
		// get playlist info
462
463
		int pos = PlaylistCurrent();
		int size = PlaylistSize();
464
465

		// see if we have got a stream going		
466
		if ( p_input )
467
		{
468
			vlc_mutex_lock( &p_input->stream.stream_lock );
469

470
471
			bool hasTitles = p_input->stream.i_area_nb > 1;
			int numChapters = p_input->stream.p_selected_area->i_part_nb;
472
473
474
475
			bool hasChapters = numChapters > 1;
			// first, look for chapters
			if ( hasChapters )
			{
476
477
478
				*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;
479
480
481
482
			}
			// if one of the skip capabilities is false,
			// make it depend on titles instead
			if ( !*canSkipPrev && hasTitles )
483
				*canSkipPrev = p_input->stream.p_selected_area->i_id > 1;
484
			if ( !*canSkipNext && hasTitles )
485
486
				*canSkipNext = p_input->stream.p_selected_area->i_id <
				                   p_input->stream.i_area_nb - 1;
487

488
			vlc_mutex_unlock( &p_input->stream.stream_lock );
489
490
491
492
493
494
495
496
497
		}
		// last but not least, make capabilities depend on playlist
		if ( !*canSkipPrev )
			*canSkipPrev = pos > 0;
		if ( !*canSkipNext )
			*canSkipNext = pos < size - 1;
	}
}

498
void VlcWrapper::navigatePrev()
499
500
501
502
{
	bool hasSkiped = false;

	// see if we have got a stream going		
503
	if ( p_input )
504
505
	{
		// get information from stream (lock it while looking at it)
506
		vlc_mutex_lock( &p_input->stream.stream_lock );
507

508
509
510
		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;
511
		bool hasTitles = numTitles > 1;
512
		int numChapters = p_input->stream.p_selected_area->i_part_nb;
513
514
		bool hasChapters = numChapters > 1;

515
		vlc_mutex_unlock( &p_input->stream.stream_lock );
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544

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

			if ( currentChapter >= 0 )
			{
				toggleChapter( currentChapter );
				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 )
			{
				toggleTitle(currentTitle);
				hasSkiped = true;
			}
		}

	}
	// last but not least, skip to previous file
	if ( !hasSkiped )
545
		PlaylistPrev();
546
547
}

548
void VlcWrapper::navigateNext()
549
550
551
552
{
	bool hasSkiped = false;

	// see if we have got a stream going		
553
	if ( p_input )
554
555
	{
		// get information from stream (lock it while looking at it)
556
		vlc_mutex_lock( &p_input->stream.stream_lock );
557

558
559
560
		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;
561
		bool hasTitles = numTitles > 1;
562
		int numChapters = p_input->stream.p_selected_area->i_part_nb;
563
564
		bool hasChapters = numChapters > 1;

565
		vlc_mutex_unlock( &p_input->stream.stream_lock );
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593

		// first, look for chapters
		if ( hasChapters )
		{
			// skip to the next chapter
			currentChapter++;
			if ( currentChapter < numChapters )
			{
				toggleChapter( currentChapter );
				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 )
			{
				toggleTitle(currentTitle);
				hasSkiped = true;
			}
		}

	}
	// last but not least, skip to next file
	if ( !hasSkiped )
594
		PlaylistNext();
595
596
597
}


598
599
600
/***************************
 * audio infos and control *
 ***************************/
601

602
void VlcWrapper::SetVolume(int value)
603
{
604
    if( p_aout != NULL )
605
    {
606
607
608
609
		if ( p_intf->p_sys->b_mute )
		{
			p_intf->p_sys->b_mute = 0;
		}
610
        aout_VolumeSet( p_aout, value );
611
    }
612
}
613

614
void VlcWrapper::VolumeMute()
615
{
616
    if( p_aout != NULL )
617
   	{
618
619
620
621
   	    aout_VolumeGet( p_aout, &p_intf->p_sys->i_saved_volume );
	    aout_VolumeMute( p_aout, NULL );
	    p_intf->p_sys->b_mute = 1;
   	}
622
623
}

624
void VlcWrapper::VolumeRestore()
625
{
626
    if( p_aout != NULL )
627
628
629
   	{
        aout_VolumeSet( p_aout, p_intf->p_sys->i_saved_volume );
        p_intf->p_sys->b_mute = 0;
630
631
	}
}
632

633
bool VlcWrapper::IsMuted()
634
{
635
    return p_intf->p_sys->b_mute;
636
637
}

638
bool VlcWrapper::HasAudio()
639
{
640
    return( p_aout != NULL );
641
642
}

643
644
645
646
/*******
 * DVD *
 *******/
bool VlcWrapper::HasTitles()
647
{
648
    if( !p_input )
649
    {
650
651
652
        return false;
    }
    return ( p_input->stream.i_area_nb > 1 );
653
654
}

655
void VlcWrapper::PrevTitle()
656
{
657
658
659
    int i_id;
    i_id = p_input->stream.p_selected_area->i_id - 1;
    if( i_id > 0 )
660
    {
661
        toggleTitle(i_id);
662
663
664
    }
}

665
void VlcWrapper::NextTitle()
666
{
667
    unsigned int i_id;
668
669
    i_id = p_input->stream.p_selected_area->i_id + 1;
    if( i_id < p_input->stream.i_area_nb )
670
    {
671
        toggleTitle(i_id);
672
673
674
    }
}

675
676
677
bool VlcWrapper::HasChapters()
{
    if( !p_input )
678
    {
679
        return false;
680
    }
681
682
    return ( p_input->stream.p_selected_area->i_part_nb > 1 );
}
683

684
685
686
687
688
689
690
691
void VlcWrapper::PrevChapter()
{
    int i_id;
    i_id = p_input->stream.p_selected_area->i_part - 1;
    if( i_id >= 0 )
    {
        toggleChapter(i_id);
    }
692
693
}

694
void VlcWrapper::NextChapter()
Eric Petit's avatar
Eric Petit committed
695
{
696
697
698
699
700
701
    int i_id;
    i_id = p_input->stream.p_selected_area->i_part + 1;
    if( i_id >= 0 )
    {
        toggleChapter(i_id);
    }
Eric Petit's avatar
Eric Petit committed
702
703
}

704
void VlcWrapper::TitleInfo( int32 &currentIndex, int32 &maxIndex )
Eric Petit's avatar
Eric Petit committed
705
706
707
{
	currentIndex = -1;
	maxIndex = -1;
708
	if ( p_input )
Eric Petit's avatar
Eric Petit committed
709
	{
710
		vlc_mutex_lock( &p_input->stream.stream_lock );
Eric Petit's avatar
Eric Petit committed
711

712
		maxIndex = p_input->stream.i_area_nb - 1;
Eric Petit's avatar
Eric Petit committed
713
		if ( maxIndex > 0)
714
			currentIndex = p_input->stream.p_selected_area->i_id;
Eric Petit's avatar
Eric Petit committed
715
716
717
		else
			maxIndex = -1;

718
		vlc_mutex_unlock( &p_input->stream.stream_lock );
Eric Petit's avatar
Eric Petit committed
719
720
721
	}
}

722
void VlcWrapper::ChapterInfo( int32 &currentIndex, int32 &maxIndex )
Eric Petit's avatar
Eric Petit committed
723
724
725
{
	currentIndex = -1;
	maxIndex = -1;
726
	if ( p_input )
Eric Petit's avatar
Eric Petit committed
727
	{
728
		vlc_mutex_lock( &p_input->stream.stream_lock );
Eric Petit's avatar
Eric Petit committed
729

730
		maxIndex = p_input->stream.p_selected_area->i_part_nb - 1;
Eric Petit's avatar
Eric Petit committed
731
		if ( maxIndex > 0)
732
			currentIndex = p_input->stream.p_selected_area->i_part;
Eric Petit's avatar
Eric Petit committed
733
734
735
		else
			maxIndex = -1;

736
		vlc_mutex_unlock( &p_input->stream.stream_lock );
Eric Petit's avatar
Eric Petit committed
737
738
739
	}
}

740
void VlcWrapper::toggleTitle(int i_title)
741
{
742
    if( p_input != NULL )
743
    {
744
745
        input_ChangeArea( p_input,
                          p_input->stream.pp_areas[i_title] );
746

747
        vlc_mutex_lock( &p_input->stream.stream_lock );
748

749
        vlc_mutex_unlock( &p_input->stream.stream_lock );
750
751
752
    }
}

753
void VlcWrapper::toggleChapter(int i_chapter)
754
{
755
    if( p_input != NULL )
756
    {
757
758
759
        p_input->stream.p_selected_area->i_part = i_chapter;
        input_ChangeArea( p_input,
                          p_input->stream.p_selected_area );
760

761
762
        vlc_mutex_lock( &p_input->stream.stream_lock );
        vlc_mutex_unlock( &p_input->stream.stream_lock );
763
764
    }
}