| @@ -108,9 +108,7 @@ typedef struct VideoPicture { · 107 unmodified lines |
| 108 | 108 | int reallocate; |
| 109 | 109 | enum AVPixelFormat pix_fmt; |
| 110 | 110 | |
| 111 | | −#if CONFIG_AVFILTER |
| 112 | | − AVFilterBufferRef *picref; |
| 113 | | −#endif |
| 111 | + AVRational sar; |
| 114 | 112 | } VideoPicture; |
| 115 | 113 | |
| 116 | 114 | typedef struct SubPicture { |
| @@ -217,8 +215,6 @@ typedef struct VideoState { · 100 unmodified lines |
| 217 | 215 | #if CONFIG_AVFILTER |
| 218 | 216 | AVFilterContext *in_video_filter; // the first filter in the video chain |
| 219 | 217 | AVFilterContext *out_video_filter; // the last filter in the video chain |
| 220 | | − int use_dr1; |
| 221 | | − FrameBuffer *buffer_pool; |
| 222 | 218 | #endif |
| 223 | 219 | |
| 224 | 220 | float skip_frames; |
| @@ -656,10 +652,10 @@ static void video_image_display(VideoState *is) · 431 unmodified lines |
| 656 | 652 | vp = &is->pictq[is->pictq_rindex]; |
| 657 | 653 | if (vp->bmp) { |
| 658 | 654 | #if CONFIG_AVFILTER |
| 659 | | − if (vp->picref->video->pixel_aspect.num == 0) |
| 655 | + if (!vp->sar.num) |
| 660 | 656 | aspect_ratio = 0; |
| 661 | 657 | else |
| 662 | | − aspect_ratio = av_q2d(vp->picref->video->pixel_aspect); |
| 658 | + aspect_ratio = av_q2d(vp->sar); |
| 663 | 659 | #else |
| 664 | 660 | |
| 665 | 661 | /* XXX: use variable in the frame */ |
| @@ -1229,9 +1225,6 @@ static void stream_close(VideoState *is) · 563 unmodified lines |
| 1229 | 1225 | /* free all pictures */ |
| 1230 | 1226 | for (i = 0; i < VIDEO_PICTURE_QUEUE_SIZE; i++) { |
| 1231 | 1227 | vp = &is->pictq[i]; |
| 1232 | | −#if CONFIG_AVFILTER |
| 1233 | | − avfilter_unref_bufferp(&vp->picref); |
| 1234 | | −#endif |
| 1235 | 1228 | if (vp->bmp) { |
| 1236 | 1229 | SDL_FreeYUVOverlay(vp->bmp); |
| 1237 | 1230 | vp->bmp = NULL; |
| @@ -1279,8 +1272,6 @@ static void alloc_picture(void *opaque) · 41 unmodified lines |
| 1279 | 1272 | SDL_FreeYUVOverlay(vp->bmp); |
| 1280 | 1273 | |
| 1281 | 1274 | #if CONFIG_AVFILTER |
| 1282 | | − avfilter_unref_bufferp(&vp->picref); |
| 1283 | | − |
| 1284 | 1275 | vp->width = is->out_video_filter->inputs[0]->w; |
| 1285 | 1276 | vp->height = is->out_video_filter->inputs[0]->h; |
| 1286 | 1277 | vp->pix_fmt = is->out_video_filter->inputs[0]->format; |
| @@ -1369,10 +1360,6 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, int64_t · 82 unmodified lines |
| 1369 | 1360 | /* if the frame is not skipped, then display it */ |
| 1370 | 1361 | if (vp->bmp) { |
| 1371 | 1362 | AVPicture pict = { { 0 } }; |
| 1372 | | −#if CONFIG_AVFILTER |
| 1373 | | − avfilter_unref_bufferp(&vp->picref); |
| 1374 | | − vp->picref = src_frame->opaque; |
| 1375 | | −#endif |
| 1376 | 1363 | |
| 1377 | 1364 | /* get a pointer on the bitmap */ |
| 1378 | 1365 | SDL_LockYUVOverlay (vp->bmp); |
| @@ -1432,6 +1419,7 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts, int64_t · 53 unmodified lines |
| 1432 | 1419 | static int output_picture2(VideoState *is, AVFrame *src_frame, double pts1, int64_t pos) |
| 1433 | 1420 | { |
| 1434 | 1421 | double frame_delay, pts; |
| 1422 | + int ret; |
| 1435 | 1423 | |
| 1436 | 1424 | pts = pts1; |
| 1437 | 1425 | |
| @@ -1448,7 +1436,9 @@ static int output_picture2(VideoState *is, AVFrame *src_frame, double pts1, int6 · 10 unmodified lines |
| 1448 | 1436 | frame_delay += src_frame->repeat_pict * (frame_delay * 0.5); |
| 1449 | 1437 | is->video_clock += frame_delay; |
| 1450 | 1438 | |
| 1451 | | − return queue_picture(is, src_frame, pts, pos); |
| 1439 | + ret = queue_picture(is, src_frame, pts, pos); |
| 1440 | + av_frame_unref(src_frame); |
| 1441 | + return ret; |
| 1452 | 1442 | } |
| 1453 | 1443 | |
| 1454 | 1444 | static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacket *pkt) |
| @@ -1504,7 +1494,7 @@ static int get_video_frame(VideoState *is, AVFrame *frame, int64_t *pts, AVPacke · 49 unmodified lines |
| 1504 | 1494 | is->skip_frames_index -= FFMAX(is->skip_frames, 1.0); |
| 1505 | 1495 | return 1; |
| 1506 | 1496 | } |
| 1507 | | − |
| 1497 | + av_frame_unref(frame); |
| 1508 | 1498 | } |
| 1509 | 1499 | return 0; |
| 1510 | 1500 | } |
| @@ -1572,13 +1562,6 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c · 61 unmodified lines |
| 1572 | 1562 | is->in_video_filter = filt_src; |
| 1573 | 1563 | is->out_video_filter = filt_out; |
| 1574 | 1564 | |
| 1575 | | − if (codec->codec->capabilities & CODEC_CAP_DR1) { |
| 1576 | | − is->use_dr1 = 1; |
| 1577 | | − codec->get_buffer = codec_get_buffer; |
| 1578 | | − codec->release_buffer = codec_release_buffer; |
| 1579 | | − codec->opaque = &is->buffer_pool; |
| 1580 | | − } |
| 1581 | | − |
| 1582 | 1565 | return ret; |
| 1583 | 1566 | } |
| 1584 | 1567 | |
| @@ -1588,7 +1571,7 @@ static int video_thread(void *arg) · 3 unmodified lines |
| 1588 | 1571 | { |
| 1589 | 1572 | AVPacket pkt = { 0 }; |
| 1590 | 1573 | VideoState *is = arg; |
| 1591 | | − AVFrame *frame = avcodec_alloc_frame(); |
| 1574 | + AVFrame *frame = av_frame_alloc(); |
| 1592 | 1575 | int64_t pts_int; |
| 1593 | 1576 | double pts; |
| 1594 | 1577 | int ret; |
| @@ -1596,7 +1579,6 @@ static int video_thread(void *arg) · 1 unmodified line |
| 1596 | 1579 | #if CONFIG_AVFILTER |
| 1597 | 1580 | AVFilterGraph *graph = avfilter_graph_alloc(); |
| 1598 | 1581 | AVFilterContext *filt_out = NULL, *filt_in = NULL; |
| 1599 | | − int64_t pos; |
| 1600 | 1582 | int last_w = is->video_st->codec->width; |
| 1601 | 1583 | int last_h = is->video_st->codec->height; |
| 1602 | 1584 | |
| @@ -1608,7 +1590,6 @@ static int video_thread(void *arg) · 5 unmodified lines |
| 1608 | 1590 | |
| 1609 | 1591 | for (;;) { |
| 1610 | 1592 | #if CONFIG_AVFILTER |
| 1611 | | − AVFilterBufferRef *picref; |
| 1612 | 1593 | AVRational tb; |
| 1613 | 1594 | #endif |
| 1614 | 1595 | while (is->paused && !is->videoq.abort_request) |
| @@ -1639,38 +1620,19 @@ static int video_thread(void *arg) · 24 unmodified lines |
| 1639 | 1620 | } |
| 1640 | 1621 | |
| 1641 | 1622 | frame->pts = pts_int; |
| 1642 | | − if (is->use_dr1) { |
| 1643 | | − FrameBuffer *buf = frame->opaque; |
| 1644 | | − AVFilterBufferRef *fb = avfilter_get_video_buffer_ref_from_arrays( |
| 1645 | | − frame->data, frame->linesize, |
| 1646 | | − AV_PERM_READ | AV_PERM_PRESERVE, |
| 1647 | | − frame->width, frame->height, |
| 1648 | | − frame->format); |
| 1649 | | − |
| 1650 | | − avfilter_copy_frame_props(fb, frame); |
| 1651 | | − fb->buf->priv = buf; |
| 1652 | | − fb->buf->free = filter_release_buffer; |
| 1653 | | − |
| 1654 | | − buf->refcount++; |
| 1655 | | − av_buffersrc_buffer(filt_in, fb); |
| 1656 | | − |
| 1657 | | − } else |
| 1658 | | − av_buffersrc_write_frame(filt_in, frame); |
| 1623 | + ret = av_buffersrc_add_frame(filt_in, frame); |
| 1624 | + if (ret < 0) |
| 1625 | + goto the_end; |
| 1659 | 1626 | |
| 1660 | 1627 | while (ret >= 0) { |
| 1661 | | − ret = av_buffersink_read(filt_out, &picref); |
| 1628 | + ret = av_buffersink_get_frame(filt_out, frame); |
| 1662 | 1629 | if (ret < 0) { |
| 1663 | 1630 | ret = 0; |
| 1664 | 1631 | break; |
| 1665 | 1632 | } |
| 1666 | 1633 | |
| 1667 | | − avfilter_copy_buf_props(frame, picref); |
| 1668 | | − |
| 1669 | | − pts_int = picref->pts; |
| 1634 | + pts_int = frame->pts; |
| 1670 | 1635 | tb = filt_out->inputs[0]->time_base; |
| 1671 | | − pos = picref->pos; |
| 1672 | | − frame->opaque = picref; |
| 1673 | | − |
| 1674 | 1636 | if (av_cmp_q(tb, is->video_st->time_base)) { |
| 1675 | 1637 | av_unused int64_t pts1 = pts_int; |
| 1676 | 1638 | pts_int = av_rescale_q(pts_int, tb, is->video_st->time_base); |
| @@ -1680,7 +1642,7 @@ static int video_thread(void *arg) · 3 unmodified lines |
| 1680 | 1642 | is->video_st->time_base.num, is->video_st->time_base.den, pts_int); |
| 1681 | 1643 | } |
| 1682 | 1644 | pts = pts_int * av_q2d(is->video_st->time_base); |
| 1683 | | − ret = output_picture2(is, frame, pts, pos); |
| 1645 | + ret = output_picture2(is, frame, pts, 0); |
| 1684 | 1646 | } |
| 1685 | 1647 | #else |
| 1686 | 1648 | pts = pts_int * av_q2d(is->video_st->time_base); |
| @@ -1690,6 +1652,7 @@ static int video_thread(void *arg) · 3 unmodified lines |
| 1690 | 1652 | if (ret < 0) |
| 1691 | 1653 | goto the_end; |
| 1692 | 1654 | |
| 1655 | + |
| 1693 | 1656 | if (step) |
| 1694 | 1657 | if (cur_stream) |
| 1695 | 1658 | stream_pause(cur_stream); |
| @@ -1700,7 +1663,7 @@ static int video_thread(void *arg) · 4 unmodified lines |
| 1700 | 1663 | avfilter_graph_free(&graph); |
| 1701 | 1664 | #endif |
| 1702 | 1665 | av_free_packet(&pkt); |
| 1703 | | − avcodec_free_frame(&frame); |
| 1666 | + av_frame_free(&frame); |
| 1704 | 1667 | return 0; |
| 1705 | 1668 | } |
| 1706 | 1669 | |
| @@ -2090,6 +2053,8 @@ static int stream_component_open(VideoState *is, int stream_index) · 383 unmodified lines |
| 2090 | 2053 | |
| 2091 | 2054 | if (!av_dict_get(opts, "threads", NULL, 0)) |
| 2092 | 2055 | av_dict_set(&opts, "threads", "auto", 0); |
| 2056 | + if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) |
| 2057 | + av_dict_set(&opts, "refcounted_frames", "1", 0); |
| 2093 | 2058 | if (!codec || |
| 2094 | 2059 | avcodec_open2(avctx, codec, &opts) < 0) |
| 2095 | 2060 | return -1; |
| @@ -2235,9 +2200,6 @@ static void stream_component_close(VideoState *is, int stream_index) · 139 unmodified lines |
| 2235 | 2200 | |
| 2236 | 2201 | ic->streams[stream_index]->discard = AVDISCARD_ALL; |
| 2237 | 2202 | avcodec_close(avctx); |
| 2238 | | −#if CONFIG_AVFILTER |
| 2239 | | − free_buffer_pool(&is->buffer_pool); |
| 2240 | | −#endif |
| 2241 | 2203 | switch (avctx->codec_type) { |
| 2242 | 2204 | case AVMEDIA_TYPE_AUDIO: |
| 2243 | 2205 | is->audio_st = NULL; |