As documented, `av_dup_packet` is broken by design, `av_packet_ref` matches the AVFrame ref-counted API and can be safely used instead.
Unified · Split
| @@ -13,9 +13,11 @@ libavutil: 2015-08-28 · 12 unmodified lines | |||
| 13 | 13 | ||
| 14 | API changes, most recent first: | 14 | API changes, most recent first: |
| 15 | 15 | ||
| 16 | 2015-xx-xx - xxxxxxx - lavc 57.7.0 - avcodec.h | 16 | 2015-xx-xx - lavc 57.7.0 - avcodec.h |
| 17 | Deprecate av_free_packet(). Use av_packet_unref() as replacement, | 17 | xxxxxx - Deprecate av_free_packet(). Use av_packet_unref() as replacement, |
| 18 | it resets the packet in a more consistent way. | 18 | it resets the packet in a more consistent way. |
| 19 | xxxxxx - Deprecate av_dup_packet(), it is a no-op for most cases. | ||
| 20 | Use av_packet_ref() to make a non-refcounted AVPacket refcounted. | ||
| 19 | 21 | ||
| 20 | 2015-xx-xx - xxxxxxx - lavc 57.5.0 - avcodec.h | 22 | 2015-xx-xx - xxxxxxx - lavc 57.5.0 - avcodec.h |
| 21 | Add data and linesize array to AVSubtitleRect, to be used instead of | 23 | Add data and linesize array to AVSubtitleRect, to be used instead of |
| @@ -3476,12 +3476,15 @@ int av_grow_packet(AVPacket *pkt, int grow_by); · 3475 unmodified lines | |||
| 3476 | */ | 3476 | */ |
| 3477 | int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size); | 3477 | int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size); |
| 3478 | 3478 | ||
| 3479 | #if FF_API_AVPACKET_OLD_API | ||
| 3479 | /** | 3480 | /** |
| 3480 | * @warning This is a hack - the packet memory allocation stuff is broken. The | 3481 | * @warning This is a hack - the packet memory allocation stuff is broken. The |
| 3481 | * packet is allocated if it was not really allocated. | 3482 | * packet is allocated if it was not really allocated. |
| 3483 | * | ||
| 3484 | * @deprecated Use av_packet_ref | ||
| 3482 | */ | 3485 | */ |
| 3486 | attribute_deprecated | ||
| 3483 | int av_dup_packet(AVPacket *pkt); | 3487 | int av_dup_packet(AVPacket *pkt); |
| 3484 | #if FF_API_AVPACKET_OLD_API | ||
| 3485 | /** | 3488 | /** |
| 3486 | * Free a packet. | 3489 | * Free a packet. |
| 3487 | * | 3490 | * |
| @@ -128,6 +128,8 @@ int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size) · 127 unmodified lines | |||
| 128 | return 0; | 128 | return 0; |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | #if FF_API_AVPACKET_OLD_API | ||
| 132 | FF_DISABLE_DEPRECATION_WARNINGS | ||
| 131 | #define ALLOC_MALLOC(data, size) data = av_malloc(size) | 133 | #define ALLOC_MALLOC(data, size) data = av_malloc(size) |
| 132 | #define ALLOC_BUF(data, size) \ | 134 | #define ALLOC_BUF(data, size) \ |
| 133 | do { \ | 135 | do { \ |
| @@ -187,6 +189,8 @@ failed_alloc: · 53 unmodified lines | |||
| 187 | av_packet_unref(pkt); | 189 | av_packet_unref(pkt); |
| 188 | return AVERROR(ENOMEM); | 190 | return AVERROR(ENOMEM); |
| 189 | } | 191 | } |
| 192 | FF_ENABLE_DEPRECATION_WARNINGS | ||
| 193 | #endif | ||
| 190 | 194 | ||
| 191 | void av_packet_free_side_data(AVPacket *pkt) | 195 | void av_packet_free_side_data(AVPacket *pkt) |
| 192 | { | 196 | { |
| @@ -1608,12 +1608,7 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt) · 1607 unmodified lines | |||
| 1608 | // buffer an audio packet to ensure the packet containing the video | 1608 | // buffer an audio packet to ensure the packet containing the video |
| 1609 | // keyframe's timecode is contained in the same cluster for WebM | 1609 | // keyframe's timecode is contained in the same cluster for WebM |
| 1610 | if (codec_type == AVMEDIA_TYPE_AUDIO) { | 1610 | if (codec_type == AVMEDIA_TYPE_AUDIO) { |
| 1611 | mkv->cur_audio_pkt = *pkt; | 1611 | ret = av_packet_ref(&mkv->cur_audio_pkt, pkt); |
| 1612 | if (pkt->buf) { | ||
| 1613 | mkv->cur_audio_pkt.buf = av_buffer_ref(pkt->buf); | ||
| 1614 | ret = mkv->cur_audio_pkt.buf ? 0 : AVERROR(ENOMEM); | ||
| 1615 | } else | ||
| 1616 | ret = av_dup_packet(&mkv->cur_audio_pkt); | ||
| 1617 | } else | 1612 | } else |
| 1618 | ret = mkv_write_packet_internal(s, pkt); | 1613 | ret = mkv_write_packet_internal(s, pkt); |
| 1619 | return ret; | 1614 | return ret; |
| @@ -416,12 +416,8 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, · 415 unmodified lines | |||
| 416 | this_pktl = av_mallocz(sizeof(AVPacketList)); | 416 | this_pktl = av_mallocz(sizeof(AVPacketList)); |
| 417 | if (!this_pktl) | 417 | if (!this_pktl) |
| 418 | return AVERROR(ENOMEM); | 418 | return AVERROR(ENOMEM); |
| 419 | this_pktl->pkt = *pkt; | 419 | |
| 420 | pkt->buf = NULL; | 420 | if ((ret = av_packet_ref(&this_pktl->pkt, pkt)) < 0) { |
| 421 | pkt->side_data = NULL; | ||
| 422 | pkt->side_data_elems = 0; | ||
| 423 | // Duplicate the packet if it uses non-allocated memory | ||
| 424 | if ((ret = av_dup_packet(&this_pktl->pkt)) < 0) { | ||
| 425 | av_free(this_pktl); | 421 | av_free(this_pktl); |
| 426 | return ret; | 422 | return ret; |
| 427 | } | 423 | } |
| @@ -450,6 +446,8 @@ next_non_null: · 22 unmodified lines | |||
| 450 | s->streams[pkt->stream_index]->last_in_packet_buffer = | 446 | s->streams[pkt->stream_index]->last_in_packet_buffer = |
| 451 | *next_point = this_pktl; | 447 | *next_point = this_pktl; |
| 452 | 448 | ||
| 449 | av_packet_unref(pkt); | ||
| 450 | |||
| 453 | return 0; | 451 | return 0; |
| 454 | } | 452 | } |
| 455 | 453 | ||