Guest User

seg fault frame alloc

a guest
Aug 16th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.46 KB | None | 0 0
  1.                 if (item_id == c->primary_item_id) {
  2.                     AVFrame *tile  = av_frame_alloc();
  3.                     AVFrame *frame = av_frame_alloc();
  4.                     unsigned grid_width, grid_height, cnt, size;
  5.  
  6.                     /* assuming 'grid' item is the primary item in tiled heif */
  7.                     pos = avio_tell(pb);
  8.                     if ((ret = avio_seek(pb, item_pos, SEEK_SET)) < 0)
  9.                         goto err;
  10.                     if ((ret = read_image_grid(c, pb)) < 0)
  11.                         goto err;
  12.                     if ((ret = avio_seek(pb, pos, SEEK_SET)) < 0)
  13.                         goto err;
  14.  
  15.                     grid_width  = c->tile_width  * c->grid_cols;
  16.                     grid_height = c->tile_height * c->grid_rows;
  17.  
  18.                     av_log(c->fc, AV_LOG_INFO, "tile res %dx%d, grid res %dx%d, output res %dx%d\n",
  19.                            c->tile_width, c->tile_height,
  20.                            grid_width, grid_height,
  21.                            c->output_width, c->output_height);
  22.  
  23.  
  24.                     for (cnt = 0; cnt < c->nb_tiles; cnt++) {
  25.                         AVPacket pkt;
  26.                         int plane;
  27.  
  28.                         AVIndexEntry *e = &st->index_entries[cnt];
  29.                         item_pos   = e->pos;
  30.                         ext_length = e->size;
  31.  
  32.                         pos = avio_tell(pb);
  33.                         if ((avio_seek(pb, item_pos, SEEK_SET)) < 0)
  34.                             goto err;
  35.                         if ((ret = av_get_packet(pb, &pkt, ext_length)) < 0)
  36.                             goto err;
  37.                         if ((avio_seek(pb, pos, SEEK_SET)) < 0)
  38.                             goto err;
  39.  
  40.                         ret = avcodec_send_packet(dec_ctx, &pkt);
  41.                         if (ret < 0) {
  42.                             av_log(c->fc, AV_LOG_ERROR, "Error sending tile for decoding\n");
  43.                             goto err;
  44.                         }
  45.                         ret = avcodec_receive_frame(dec_ctx, tile);
  46.                         if (ret < 0) {
  47.                             av_log(c->fc, AV_LOG_ERROR, "Error decoding tile\n");
  48.                             goto err;
  49.                         }
  50.  
  51.                         if (!cnt) {
  52.                             av_frame_copy_props(frame, tile);
  53.                             frame->width  = grid_width;
  54.                             frame->height = grid_height;
  55.                             frame->format = tile->format;
  56.                             ret = av_image_alloc(frame->data, frame->linesize,
  57.                                                  frame->width, frame->height,
  58.                                                  frame->format, 1);
  59.                             if (ret < 0)
  60.                                 goto err;
  61.                             /*ret = av_frame_make_writable(frame);*/
  62.                             /*if (ret < 0)*/
  63.                                 /*goto err;*/
  64.                             ret = av_image_fill_black(frame->data,
  65.                                             (const ptrdiff_t *)frame->linesize,
  66.                                             frame->format, frame->color_range,
  67.                                             frame->width, frame->height);
  68.                             if (ret < 0)
  69.                                 goto err;
  70.                         }
  71.  
  72.                         av_log(c->fc, AV_LOG_INFO, "cnt %d\t\n", cnt);
  73.                         for (plane = 0; plane < 3; plane++) {
  74.                             uint8_t *p, *q;
  75.                             unsigned x, y, line;
  76.                             x = (cnt % c->grid_cols) * c->tile_width;
  77.                             y = (cnt / c->grid_cols) * c->tile_height;
  78.                             p = &tile->data[plane][0];
  79.                             q = &frame->data[plane][y * frame->linesize[plane] + x];
  80.                             av_log(c->fc, AV_LOG_INFO, "x, y: %d %d\t\n", x, y);
  81.                             for (line = 0; line < c->tile_height; line++) {
  82.                                 memcpy(q, p, c->tile_width);
  83.                                 p += tile->linesize[plane];
  84.                                 q += frame->linesize[plane];
  85.                             }
  86.                         }
  87.                     }
  88.  
  89.                     size = av_image_get_buffer_size(tile->format, frame->width,
  90.                                                     frame->height, 32);
  91.                     av_new_packet(&st->attached_pic, size);
  92.                     av_image_copy_to_buffer(st->attached_pic.data, size,
  93.                                             (const uint8_t **)frame->data,
  94.                                             frame->linesize, frame->format,
  95.                                             frame->width, frame->height, 32);
  96.  
  97.                     st->disposition |= AV_DISPOSITION_ATTACHED_PIC;
  98.                     st->attached_pic.stream_index = st->index;
  99.                     st->attached_pic.flags |= AV_PKT_FLAG_KEY;
  100.                     st->codecpar->width = grid_width;
  101.                     st->codecpar->height = grid_height;
  102.                     st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
  103.                     st->codecpar->format = frame->format;
  104.                     avcodec_close(dec_ctx);
  105.                     avcodec_free_context(&dec_ctx);
  106.                     av_frame_free(&tile);
  107.                     av_frame_free(&frame);
  108.                     av_freep(&st->index_entries);
Add Comment
Please, Sign In to add comment