mirror of
https://github.com/alexkay/spek.git
synced 2025-04-22 03:10:29 +03:00
Show decoding errors
This commit is contained in:
parent
a63571d6dd
commit
fd236e4b1a
@ -1,3 +1,7 @@
|
||||
[encoding: UTF-8]
|
||||
data/spek.desktop.in.in
|
||||
src/spek.vala
|
||||
src/spek-audio.c
|
||||
src/spek-pipeline.vala
|
||||
src/spek-spectrogram.vala
|
||||
src/spek-window.vala
|
||||
|
@ -1,4 +1,5 @@
|
||||
data/spek.desktop.in
|
||||
src/spek.c
|
||||
src/spek-pipeline.c
|
||||
src/spek-spectrogram.c
|
||||
src/spek-window.c
|
||||
|
@ -16,6 +16,8 @@
|
||||
* along with Spek. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "spek-audio.h"
|
||||
|
||||
void spek_audio_init () {
|
||||
@ -31,16 +33,15 @@ SpekAudioContext * spek_audio_open (const char *file_name) {
|
||||
cx->file_name = g_strdup (file_name);
|
||||
|
||||
if (av_open_input_file (&cx->format_context, file_name, NULL, 0, NULL) != 0) {
|
||||
/* TODO
|
||||
*/
|
||||
printf ("cannot open\n");
|
||||
cx->error = _("Cannot open input file");
|
||||
return cx;
|
||||
}
|
||||
if (av_find_stream_info (cx->format_context) < 0) {
|
||||
/* TODO
|
||||
*/
|
||||
printf ("cannot find stream info\n");
|
||||
return cx;
|
||||
/* 24-bit APE returns an error but parses the stream info just fine */
|
||||
if (cx->format_context->nb_streams <= 0) {
|
||||
cx->error = _("Cannot find stream info");
|
||||
return cx;
|
||||
}
|
||||
}
|
||||
cx->audio_stream = -1;
|
||||
for (i = 0; i < cx->format_context->nb_streams; i++) {
|
||||
@ -50,25 +51,16 @@ SpekAudioContext * spek_audio_open (const char *file_name) {
|
||||
}
|
||||
}
|
||||
if (cx->audio_stream == -1) {
|
||||
/* TODO
|
||||
*/
|
||||
printf ("no audio streams\n");
|
||||
cx->error = _("The file contains no audio streams");
|
||||
return cx;
|
||||
}
|
||||
cx->codec_context = cx->format_context->streams[cx->audio_stream]->codec;
|
||||
cx->codec = avcodec_find_decoder (cx->codec_context->codec_id);
|
||||
if (cx->codec == NULL) {
|
||||
/* TODO
|
||||
*/
|
||||
printf ("cannot find decoder\n");
|
||||
return cx;
|
||||
}
|
||||
if (avcodec_open (cx->codec_context, cx->codec) < 0) {
|
||||
/* TODO
|
||||
*/
|
||||
printf ("cannot open decoder\n");
|
||||
cx->error = _("Cannot find decoder");
|
||||
return cx;
|
||||
}
|
||||
/* We can already fill in the stream info even if the codec won't be able to open it */
|
||||
cx->codec_name = g_strdup (cx->codec->long_name);
|
||||
cx->bit_rate = cx->codec_context->bit_rate;
|
||||
cx->sample_rate = cx->codec_context->sample_rate;
|
||||
@ -78,6 +70,10 @@ SpekAudioContext * spek_audio_open (const char *file_name) {
|
||||
cx->bits_per_sample = cx->codec_context->bits_per_coded_sample;
|
||||
}
|
||||
cx->channels = cx->codec_context->channels;
|
||||
if (avcodec_open (cx->codec_context, cx->codec) < 0) {
|
||||
cx->error = _("Cannot open decoder");
|
||||
return cx;
|
||||
}
|
||||
return cx;
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@ typedef struct {
|
||||
*/
|
||||
gchar *file_name;
|
||||
gchar *codec_name;
|
||||
gchar *error;
|
||||
gint bit_rate;
|
||||
gint sample_rate;
|
||||
gint bits_per_sample;
|
||||
|
@ -22,7 +22,6 @@ namespace Spek {
|
||||
public string description { get; private set; }
|
||||
|
||||
public Pipeline (string file_name) {
|
||||
// TODO: check for errors
|
||||
cx = new Audio.Context (file_name);
|
||||
|
||||
// Build the description string.
|
||||
@ -46,6 +45,11 @@ namespace Spek {
|
||||
printf (cx.channels);
|
||||
}
|
||||
description = items.length > 0 ? string.joinv (", ", items) : "";
|
||||
|
||||
if (cx.error != null) {
|
||||
// TRANSLATORS: first %s is the error message, second %s is stream description.
|
||||
description = _("%s: %s").printf (cx.error, description);
|
||||
}
|
||||
}
|
||||
|
||||
public string file_name {
|
||||
|
@ -5,6 +5,7 @@ namespace Spek.Audio {
|
||||
public class Context {
|
||||
public string file_name;
|
||||
public string codec_name;
|
||||
public string error;
|
||||
public int bit_rate;
|
||||
public int sample_rate;
|
||||
public int bits_per_sample;
|
||||
|
Loading…
x
Reference in New Issue
Block a user