X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fexamine_ffmpeg_subtitles_job.cc;h=8c762d893bb311e9c47a6545d7fa60ee1820dcd7;hb=16dbc2de1ce97770d6ba223e4968ba352511ca68;hp=af548b7944529100d2d57e3ec925e85f6255f6e4;hpb=0e6d4402c013eb6be666b5f638dd932052ae6c51;p=dcpomatic.git diff --git a/src/lib/examine_ffmpeg_subtitles_job.cc b/src/lib/examine_ffmpeg_subtitles_job.cc index af548b794..8c762d893 100644 --- a/src/lib/examine_ffmpeg_subtitles_job.cc +++ b/src/lib/examine_ffmpeg_subtitles_job.cc @@ -33,7 +33,7 @@ extern "C" { using std::string; using std::cout; -using boost::shared_ptr; +using std::shared_ptr; ExamineFFmpegSubtitlesJob::ExamineFFmpegSubtitlesJob (shared_ptr film, shared_ptr c) : Job (film) @@ -43,6 +43,11 @@ ExamineFFmpegSubtitlesJob::ExamineFFmpegSubtitlesJob (shared_ptr fil } +ExamineFFmpegSubtitlesJob::~ExamineFFmpegSubtitlesJob () +{ + stop_thread (); +} + string ExamineFFmpegSubtitlesJob::name () const { @@ -60,8 +65,11 @@ ExamineFFmpegSubtitlesJob::run () { int64_t const len = _file_group.length (); while (true) { - int r = av_read_frame (_format_context, &_packet); + auto packet = av_packet_alloc (); + DCPOMATIC_ASSERT (packet); + int r = av_read_frame (_format_context, packet); if (r < 0) { + av_packet_free (&packet); break; } @@ -71,10 +79,10 @@ ExamineFFmpegSubtitlesJob::run () set_progress_unknown (); } - if (_content->subtitle_stream() && _content->subtitle_stream()->uses_index(_format_context, _packet.stream_index) && _content->only_text()->use()) { + if (_content->subtitle_stream() && _content->subtitle_stream()->uses_index(_format_context, packet->stream_index) && _content->only_text()->use()) { int got_subtitle; AVSubtitle sub; - if (avcodec_decode_subtitle2(subtitle_codec_context(), &sub, &got_subtitle, &_packet) >= 0 && got_subtitle) { + if (avcodec_decode_subtitle2(subtitle_codec_context(), &sub, &got_subtitle, packet) >= 0 && got_subtitle) { for (unsigned int i = 0; i < sub.num_rects; ++i) { AVSubtitleRect const * rect = sub.rects[i]; if (rect->type == SUBTITLE_BITMAP) { @@ -82,23 +90,24 @@ ExamineFFmpegSubtitlesJob::run () /* sub_p looks up into a BGRA palette which is here (i.e. first byte B, second G, third R, fourth A) */ - uint32_t const * palette = (uint32_t *) rect->pict.data[1]; + uint8_t const * palette = rect->pict.data[1]; #else /* sub_p looks up into a BGRA palette which is here (i.e. first byte B, second G, third R, fourth A) */ - uint32_t const * palette = (uint32_t *) rect->data[1]; + uint8_t const * palette = rect->data[1]; #endif for (int j = 0; j < rect->nb_colors; ++j) { - RGBA c ((palette[j] & 0xff0000) >> 16, (palette[j] & 0xff00) >> 8, palette[j] & 0xff, (palette[j] & 0xff000000) >> 24); + RGBA c (palette[2], palette[1], palette[0], palette[3]); _content->subtitle_stream()->set_colour (c, c); + palette += 4; } } } } } - av_packet_unref (&_packet); + av_packet_free (&packet); } set_progress (1);