1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 2005-2007 Koos Vriezen <koos.vriezen@gmail.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef _KMPLAYER_SMILL_H_
22 #define _KMPLAYER_SMILL_H_
23 
24 #include "config-kmplayer.h"
25 #include <qstring.h>
26 #include <qstringlist.h>
27 
28 #include "kmplayerplaylist.h"
29 #include "surface.h"
30 
31 struct TransTypeInfo;
32 
33 namespace KMPlayer {
34 
35 class ImageMedia;
36 class Expression;
37 
38 /*
39  * Interpretation of sizes
40  */
41 class KMPLAYER_NO_EXPORT SizeType {
42 public:
43     SizeType ();
44     SizeType (const QString & s, bool force_perc=false);
45     void reset ();
46     SizeType & operator = (const QString & s);
47     SizeType & operator = (Single d);
48     SizeType & operator += (const SizeType & s);
49     SizeType & operator -= (const SizeType & s);
50     SizeType & operator /= (const int i)
51         { perc_size /= i; abs_size /= i; return *this; }
52     SizeType & operator *= (const float f)
53         { perc_size *= f; abs_size *= f; return *this; }
54     Single size (Single relative_to = 100) const;
isSet()55     bool isSet () const { return isset; }
56     QString toString () const;
57 private:
58     Single perc_size;
59     Single abs_size;
60     bool isset;
61     bool has_percentage;
62 };
63 
64 /**
65  * For RegPoint, Region and MediaType, having sizes
66  */
67 class KMPLAYER_NO_EXPORT CalculatedSizer {
68 public:
CalculatedSizer()69     KDE_NO_CDTOR_EXPORT CalculatedSizer () {}
~CalculatedSizer()70     KDE_NO_CDTOR_EXPORT ~CalculatedSizer () {}
71 
72     void resetSizes ();
73     void calcSizes (Node *, CalculatedSizer *region_sz, Single w, Single h,
74             Single & xoff, Single & yoff, Single & w1, Single & h1);
75     bool applyRegPoints (Node *, CalculatedSizer *region_sz, Single w, Single h,
76             Single & xoff, Single & yoff, Single & w1, Single & h1);
77     SizeType left, top, width, height, right, bottom;
78     QString reg_point, reg_align;
79     bool setSizeParam (const TrieString &name, const QString &value);
80     void move (const SizeType &x, const SizeType &y);
81 };
82 
83 /**
84  * Live representation of a SMIL element having timings
85  */
86 class KMPLAYER_NO_EXPORT Runtime {
87 public:
88     enum TimingState {
89         TimingsInit = 0, TimingsInitialized, TimingsDisabled,
90         timings_began, timings_started, TimingsTransIn, timings_paused,
91         timings_stopped, timings_freezed
92     };
93     enum Fill {
94         fill_default, fill_inherit, fill_remove, fill_freeze,
95         fill_hold, fill_transition, fill_auto
96     };
97     enum DurationTime { BeginTime = 0, DurTime, EndTime, DurTimeLast };
98     enum Duration {
99         DurIndefinite = -1,
100         DurTimer = (int) MsgEventTimer,
101         DurActivated = (int) MsgEventClicked,
102         DurInBounds = (int) MsgEventPointerInBounds,
103         DurOutBounds = (int) MsgEventPointerOutBounds,
104         DurStart = (int) MsgEventStarted,
105         DurEnd = (int) MsgEventStopped,
106         DurMedia = (int)MsgMediaFinished,
107         DurStateChanged = (int)MsgStateChanged,
108         DurAccessKey = (int)MsgAccessKey,
109         DurTransition,
110         DurLastDuration
111     };
112     Runtime (Element *e);
113     ~Runtime ();
114     /**
115      * Called when element is pulled in scope, from Node::activate()
116      */
117     void start ();
tryFinish()118     void tryFinish () { propagateStop (false); }
doFinish()119     void doFinish () { propagateStop (true); }
120     void finish ();
121     void startAndBeginNode (); // skip start timer (if any)
122     /**
123      * Reset all data, called from end() and init()
124      */
125     void init ();
126     void initialize ();
127     bool parseParam (const TrieString & name, const QString & value);
state()128     TimingState state () const { return timingstate; }
129     void message (MessageType msg, void *content=NULL);
130     void *role (RoleType msg, void *content=NULL);
131     /**
132      * Duration items, begin/dur/end, length information or connected element
133      */
134     struct DurationItem {
135         DurationItem ();
136         DurationItem &operator = (const DurationItem &other);
137         bool matches (const Duration dur, const Posting *post);
138         void clear();
139         Duration durval;
140         int offset;
141         VirtualVoid *payload;
142         ConnectionLink connection;
143         DurationItem *next;
144     } durations [(const int) DurTimeLast];
145     void setDuration ();
146     bool started () const;
active()147     bool active () const {
148         return timingstate >= timings_started && timingstate != timings_stopped;
149     }
150     void stopped ();
beginTime()151     KDE_NO_EXPORT DurationItem & beginTime () { return durations[BeginTime]; }
durTime()152     KDE_NO_EXPORT DurationItem & durTime () { return durations[DurTime]; }
endTime()153     KDE_NO_EXPORT DurationItem & endTime () { return durations [EndTime]; }
154 
155     TimingState timingstate;
156     TimingState unpaused_state;
157     int repeat_count;
158     QString expr;
159     ConnectionList m_StartListeners;        // Element about to be started
160     ConnectionList m_StartedListeners;      // Element is started
161     ConnectionList m_StoppedListeners;      // Element stopped
162     Posting *begin_timer;
163     Posting *duration_timer;
164     Posting *started_timer;
165     Posting *stopped_timer;
166     NodePtrW paused_by;
167     unsigned int start_time;
168     unsigned int finish_time;
169     unsigned int paused_time;
170     Fill fill;
171     Fill fill_def;
172     Fill fill_active;
173     Element *element;
174     int trans_in_dur;
175 private:
176     void propagateStop (bool forced);
177     void propagateStart ();
178     int repeat;
179 };
180 
181 class KMPLAYER_NO_EXPORT MouseListeners {
182 public:
183     MouseListeners();
184 
185     ConnectionList *receivers (MessageType msg);
186 
187     ConnectionList m_ActionListeners;      // mouse clicked
188     ConnectionList m_OutOfBoundsListeners; // mouse left
189     ConnectionList m_InBoundsListeners;    // mouse entered
190 };
191 
192 /**
193  * Translates string to centi-seconds or 'special' high number
194  */
195 bool parseTime (const QString & val, int & dur /*,const QString & dateformat*/);
196 
197 class KMPLAYER_NO_EXPORT SmilTextProperties {
198 public:
199     enum Align { AlignInherit, AlignLeft, AlignCenter, AlignRight };
200     enum FontWeight { WeightNormal, WeightBold, WeightInherit };
201     enum Spacing { SpaceDefault, SpacePreserve };
202     enum Style {
203         StyleNormal, StyleItalic, StyleOblique, StyleRevOblique, StyleInherit
204     };
205     enum TextDirection { DirLtr, DirRtl, DirLtro, DirRtlo, DirInherit };
206     enum TextMode { ModeAppend, ModeReplace, ModeInherit };
207     enum TextPlace { PlaceStart, PlaceCenter, PlaceEnd, PlaceInherit };
208     enum TextWrap { Wrap, NoWrap, WrapInherit };
209     enum TextWriting { WritingLrTb, WritingRlTb, WritingTbLr, WritingTbRl };
210 
211     void init ();
212     bool parseParam (const TrieString &name, const QString &value);
213     void mask (const SmilTextProperties &props);
214 
215     QString font_family;
216     QString text_style;
217     int font_color;
218     int background_color;
219     unsigned char text_direction;
220     unsigned char font_style;
221     unsigned char font_weight;
222     unsigned char text_mode;
223     unsigned char text_place;
224     unsigned char text_wrap;
225     unsigned char space;
226     unsigned char text_writing;
227     unsigned char text_align;
228     unsigned char padding;
229     SizeType font_size;
230 };
231 
232 class KMPLAYER_NO_EXPORT SmilColorProperty {
233 public:
234     void init ();
235     void setColor (const QString &value);
236     void setOpacity (const QString &value);
237 
238     unsigned int color;
239     int opacity;
240 };
241 
242 class KMPLAYER_NO_EXPORT MediaOpacity {
243 public:
244     void init ();
245 
246     unsigned short opacity;
247     unsigned short bg_opacity;
248 };
249 
250 class KMPLAYER_NO_EXPORT TransitionModule {
251 public:
TransitionModule()252     TransitionModule ()
253      : trans_start_time (0),
254        trans_out_timer (NULL),
255        trans_out_active (false) {}
256 
257     void init ();
258     void begin (Node *n, Runtime *r);
259     bool handleMessage (Node *n, Runtime *r, Surface *s, MessageType m, void *);
260     void cancelTimer (Node *n);
261     void finish (Node *n);
262 
263     NodePtrW trans_in;
264     NodePtrW trans_out;
265     NodePtrW active_trans;
266     unsigned int trans_start_time;
267     unsigned int trans_end_time;
268     Posting *trans_out_timer;
269     float trans_gain;
270     ConnectionList m_TransformedIn;        // transIn ready
271     ConnectionLink transition_updater;
272     bool trans_out_active;
273 };
274 
275 //-----------------------------------------------------------------------------
276 
277 namespace SMIL {
278 
279 const short id_node_smil = 100;
280 const short id_node_head = 101;
281 const short id_node_state = 102;
282 const short id_node_layout = 103;
283 const short id_node_root_layout = 104;
284 const short id_node_region = 105;
285 const short id_node_regpoint = 106;
286 const short id_node_transition = 107;
287 const short id_node_body = 110;
288 const short id_node_par = 111;
289 const short id_node_seq = 112;
290 const short id_node_switch = 113;
291 const short id_node_excl = 114;
292 const short id_node_text = 120;
293 const short id_node_ref = 121;
294 const short id_node_brush = 122;
295 const short id_node_smil_text = 123;
296 const short id_node_tev = 124;
297 const short id_node_clear = 125;
298 const short id_node_text_styling = 126;
299 const short id_node_set_value = 127;
300 const short id_node_new_value = 128;
301 const short id_node_del_value = 129;
302 const short id_node_send = 130;
303 const short id_node_set = 132;
304 const short id_node_animate = 133;
305 const short id_node_animate_color = 134;
306 const short id_node_animate_motion = 135;
307 const short id_node_title = 140;
308 const short id_node_param = 141;
309 const short id_node_meta = 142;
310 const short id_node_priorityclass = 143;
311 const short id_node_div = 144;
312 const short id_node_span = 145;
313 const short id_node_p = 146;
314 const short id_node_br = 147;
315 const short id_node_anchor = 150;
316 const short id_node_area = 151;
317 const short id_node_state_data = 151;
318 const short id_node_first = id_node_smil;
319 const short id_node_first_timed_mrl = id_node_body;
320 const short id_node_last_timed_mrl = id_node_animate_motion;
321 const short id_node_first_mediatype = id_node_text;
322 const short id_node_last_mediatype = id_node_brush;
323 const short id_node_first_group = id_node_body;
324 const short id_node_last_group = id_node_excl;
325 const short id_node_last = 200; // reserve 100 ids
326 
327 /**
328  * '<smil>' tag
329  */
330 class Smil : public Mrl {
331 public:
Smil(NodePtr & d)332     KDE_NO_CDTOR_EXPORT Smil (NodePtr & d) : Mrl (d, id_node_smil) {}
333     Node *childFromTag (const QString & tag);
nodeName()334     KDE_NO_EXPORT const char * nodeName () const { return "smil"; }
playType()335     PlayType playType () { return play_type_video; }
336     void activate ();
337     void deactivate ();
338     void closed ();
339     void *role (RoleType msg, void *content=NULL);
340     void message (MessageType msg, void *content=NULL);
accept(Visitor * v)341     void accept (Visitor *v) { v->visit (this); }
342     void jump (const QString & id);
343     static Smil * findSmilNode (Node * node);
344 
345     NodePtrW layout_node;
346     NodePtrW state_node;
347 };
348 
349 /**
350  * Represents optional 'head' tag of SMIL document as in
351  * &lt;smil&gt;&lt;head/&gt;&lt;body/&gt;&lt;/smil&gt;
352  */
353 class KMPLAYER_NO_EXPORT Head : public Element {
354 public:
Head(NodePtr & d)355     KDE_NO_CDTOR_EXPORT Head (NodePtr & d) : Element (d, id_node_head) {}
356     Node *childFromTag (const QString & tag);
nodeName()357     KDE_NO_EXPORT const char * nodeName () const { return "head"; }
358     void closed ();
359     void message (MessageType msg, void *content=NULL);
360 };
361 
362 /**
363  * Defines state, should reside below 'head' element
364  */
365 class KMPLAYER_NO_EXPORT State : public Element {
366 public:
367     enum Where { before, after, child };
368     enum Method { get, put };
369     enum Replace { all, instance, none };
370 
371     State (NodePtr & d);
372 
373     virtual Node *childFromTag (const QString & tag);
374     virtual void closed ();
375     virtual void activate ();
376     virtual void parseParam (const TrieString & name, const QString & value);
377     virtual void deactivate ();
378     virtual void message (MessageType msg, void *content=NULL);
379     virtual void *role (RoleType msg, void *content=NULL);
nodeName()380     KDE_NO_EXPORT virtual const char * nodeName () const { return "state"; }
381 
382     QString domain ();
383     void newValue (Node *ref, Where w, const QString &name, const QString &val);
384     void setValue (Node *ref, const QString &value);
385     void delValue (Node *ref);
386     void stateChanged (Node *ref);
387 
388     ConnectionList m_StateChangeListeners;        // setValue changed a value
389     PostponePtr postpone_lock;                    // pause while loading src
390     MediaInfo *media_info;
391     QString m_url;
392 };
393 
394 /**
395  * Defines region layout, should reside below 'head' element
396  */
397 class KMPLAYER_NO_EXPORT Layout : public Element {
398 public:
399     Layout (NodePtr & d);
400     Node *childFromTag (const QString & tag);
nodeName()401     KDE_NO_EXPORT const char * nodeName () const { return "layout"; }
402     void closed ();
403     void message (MessageType msg, void *content=NULL);
accept(Visitor * v)404     void accept (Visitor *v) { v->visit (this); }
405 
406     NodePtrW root_layout;
407 };
408 
409 /**
410  * Base class for SMIL::Region, SMIL::RootLayout and SMIL::Layout
411  */
412 class KMPLAYER_NO_EXPORT RegionBase : public Element {
413 public:
414     enum ShowBackground { ShowAlways, ShowWhenActive };
415 
416     ~RegionBase ();
417     virtual void activate ();
418     virtual void deactivate ();
419     virtual void parseParam (const TrieString & name, const QString & value);
420     virtual void message (MessageType msg, void *content=NULL);
421     virtual void *role (RoleType msg, void *content=NULL);
accept(Visitor * v)422     virtual void accept (Visitor *v) { v->visit (this); }
423     /**
424      * repaints region, calls scheduleRepaint(x,y,w,h) on view
425      */
426     void repaint ();
427     void repaint (const SRect & rect);
428 
429     SurfacePtrW region_surface;
430     MediaInfo *media_info;
431     CalculatedSizer sizes;
432 
433     int z_order;
434     SmilColorProperty background_color;
435     MediaOpacity media_opacity;
436     QString background_image;
437     enum BackgroundRepeat {
438         BgRepeat, BgRepeatX, BgRepeatY, BgNoRepeat, BgInherit
439     } bg_repeat;
440     ShowBackground show_background;
441     Fit fit;
442     SmilTextProperties font_props;
443     ConnectionList m_AttachedMediaTypes;   // active attached mediatypes
444 protected:
445     RegionBase (NodePtr & d, short id);
446     PostponePtr postpone_lock;               // pause while loading bg image
447     void dataArrived (); // image downloaded
448 };
449 
450 /**
451  * Represents the root area for the other regions
452  */
453 class KMPLAYER_NO_EXPORT RootLayout : public RegionBase {
454 public:
RootLayout(NodePtr & d)455     KDE_NO_CDTOR_EXPORT RootLayout (NodePtr & d)
456         : RegionBase (d, id_node_root_layout) {}
457     ~RootLayout ();
458     void closed ();
459     void deactivate ();
460     void message (MessageType msg, void *content=NULL);
461     void *role (RoleType msg, void *content=NULL);
nodeName()462     KDE_NO_EXPORT const char * nodeName () const { return "root-layout"; }
463 };
464 
465 /**
466  * Represents a rectangle on the viewing area
467  */
468 class KMPLAYER_NO_EXPORT Region : public RegionBase {
469 public:
470     Region (NodePtr & d);
471     ~Region ();
472     void deactivate ();
nodeName()473     KDE_NO_EXPORT const char * nodeName () const { return "region"; }
474     Node *childFromTag (const QString & tag);
475     void message (MessageType msg, void *content=NULL);
476     void *role (RoleType msg, void *content=NULL);
477 private:
478     MouseListeners mouse_listeners;
479 };
480 
481 /**
482  * Represents a regPoint element for alignment inside regions
483  */
484 class KMPLAYER_NO_EXPORT RegPoint : public Element {
485 public:
RegPoint(NodePtr & d)486     KDE_NO_CDTOR_EXPORT RegPoint (NodePtr & d) : Element(d, id_node_regpoint) {}
~RegPoint()487     KDE_NO_CDTOR_EXPORT ~RegPoint () {}
nodeName()488     KDE_NO_EXPORT const char * nodeName () const { return "regPoint"; }
489     void parseParam (const TrieString & name, const QString & value);
490     CalculatedSizer sizes;
491 };
492 
493 /**
494  * Represents a transition element for starting media types
495  */
496 class KMPLAYER_NO_EXPORT Transition : public Element {
497 public:
498     enum TransType {
499         TransTypeNone = 0,
500         BarWipe, IrisWipe, ClockWipe, SnakeWipe, // required, TODO
501         BoxWipe, FourBoxWipe, BarnDoorWipe, DiagonalWipe, BowTieWipe,
502         MiscDiagonalWipe, VeeWipe, BarnVeeWipe, ZigZagWipe, BarnZigZagWipe,
503         TriangleWipe, ArrowHeadWipe, PentagonWipe, HexagonWipe, EllipseWipe,
504         EyeWipe, RoundRectWipe, StarWipe, MiscShapeWipe,
505         PinWheelWipe, SingleSweepWipe, FanWipe, DoubleFanWipe,
506         DoubleSweepWipe, SaloonDoorWipe, WindShieldWipe,
507         SpiralWipe, ParallelSnakesWipe, BoxSnakesWipe, WaterFallWipe,
508         PushWipe, SideWipe, Fade,
509         TransLast
510     };
511     enum TransSubType {
512         SubTransTypeNone = 0,
513         SubLeftToRight, SubTopToBottom, SubTopLeft, SubTopRight,
514         SubBottomRight, SubBottomLeft,
515         SubTopCenter, SubRightCenter, SubBottomCenter, SubLeftCenter,
516         SubCornersIn, SubCornersOut,
517         SubCircle, SubVertical, SubHorizontal,
518         SubFromLeft, SubFromTop, SubFromRight, SubFromBottom,
519         SubCrossfade, SubFadeToColor, SubFadeFromColor,
520         SubRectangle, SubDiamond,
521         SubClockwiseTwelve, SubClockwiseThree, SubClockwiseSix,
522         SubClockwiseNine,
523          // and lots more .. TODO
524         SubTransLast
525     };
526     Transition (NodePtr & d);
~Transition()527     KDE_NO_CDTOR_EXPORT ~Transition () {}
528     void activate ();
accept(Visitor * v)529     KDE_NO_EXPORT void accept (Visitor * v) { v->visit (this); }
nodeName()530     KDE_NO_EXPORT const char * nodeName () const { return "transition"; }
531     void parseParam (const TrieString & name, const QString & value);
532     bool supported ();
533     TransType type;
534     TransSubType sub_type;
535     TransTypeInfo *type_info;
536     enum { dir_forward, dir_reverse } direction;
537     int dur; // centi seconds
538     float start_progress, end_progress;
539     unsigned int fade_color;
540 };
541 
542 /**
543  * Abstract base for the group elements (par/seq/excl/..)
544  */
545 class KMPLAYER_NO_EXPORT GroupBase : public Element {
546 public:
547     ~GroupBase ();
548     Node *childFromTag (const QString & tag);
playType()549     PlayType playType () { return play_type_none; }
550     void parseParam (const TrieString &name, const QString &value);
551     void init ();
552     void finish ();
553     void activate ();
554     void deactivate ();
555     void reset ();
556     void message (MessageType msg, void *content=NULL);
557     void *role (RoleType msg, void *content=NULL);
558     void setJumpNode (NodePtr);
559     Runtime *runtime;
560 protected:
561     GroupBase (NodePtr & d, short id);
562     NodePtrW jump_node;
563 };
564 
565 /**
566  * A Par represents parallel processing of all its children
567  */
568 class KMPLAYER_NO_EXPORT Par : public GroupBase {
569 public:
Par(NodePtr & d)570     KDE_NO_CDTOR_EXPORT Par (NodePtr & d) : GroupBase (d, id_node_par) {}
nodeName()571     KDE_NO_EXPORT const char * nodeName () const { return "par"; }
572     void begin ();
573     void reset ();
574     void message (MessageType msg, void *content=NULL);
575     void *role (RoleType msg, void *content=NULL);
accept(Visitor * v)576     KDE_NO_EXPORT void accept (Visitor * v) { v->visit (this); }
577 };
578 
579 /**
580  * A Seq represents sequential processing of all its children
581  */
582 class KMPLAYER_NO_EXPORT Seq : public GroupBase {
583 public:
Seq(NodePtr & d)584     KDE_NO_CDTOR_EXPORT Seq (NodePtr & d) : GroupBase(d, id_node_seq) {}
nodeName()585     KDE_NO_EXPORT const char * nodeName () const { return "seq"; }
586     void begin ();
587     void message (MessageType msg, void *content=NULL);
588     void *role (RoleType msg, void *content=NULL);
accept(Visitor * v)589     KDE_NO_EXPORT void accept (Visitor * v) { v->visit (this); }
590     ConnectionLink starting_connection;
591     ConnectionLink trans_connection;
592 protected:
Seq(NodePtr & d,short id)593     KDE_NO_CDTOR_EXPORT Seq (NodePtr & d, short id) : GroupBase(d, id) {}
594 };
595 
596 /**
597  * Represents the 'body' tag of SMIL document as in
598  * &lt;smil&gt;&lt;head/&gt;&lt;body/&gt;&lt;/smil&gt;
599  */
600 class KMPLAYER_NO_EXPORT Body : public Seq {
601 public:
Body(NodePtr & d)602     KDE_NO_CDTOR_EXPORT Body (NodePtr & d) : Seq (d, id_node_body) {}
nodeName()603     KDE_NO_EXPORT const char * nodeName () const { return "body"; }
604 };
605 
606 /**
607  * An Excl represents exclusive processing of one of its children
608  */
609 class KMPLAYER_NO_EXPORT Excl : public GroupBase {
610 public:
611     Excl (NodePtr & d);
612     ~Excl ();
nodeName()613     KDE_NO_EXPORT const char * nodeName () const { return "excl"; }
614     Node *childFromTag (const QString & tag);
615     void begin ();
616     void deactivate ();
617     void message (MessageType msg, void *content=NULL);
accept(Visitor * v)618     KDE_NO_EXPORT void accept (Visitor * v) { v->visit (this); }
619 
620     struct ConnectionItem {
ConnectionItemConnectionItem621         ConnectionItem (ConnectionItem *n) : next (n) {}
622         ConnectionLink link;
623         ConnectionItem *next;
624     } *started_event_list;
625     ConnectionLink stopped_connection;
626     NodeRefList priority_queue;
627     NodePtrW cur_node;
628 };
629 
630 /**
631  * A PriorityClass groups children within an Excl element
632  */
633 class KMPLAYER_NO_EXPORT PriorityClass : public Element {
634 public:
PriorityClass(NodePtr & d)635     KDE_NO_CDTOR_EXPORT PriorityClass (NodePtr &d)
636         : Element (d, id_node_priorityclass) {}
nodeName()637     KDE_NO_EXPORT const char * nodeName () const { return "priorityClass"; }
638     Node *childFromTag (const QString & tag);
639     void init ();
640     void parseParam (const TrieString &, const QString &);
641     void message (MessageType msg, void *content=NULL);
accept(Visitor * v)642     KDE_NO_EXPORT void accept (Visitor * v) { v->visit (this); }
643 
644     enum { PeersStop, PeersPause, PeersDefer, PeersNever } peers;
645     enum { HigherStop, HigherPause } higher;
646     enum { LowerDefer, LowerNever } lower;
647     enum { PauseDisplayDisable, PauseDisplayHide, PauseDisplayShow } pause_display;
648 };
649 
650 /*
651  * An automatic selection between child elements based on a condition
652  */
653 class KMPLAYER_NO_EXPORT Switch : public GroupBase {
654 public:
Switch(NodePtr & d)655     KDE_NO_CDTOR_EXPORT Switch (NodePtr &d) : GroupBase (d, id_node_switch) {}
nodeName()656     KDE_NO_EXPORT const char * nodeName () const { return "switch"; }
657     // Condition
658     void begin ();
659     void init ();
660     void deactivate ();
661     void reset ();
662     void message (MessageType msg, void *content=NULL);
accept(Visitor * v)663     KDE_NO_EXPORT void accept (Visitor * v) { v->visit (this); }
664 
665     Node *chosenOne ();
666 private:
667     NodePtrW chosen_one;
668 };
669 
670 class KMPLAYER_NO_EXPORT LinkingBase : public Element {
671 public:
~LinkingBase()672     KDE_NO_CDTOR_EXPORT ~LinkingBase () {}
673     void deactivate ();
674     void parseParam (const TrieString & name, const QString & value);
675     ConnectionLink mediatype_attach;
676     QString href;
677     QString target;
678     enum { show_new, show_replace } show;
679 protected:
680     LinkingBase (NodePtr & d, short id);
681 };
682 
683 class KMPLAYER_NO_EXPORT Anchor : public LinkingBase {
684 public:
685     Anchor (NodePtr & d);
~Anchor()686     KDE_NO_CDTOR_EXPORT ~Anchor () {}
687     void activate ();
688     void message (MessageType msg, void *content=NULL);
689     void *role (RoleType msg, void *content=NULL);
nodeName()690     KDE_NO_EXPORT const char * nodeName () const { return "a"; }
691     Node *childFromTag (const QString & tag);
accept(Visitor * v)692     KDE_NO_EXPORT void accept (Visitor * v) { v->visit (this); }
693 };
694 
695 class KMPLAYER_NO_EXPORT Area : public LinkingBase {
696 public:
697     Area (NodePtr & d, const QString & tag);
698     ~Area ();
699     void activate ();
nodeName()700     KDE_NO_EXPORT const char * nodeName () const { return tag.constData (); }
accept(Visitor * v)701     KDE_NO_EXPORT void accept (Visitor * v) { v->visit (this); }
702     void parseParam (const TrieString & name, const QString & value);
703     void *role (RoleType msg, void *content=NULL);
704     SizeType * coords;
705     int nr_coords;
706     const QByteArray tag;
707     MouseListeners mouse_listeners;
708 };
709 
710 /**
711  * Abstract base for the MediaType classes (video/audio/text/img/..)
712  */
713 class KMPLAYER_NO_EXPORT MediaType : public Mrl {
714 public:
715     MediaType (NodePtr & d, const QByteArray& t, short id);
716     ~MediaType ();
717 
718     Node *childFromTag (const QString & tag);
nodeName()719     KDE_NO_EXPORT const char * nodeName () const { return m_type.constData (); }
720     virtual void closed ();
721     virtual void init ();
722     virtual void activate ();
723     virtual void deactivate ();
724     virtual void defer ();
725     virtual void undefer ();
726     virtual void begin ();
727     virtual void finish ();
728     virtual void reset ();
729     SRect calculateBounds ();
730     virtual void parseParam (const TrieString & name, const QString & value);
731     virtual void message (MessageType msg, void *content=NULL);
732     virtual void *role (RoleType msg, void *content=NULL);
accept(Visitor * v)733     virtual void accept (Visitor *v) { v->visit (this); }
734 
735     Surface *surface ();
736 
737     Runtime *runtime;
738     SurfacePtrW sub_surface;
739     NodePtrW external_tree; // if src points to playlist, the resolved top node
740     TransitionModule transition;
741     NodePtrW region_node;
742     QByteArray m_type;
743     CalculatedSizer sizes;
744     CalculatedSizer *pan_zoom;
745     Fit fit;
746     Fit effective_fit;
747     SmilColorProperty background_color;
748     MediaOpacity media_opacity;
749     unsigned int bitrate;
750     enum { sens_opaque, sens_transparent, sens_percentage } sensitivity;
751 
752 protected:
753     virtual void prefetch ();
754     virtual void clipStart ();
755     virtual void clipStop ();
756 
757     MouseListeners mouse_listeners;
758     ConnectionList m_MediaAttached;
759     ConnectionLink region_attach;          // attached to region
760     ConnectionLink document_postponed;     // pause audio/video accordantly
761     PostponePtr postpone_lock;
762 };
763 
764 class KMPLAYER_NO_EXPORT RefMediaType : public MediaType {
765 public:
766     RefMediaType (NodePtr &doc, const QByteArray &tag);
767     Node *childFromTag (const QString & tag);
768     virtual void activate ();
769     virtual void begin ();
770     virtual void finish ();
771     virtual PlayType playType ();
772     virtual void accept (Visitor *);
773     virtual void message (MessageType msg, void *content=NULL);
774     virtual void *role (RoleType msg, void *content=NULL);
775     virtual void prefetch ();
776     virtual void clipStart ();
777 };
778 
779 class KMPLAYER_NO_EXPORT TextMediaType : public MediaType {
780 public:
781     TextMediaType (NodePtr & d);
playType()782     PlayType playType () { return play_type_info; }
783     virtual void init ();
784     virtual void accept (Visitor *);
785     virtual void parseParam (const TrieString &, const QString &);
786     virtual void prefetch ();
787 
788     QString font_name;
789     int font_size;
790     unsigned int font_color;
791     enum { align_left, align_center, align_right } halign;
792 };
793 
794 class KMPLAYER_NO_EXPORT Brush : public MediaType {
795 public:
796     Brush (NodePtr & d);
797     virtual void init ();
798     virtual void accept (Visitor *);
799     virtual void parseParam (const TrieString &, const QString &);
800     SmilColorProperty color;
801 };
802 
803 class KMPLAYER_NO_EXPORT SmilText : public Element {
804 public:
805     SmilText (NodePtr &doc);
806     ~SmilText ();
807     virtual void init ();
808     virtual void activate ();
809     virtual void begin ();
810     virtual void finish ();
811     virtual void deactivate ();
812     virtual void reset ();
nodeName()813     KDE_NO_EXPORT const char *nodeName () const { return "smilText"; }
814     Node *childFromTag (const QString & tag);
815     virtual void parseParam (const TrieString &name, const QString &value);
816     virtual void message (MessageType msg, void *content=NULL);
817     virtual void *role (RoleType msg, void *content=NULL);
accept(Visitor * v)818     virtual void accept (Visitor *v) { v->visit (this); }
819 
820     Surface *surface ();
821     void updateBounds (bool remove);
822 
823     SmilColorProperty background_color;
824     MediaOpacity media_opacity;
825     TransitionModule transition;
826     SmilTextProperties props;
827     SurfacePtrW text_surface;
828     NodePtrW region_node;
829     CalculatedSizer sizes;
830     SSize size;
831     ConnectionLink region_attach;
832     ConnectionList media_attached;
833     MouseListeners mouse_listeners;
834     Runtime *runtime;
835 };
836 
837 class KMPLAYER_NO_EXPORT TextFlow : public Element {
838 public:
839     TextFlow (NodePtr &doc, short id, const QByteArray &tag);
840     ~TextFlow ();
841 
842     virtual void init ();
843     virtual void activate ();
nodeName()844     KDE_NO_EXPORT const char *nodeName () const { return tag.data (); }
845     Node *childFromTag (const QString &tag);
846     virtual void parseParam (const TrieString &name, const QString &value);
accept(Visitor * v)847     virtual void accept (Visitor *v) { v->visit (this); }
848 
849     SmilTextProperties props;
850     QByteArray tag;
851 };
852 
853 class KMPLAYER_NO_EXPORT TemporalMoment : public Element {
854 public:
855     TemporalMoment (NodePtr &doc, short id, const QByteArray &tag);
856     ~TemporalMoment ();
857     virtual void init ();
858     virtual void activate ();
859     virtual void begin ();
860     virtual void deactivate ();
nodeName()861     KDE_NO_EXPORT const char *nodeName () const { return tag.data (); }
862     Node *childFromTag (const QString & tag);
863     virtual void parseParam (const TrieString &name, const QString &value);
864     virtual void message (MessageType msg, void *content=NULL);
865     virtual void *role (RoleType msg, void *content=NULL);
accept(Visitor * v)866     virtual void accept (Visitor *v) { v->visit (this); }
867 
868     Runtime *runtime;
869     QByteArray tag;
870 };
871 
872 class KMPLAYER_NO_EXPORT StateValue : public Element {
873 public:
874     ~StateValue ();
875 
876     virtual void init ();
877     virtual void activate ();
878     virtual void finish ();
879     virtual void deactivate ();
880     virtual void reset ();
881     virtual void parseParam (const TrieString &name, const QString &value);
882     virtual void message (MessageType msg, void *content=NULL);
883     virtual void *role (RoleType msg, void *content=NULL);
884 protected:
885     StateValue (NodePtr &d, short _id);
886 
887     QString value;
888     NodePtrW state;
889     Expression *ref;
890     Runtime *runtime;
891 };
892 
893 class KMPLAYER_NO_EXPORT NewValue : public StateValue {
894 public:
NewValue(NodePtr & d)895     NewValue (NodePtr &d) : StateValue (d, id_node_new_value) {}
896 
897     virtual void init ();
898     virtual void begin ();
899     virtual void parseParam (const TrieString &name, const QString &value);
nodeName()900     KDE_NO_EXPORT const char *nodeName () const { return "newvalue"; }
901 
902 private:
903     QString name;
904     SMIL::State::Where where;
905 };
906 
907 class KMPLAYER_NO_EXPORT SetValue : public StateValue {
908 public:
SetValue(NodePtr & d)909     SetValue (NodePtr &d) : StateValue (d, id_node_set_value) {}
910 
911     virtual void begin ();
nodeName()912     KDE_NO_EXPORT const char *nodeName () const { return "setvalue"; }
913 };
914 
915 class KMPLAYER_NO_EXPORT DelValue : public StateValue {
916 public:
DelValue(NodePtr & d)917     DelValue (NodePtr &d) : StateValue (d, id_node_del_value) {}
918 
919     virtual void begin ();
nodeName()920     KDE_NO_EXPORT const char *nodeName () const { return "delvalue"; }
921 };
922 
923 class KMPLAYER_NO_EXPORT Send : public StateValue {
924 public:
Send(NodePtr & d)925     Send (NodePtr &d) : StateValue (d, id_node_send), media_info (NULL) {}
926 
927     virtual void init ();
928     virtual void begin ();
929     virtual void deactivate ();
930     virtual void parseParam (const TrieString &name, const QString &value);
931     virtual void message (MessageType msg, void *content=NULL);
nodeName()932     KDE_NO_EXPORT const char *nodeName () const { return "send"; }
933 
934 private:
935     QString action;
936     SMIL::State::Replace replace;
937     SMIL::State::Method method;
938     MediaInfo *media_info;
939 };
940 
941 class KMPLAYER_NO_EXPORT AnimateGroup : public Element {
942 public:
943     ~AnimateGroup ();
944     virtual void init ();
945     virtual void activate ();
946     virtual void finish ();
947     virtual void deactivate ();
948     virtual void reset ();
949     virtual void parseParam (const TrieString & name, const QString & value);
950     virtual void message (MessageType msg, void *content=NULL);
951     virtual void *role (RoleType msg, void *content=NULL);
952     Runtime *runtime;
953 protected:
954     virtual void restoreModification ();
955     Node *targetElement ();
956     AnimateGroup (NodePtr &d, short _id);
957     NodePtrW target_element;
958     TrieString changed_attribute;
959     QString target_id;
960     QString change_to;
961     int modification_id;
962 };
963 
964 class KMPLAYER_NO_EXPORT Set : public AnimateGroup {
965 public:
Set(NodePtr & d)966     KDE_NO_CDTOR_EXPORT Set (NodePtr & d) : AnimateGroup (d, id_node_set) {}
967     virtual void begin ();
nodeName()968     KDE_NO_EXPORT const char * nodeName () const { return "set"; }
playType()969     PlayType playType () { return play_type_none; }
970 };
971 
972 class KMPLAYER_NO_EXPORT AnimateBase : public AnimateGroup {
973 public:
974     struct Point2D {
975         float x;
976         float y;
977     };
978     AnimateBase (NodePtr &d, short id);
979     ~AnimateBase ();
980 
981     virtual void init ();
982     virtual void begin ();
983     virtual void finish ();
984     virtual void deactivate ();
985     virtual void parseParam (const TrieString & name, const QString & value);
986     virtual void message (MessageType msg, void *content=NULL);
accept(Visitor * v)987     virtual void accept (Visitor *v) { v->visit (this); }
playType()988     PlayType playType () { return play_type_none; }
989 
990     Posting *anim_timer;
991 protected:
992     virtual bool timerTick (unsigned int cur_time) = 0;
993     virtual void applyStep () = 0;
994 
995     bool setInterval ();
996 
997     enum { acc_none, acc_sum } accumulate;
998     enum { add_replace, add_sum } additive;
999     enum { calc_discrete, calc_linear, calc_paced, calc_spline } calcMode;
1000     QString change_from;
1001     QString change_by;
1002     QStringList values;
1003     ConnectionLink change_updater;
1004     float *keytimes;
1005     Point2D *spline_table;
1006     QStringList splines;
1007     float control_point[4];
1008     unsigned int keytime_count;
1009     unsigned int keytime_steps;
1010     unsigned int interval;
1011     unsigned int interval_start_time;
1012     unsigned int interval_end_time;
1013 };
1014 
1015 class KMPLAYER_NO_EXPORT Animate : public AnimateBase {
1016 public:
1017     Animate (NodePtr &doc);
1018 
1019     virtual void init ();
1020     virtual void begin ();
1021     virtual void finish ();
1022     virtual void deactivate ();
1023     //virtual void accept (Visitor *v) { v->visit (this); }
nodeName()1024     KDE_NO_EXPORT const char * nodeName () const { return "animate"; }
1025 
1026 private:
1027     virtual bool timerTick (unsigned int cur_time);
1028     virtual void applyStep ();
1029 
1030     void cleanUp ();
1031 
1032     int num_count;
1033     SizeType *begin_;
1034     SizeType *cur;
1035     SizeType *delta;
1036     SizeType *end;
1037 };
1038 
1039 class KMPLAYER_NO_EXPORT AnimateMotion : public AnimateBase {
1040 public:
AnimateMotion(NodePtr & d)1041     AnimateMotion (NodePtr &d) : AnimateBase (d, id_node_animate_motion) {}
1042 
1043     virtual void init ();
1044     virtual void begin ();
1045     virtual void finish ();
1046     //virtual void accept (Visitor *v) { v->visit (this); }
nodeName()1047     KDE_NO_EXPORT const char * nodeName () const { return "animateMotion"; }
1048 
1049 private:
1050     virtual void restoreModification ();
1051     virtual bool timerTick (unsigned int cur_time);
1052     virtual void applyStep ();
1053 
1054     CalculatedSizer old_sizes;
1055     SizeType begin_x, begin_y;
1056     SizeType cur_x, cur_y;
1057     SizeType delta_x, delta_y;
1058     SizeType end_x, end_y;
1059 };
1060 
1061 class KMPLAYER_NO_EXPORT AnimateColor : public AnimateBase {
1062 public:
1063     struct Channels {
1064         short blue;
1065         short green;
1066         short red;
1067         short alpha;
1068         unsigned int argb ();
1069         void clear ();
1070         Channels &operator *= (const float f);
1071         Channels &operator += (const Channels &c);
1072         Channels &operator -= (const Channels &c);
1073     };
1074 
AnimateColor(NodePtr & d)1075     AnimateColor (NodePtr &d) : AnimateBase (d, id_node_animate_color) {}
1076 
1077     virtual void init ();
1078     virtual void begin ();
1079     virtual void finish ();
1080     //virtual void accept (Visitor *v) { v->visit (this); }
nodeName()1081     KDE_NO_EXPORT const char * nodeName () const { return "animateColor"; }
1082 
1083 private:
1084     virtual bool timerTick (unsigned int cur_time);
1085     virtual void applyStep ();
1086 
1087     Channels begin_c;
1088     Channels cur_c;
1089     Channels delta_c;
1090     Channels end_c;
1091 };
1092 
1093 // TODO transitionFilter
1094 
1095 class KMPLAYER_NO_EXPORT Param : public Element {
1096 public:
Param(NodePtr & d)1097     KDE_NO_CDTOR_EXPORT Param (NodePtr & d) : Element (d, id_node_param) {}
nodeName()1098     KDE_NO_EXPORT const char * nodeName () const { return "param"; }
1099     void activate ();
1100 };
1101 
1102 } // SMIL namespace
1103 
1104 }  // KMPlayer namespace
1105 
1106 #endif //_KMPLAYER_SMIL_H_
1107