3 Copyright (C) 2007, Cockos Incorporated
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
22 This file provides for an object to source a SHOUTcast (www.shoutcast.com) stream.
23 It uses the lameencdec.h interface (and lame_enc.dll) to encode, and JNetLib to send the data.
26 This object will not auto-reconnect on disconnect. If GetStatus() returns error, the callee needs to
27 delete the object and create a new one.
37 #include "jnetlib/connection.h"
38 #include "jnetlib/httpget.h"
39 #include "lameencdec.h"
40 #include "wdlstring.h"
41 #include "fastqueue.h"
45 class WDL_ShoutcastSource
48 WDL_ShoutcastSource(const char *host
, const char *pass
, const char *name
, bool pub
=false,
49 const char *genre
=NULL
, const char *url
=NULL
,
51 int nch
=2, int srate
=44100, int kbps
=128,
52 const char *ircchan
=NULL
54 ~WDL_ShoutcastSource();
56 int GetStatus(); // returns 0 if connected/connecting, >0 if disconnected, -1 if failed connect (or other error) from the start
57 void GetStatusText(char *buf
, int bufsz
); // gets status text
59 void SetCurTitle(const char *title
);
61 int GetSampleRate() { return m_srate
; }
62 void OnSamples(float **samples
, int nch
, int chspread
, int frames
, double srate
);
63 int RunStuff(); // returns nonzero if work done
67 int totalBitrate
; // 0 for normal, otherwise if using NSV (below) set to kbps of total stream
68 // allows hooking to say, I dunno, package in some other format such as NSV?
69 void (*sendProcessor
)(void *userData
, WDL_Queue
*dataout
, WDL_Queue
*data
);
71 int GetAudioBitrate() { return m_br
*1000; }
77 LameEncoder
*m_encoder
;
80 WDL_String m_host
,m_pass
,m_url
,m_genre
,m_name
,m_ircchan
;
84 time_t m_titlecon_start
,m_sendcon_start
;
86 unsigned int m_bytesout
;
90 double m_last_samples
[2] WDL_FIXALIGN
;
91 double m_rspos
; // last resample fractional position
93 WDL_FastQueue m_samplequeue
; // interleaved samples (float)
95 JNL_HTTPGet
*m_titlecon
;
96 JNL_Connection
*m_sendcon
;
98 WDL_TypedBuf
<float> m_workbuf
,m_rsbuf
;
99 WDL_Mutex m_samplemutex
;
100 WDL_Mutex m_titlemutex
;
106 unsigned int m_postmode_session
;
107 int m_post_bytesleft
;
108 int m_post_postsleft
;
110 void PostModeConnect();
114 #endif // _WDL_SCSRC_H_