aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-28 23:41:45 +0100
committerMax Kellermann <max@duempel.org>2013-01-28 23:41:45 +0100
commit76417d44464248949e7843eee0d5338a8e0a22ac (patch)
treec8f6416505b7268ce4f3902660ba35f4e35d1c04
parentcffc78ad6a978c8ef0afae4fbdd4b189612a7167 (diff)
downloadmpd-76417d44464248949e7843eee0d5338a8e0a22ac.tar.gz
mpd-76417d44464248949e7843eee0d5338a8e0a22ac.tar.xz
mpd-76417d44464248949e7843eee0d5338a8e0a22ac.zip
InputStream: use std::string
-rw-r--r--src/DecoderThread.cxx5
-rw-r--r--src/InputStream.cxx7
-rw-r--r--src/InputStream.hxx21
-rw-r--r--src/decoder/FfmpegDecoderPlugin.cxx7
-rw-r--r--src/decoder/WavpackDecoderPlugin.cxx3
-rw-r--r--src/input/CurlInputPlugin.cxx5
-rw-r--r--src/input/RewindInputPlugin.cxx10
-rw-r--r--test/run_input.cxx4
8 files changed, 27 insertions, 35 deletions
diff --git a/src/DecoderThread.cxx b/src/DecoderThread.cxx
index 67054cbc9..ac89b54ca 100644
--- a/src/DecoderThread.cxx
+++ b/src/DecoderThread.cxx
@@ -202,10 +202,11 @@ decoder_run_stream_mime_type(struct decoder *decoder, struct input_stream *is,
const struct decoder_plugin *plugin;
unsigned int next = 0;
- if (is->mime == NULL)
+ if (is->mime.empty())
return false;
- while ((plugin = decoder_plugin_from_mime_type(is->mime, next++))) {
+ while ((plugin = decoder_plugin_from_mime_type(is->mime.c_str(),
+ next++))) {
if (plugin->stream_decode == NULL)
continue;
diff --git a/src/InputStream.cxx b/src/InputStream.cxx
index ef77a468d..913fcf637 100644
--- a/src/InputStream.cxx
+++ b/src/InputStream.cxx
@@ -115,7 +115,7 @@ input_stream_get_mime_type(const struct input_stream *is)
assert(is != NULL);
assert(is->ready);
- return is->mime;
+ return is->mime.empty() ? nullptr : is->mime.c_str();
}
void
@@ -124,8 +124,7 @@ input_stream_override_mime_type(struct input_stream *is, const char *mime)
assert(is != NULL);
assert(is->ready);
- g_free(is->mime);
- is->mime = g_strdup(mime);
+ is->mime = mime;
}
goffset
@@ -158,7 +157,7 @@ input_stream_is_seekable(const struct input_stream *is)
bool
input_stream_cheap_seeking(const struct input_stream *is)
{
- return is->seekable && (is->uri == NULL || !uri_has_scheme(is->uri));
+ return is->seekable && !uri_has_scheme(is->uri.c_str());
}
bool
diff --git a/src/InputStream.hxx b/src/InputStream.hxx
index 32940fd96..96172723a 100644
--- a/src/InputStream.hxx
+++ b/src/InputStream.hxx
@@ -26,7 +26,7 @@
#include "thread/Cond.hxx"
#include "gcc.h"
-#include <glib.h>
+#include <string>
#include <assert.h>
@@ -37,10 +37,9 @@ struct input_stream {
const struct input_plugin &plugin;
/**
- * The absolute URI which was used to open this stream. May
- * be NULL if this is unknown.
+ * The absolute URI which was used to open this stream.
*/
- char *uri;
+ std::string uri;
/**
* A mutex that protects the mutable attributes of this object
@@ -84,24 +83,18 @@ struct input_stream {
goffset offset;
/**
- * the MIME content type of the resource, or NULL if unknown
+ * the MIME content type of the resource, or empty if unknown.
*/
- char *mime;
+ std::string mime;
input_stream(const input_plugin &_plugin,
const char *_uri, Mutex &_mutex, Cond &_cond)
- :plugin(_plugin), uri(g_strdup(_uri)),
+ :plugin(_plugin), uri(_uri),
mutex(_mutex), cond(_cond),
ready(false), seekable(false),
- size(-1), offset(0),
- mime(nullptr) {
+ size(-1), offset(0) {
assert(_uri != NULL);
}
-
- ~input_stream() {
- g_free(uri);
- g_free(mime);
- }
};
gcc_nonnull(1)
diff --git a/src/decoder/FfmpegDecoderPlugin.cxx b/src/decoder/FfmpegDecoderPlugin.cxx
index e40813775..dd98b9686 100644
--- a/src/decoder/FfmpegDecoderPlugin.cxx
+++ b/src/decoder/FfmpegDecoderPlugin.cxx
@@ -395,7 +395,7 @@ ffmpeg_probe(struct decoder *decoder, struct input_stream *is)
AVProbeData avpd;
avpd.buf = buffer;
avpd.buf_size = nbytes;
- avpd.filename = is->uri;
+ avpd.filename = is->uri.c_str();
AVInputFormat *format = av_probe_input_format(&avpd, true);
g_free(buffer);
@@ -422,7 +422,8 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
//ffmpeg works with ours "fileops" helper
AVFormatContext *format_context = NULL;
- if (mpd_ffmpeg_open_input(&format_context, stream->io, input->uri,
+ if (mpd_ffmpeg_open_input(&format_context, stream->io,
+ input->uri.c_str(),
input_format) != 0) {
g_warning("Open failed\n");
mpd_ffmpeg_stream_close(stream);
@@ -581,7 +582,7 @@ ffmpeg_scan_stream(struct input_stream *is,
return false;
AVFormatContext *f = NULL;
- if (mpd_ffmpeg_open_input(&f, stream->io, is->uri,
+ if (mpd_ffmpeg_open_input(&f, stream->io, is->uri.c_str(),
input_format) != 0) {
mpd_ffmpeg_stream_close(stream);
return false;
diff --git a/src/decoder/WavpackDecoderPlugin.cxx b/src/decoder/WavpackDecoderPlugin.cxx
index b7348e218..bac62d429 100644
--- a/src/decoder/WavpackDecoderPlugin.cxx
+++ b/src/decoder/WavpackDecoderPlugin.cxx
@@ -517,7 +517,8 @@ wavpack_streamdecode(struct decoder * decoder, struct input_stream *is)
struct wavpack_input isp, isp_wvc;
bool can_seek = is->seekable;
- is_wvc = wavpack_open_wvc(decoder, is->uri, is->mutex, is->cond,
+ is_wvc = wavpack_open_wvc(decoder, is->uri.c_str(),
+ is->mutex, is->cond,
&isp_wvc);
if (is_wvc != NULL) {
open_flags |= OPEN_WVC;
diff --git a/src/input/CurlInputPlugin.cxx b/src/input/CurlInputPlugin.cxx
index f3edf1dc8..550bcd0ce 100644
--- a/src/input/CurlInputPlugin.cxx
+++ b/src/input/CurlInputPlugin.cxx
@@ -925,8 +925,7 @@ input_curl_headerfunction(void *ptr, size_t size, size_t nmemb, void *stream)
c->base.size = c->base.offset + g_ascii_strtoull(buffer, NULL, 10);
} else if (g_ascii_strcasecmp(name, "content-type") == 0) {
- g_free(c->base.mime);
- c->base.mime = g_strndup(value, end - value);
+ c->base.mime.assign(value, end);
} else if (g_ascii_strcasecmp(name, "icy-name") == 0 ||
g_ascii_strcasecmp(name, "ice-name") == 0 ||
g_ascii_strcasecmp(name, "x-audiocast-name") == 0) {
@@ -1031,7 +1030,7 @@ input_curl_easy_init(struct input_curl *c, GError **error_r)
g_free(proxy_auth_str);
}
- code = curl_easy_setopt(c->easy, CURLOPT_URL, c->base.uri);
+ code = curl_easy_setopt(c->easy, CURLOPT_URL, c->base.uri.c_str());
if (code != CURLE_OK) {
g_set_error(error_r, curl_quark(), code,
"curl_easy_setopt() failed: %s",
diff --git a/src/input/RewindInputPlugin.cxx b/src/input/RewindInputPlugin.cxx
index 362e55b3f..207d9ff0f 100644
--- a/src/input/RewindInputPlugin.cxx
+++ b/src/input/RewindInputPlugin.cxx
@@ -61,7 +61,7 @@ struct RewindInputStream {
char buffer[64 * 1024];
RewindInputStream(input_stream *_input)
- :base(rewind_input_plugin, _input->uri,
+ :base(rewind_input_plugin, _input->uri.c_str(),
_input->mutex, _input->cond),
input(_input), tail(0) {
}
@@ -89,7 +89,7 @@ struct RewindInputStream {
const struct input_stream *src = input;
assert(dest != src);
- assert(src->mime == NULL || dest->mime != src->mime);
+ assert(src->mime.empty() || dest->mime != src->mime);
bool dest_ready = dest->ready;
@@ -98,10 +98,8 @@ struct RewindInputStream {
dest->size = src->size;
dest->offset = src->offset;
- if (!dest_ready && src->ready) {
- g_free(dest->mime);
- dest->mime = g_strdup(src->mime);
- }
+ if (!dest_ready && src->ready)
+ dest->mime = src->mime;
}
};
diff --git a/test/run_input.cxx b/test/run_input.cxx
index db3e4dc80..157613dbc 100644
--- a/test/run_input.cxx
+++ b/test/run_input.cxx
@@ -69,8 +69,8 @@ dump_input_stream(struct input_stream *is)
/* print meta data */
- if (is->mime != NULL)
- g_printerr("MIME type: %s\n", is->mime);
+ if (!is->mime.empty())
+ g_printerr("MIME type: %s\n", is->mime.c_str());
/* read data and tags from the stream */