xref: /haiku/headers/os/media/MediaRecorder.h (revision fcf7cbe79e26d0c2d9d339c2dc826db755bc7323)
1 /*
2  * Copyright 2014, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _MEDIA_RECORDER_H
6 #define _MEDIA_RECORDER_H
7 
8 
9 #include <MediaDefs.h>
10 #include <MediaNode.h>
11 
12 
13 namespace BPrivate { namespace media {
14 class BMediaRecorderNode;
15 }
16 }
17 
18 
19 class BMediaRecorder {
20 public:
21 	enum notification {
22 		B_WILL_START = 1,	// performance_time
23 		B_WILL_STOP,		// performance_time immediate
24 		B_WILL_SEEK,		// performance_time media_time
25 		B_WILL_TIMEWARP,	// real_time performance_time
26 	};
27 
28 	typedef void				(*ProcessFunc)(void* cookie,
29 									bigtime_t timestamp, void* data,
30 									size_t size, const media_format& format);
31 
32 	typedef void				(*NotifyFunc)(void* cookie,
33 									notification what, ...);
34 
35 public:
36 								BMediaRecorder(const char* name,
37 									media_type type
38 										= B_MEDIA_UNKNOWN_TYPE);
39 
40 	virtual						~BMediaRecorder();
41 
42 			status_t			InitCheck() const;
43 
44 			status_t			SetHooks(ProcessFunc recordFunc = NULL,
45 									NotifyFunc notifyFunc = NULL,
46 									void* cookie = NULL);
47 
48 			void				SetAcceptedFormat(
49 									const media_format& format);
50 			const media_format&	AcceptedFormat() const;
51 
52 	virtual status_t			Start(bool force = false);
53 	virtual status_t			Stop(bool force = false);
54 
55 	virtual status_t			Connect(const media_format& format);
56 
57 	virtual status_t			Connect(const dormant_node_info& dormantInfo,
58 									const media_format& format);
59 
60 	virtual status_t			Connect(const media_node& node,
61 									const media_output* output = NULL,
62 									const media_format* format = NULL);
63 
64 	virtual status_t			Disconnect();
65 
66 			bool				IsConnected() const;
67 			bool				IsRunning() const;
68 
69 			const media_format&	Format() const;
70 
71 protected:
72 			// Get the producer node source
73 			const media_source&	MediaSource() const;
74 			// This is the our own input
75 			const media_input	MediaInput() const;
76 
77 	virtual	void				BufferReceived(void* buffer, size_t size,
78 									const media_header& header);
79 
80 			status_t			SetUpConnection(media_source outputSource);
81 
82 private:
83 
84 			status_t			_Connect(const media_node& mediaNode,
85 									const media_output* output,
86 									const media_format& format);
87 
88 	virtual	void				_ReservedMediaRecorder0();
89 	virtual	void				_ReservedMediaRecorder1();
90 	virtual	void				_ReservedMediaRecorder2();
91 	virtual	void				_ReservedMediaRecorder3();
92 	virtual	void				_ReservedMediaRecorder4();
93 	virtual	void				_ReservedMediaRecorder5();
94 	virtual	void				_ReservedMediaRecorder6();
95 	virtual	void				_ReservedMediaRecorder7();
96 
97 			status_t			fInitErr;
98 
99 			bool				fConnected;
100 			bool				fRunning;
101 			bool				fReleaseOutputNode;
102 
103 			ProcessFunc			fRecordHook;
104 			NotifyFunc			fNotifyHook;
105 
106 			media_node			fOutputNode;
107 			media_source		fOutputSource;
108 
109 			BPrivate::media::BMediaRecorderNode* fNode;
110 
111 			void*				fBufferCookie;
112 			uint32				fPadding[32];
113 
114 			friend class		BPrivate::media::BMediaRecorderNode;
115 };
116 
117 #endif	//	_MEDIA_RECORDER_H
118