Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[afcc26]: xbmc / FileSystem / FileShoutcast.cpp Maximize Restore History

Repo status: analyzing...

Download this file

FileShoutcast.cpp    146 lines (125 with data), 3.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
// FileShoutcast.cpp: implementation of the CFileShoutcast class.
//
//////////////////////////////////////////////////////////////////////
#include "system.h"
#include "AdvancedSettings.h"
#include "Application.h"
#include "FileShoutcast.h"
#include "GUISettings.h"
#include "GUIDialogProgress.h"
#include "GUIWindowManager.h"
#include "URL.h"
#include "utils/TimeUtils.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#include "utils/GUIInfoManager.h"
#include "utils/log.h"
using namespace XFILE;
using namespace MUSIC_INFO;
CFileShoutcast::CFileShoutcast()
{
m_lastTime = CTimeUtils::GetTimeMS();
m_discarded = 0;
m_currint = 0;
m_buffer = NULL;
}
CFileShoutcast::~CFileShoutcast()
{
Close();
}
int64_t CFileShoutcast::GetPosition()
{
return m_file.GetPosition()-m_discarded;
}
int64_t CFileShoutcast::GetLength()
{
return 0;
}
bool CFileShoutcast::Open(const CURL& url)
{
CURL url2(url);
url2.SetProtocolOptions("noshout=true&Icy-MetaData=1");
url2.SetProtocol("http");
bool result=false;
if ((result=m_file.Open(url2.Get())))
{
m_tag.SetTitle(m_file.GetHttpHeader().GetValue("icy-name"));
if (m_tag.GetTitle().IsEmpty())
m_tag.SetTitle(m_file.GetHttpHeader().GetValue("ice-name")); // icecast
m_tag.SetGenre(m_file.GetHttpHeader().GetValue("icy-genre"));
if (m_tag.GetGenre().IsEmpty())
m_tag.SetGenre(m_file.GetHttpHeader().GetValue("ice-genre")); // icecast
m_tag.SetLoaded(true);
g_infoManager.SetCurrentSongTag(m_tag);
}
m_metaint = atoi(m_file.GetHttpHeader().GetValue("icy-metaint").c_str());
m_buffer = new char[16*255];
return result;
}
unsigned int CFileShoutcast::Read(void* lpBuf, int64_t uiBufSize)
{
if (m_currint >= m_metaint && m_metaint > 0)
{
unsigned char header;
m_file.Read(&header,1);
ReadTruncated(m_buffer, header*16);
ExtractTagInfo(m_buffer);
m_discarded += header*16+1;
m_currint = 0;
}
if (CTimeUtils::GetTimeMS() - m_lastTime > 500)
{
m_lastTime = CTimeUtils::GetTimeMS();
g_infoManager.SetCurrentSongTag(m_tag);
}
unsigned int toRead = std::min((unsigned int)uiBufSize,(unsigned int)m_metaint-m_currint);
toRead = m_file.Read(lpBuf,toRead);
m_currint += toRead;
return toRead;
}
int64_t CFileShoutcast::Seek(int64_t iFilePosition, int iWhence)
{
return -1;
}
void CFileShoutcast::Close()
{
delete[] m_buffer;
m_file.Close();
}
void CFileShoutcast::ExtractTagInfo(const char* buf)
{
char temp[1024];
if (sscanf(buf,"StreamTitle='%[^']",temp) > 0)
m_tag.SetTitle(temp);
}
void CFileShoutcast::ReadTruncated(char* buf2, int size)
{
char* buf = buf2;
while (size > 0)
{
int read = m_file.Read(buf,size);
size -= read;
buf += read;
}
}