[vlc-devel] [PATCH 1/2] opus: add encoder

Tristan Matthews le.businessman at gmail.com
Sun Sep 22 07:46:35 CEST 2013


On Sat, Sep 21, 2013 at 10:56 AM, Rafaël Carré <funman at videolan.org> wrote:

> Hello,
>
> I send a small patchset which fixes a few problems I had.
>

Thanks.


> Some questions left:
>
> Le 19/09/2013 08:56, Tristan Matthews a écrit :
>
> > +static block_t *Encode(encoder_t *enc, block_t *buf)
> > +{
> > +    encoder_sys_t *sys = enc->p_sys;
> > +    opus_int32 bytes_encoded;
> > +
> > +    if (!buf)
> > +        return NULL;
> > +
> > +    mtime_t i_pts = buf->i_pts -
> > +                (mtime_t) CLOCK_FREQ * (mtime_t) sys->i_samples_delay /
> > +                (mtime_t) enc->fmt_in.audio.i_rate;
> > +
> > +    sys->i_samples_delay += buf->i_nb_samples;
> > +
> > +    block_t *result = 0;
> > +    unsigned src_start = 0;
> > +    unsigned padding_start = 0;
> > +    /* The maximum Opus frame size is 1275 bytes + TOC sequence length.
> */
> > +    const unsigned OPUS_MAX_ENCODED_BYTES = ((1275 + 3) *
> sys->nb_streams) - 2;
> > +
> > +    while (sys->i_nb_samples + buf->i_nb_samples >= OPUS_FRAME_SIZE)
> > +    {
> > +        block_t *out_block = block_Alloc(OPUS_MAX_ENCODED_BYTES);
> > +
> > +        /* add padding to beginning */
> > +        if (sys->padding)
> > +        {
> > +            const size_t leftover_space = OPUS_FRAME_SIZE -
> sys->i_nb_samples;
> > +            padding_start = fill_buffer(enc, padding_start,
> sys->padding,
> > +                    __MIN(sys->padding->i_nb_samples, leftover_space));
> > +            if (sys->padding->i_nb_samples <= 0)
> > +            {
> > +                block_Release(sys->padding);
> > +                sys->padding = 0;
> > +            }
> > +        }
> > +
> > +        /* padding may have been freed either before or inside previous
> > +         * if-statement */
> > +        if (!sys->padding)
> > +        {
> > +            const size_t leftover_space = OPUS_FRAME_SIZE -
> sys->i_nb_samples;
> > +            src_start = fill_buffer(enc, src_start, buf,
> > +                    __MIN(buf->i_nb_samples, leftover_space));
> > +        }
> > +
> > +        bytes_encoded = opus_multistream_encode_float(sys->enc,
> sys->buffer,
> > +                OPUS_FRAME_SIZE, out_block->p_buffer,
> out_block->i_buffer);
> > +
> > +        out_block->i_length = (mtime_t) CLOCK_FREQ *
> > +            (mtime_t) OPUS_FRAME_SIZE / (mtime_t)
> enc->fmt_in.audio.i_rate;
> > +
> > +        out_block->i_dts = out_block->i_pts = i_pts;
>
> Those should be moved in "if (bytes_encoded >= 0)"
>
> > +
> > +        sys->i_samples_delay -= OPUS_FRAME_SIZE;
> > +
> > +        i_pts += out_block->i_length;
> > +
> > +        sys->i_nb_samples = 0;
> > +
>
> What about those?
>

Quite right, they should all be in the bytes_encoded >= (aka else)
branch.

Best,
Tristan

-- 
Tristan Matthews
web: http://tristanswork.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20130922/70242335/attachment.html>


More information about the vlc-devel mailing list