History

avcodec/packet: deprecate av_init_packet()

Once removed, sizeof(AVPacket) will stop being a part of the public ABI.

James Almer committed 5 years ago

Commit f7db77b1 parent a1cd4195 files · +46 −13Browse files

Unified · Split

5 files
  1. doc/APIchanges +5 −0
  2. libavcodec/avpacket.c +15 −8
  3. libavcodec/packet.h +18 −4
  4. libavcodec/version.h +4 −1
  5. libavformat/avformat.h +4 −0
doc/APIchanges+5−0
@@ -15,6 +15,11 @@ libavutil: 2017-10-21 · 14 unmodified lines
1515
1616 API changes, most recent first:
1717
18+2021-03-xx - xxxxxxxxxx - lavc 58.133.100 - codec.h
19+ Deprecated av_init_packet(). Once removed, sizeof(AVPacket) will
20+ no longer be a part of the public ABI.
21+ Deprecated AVPacketList.
22+
1823 2021-03-xx - xxxxxxxxxx - lavc 58.132.100 - codec.h
1924 Add AV_CODEC_CAP_OTHER_THREADS as a new name for
2025 AV_CODEC_CAP_AUTO_THREADS. AV_CODEC_CAP_AUTO_THREADS
libavcodec/avpacket.c+15−8
@@ -32,6 +32,7 @@ · 31 unmodified lines
3232 #include "packet.h"
3333 #include "packet_internal.h"
3434
35+#if FF_API_INIT_PACKET
3536 void av_init_packet(AVPacket *pkt)
3637 {
3738 pkt->pts = AV_NOPTS_VALUE;
@@ -49,6 +50,16 @@ FF_ENABLE_DEPRECATION_WARNINGS · 11 unmodified lines
4950 pkt->side_data = NULL;
5051 pkt->side_data_elems = 0;
5152 }
53+#endif
54+
55+static void get_packet_defaults(AVPacket *pkt)
56+{
57+ memset(pkt, 0, sizeof(*pkt));
58+
59+ pkt->pts = AV_NOPTS_VALUE;
60+ pkt->dts = AV_NOPTS_VALUE;
61+ pkt->pos = -1;
62+}
5263
5364 AVPacket *av_packet_alloc(void)
5465 {
@@ -56,7 +67,7 @@ AVPacket *av_packet_alloc(void) · 1 unmodified line
5667 if (!pkt)
5768 return pkt;
5869
59− av_init_packet(pkt);
70+ get_packet_defaults(pkt);
6071
6172 return pkt;
6273 }
@@ -92,7 +103,7 @@ int av_new_packet(AVPacket *pkt, int size) · 29 unmodified lines
92103 if (ret < 0)
93104 return ret;
94105
95− av_init_packet(pkt);
106+ get_packet_defaults(pkt);
96107 pkt->buf = buf;
97108 pkt->data = buf->data;
98109 pkt->size = size;
@@ -611,9 +622,7 @@ void av_packet_unref(AVPacket *pkt) · 512 unmodified lines
611622 {
612623 av_packet_free_side_data(pkt);
613624 av_buffer_unref(&pkt->buf);
614− av_init_packet(pkt);
615− pkt->data = NULL;
616− pkt->size = 0;
625+ get_packet_defaults(pkt);
617626 }
618627
619628 int av_packet_ref(AVPacket *dst, const AVPacket *src)
@@ -668,9 +677,7 @@ AVPacket *av_packet_clone(const AVPacket *src) · 48 unmodified lines
668677 void av_packet_move_ref(AVPacket *dst, AVPacket *src)
669678 {
670679 *dst = *src;
671− av_init_packet(src);
672− src->data = NULL;
673− src->size = 0;
680+ get_packet_defaults(src);
674681 }
675682
676683 int av_packet_make_refcounted(AVPacket *pkt)
libavcodec/packet.h+18−4
@@ -323,10 +323,6 @@ typedef struct AVPacketSideData { · 322 unmodified lines
323323 * packets, with no compressed data, containing only side data
324324 * (e.g. to update some stream parameters at the end of encoding).
325325 *
326− * AVPacket is one of the few structs in FFmpeg, whose size is a part of public
327− * ABI. Thus it may be allocated on stack and no new fields can be added to it
328− * without libavcodec and libavformat major bump.
329− *
330326 * The semantics of data ownership depends on the buf field.
331327 * If it is set, the packet data is dynamically allocated and is
332328 * valid indefinitely until a call to av_packet_unref() reduces the
@@ -338,6 +334,12 @@ typedef struct AVPacketSideData { · 5 unmodified lines
338334 * The side data is always allocated with av_malloc(), copied by
339335 * av_packet_ref() and freed by av_packet_unref().
340336 *
337+ * sizeof(AVPacket) being a part of the public ABI is deprecated. once
338+ * av_init_packet() is removed, new packets will only be able to be allocated
339+ * with av_packet_alloc(), and new fields may be added to the end of the struct
340+ * with a minor bump.
341+ *
342+ * @see av_packet_alloc
341343 * @see av_packet_ref
342344 * @see av_packet_unref
343345 */
@@ -397,10 +399,13 @@ typedef struct AVPacket { · 53 unmodified lines
397399 #endif
398400 } AVPacket;
399401
402+#if FF_API_INIT_PACKET
403+attribute_deprecated
400404 typedef struct AVPacketList {
401405 AVPacket pkt;
402406 struct AVPacketList *next;
403407 } AVPacketList;
408+#endif
404409
405410 #define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe
406411 #define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
@@ -464,6 +469,7 @@ AVPacket *av_packet_clone(const AVPacket *src); · 57 unmodified lines
464469 */
465470 void av_packet_free(AVPacket **pkt);
466471
472+#if FF_API_INIT_PACKET
467473 /**
468474 * Initialize optional fields of a packet with default values.
469475 *
@@ -471,8 +477,16 @@ void av_packet_free(AVPacket **pkt); · 1 unmodified line
471477 * initialized separately.
472478 *
473479 * @param pkt packet
480+ *
481+ * @see av_packet_alloc
482+ * @see av_packet_unref
483+ *
484+ * @deprecated This function is deprecated. Once it's removed,
485+ sizeof(AVPacket) will not be a part of the ABI anymore.
474486 */
487+attribute_deprecated
475488 void av_init_packet(AVPacket *pkt);
489+#endif
476490
477491 /**
478492 * Allocate the payload of a packet and initialize its fields with
libavcodec/version.h+4−1
@@ -28,7 +28,7 @@ · 27 unmodified lines
2828 #include "libavutil/version.h"
2929
3030 #define LIBAVCODEC_VERSION_MAJOR 58
31−#define LIBAVCODEC_VERSION_MINOR 132
31+#define LIBAVCODEC_VERSION_MINOR 133
3232 #define LIBAVCODEC_VERSION_MICRO 100
3333
3434 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
@@ -165,5 +165,8 @@ · 130 unmodified lines
165165 #ifndef FF_API_AUTO_THREADS
166166 #define FF_API_AUTO_THREADS (LIBAVCODEC_VERSION_MAJOR < 60)
167167 #endif
168+#ifndef FF_API_INIT_PACKET
169+#define FF_API_INIT_PACKET (LIBAVCODEC_VERSION_MAJOR < 60)
170+#endif
168171
169172 #endif /* AVCODEC_VERSION_H */
libavformat/avformat.h+4−0
@@ -954,7 +954,11 @@ typedef struct AVStream { · 953 unmodified lines
954954 * decoding: set by libavformat, must not be modified by the caller.
955955 * encoding: unused
956956 */
957+#if FF_API_INIT_PACKET
957958 AVPacket attached_pic;
959+#else
960+ AVPacket *attached_pic;
961+#endif
958962
959963 /**
960964 * An array of side data that applies to the whole stream (i.e. the

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