Rename SafeStringStream -> locked_stringstream. Bump deps for removal of stringstream.
[dcpomatic.git] / src / lib / ffmpeg_examiner.cc
index 44d6a87dfdd6b262b4eaafd5d54ab678d7c809d8..544cc11b91fc545d2d74426b5ab372db4933fdd1 100644 (file)
@@ -1,19 +1,20 @@
 /*
     Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
 
-    This program is free software; you can redistribute it and/or modify
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
 
-    This program is distributed in the hope that it will be useful,
+    DCP-o-matic is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
 
     You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 
@@ -29,7 +30,7 @@ extern "C" {
 #include "ffmpeg_audio_stream.h"
 #include "ffmpeg_subtitle_stream.h"
 #include "util.h"
-#include "safe_stringstream.h"
+#include <locked_sstream.h>
 #include <boost/foreach.hpp>
 #include <iostream>
 
@@ -61,9 +62,20 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr<const FFmpegContent> c, shared_ptr<Jo
                                s->codec->channel_layout = av_get_default_channel_layout (s->codec->channels);
                        }
 
+                       DCPOMATIC_ASSERT (_format_context->duration != AV_NOPTS_VALUE);
+                       DCPOMATIC_ASSERT (s->codec->codec);
+                       DCPOMATIC_ASSERT (s->codec->codec->name);
+
                        _audio_streams.push_back (
                                shared_ptr<FFmpegAudioStream> (
-                                       new FFmpegAudioStream (audio_stream_name (s), s->id, s->codec->sample_rate, s->codec->channels)
+                                       new FFmpegAudioStream (
+                                               stream_name (s),
+                                               s->codec->codec->name,
+                                               s->id,
+                                               s->codec->sample_rate,
+                                               (double (_format_context->duration) / AV_TIME_BASE) * s->codec->sample_rate,
+                                               s->codec->channels
+                                               )
                                        )
                                );
 
@@ -83,8 +95,10 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr<const FFmpegContent> c, shared_ptr<Jo
        if (job) {
                if (_need_video_length) {
                        job->sub (_("Finding length and subtitles"));
-               } else {
+               } else if (!_subtitle_streams.empty()) {
                        job->sub (_("Finding subtitles"));
+               } else {
+                       job->sub (_("Finding length"));
                }
        }
 
@@ -334,26 +348,10 @@ FFmpegExaminer::sample_aspect_ratio () const
        return double (sar.num) / sar.den;
 }
 
-string
-FFmpegExaminer::audio_stream_name (AVStream* s) const
-{
-       SafeStringStream n;
-
-       n << stream_name (s);
-
-       if (!n.str().empty()) {
-               n << "; ";
-       }
-
-       n << s->codec->channels << " channels";
-
-       return n.str ();
-}
-
 string
 FFmpegExaminer::subtitle_stream_name (AVStream* s) const
 {
-       SafeStringStream n;
+       locked_stringstream n;
 
        n << stream_name (s);
 
@@ -367,7 +365,7 @@ FFmpegExaminer::subtitle_stream_name (AVStream* s) const
 string
 FFmpegExaminer::stream_name (AVStream* s) const
 {
-       SafeStringStream n;
+       locked_stringstream n;
 
        if (s->metadata) {
                AVDictionaryEntry const * lang = av_dict_get (s->metadata, "language", 0, 0);