]> git.sesse.net Git - vlc/blob - modules/gui/beos/AudioOutput.cpp
Strings review
[vlc] / modules / gui / beos / AudioOutput.cpp
1 /*****************************************************************************
2  * AudioOutput.cpp: BeOS audio output
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 VideoLAN
5  * $Id: AudioOutput.cpp,v 1.30 2004/01/26 16:52:31 zorglub Exp $
6  *
7  * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *          Eric Petit <titer@videolan.org>
10  *
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.
15  *
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.
20  *
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include <stdio.h>
30 #include <stdlib.h>                                      /* malloc(), free() */
31 #include <malloc.h>
32 #include <string.h>
33
34 #include <SoundPlayer.h>
35 #include <media/MediaDefs.h>
36
37
38 #include <vlc/vlc.h>
39 #include <vlc/aout.h>
40 extern "C"
41 {
42     #include <aout_internal.h>
43 }
44
45 /*****************************************************************************
46  * aout_sys_t: BeOS audio output method descriptor
47  *****************************************************************************/
48
49 typedef struct aout_sys_t
50 {
51     BSoundPlayer * p_player;
52     mtime_t        latency;
53
54 } aout_sys_t;
55
56 /*****************************************************************************
57  * Local prototypes.
58  *****************************************************************************/
59 static void Play         ( void * p_aout, void * p_buffer, size_t size,
60                            const media_raw_audio_format & format );
61 static void DoNothing    ( aout_instance_t * p_aout );
62
63 /*****************************************************************************
64  * OpenAudio
65  *****************************************************************************/
66 int E_(OpenAudio) ( vlc_object_t * p_this )
67 {
68     aout_instance_t * p_aout = (aout_instance_t*) p_this;
69     p_aout->output.p_sys = (aout_sys_t*) malloc( sizeof( aout_sys_t ) );
70     if( p_aout->output.p_sys == NULL )
71     {
72         msg_Err( p_aout, "out of memory" );
73         return -1;
74     }
75     aout_sys_t * p_sys = p_aout->output.p_sys;
76
77     aout_VolumeSoftInit( p_aout );
78
79     int i_nb_channels = aout_FormatNbChannels( &p_aout->output.output );
80     /* BSoundPlayer does not support more than 2 channels AFAIK */
81     if( i_nb_channels > 2 )
82     {
83         i_nb_channels = 2;
84         p_aout->output.output.i_physical_channels
85             = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
86     }
87
88     media_raw_audio_format * p_format;
89     p_format = (media_raw_audio_format*)
90         malloc( sizeof( media_raw_audio_format ) );
91
92     p_format->channel_count = i_nb_channels;
93     p_format->frame_rate = p_aout->output.output.i_rate;
94     p_format->format = media_raw_audio_format::B_AUDIO_FLOAT;
95 #ifdef WORDS_BIGENDIAN
96     p_format->byte_order = B_MEDIA_BIG_ENDIAN;
97 #else
98     p_format->byte_order = B_MEDIA_LITTLE_ENDIAN;
99 #endif
100     p_format->buffer_size = 8192;
101
102     p_aout->output.output.i_format = VLC_FOURCC('f','l','3','2');
103     p_aout->output.i_nb_samples = 2048 / i_nb_channels;
104     p_aout->output.pf_play = DoNothing;
105
106     p_sys->p_player = new BSoundPlayer( p_format, "player", Play, NULL, p_aout );
107     if( p_sys->p_player->InitCheck() != B_OK )
108     {
109         msg_Err( p_aout, "BSoundPlayer InitCheck failed" );
110         delete p_sys->p_player;
111         free( p_sys );
112         return -1;
113     }
114
115     /* Start playing */
116     p_sys->latency = p_sys->p_player->Latency();
117     p_sys->p_player->Start();
118     p_sys->p_player->SetHasData( true );
119
120     return 0;
121 }
122
123 /*****************************************************************************
124  * CloseAudio
125  *****************************************************************************/
126 void E_(CloseAudio) ( vlc_object_t * p_this )
127 {
128     aout_instance_t * p_aout = (aout_instance_t *) p_this;
129     aout_sys_t * p_sys = (aout_sys_t *) p_aout->output.p_sys;
130
131     /* Clean up */
132     p_sys->p_player->Stop();
133     delete p_sys->p_player;
134     free( p_sys );
135 }
136
137 /*****************************************************************************
138  * Play
139  *****************************************************************************/
140 static void Play( void * _p_aout, void * _p_buffer, size_t i_size,
141                   const media_raw_audio_format &format )
142 {
143     aout_instance_t * p_aout = (aout_instance_t*) _p_aout;
144     float * p_buffer = (float*) _p_buffer;
145     aout_sys_t * p_sys = (aout_sys_t*) p_aout->output.p_sys;
146     aout_buffer_t * p_aout_buffer;
147
148     p_aout_buffer = aout_OutputNextBuffer( p_aout,
149                                            mdate() + p_sys->latency,
150                                            VLC_FALSE );
151
152     if( p_aout_buffer != NULL )
153     {
154         p_aout->p_vlc->pf_memcpy( p_buffer, p_aout_buffer->p_buffer,
155                                   MIN( i_size, p_aout_buffer->i_nb_bytes ) );
156         if( p_aout_buffer->i_nb_bytes < i_size )
157         {
158             p_aout->p_vlc->pf_memset( p_buffer + p_aout_buffer->i_nb_bytes,
159                                       0, i_size - p_aout_buffer->i_nb_bytes );
160         }
161         aout_BufferFree( p_aout_buffer );
162     }
163     else
164     {
165         p_aout->p_vlc->pf_memset( p_buffer, 0, i_size );
166     }
167 }
168
169 /*****************************************************************************
170  * DoNothing
171  *****************************************************************************/
172 static void DoNothing( aout_instance_t *p_aout )
173 {
174     return;
175 }