Fix merge.
[dcpomatic.git] / src / lib / ffmpeg.cc
index 9d5aa92eca3d3f36f2e04c3e6c05ca5737a97ba0..296002c742385cbbc4a2f10ea3e6f7bbefa86348 100644 (file)
@@ -26,6 +26,7 @@
 #include "log.h"
 #include "ffmpeg_subtitle_stream.h"
 #include "ffmpeg_audio_stream.h"
+#include "md5_digester.h"
 #include "compose.hpp"
 extern "C" {
 #include <libavcodec/avcodec.h>
@@ -99,7 +100,7 @@ FFmpeg::ffmpeg_log_callback (void* ptr, int level, const char* fmt, va_list vl)
        if (log) {
                string str (line);
                boost::algorithm::trim (str);
-               log->log (String::compose ("FFmpeg: %1", str), Log::TYPE_GENERAL);
+               log->log (String::compose ("FFmpeg: %1", str), LogEntry::TYPE_GENERAL);
        } else {
                cerr << line;
        }
@@ -268,6 +269,52 @@ FFmpeg::subtitle_period (AVSubtitle const & sub)
                );
 }
 
+string
+FFmpeg::subtitle_id (AVSubtitle const & sub)
+{
+       MD5Digester digester;
+       digester.add (sub.pts);
+       for (unsigned int i = 0; i < sub.num_rects; ++i) {
+               AVSubtitleRect* rect = sub.rects[i];
+               digester.add (rect->x);
+               digester.add (rect->y);
+               digester.add (rect->w);
+               digester.add (rect->h);
+               int const line = rect->linesize[0];
+               for (int j = 0; j < rect->h; ++j) {
+                       digester.add (rect->data[0] + j * line, line);
+               }
+       }
+       return digester.get ();
+}
+
+/** @return true if sub starts a new image subtitle */
+bool
+FFmpeg::subtitle_starts_image (AVSubtitle const & sub)
+{
+       bool image = false;
+       bool text = false;
+
+       for (unsigned int i = 0; i < sub.num_rects; ++i) {
+               switch (sub.rects[i]->type) {
+               case SUBTITLE_BITMAP:
+                       image = true;
+                       break;
+               case SUBTITLE_TEXT:
+               case SUBTITLE_ASS:
+                       text = true;
+                       break;
+               default:
+                       break;
+               }
+       }
+
+       /* We can't cope with mixed image/text in one AVSubtitle */
+       DCPOMATIC_ASSERT (!image || !text);
+
+       return image;
+}
+
 /** Compute the pts offset to use given a set of audio streams and some video details.
  *  Sometimes these parameters will have just been determined by an Examiner, sometimes
  *  they will have been retrieved from a piece of Content, hence the need for this method
@@ -314,7 +361,7 @@ FFmpeg::pts_offset (vector<shared_ptr<FFmpegAudioStream> > audio_streams, option
 
        /* Now adjust so that the video pts starts on a frame */
        if (first_video) {
-               ContentTime fvc = first_video.get() + po;
+               ContentTime const fvc = first_video.get() + po;
                po += fvc.round_up (video_frame_rate) - fvc;
        }