Remove some dcp prefixes; better logging of content on DCP creation.
[dcpomatic.git] / src / lib / ffmpeg_content.cc
index b4c1ecbfacd5abc19c13e2cafecb4e5e66b896a8..00499cf135a737be9672cfec85b503485bc9bf49 100644 (file)
@@ -34,6 +34,7 @@ using std::stringstream;
 using std::vector;
 using std::list;
 using std::cout;
+using std::pair;
 using boost::shared_ptr;
 using boost::lexical_cast;
 
@@ -79,20 +80,7 @@ FFmpegContent::FFmpegContent (shared_ptr<const Film> f, shared_ptr<const cxml::N
                _filters.push_back (Filter::from_id ((*i)->content ()));
        }
 
-       _first_video = node->optional_number_child<Time> ("FirstVideo");
-}
-
-FFmpegContent::FFmpegContent (FFmpegContent const & o)
-       : Content (o)
-       , VideoContent (o)
-       , AudioContent (o)
-       , SubtitleContent (o)
-       , _subtitle_streams (o._subtitle_streams)
-       , _subtitle_stream (o._subtitle_stream)
-       , _audio_streams (o._audio_streams)
-       , _audio_stream (o._audio_stream)
-{
-
+       _first_video = node->optional_number_child<double> ("FirstVideo");
 }
 
 void
@@ -147,38 +135,60 @@ FFmpegContent::examine (shared_ptr<Job> job)
        video_length = examiner->video_length ();
        film->log()->log (String::compose ("Video length obtained from header as %1 frames", video_length));
 
-        {
-                boost::mutex::scoped_lock lm (_mutex);
+       {
+               boost::mutex::scoped_lock lm (_mutex);
 
-                _video_length = video_length;
+               _video_length = video_length;
 
-                _subtitle_streams = examiner->subtitle_streams ();
-                if (!_subtitle_streams.empty ()) {
-                        _subtitle_stream = _subtitle_streams.front ();
-                }
-                
-                _audio_streams = examiner->audio_streams ();
-                if (!_audio_streams.empty ()) {
-                        _audio_stream = _audio_streams.front ();
-                }
+               _subtitle_streams = examiner->subtitle_streams ();
+               if (!_subtitle_streams.empty ()) {
+                       _subtitle_stream = _subtitle_streams.front ();
+               }
+               
+               _audio_streams = examiner->audio_streams ();
+               if (!_audio_streams.empty ()) {
+                       _audio_stream = _audio_streams.front ();
+               }
 
                _first_video = examiner->first_video ();
-        }
+       }
 
-        take_from_video_examiner (examiner);
+       take_from_video_examiner (examiner);
 
-        signal_changed (ContentProperty::LENGTH);
-        signal_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
-        signal_changed (FFmpegContentProperty::SUBTITLE_STREAM);
-        signal_changed (FFmpegContentProperty::AUDIO_STREAMS);
-        signal_changed (FFmpegContentProperty::AUDIO_STREAM);
-        signal_changed (AudioContentProperty::AUDIO_CHANNELS);
+       signal_changed (ContentProperty::LENGTH);
+       signal_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
+       signal_changed (FFmpegContentProperty::SUBTITLE_STREAM);
+       signal_changed (FFmpegContentProperty::AUDIO_STREAMS);
+       signal_changed (FFmpegContentProperty::AUDIO_STREAM);
+       signal_changed (AudioContentProperty::AUDIO_CHANNELS);
 }
 
 string
 FFmpegContent::summary () const
 {
-       return String::compose (_("Movie: %1"), file().filename().string());
+       return String::compose (_("%1 [movie]"), file().filename().string());
+}
+
+string
+FFmpegContent::technical_summary () const
+{
+       string as = "none";
+       if (_audio_stream) {
+               as = String::compose ("id %1", _audio_stream->id);
+       }
+
+       string ss = "none";
+       if (_subtitle_stream) {
+               ss = String::compose ("id %1", _subtitle_stream->id);
+       }
+
+       pair<string, string> filt = Filter::ffmpeg_strings (_filters);
+       
+       return Content::technical_summary() + " - "
+               + VideoContent::technical_summary() + " - "
+               + String::compose (
+                       "ffmpeg: audio %1, subtitle %2, filters %3 %4", as, ss, filt.first, filt.second
+                       );
 }
 
 string
@@ -199,23 +209,23 @@ FFmpegContent::information () const
 void
 FFmpegContent::set_subtitle_stream (shared_ptr<FFmpegSubtitleStream> s)
 {
-        {
-                boost::mutex::scoped_lock lm (_mutex);
-                _subtitle_stream = s;
-        }
+       {
+               boost::mutex::scoped_lock lm (_mutex);
+               _subtitle_stream = s;
+       }
 
-        signal_changed (FFmpegContentProperty::SUBTITLE_STREAM);
+       signal_changed (FFmpegContentProperty::SUBTITLE_STREAM);
 }
 
 void
 FFmpegContent::set_audio_stream (shared_ptr<FFmpegAudioStream> s)
 {
-        {
-                boost::mutex::scoped_lock lm (_mutex);
-                _audio_stream = s;
-        }
+       {
+               boost::mutex::scoped_lock lm (_mutex);
+               _audio_stream = s;
+       }
 
-        signal_changed (FFmpegContentProperty::AUDIO_STREAM);
+       signal_changed (FFmpegContentProperty::AUDIO_STREAM);
 }
 
 AudioContent::Frame
