[FFmpeg-devel] [PATCH][4/4] Enable use of the extended API

Björn Axelsson bjorn.axelsson
Thu Dec 13 17:31:31 CET 2007


On Thu, 2007-12-13 at 16:25 +0100, Bj?rn Axelsson wrote:
> On Mon, 2007-12-03 at 03:34 +0100, Michael Niedermayer wrote:
> > On Tue, Nov 27, 2007 at 11:26:38AM +0100, Bj?rn Axelsson wrote:
> > > On Thu, 2007-11-22 at 15:01 +0000, Bj?rn Axelsson wrote: 
> > > > Enable av_read_pause(), av_read_play() and the ASF demuxer's
> > > > av_read_seek() to use the protocol-native functionality if available.
> > > > 
> > > > I forgot to write this before: The code passes "make test" after each
> > > > patch has been applied, and after all patches have been applied. 
> > > > Patch 2 depends on patch 1, and patch 4 on patch 2.
> > > > 
> > > > There's still no code that uses this functionality, but I'll break up
> > > > the MMS patch in smaller diffs and submit it soon.
> > > 
> > > Patch updated for the changes in the previous patches and to handle the
> > > case where read_seek() is given a stream index but that isn't supported
> > > by the protocol's read_seek(). 
> > > Please double-check the pts calculations I'm doing in asf.c, as I'm not
> > > totally comfortable with them.
> > > 
> > > The patch passes "make test" and also tests out ok with the upcoming MMS
> > > implementation.
> > > 
> > > -- 
> > > Bj?rn Axelsson                    Phone: +46-(0)90-18 98 97
> > > Intinor AB                          Fax: +46-(0)920-757 10
> > > www.intinor.se
> > > Interactive Television & Digital Media Distribution
> > 
> > > Index: libavformat/asf.c
> > > ===================================================================
> > > --- libavformat/asf.c.orig	2007-11-27 10:43:35.269134455 +0100
> > > +++ libavformat/asf.c	2007-11-27 11:20:30.010091214 +0100
> > > @@ -1049,6 +1049,26 @@
> > >      if (asf->packet_size <= 0)
> > >          return -1;
> > >  
> > > +    /* Try using the protocol's read_seek if available */
> > > +    if(s->pb->read_seek) {
> > > +        int ret = av_url_read_fseek(s->pb, stream_index, pts, flags);
> > > +        if(ret == AVERROR(ENOTSUP) && stream_index != -1) {
> > > +            /* Retry with pts in AV_TIME_BASE from beginning of presentation
> > > +             * and stream_index = -1 */
> > > +            AVStream *st  = s->streams[stream_index];
> > > +            uint64_t offs = st->start_time==AV_NOPTS_VALUE ? 0 : st->start_time;
> > > +            uint64_t npts = av_rescale(pts + offs,
> > > +                                       AV_TIME_BASE*(int64_t)st->time_base.num,
> > > +                                       st->time_base.den);
> > > +            ret = av_url_read_fseek(s->pb, -1, npts, flags);
> > > +        }
> > > +        if(ret != AVERROR(ENOTSUP)) {
> > > +            if(ret >= 0) // Success
> > > +                asf_reset_header(s);
> > > +            return ret;
> > > +        }
> > > +    }
> > 
> > this is wrong, offs MUST always be 0
> > this is due to the existing API for AVInputFormat read_seek
> > and the cases for stream_index==-1 and stream_index!=-1
> > the code as is, is inconsistant ...
> 
> Thanks for the review. So the time rescaling would be correct with
> offs=0? (See the new api_extension_enable.diff)
> 
> > also the existing API is good, the one for av_url_read_fseek() is not
> > and should be changed to match it, timestamps should always use the same
> > 0 point
> 
> If there's more to the av_url_read_fseek() API than the offset handling
> that is bad, please elaborate since there are several other minor API
> differences compared to the AVInputFormat read_seek() and
> av_seek_frame(), but for good reasons.
> If not, please see the attached patch av_url_read_fseek_api.diff that
> copies the doc for stream_index==1 from av_read_seek().
> 
> I also now realise that its interface is closer to av_seek_frame() than
> to AVInputFormat read_seek(). Maybe calling it av_url_fseek_frame()
> wouldn't be a bad idea.

Sorry, but I didn't think that through enough. If there's no need to
adjust the 0 point for different streams, then the same API can indeed
be used. New patches attached. Slightly modified commit message below.

> > [...]
> > > Index: libavformat/utils.c
> > > ===================================================================
> > > --- libavformat/utils.c.orig	2007-11-27 10:43:35.269134455 +0100
> > > +++ libavformat/utils.c	2007-11-27 10:44:58.611571860 +0100
> > > @@ -2028,6 +2028,8 @@
> > >  
> > >  int av_read_play(AVFormatContext *s)
> > >  {
> > > +    if (s->pb && s->pb->read_play)
> > > +        return av_url_read_fplay(s->pb);
> > >      if (!s->iformat->read_play)
> > >          return AVERROR(ENOSYS);
> > >      return s->iformat->read_play(s);
> > > @@ -2035,6 +2037,8 @@
> > >  
> > >  int av_read_pause(AVFormatContext *s)
> > >  {
> > > +    if (s->pb && s->pb->read_pause)
> > > +        return av_url_read_fpause(s->pb);
> > >      if (!s->iformat->read_pause)
> > >          return AVERROR(ENOSYS);
> > >      return s->iformat->read_pause(s);
> > 
> > i dont know if bypassing the demuxer is always safe ...
> 
> You are probably correct. I've moved the call to the muxer (also in
> api_extension_enable.diff).
> 
> Suggested commit messages:
>   api_extension_enable.diff
>     Enable the url-based seek/play/pause API in asf demuxer
>   av_url_read_fseek_api.diff
>     Same API as av_seek_frame() when stream_index==-1
  av_url_read_fseek_api.diff
    Give av_url_read_fseek() same API as AVFormat read_seek()

-- 
Bj?rn Axelsson                    Phone: +46-(0)90-18 98 97
Intinor AB                          Fax: +46-(0)920-757 10
www.intinor.se
Interactive Television & Digital Media Distribution
-------------- next part --------------
A non-text attachment was scrubbed...
Name: api_extension_enable.diff
Type: text/x-patch
Size: 1208 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20071213/e76adf8c/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: av_url_read_fseek_api.diff
Type: text/x-patch
Size: 1425 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20071213/e76adf8c/attachment-0001.bin>



More information about the ffmpeg-devel mailing list