Fix start-trim of audio-only content (#915).
authorCarl Hetherington <cth@carlh.net>
Wed, 27 Jul 2016 23:44:40 +0000 (00:44 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 27 Jul 2016 23:44:40 +0000 (00:44 +0100)
ChangeLog
src/lib/ffmpeg_decoder.cc
src/lib/ffmpeg_stream.cc
src/lib/ffmpeg_stream.h

index a099425f620e0c12a63f32f14b2d07c9626d0c41..8904eef6c1478dd651e66c5ad208206fc0843efb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2016-07-28  Carl Hetherington  <cth@carlh.net>
+
+       * Fix start-trim of audio-only content (#915).
+
 2016-07-26  Carl Hetherington  <cth@carlh.net>
 
        * Expand vertical size of servers list in preferences (#913).
index 164785c8368bb0fbffea1a28d468247df4eadf47..f7c435a7455a4ccb5993ce55da908749d5b468fe 100644 (file)
@@ -40,6 +40,7 @@
 #include "audio_decoder.h"
 #include "compose.hpp"
 #include "subtitle_content.h"
+#include "audio_content.h"
 #include <dcp/subtitle_string.h>
 #include <sub/ssa_reader.h>
 #include <sub/subtitle.h>
@@ -73,6 +74,8 @@ using std::map;
 using boost::shared_ptr;
 using boost::is_any_of;
 using boost::split;
+using boost::optional;
+using boost::dynamic_pointer_cast;
 using dcp::Size;
 
 FFmpegDecoder::FFmpegDecoder (shared_ptr<const FFmpegContent> c, shared_ptr<Log> log)
@@ -326,7 +329,18 @@ FFmpegDecoder::seek (ContentTime time, bool accurate)
           http://www.mjbshaw.com/2012/04/seeking-in-ffmpeg-know-your-timestamp.html
        */
 
-       DCPOMATIC_ASSERT (_video_stream);
+       optional<int> stream;
+
+       if (_video_stream) {
+               stream = _video_stream;
+       } else {
+               shared_ptr<FFmpegAudioStream> s = dynamic_pointer_cast<FFmpegAudioStream> (_ffmpeg_content->audio->stream ());
+               if (s) {
+                       stream = s->index (_format_context);
+               }
+       }
+
+       DCPOMATIC_ASSERT (stream);
 
        ContentTime u = time - _pts_offset;
        if (u < ContentTime ()) {
@@ -376,7 +390,7 @@ FFmpegDecoder::decode_audio_packet ()
                if (decode_result < 0) {
                        /* avcodec_decode_audio4 can sometimes return an error even though it has decoded
                           some valid data; for example dca_subframe_footer can return AVERROR_INVALIDDATA
-                          if it overreads the auxiliary data.  ffplay carries on if frame_finished is true,
+                          if it overreads the auxiliary data.  ffplay carries on if frame_finished is true,
                           even in the face of such an error, so I think we should too.
 
                           Returning from the method here caused mantis #352.
index 085c78fa8427d21d1f367143bcf90d11c07bcd41..7a8748e4e3f762f9fe9ea8287b8d8cb6a09cc14f 100644 (file)
@@ -62,3 +62,18 @@ FFmpegStream::stream (AVFormatContext const * fc) const
        DCPOMATIC_ASSERT (false);
        return 0;
 }
+
+int
+FFmpegStream::index (AVFormatContext const * fc) const
+{
+       size_t i = 0;
+       while (i < fc->nb_streams) {
+               if (fc->streams[i]->id == _id) {
+                       return i;
+               }
+               ++i;
+       }
+
+       DCPOMATIC_ASSERT (false);
+       return 0;
+}
index 317ee2e9c7e6fedb596bf7d8c30fb0289000e3a3..ec27a30f0efbaa480d7acc9d53a40eea265612cf 100644 (file)
@@ -54,6 +54,12 @@ public:
                return boost::lexical_cast<std::string> (_id);
        }
 
+       int id () const {
+               return _id;
+       }
+
+       int index (AVFormatContext const * c) const;
+
        std::string name;
 
        friend bool operator== (FFmpegStream const & a, FFmpegStream const & b);