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
1313
1414 API changes, most recent first:
1515
16−2015-xx-xx - xxxxxxx - lavc 57.7.0 - avcodec.h
17− Deprecate av_free_packet(). Use av_packet_unref() as replacement,
18− it resets the packet in a more consistent way.
16+2015-xx-xx - lavc 57.7.0 - avcodec.h
17+ xxxxxx - Deprecate av_free_packet(). Use av_packet_unref() as replacement,
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.
1921
2022 2015-xx-xx - xxxxxxx - lavc 57.5.0 - avcodec.h
2123 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
34763476 */
34773477 int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size);
34783478
3479+#if FF_API_AVPACKET_OLD_API
34793480 /**
34803481 * @warning This is a hack - the packet memory allocation stuff is broken. The
34813482 * packet is allocated if it was not really allocated.
3483+ *
3484+ * @deprecated Use av_packet_ref
34823485 */
3486+attribute_deprecated
34833487 int av_dup_packet(AVPacket *pkt);
3484−#if FF_API_AVPACKET_OLD_API
34853488 /**
34863489 * Free a packet.
34873490 *
libavcodec/avpacket.c+4−0
@@ -128,6 +128,8 @@ int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size) · 127 unmodified lines
128128 return 0;
129129 }
130130
131+#if FF_API_AVPACKET_OLD_API
132+FF_DISABLE_DEPRECATION_WARNINGS
131133 #define ALLOC_MALLOC(data, size) data = av_malloc(size)
132134 #define ALLOC_BUF(data, size) \
133135 do { \
@@ -187,6 +189,8 @@ failed_alloc: · 53 unmodified lines
187189 av_packet_unref(pkt);
188190 return AVERROR(ENOMEM);
189191 }
192+FF_ENABLE_DEPRECATION_WARNINGS
193+#endif
190194
191195 void av_packet_free_side_data(AVPacket *pkt)
192196 {
libavformat/matroskaenc.c+1−6
@@ -1608,12 +1608,7 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt) · 1607 unmodified lines
16081608 // buffer an audio packet to ensure the packet containing the video
16091609 // keyframe's timecode is contained in the same cluster for WebM
16101610 if (codec_type == AVMEDIA_TYPE_AUDIO) {
1611− 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);
1611+ ret = av_packet_ref(&mkv->cur_audio_pkt, pkt);
16171612 } else
16181613 ret = mkv_write_packet_internal(s, pkt);
16191614 return ret;
libavformat/mux.c+4−6
@@ -416,12 +416,8 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, · 415 unmodified lines
416416 this_pktl = av_mallocz(sizeof(AVPacketList));
417417 if (!this_pktl)
418418 return AVERROR(ENOMEM);
419− this_pktl->pkt = *pkt;
420− pkt->buf = NULL;
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) {
419+
420+ if ((ret = av_packet_ref(&this_pktl->pkt, pkt)) < 0) {
425421 av_free(this_pktl);
426422 return ret;
427423 }
@@ -450,6 +446,8 @@ next_non_null: · 22 unmodified lines
450446 s->streams[pkt->stream_index]->last_in_packet_buffer =
451447 *next_point = this_pktl;
452448
449+ av_packet_unref(pkt);
450+
453451 return 0;
454452 }
455453

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