From: Andre Noll <maan@systemlinux.org>
Date: Sat, 24 Mar 2007 21:20:29 +0000 (+0100)
Subject: ogg_afh.c: store bitrate, frequency and channels in struct audio_file info
X-Git-Tag: v0.2.16~7^2~4
X-Git-Url: https://git.tuebingen.mpg.de/?a=commitdiff_plain;h=86c9ceb46b4299282ea1e5f3fe1aab7a97ef30bc;p=paraslash.git

ogg_afh.c: store bitrate, frequency and channels in struct audio_file info

This patch also contains some other improvements:

	- make sure that we never write beyond the end of the chunk table
	- get rid of some unneeded includes
	- kill pointless raw_total variable
	- get rid of time_total, vi_sampling_rate and vi_bitrate and use
	  the corresponding members of struct audio_file_info directly
---

diff --git a/ogg_afh.c b/ogg_afh.c
index eaed1621..078ff786 100644
--- a/ogg_afh.c
+++ b/ogg_afh.c
@@ -22,9 +22,7 @@
 #include <vorbis/codec.h>
 #include <vorbis/vorbisfile.h>
 
-#include "server.cmdline.h"
 #include "server.h"
-#include "vss.h"
 #include "error.h"
 #include "string.h"
 
@@ -218,10 +216,10 @@ static long unsigned ogg_compute_chunk_table(OggVorbis_File *of,
 	num = time_total / chunk_time + 3;
 	PARA_DEBUG_LOG("chunk time: %g allocating %d chunk pointers\n",
 		chunk_time, num);
-	afi->chunk_table = para_malloc(num * sizeof(size_t));
+	afi->chunk_table = para_malloc((num + 1) * sizeof(size_t));
 	afi->chunk_table[0] = 0;
 	max_chunk_len = 0;
-	for (i = 1; ret == 0; i++) {
+	for (i = 1; ret <= num; i++) {
 		ogg_int64_t diff;
 		ret = ov_time_seek(of, i * chunk_time);
 		if (ret)
@@ -238,7 +236,7 @@ static long unsigned ogg_compute_chunk_table(OggVorbis_File *of,
 		old_pos = pos;
 	}
 	num_chunks = i - 1;
-	afi->chunk_table[i] = pos;
+//fi->chunk_table[i] = pos;
 	PARA_INFO_LOG("%lu chunks (%fs), max chunk: %zd, min chunk: %zd\n",
 		num_chunks, chunk_time, max_chunk_len, min);
 	return num_chunks;
@@ -251,10 +249,7 @@ static int ogg_get_file_info(char *map, off_t numbytes,
 		struct audio_format_info *afi)
 {
 	int ret;
-	double time_total;
 	vorbis_info *vi;
-	ogg_int64_t raw_total;
-	long vi_sampling_rate, vi_bitrate;
 	OggVorbis_File of;
 	const ov_callbacks ovc = {
 		.read_func = cb_read,
@@ -274,18 +269,17 @@ static int ogg_get_file_info(char *map, off_t numbytes,
 	vi = ov_info(&of, 0);
 	if (!vi)
 		goto err;
-	time_total = ov_time_total(&of, -1);
-	raw_total = ov_raw_total(&of, -1);
-	afi->seconds_total = time_total;
-	vi_sampling_rate = vi->rate;
-	vi_bitrate = ov_bitrate(&of, 0);
-	afi->chunks_total = ogg_compute_chunk_table(&of, afi, time_total);
-	sprintf(afi->info_string, "audio_file_info1:%lu x %lu, %ldkHz, "
-		"%d channels, %ldkbps\n"
+	afi->seconds_total = ov_time_total(&of, -1);
+	afi->frequency = vi->rate;
+	afi->bitrate = ov_bitrate(&of, 0);
+	afi->channels = vi->channels;
+	afi->chunks_total = ogg_compute_chunk_table(&of, afi, afi->seconds_total);
+	sprintf(afi->info_string, "audio_file_info1:%lu x %lu, %ukHz, "
+		"%d channels, %ukbps\n"
 		"audio_file_info2: \n"
 		"audio_file_info3: \n",
 		afi->chunks_total, (long unsigned) (chunk_time * 1000 * 1000),
-		vi_sampling_rate / 1000, vi->channels, vi_bitrate / 1000
+		afi->frequency / 1000, vi->channels, afi->bitrate / 1000
 		);
 	afi->chunk_tv.tv_sec = 0;
 	afi->chunk_tv.tv_usec = 250 * 1000;