]> git.sesse.net Git - mlt/blob - src/framework/mlt_consumer.h
0b6bc22b0028ada23a4ddf47875eea5750c30fe7
[mlt] / src / framework / mlt_consumer.h
1 /**
2  * \file mlt_consumer.h
3  * \brief abstraction for all consumer services
4  *
5  * Copyright (C) 2003-2008 Ushodaya Enterprises Limited
6  * \author Charles Yates <charles.yates@pandora.be>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #ifndef _MLT_CONSUMER_H_
24 #define _MLT_CONSUMER_H_
25
26 #include "mlt_service.h"
27 #include "mlt_events.h"
28 #include <pthread.h>
29
30 /** \brief Consumer abstract service class
31  *
32  * A consumer is a service that pulls audio and video from the connected
33  * producers, filters, and transitions. Typically a consumer is used to
34  * output audio and/or video to a device, file, or socket.
35  *
36  * \extends mlt_service_s
37  * \properties \em rescale the scaling algorithm to pass on to all scaling
38  * filters, defaults to "bilinear"
39  * \properties \em buffer the number of frames to use in the asynchronous
40  * render thread, defaults to 25
41  * \properties \em frequency the audio sample rate to use in Hertz, defaults to 48000
42  * \properties \em channels the number of audio channels to use, defaults to 2
43  * \properties \em real_time the asynchronous behavior: 1 (default) for asynchronous
44  * with frame dropping, -1 for asynchronous without frame dropping, 0 to disable (synchronous)
45  * \properties \em test_card the name of a resource to use as the test card, defaults to
46  * environment variable MLT_TEST_CARD. If undefined, the hard-coded default test card is
47  * white silence. A test card is what appears when nothing is produced.
48  * \event \em consumer-frame-show Subclass implementations should fire this.
49  * \event \em consumer-frame-render The abstract class fires this.
50  * \event \em consumer-stopped
51  * \properties \em fps video frames per second as floating point (read only)
52  * \properties \em frame_rate_num the numerator of the video frame rate, overrides \p mlt_profile_s
53  * \properties \em frame_rate_den the denominator of the video frame rate, overrides \p mlt_profile_s
54  * \properties \em width the horizontal video resolution, overrides \p mlt_profile_s
55  * \properties \em height the vertical video resolution, overrides \p mlt_profile_s
56  * \properties \em progressive a flag that indicates if the video is interlaced
57  * or progressive, overrides \p mlt_profile_s
58  * \properties \em aspect_ratio the video sample (pixel) aspect ratio as floating point (read only)
59  * \properties \em sample_aspect_num the numerator of the sample aspect ratio, overrides \p mlt_profile_s
60  * \properties \em sample_aspect_den the denominator of the sample aspect ratio, overrides \p mlt_profile_s
61  * \properties \em display_ratio the video frame aspect ratio as floating point (read only)
62  * \properties \em display_aspect_num the numerator of the video frame aspect ratio, overrides \p mlt_profile_s
63  * \properties \em display_aspect_den the denominator of the video frame aspect ratio, overrides \p mlt_profile_s
64  *
65  */
66
67 struct mlt_consumer_s
68 {
69         /** A consumer is a service. */
70         struct mlt_service_s parent;
71
72         /** Start the consumer to pull frames (virtual function).
73          *
74          * \param mlt_consumer a consumer
75          * \return true if there was an error
76          */
77         int ( *start )( mlt_consumer );
78
79         /** Stop the consumer (virtual function).
80          *
81          * \param mlt_consumer a consumer
82          * \return true if there was an error
83          */
84         int ( *stop )( mlt_consumer );
85
86         /** Get whether the consumer is running or stopped (virtual function).
87          *
88          * \param mlt_consumer a consumer
89          * \return true if the consumer is stopped
90          */
91         int ( *is_stopped )( mlt_consumer );
92
93         /** The destructor virtual function
94          *
95          * \param mlt_consumer a consumer
96          */
97         void ( *close )( mlt_consumer );
98
99         void *local; /**< \private instance object */
100         void *child; /**< \private the object of a subclass */
101
102         int real_time;
103         int ahead;
104         mlt_image_format format;
105         mlt_deque queue;
106         pthread_t ahead_thread;
107         pthread_mutex_t mutex;
108         pthread_cond_t cond;
109         pthread_mutex_t put_mutex;
110         pthread_cond_t put_cond;
111         mlt_frame put;
112         int put_active;
113         mlt_event event_listener;
114 };
115
116 #define MLT_CONSUMER_SERVICE( consumer )        ( &( consumer )->parent )
117 #define MLT_CONSUMER_PROPERTIES( consumer )     MLT_SERVICE_PROPERTIES( MLT_CONSUMER_SERVICE( consumer ) )
118
119 extern int mlt_consumer_init( mlt_consumer self, void *child, mlt_profile profile );
120 extern mlt_consumer mlt_consumer_new( mlt_profile profile );
121 extern mlt_service mlt_consumer_service( mlt_consumer self );
122 extern mlt_properties mlt_consumer_properties( mlt_consumer self );
123 extern int mlt_consumer_connect( mlt_consumer self, mlt_service producer );
124 extern int mlt_consumer_start( mlt_consumer self );
125 extern void mlt_consumer_purge( mlt_consumer self );
126 extern int mlt_consumer_put_frame( mlt_consumer self, mlt_frame frame );
127 extern mlt_frame mlt_consumer_get_frame( mlt_consumer self );
128 extern mlt_frame mlt_consumer_rt_frame( mlt_consumer self );
129 extern int mlt_consumer_stop( mlt_consumer self );
130 extern int mlt_consumer_is_stopped( mlt_consumer self );
131 extern void mlt_consumer_stopped( mlt_consumer self );
132 extern void mlt_consumer_close( mlt_consumer );
133
134 #endif