}
}
+static void deinit_muxer(AVFormatContext *s)
+{
+ if (s->oformat && s->oformat->deinit && s->internal->initialized)
+ s->oformat->deinit(s);
+ s->internal->initialized =
+ s->internal->streams_initialized = 0;
+}
+
int avformat_init_output(AVFormatContext *s, AVDictionary **options)
{
int ret = 0;
return streams_already_initialized;
fail:
- if (s->oformat->deinit)
- s->oformat->deinit(s);
+ deinit_muxer(s);
return ret;
}
if (ret < 0) {
pkt->pts = pts_backup;
pkt->dts = dts_backup;
- }
+ } else
+ s->streams[pkt->stream_index]->nb_frames++;
return ret;
}
return ret;
#endif
- ret = write_packet(s, pkt);
- if (ret >= 0 && s->pb && s->pb->error < 0)
- ret = s->pb->error;
-
- if (ret >= 0)
- s->streams[pkt->stream_index]->nb_frames++;
- return ret;
+ return write_packet(s, pkt);
}
#define CHUNK_START 0x1000
{
int ret;
AVPacketList **next_point, *this_pktl;
- AVStream *st = s->streams[pkt->stream_index];
- int chunked = s->max_chunk_size || s->max_chunk_duration;
+ AVStream *st = s->streams[pkt->stream_index];
+ int chunked = s->max_chunk_size || s->max_chunk_duration;
- this_pktl = av_mallocz(sizeof(AVPacketList));
+ this_pktl = av_malloc(sizeof(AVPacketList));
if (!this_pktl)
return AVERROR(ENOMEM);
- if ((pkt->flags & AV_PKT_FLAG_UNCODED_FRAME)) {
+ if (pkt->flags & AV_PKT_FLAG_UNCODED_FRAME) {
av_assert0(pkt->size == UNCODED_FRAME_PACKET_SIZE);
av_assert0(((AVFrame *)pkt->data)->buf);
- this_pktl->pkt = *pkt;
- pkt->buf = NULL;
- pkt->side_data = NULL;
- pkt->side_data_elems = 0;
} else {
- if ((ret = av_packet_ref(&this_pktl->pkt, pkt)) < 0) {
+ if ((ret = av_packet_make_refcounted(pkt)) < 0) {
av_free(this_pktl);
return ret;
}
}
- if (s->streams[pkt->stream_index]->last_in_packet_buffer) {
+ av_packet_move_ref(&this_pktl->pkt, pkt);
+ pkt = &this_pktl->pkt;
+
+ if (st->last_in_packet_buffer) {
next_point = &(st->last_in_packet_buffer->next);
} else {
next_point = &s->internal->packet_buffer;
st->interleaver_chunk_duration += pkt->duration;
if ( (s->max_chunk_size && st->interleaver_chunk_size > s->max_chunk_size)
|| (max && st->interleaver_chunk_duration > max)) {
- st->interleaver_chunk_size = 0;
- this_pktl->pkt.flags |= CHUNK_START;
+ st->interleaver_chunk_size = 0;
+ pkt->flags |= CHUNK_START;
if (max && st->interleaver_chunk_duration > max) {
int64_t syncoffset = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)*max/2;
int64_t syncto = av_rescale(pkt->dts + syncoffset, 1, max)*max - syncoffset;
}
}
if (*next_point) {
- if (chunked && !(this_pktl->pkt.flags & CHUNK_START))
+ if (chunked && !(pkt->flags & CHUNK_START))
goto next_non_null;
if (compare(s, &s->internal->packet_buffer_end->pkt, pkt)) {
this_pktl->next = *next_point;
- s->streams[pkt->stream_index]->last_in_packet_buffer =
- *next_point = this_pktl;
-
- av_packet_unref(pkt);
+ st->last_in_packet_buffer = *next_point = this_pktl;
return 0;
}
return ret;
ret = write_packet(s, &opkt);
- if (ret >= 0)
- s->streams[opkt.stream_index]->nb_frames++;
av_packet_unref(&opkt);
if (ret < 0)
return ret;
- if(s->pb && s->pb->error)
- return s->pb->error;
}
fail:
av_packet_unref(pkt);
break;
ret = write_packet(s, &pkt);
- if (ret >= 0)
- s->streams[pkt.stream_index]->nb_frames++;
av_packet_unref(&pkt);
if (ret < 0)
goto fail;
- if(s->pb && s->pb->error)
- goto fail;
}
fail:
}
}
- if (s->oformat->deinit)
- s->oformat->deinit(s);
-
- s->internal->initialized =
- s->internal->streams_initialized = 0;
+ deinit_muxer(s);
if (s->pb)
avio_flush(s->pb);
return ret;
}
-static int av_write_uncoded_frame_internal(AVFormatContext *s, int stream_index,
- AVFrame *frame, int interleaved)
+static int write_uncoded_frame_internal(AVFormatContext *s, int stream_index,
+ AVFrame *frame, int interleaved)
{
AVPacket pkt, *pktp;
int av_write_uncoded_frame(AVFormatContext *s, int stream_index,
AVFrame *frame)
{
- return av_write_uncoded_frame_internal(s, stream_index, frame, 0);
+ return write_uncoded_frame_internal(s, stream_index, frame, 0);
}
int av_interleaved_write_uncoded_frame(AVFormatContext *s, int stream_index,
AVFrame *frame)
{
- return av_write_uncoded_frame_internal(s, stream_index, frame, 1);
+ return write_uncoded_frame_internal(s, stream_index, frame, 1);
}
int av_write_uncoded_frame_query(AVFormatContext *s, int stream_index)