X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=futatabi%2Fmain.cpp;h=00de13f5bc8002cd6fa36456cdaa9925e678c6bf;hb=2f92c975a3cf9f4803a58267fd2a12765e34a69e;hp=19cd5fb3e4162439e22e7cac2cd8208b3a84686e;hpb=33b86069c755119da2a35af63fbd580ca9abfa7c;p=nageru diff --git a/futatabi/main.cpp b/futatabi/main.cpp index 19cd5fb..00de13f 100644 --- a/futatabi/main.cpp +++ b/futatabi/main.cpp @@ -201,7 +201,7 @@ int main(int argc, char **argv) { parse_flags(argc, argv); if (optind == argc) { - global_flags.stream_source = "multiangle.mp4"; + global_flags.stream_source = "multicam.mp4"; global_flags.slow_down_input = true; } else if (optind + 1 == argc) { global_flags.stream_source = argv[optind]; @@ -526,44 +526,41 @@ void record_thread_func() vector pending_audio[MAX_STREAMS]; int64_t last_pts = -1; while (!should_quit.load()) { - AVPacket pkt; - unique_ptr pkt_cleanup( - &pkt, av_packet_unref); - av_init_packet(&pkt); - pkt.data = nullptr; - pkt.size = 0; + AVPacketWithDeleter pkt = av_packet_alloc_unique(); + pkt->data = nullptr; + pkt->size = 0; // TODO: Make it possible to abort av_read_frame() (use an interrupt callback); // right now, should_quit will be ignored if it's hung on I/O. - if (av_read_frame(format_ctx.get(), &pkt) != 0) { + if (av_read_frame(format_ctx.get(), pkt.get()) != 0) { break; } - AVStream *stream = format_ctx->streams[pkt.stream_index]; + AVStream *stream = format_ctx->streams[pkt->stream_index]; if (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && - audio_stream_to_video_stream_idx.count(pkt.stream_index)) { - if ((pkt.size % (sizeof(uint32_t) * 2)) != 0) { + audio_stream_to_video_stream_idx.count(pkt->stream_index)) { + if ((pkt->size % (sizeof(uint32_t) * 2)) != 0) { fprintf(stderr, "Audio stream %u had a packet of strange length %d, ignoring.\n", - pkt.stream_index, pkt.size); + pkt->stream_index, pkt->size); } else { // TODO: Endianness? - const uint32_t *begin = (const uint32_t *)pkt.data; - const uint32_t *end = (const uint32_t *)(pkt.data + pkt.size); - pending_audio[audio_stream_to_video_stream_idx[pkt.stream_index]].assign(begin, end); + const uint32_t *begin = (const uint32_t *)pkt->data; + const uint32_t *end = (const uint32_t *)(pkt->data + pkt->size); + pending_audio[audio_stream_to_video_stream_idx[pkt->stream_index]].assign(begin, end); } } - if (pkt.stream_index >= MAX_STREAMS || + if (pkt->stream_index >= MAX_STREAMS || stream->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) { continue; } - ++metric_received_frames[pkt.stream_index]; - metric_received_frame_size_bytes.count_event(pkt.size); + ++metric_received_frames[pkt->stream_index]; + metric_received_frame_size_bytes.count_event(pkt->size); // Convert pts to our own timebase. AVRational stream_timebase = stream->time_base; - int64_t pts = av_rescale_q(pkt.pts, stream_timebase, AVRational{ 1, TIMEBASE }); + int64_t pts = av_rescale_q(pkt->pts, stream_timebase, AVRational{ 1, TIMEBASE }); // Translate offset into our stream. if (last_pts == -1) { @@ -572,11 +569,11 @@ void record_thread_func() pts = std::max(pts + pts_offset, start_pts); //fprintf(stderr, "Got a frame from camera %d, pts = %ld, size = %d\n", - // pkt.stream_index, pts, pkt.size); - FrameOnDisk frame = write_frame(pkt.stream_index, pts, pkt.data, pkt.size, move(pending_audio[pkt.stream_index]), &db); + // pkt->stream_index, pts, pkt->size); + FrameOnDisk frame = write_frame(pkt->stream_index, pts, pkt->data, pkt->size, move(pending_audio[pkt->stream_index]), &db); - post_to_main_thread([pkt, frame] { - global_mainwindow->display_frame(pkt.stream_index, frame); + post_to_main_thread([stream_index{pkt->stream_index}, frame] { + global_mainwindow->display_frame(stream_index, frame); }); if (last_pts != -1 && global_flags.slow_down_input) {