Merge master.
[dcpomatic.git] / src / lib / ffmpeg_content.cc
index 86ce7503c9483c192e78c1655c99391f0ba68d36..d15f3fd26a8fcbe47175fdb23e966964a1bd5d51 100644 (file)
@@ -21,6 +21,7 @@ extern "C" {
 #include <libavformat/avformat.h>
 }
 #include <libcxml/cxml.h>
+#include <libdcp/raw_convert.h>
 #include "ffmpeg_content.h"
 #include "ffmpeg_examiner.h"
 #include "compose.hpp"
@@ -40,8 +41,8 @@ using std::list;
 using std::cout;
 using std::pair;
 using boost::shared_ptr;
-using boost::lexical_cast;
 using boost::dynamic_pointer_cast;
+using libdcp::raw_convert;
 
 int const FFmpegContentProperty::SUBTITLE_STREAMS = 100;
 int const FFmpegContentProperty::SUBTITLE_STREAM = 101;
@@ -58,7 +59,7 @@ FFmpegContent::FFmpegContent (shared_ptr<const Film> f, boost::filesystem::path
 
 }
 
-FFmpegContent::FFmpegContent (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node, int version, list<string>& notes)
+FFmpegContent::FFmpegContent (shared_ptr<const Film> f, cxml::ConstNodePtr node, int version, list<string>& notes)
        : Content (f, node)
        , VideoContent (f, node, version)
        , AudioContent (f, node)
@@ -152,7 +153,7 @@ FFmpegContent::as_xml (xmlpp::Node* node) const
        }
 
        if (_first_video) {
-               node->add_child("FirstVideo")->add_child_text (lexical_cast<string> (_first_video.get().get()));
+               node->add_child("FirstVideo")->add_child_text (raw_convert<string> (_first_video.get().get()));
        }
 }
 
@@ -268,8 +269,7 @@ FFmpegContent::set_audio_stream (shared_ptr<FFmpegAudioStream> s)
 ContentTime
 FFmpegContent::audio_length () const
 {
-       boost::mutex::scoped_lock lm (_mutex);
-       if (!_audio_stream) {
+       if (!audio_stream ()) {
                return ContentTime ();
        }
 
@@ -289,7 +289,7 @@ FFmpegContent::audio_channels () const
 }
 
 int
-FFmpegContent::content_audio_frame_rate () const
+FFmpegContent::audio_frame_rate () const
 {
        boost::mutex::scoped_lock lm (_mutex);
 
@@ -300,29 +300,6 @@ FFmpegContent::content_audio_frame_rate () const
        return _audio_stream->frame_rate;
 }
 
-int
-FFmpegContent::output_audio_frame_rate () const
-{
-       shared_ptr<const Film> film = _film.lock ();
-       assert (film);
-       
-       /* Resample to a DCI-approved sample rate */
-       double t = dcp_audio_frame_rate (content_audio_frame_rate ());
-
-       FrameRateChange 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
-          look different in the DCP compared to the source (slower or faster).
-       */
-
-       if (frc.change_speed) {
-               t /= frc.speed_up;
-       }
-
-       return rint (t);
-}
-
 bool
 operator== (FFmpegStream const & a, FFmpegStream const & b)
 {
@@ -335,7 +312,7 @@ operator!= (FFmpegStream const & a, FFmpegStream const & b)
        return a._id != b._id;
 }
 
-FFmpegStream::FFmpegStream (shared_ptr<const cxml::Node> node)
+FFmpegStream::FFmpegStream (cxml::ConstNodePtr node)
        : name (node->string_child ("Name"))
        , _id (node->number_child<int> ("Id"))
 {
@@ -346,10 +323,10 @@ void
 FFmpegStream::as_xml (xmlpp::Node* root) const
 {
        root->add_child("Name")->add_child_text (name);
-       root->add_child("Id")->add_child_text (lexical_cast<string> (_id));
+       root->add_child("Id")->add_child_text (raw_convert<string> (_id));
 }
 
-FFmpegAudioStream::FFmpegAudioStream (shared_ptr<const cxml::Node> node, int version)
+FFmpegAudioStream::FFmpegAudioStream (cxml::ConstNodePtr node, int version)
        : FFmpegStream (node)
        , mapping (node->node_child ("Mapping"), version)
 {
@@ -362,10 +339,10 @@ void
 FFmpegAudioStream::as_xml (xmlpp::Node* root) const
 {
        FFmpegStream::as_xml (root);
-       root->add_child("FrameRate")->add_child_text (lexical_cast<string> (frame_rate));
-       root->add_child("Channels")->add_child_text (lexical_cast<string> (channels));
+       root->add_child("FrameRate")->add_child_text (raw_convert<string> (frame_rate));
+       root->add_child("Channels")->add_child_text (raw_convert<string> (channels));
        if (first_audio) {
-               root->add_child("FirstAudio")->add_child_text (lexical_cast<string> (first_audio.get().get()));
+               root->add_child("FirstAudio")->add_child_text (raw_convert<string> (first_audio.get().get()));
        }
        mapping.as_xml (root->add_child("Mapping"));
 }
@@ -403,7 +380,7 @@ FFmpegStream::stream (AVFormatContext const * fc) const
  *  @param t String returned from to_string().
  *  @param v State file version.
  */
-FFmpegSubtitleStream::FFmpegSubtitleStream (shared_ptr<const cxml::Node> node)
+FFmpegSubtitleStream::FFmpegSubtitleStream (cxml::ConstNodePtr node)
        : FFmpegStream (node)
 {
        
@@ -450,7 +427,7 @@ void
 FFmpegContent::set_audio_mapping (AudioMapping m)
 {
        audio_stream()->mapping = m;
-       signal_changed (AudioContentProperty::AUDIO_MAPPING);
+       AudioContent::set_audio_mapping (m);
 }
 
 string