History

avpacket: Deprecate av_dup_packet

As documented, `av_dup_packet` is broken by design, `av_packet_ref` matches the AVFrame ref-counted API and can be safely used instead.

Luca Barbato committed 11 years ago

Commit 9b56d5c1 parent d5845335 files · +18 −16Browse files

Unified · Split

5 files
  1. doc/APIchanges +5 −3
  2. libavcodec/avcodec.h +4 −1
  3. libavcodec/avpacket.c +4 −0
  4. libavformat/matroskaenc.c +1 −6
  5. libavformat/mux.c +4 −6
doc/APIchanges+5−3
@@ -13,9 +13,11 @@ libavutil: 2015-08-28 · 12 unmodified lines
13 13
14API changes, most recent first:14API changes, most recent first:
15 15
162015-xx-xx - xxxxxxx - lavc 57.7.0 - avcodec.h162015-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
202015-xx-xx - xxxxxxx - lavc 57.5.0 - avcodec.h222015-xx-xx - xxxxxxx - lavc 57.5.0 - avcodec.h
21 Add data and linesize array to AVSubtitleRect, to be used instead of23 Add data and linesize array to AVSubtitleRect, to be used instead of
libavcodec/avcodec.h+4−1
@@ -3476,12 +3476,15 @@ int av_grow_packet(AVPacket *pkt, int grow_by); · 3475 unmodified lines
3476 */3476 */
3477int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size);3477int 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. The3481 * @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 */
3486attribute_deprecated
3483int av_dup_packet(AVPacket *pkt);3487int av_dup_packet(AVPacket *pkt);
3484#if FF_API_AVPACKET_OLD_API
3485/**3488/**
3486 * Free a packet.3489 * Free a packet.
3487 *3490 *
libavcodec/avpacket.c+4−0
@@ -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
132FF_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) \
133do { \135do { \
@@ -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}
192FF_ENABLE_DEPRECATION_WARNINGS
193#endif
190 194
191void av_packet_free_side_data(AVPacket *pkt)195void av_packet_free_side_data(AVPacket *pkt)
192{196{
libavformat/matroskaenc.c+1−6
@@ -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 video1608 // buffer an audio packet to ensure the packet containing the video
1609 // keyframe's timecode is contained in the same cluster for WebM1609 // 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 } else1612 } else
1618 ret = mkv_write_packet_internal(s, pkt);1613 ret = mkv_write_packet_internal(s, pkt);
1619 return ret;1614 return ret;
libavformat/mux.c+4−6
@@ -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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t