On Sun, 2 Aug 2020 14:43:20 +0200
"Andreas Rheinhardt" <andreas.rheinha...@gmail.com> wrote:

> > So, something like this basically:
> >
> >     static int argo_asf_write_packet(AVFormatContext *s, AVPacket *pkt)
> >     {
> >         if (pkt->size != 17 && pkt->size != 34)
> >             return AVERROR(EINVAL);
> >
> >         avio_write(s->pb, pkt->data, pkt->size);
> >         return 0;
> >     }
> >  
> I think it is rather AVERROR_INVALIDDATA. But even then there are still
> two problems: You allow 17 byte packets in case of stereo, yet in this
> case you still assert that the data size is divisible by 34. And more
> serious: Currently, the AVIOContext's position is incremented even if a
> write error happened or if writing is not even attempted because of an
> earlier write error, yet there is no guarantee that it always stays that
> way.

Yeah, it's late here, I shouldn't be doing this when tired.
That check should have been:

    if (pkt->size != 17 * s->streams[0]->codecpar->channels)
        return AVERROR_INVALIDDATA;

> 
> For the record, AVStream.nb_frames contains the number of frames
> successfully written. You could simply use that and ignore any
> divisibility. Or you could check the sizes in a custom write_packet
> function and still just use AVStream.nb_frames when writing the trailer.
> 
I didn't know about AVStream.nb_frames, that makes things much nicer.
I've removed the assert and changed it to do what you suggested.


Zane

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to