1/*
2 * ESounD media addon for BeOS
3 *
4 * Copyright (c) 2006 François Revol (revol@free.fr)
5 *
6 * Based on Multi Audio addon for Haiku,
7 * Copyright (c) 2002, 2003 Jerome Duval (jerome.duval@free.fr)
8 *
9 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
12 *
13 * - Redistributions of source code must retain the above copyright notice,
14 *   this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright notice,
16 *   this list of conditions and the following disclaimer in the documentation
17 *   and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 */
31#ifndef ESDENDPOINT_H
32#define ESDENDPOINT_H
33
34#include "esdproto.h"
35#include <DataIO.h>
36#include <String.h>
37
38//#define ESD_FMT 8
39#define ESD_FMT 16
40
41class ESDEndpoint : public BDataIO {
42public:
43	ESDEndpoint();
44	~ESDEndpoint();
45
46	/*  */
47status_t	InitCheck() const;
48void		Reset();
49status_t	SendAuthKey();
50
51bool		Connected() const;
52status_t	Connect(const char *host, uint16 port=ESD_DEFAULT_PORT);
53status_t	WaitForConnect();
54status_t	Disconnect();
55
56	/* set the default command and format for BDataIO interface */
57status_t	SetCommand(esd_command_t cmd=ESD_PROTO_STREAM_PLAY);
58status_t	SetFormat(int bits, int channels, float rate=ESD_DEFAULT_RATE);
59
60status_t	GetServerInfo();
61
62	/*  */
63
64bigtime_t	Latency() const { return fLatency; };
65const char	*Host() const { return fHost.String(); };
66uint16		Port() const { return fPort; };
67void		GetFriendlyName(BString &name);
68
69bool		CanSend();
70
71	/* BDataIO */
72
73virtual ssize_t		Read(void *buffer, size_t size);
74virtual ssize_t		Write(const void *buffer, size_t size);
75
76	status_t	SendCommand(esd_command_t cmd, const uint8 *obuf, size_t olen, uint8 *ibuf, size_t ilen);
77	status_t	SendDefaultCommand();
78private:
79
80	static int32	_ConnectThread(void *_arg);
81	int32			ConnectThread(void);
82
83	status_t		fInitStatus;
84	thread_id		fConnectThread;
85	BString			fHost;
86	uint16			fPort;
87	int				fSocket;
88	esd_key_t		fAuthKey;
89	esd_command_t	fDefaultCommand;
90	bool			fDefaultCommandSent;
91	esd_format_t	fDefaultFormat;
92	esd_rate_t		fDefaultRate;
93	bigtime_t		fLatency;
94};
95
96
97#endif /* ESDENDPOINT_H */
98