]> git.decadent.org.uk Git - videolink.git/blob - generate_dvd.hpp
Moved generation of menu VOBs from videolink_window to dvd_generator.
[videolink.git] / generate_dvd.hpp
1 // Copyright 2005-6 Ben Hutchings <ben@decadent.org.uk>.
2 // See the file "COPYING" for licence details.
3
4 #ifndef INC_GENERATE_DVD_HPP
5 #define INC_GENERATE_DVD_HPP
6
7 #include <string>
8 #include <vector>
9
10 #include <boost/shared_ptr.hpp>
11
12 #include <glibmm/refptr.h>
13
14 #include "geometry.hpp"
15 #include "temp_file.hpp"
16 #include "video.hpp"
17 #include "vob_list.hpp"
18
19 namespace Gdk
20 {
21     class Pixbuf;
22 }
23
24 // Description of menus and titles to go on a DVD.
25
26 class dvd_generator
27 {
28 public:
29     enum pgc_type { unknown_pgc,  menu_pgc, title_pgc };
30
31     // Reference to some PGC (program chain).
32     struct pgc_ref
33     {
34         explicit pgc_ref(pgc_type type = unknown_pgc,
35                          int index = -1,
36                          int sub_index = 0)
37                 : type(type), index(index), sub_index(sub_index)
38             {}
39         bool operator==(const pgc_ref & other) const
40             {
41                 return type == other.type && index == other.index;
42             }
43         bool operator!=(const pgc_ref & other) const
44             {
45                 return !(*this == other);
46             }
47             
48         pgc_type type;      // Menu or title reference?
49         unsigned index;     // Menu or title index (within resp. vector)
50         unsigned sub_index; // Button or chapter number (1-based; 0 if
51                             // unspecified; not compared!)
52     };
53
54     // We can try using any of these encoders to convert PNG to MPEG.
55     enum mpeg_encoder
56     {
57         mpeg_encoder_ffmpeg,         // ffmpeg
58         mpeg_encoder_mjpegtools_old, // mjpegtools before version 1.8
59         mpeg_encoder_mjpegtools_new  // mjpegtools from version 1.8
60     };
61
62     dvd_generator(const video::frame_params & frame_params,
63                   mpeg_encoder encoder)
64             : frame_params_(frame_params),
65               encoder_(encoder)
66         {}
67
68     // Create a new empty menu; return a reference to it.
69     // The client must call generate_menu_vob() for each menu before
70     // calling generate().
71     pgc_ref add_menu();
72     // Add a menu entry (link) to an existing menu.
73     void add_menu_entry(unsigned index,
74                         const rectangle & area,
75                         const pgc_ref & target);
76     // Generate the menu VOB from a background image and button
77     // highlight image.
78     void generate_menu_vob(unsigned index,
79                            Glib::RefPtr<Gdk::Pixbuf> background,
80                            Glib::RefPtr<Gdk::Pixbuf> highlights) const;
81
82     // Create a new title using the given vob_list; return a reference
83     // to it.  The argument will be pilfered (i.e. emptied).
84     pgc_ref add_title(vob_list & list);
85
86     // Use dvdauthor to generate a DVD filesystem.
87     void generate(const std::string & output_dir) const;
88
89 private:
90     struct menu_entry
91     {
92         rectangle area;
93         pgc_ref target;
94     };
95
96     // Menu definition.
97     struct menu
98     {
99         menu();
100
101         // Temporary file in which the menu VOB should be generated.
102         // This is created as an empty file and then closed.
103         boost::shared_ptr<temp_file> vob_temp;
104
105         // References to the menus and titles that the menu buttons
106         // are meant to link to, in the same order as the buttons.
107         std::vector<menu_entry> entries;
108     };
109
110     video::frame_params frame_params_;
111     mpeg_encoder encoder_;
112     std::vector<menu> menus_;
113     std::vector<vob_list> titles_;
114 };
115
116 #endif // !INC_GENERATE_DVD_HPP