xref: /haiku/src/add-ons/media/media-add-ons/firewire_dv/FireWireDVNode.h (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
1 /*
2  * FireWire DV media addon for Haiku
3  *
4  * Copyright (c) 2008, JiSheng Zhang (jszhang3@mail.ustc.edu.cn)
5  * Distributed under the terms of the MIT License.
6  *
7  * Based on DVB media addon
8  * Copyright (c) 2004-2007 Marcus Overhagen <marcus@overhagen.de>
9  */
10 
11 #ifndef __FIREWIRE_DV_NODE_H
12 #define __FIREWIRE_DV_NODE_H
13 
14 
15 #include <OS.h>
16 #include <media/BufferProducer.h>
17 //#include <media/BufferConsumer.h>
18 #include <media/Controllable.h>
19 #include <media/MediaDefs.h>
20 #include <media/MediaEventLooper.h>
21 #include <media/MediaNode.h>
22 #include <support/Locker.h>
23 
24 class FireWireCard;
25 class BParameterGroup;
26 
27 class FireWireDVNode : public virtual BBufferProducer,
28 	public virtual BControllable, public virtual BMediaEventLooper {
29 public:
30 				FireWireDVNode(BMediaAddOn *addon,
31 					const char *name, int32 internal_id,
32 					FireWireCard *card);
33 	virtual			~FireWireDVNode();
34 
35 	virtual	status_t	InitCheck() const { return fInitStatus; }
36 
37 /* BMediaNode */
38 public:
39 	virtual	BMediaAddOn	*AddOn(int32 * internal_id) const;
40 	virtual	status_t 	HandleMessage(int32 message, const void *data,
41 					size_t size);
42 protected:
43 	virtual	void 		Preroll();
44 	virtual void		SetTimeSource(BTimeSource * time_source);
45 	virtual void		SetRunMode(run_mode mode);
46 
47 /* BMediaEventLooper */
48 protected:
49 	virtual	void 		NodeRegistered();
50 	virtual void		HandleEvent(const media_timed_event *event,
51 					bigtime_t lateness,
52 					bool realTimeEvent = false);
53 
54 /* BBufferProducer */
55 protected:
56 	virtual	status_t	FormatSuggestionRequested(media_type type,
57 					int32 quality, media_format* format);
58 	virtual	status_t 	FormatProposal(const media_source &source,
59 					media_format* format);
60 	virtual	status_t	FormatChangeRequested(
61 					const media_source &source,
62 					const media_destination &destination,
63 					media_format* io_format,
64 					int32* _deprecated_);
65 	virtual	status_t 	GetNextOutput(int32* cookie,
66 					media_output* out_output);
67 	virtual	status_t	DisposeOutputCookie(int32 cookie);
68 	virtual	status_t	SetBufferGroup(const media_source& for_source,
69 					BBufferGroup* group);
70 	virtual	status_t 	VideoClippingChanged(
71 					const media_source& for_source,
72 					int16 num_shorts, int16* clip_data,
73 					const media_video_display_info &display,
74 					int32* _deprecated_);
75 	virtual	status_t	GetLatency(bigtime_t* out_latency);
76 	virtual	status_t	PrepareToConnect(const media_source& what,
77 					const media_destination& where,
78 					media_format* format,
79 					media_source* out_source,
80 					char* out_name);
81 	virtual	void		Connect(status_t error,
82 					const media_source& source,
83 					const media_destination& destination,
84 					const media_format& format,
85 					char* io_name);
86 	virtual	void 		Disconnect(const media_source& what,
87 					const media_destination& where);
88 	virtual	void 		LateNoticeReceived(const media_source& what,
89 					bigtime_t how_much,
90 					bigtime_t performance_time);
91 	virtual	void 		EnableOutput(const media_source& what,
92 					bool enabled, int32* _deprecated_);
93 	virtual	void 		AdditionalBufferRequested(
94 					const media_source& source,
95 					media_buffer_id prev_buffer,
96 					bigtime_t prev_time,
97 					const media_seek_tag* prev_tag);
98 
99 /* BControllable */
100 protected:
101 	virtual status_t	GetParameterValue(int32 id,
102 					bigtime_t* last_change, void* value,
103 					size_t* size);
104 	virtual void		SetParameterValue(int32 id, bigtime_t when,
105 					const void* value, size_t size);
106 
107 /* state */
108 private:
109 	void			HandleStart(bigtime_t performance_time);
110 	void			HandleStop();
111 	void			HandleTimeWarp(bigtime_t performance_time);
112 	void			HandleSeek(bigtime_t performance_time);
113 
114 
115 	BParameterWeb*		CreateParameterWeb();
116 	void			SetAboutInfo(BParameterGroup *about);
117 
118 	void			RefreshParameterWeb();
119 
120 	status_t		StartCapture();
121 	status_t		StopCapture();
122 	status_t		StartCaptureThreads();
123 	status_t		StopCaptureThreads();
124 
125 	static int32		_card_reader_thread_(void *arg);
126 
127 	void			card_reader_thread();
128 
129 	status_t		fInitStatus;
130 	int32			fInternalID;
131 	BMediaAddOn*		fAddOn;
132 	bool			fOutputEnabledEncVideo;
133 	media_output		fOutputEncVideo;
134 	media_format		fDefaultFormatEncVideo;
135 	FireWireCard*		fCard;
136 	bool			fCaptureThreadsActive;
137 	thread_id		fThreadIdCardReader;
138 	volatile bool		fTerminateThreads;
139 	BBufferGroup*		fBufferGroupEncVideo;
140 	BParameterWeb*		fWeb;
141 	bool			fCaptureActive;
142 	BLocker			fLock;
143 
144 };
145 
146 #endif	// __FIREWIRE_DV_NODE_H
147 
148