Browse Source

add command line utility, don't fail if read samples don't match info samples

remove_deprecated_ffmpeg_api
Alexandros Theodotou 3 years ago
parent
commit
61c6e00b8e
Signed by: alex
GPG Key ID: 022EAE42313D70F3
  1. 28
      meson.build
  2. 6
      meson_options.txt
  3. 15
      src/ad_plugin.c
  4. 97
      src/main.c
  5. 2
      tests/helper.h
  6. 4
      tests/meson.build
  7. 4
      tests/test.c
  8. BIN
      tests/test.wav

28
meson.build

@ -19,7 +19,7 @@ project ( @@ -19,7 +19,7 @@ project (
'libaudec', ['c'],
version: '0.1.0',
license: 'AGPLv3+',
meson_version: '>= 0.46.0',
meson_version: '>= 0.47.0',
default_options: [
'warning_level=2',
'buildtype=debug',
@ -134,10 +134,19 @@ audec_cflags = cc.get_supported_arguments ( @@ -134,10 +134,19 @@ audec_cflags = cc.get_supported_arguments (
audec_cflags)
audec_deps = []
if (get_option('enable_ffmpeg'))
audec_deps += dependency('libavcodec')
audec_deps += dependency('libavformat')
audec_deps += dependency('libavutil')
libavcodec_dep = dependency (
'libavcodec', required: get_option ('ffmpeg'))
libavformat_dep = dependency (
'libavformat', required: get_option ('ffmpeg'))
libavutil_dep = dependency (
'libavutil', required: get_option ('ffmpeg'))
audec_deps += [
libavcodec_dep,
libavformat_dep,
libavutil_dep,
]
have_ffmpeg = libavcodec_dep.found () and libavformat_dep.found () and libavutil_dep.found () and not get_option ('ffmpeg').disabled ()
if have_ffmpeg
cdata.set('HAVE_FFMPEG', 1)
endif
@ -174,6 +183,7 @@ audec = static_library ( @@ -174,6 +183,7 @@ audec = static_library (
# subproject
libaudec_dep = declare_dependency (
include_directories: inc,
dependencies: audec_deps,
link_with: audec)
if not meson.is_subproject()
@ -187,6 +197,12 @@ if not meson.is_subproject() @@ -187,6 +197,12 @@ if not meson.is_subproject()
)
endif
audec_exe = executable (
'audec',
'src/main.c',
dependencies: libaudec_dep,
)
subdir('tests')
summary = [
@ -197,7 +213,7 @@ summary = [ @@ -197,7 +213,7 @@ summary = [
' Build type: @0@'.format(
get_option('buildtype')),
' Optional libraries:',
' ffmpeg: @0@'.format(get_option('enable_ffmpeg')),
' ffmpeg: @0@'.format(have_ffmpeg),
' Directories:',
' prefix: @0@'.format(prefix),
' includedir: @0@'.format(includedir),

6
meson_options.txt

@ -16,8 +16,8 @@ @@ -16,8 +16,8 @@
# along with libaudec. If not, see <https://www.gnu.org/licenses/>.
option (
'enable_ffmpeg',
type: 'boolean',
value: false,
'ffmpeg',
type: 'feature',
value: 'disabled',
yield: true,
description: 'Compile with ffmpeg (for MP3 support)')

15
src/ad_plugin.c

@ -249,10 +249,19 @@ audec_read ( @@ -249,10 +249,19 @@ audec_read (
if (ret != (ssize_t) in_len)
{
dbg (
AUDEC_DEBUG_LEVEL_ERROR,
AUDEC_DEBUG_LEVEL_DEBUG,
"Number of read in frames %ld not equal to "
"given buf size %ld",
ret, in_len);
}
if (ret > (ssize_t) in_len)
{
dbg (
AUDEC_DEBUG_LEVEL_ERROR,
"Number of read in frames %ld greater than "
"given buf size %ld",
ret, in_len);
free (in);
return -1;
}
@ -378,8 +387,8 @@ audec_read ( @@ -378,8 +387,8 @@ audec_read (
dbg (
AUDEC_DEBUG_LEVEL_INFO,
"No resampling done, returning %ld frames "
"(out buffer size %lu)",
nfo.frames, in_len);
"(out buffer size %zu)",
nfo.frames, ret);
}
return ret;

97
src/main.c

@ -0,0 +1,97 @@ @@ -0,0 +1,97 @@
/*
* Copyright (C) 2020 Alexandros Theodotou <alex at zrythm dot org>
*
* This file is part of libaudec
*
* libaudec is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* libaudec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with libaudec. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ad_plugin.h"
#include "audec/audec.h"
int
main (int argc,
char **argv)
{
if (argc < 2)
{
printf ("Need at least 1 argument\n");
exit (-1);
}
char * command = argv[1];
char * arg2 = NULL;
char * arg3 = NULL;
if (argc > 2)
arg2 = argv[2];
if (argc > 3)
arg3 = argv[3];
audec_init ();
if (!strcmp (command, "info"))
{
if (!arg2)
{
printf ("No file provided\n");
exit (-1);
}
AudecInfo nfo;
AudecHandle * handle =
audec_open (arg2, &nfo);
audec_dump_info (AUDEC_DEBUG_LEVEL_ERROR, &nfo);
int ret = audec_close (handle);
if (ret)
{
printf ("An error occured closing handle\n");
exit (-1);
}
}
if (!strcmp (command, "read"))
{
if (!arg2)
{
printf ("No file provided\n");
exit (-1);
}
if (!arg3)
{
printf ("No samplerate provided\n");
exit (-1);
}
AudecInfo nfo;
AudecHandle * handle =
audec_open (arg2, &nfo);
float * out_frames = NULL;
ssize_t samples_read =
audec_read (
handle, &out_frames, atoi (arg3));
printf ("Samples read: %zu\n", samples_read);
int ret = audec_close (handle);
if (ret)
{
printf ("An error occured closing handle\n");
exit (-1);
}
}
return 0;
}

2
tests/helper.h

@ -21,6 +21,7 @@ @@ -21,6 +21,7 @@
#define __AD_TESTS_HELPER_H__
#include <math.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -32,6 +33,7 @@ @@ -32,6 +33,7 @@
if (!(x)) \
{ \
ad_printf("Assertion failed: %s", #x); \
raise (SIGTRAP); \
exit(1); \
}

4
tests/meson.build

@ -25,9 +25,9 @@ test ( @@ -25,9 +25,9 @@ test (
args: [
join_paths (
meson.current_source_dir(), 'test.wav'),
'48000',
'44000',
])
if (get_option ('enable_ffmpeg'))
if have_ffmpeg
test (
'mp3_test', e,
args: [

4
tests/test.c

@ -34,8 +34,8 @@ int main ( @@ -34,8 +34,8 @@ int main (
unsigned int expected_channels_before = 0;
if (str_endswith (filename, "test.wav"))
{
expected_frames_before = 291583;
expected_sample_rate_before = 44100;
expected_frames_before = 164571;
expected_sample_rate_before = 48000;
expected_channels_before = 2;
}
else if (str_endswith (filename, "test.mp3"))

BIN
tests/test.wav

Binary file not shown.
Loading…
Cancel
Save