[libbluray-devel] sound_dump: use public API
hpi1
git at videolan.org
Wed Oct 9 11:44:31 CEST 2013
libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Wed Oct 9 11:13:29 2013 +0300| [da620fd26b3f98a9a386a932e0673ee27c6ebcc1] | committer: hpi1
sound_dump: use public API
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=da620fd26b3f98a9a386a932e0673ee27c6ebcc1
---
src/examples/Makefile.am | 7 ++--
src/examples/sound_dump.c | 81 ++++++++++++++++++++++-----------------------
2 files changed, 41 insertions(+), 47 deletions(-)
diff --git a/src/examples/Makefile.am b/src/examples/Makefile.am
index bad8499..53371a8 100644
--- a/src/examples/Makefile.am
+++ b/src/examples/Makefile.am
@@ -44,11 +44,8 @@ clpi_dump_SOURCES = \
clpi_dump_LDADD = $(BLURAY_LIB)
sound_dump_SOURCES = \
- sound_dump.c \
- ../util/bits.c \
- ../util/logging.c \
- ../file/file_posix.c \
- ../libbluray/bdnav/sound_parse.c
+ sound_dump.c
+sound_dump_LDADD = $(BLURAY_LIB)
index_dump_SOURCES = \
index_dump.c \
diff --git a/src/examples/sound_dump.c b/src/examples/sound_dump.c
index b89e14a..e0d0bdf 100644
--- a/src/examples/sound_dump.c
+++ b/src/examples/sound_dump.c
@@ -17,58 +17,45 @@
* <http://www.gnu.org/licenses/>.
*/
-#include "libbluray/bdnav/sound_parse.h"
+#include "libbluray/bluray.h"
#include <stdio.h>
#include <stdlib.h>
-static void _sound_print(SOUND_DATA *data)
+static void _sound_print(int sound_index, BLURAY_SOUND_EFFECT *data)
{
- uint32_t i;
-
- printf("Number of sounds: %d\n", data->num_sounds);
-
- for (i = 0; i < data->num_sounds; i++) {
- printf(" Sound %d:\n", i);
- printf(" bits per sample: %d\n", data->sounds[i].bits_per_sample);
- printf(" sample rate: %d\n", data->sounds[i].sample_rate);
- printf(" channels: %d\n", data->sounds[i].num_channels);
- printf(" audio frames: %d", data->sounds[i].num_frames);
- printf(" (%d ms)\n", data->sounds[i].num_frames * 1000 / data->sounds[i].sample_rate);
- }
+ printf(" Sound %d:\n", sound_index);
+ printf(" bits per sample: %d\n", 16);
+ printf(" sample rate: %d\n", 48000);
+ printf(" channels: %d\n", data->num_channels);
+ printf(" audio frames: %d", data->num_frames);
+ printf(" (%d ms)\n", data->num_frames * 1000 / 48000);
}
-static void _sound_dump(SOUND_DATA *data, int sound)
+static void _sound_dump(int sound_index, BLURAY_SOUND_EFFECT *data)
{
size_t bytes;
- if (sound < 0 || sound >= data->num_sounds) {
- fprintf(stderr, "Invalid sound index %d\n", sound);
- return;
- }
-
fprintf(stderr, "Sound %d: %d frames LPCM_LE, %dHz, %d bits, %s\n",
- sound,
- data->sounds[sound].num_frames,
- data->sounds[sound].sample_rate,
- data->sounds[sound].bits_per_sample,
- data->sounds[sound].num_channels == 1 ? "mono" : "stereo");
+ sound_index,
+ data->num_frames,
+ 48000,
+ 16,
+ data->num_channels == 1 ? "mono" : "stereo");
- bytes = data->sounds[sound].bits_per_sample/8 * data->sounds[sound].num_channels;
- bytes *= data->sounds[sound].num_frames;
+ bytes = 2 * data->num_channels * data->num_frames;
- if (fwrite(data->sounds[sound].samples, bytes, 1, stdout) != bytes) {
+ if (fwrite(data->samples, bytes, 1, stdout) != 1) {
fprintf(stderr, "I/O error\n");
}
-
}
int main(int argc, const char *argv[])
{
- char file[1024];
- SOUND_DATA *data;
- int sound_index = -1;
+ BLURAY_SOUND_EFFECT effect;
+ BLURAY *bd;
+ int sound_index = -1;
if (argc < 2 || argc > 3) {
fprintf(stderr, "usage: sound_dump [sound_index] <disc_root>\n");
@@ -80,21 +67,31 @@ int main(int argc, const char *argv[])
sound_index = atoi(argv[1]);
}
- sprintf(file, "%s/BDMV/AUXDATA/sound.bdmv", argv[argc-1]);
-
- data = sound_parse(file);
-
- if (data) {
-
- if (sound_index >= 0) {
- _sound_dump(data, sound_index);
+ /* open disc */
+ bd = bd_open(argv[argc-1], NULL);
+ if (!bd) {
+ fprintf(stderr, "error opening disc %s\n", argv[argc-1]);
+ return -1;
+ }
+ if (sound_index >= 0) {
+ if (bd_get_sound_effect(bd, sound_index, &effect) <= 0) {
+ fprintf(stderr, "Invalid sound index %d\n", sound_index);
} else {
- _sound_print(data);
+ _sound_dump(sound_index, &effect);
}
- sound_free(&data);
+ } else {
+
+ while (bd_get_sound_effect(bd, ++sound_index, &effect) > 0) {
+ _sound_print(sound_index, &effect);
+ }
+ if (sound_index == 0) {
+ fprintf(stderr, "No sound effects\n");
+ }
}
+ bd_close(bd);
+
return 0;
}
More information about the libbluray-devel
mailing list