@@ -226,11 +236,11 @@ FFmpegContent::audio_length () const
        VideoContent::Frame const vl = video_length ();
 
        boost::mutex::scoped_lock lm (_mutex);
-        if (!_audio_stream) {
-                return 0;
-        }
-        
-        return video_frames_to_audio_frames (vl, cafr, vfr);
+       if (!_audio_stream) {
+               return 0;
+       }
+       
+       return video_frames_to_audio_frames (vl, cafr, vfr);
 }
 
 int
@@ -238,11 +248,11 @@ FFmpegContent::audio_channels () const
 {
        boost::mutex::scoped_lock lm (_mutex);
        
-        if (!_audio_stream) {
-                return 0;
-        }
+       if (!_audio_stream) {
+               return 0;
+       }
 
-        return _audio_stream->channels;
+       return _audio_stream->channels;
 }
 
 int
@@ -250,11 +260,11 @@ FFmpegContent::content_audio_frame_rate () const
 {
        boost::mutex::scoped_lock lm (_mutex);
 
-        if (!_audio_stream) {
-                return 0;
-        }
+       if (!_audio_stream) {
+               return 0;
+       }
 
-        return _audio_stream->frame_rate;
+       return _audio_stream->frame_rate;
 }
 
 int
@@ -266,7 +276,7 @@ FFmpegContent::output_audio_frame_rate () const
        /* Resample to a DCI-approved sample rate */
        double t = dcp_audio_frame_rate (content_audio_frame_rate ());
 
-       FrameRateConversion frc (video_frame_rate(), film->dcp_video_frame_rate());
+       FrameRateConversion frc (video_frame_rate(), film->video_frame_rate());
 
        /* Compensate if the DCP is being run at a different frame rate
           to the source; that is, if the video is run such that it will
@@ -275,7 +285,7 @@ FFmpegContent::output_audio_frame_rate () const
        */
 
        if (frc.change_speed) {
-               t *= video_frame_rate() * frc.factor() / film->dcp_video_frame_rate();
+               t *= video_frame_rate() * frc.factor() / film->video_frame_rate();
        }
 
        return rint (t);
@@ -284,23 +294,23 @@ FFmpegContent::output_audio_frame_rate () const
 bool
 operator== (FFmpegSubtitleStream const & a, FFmpegSubtitleStream const & b)
 {
-        return a.id == b.id;
+       return a.id == b.id;
 }
 
 bool
 operator== (FFmpegAudioStream const & a, FFmpegAudioStream const & b)
 {
-        return a.id == b.id;
+       return a.id == b.id;
 }
 
 FFmpegAudioStream::FFmpegAudioStream (shared_ptr<const cxml::Node> node)
+       : mapping (node->node_child ("Mapping"))
 {
        name = node->string_child ("Name");
        id = node->number_child<int> ("Id");
        frame_rate = node->number_child<int> ("FrameRate");
        channels = node->number_child<int64_t> ("Channels");
-       mapping = AudioMapping (node->node_child ("Mapping"));
-       first_audio = node->optional_number_child<Time> ("FirstAudio");
+       first_audio = node->optional_number_child<double> ("FirstAudio");
 }
 
 void
@@ -311,7 +321,7 @@ FFmpegAudioStream::as_xml (xmlpp::Node* root) const
        root->add_child("FrameRate")->add_child_text (lexical_cast<string> (frame_rate));
        root->add_child("Channels")->add_child_text (lexical_cast<string> (channels));
        if (first_audio) {
-               root->add_child("FirstAudio")->add_child_text (lexical_cast<string> (first_audio));
+               root->add_child("FirstAudio")->add_child_text (lexical_cast<string> (first_audio.get ()));
        }
        mapping.as_xml (root->add_child("Mapping"));
 }
@@ -333,20 +343,14 @@ FFmpegSubtitleStream::as_xml (xmlpp::Node* root) const
        root->add_child("Id")->add_child_text (lexical_cast<string> (id));
 }
 
-shared_ptr<Content>
-FFmpegContent::clone () const
-{
-       return shared_ptr<Content> (new FFmpegContent (*this));
-}
-
 Time
 FFmpegContent::length () const
 {
        shared_ptr<const Film> film = _film.lock ();
        assert (film);
        
-       FrameRateConversion frc (video_frame_rate (), film->dcp_video_frame_rate ());
-       return video_length() * frc.factor() * TIME_HZ / film->dcp_video_frame_rate ();
+       FrameRateConversion frc (video_frame_rate (), film->video_frame_rate ());
+       return video_length() * frc.factor() * TIME_HZ / film->video_frame_rate ();
 }
 
 AudioMapping
@@ -398,3 +402,4 @@ FFmpegContent::identifier () const
 
        return s.str ();
 }
+