MHD_OPTION_END);
}
-void HTTPD::add_packet(const AVPacket &pkt, int64_t pts, int64_t dts, PacketDestination destination)
+void HTTPD::add_packet(const AVPacket &pkt, int64_t pts, int64_t dts)
{
unique_lock<mutex> lock(streams_mutex);
- if (destination != DESTINATION_FILE_ONLY) {
- for (Stream *stream : streams) {
- stream->add_packet(pkt, pts, dts);
- }
- }
- if (file_mux && destination != DESTINATION_HTTP_ONLY) {
- file_mux->add_packet(pkt, pts, dts);
- }
-}
-
-void HTTPD::open_output_file(const string &filename)
-{
- AVFormatContext *avctx = avformat_alloc_context();
- avctx->oformat = av_guess_format(NULL, filename.c_str(), NULL);
- assert(filename.size() < sizeof(avctx->filename) - 1);
- strcpy(avctx->filename, filename.c_str());
-
- string url = "file:" + filename;
- int ret = avio_open2(&avctx->pb, url.c_str(), AVIO_FLAG_WRITE, &avctx->interrupt_callback, NULL);
- if (ret < 0) {
- char tmp[AV_ERROR_MAX_STRING_SIZE];
- fprintf(stderr, "%s: avio_open2() failed: %s\n", filename.c_str(), av_make_error_string(tmp, sizeof(tmp), ret));
- exit(1);
+ for (Stream *stream : streams) {
+ stream->add_packet(pkt, pts, dts);
}
-
- file_mux.reset(new Mux(avctx, width, height, Mux::CODEC_H264, TIMEBASE));
-}
-
-void HTTPD::close_output_file()
-{
- file_mux.reset();
}
int HTTPD::answer_to_connection_thunk(void *cls, MHD_Connection *connection,
AVOutputFormat *oformat = av_guess_format(global_flags.stream_mux_name.c_str(), nullptr, nullptr);
assert(oformat != nullptr);
+ // TODO: This is an ugly place to have this logic.
+ const int bit_rate = global_flags.stream_audio_codec_name.empty() ?
+ DEFAULT_AUDIO_OUTPUT_BIT_RATE :
+ global_flags.stream_audio_codec_bitrate;
+
int time_base = global_flags.stream_coarse_timebase ? COARSE_TIMEBASE : TIMEBASE;
- HTTPD::Stream *stream = new HTTPD::Stream(oformat, width, height, time_base);
+ HTTPD::Stream *stream = new HTTPD::Stream(oformat, width, height, time_base, bit_rate);
{
unique_lock<mutex> lock(streams_mutex);
streams.insert(stream);
}
}
-HTTPD::Stream::Stream(AVOutputFormat *oformat, int width, int height, int time_base)
+HTTPD::Stream::Stream(AVOutputFormat *oformat, int width, int height, int time_base, int bit_rate)
{
AVFormatContext *avctx = avformat_alloc_context();
avctx->oformat = oformat;
avctx->flags = AVFMT_FLAG_CUSTOM_IO;
- mux.reset(new Mux(avctx, width, height, video_codec, time_base));
+ mux.reset(new Mux(avctx, width, height, video_codec, time_base, bit_rate));
}
ssize_t HTTPD::Stream::reader_callback_thunk(void *cls, uint64_t pos, char *buf, size_t max)