blob: d97d8be5935583354ea74c2850127be86e9ab078 (
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
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> //Header file for sleep(). man 3 sleep for details.
#include <errno.h>
#include <pthread.h>
#include <sys/socket.h>
#include <sys/un.h>
/* Flags for the info decoder function. */
enum tags_select
{
TAGS_COMMENTS = 0x01, /* artist, title, etc. */
TAGS_TIME = 0x02 /* time of the file. */
};
enum moc_state {
STOPPED,
PLAYING,
PAUSED
};
enum moc_status {
INITIALIZING,
CONNECTED,
FAILED_TO_CONNECT,
ERROR,
RECONNECTING
};
/* One entry in the server's playlist or queue. A singly-linked list hangs
* off struct moc's playlist/queue fields. */
struct moc_plist_item {
char *file;
char *title;
char *artist;
char *album;
int track;
int time;
struct moc_plist_item *next;
};
struct moc {
pthread_mutex_t lock;
enum moc_status status;
enum moc_state state;
char *filename;
char *title;
char *album;
char *artist;
int track;
int time;
int filled;
int length;
struct moc_plist_item *playlist;
struct moc_plist_item *queue;
/* The background thread owns the actual reads; sock/sock_lock let any
* other thread send commands without racing/interleaving with it or with
* the background thread's own internal requests. */
int sock;
pthread_mutex_t sock_lock;
};
extern const char * moc_str_status(enum moc_status s);
extern const char * moc_str_state(enum moc_state s);
extern struct moc * moc_init();
/* Commands a UI can call from any thread to control playback or modify the
* playlist. Safe to call concurrently with each other and with the
* background thread; each is a single atomic request to the server. */
extern void moc_play(struct moc *mh, const char *file);
extern void moc_pause(struct moc *mh);
extern void moc_unpause(struct moc *mh);
extern void moc_stop(struct moc *mh);
extern void moc_next(struct moc *mh);
extern void moc_prev(struct moc *mh);
extern void moc_playlist_add(struct moc *mh, const char *file);
extern void moc_playlist_remove(struct moc *mh, const char *file);
extern void moc_playlist_clear(struct moc *mh);
|