summaryrefslogtreecommitdiff
path: root/libavformat/mpegts.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2012-10-31 08:53:18 +0100
committerAnton Khirnov <anton@khirnov.net>2013-03-08 07:33:45 +0100
commit1afddbe59e96af75f1c07605afc95615569f388f (patch)
tree0e8223d9813de6976ec50dc1a5a7c7bf9a099450 /libavformat/mpegts.c
parent1cec0624d0e6f48590283a57169b58b9fe8449d3 (diff)
avpacket: use AVBuffer to allow refcounting the packets.
This will allow us to avoid copying the packets in many cases. This breaks ABI.
Diffstat (limited to 'libavformat/mpegts.c')
-rw-r--r--libavformat/mpegts.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 399b0743ce..61b8b55c42 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavutil/buffer.h"
#include "libavutil/crc.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/log.h"
@@ -173,7 +174,7 @@ typedef struct PESContext {
int64_t pts, dts;
int64_t ts_packet_pos; /**< position of first TS packet of this PES packet */
uint8_t header[MAX_PES_HEADER_SIZE];
- uint8_t *buffer;
+ AVBufferRef *buffer;
SLConfigDescr sl;
} PESContext;
@@ -364,7 +365,7 @@ static void mpegts_close_filter(MpegTSContext *ts, MpegTSFilter *filter)
av_freep(&filter->u.section_filter.section_buf);
else if (filter->type == MPEGTS_PES) {
PESContext *pes = filter->u.pes_filter.opaque;
- av_freep(&pes->buffer);
+ av_buffer_unref(&pes->buffer);
/* referenced private data will be freed later in
* avformat_close_input */
if (!((PESContext *)filter->u.pes_filter.opaque)->st) {
@@ -635,8 +636,8 @@ static void new_pes_packet(PESContext *pes, AVPacket *pkt)
{
av_init_packet(pkt);
- pkt->destruct = av_destruct_packet;
- pkt->data = pes->buffer;
+ pkt->buf = pes->buffer;
+ pkt->data = pes->buffer->data;
pkt->size = pes->data_index;
if(pes->total_size != MAX_PES_PAYLOAD &&
@@ -793,7 +794,8 @@ static int mpegts_push_data(MpegTSFilter *filter,
pes->total_size = MAX_PES_PAYLOAD;
/* allocate pes buffer */
- pes->buffer = av_malloc(pes->total_size+FF_INPUT_BUFFER_PADDING_SIZE);
+ pes->buffer = av_buffer_alloc(pes->total_size +
+ FF_INPUT_BUFFER_PADDING_SIZE);
if (!pes->buffer)
return AVERROR(ENOMEM);
@@ -895,7 +897,7 @@ static int mpegts_push_data(MpegTSFilter *filter,
if (pes->data_index > 0 && pes->data_index+buf_size > pes->total_size) {
new_pes_packet(pes, ts->pkt);
pes->total_size = MAX_PES_PAYLOAD;
- pes->buffer = av_malloc(pes->total_size+FF_INPUT_BUFFER_PADDING_SIZE);
+ pes->buffer = av_buffer_alloc(pes->total_size + FF_INPUT_BUFFER_PADDING_SIZE);
if (!pes->buffer)
return AVERROR(ENOMEM);
ts->stop_parse = 1;
@@ -904,7 +906,7 @@ static int mpegts_push_data(MpegTSFilter *filter,
// not sure if this is legal in ts but see issue #2392
buf_size = pes->total_size;
}
- memcpy(pes->buffer+pes->data_index, p, buf_size);
+ memcpy(pes->buffer->data + pes->data_index, p, buf_size);
pes->data_index += buf_size;
}
buf_size = 0;
@@ -1781,7 +1783,7 @@ static int handle_packets(MpegTSContext *ts, int nb_packets)
if (ts->pids[i]) {
if (ts->pids[i]->type == MPEGTS_PES) {
PESContext *pes = ts->pids[i]->u.pes_filter.opaque;
- av_freep(&pes->buffer);
+ av_buffer_unref(&pes->buffer);
pes->data_index = 0;
pes->state = MPEGTS_SKIP; /* skip until pes header */
}