* printf -> TRACE (turned off)

* fixed a few compiler warnings


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24475 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2008-03-19 18:49:09 +00:00
parent a08f6a39d8
commit 9b58b8e2d8
2 changed files with 94 additions and 53 deletions
@@ -27,7 +27,7 @@
#include "OpenDMLParser.h"
#include "avi.h"
#define TRACE_ODML_PARSER
//#define TRACE_ODML_PARSER
#ifdef TRACE_ODML_PARSER
#define TRACE printf
#else
@@ -167,9 +167,13 @@ OpenDMLParser::Init()
return B_ERROR;
}
uint32 frame_count = OdmlExtendedHeader() ? OdmlExtendedHeader()->total_frames : AviMainHeader()->total_frames;
bigtime_t duration = frame_count * AviMainHeader()->micro_sec_per_frame;
printf("AVI Header frame count %lu, duration %.6f\n", frame_count, duration / 1E6);
#ifdef TRACE_ODML_PARSER
uint32 frameCount = OdmlExtendedHeader() ?
OdmlExtendedHeader()->total_frames : AviMainHeader()->total_frames;
bigtime_t duration = frameCount * AviMainHeader()->micro_sec_per_frame;
printf("AVI Header frame count %lu, duration %.6f\n", frameCount,
duration / 1E6);
#endif
for (int i = 0; i < fStreamCount; i++) {
SetupStreamLength(const_cast<stream_info *>(StreamInfo(i)));
@@ -197,42 +201,48 @@ OpenDMLParser::SetupAudioStreamLength(stream_info *stream)
&& stream->stream_header.sample_size != 0
&& stream->stream_header.sample_size != 1) { // PCM
stream->frame_count /= (stream->stream_header.sample_size + 7) / 8;
printf("audio: messing up PCM frame_count?\n");
TRACE("audio: messing up PCM frame_count?\n");
}
if (stream->stream_header.rate && stream->stream_header.scale) {
stream->frames_per_sec_rate = stream->stream_header.rate;
stream->frames_per_sec_scale = stream->stream_header.scale;
stream->duration = (stream->frame_count * stream->frames_per_sec_scale * 1000000) / stream->frames_per_sec_rate;
printf("audio: using rate+scale\n");
TRACE("audio: using rate+scale\n");
} else if (stream->audio_format->avg_bytes_per_sec) {
stream->frames_per_sec_rate = stream->audio_format->avg_bytes_per_sec;
stream->frames_per_sec_scale = 1;
stream->duration = (stream->frame_count * stream->frames_per_sec_scale * 1000000) / stream->frames_per_sec_rate;
printf("audio: using avg_bytes_per_sec\n");
TRACE("audio: using avg_bytes_per_sec\n");
} else if (AviMainHeader()->micro_sec_per_frame) {
uint32 video_frame_count = OdmlExtendedHeader() ? OdmlExtendedHeader()->total_frames : AviMainHeader()->total_frames;
stream->duration = video_frame_count * AviMainHeader()->micro_sec_per_frame;
stream->frames_per_sec_rate = (stream->frame_count * 1000 * 1000000) / stream->duration;
stream->frames_per_sec_scale = 1000;
printf("audio: using micro_sec_per_frame\n");
TRACE("audio: using micro_sec_per_frame\n");
} else {
printf("audio: no idea what to do\n");
TRACE("audio: no idea what to do\n");
}
if (stream->audio_format->avg_bytes_per_sec) {
int64 expected_frame_count = (stream->duration * stream->audio_format->avg_bytes_per_sec) / 1000000;
printf("audio: expected frame_count %lld, calculated stream frame_count %lld\n", expected_frame_count, stream->frame_count);
if (expected_frame_count * 9 > stream->frame_count * 10) {
printf("audio: something is wrong, ignoring calculated stream frame_count, rate and scale\n");
stream->frame_count = expected_frame_count;
stream->frames_per_sec_rate = stream->audio_format->avg_bytes_per_sec;
int64 expectedFrameCount
= (stream->duration * stream->audio_format->avg_bytes_per_sec)
/ 1000000;
TRACE("audio: expected frame_count %lld, calculated stream "
"frame_count %lld\n", expectedFrameCount, stream->frame_count);
if (expectedFrameCount * 9 > stream->frame_count * 10) {
TRACE("audio: something is wrong, ignoring calculated stream "
"frame_count, rate and scale\n");
stream->frame_count = expectedFrameCount;
stream->frames_per_sec_rate
= stream->audio_format->avg_bytes_per_sec;
stream->frames_per_sec_scale = 1;
}
}
printf("audio: frame_count %lld, duration %.6f, fps %.3f\n",
stream->frame_count, stream->duration / 1E6, stream->frames_per_sec_rate / (double)stream->frames_per_sec_scale);
TRACE("audio: frame_count %lld, duration %.6f, fps %.3f\n",
stream->frame_count, stream->duration / 1E6,
stream->frames_per_sec_rate / (double)stream->frames_per_sec_scale);
}
void
@@ -242,20 +252,22 @@ OpenDMLParser::SetupVideoStreamLength(stream_info *stream)
if (stream->stream_header.rate && stream->stream_header.scale) {
stream->frames_per_sec_rate = stream->stream_header.rate;
stream->frames_per_sec_scale = stream->stream_header.scale;
printf("video: using rate+scale\n");
TRACE("video: using rate+scale\n");
} else if (AviMainHeader()->micro_sec_per_frame) {
stream->frames_per_sec_rate = 1000000;
stream->frames_per_sec_scale = AviMainHeader()->micro_sec_per_frame;
printf("video: using micro_sec_per_frame\n");
TRACE("video: using micro_sec_per_frame\n");
} else {
stream->frames_per_sec_rate = 25;
stream->frames_per_sec_scale = 1;
printf("video: using fallback\n");
TRACE("video: using fallback\n");
}
stream->duration = (stream->frame_count * stream->frames_per_sec_scale * 1000000) / stream->frames_per_sec_rate;
stream->duration = (stream->frame_count * stream->frames_per_sec_scale
* 1000000) / stream->frames_per_sec_rate;
printf("video: frame_count %lld, duration %.6f, fps %.3f\n",
stream->frame_count, stream->duration / 1E6, stream->frames_per_sec_rate / (double)stream->frames_per_sec_scale);
TRACE("video: frame_count %lld, duration %.6f, fps %.3f\n",
stream->frame_count, stream->duration / 1E6,
stream->frames_per_sec_rate / (double)stream->frames_per_sec_scale);
}
status_t
@@ -33,6 +33,16 @@
#include <StopWatch.h>
//#define TRACE_ODML_PARSER
#ifdef TRACE_ODML_PARSER
#define TRACE printf
#else
#define TRACE(a...)
#endif
#define ERROR(a...) fprintf(stderr, a)
StandardIndex::StandardIndex(BPositionIO *source, OpenDMLParser *parser)
: Index(source, parser)
, fIndex(NULL)
@@ -64,13 +74,15 @@ StandardIndex::Init()
uint32 seekHintsStride = 1800 * fStreamCount;
uint32 seekHintsMax = fIndexSize / seekHintsStride;
printf("StandardIndex::Init: seekHintsStride %lu\n", seekHintsStride);
printf("StandardIndex::Init: seekHintsMax %lu\n", seekHintsMax);
TRACE("StandardIndex::Init: seekHintsStride %lu\n", seekHintsStride);
TRACE("StandardIndex::Init: seekHintsMax %lu\n", seekHintsMax);
{ BStopWatch w("StandardIndex::Init: malloc");
#ifdef TRACE_ODML_PARSER
{ BStopWatch w("StandardIndex::Init: malloc");
#endif
if (indexBytes > 0x1900000) { // 25 MB
printf("StandardIndex::Init index is way too big\n");
ERROR("libOpenDML: StandardIndex::Init index is way too big\n");
return B_NO_MEMORY;
}
@@ -81,21 +93,25 @@ StandardIndex::Init()
fIndex = new (std::nothrow) avi_standard_index_entry[fIndexSize];
if (fIndex == NULL) {
printf("StandardIndex::Init out of memory\n");
ERROR("libOpenDML: StandardIndex::Init out of memory\n");
return B_NO_MEMORY;
}
#ifdef TRACE_ODML_PARSER
}
{ BStopWatch w("StandardIndex::Init: file read");
#endif
if (indexBytes != fSource->ReadAt(fParser->StandardIndexStart(), fIndex, indexBytes)) {
printf("StandardIndex::Init file reading failed\n");
if ((int32)indexBytes != fSource->ReadAt(fParser->StandardIndexStart(),
fIndex, indexBytes)) {
ERROR("libOpenDML: StandardIndex::Init file reading failed\n");
delete [] fIndex;
fIndex = NULL;
return B_IO_ERROR;
}
#ifdef TRACE_ODML_PARSER
}
//DumpIndex();
#endif
fStreamData = new stream_data[fStreamCount];
for (int i = 0; i < fStreamCount; i++) {
@@ -109,16 +125,18 @@ StandardIndex::Init()
fStreamData[i].seek_hints_next = seekHintsStride;
}
#ifdef TRACE_ODML_PARSER
{ BStopWatch w("StandardIndex::Init: scan index");
#endif
for (int stream = 0; stream < fStreamCount; stream++) {
uint32 chunk_id = fStreamData[stream].chunk_id;
uint64 stream_size = 0;
uint32 chunk_count = 0;
uint32 keyframe_count = 0;
int seek_hints_next = seekHintsStride;
int seek_hints_count = 0;
for (int i = 0; i < fIndexSize; i++) {
uint32 seek_hints_next = seekHintsStride;
uint32 seek_hints_count = 0;
for (uint32 i = 0; i < fIndexSize; i++) {
if ((fIndex[i].chunk_id & 0xffff) == chunk_id) {
stream_size += fIndex[i].chunk_length;
chunk_count++;
@@ -126,7 +144,8 @@ StandardIndex::Init()
if (i >= seek_hints_next) {
seek_hints_next = i + seekHintsStride;
seek_hint *hint = &fStreamData[stream].seek_hints[seek_hints_count++];
seek_hint *hint = &fStreamData[stream].seek_hints[
seek_hints_count++];
hint->stream_pos = fIndex[i].chunk_offset;
hint->index_pos = i;
}
@@ -137,19 +156,23 @@ StandardIndex::Init()
fStreamData[stream].keyframe_count = keyframe_count;
fStreamData[stream].seek_hints_count = seek_hints_count;
}
#ifdef TRACE_ODML_PARSER
}
for (int i = 0; i < fStreamCount; i++) {
printf("stream %d, stream_size %llu\n", i, fStreamData[i].stream_size);
printf("stream %d, chunk_count %lu\n", i, fStreamData[i].chunk_count);
printf("stream %d, keyframe_count %lu\n", i, fStreamData[i].keyframe_count);
printf("stream %d, seek_hints_count %lu\n", i, fStreamData[i].seek_hints_count);
printf("stream %d, keyframe_count %lu\n", i,
fStreamData[i].keyframe_count);
printf("stream %d, seek_hints_count %lu\n", i,
fStreamData[i].seek_hints_count);
for (int j = 0; j < fStreamData[i].seek_hints_count; j++) {
printf(" seek_hint %3d, index_pos %6lu, stream_pos %lld\n", j,
fStreamData[i].seek_hints[j].index_pos,
fStreamData[i].seek_hints[j].stream_pos);
}
}
#endif // TRACE_ODML_PARSER
return B_OK;
}
@@ -162,8 +185,8 @@ StandardIndex::DumpIndex()
int count = 0;
int pos = 0;
printf("StandardIndex::DumpIndex %u entries\n", fIndexSize);
for (int i = 0; i < fIndexSize; i++) {
printf("StandardIndex::DumpIndex %lu entries\n", fIndexSize);
for (uint32 i = 0; i < fIndexSize; i++) {
count++;
if (chunk != fIndex[i].chunk_id) {
printf("%3d %c%c%c%c", count, FOURCC_PARAM(chunk));
@@ -180,13 +203,15 @@ StandardIndex::DumpIndex()
status_t
StandardIndex::GetNextChunkInfo(int stream_index, int64 *start, uint32 *size, bool *keyframe)
StandardIndex::GetNextChunkInfo(int stream_index, int64 *start, uint32 *size,
bool *keyframe)
{
stream_data *data = &fStreamData[stream_index];
while (data->stream_pos < fIndexSize) {
if ((fIndex[data->stream_pos].chunk_id & 0xffff) == data->chunk_id) {
*keyframe = fIndex[data->stream_pos].flags & AVIIF_KEYFRAME;
*start = fDataOffset + fIndex[data->stream_pos].chunk_offset + 8; // skip 8 bytes (chunk id + chunk size)
*start = fDataOffset + fIndex[data->stream_pos].chunk_offset + 8;
// skip 8 bytes (chunk id + chunk size)
*size = fIndex[data->stream_pos].chunk_length;
data->stream_pos++;
return B_OK;
@@ -199,14 +224,17 @@ StandardIndex::GetNextChunkInfo(int stream_index, int64 *start, uint32 *size, bo
status_t
StandardIndex::Seek(int stream_index, uint32 seekTo, int64 *frame, bigtime_t *time)
StandardIndex::Seek(int stream_index, uint32 seekTo, int64 *frame,
bigtime_t *time)
{
printf("StandardIndex::Seek: stream %d, seekTo%s%s%s%s, time %Ld, frame %Ld\n",
stream_index,
TRACE("StandardIndex::Seek: stream %d, seekTo%s%s%s%s, time %Ld, "
"frame %Ld\n", stream_index,
(seekTo & B_MEDIA_SEEK_TO_TIME) ? " B_MEDIA_SEEK_TO_TIME" : "",
(seekTo & B_MEDIA_SEEK_TO_FRAME) ? " B_MEDIA_SEEK_TO_FRAME" : "",
(seekTo & B_MEDIA_SEEK_CLOSEST_FORWARD) ? " B_MEDIA_SEEK_CLOSEST_FORWARD" : "",
(seekTo & B_MEDIA_SEEK_CLOSEST_BACKWARD) ? " B_MEDIA_SEEK_CLOSEST_BACKWARD" : "",
(seekTo & B_MEDIA_SEEK_CLOSEST_FORWARD) ?
" B_MEDIA_SEEK_CLOSEST_FORWARD" : "",
(seekTo & B_MEDIA_SEEK_CLOSEST_BACKWARD) ?
" B_MEDIA_SEEK_CLOSEST_BACKWARD" : "",
*time, *frame);
const stream_info *stream = fParser->StreamInfo(stream_index);
@@ -215,14 +243,15 @@ StandardIndex::Seek(int stream_index, uint32 seekTo, int64 *frame, bigtime_t *ti
int64 frame_pos;
if (seekTo & B_MEDIA_SEEK_TO_FRAME)
frame_pos = *frame;
else if (seekTo & B_MEDIA_SEEK_TO_TIME)
frame_pos = (*time * stream->frames_per_sec_rate) / (1000000 * stream->frames_per_sec_scale);
else
else if (seekTo & B_MEDIA_SEEK_TO_TIME) {
frame_pos = (*time * stream->frames_per_sec_rate)
/ (1000000 * stream->frames_per_sec_scale);
} else
return B_BAD_VALUE;
if (stream->is_audio) {
int64 bytes = 0;
for (int i = 0; i < fIndexSize; i++) {
for (uint32 i = 0; i < fIndexSize; i++) {
if ((fIndex[i].chunk_id & 0xffff) == data->chunk_id) {
int64 bytesNext = bytes + fIndex[i].chunk_length;
if (bytes <= frame_pos && bytesNext > frame_pos) {
@@ -234,7 +263,7 @@ StandardIndex::Seek(int stream_index, uint32 seekTo, int64 *frame, bigtime_t *ti
}
} else if (stream->is_video) {
int pos = 0;
for (int i = 0; i < fIndexSize; i++) {
for (uint32 i = 0; i < fIndexSize; i++) {
if ((fIndex[i].chunk_id & 0xffff) == data->chunk_id) {
if (pos == frame_pos) {
data->stream_pos = i;
@@ -247,11 +276,11 @@ StandardIndex::Seek(int stream_index, uint32 seekTo, int64 *frame, bigtime_t *ti
return B_BAD_VALUE;
}
printf("seek failed, position not found\n");
ERROR("libOpenDML: seek failed, position not found\n");
return B_ERROR;
done:
printf("seek done: index: pos %d, size %d\n", data->stream_pos, fIndexSize);
TRACE("seek done: index: pos %d, size %d\n", data->stream_pos, fIndexSize);
*frame = frame_pos;
*time = (frame_pos * 1000000 * stream->frames_per_sec_scale) / stream->frames_per_sec_rate;
return B_OK;