xref: /haiku/src/add-ons/media/media-add-ons/esound_sink/ESDEndpoint.h (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
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 
41 class ESDEndpoint : public BDataIO {
42 public:
43 	ESDEndpoint();
44 	~ESDEndpoint();
45 
46 	/*  */
47 status_t	InitCheck() const;
48 void		Reset();
49 status_t	SendAuthKey();
50 
51 bool		Connected() const;
52 status_t	Connect(const char *host, uint16 port=ESD_DEFAULT_PORT);
53 status_t	Disconnect();
54 
55 	/* set the default command and format for BDataIO interface */
56 status_t	SetCommand(esd_command_t cmd=ESD_PROTO_STREAM_PLAY);
57 status_t	SetFormat(int bits, int channels, float rate=ESD_DEFAULT_RATE);
58 
59 status_t	GetServerInfo();
60 
61 	/*  */
62 
63 bigtime_t	GetLatency() const { return fLatency; };
64 const char	*Host() const { return fHost.String(); };
65 uint16		Port() const { return fPort; };
66 
67 bool		CanSend();
68 
69 	/* BDataIO */
70 
71 virtual ssize_t		Read(void *buffer, size_t size);
72 virtual ssize_t		Write(const void *buffer, size_t size);
73 
74 	status_t	SendCommand(esd_command_t cmd, const uint8 *obuf, size_t olen, uint8 *ibuf, size_t ilen);
75 	status_t	SendDefaultCommand();
76 private:
77 
78 	static int32	_ConnectThread(void *_arg);
79 	int32			ConnectThread(void);
80 
81 	status_t		fInitStatus;
82 	thread_id		fConnectThread;
83 	BString			fHost;
84 	uint16			fPort;
85 	int				fSocket;
86 	esd_key_t		fAuthKey;
87 	esd_command_t	fDefaultCommand;
88 	bool			fDefaultCommandSent;
89 	esd_format_t	fDefaultFormat;
90 	esd_rate_t		fDefaultRate;
91 	bigtime_t		fLatency;
92 };
93 
94 
95 #endif /* ESDENDPOINT_H */
96