1 ///////////////////////////////////////////////////////////////////////////
3 // Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
6 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of Industrial Light & Magic nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ///////////////////////////////////////////////////////////////////////////
36 #ifndef INCLUDED_IMF_TIME_CODE_H
37 #define INCLUDED_IMF_TIME_CODE_H
39 //-----------------------------------------------------------------------------
43 // A TimeCode object stores time and control codes as described
44 // in SMPTE standard 12M-1999. A TimeCode object contains the
49 // hours integer, range 0 - 23
50 // minutes integer, range 0 - 59
51 // seconds integer, range 0 - 59
52 // frame integer, range 0 - 29
56 // drop frame flag boolean
57 // color frame flag boolean
58 // field/phase flag boolean
63 // Binary groups for user-defined data and control codes:
65 // binary group 1 integer, range 0 - 15
66 // binary group 2 integer, range 0 - 15
68 // binary group 8 integer, range 0 - 15
70 // Class TimeCode contains methods to convert between the fields
71 // listed above and a more compact representation where the fields
72 // are packed into two unsigned 32-bit integers. In the packed
73 // integer representations, bit 0 is the least significant bit,
74 // and bit 31 is the most significant bit of the integer value.
76 // The time address and flags fields can be packed in three
79 // bits packing for packing for packing for
80 // 24-frame 60-field 50-field
81 // film television television
83 // 0 - 3 frame units frame units frame units
84 // 4 - 5 frame tens frame tens frame tens
85 // 6 unused, set to 0 drop frame flag unused, set to 0
86 // 7 unused, set to 0 color frame flag color frame flag
87 // 8 - 11 seconds units seconds units seconds units
88 // 12 - 14 seconds tens seconds tens seconds tens
89 // 15 phase flag field/phase flag bgf0
90 // 16 - 19 minutes units minutes units minutes units
91 // 20 - 22 minutes tens minutes tens minutes tens
93 // 24 - 27 hours units hours units hours units
94 // 28 - 29 hours tens hours tens hours tens
96 // 31 bgf2 bgf2 field/phase flag
98 // User-defined data and control codes are packed as follows:
102 // 0 - 3 binary group 1
103 // 4 - 7 binary group 2
104 // 8 - 11 binary group 3
105 // 12 - 15 binary group 4
106 // 16 - 19 binary group 5
107 // 20 - 23 binary group 6
108 // 24 - 27 binary group 7
109 // 28 - 31 binary group 8
111 //-----------------------------------------------------------------------------
120 //---------------------
121 // Bit packing variants
122 //---------------------
126 TV60_PACKING, // packing for 60-field television
127 TV50_PACKING, // packing for 50-field television
128 FILM24_PACKING // packing for 24-frame film
132 //-------------------------------------
133 // Constructors and assignment operator
134 //-------------------------------------
136 TimeCode (); // all fields set to 0 or false
142 bool dropFrame = false,
143 bool colorFrame = false,
144 bool fieldPhase = false,
148 int binaryGroup1 = 0,
149 int binaryGroup2 = 0,
150 int binaryGroup3 = 0,
151 int binaryGroup4 = 0,
152 int binaryGroup5 = 0,
153 int binaryGroup6 = 0,
154 int binaryGroup7 = 0,
155 int binaryGroup8 = 0);
157 TimeCode (unsigned int timeAndFlags,
158 unsigned int userData = 0,
159 Packing packing = TV60_PACKING);
161 TimeCode (const TimeCode &other);
163 TimeCode & operator = (const TimeCode &other);
166 //----------------------------
167 // Access to individual fields
168 //----------------------------
171 void setHours (int value);
173 int minutes () const;
174 void setMinutes (int value);
176 int seconds () const;
177 void setSeconds (int value);
180 void setFrame (int value);
182 bool dropFrame () const;
183 void setDropFrame (bool value);
185 bool colorFrame () const;
186 void setColorFrame (bool value);
188 bool fieldPhase () const;
189 void setFieldPhase (bool value);
192 void setBgf0 (bool value);
195 void setBgf1 (bool value);
198 void setBgf2 (bool value);
200 int binaryGroup (int group) const; // group must be between 1 and 8
201 void setBinaryGroup (int group, int value);
204 //---------------------------------
205 // Access to packed representations
206 //---------------------------------
208 unsigned int timeAndFlags (Packing packing = TV60_PACKING) const;
210 void setTimeAndFlags (unsigned int value,
211 Packing packing = TV60_PACKING);
213 unsigned int userData () const;
215 void setUserData (unsigned int value);