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