- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# ShoutcastSource.h

    00001 /*
    00002  *      Copyright (C) 2003-2005 Gabest
    00003  *      http://www.gabest.org
    00004  *
    00005  *  This Program is free software; you can redistribute it and/or modify
    00006  *  it under the terms of the GNU General Public License as published by
    00007  *  the Free Software Foundation; either version 2, or (at your option)
    00008  *  any later version.
    00009  *
    00010  *  This Program is distributed in the hope that it will be useful,
    00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    00013  *  GNU General Public License for more details.
    00014  *
    00015  *  You should have received a copy of the GNU General Public License
    00016  *  along with GNU Make; see the file COPYING.  If not, write to
    00017  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
    00018  *  http://www.gnu.org/copyleft/gpl.html
    00019  *
    00020  */
    00021
    00022 #pragma once
    00023
    00024 #include <atlbase.h>
    00025 #include <afxtempl.h>
    00026 #include <afxinet.h>
    00027 #include <afxsock.h>
    00028 #include <atlutil.h>
    00029 #include <qnetwork.h>
    00030
    00031 [uuid("68F540E9-766F-44d2-AB07-E26CC6D27A79")]
    00032 class CShoutcastSource
    00033         : public CSource
    00034         , public IFileSourceFilter
    00035         , public IAMFilterMiscFlags
    00036         , public IAMOpenProgress
    00037         , public IAMMediaContent
    00038 {
    00039         CStringW m_fn;
    00040
    00041 public:
    00042         CShoutcastSource(LPUNKNOWN lpunk, HRESULT* phr);
    00043         virtual ~CShoutcastSource();
    00044
    00045         DECLARE_IUNKNOWN;
    00046     STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
    00047
    00048         // IFileSourceFilter
    00049         STDMETHODIMP Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt);
    00050         STDMETHODIMP GetCurFile(LPOLESTR* ppszFileName, AM_MEDIA_TYPE* pmt);
    00051
    00052         // IAMFilterMiscFlags
    00053         STDMETHODIMP_(ULONG) GetMiscFlags();
    00054
    00055         // IAMOpenProgress
    00056     STDMETHODIMP QueryProgress(LONGLONG* pllTotal, LONGLONG* pllCurrent);
    00057     STDMETHODIMP AbortOperation();
    00058
    00059         // IAMMediaContent
    00060         STDMETHODIMP GetTypeInfoCount(UINT* pctinfo) {return E_NOTIMPL;}
    00061         STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo) {return E_NOTIMPL;}
    00062         STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, UINT cNames, LCID lcid, DISPID* rgdispid) {return E_NOTIMPL;}
    00063         STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr) {return E_NOTIMPL;}
    00064         STDMETHODIMP get_AuthorName(BSTR* pbstrAuthorName) {return E_NOTIMPL;}
    00065         STDMETHODIMP get_Title(BSTR* pbstrTitle);
    00066         STDMETHODIMP get_Rating(BSTR* pbstrRating) {return E_NOTIMPL;}
    00067         STDMETHODIMP get_Description(BSTR* pbstrDescription) {return E_NOTIMPL;}
    00068         STDMETHODIMP get_Copyright(BSTR* pbstrCopyright) {return E_NOTIMPL;}
    00069         STDMETHODIMP get_BaseURL(BSTR* pbstrBaseURL) {return E_NOTIMPL;}
    00070         STDMETHODIMP get_LogoURL(BSTR* pbstrLogoURL) {return E_NOTIMPL;}
    00071         STDMETHODIMP get_LogoIconURL(BSTR* pbstrLogoURL) {return E_NOTIMPL;}
    00072         STDMETHODIMP get_WatermarkURL(BSTR* pbstrWatermarkURL) {return E_NOTIMPL;}
    00073         STDMETHODIMP get_MoreInfoURL(BSTR* pbstrMoreInfoURL) {return E_NOTIMPL;}
    00074         STDMETHODIMP get_MoreInfoBannerImage(BSTR* pbstrMoreInfoBannerImage) {return E_NOTIMPL;}
    00075         STDMETHODIMP get_MoreInfoBannerURL(BSTR* pbstrMoreInfoBannerURL) {return E_NOTIMPL;}
    00076         STDMETHODIMP get_MoreInfoText(BSTR* pbstrMoreInfoText) {return E_NOTIMPL;}
    00077 };
    00078
    00079 class CShoutcastStream : public CSourceStream
    00080 {
    00081         class mp3frame
    00082         {
    00083         public:
    00084                 DWORD len;
    00085                 BYTE* pData;
    00086                 REFERENCE_TIME rtStart, rtStop;
    00087                 CString title;
    00088                 mp3frame(DWORD len = 0) {pData = (this->len = len) ? new BYTE[len] : NULL; rtStart = rtStop = 0;}
    00089                 mp3frame(const mp3frame& f) {*this = f;}
    00090                 ~mp3frame() {delete pData;}
    00091                 void operator = (const mp3frame& f)
    00092                 {
    00093                         len = f.len;
    00094                         pData = f.pData;
    00095                         rtStart = f.rtStart;
    00096                         rtStop = f.rtStop;
    00097                         title = f.title;
    00098                         ((mp3frame*)&f)->pData = NULL;
    00099                 }
    00100         };
    00101
    00102         class mp3queue : public CList<mp3frame>, public CCritSec {} m_queue;
    00103
    00104         class CShoutcastSocket : public CSocket
    00105         {
    00106                 DWORD m_nBytesRead;
    00107
    00108         public:
    00109                 CShoutcastSocket() {m_metaint = m_bitrate = m_freq = m_channels = 0;}
    00110                 int Receive(void* lpBuf, int nBufLen, int nFlags = 0);
    00111
    00112                 DWORD m_metaint, m_bitrate, m_freq, m_channels;
    00113                 CString m_title;
    00114                 bool Connect(CUrl& url);
    00115                 bool FindSync();
    00116         } m_socket;
    00117
    00118         HANDLE m_hSocketThread;
    00119
    00120         CUrl m_url;
    00121
    00122         bool m_fBuffering;
    00123         CString m_title;
    00124
    00125 public:
    00126     CShoutcastStream(const WCHAR* wfn, CShoutcastSource* pParent, HRESULT* phr);
    00127         virtual ~CShoutcastStream();
    00128
    00129         bool fExitThread;
    00130         UINT SocketThreadProc();
    00131
    00132         void EmptyBuffer();
    00133         LONGLONG GetBufferFullness();
    00134         CString GetTitle();
    00135
    00136     HRESULT DecideBufferSize(IMemAllocator* pIMemAlloc, ALLOCATOR_PROPERTIES* pProperties);
    00137     HRESULT FillBuffer(IMediaSample* pSample);
    00138     HRESULT CheckMediaType(const CMediaType* pMediaType);
    00139     HRESULT GetMediaType(int iPosition, CMediaType* pmt);
    00140
    00141         STDMETHODIMP Notify(IBaseFilter* pSender, Quality q) {return E_NOTIMPL;}
    00142
    00143     HRESULT OnThreadCreate();
    00144     HRESULT OnThreadDestroy();
    00145         HRESULT Inactive();
    00146     HRESULT Pause();
    00147 };