Merge pull request #110 from tesselode/fixes
[wdl/wdl-ol.git] / WDL / scsrc.h
blobb4cbbb62a94fb096ee85255f32a57b05987c76ea
1 /*
2 WDL - scsrc.h
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.
33 #ifndef _WDL_SCSRC_H_
34 #define _WDL_SCSRC_H_
36 #include <time.h>
37 #include "jnetlib/connection.h"
38 #include "jnetlib/httpget.h"
39 #include "lameencdec.h"
40 #include "wdlstring.h"
41 #include "fastqueue.h"
42 #include "queue.h"
43 #include "mutex.h"
45 #include "resample.h"
48 class WDL_ShoutcastSource
50 public:
51 WDL_ShoutcastSource(const char *host, const char *pass, const char *name, bool pub=false,
52 const char *genre=NULL, const char *url=NULL,
54 int nch=2, int srate=44100, int kbps=128,
55 const char *ircchan=NULL
57 ~WDL_ShoutcastSource();
59 int GetStatus(); // returns 0 if connected/connecting, >0 if disconnected, -1 if failed connect (or other error) from the start
60 void GetStatusText(char *buf, int bufsz); // gets status text
62 void SetCurTitle(const char *title);
64 int GetSampleRate() { return m_srate; }
65 void OnSamples(float **samples, int nch, int chspread, int frames, double srate);
66 int RunStuff(); // returns nonzero if work done
69 void *userData;
70 int totalBitrate; // 0 for normal, otherwise if using NSV (below) set to kbps of total stream
71 // allows hooking to say, I dunno, package in some other format such as NSV?
72 void (*sendProcessor)(void *userData, WDL_Queue *dataout, WDL_Queue *data);
74 int GetAudioBitrate() { return m_br*1000; }
76 private:
78 WDL_Queue m_procdata;
80 LameEncoder *m_encoder;
81 int m_encoder_splsin;
83 WDL_String m_host,m_pass,m_url,m_genre,m_name,m_ircchan;
84 int m_br;
85 bool m_pub;
87 time_t m_titlecon_start,m_sendcon_start;
89 unsigned int m_bytesout;
90 int m_state;
91 int m_nch,m_srate;
93 WDL_Resampler m_rs;
94 WDL_FastQueue m_samplequeue; // interleaved samples (float)
96 JNL_HTTPGet *m_titlecon;
97 JNL_Connection *m_sendcon;
99 WDL_TypedBuf<float> m_workbuf;
100 WDL_Mutex m_samplemutex;
101 WDL_Mutex m_titlemutex;
102 char m_title[512];
103 bool m_needtitle;
106 bool m_is_postmode;
107 unsigned int m_postmode_session;
108 int m_post_bytesleft;
109 int m_post_postsleft;
111 void PostModeConnect();
115 #endif // _WDL_SCSRC_H_