aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/matroskaenc.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/matroskaenc.c
parent1cec0624d0e6f48590283a57169b58b9fe8449d3 (diff)
downloadffmpeg-1afddbe59e96af75f1c07605afc95615569f388f.tar.gz
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/matroskaenc.c')
-rw-r--r--libavformat/matroskaenc.c28
1 files changed, 7 insertions, 21 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index b37d10cba1..b1e4a1e146 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -90,7 +90,6 @@ typedef struct MatroskaMuxContext {
mkv_cues *cues;
mkv_track *tracks;
- unsigned int audio_buffer_size;
AVPacket cur_audio_pkt;
int have_attachments;
@@ -969,7 +968,6 @@ static int mkv_write_header(AVFormatContext *s)
av_init_packet(&mkv->cur_audio_pkt);
mkv->cur_audio_pkt.size = 0;
- mkv->audio_buffer_size = 0;
avio_flush(pb);
return 0;
@@ -1180,19 +1178,6 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
return 0;
}
-static int mkv_copy_packet(MatroskaMuxContext *mkv, const AVPacket *pkt)
-{
- uint8_t *data = mkv->cur_audio_pkt.data;
- mkv->cur_audio_pkt = *pkt;
- mkv->cur_audio_pkt.data = av_fast_realloc(data, &mkv->audio_buffer_size, pkt->size);
- if (!mkv->cur_audio_pkt.data)
- return AVERROR(ENOMEM);
-
- memcpy(mkv->cur_audio_pkt.data, pkt->data, pkt->size);
- mkv->cur_audio_pkt.size = pkt->size;
- return 0;
-}
-
static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
{
MatroskaMuxContext *mkv = s->priv_data;
@@ -1219,7 +1204,7 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
// check if we have an audio packet cached
if (mkv->cur_audio_pkt.size > 0) {
ret = mkv_write_packet_internal(s, &mkv->cur_audio_pkt);
- mkv->cur_audio_pkt.size = 0;
+ av_free_packet(&mkv->cur_audio_pkt);
if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Could not write cached audio packet ret:%d\n", ret);
return ret;
@@ -1228,9 +1213,11 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
// buffer an audio packet to ensure the packet containing the video
// keyframe's timecode is contained in the same cluster for WebM
- if (codec->codec_type == AVMEDIA_TYPE_AUDIO)
- ret = mkv_copy_packet(mkv, pkt);
- else
+ if (codec->codec_type == AVMEDIA_TYPE_AUDIO) {
+ mkv->cur_audio_pkt = *pkt;
+ mkv->cur_audio_pkt.buf = av_buffer_ref(pkt->buf);
+ ret = mkv->cur_audio_pkt.buf ? 0 : AVERROR(ENOMEM);
+ } else
ret = mkv_write_packet_internal(s, pkt);
return ret;
}
@@ -1245,7 +1232,7 @@ static int mkv_write_trailer(AVFormatContext *s)
// check if we have an audio packet cached
if (mkv->cur_audio_pkt.size > 0) {
ret = mkv_write_packet_internal(s, &mkv->cur_audio_pkt);
- mkv->cur_audio_pkt.size = 0;
+ av_free_packet(&mkv->cur_audio_pkt);
if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Could not write cached audio packet ret:%d\n", ret);
return ret;
@@ -1282,7 +1269,6 @@ static int mkv_write_trailer(AVFormatContext *s)
av_free(mkv->tracks);
av_freep(&mkv->cues->entries);
av_freep(&mkv->cues);
- av_destruct_packet(&mkv->cur_audio_pkt);
return 0;
}