InputStream: use std::string
This commit is contained in:
parent
cffc78ad6a
commit
76417d4446
@ -202,10 +202,11 @@ decoder_run_stream_mime_type(struct decoder *decoder, struct input_stream *is,
|
|||||||
const struct decoder_plugin *plugin;
|
const struct decoder_plugin *plugin;
|
||||||
unsigned int next = 0;
|
unsigned int next = 0;
|
||||||
|
|
||||||
if (is->mime == NULL)
|
if (is->mime.empty())
|
||||||
return false;
|
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)
|
if (plugin->stream_decode == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ input_stream_get_mime_type(const struct input_stream *is)
|
|||||||
assert(is != NULL);
|
assert(is != NULL);
|
||||||
assert(is->ready);
|
assert(is->ready);
|
||||||
|
|
||||||
return is->mime;
|
return is->mime.empty() ? nullptr : is->mime.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -124,8 +124,7 @@ input_stream_override_mime_type(struct input_stream *is, const char *mime)
|
|||||||
assert(is != NULL);
|
assert(is != NULL);
|
||||||
assert(is->ready);
|
assert(is->ready);
|
||||||
|
|
||||||
g_free(is->mime);
|
is->mime = mime;
|
||||||
is->mime = g_strdup(mime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
goffset
|
goffset
|
||||||
@ -158,7 +157,7 @@ input_stream_is_seekable(const struct input_stream *is)
|
|||||||
bool
|
bool
|
||||||
input_stream_cheap_seeking(const struct input_stream *is)
|
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
|
bool
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#include "thread/Cond.hxx"
|
#include "thread/Cond.hxx"
|
||||||
#include "gcc.h"
|
#include "gcc.h"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <string>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
@ -37,10 +37,9 @@ struct input_stream {
|
|||||||
const struct input_plugin &plugin;
|
const struct input_plugin &plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The absolute URI which was used to open this stream. May
|
* The absolute URI which was used to open this stream.
|
||||||
* be NULL if this is unknown.
|
|
||||||
*/
|
*/
|
||||||
char *uri;
|
std::string uri;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mutex that protects the mutable attributes of this object
|
* A mutex that protects the mutable attributes of this object
|
||||||
@ -84,24 +83,18 @@ struct input_stream {
|
|||||||
goffset offset;
|
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,
|
input_stream(const input_plugin &_plugin,
|
||||||
const char *_uri, Mutex &_mutex, Cond &_cond)
|
const char *_uri, Mutex &_mutex, Cond &_cond)
|
||||||
:plugin(_plugin), uri(g_strdup(_uri)),
|
:plugin(_plugin), uri(_uri),
|
||||||
mutex(_mutex), cond(_cond),
|
mutex(_mutex), cond(_cond),
|
||||||
ready(false), seekable(false),
|
ready(false), seekable(false),
|
||||||
size(-1), offset(0),
|
size(-1), offset(0) {
|
||||||
mime(nullptr) {
|
|
||||||
assert(_uri != NULL);
|
assert(_uri != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
~input_stream() {
|
|
||||||
g_free(uri);
|
|
||||||
g_free(mime);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
gcc_nonnull(1)
|
gcc_nonnull(1)
|
||||||
|
@ -395,7 +395,7 @@ ffmpeg_probe(struct decoder *decoder, struct input_stream *is)
|
|||||||
AVProbeData avpd;
|
AVProbeData avpd;
|
||||||
avpd.buf = buffer;
|
avpd.buf = buffer;
|
||||||
avpd.buf_size = nbytes;
|
avpd.buf_size = nbytes;
|
||||||
avpd.filename = is->uri;
|
avpd.filename = is->uri.c_str();
|
||||||
|
|
||||||
AVInputFormat *format = av_probe_input_format(&avpd, true);
|
AVInputFormat *format = av_probe_input_format(&avpd, true);
|
||||||
g_free(buffer);
|
g_free(buffer);
|
||||||
@ -422,7 +422,8 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
|
|||||||
|
|
||||||
//ffmpeg works with ours "fileops" helper
|
//ffmpeg works with ours "fileops" helper
|
||||||
AVFormatContext *format_context = NULL;
|
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) {
|
input_format) != 0) {
|
||||||
g_warning("Open failed\n");
|
g_warning("Open failed\n");
|
||||||
mpd_ffmpeg_stream_close(stream);
|
mpd_ffmpeg_stream_close(stream);
|
||||||
@ -581,7 +582,7 @@ ffmpeg_scan_stream(struct input_stream *is,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
AVFormatContext *f = NULL;
|
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) {
|
input_format) != 0) {
|
||||||
mpd_ffmpeg_stream_close(stream);
|
mpd_ffmpeg_stream_close(stream);
|
||||||
return false;
|
return false;
|
||||||
|
@ -517,7 +517,8 @@ wavpack_streamdecode(struct decoder * decoder, struct input_stream *is)
|
|||||||
struct wavpack_input isp, isp_wvc;
|
struct wavpack_input isp, isp_wvc;
|
||||||
bool can_seek = is->seekable;
|
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);
|
&isp_wvc);
|
||||||
if (is_wvc != NULL) {
|
if (is_wvc != NULL) {
|
||||||
open_flags |= OPEN_WVC;
|
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);
|
c->base.size = c->base.offset + g_ascii_strtoull(buffer, NULL, 10);
|
||||||
} else if (g_ascii_strcasecmp(name, "content-type") == 0) {
|
} else if (g_ascii_strcasecmp(name, "content-type") == 0) {
|
||||||
g_free(c->base.mime);
|
c->base.mime.assign(value, end);
|
||||||
c->base.mime = g_strndup(value, end - value);
|
|
||||||
} else if (g_ascii_strcasecmp(name, "icy-name") == 0 ||
|
} else if (g_ascii_strcasecmp(name, "icy-name") == 0 ||
|
||||||
g_ascii_strcasecmp(name, "ice-name") == 0 ||
|
g_ascii_strcasecmp(name, "ice-name") == 0 ||
|
||||||
g_ascii_strcasecmp(name, "x-audiocast-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);
|
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) {
|
if (code != CURLE_OK) {
|
||||||
g_set_error(error_r, curl_quark(), code,
|
g_set_error(error_r, curl_quark(), code,
|
||||||
"curl_easy_setopt() failed: %s",
|
"curl_easy_setopt() failed: %s",
|
||||||
|
@ -61,7 +61,7 @@ struct RewindInputStream {
|
|||||||
char buffer[64 * 1024];
|
char buffer[64 * 1024];
|
||||||
|
|
||||||
RewindInputStream(input_stream *_input)
|
RewindInputStream(input_stream *_input)
|
||||||
:base(rewind_input_plugin, _input->uri,
|
:base(rewind_input_plugin, _input->uri.c_str(),
|
||||||
_input->mutex, _input->cond),
|
_input->mutex, _input->cond),
|
||||||
input(_input), tail(0) {
|
input(_input), tail(0) {
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ struct RewindInputStream {
|
|||||||
const struct input_stream *src = input;
|
const struct input_stream *src = input;
|
||||||
|
|
||||||
assert(dest != src);
|
assert(dest != src);
|
||||||
assert(src->mime == NULL || dest->mime != src->mime);
|
assert(src->mime.empty() || dest->mime != src->mime);
|
||||||
|
|
||||||
bool dest_ready = dest->ready;
|
bool dest_ready = dest->ready;
|
||||||
|
|
||||||
@ -98,10 +98,8 @@ struct RewindInputStream {
|
|||||||
dest->size = src->size;
|
dest->size = src->size;
|
||||||
dest->offset = src->offset;
|
dest->offset = src->offset;
|
||||||
|
|
||||||
if (!dest_ready && src->ready) {
|
if (!dest_ready && src->ready)
|
||||||
g_free(dest->mime);
|
dest->mime = src->mime;
|
||||||
dest->mime = g_strdup(src->mime);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -69,8 +69,8 @@ dump_input_stream(struct input_stream *is)
|
|||||||
|
|
||||||
/* print meta data */
|
/* print meta data */
|
||||||
|
|
||||||
if (is->mime != NULL)
|
if (!is->mime.empty())
|
||||||
g_printerr("MIME type: %s\n", is->mime);
|
g_printerr("MIME type: %s\n", is->mime.c_str());
|
||||||
|
|
||||||
/* read data and tags from the stream */
|
/* read data and tags from the stream */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user