File: CorePlayer.h

package info (click to toggle)
alsaplayer 0.99.81-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 5,736 kB
  • sloc: ansic: 20,668; sh: 11,296; cpp: 10,615; makefile: 1,106; yacc: 289; sed: 16
file content (196 lines) | stat: -rw-r--r-- 5,531 bytes parent folder | download | duplicates (2)
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
/*  CorePlayer.h
 *  Copyright (C) 1998-2002 Andy Lo A Foe <andy@alsaplayer.org>
 *
 *  This file is part of AlsaPlayer.
 *
 *  AlsaPlayer 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 3 of the License, or
 *  (at your option) any later version.
 *
 *  AlsaPlayer 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, see <http://www.gnu.org/licenses/>.
 *
 *  $Id: CorePlayer.h 1250 2007-07-08 14:17:12Z dominique_libre $
 *  
*/ 

#ifndef __CorePlayer_h__
#define __CorePlayer_h__
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <set>
#include "SampleBuffer.h"
#include "AlsaNode.h"
#include "AlsaSubscriber.h"
#include "input_plugin.h"

#ifdef __linux__
#include <linux/limits.h>
#endif // __linux__

// Tunable parameters

#define BUF_SIZE (10240)	// Size of a single ringbuffer partition
#define NR_BUF 16		// Number of partitions in ringbuffer
#define NR_CBUF 8		// Number of partitions to read ahead
				// (equals 2.6 seconds). NOTE: NR_CBUF
				// should NEVER exceed (NR_BUF/2), it doesn't
				// make sense otherwise

#define MAX_INPUT_PLUGINS 16

typedef void(*volume_changed_type)(void *, float new_vol);
typedef void(*speed_changed_type)(void *, float new_speed);
typedef void(*pan_changed_type)(void *, float new_pan);
typedef void(*position_notify_type)(void *, int pos);
typedef void(*stop_notify_type)(void *);
typedef void(*start_notify_type)(void *);		

typedef struct _coreplayer_notifier
{
	void *data;
	volume_changed_type volume_changed;
	speed_changed_type speed_changed;
	pan_changed_type pan_changed;
	position_notify_type position_notify;
	start_notify_type start_notify;
	stop_notify_type stop_notify;
} coreplayer_notifier;


typedef struct _sample_buf
{
	int start;
	_sample_buf *next, *prev;
	SampleBuffer *buf;
} sample_buf;


class CorePlayer // Much more abstraction to come, well maybe not
{
 private:
	int total_frames;
	int write_buf_changed;
	int read_direction;
	int frames_in_buffer;
	int jump_point;
	int last_read;
	bool streaming;
	int repitched;
	int new_frame_number;
	float pitch_point;
	float pitch;
	float pitch_multi;
        float real_pitch;
	bool jumped;
	bool producing;
	float volume;
	float pan;
	int output_rate;
	int input_rate;
	AlsaNode *node;
	AlsaSubscriber *sub;
	float save_speed;

	std::set<coreplayer_notifier *> notifiers;
	
	// INPUT plugin stuff
	input_object *the_object;
	input_plugin *plugin; // Pointer to the current plugin
	
	pthread_t producer_thread;
	pthread_mutex_t player_mutex;
	pthread_mutex_t counter_mutex;
	pthread_cond_t producer_ready;
	pthread_mutex_t thread_mutex;
	pthread_mutex_t notifier_mutex;
#if !defined(EMBEDDED)
	// this buffer is used to apply volume/pan and mixing channels
	char *input_buffer;
#endif
	sample_buf *buffer;
	sample_buf *read_buf, *write_buf, *new_write_buf;
	int FrameSeek(int);
	int FilledBuffers();
	void ResetBuffer();
	void SetSpeedMulti(float multi) { pitch_multi = multi; }
	void update_pitch();
	void kill_producer();
	static void producer_func(void *data);
	static bool streamer_func(void *, void *, int);
	int pcm_worker(sample_buf *dest, int start);
	int Read32(void *, int);
	int SetDirection(int dir);
	int GetDirection() { return read_direction; }
	void load_input_addons();
	void unregister_plugins();
	void UnregisterPlugins();
	void Lock();
	void Unlock();
	void LockNotifiers();
	void UnlockNotifiers();
	int RegisterPlugin(input_plugin *the_plugin);

 public:
	// Static members
	static int plugins_loaded;
	static int plugin_count;
	static pthread_mutex_t plugins_mutex;
	static input_plugin plugins[MAX_INPUT_PLUGINS];
	
	CorePlayer(AlsaNode *node=(AlsaNode *)NULL);
	~CorePlayer();

	void RegisterNotifier(coreplayer_notifier *, void *data);
	void UnRegisterNotifier(coreplayer_notifier *);

	AlsaNode *GetNode() { return node; }
	int GetPosition();	// Current position in frames
	void PositionUpdate();	// Notify the interfaces about the position
	int SetSpeed(float val);	// Set the playback speed: 1.0 = 100%
	float GetSpeed();	// Get speed
	float GetVolume() { return volume; }	// Get Volume level
	void SetVolume(float vol);	// Set volume level
	float GetPan() { return pan; }	// Get Pan level
	
	void SetPan(float p);	// Set Pan level: 
					// 0.0	= center
					// -1.0 = right channel muted
					// 1.0  = left channel muted
	
	int GetCurrentTime(int frame=-1);
					// Returns the time position of frame in
					// hundreths of seconds
	int GetStreamInfo(stream_info *info); // Return stream info
	int GetFrames();	// Total number of frames
	int GetTracks();	// Total number of tracks
	int GetSampleRate();	// Samplerat of this player
	int GetChannels();	// Number of channels
	int GetFrameSize();	// Frame size in bytes
	input_plugin * GetPlayer(const char *); // This one is temporary
	int GetLatency() { if (node) return node->GetLatency(); else return 0; }

	bool Open(const char *path = (const char *)NULL);
	void Close();
	bool Start();
	void Stop();
	int Seek(int pos);
	bool CanSeek();

	void Pause ();
	void UnPause ();
	bool IsPaused ();
	
	int IsActive() { return streaming; }	
	int IsPlaying() { return producing; }
};


#endif