* 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
@@ -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;