Fix VideoDecoder::get_video() with 3D.
[dcpomatic.git] / src / lib / ffmpeg_content.cc
index 1d2f20fe6e7012bd124a2b56a78e5acd0f3a6812..b2b67e5656c13e1a3d928b43a5f92e1e19b939c7 100644 (file)
@@ -54,6 +54,7 @@ using std::list;
 using std::cout;
 using std::pair;
 using std::make_pair;
+using std::max;
 using boost::shared_ptr;
 using boost::dynamic_pointer_cast;
 using boost::optional;
@@ -72,7 +73,7 @@ FFmpegContent::FFmpegContent (shared_ptr<const Film> film, cxml::ConstNodePtr no
        : Content (film, node)
 {
        video = VideoContent::from_xml (this, node, version);
-       audio = AudioContent::from_xml (this, node);
+       audio = AudioContent::from_xml (this, node, version);
        subtitle = SubtitleContent::from_xml (this, node, version);
 
        list<cxml::NodePtr> c = node->node_children ("SubtitleStream");
@@ -121,6 +122,9 @@ FFmpegContent::FFmpegContent (shared_ptr<const Film> film, cxml::ConstNodePtr no
 FFmpegContent::FFmpegContent (shared_ptr<const Film> film, vector<boost::shared_ptr<Content> > c)
        : Content (film, c)
 {
+       /* XXX: this should look at c to decide which of video/audio/subtitle
+          get created.
+       */
        video.reset (new VideoContent (this, c));
        audio.reset (new AudioContent (this, c));
        subtitle.reset (new SubtitleContent (this, c));
@@ -331,7 +335,13 @@ FFmpegContent::full_length () const
        }
 
        DCPOMATIC_ASSERT (audio);
-       return DCPTime::from_frames (llrint (audio->stream()->length() / frc.speed_up), audio->stream()->frame_rate());
+
+       DCPTime longest;
+       BOOST_FOREACH (AudioStreamPtr i, audio->streams ()) {
+               longest = max (longest, DCPTime::from_frames (llrint (i->length() / frc.speed_up), i->frame_rate()));
+       }
+
+       return longest;
 }
 
 void
@@ -427,21 +437,21 @@ FFmpegContent::add_properties (list<UserProperty>& p) const
                        case AVCOL_RANGE_UNSPECIFIED:
                                /// TRANSLATORS: this means that the range of pixel values used in this
                                /// file is unknown (not specified in the file).
-                               p.push_back (UserProperty (_("Video"), _("Colour range"), _("Unspecified")));
+                               p.push_back (UserProperty (UserProperty::VIDEO, _("Colour range"), _("Unspecified")));
                                break;
                        case AVCOL_RANGE_MPEG:
                                /// TRANSLATORS: this means that the range of pixel values used in this
                                /// file is limited, so that not all possible values are valid.
                                p.push_back (
                                        UserProperty (
-                                               _("Video"), _("Colour range"), String::compose (_("Limited (%1-%2)"), (total - sub) / 2, (total + sub) / 2)
+                                               UserProperty::VIDEO, _("Colour range"), String::compose (_("Limited (%1-%2)"), (total - sub) / 2, (total + sub) / 2)
                                                )
                                        );
                                break;
                        case AVCOL_RANGE_JPEG:
                                /// TRANSLATORS: this means that the range of pixel values used in this
                                /// file is full, so that all possible pixel values are valid.
-                               p.push_back (UserProperty (_("Video"), _("Colour range"), String::compose (_("Full (0-%1)"), total)));
+                               p.push_back (UserProperty (UserProperty::VIDEO, _("Colour range"), String::compose (_("Full (0-%1)"), total)));
                                break;
                        default:
                                DCPOMATIC_ASSERT (false);
@@ -451,17 +461,17 @@ FFmpegContent::add_properties (list<UserProperty>& p) const
                        case AVCOL_RANGE_UNSPECIFIED:
                                /// TRANSLATORS: this means that the range of pixel values used in this
                                /// file is unknown (not specified in the file).
-                               p.push_back (UserProperty (_("Video"), _("Colour range"), _("Unspecified")));
+                               p.push_back (UserProperty (UserProperty::VIDEO, _("Colour range"), _("Unspecified")));
                                break;
                        case AVCOL_RANGE_MPEG:
                                /// TRANSLATORS: this means that the range of pixel values used in this
                                /// file is limited, so that not all possible values are valid.
-                               p.push_back (UserProperty (_("Video"), _("Colour range"), _("Limited")));
+                               p.push_back (UserProperty (UserProperty::VIDEO, _("Colour range"), _("Limited")));
                                break;
                        case AVCOL_RANGE_JPEG:
                                /// TRANSLATORS: this means that the range of pixel values used in this
                                /// file is full, so that all possible pixel values are valid.
-                               p.push_back (UserProperty (_("Video"), _("Colour range"), _("Full")));
+                               p.push_back (UserProperty (UserProperty::VIDEO, _("Colour range"), _("Full")));
                                break;
                        default:
                                DCPOMATIC_ASSERT (false);
@@ -483,7 +493,7 @@ FFmpegContent::add_properties (list<UserProperty>& p) const
                };
 
                DCPOMATIC_ASSERT (AVCOL_PRI_NB <= 11);
-               p.push_back (UserProperty (_("Video"), _("Colour primaries"), primaries[_color_primaries]));
+               p.push_back (UserProperty (UserProperty::VIDEO, _("Colour primaries"), primaries[_color_primaries]));
 
                char const * transfers[] = {
                        _("Unspecified"),
@@ -507,7 +517,7 @@ FFmpegContent::add_properties (list<UserProperty>& p) const
                };
 
                DCPOMATIC_ASSERT (AVCOL_TRC_NB <= 18);
-               p.push_back (UserProperty (_("Video"), _("Colour transfer characteristic"), transfers[_color_trc]));
+               p.push_back (UserProperty (UserProperty::VIDEO, _("Colour transfer characteristic"), transfers[_color_trc]));
 
                char const * spaces[] = {
                        _("RGB / sRGB (IEC61966-2-1)"),
@@ -524,10 +534,10 @@ FFmpegContent::add_properties (list<UserProperty>& p) const
                };
 
                DCPOMATIC_ASSERT (AVCOL_SPC_NB == 11);
-               p.push_back (UserProperty (_("Video"), _("Colourspace"), spaces[_colorspace]));
+               p.push_back (UserProperty (UserProperty::VIDEO, _("Colourspace"), spaces[_colorspace]));
 
                if (_bits_per_pixel) {
-                       p.push_back (UserProperty (_("Video"), _("Bits per pixel"), raw_convert<string> (_bits_per_pixel.get ())));
+                       p.push_back (UserProperty (UserProperty::VIDEO, _("Bits per pixel"), raw_convert<string> (_bits_per_pixel.get ())));
                }
        }