Merge master; specify libdcp-1.0.
[dcpomatic.git] / src / lib / video_decoder.cc
index 38d5dfcb87298a4ec28f782c89c3ba430551edc0..a3b45716c532887473d76c17f50957bf80dba5ac 100644 (file)
 
 using std::cout;
 using boost::shared_ptr;
+using boost::optional;
 
-VideoDecoder::VideoDecoder (shared_ptr<const Film> f)
+VideoDecoder::VideoDecoder (shared_ptr<const Film> f, shared_ptr<const VideoContent> c)
        : Decoder (f)
-       , _video_position (0)
+       , _video_content (c)
 {
 
 }
 
+/** Called by subclasses when they have a video frame ready */
 void
-VideoDecoder::video (shared_ptr<const Image> image, bool same, VideoContent::Frame frame)
+VideoDecoder::video (shared_ptr<const Image> image, bool same, VideoFrame frame)
 {
-       Video (image, same, frame);
-       _video_position = frame + 1;
+       switch (_video_content->video_frame_type ()) {
+       case VIDEO_FRAME_TYPE_2D:
+               _pending.push_back (shared_ptr<DecodedVideo> (new DecodedVideo (image, EYES_BOTH, same, frame)));
+               break;
+       case VIDEO_FRAME_TYPE_3D_LEFT_RIGHT:
+       {
+               int const half = image->size().width / 2;
+               _pending.push_back (shared_ptr<DecodedVideo> (new DecodedVideo (image->crop (Crop (0, half, 0, 0), true), EYES_LEFT, same, frame)));
+               _pending.push_back (shared_ptr<DecodedVideo> (new DecodedVideo (image->crop (Crop (half, 0, 0, 0), true), EYES_RIGHT, same, frame)));
+               break;
+       }
+       case VIDEO_FRAME_TYPE_3D_TOP_BOTTOM:
+       {
+               int const half = image->size().height / 2;
+               _pending.push_back (shared_ptr<DecodedVideo> (new DecodedVideo (image->crop (Crop (0, 0, 0, half), true), EYES_LEFT, same, frame)));
+               _pending.push_back (shared_ptr<DecodedVideo> (new DecodedVideo (image->crop (Crop (0, 0, half, 0), true), EYES_RIGHT, same, frame)));
+               break;
+       }
+       default:
+               assert (false);
+       }
 }
-