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