InputStream.cxx 2.4 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2014 The Music Player Daemon Project
3
 * http://www.musicpd.org
4 5 6 7 8 9 10 11 12 13
 *
 * 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 of the License, 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.
14 15 16 17
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 19
 */

Max Kellermann's avatar
Max Kellermann committed
20
#include "config.h"
21
#include "InputStream.hxx"
22
#include "thread/Cond.hxx"
23
#include "util/StringUtil.hxx"
24

25
#include <assert.h>
26

27 28 29 30
InputStream::~InputStream()
{
}

31
bool
32
InputStream::Check(gcc_unused Error &error)
33
{
34
	return true;
35 36
}

37
void
38
InputStream::Update()
39 40 41
{
}

42 43 44 45 46 47 48 49 50
void
InputStream::SetReady()
{
	assert(!ready);

	ready = true;
	cond.broadcast();
}

51
void
52
InputStream::WaitReady()
53 54
{
	while (true) {
55 56
		Update();
		if (ready)
57 58
			break;

59
		cond.wait(mutex);
60 61 62 63
	}
}

void
64
InputStream::LockWaitReady()
65
{
66 67
	const ScopeLock protect(mutex);
	WaitReady();
68 69
}

70 71 72 73 74 75 76 77 78
/**
 * Is seeking on resources behind this URI "expensive"?  For example,
 * seeking in a HTTP file requires opening a new connection with a new
 * HTTP request.
 */
gcc_pure
static bool
ExpensiveSeeking(const char *uri)
{
79 80
	return StringStartsWith(uri, "http://") ||
		StringStartsWith(uri, "https://");
81 82
}

83
bool
84
InputStream::CheapSeeking() const
85
{
86
	return IsSeekable() && !ExpensiveSeeking(uri.c_str());
87 88
}

89
bool
90
InputStream::Seek(gcc_unused offset_type new_offset,
91
		  gcc_unused Error &error)
Avuton Olrich's avatar
Avuton Olrich committed
92
{
93
	return false;
94 95
}

96
bool
97
InputStream::LockSeek(offset_type _offset, Error &error)
98
{
99
	const ScopeLock protect(mutex);
100
	return Seek(_offset, error);
101 102
}

Max Kellermann's avatar
Max Kellermann committed
103
Tag *
104
InputStream::ReadTag()
105
{
106
	return nullptr;
107 108
}

Max Kellermann's avatar
Max Kellermann committed
109
Tag *
110
InputStream::LockReadTag()
111
{
112 113
	const ScopeLock protect(mutex);
	return ReadTag();
114 115 116
}

bool
117
InputStream::IsAvailable()
118
{
119
	return true;
120 121
}

122
size_t
123
InputStream::LockRead(void *ptr, size_t _size, Error &error)
124
{
125
	assert(ptr != nullptr);
126
	assert(_size > 0);
127

128 129
	const ScopeLock protect(mutex);
	return Read(ptr, _size, error);
130 131 132
}

bool
133
InputStream::LockIsEOF()
Avuton Olrich's avatar
Avuton Olrich committed
134
{
135 136
	const ScopeLock protect(mutex);
	return IsEOF();
137
}
138