[Spice-devel] [spice-server 3/3] mjpeg: Use RedChunkIterator

Christophe Fergeau cfergeau at redhat.com
Fri Sep 9 14:43:55 UTC 2016


On Fri, Sep 09, 2016 at 09:54:17AM -0400, Frediano Ziglio wrote:
> >  static int encode_frame(MJpegEncoder *encoder, const SpiceRect *src,
> >                          const SpiceBitmap *image, int top_down)
> >  {
> > -    SpiceChunks *chunks;
> > +    RedChunkIterator it;
> >      uint32_t image_stride;
> > -    size_t offset;
> > -    int i, chunk;
> > +    unsigned int i;
> >  
> > -    chunks = image->data;
> > -    offset = 0;
> > -    chunk = 0;
> >      image_stride = image->stride;
> > +    red_chunk_iterator_init(&it, image->data);
> >  
> >      const int skip_lines = top_down ? src->top : image->y - (src->bottom -
> >      0);
> >      for (i = 0; i < skip_lines; i++) {
> > -        get_image_line(chunks, &offset, &chunk, image_stride);
> > +        red_chunk_iterator_skip_bytes(&it, image_stride);
> >      }
> >  
> >      const unsigned int stream_height = src->bottom - src->top;
> >      const unsigned int stream_width = src->right - src->left;
> >  
> >      for (i = 0; i < stream_height; i++) {
> > -        uint8_t *src_line = get_image_line(chunks, &offset, &chunk,
> > image_stride);
> > +        uint8_t line_data[image_stride];
> 
> Potentially 4gb on the stack.
> Beside this I think previously there was no allocation of a line
> and no memory copy.
> By definition a line have to be contained in a single chunk.

Avoiding that means exporting something similar to
red_chunk_iterator_get_data_one_chunk(). With RedChunkIterator, we
do not really care whether one line fits in one chunk or not. You say
"by definition", is there anything guaranteeing that? I agree the stack
usage, and then the memcpy should be fixed.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20160909/70195abb/attachment.sig>


More information about the Spice-devel mailing list