summaryrefslogtreecommitdiff
path: root/src/player/player2.c
blob: cd9beae98b21413be7da7b2eda10ff3a4b766a70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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
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
/*
Copyright (c) 2015
    Micha³ Cichoñ <thedmd@interia.pl>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

/* receive/play audio stream */

/* based on DShow example player */

#include "config.h"
#include "player2_private.h"
#include <stdlib.h>
#include <string.h>
#include <memory.h>

# define length_of(x)   (sizeof(x)/sizeof(*(x)))

static player2_iface* player2_backends[] =
{
    &player2_windows_media_foundation, // expermiental
    &player2_direct_show,
};

struct _player_t
{
    player2_iface*  backend;
    player2_t       player;
};

bool BarPlayer2Init(player2_t* outPlayer, const char* defaultPlayer)
{
    player2_t player;
    struct _player_t result;
    int i;

    memset(&result, 0, sizeof(struct _player_t));

    for (i = 0; i < length_of(player2_backends); ++i)
    {
        player2_iface* backend = player2_backends[i];

        bool acceptPlayer = true;
        if (defaultPlayer && !(strcmp(backend->Id, defaultPlayer) == 0))
            acceptPlayer = false;

        if (acceptPlayer)
            result.player = backend->Create();

        if (result.player)
        {
            result.backend = backend;
            break;
        }
    }

    if (!result.backend)
        return false;

    player = malloc(sizeof(struct _player_t));
    if (!player)
        return false;

    *player = result;

    *outPlayer = player;

    return true;
}

void BarPlayer2Destroy(player2_t player)
{
    if (player->player)
    {
        player->backend->Destroy(player->player);
        player->player = NULL;
    }
}

void BarPlayer2SetVolume(player2_t player, float volume)
{
    if (player->player)
        player->backend->SetVolume(player->player, volume);
}

float BarPlayer2GetVolume(player2_t player)
{
    if (player->player)
        return player->backend->GetVolume(player->player);
    else
        return 0.0f;
}

void BarPlayer2SetGain(player2_t player, float gainDb)
{
    if (player->player)
        player->backend->SetGain(player->player, gainDb);
}

float BarPlayer2GetGain(player2_t player)
{
    if (player->player)
        return player->backend->GetGain(player->player);
    else
        return 0.0f;
}

double BarPlayer2GetDuration(player2_t player)
{
    if (player->player)
        return player->backend->GetDuration(player->player);
    else
        return 0.0f;
}

double BarPlayer2GetTime(player2_t player)
{
    if (player->player)
        return player->backend->GetTime(player->player);
    else
        return 0.0f;
}

bool BarPlayer2Open(player2_t player, const char* url)
{
    if (player->player)
        return player->backend->Open(player->player, url);
    else
        return false;
}

bool BarPlayer2Play(player2_t player)
{
    if (player->player)
        return player->backend->Play(player->player);
    else
        return false;
}

bool BarPlayer2Pause(player2_t player)
{
    if (player->player)
        return player->backend->Pause(player->player);
    else
        return false;
}

bool BarPlayer2Stop(player2_t player)
{
    if (player->player)
        return player->backend->Stop(player->player);
    else
        return false;
}

bool BarPlayer2Finish(player2_t player)
{
    if (player->player)
        return player->backend->Finish(player->player);
    else
        return false;
}

bool BarPlayer2IsPlaying(player2_t player)
{
    if (player->player)
        return player->backend->IsPlaying(player->player);
    else
        return false;
}

bool BarPlayer2IsPaused(player2_t player)
{
    if (player->player)
        return player->backend->IsPaused(player->player);
    else
        return false;
}

bool BarPlayer2IsStopped(player2_t player)
{
    if (player->player)
        return player->backend->IsStopped(player->player);
    else
        return false;
}

bool BarPlayer2IsFinished(player2_t player)
{
    if (player->player)
        return player->backend->IsFinished(player->player);
    else
        return true;
}