@@ -3230,10 +3230,6 @@ static int init_output_stream(OutputStream *ost, AVFrame *frame,
ost->initialized = 1;
- ret = of_check_init(output_files[ost->file_index]);
- if (ret < 0)
- return ret;
-
return ret;
}
@@ -699,8 +699,6 @@ int hwaccel_decode_init(AVCodecContext *avctx);
int of_muxer_init(OutputFile *of, AVFormatContext *fc,
AVDictionary *opts, int64_t limit_filesize);
-/* open the muxer when all the streams are initialized */
-int of_check_init(OutputFile *of);
int of_write_trailer(OutputFile *of);
void of_close(OutputFile **pof);
@@ -63,6 +63,59 @@ struct Muxer {
static int want_sdp = 1;
+static int print_sdp(void)
+{
+ char sdp[16384];
+ int i;
+ int j, ret;
+ AVIOContext *sdp_pb;
+ AVFormatContext **avc;
+
+ for (i = 0; i < nb_output_files; i++) {
+ if (!output_files[i]->mux->header_written)
+ return 0;
+ }
+
+ avc = av_malloc_array(nb_output_files, sizeof(*avc));
+ if (!avc)
+ return AVERROR(ENOMEM);
+ for (i = 0, j = 0; i < nb_output_files; i++) {
+ if (!strcmp(output_files[i]->format->name, "rtp")) {
+ avc[j] = output_files[i]->mux->fc;
+ j++;
+ }
+ }
+
+ if (!j) {
+ av_log(NULL, AV_LOG_ERROR, "No output streams in the SDP.\n");
+ ret = AVERROR(EINVAL);
+ goto fail;
+ }
+
+ ret = av_sdp_create(avc, j, sdp, sizeof(sdp));
+ if (ret < 0)
+ goto fail;
+
+ if (!sdp_filename) {
+ printf("SDP:\n%s\n", sdp);
+ fflush(stdout);
+ } else {
+ ret = avio_open2(&sdp_pb, sdp_filename, AVIO_FLAG_WRITE, &int_cb, NULL);
+ if (ret < 0) {
+ av_log(NULL, AV_LOG_ERROR, "Failed to open sdp file '%s'\n", sdp_filename);
+ goto fail;
+ }
+
+ avio_print(sdp_pb, sdp);
+ avio_closep(&sdp_pb);
+ av_freep(&sdp_filename);
+ }
+
+fail:
+ av_freep(&avc);
+ return ret;
+}
+
static int update_video_stats(OutputStream *ost, const AVPacket *pkt, int write_vstats)
{
const uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS,
@@ -273,92 +326,8 @@ static int submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
return ret;
}
-int of_submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof)
-{
- if (ost->sq_idx_mux >= 0) {
- int ret = sq_send(of->sq_mux, ost->sq_idx_mux,
- SQPKT(eof ? NULL: pkt));
- if (ret < 0) {
- av_packet_unref(pkt);
- if (ret == AVERROR_EOF) {
- ost->finished |= MUXER_FINISHED;
- return 0;
- } else
- return ret;
- }
-
- while (1) {
- ret = sq_receive(of->sq_mux, -1, SQPKT(pkt));
- if (ret == AVERROR_EOF || ret == AVERROR(EAGAIN))
- return 0;
- else if (ret < 0)
- return ret;
-
- ret = submit_packet(of, pkt, output_streams[of->ost_index + ret]);
- if (ret < 0)
- return ret;
- }
- } else if (!eof)
- return submit_packet(of, pkt, ost);
-
- return 0;
-}
-
-static int print_sdp(void)
-{
- char sdp[16384];
- int i;
- int j, ret;
- AVIOContext *sdp_pb;
- AVFormatContext **avc;
-
- for (i = 0; i < nb_output_files; i++) {
- if (!output_files[i]->mux->header_written)
- return 0;
- }
-
- avc = av_malloc_array(nb_output_files, sizeof(*avc));
- if (!avc)
- return AVERROR(ENOMEM);
- for (i = 0, j = 0; i < nb_output_files; i++) {
- if (!strcmp(output_files[i]->format->name, "rtp")) {
- avc[j] = output_files[i]->mux->fc;
- j++;
- }
- }
-
- if (!j) {
- av_log(NULL, AV_LOG_ERROR, "No output streams in the SDP.\n");
- ret = AVERROR(EINVAL);
- goto fail;
- }
-
- ret = av_sdp_create(avc, j, sdp, sizeof(sdp));
- if (ret < 0)
- goto fail;
-
- if (!sdp_filename) {
- printf("SDP:\n%s\n", sdp);
- fflush(stdout);
- } else {
- ret = avio_open2(&sdp_pb, sdp_filename, AVIO_FLAG_WRITE, &int_cb, NULL);
- if (ret < 0) {
- av_log(NULL, AV_LOG_ERROR, "Failed to open sdp file '%s'\n", sdp_filename);
- goto fail;
- }
-
- avio_print(sdp_pb, sdp);
- avio_closep(&sdp_pb);
- av_freep(&sdp_filename);
- }
-
-fail:
- av_freep(&avc);
- return ret;
-}
-
/* open the muxer when all the streams are initialized */
-int of_check_init(OutputFile *of)
+static int check_write_header(OutputFile *of)
{
AVFormatContext *fc = of->mux->fc;
int ret, i;
@@ -397,10 +366,6 @@ int of_check_init(OutputFile *of)
OutputStream *ost = output_streams[of->ost_index + i];
AVPacket *pkt;
- /* try to improve muxing time_base (only possible if nothing has been written yet) */
- if (!av_fifo_can_read(ms->muxing_queue))
- ost->mux_timebase = ost->st->time_base;
-
while (av_fifo_read(ms->muxing_queue, &pkt, 1) >= 0) {
ms->muxing_queue_data_size -= pkt->size;
ret = write_packet(of, ost, pkt);
@@ -413,6 +378,47 @@ int of_check_init(OutputFile *of)
return 0;
}
+int of_submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof)
+{
+ int ret;
+
+ if (!of->mux->header_written) {
+ ret = check_write_header(of);
+ if (ret < 0) {
+ av_packet_unref(pkt);
+ return ret;
+ }
+ }
+
+ if (ost->sq_idx_mux >= 0) {
+ ret = sq_send(of->sq_mux, ost->sq_idx_mux,
+ SQPKT(eof ? NULL: pkt));
+ if (ret < 0) {
+ av_packet_unref(pkt);
+ if (ret == AVERROR_EOF) {
+ ost->finished |= MUXER_FINISHED;
+ return 0;
+ } else
+ return ret;
+ }
+
+ while (1) {
+ ret = sq_receive(of->sq_mux, -1, SQPKT(pkt));
+ if (ret == AVERROR_EOF || ret == AVERROR(EAGAIN))
+ return 0;
+ else if (ret < 0)
+ return ret;
+
+ ret = submit_packet(of, pkt, output_streams[of->ost_index + ret]);
+ if (ret < 0)
+ return ret;
+ }
+ } else if (!eof)
+ return submit_packet(of, pkt, ost);
+
+ return 0;
+}
+
int of_write_trailer(OutputFile *of)
{
AVFormatContext *fc = of->mux->fc;
@@ -540,7 +546,7 @@ int of_muxer_init(OutputFile *of, AVFormatContext *fc,
/* write the header for files with no streams */
if (of->format->flags & AVFMT_NOSTREAMS && fc->nb_streams == 0) {
- ret = of_check_init(of);
+ ret = check_write_header(of);
if (ret < 0)
goto fail;
}