Index: mythmusic/mythmusic/avfdecoder.cpp =================================================================== RCS file: /var/lib/mythcvs/mythmusic/mythmusic/avfdecoder.cpp,v retrieving revision 1.1 diff -u -r1.1 avfdecoder.cpp --- mythmusic/mythmusic/avfdecoder.cpp 2 Jan 2004 22:44:39 -0000 1.1 +++ mythmusic/mythmusic/avfdecoder.cpp 9 Jan 2004 07:22:25 -0000 @@ -12,6 +12,7 @@ Revision History - Initial release + - 1/9/2004 - Improved seek support */ #include @@ -298,21 +299,33 @@ // Look to see if user has requested a seek if (seekTime >= 0.0) - { - // curpos = (int)(((seekTime * 44100) / CD_FRAMESAMPLES) + start); - // Add seeking here + { cerr << "avfdecoder.o: seek time " << seekTime << endl; - //ifmt->read_seek(ic, (int64_t)(pkt->pts + ((seekTime * 1000)*AV_TIME_BASE))); - //ifmt->read_seek(ic, 0, (int64_t)((seekTime * 1000) * AV_TIME_BASE)); - if (av_seek_frame(ic, 0, (int64_t)((seekTime * 1000) * - AV_TIME_BASE)) < 0) + + // For whatever reason, the ASF code (and maybe others) + // does not release its private data (headers) unless + // the file is closed. If the headers are not released + // then seeking could fail because after the seek, + // old headers are still in memory. Simply freeing the + // structure and reallocating doesn't seem to be enough + // and while expensive, this seems to work consistently + av_close_input_file(ic); + ifmt = NULL; + av_open_input_file(&ic, filename, ifmt, 0, ap); + av_find_stream_info(ic); + audio_dec = &ic->streams[0]->codec; + codec = avcodec_find_decoder(audio_dec->codec_id); + avcodec_open(audio_dec,codec); + + if (av_seek_frame(ic, 0, (int64_t)(seekTime * AV_TIME_BASE)) < 0) { - cerr << "error seeking" << endl; + cerr << "avfdecoder.o: error seeking" << endl; } seekTime = -1.0; } + // Read a packet from the input context // if (av_read_packet(ic, pkt) < 0) if (av_read_frame(ic, pkt) < 0) @@ -328,7 +341,8 @@ len = pkt->size; mutex()->unlock(); - while (len > 0 && !done && !finish && !user_stop) + while (len > 0 && !done && !finish && !user_stop && + seekTime <= 0.0) { mutex()->lock(); // Decode the stream to the output codec @@ -386,7 +400,7 @@ len -= dec_len; mutex()->unlock(); } - // av_free_packet(pkt); + av_free_packet(pkt); } flush(TRUE); @@ -433,10 +447,15 @@ title += (char *)ic->title; genre += (char *)ic->genre; year = ic->year; + tracknum = ic->track; length = (ic->duration / AV_TIME_BASE) * 1000; // Only mess around with this is the format is ASF - if (strcmp(ic->iformat->name, "asf") == 0 && !ignore_id3) + // And only if we didn't get the info from the + // library. Patch is in CVS so it could be + // working if libavformat is new enough + if (strcmp(ic->iformat->name, "asf") == 0 && !ignore_id3 && + (strcmp(album,"") == 0 || tracknum == 0)) { // Raw code for reading album from extended information not supported // by libavformat. Should be included in library because it is specific