Token effort toward non-bitmap subtitles from FFmpegDecoder.
authorCarl Hetherington <cth@carlh.net>
Wed, 13 May 2015 22:38:49 +0000 (23:38 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 13 May 2015 22:38:49 +0000 (23:38 +0100)
src/lib/ffmpeg_decoder.cc
src/lib/ffmpeg_decoder.h

index 6122a547ed3b9f816345b0f092ccdc95c403ab88..35e15a331c2cd58c0bd7a2926b21ca340af456ab 100644 (file)
@@ -453,15 +453,43 @@ FFmpegDecoder::decode_subtitle_packet ()
        
        AVSubtitleRect const * rect = sub.rects[0];
 
-       if (rect->type != SUBTITLE_BITMAP) {
-               throw DecodeError (_("non-bitmap subtitles not yet supported"));
+       switch (rect->type) {
+       case SUBTITLE_NONE:
+               break;
+       case SUBTITLE_BITMAP:
+               decode_bitmap_subtitle (rect, period);
+               break;
+       case SUBTITLE_TEXT:
+               cout << "XXX: SUBTITLE_TEXT " << rect->text << "\n";
+               break;
+       case SUBTITLE_ASS:
+               cout << "XXX: SUBTITLE_ASS " << rect->ass << "\n";
+               break;
        }
+       
+       avsubtitle_free (&sub);
+}
+
+list<ContentTimePeriod>
+FFmpegDecoder::image_subtitles_during (ContentTimePeriod p, bool starting) const
+{
+       return _ffmpeg_content->subtitles_during (p, starting);
+}
 
+list<ContentTimePeriod>
+FFmpegDecoder::text_subtitles_during (ContentTimePeriod, bool) const
+{
+       return list<ContentTimePeriod> ();
+}
+
+void
+FFmpegDecoder::decode_bitmap_subtitle (AVSubtitleRect const * rect, ContentTimePeriod period)
+{
        /* Note RGBA is expressed little-endian, so the first byte in the word is R, second
           G, third B, fourth A.
        */
        shared_ptr<Image> image (new Image (PIX_FMT_RGBA, dcp::Size (rect->w, rect->h), true));
-
+       
        /* Start of the first line in the subtitle */
        uint8_t* sub_p = rect->pict.data[0];
        /* sub_p looks up into a BGRA palette which is here
@@ -470,7 +498,7 @@ FFmpegDecoder::decode_subtitle_packet ()
        uint32_t const * palette = (uint32_t *) rect->pict.data[1];
        /* Start of the output data */
        uint32_t* out_p = (uint32_t *) image->data()[0];
-
+       
        for (int y = 0; y < rect->h; ++y) {
                uint8_t* sub_line_p = sub_p;
                uint32_t* out_line_p = out_p;
@@ -481,7 +509,7 @@ FFmpegDecoder::decode_subtitle_packet ()
                sub_p += rect->pict.linesize[0];
                out_p += image->stride()[0] / sizeof (uint32_t);
        }
-
+       
        dcp::Size const vs = _ffmpeg_content->video_size ();
        dcpomatic::Rect<double> const scaled_rect (
                static_cast<double> (rect->x) / vs.width,
@@ -489,20 +517,7 @@ FFmpegDecoder::decode_subtitle_packet ()
                static_cast<double> (rect->w) / vs.width,
                static_cast<double> (rect->h) / vs.height
                );
-
-       image_subtitle (ContentTimePeriod (period.from, period.to), image, scaled_rect);
        
-       avsubtitle_free (&sub);
-}
-
-list<ContentTimePeriod>
-FFmpegDecoder::image_subtitles_during (ContentTimePeriod p, bool starting) const
-{
-       return _ffmpeg_content->subtitles_during (p, starting);
+       image_subtitle (period, image, scaled_rect);
 }
 
-list<ContentTimePeriod>
-FFmpegDecoder::text_subtitles_during (ContentTimePeriod, bool) const
-{
-       return list<ContentTimePeriod> ();
-}
index 616fa88dd42f3f40f3ab993785ef89fe89a0e075..6f027ce1c1ba2687df7d774aa22207883f373a27 100644 (file)
@@ -64,6 +64,8 @@ private:
        void decode_audio_packet ();
        void decode_subtitle_packet ();
 
+       void decode_bitmap_subtitle (AVSubtitleRect const * rect, ContentTimePeriod period);
+
        void maybe_add_subtitle ();
        boost::shared_ptr<AudioBuffers> deinterleave_audio (uint8_t** data, int size);