~oxalin/lightspark/buildnaudioplugin

« back to all changes in this revision

Viewing changes to backends/interfaces/audio/openal/OpenALPlugin.h

  • Committer: Alessandro
  • Date: 2010-09-06 19:31:31 UTC
  • mfrom: (911.13.93)
  • Revision ID: git-v1:9f6175895e49dc81d39f6f99e66e2adc5a82bdb3
Merge branch 'master' of http://github.com/Oxalin/lightspark

Conflicts:
        CMakeLists.txt
        scripting/flashnet.cpp

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************************
 
2
    Lightspark, a free flash player implementation
 
3
 
 
4
    Copyright (C) 2009,2010  Alessandro Pignotti (a.pignotti@sssup.it)
 
5
 
 
6
    This program is free software: you can redistribute it and/or modify
 
7
    it under the terms of the GNU Lesser General Public License as published by
 
8
    the Free Software Foundation, either version 3 of the License, or
 
9
    (at your option) any later version.
 
10
 
 
11
    This program is distributed in the hope that it will be useful,
 
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
    GNU Lesser General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU Lesser General Public License
 
17
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
**************************************************************************/
 
19
 
 
20
#ifndef OPENALPLUGIN_H
 
21
#define OPENALPLUGIN_H
 
22
 
 
23
#include <AL/al.h>
 
24
#include <AL/alc.h>
 
25
#include "../IAudioPlugin.h"
 
26
#include "../../../decoder.h"
 
27
#include "../../../../compat.h"
 
28
#include <iostream>
 
29
 
 
30
#define NUM_BUFFERS 4
 
31
#define NUM_SOURCES 1
 
32
 
 
33
using namespace std;
 
34
 
 
35
 
 
36
class OpenALPlugin : public IAudioPlugin
 
37
{
 
38
private:
 
39
        ALCcontext *context;
 
40
        ALCdevice *playbackDevice;
 
41
        ALCdevice *captureDevice;
 
42
        ALuint  pbBuffers[NUM_BUFFERS];
 
43
        ALuint  pbSources[NUM_SOURCES];
 
44
        void initPlayback ( OpenALPlugin *th );
 
45
        void initCapture ( OpenALPlugin *th );
 
46
        static void contextStatusCB ( pa_context *context, OpenALPlugin *th );
 
47
        static void streamStatusCB ( pa_stream *stream, AudioStream *th );
 
48
        static void streamWriteCB ( pa_stream *stream, size_t nbytes, AudioStream *th );
 
49
        void addDeviceToList ( vector<string *> *devicesList, string *deviceName );
 
50
        void generateDevicesList ( vector<string *> *devicesList, DEVICE_TYPES desiredType ); //To populate the devices lists, devicesType must be playback or capture
 
51
        void start();
 
52
        vector<AudioStream*> streams;
 
53
public:
 
54
        OpenALPlugin ( PLUGIN_TYPES init_Type = AUDIO, string init_Name = "OpenAL plugin",
 
55
                       string init_audiobackend = "openal", bool init_contextReady = false,
 
56
                       bool init_noServer = false, bool init_stopped = false );
 
57
        void set_device ( string desiredDevice, DEVICE_TYPES desiredType );
 
58
        uint32_t createStream ( lightspark::AudioDecoder *decoder );
 
59
        void freeStream ( uint32_t id );
 
60
        void fill ( uint32_t id );
 
61
        void stop();
 
62
        uint32_t getPlayedTime ( uint32_t streamId );
 
63
        ~OpenALPlugin();
 
64
};
 
65
 
 
66
class AudioStream
 
67
{
 
68
public:
 
69
        enum STREAM_STATUS { STREAM_STARTING = 0, STREAM_READY = 1, STREAM_DEAD = 2 };
 
70
        pa_stream *stream;
 
71
        lightspark::AudioDecoder *decoder;
 
72
        OpenALPlugin *manager;
 
73
        volatile STREAM_STATUS streamStatus;
 
74
        AudioStream ( OpenALPlugin *m ) : stream ( NULL ), decoder ( NULL ), manager ( m ), streamStatus ( STREAM_STARTING ) {}
 
75
};