Skip to content
Snippets Groups Projects
Commit 1439f6c3 authored by ale's avatar ale
Browse files

fix metadata extraction of .ogg files

Includes metadata extraction tests for a few supported file
formats (mp3, ogg, flac).
parent 1a2a061e
No related branches found
No related tags found
No related merge requests found
...@@ -426,7 +426,11 @@ void audecode_dump_metadata(audecode_t p) { ...@@ -426,7 +426,11 @@ void audecode_dump_metadata(audecode_t p) {
audecode_metadata_iterator_t audecode_get_metadata(audecode_t p) { audecode_metadata_iterator_t audecode_get_metadata(audecode_t p) {
audecode_metadata_iterator_t mdi = (audecode_metadata_iterator_t)malloc(sizeof(struct audecode_metadata_iterator)); audecode_metadata_iterator_t mdi = (audecode_metadata_iterator_t)malloc(sizeof(struct audecode_metadata_iterator));
mdi->p = p; mdi->p = p;
if (p->fmt->metadata && av_dict_count(p->fmt->metadata) > 0) {
mdi->meta = p->fmt->metadata; mdi->meta = p->fmt->metadata;
} else {
mdi->meta = p->stream->metadata;
}
mdi->entry = NULL; mdi->entry = NULL;
return mdi; return mdi;
} }
......
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
#include "audecode.h" #include "audecode.h"
#include "test_lib.h" #include "test_lib.h"
static char input_file[4096];
void decode_input(int sample_rate, int channels, int bytes_per_sample, uint8_t **obuf, int *osz) { void decode_input(int sample_rate, int channels, int bytes_per_sample, uint8_t **obuf, int *osz) {
audecode_t p; audecode_t p;
struct fdctx ctx; struct fdctx ctx;
...@@ -23,10 +21,10 @@ void decode_input(int sample_rate, int channels, int bytes_per_sample, uint8_t * ...@@ -23,10 +21,10 @@ void decode_input(int sample_rate, int channels, int bytes_per_sample, uint8_t *
*osz = 0; *osz = 0;
read_bytes = 0; read_bytes = 0;
ctx.fd = open(input_file, O_RDONLY); ctx.fd = open(path_of(TEST_INPUT), O_RDONLY);
r = audecode_new(&p, 4096, &my_read_cb, (void *)&ctx); r = audecode_new(&p, 4096, &my_read_cb, (void *)&ctx);
if (r < 0) { if (r < 0) {
die(r); die("audecode_new", r);
} }
audecode_set_output_params(p, sample_rate, channels, bytes_per_sample); audecode_set_output_params(p, sample_rate, channels, bytes_per_sample);
...@@ -186,35 +184,36 @@ int test_codec_params() { ...@@ -186,35 +184,36 @@ int test_codec_params() {
const char *codec = NULL; const char *codec = NULL;
int bit_rate = 0; int bit_rate = 0;
struct fdctx ctx; struct fdctx ctx;
int r; int r, ret = 0;
ctx.fd = open(input_file, O_RDONLY); ctx.fd = open(path_of(TEST_INPUT), O_RDONLY);
r = audecode_new(&p, 4096, &my_read_cb, (void *)&ctx); r = audecode_new(&p, 4096, &my_read_cb, (void *)&ctx);
if (r < 0) { if (r < 0) {
die(r); die("audecode_new", r);
} }
audecode_get_input_codec_params(p, &codec, &bit_rate); audecode_get_input_codec_params(p, &codec, &bit_rate);
if (codec == NULL) { if (codec == NULL) {
fprintf(stdout, "ERROR: 'codec' is empty\n"); fprintf(stdout, "ERROR: 'codec' is empty\n");
return 1; ret = 1;
} }
if (strcmp(codec, "flac") != 0) { if (strcmp(codec, "flac") != 0) {
fprintf(stdout, "ERROR: 'codec' is '%s', not 'flac'\n", codec); fprintf(stdout, "ERROR: 'codec' is '%s', not 'flac'\n", codec);
return 1; ret = 1;
} }
if (bit_rate != 0) { if (bit_rate != 0) {
fprintf(stdout, "ERROR: 'bit_rate' is not empty (%d)\n", bit_rate); fprintf(stdout, "ERROR: 'bit_rate' is not empty (%d)\n", bit_rate);
return 1; ret = 1;
} }
return 0;
audecode_close(p);
return ret;
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
int errors = 0; int errors = 0;
sprintf(input_file, "%s/%s", getenv("srcdir"), TEST_INPUT);
audecode_init(); audecode_init();
fprintf(stdout, "test_decode\n"); fprintf(stdout, "test_decode\n");
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#define TEST_NUM_SAMPLES 138526 #define TEST_NUM_SAMPLES 138526
#define TEST_INPUT_SIZE 656450 #define TEST_INPUT_SIZE 656450
#include <string.h>
static int read_bytes; static int read_bytes;
struct fdctx { struct fdctx {
...@@ -21,14 +23,21 @@ static int my_read_cb(void *opaque, uint8_t *buf, int buf_size) { ...@@ -21,14 +23,21 @@ static int my_read_cb(void *opaque, uint8_t *buf, int buf_size) {
} }
} }
void die(int error) { void die(const char *tag, int error) {
char errbuf[256]; char errbuf[256];
audecode_strerror(error, errbuf, sizeof(errbuf)); audecode_strerror(error, errbuf, sizeof(errbuf));
fprintf(stderr, "TEST ERROR: %s\n", errbuf); fprintf(stderr, "TEST ERROR: %s: %s\n", tag, errbuf);
exit(1); exit(1);
} }
void die_msg(char *s) { void die_msg(const char *s) {
fprintf(stderr, "TEST ERROR: %s\n", s); fprintf(stderr, "TEST ERROR: %s\n", s);
exit(1); exit(1);
} }
char *path_of(const char *base) {
char *srcdir = getenv("srcdir");
char *out = (char *)malloc(2 + strlen(srcdir) + strlen(base));
sprintf(out, "%s/%s", srcdir, base);
return out;
}
...@@ -17,10 +17,10 @@ int test_read_artist(char *input_file) { ...@@ -17,10 +17,10 @@ int test_read_artist(char *input_file) {
struct fdctx ctx; struct fdctx ctx;
int r, count = 0; int r, count = 0;
ctx.fd = open(input_file, O_RDONLY); ctx.fd = open(path_of(input_file), O_RDONLY);
r = audecode_new(&p, 4096, &my_read_cb, (void *)&ctx); r = audecode_new(&p, 4096, &my_read_cb, (void *)&ctx);
if (r < 0) { if (r < 0) {
die(r); die("audecode_new", r);
} }
mdi = audecode_get_metadata(p); mdi = audecode_get_metadata(p);
...@@ -45,11 +45,56 @@ int test_read_artist(char *input_file) { ...@@ -45,11 +45,56 @@ int test_read_artist(char *input_file) {
die_msg("read too much metadata"); die_msg("read too much metadata");
} }
audecode_close(p);
return 0;
}
int test_read_any_meta(char *input_file) {
audecode_t p;
audecode_metadata_iterator_t mdi;
char *key, *value;
struct fdctx ctx;
int r, count = 0;
ctx.fd = open(path_of(input_file), O_RDONLY);
r = audecode_new(&p, 4096, &my_read_cb, (void *)&ctx);
if (r < 0) {
die("audecode_new", r);
}
mdi = audecode_get_metadata(p);
if (mdi == NULL) {
fprintf(stderr, "ERROR: audecode_get_metadata(%s) returned NULL\n", input_file);
return 1;
}
while (0 == audecode_metadata_next(mdi, &key, &value)) {
fprintf(stderr, "md: %s = %s\n", key, value);
count++;
}
if (count == 0) {
fprintf(stdout, "ERROR: found no metadata in %s\n", input_file);
audecode_dump_metadata(p);
return 1;
}
audecode_close(p);
return 0; return 0;
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
int errors = 0;
audecode_init(); audecode_init();
return test_read_artist(TEST_INPUT); fprintf(stdout, "test_read_artist\n");
errors += test_read_artist(TEST_INPUT);
fprintf(stdout, "test_read_any_meta\n");
errors += test_read_any_meta("testdata/meta1.mp3");
errors += test_read_any_meta("testdata/meta1.flac");
errors += test_read_any_meta("testdata/meta1.ogg");
return (errors > 0) ? 1 : 0;
} }
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment