implement seek function

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29305 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
David McPaul
2009-02-24 08:00:06 +00:00
parent c6527ff508
commit decfff7c4d
2 changed files with 37 additions and 13 deletions
+35 -10
View File
@@ -205,8 +205,9 @@ avCodec::Setup(media_format *ioEncodedFormat, const void *infoBuffer,
status_t status_t
avCodec::Seek(uint32 in_towhat,int64 in_requiredFrame, int64 *inout_frame, avCodec::Seek(uint32 seekTo,
bigtime_t in_requiredTime, bigtime_t *inout_time) int64 seekFrame, int64 *frame,
bigtime_t seekTime, bigtime_t *time)
{ {
// reset the ffmpeg codec // reset the ffmpeg codec
// to flush buffers, so we keep the sync // to flush buffers, so we keep the sync
@@ -215,7 +216,25 @@ avCodec::Seek(uint32 in_towhat,int64 in_requiredFrame, int64 *inout_frame,
avcodec_close(ffc); avcodec_close(ffc);
fCodecInitDone = (avcodec_open(ffc, fCodec) >= 0); fCodecInitDone = (avcodec_open(ffc, fCodec) >= 0);
} }
fFrame = *inout_frame;
if (seekTo == B_MEDIA_SEEK_TO_TIME) {
TRACE("avCodec::Seek by time ");
TRACE("from frame %Ld and time %.6f TO Required Time %.6f. ", fFrame, fStartTime / 1000000.0, seekTime / 1000000.0);
*frame = (int64)(seekTime * fOutputFrameRate / 1000000LL);
*time = seekTime;
} else if (seekTo == B_MEDIA_SEEK_TO_FRAME) {
TRACE("avCodec::Seek by Frame ");
TRACE("from time %.6f and frame %Ld TO Required Frame %Ld. ", fStartTime / 1000000.0, fFrame, seekFrame);
*time = (bigtime_t)(seekFrame * 1000000LL / fOutputFrameRate);
*frame = seekFrame;
} else
return B_BAD_VALUE;
fFrame = *frame;
fStartTime = *time;
TRACE("so new frame is %Ld at time %.6f\n", *frame, *time / 1000000.0);
return B_OK; return B_OK;
} }
@@ -300,6 +319,8 @@ avCodec::NegotiateOutputFormat(media_format *inout_format)
// ffc->frame_rate = (int)(fOutputVideoFormat.field_rate // ffc->frame_rate = (int)(fOutputVideoFormat.field_rate
// * ffc->frame_rate_base); // * ffc->frame_rate_base);
fOutputFrameRate = fOutputVideoFormat.field_rate;
if (fInputFormat.MetaDataSize() > 0) { if (fInputFormat.MetaDataSize() > 0) {
ffc->extradata = (uint8_t *)fInputFormat.MetaData(); ffc->extradata = (uint8_t *)fInputFormat.MetaData();
ffc->extradata_size = fInputFormat.MetaDataSize(); ffc->extradata_size = fInputFormat.MetaDataSize();
@@ -331,6 +352,7 @@ avCodec::NegotiateOutputFormat(media_format *inout_format)
// XXX set n-th ffc->pix_fmt here // XXX set n-th ffc->pix_fmt here
if (avcodec_open(ffc, fCodec) >= 0) { if (avcodec_open(ffc, fCodec) >= 0) {
fCodecInitDone = true; fCodecInitDone = true;
conv_func = resolve_colorspace( conv_func = resolve_colorspace(
fOutputVideoFormat.display.format, ffc->pix_fmt); fOutputVideoFormat.display.format, ffc->pix_fmt);
} }
@@ -339,11 +361,12 @@ avCodec::NegotiateOutputFormat(media_format *inout_format)
} }
if (!fCodecInitDone) { if (!fCodecInitDone) {
TRACE("avcodec_open() failed!\n"); TRACE("avcodec_open() failed to init codec!\n");
return B_ERROR; return B_ERROR;
} }
if (!conv_func) { if (!conv_func) {
TRACE("no conv_func!\n"); TRACE("no conv_func found!\n");
return B_ERROR; return B_ERROR;
} }
@@ -393,9 +416,9 @@ avCodec::Decode(void *out_buffer, int64 *out_frameCount,
// TRACE("[%c] avCodec::Decode()\n", isAudio?('a'):('v')); // TRACE("[%c] avCodec::Decode()\n", isAudio?('a'):('v'));
if (isAudio) { mh->start_time = fStartTime;
mh->start_time = fStartTime; if (isAudio) {
// TRACE("audio start_time %.6f\n", mh->start_time / 1000000.0); // TRACE("audio start_time %.6f\n", mh->start_time / 1000000.0);
@@ -462,6 +485,7 @@ avCodec::Decode(void *out_buffer, int64 *out_frameCount,
fOutputBufferSize = out_size; fOutputBufferSize = out_size;
} }
} }
fFrame += *out_frameCount;
} else { // Video } else { // Video
@@ -477,9 +501,7 @@ avCodec::Decode(void *out_buffer, int64 *out_frameCount,
} }
mh->type = B_MEDIA_RAW_VIDEO; mh->type = B_MEDIA_RAW_VIDEO;
// mh->start_time = (bigtime_t) (1000000.0 * fFrame // mh->start_time = chunk_mh.start_time;
// / fOutputVideoFormat.field_rate);
mh->start_time = chunk_mh.start_time;
mh->file_pos = 0; mh->file_pos = 0;
mh->orig_size = 0; mh->orig_size = 0;
mh->u.raw_video.field_gamma = 1.0; mh->u.raw_video.field_gamma = 1.0;
@@ -561,6 +583,9 @@ avCodec::Decode(void *out_buffer, int64 *out_frameCount,
#endif #endif
} }
} }
fStartTime = (bigtime_t) (1000000LL * fFrame / fOutputFrameRate);
// TRACE("END of avCodec::Decode()\n"); // TRACE("END of avCodec::Decode()\n");
return B_OK; return B_OK;
} }
+2 -3
View File
@@ -45,9 +45,8 @@ class avCodec : public Decoder
virtual status_t Decode(void *out_buffer, int64 *out_frameCount, virtual status_t Decode(void *out_buffer, int64 *out_frameCount,
media_header *mh, media_decode_info *info); media_header *mh, media_decode_info *info);
virtual status_t Seek(uint32 in_towhat, virtual status_t Seek(uint32 seekTo, int64 seekFrame, int64 *frame,
int64 in_requiredFrame, int64 *inout_frame, bigtime_t seekTime, bigtime_t *time);
bigtime_t in_requiredTime, bigtime_t *inout_time);
protected: protected: