They seek him here, they seek him there.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30673 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
David McPaul
2009-05-08 13:04:27 +00:00
parent 5561b695a1
commit e5d9cba691
3 changed files with 34 additions and 23 deletions
@@ -299,7 +299,7 @@ ASFFileReader::ParseIndex() {
while (asf_get_packet(asfFile, packet) > 0) {
for (int i=0;i<packet->payload_count;i++) {
payload = (asf_payload_t *)(&packet->payloads[i]);
// printf("Payload %d Stream %d Keyframe %d send time %Ld pts %Ld id %d size %d\n",i+1,payload->stream_number,payload->key_frame, 1000L * bigtime_t(packet->send_time), 1000L * bigtime_t(payload->pts), payload->media_object_number, payload->datalen);
// printf("Payload %d Stream %d Keyframe %d send time %Ld pts %Ld id %d size %d\n",i+1,payload->stream_number,payload->key_frame, 1000L * bigtime_t(packet->send_time), 1000L * bigtime_t(payload->pts), payload->media_object_number, payload->datalen);
if (payload->stream_number < streams.size()) {
streams[payload->stream_number].AddPayload(payload->media_object_number, payload->key_frame, 1000L * payload->pts, payload->datalen, false);
}
@@ -329,6 +329,7 @@ ASFFileReader::GetNextChunkInfo(uint32 streamIndex, uint32 pFrameNo,
if (indexEntry.noPayloads == 0) {
// No index entry
printf("No Index entry for frame %ld\n",pFrameNo);
return false;
}
@@ -73,7 +73,6 @@ StreamEntry::GetIndex(uint32 frameNo)
for (std::vector<IndexEntry>::iterator itr = index.begin(); itr != index.end(); ++itr) {
if (itr->frameNo == frameNo) {
indexEntry = *itr;
index.erase(itr);
break;
}
}
@@ -84,12 +83,10 @@ bool
StreamEntry::HasIndex(uint32 frameNo)
{
if (!index.empty()) {
for (std::vector<IndexEntry>::iterator itr = index.begin();
itr != index.end();
++itr) {
if (itr->frameNo == frameNo) {
return true;
}
for (std::vector<IndexEntry>::iterator itr = index.begin(); itr != index.end(); ++itr) {
if (itr->frameNo == frameNo) {
return true;
}
}
}
@@ -104,7 +101,6 @@ StreamEntry::GetIndex(bigtime_t pts)
for (std::vector<IndexEntry>::iterator itr = index.begin(); itr != index.end(); ++itr) {
if (pts <= itr->pts) {
indexEntry = *itr;
index.erase(itr);
break;
}
}
@@ -115,12 +111,10 @@ bool
StreamEntry::HasIndex(bigtime_t pts)
{
if (!index.empty()) {
for (std::vector<IndexEntry>::iterator itr = index.begin();
itr != index.end();
++itr) {
if (pts <= itr->pts) {
return true;
}
for (std::vector<IndexEntry>::iterator itr = index.begin(); itr != index.end(); ++itr) {
if (pts <= itr->pts) {
return true;
}
}
}
@@ -190,7 +190,7 @@ asfReader::AllocateCookie(int32 streamNumber, void **_cookie)
TRACE("frame_count %Ld\n", cookie->frame_count);
TRACE("duration %.6f (%Ld)\n", cookie->duration / 1E6, cookie->duration);
TRACE("calculated fps=%ld\n", cookie->frame_count * 1000000LL / cookie->duration);
TRACE("calculated fps=%Ld\n", cookie->frame_count * 1000000LL / cookie->duration);
// asf does not have a frame rate! The extended descriptor defines an average time per frame which is generally useless.
if (videoFormat.FrameScale && videoFormat.FrameRate) {
@@ -469,7 +469,7 @@ asfReader::FindKeyFrame(void* cookie, uint32 flags,
// Find the nearest keyframe to the given time or frame.
asf_cookie *asfCookie = (asf_cookie *)cookie;
bool keyframe = false;
IndexEntry indexEntry;
if (flags & B_MEDIA_SEEK_TO_TIME) {
// convert time to frame as we seek by frame
@@ -477,12 +477,6 @@ asfReader::FindKeyFrame(void* cookie, uint32 flags,
*frame = ((*time * asfCookie->frames_per_sec_rate) / (int64)asfCookie->frames_per_sec_scale) / 1000000LL;
}
if (flags & B_MEDIA_SEEK_TO_FRAME) {
// convert frame to time as we seek by frame
// frame = (time * rate) / fps / 1000000LL
*time = *frame * 1000000LL * (int64)asfCookie->frames_per_sec_scale / asfCookie->frames_per_sec_rate;
}
TRACE("asfReader::FindKeyFrame: seekTo%s%s%s%s, time %Ld, frame %Ld\n",
(flags & B_MEDIA_SEEK_TO_TIME) ? " B_MEDIA_SEEK_TO_TIME" : "",
(flags & B_MEDIA_SEEK_TO_FRAME) ? " B_MEDIA_SEEK_TO_FRAME" : "",
@@ -490,6 +484,28 @@ asfReader::FindKeyFrame(void* cookie, uint32 flags,
(flags & B_MEDIA_SEEK_CLOSEST_BACKWARD) ? " B_MEDIA_SEEK_CLOSEST_BACKWARD" : "",
*time, *frame);
if (asfCookie->audio == false) {
// Only video has keyframes
if (flags & B_MEDIA_SEEK_CLOSEST_FORWARD || flags & B_MEDIA_SEEK_CLOSEST_BACKWARD) {
indexEntry = theFileReader->GetIndex(asfCookie->stream,*frame);
while (indexEntry.noPayloads > 0 && indexEntry.keyFrame == false && *frame > 0) {
if (flags & B_MEDIA_SEEK_CLOSEST_BACKWARD) {
(*frame)--;
} else {
(*frame)++;
}
indexEntry = theFileReader->GetIndex(asfCookie->stream,*frame);
}
if (indexEntry.noPayloads == 0) {
return B_ERROR;
}
}
}
*time = *frame * 1000000LL * (int64)asfCookie->frames_per_sec_scale / asfCookie->frames_per_sec_rate;
return B_OK;
}