On Thu, Apr 07, 2011 at 06:54:29AM +0200, Janne Grunau wrote:
> On Wed, Apr 06, 2011 at 10:26:08PM +0200, Kostya Shishkov wrote:
> > This adds side information to AVPacket
> >
> > ---
> > libavcodec/avcodec.h | 21 +++++++++++++++++++++
> > libavcodec/avpacket.c | 39 +++++++++++++++++++++++++++++++++++++++
> > libavcodec/version.h | 2 +-
> > 3 files changed, 61 insertions(+), 1 deletions(-)
> >
> > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> > index 95a933d..4b7bedc 100644
> > --- a/libavcodec/avcodec.h
> > +++ b/libavcodec/avcodec.h
> > @@ -1054,6 +1054,14 @@ typedef struct AVPacket {
> > int64_t dts;
> > uint8_t *data;
> > int size;
> > + /**
> > + * Additional packet data that may be provided by container. If present
> > + * it should declare side data type and size.
> > + */
> > + uint8_t *side_data;
> > + int side_data_size;
> > + int side_data_type;
> > +
> > int stream_index;
> > int flags;
> > /**
> > @@ -1089,6 +1097,9 @@ typedef struct AVPacket {
> > #define PKT_FLAG_KEY AV_PKT_FLAG_KEY
> > #endif
> >
> > +#define AV_PKT_DATA_NONE 0 ///< no packet side information
> > +#define AV_PKT_DATA_PAL 1 ///< packet side information contains new
> > palette
>
> enum?
not in that neighbourhood
> > +
> > /**
> > * Audio Video Frame.
> > * New fields can be added to the end of FF_COMMON_FRAME with minor version
> > @@ -3190,6 +3201,16 @@ void av_shrink_packet(AVPacket *pkt, int size);
> > int av_grow_packet(AVPacket *pkt, int grow_by);
> >
> > /**
> > + * Allocate the side information of a packet.
> > + *
> > + * @param pkt packet
> > + * @param type side information type (AV_PKT_DATA_*)
> > + * @param size wanted side information size
> > + * @return 0 if OK, AVERROR_xxx otherwise
> > + */
> > +int av_new_packet_side_data(AVPacket *pkt, int type, int size);
>
> av_packet_new_side_data() is less confusing
renamed
> > +/**
> > * @warning This is a hack - the packet memory allocation stuff is broken.
> > The
> > * packet is allocated if it was not really allocated.
> > */
> > diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> > index f6aef20..ef16bbd 100644
> > --- a/libavcodec/avpacket.c
> > +++ b/libavcodec/avpacket.c
> > @@ -26,12 +26,18 @@
> > void av_destruct_packet_nofree(AVPacket *pkt)
> > {
> > pkt->data = NULL; pkt->size = 0;
> > + pkt->side_data = NULL;
> > + pkt->side_data_size = 0;
>
> is av_destruct_packet_nofree only called on duplicated packets?
> otherwise this leaks memory in cases there only packet.data is used and
> freed.
yes, it's for duplicated packets only
>From bb18bdff543fd8c5d3e3c89350520be7932594b9 Mon Sep 17 00:00:00 2001
From: Kostya Shishkov <[email protected]>
Date: Thu, 7 Apr 2011 09:45:47 +0200
Subject: [PATCH 1/2] introduce side information in AVPacket
---
libavcodec/avcodec.h | 21 +++++++++++++++++++++
libavcodec/avpacket.c | 41 +++++++++++++++++++++++++++++++++++++++++
libavcodec/version.h | 2 +-
3 files changed, 63 insertions(+), 1 deletions(-)
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 95a933d..3731a6c 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1054,6 +1054,14 @@ typedef struct AVPacket {
int64_t dts;
uint8_t *data;
int size;
+ /**
+ * Additional packet data that may be provided by container. If present
+ * it should declare side data type and size.
+ */
+ uint8_t *side_data;
+ int side_data_size;
+ int side_data_type;
+
int stream_index;
int flags;
/**
@@ -1089,6 +1097,9 @@ typedef struct AVPacket {
#define PKT_FLAG_KEY AV_PKT_FLAG_KEY
#endif
+#define AV_PKT_DATA_NONE 0 ///< no packet side information
+#define AV_PKT_DATA_PAL 1 ///< packet side information contains new palette
+
/**
* Audio Video Frame.
* New fields can be added to the end of FF_COMMON_FRAME with minor version
@@ -3190,6 +3201,16 @@ void av_shrink_packet(AVPacket *pkt, int size);
int av_grow_packet(AVPacket *pkt, int grow_by);
/**
+ * Allocate the side information of a packet.
+ *
+ * @param pkt packet
+ * @param type side information type (AV_PKT_DATA_*)
+ * @param size wanted side information size
+ * @return 0 if OK, AVERROR_xxx otherwise
+ */
+int av_packet_new_side_data(AVPacket *pkt, int type, int size);
+
+/**
* @warning This is a hack - the packet memory allocation stuff is broken. The
* packet is allocated if it was not really allocated.
*/
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index f6aef20..2cce0f1 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -26,12 +26,18 @@
void av_destruct_packet_nofree(AVPacket *pkt)
{
pkt->data = NULL; pkt->size = 0;
+ pkt->side_data = NULL;
+ pkt->side_data_size = 0;
}
void av_destruct_packet(AVPacket *pkt)
{
av_free(pkt->data);
pkt->data = NULL; pkt->size = 0;
+ av_free(pkt->side_data);
+ pkt->side_data = NULL;
+ pkt->side_data_size = 0;
+ pkt->side_data_type = AV_PKT_DATA_NONE;
}
void av_init_packet(AVPacket *pkt)
@@ -44,6 +50,9 @@ void av_init_packet(AVPacket *pkt)
pkt->flags = 0;
pkt->stream_index = 0;
pkt->destruct= NULL;
+ pkt->side_data = NULL;
+ pkt->side_data_size = 0;
+ pkt->side_data_type = AV_PKT_DATA_NONE;
}
int av_new_packet(AVPacket *pkt, int size)
@@ -59,6 +68,9 @@ int av_new_packet(AVPacket *pkt, int size)
av_init_packet(pkt);
pkt->data = data;
pkt->size = size;
+ pkt->side_data = NULL;
+ pkt->side_data_size = 0;
+ pkt->side_data_type = AV_PKT_DATA_NONE;
pkt->destruct = av_destruct_packet;
if(!data)
return AVERROR(ENOMEM);
@@ -89,6 +101,21 @@ int av_grow_packet(AVPacket *pkt, int grow_by)
return 0;
}
+int av_packet_new_side_data(AVPacket *pkt, int type, int size)
+{
+ void *new_ptr;
+ if ((unsigned)size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE)
+ return -1;
+ new_ptr = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!new_ptr)
+ return AVERROR(ENOMEM);
+ pkt->side_data = new_ptr;
+ pkt->side_data_size = size;
+ pkt->side_data_type = type;
+ memset(pkt->side_data + pkt->side_data_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+ return 0;
+}
+
int av_dup_packet(AVPacket *pkt)
{
if (((pkt->destruct == av_destruct_packet_nofree) || (pkt->destruct == NULL)) && pkt->data) {
@@ -96,6 +123,9 @@ int av_dup_packet(AVPacket *pkt)
/* We duplicate the packet and don't forget to add the padding again. */
if((unsigned)pkt->size > (unsigned)pkt->size + FF_INPUT_BUFFER_PADDING_SIZE)
return AVERROR(ENOMEM);
+ if((unsigned)pkt->side_data_size >
+ (unsigned)pkt->side_data_size + FF_INPUT_BUFFER_PADDING_SIZE)
+ return AVERROR(ENOMEM);
data = av_malloc(pkt->size + FF_INPUT_BUFFER_PADDING_SIZE);
if (!data) {
return AVERROR(ENOMEM);
@@ -103,6 +133,15 @@ int av_dup_packet(AVPacket *pkt)
memcpy(data, pkt->data, pkt->size);
memset(data + pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
pkt->data = data;
+ if (pkt->side_data) {
+ data = av_malloc(pkt->side_data_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (!data) {
+ return AVERROR(ENOMEM);
+ }
+ memcpy(data, pkt->side_data, pkt->side_data_size);
+ memset(data + pkt->side_data_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+ pkt->side_data = data;
+ }
pkt->destruct = av_destruct_packet;
}
return 0;
@@ -113,5 +152,7 @@ void av_free_packet(AVPacket *pkt)
if (pkt) {
if (pkt->destruct) pkt->destruct(pkt);
pkt->data = NULL; pkt->size = 0;
+ pkt->side_data = NULL;
+ pkt->side_data_size = 0;
}
}
diff --git a/libavcodec/version.h b/libavcodec/version.h
index b93e753..945f395 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -21,7 +21,7 @@
#define AVCODEC_VERSION_H
#define LIBAVCODEC_VERSION_MAJOR 52
-#define LIBAVCODEC_VERSION_MINOR 117
+#define LIBAVCODEC_VERSION_MINOR 118
#define LIBAVCODEC_VERSION_MICRO 0
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
--
1.7.0.4
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel