Commit 76417d44 authored by Max Kellermann's avatar Max Kellermann

InputStream: use std::string

parent cffc78ad
......@@ -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;
......
......@@ -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
......
......@@ -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)
......
......@@ -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;
......
......@@ -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;
......
......@@ -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",
......
......@@ -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;
}
};
......
......@@ -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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment