1a1830cbdSFrançois Revol /*
2a1830cbdSFrançois Revol * Copyright 2004-2008, François Revol, <revol@free.fr>.
3a1830cbdSFrançois Revol * Distributed under the terms of the MIT License.
4a1830cbdSFrançois Revol */
52c9bd703SFrançois Revol #ifndef _VIDEO_PRODUCER_H
62c9bd703SFrançois Revol #define _VIDEO_PRODUCER_H
72c9bd703SFrançois Revol
82c9bd703SFrançois Revol #include <kernel/OS.h>
92c9bd703SFrançois Revol #include <media/BufferProducer.h>
102c9bd703SFrançois Revol #include <media/Controllable.h>
112c9bd703SFrançois Revol #include <media/MediaDefs.h>
122c9bd703SFrançois Revol #include <media/MediaEventLooper.h>
132c9bd703SFrançois Revol #include <media/MediaNode.h>
142c9bd703SFrançois Revol #include <support/Locker.h>
150866ac7eSFrançois Revol #include <support/String.h>
162c9bd703SFrançois Revol
172c9bd703SFrançois Revol class CamDevice;
180866ac7eSFrançois Revol class BParameter;
190866ac7eSFrançois Revol class BTextParameter;
202c9bd703SFrançois Revol
212c9bd703SFrançois Revol class VideoProducer :
222c9bd703SFrançois Revol public virtual BMediaEventLooper,
232c9bd703SFrançois Revol public virtual BBufferProducer,
24*02af02f9SJérôme Duval public virtual BControllable {
252c9bd703SFrançois Revol public:
262c9bd703SFrançois Revol VideoProducer(BMediaAddOn *addon, CamDevice *dev,
272c9bd703SFrançois Revol const char *name, int32 internal_id);
282c9bd703SFrançois Revol virtual ~VideoProducer();
292c9bd703SFrançois Revol
InitCheck()302c9bd703SFrançois Revol virtual status_t InitCheck() const { return fInitStatus; }
312c9bd703SFrançois Revol
32a486abdcSFrançois Revol
332c9bd703SFrançois Revol /* BMediaNode */
342c9bd703SFrançois Revol public:
352c9bd703SFrançois Revol virtual port_id ControlPort() const;
362c9bd703SFrançois Revol virtual BMediaAddOn *AddOn(int32 * internal_id) const;
372c9bd703SFrançois Revol virtual status_t HandleMessage(int32 message, const void *data,
382c9bd703SFrançois Revol size_t size);
392c9bd703SFrançois Revol protected:
402c9bd703SFrançois Revol virtual void Preroll();
412c9bd703SFrançois Revol virtual void SetTimeSource(BTimeSource * time_source);
422c9bd703SFrançois Revol virtual status_t RequestCompleted(const media_request_info & info);
432c9bd703SFrançois Revol
442c9bd703SFrançois Revol /* BMediaEventLooper */
452c9bd703SFrançois Revol protected:
462c9bd703SFrançois Revol virtual void NodeRegistered();
472c9bd703SFrançois Revol virtual void Start(bigtime_t performance_time);
482c9bd703SFrançois Revol virtual void Stop(bigtime_t performance_time, bool immediate);
492c9bd703SFrançois Revol virtual void Seek(bigtime_t media_time, bigtime_t performance_time);
502c9bd703SFrançois Revol virtual void TimeWarp(bigtime_t at_real_time,
512c9bd703SFrançois Revol bigtime_t to_performance_time);
522c9bd703SFrançois Revol virtual status_t AddTimer(bigtime_t at_performance_time, int32 cookie);
532c9bd703SFrançois Revol virtual void SetRunMode(run_mode mode);
542c9bd703SFrançois Revol virtual void HandleEvent(const media_timed_event *event,
552c9bd703SFrançois Revol bigtime_t lateness, bool realTimeEvent = false);
562c9bd703SFrançois Revol virtual void CleanUpEvent(const media_timed_event *event);
572c9bd703SFrançois Revol virtual bigtime_t OfflineTime();
582c9bd703SFrançois Revol virtual void ControlLoop();
592c9bd703SFrançois Revol virtual status_t DeleteHook(BMediaNode * node);
602c9bd703SFrançois Revol
612c9bd703SFrançois Revol /* BBufferProducer */
622c9bd703SFrançois Revol protected:
632c9bd703SFrançois Revol virtual status_t FormatSuggestionRequested(media_type type, int32 quality,
642c9bd703SFrançois Revol media_format * format);
652c9bd703SFrançois Revol virtual status_t FormatProposal(const media_source &output,
662c9bd703SFrançois Revol media_format *format);
672c9bd703SFrançois Revol virtual status_t FormatChangeRequested(const media_source &source,
682c9bd703SFrançois Revol const media_destination &destination,
692c9bd703SFrançois Revol media_format *io_format, int32 *_deprecated_);
702c9bd703SFrançois Revol virtual status_t GetNextOutput(int32 * cookie, media_output * out_output);
712c9bd703SFrançois Revol virtual status_t DisposeOutputCookie(int32 cookie);
722c9bd703SFrançois Revol virtual status_t SetBufferGroup(const media_source &for_source,
732c9bd703SFrançois Revol BBufferGroup * group);
742c9bd703SFrançois Revol virtual status_t VideoClippingChanged(const media_source &for_source,
752c9bd703SFrançois Revol int16 num_shorts, int16 *clip_data,
762c9bd703SFrançois Revol const media_video_display_info &display,
772c9bd703SFrançois Revol int32 * _deprecated_);
782c9bd703SFrançois Revol virtual status_t GetLatency(bigtime_t * out_latency);
792c9bd703SFrançois Revol virtual status_t PrepareToConnect(const media_source &what,
802c9bd703SFrançois Revol const media_destination &where,
812c9bd703SFrançois Revol media_format *format,
822c9bd703SFrançois Revol media_source *out_source, char *out_name);
832c9bd703SFrançois Revol virtual void Connect(status_t error, const media_source &source,
842c9bd703SFrançois Revol const media_destination &destination,
852c9bd703SFrançois Revol const media_format & format, char *io_name);
862c9bd703SFrançois Revol virtual void Disconnect(const media_source & what,
872c9bd703SFrançois Revol const media_destination & where);
882c9bd703SFrançois Revol virtual void LateNoticeReceived(const media_source & what,
892c9bd703SFrançois Revol bigtime_t how_much, bigtime_t performance_time);
902c9bd703SFrançois Revol virtual void EnableOutput(const media_source & what, bool enabled,
912c9bd703SFrançois Revol int32 * _deprecated_);
922c9bd703SFrançois Revol virtual status_t SetPlayRate(int32 numer,int32 denom);
932c9bd703SFrançois Revol virtual void AdditionalBufferRequested(const media_source & source,
942c9bd703SFrançois Revol media_buffer_id prev_buffer, bigtime_t prev_time,
952c9bd703SFrançois Revol const media_seek_tag * prev_tag);
962c9bd703SFrançois Revol virtual void LatencyChanged(const media_source & source,
972c9bd703SFrançois Revol const media_destination & destination,
982c9bd703SFrançois Revol bigtime_t new_latency, uint32 flags);
992c9bd703SFrançois Revol
1002c9bd703SFrançois Revol /* BControllable */
1012c9bd703SFrançois Revol protected:
1022c9bd703SFrançois Revol virtual status_t GetParameterValue(int32 id, bigtime_t *last_change,
1032c9bd703SFrançois Revol void *value, size_t *size);
1042c9bd703SFrançois Revol virtual void SetParameterValue(int32 id, bigtime_t when,
1052c9bd703SFrançois Revol const void *value, size_t size);
1062c9bd703SFrançois Revol virtual status_t StartControlPanel(BMessenger *out_messenger);
1072c9bd703SFrançois Revol
1082c9bd703SFrançois Revol /* state */
1092c9bd703SFrançois Revol private:
1102c9bd703SFrançois Revol void HandleStart(bigtime_t performance_time);
1112c9bd703SFrançois Revol void HandleStop();
1122c9bd703SFrançois Revol void HandleTimeWarp(bigtime_t performance_time);
1132c9bd703SFrançois Revol void HandleSeek(bigtime_t performance_time);
1142c9bd703SFrançois Revol
1150866ac7eSFrançois Revol void _UpdateStats();
1160866ac7eSFrançois Revol
1172c9bd703SFrançois Revol static int32 fInstances;
1182c9bd703SFrançois Revol
1192c9bd703SFrançois Revol status_t fInitStatus;
1202c9bd703SFrançois Revol
1212c9bd703SFrançois Revol int32 fInternalID;
1222c9bd703SFrançois Revol BMediaAddOn *fAddOn;
1232c9bd703SFrançois Revol CamDevice *fCamDevice;
1242c9bd703SFrançois Revol
1252c9bd703SFrançois Revol BLocker fLock;
1262c9bd703SFrançois Revol BBufferGroup *fBufferGroup;
1272c9bd703SFrançois Revol
1282c9bd703SFrançois Revol thread_id fThread;
1292c9bd703SFrançois Revol sem_id fFrameSync;
1302c9bd703SFrançois Revol static int32 _frame_generator_(void *data);
1312c9bd703SFrançois Revol int32 FrameGenerator();
1322c9bd703SFrançois Revol
1332c9bd703SFrançois Revol /* The remaining variables should be declared volatile, but they
1342c9bd703SFrançois Revol * are not here to improve the legibility of the sample code. */
1352c9bd703SFrançois Revol uint32 fFrame;
1362c9bd703SFrançois Revol uint32 fFrameBase;
1372c9bd703SFrançois Revol bigtime_t fPerformanceTimeBase;
1382c9bd703SFrançois Revol bigtime_t fProcessingLatency;
1392c9bd703SFrançois Revol media_output fOutput;
1402c9bd703SFrançois Revol media_raw_video_format fConnectedFormat;
1412c9bd703SFrançois Revol bool fRunning;
1422c9bd703SFrançois Revol bool fConnected;
1432c9bd703SFrançois Revol bool fEnabled;
1442c9bd703SFrançois Revol
1450866ac7eSFrançois Revol enum {
1460866ac7eSFrançois Revol P_COLOR,
1470866ac7eSFrançois Revol P_INFO,
1480866ac7eSFrançois Revol P_LAST // first available for addons
1490866ac7eSFrançois Revol };
1502c9bd703SFrançois Revol uint32 fColor;
1510866ac7eSFrançois Revol BString fInfoString;
1520866ac7eSFrançois Revol bigtime_t fLastColorChange; // TODO: rename
1530866ac7eSFrançois Revol
1540866ac7eSFrançois Revol struct {
1550866ac7eSFrançois Revol uint32 frames;
1560866ac7eSFrançois Revol uint32 actual;
1570866ac7eSFrançois Revol uint32 missed;
1580866ac7eSFrançois Revol bigtime_t stamp;
1590866ac7eSFrançois Revol } fStats[2];
1602c9bd703SFrançois Revol };
1612c9bd703SFrançois Revol
1622c9bd703SFrançois Revol #endif
163