Merge master.
[dcpomatic.git] / src / lib / ffmpeg_decoder.cc
index c9efd80fc47ba87b052362fd34b7940b570ff127..d251a37446ff96e2e49d514575b7719e53f44b6c 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -27,7 +27,6 @@
 #include <iomanip>
 #include <iostream>
 #include <stdint.h>
-#include <boost/lexical_cast.hpp>
 #include <sndfile.h>
 extern "C" {
 #include <libavcodec/avcodec.h>
@@ -42,6 +41,7 @@ extern "C" {
 #include "filter_graph.h"
 #include "audio_buffers.h"
 #include "ffmpeg_content.h"
+#include "image_proxy.h"
 
 #include "i18n.h"
 
@@ -313,9 +313,9 @@ FFmpegDecoder::minimal_run (boost::function<bool (optional<ContentTime>, optiona
 
                        avcodec_get_frame_defaults (_frame);
                        
-                       int finished = 0;
-                       r = avcodec_decode_video2 (video_codec_context(), _frame, &finished, &_packet);
-                       if (r >= 0 && finished) {
+                       int got_picture = 0;
+                       r = avcodec_decode_video2 (video_codec_context(), _frame, &got_picture, &_packet);
+                       if (r >= 0 && got_picture) {
                                last_video = ContentTime::from_seconds (av_frame_get_best_effort_timestamp (_frame) * time_base) + _pts_offset;
                        }
 
@@ -323,9 +323,9 @@ FFmpegDecoder::minimal_run (boost::function<bool (optional<ContentTime>, optiona
                        AVPacket copy_packet = _packet;
                        while (copy_packet.size > 0) {
 
-                               int finished;
-                               r = avcodec_decode_audio4 (audio_codec_context(), _frame, &finished, &_packet);
-                               if (r >= 0 && finished) {
+                               int got_frame;
+                               r = avcodec_decode_audio4 (audio_codec_context(), _frame, &got_frame, &_packet);
+                               if (r >= 0 && got_frame) {
                                        last_audio = ContentTime::from_seconds (av_frame_get_best_effort_timestamp (_frame) * time_base) + _pts_offset;
                                }
                                        
@@ -387,12 +387,12 @@ FFmpegDecoder::seek (ContentTime time, bool accurate)
        VideoDecoder::seek (time, accurate);
        AudioDecoder::seek (time, accurate);
        
-       /* If we are doing an accurate seek, our initial shot will be 200ms (200 being
+       /* If we are doing an accurate seek, our initial shot will be 2s (2 being
           a number plucked from the air) earlier than we want to end up.  The loop below
           will hopefully then step through to where we want to be.
        */
 
-       ContentTime pre_roll = accurate ? ContentTime::from_seconds (0.2) : ContentTime (0);
+       ContentTime pre_roll = accurate ? ContentTime::from_seconds (2) : ContentTime (0);
        ContentTime initial_seek = time - pre_roll;
        if (initial_seek < ContentTime (0)) {
                initial_seek = ContentTime (0);
@@ -485,7 +485,7 @@ FFmpegDecoder::decode_video_packet ()
                
                if (i->second != AV_NOPTS_VALUE) {
                        double const pts = i->second * av_q2d (_format_context->streams[_video_stream]->time_base) + _pts_offset.seconds ();
-                       video (image, rint (pts * _ffmpeg_content->video_frame_rate ()));
+                       video (shared_ptr<ImageProxy> (new RawImageProxy (image)), rint (pts * _ffmpeg_content->video_frame_rate ()));
                } else {
                        _log->log ("Dropping frame without PTS");
                }
@@ -551,7 +551,9 @@ FFmpegDecoder::decode_subtitle_packet ()
        AVSubtitleRect const * rect = sub.rects[0];
 
        if (rect->type != SUBTITLE_BITMAP) {
-               throw DecodeError (_("non-bitmap subtitles not yet supported"));
+               /* XXX */
+               // throw DecodeError (_("non-bitmap subtitles not yet supported"));
+               return;
        }
 
        /* Note RGBA is expressed little-endian, so the first byte in the word is R, second