1/*
2 * Copyright (c) 2000-2008, Ingo Weinhold <ingo_weinhold@gmx.de>,
3 * Copyright (c) 2000-2008, Stephan Aßmus <superstippi@gmx.de>,
4 * All Rights Reserved. Distributed under the terms of the MIT license.
5 */
6#ifndef NODE_MANAGER_H
7#define NODE_MANAGER_H
8
9
10#include <MediaNode.h>
11
12#include "PlaybackManager.h"
13
14
15class BMediaRoster;
16class AudioProducer;
17class VideoTarget;
18class VideoProducer;
19class VideoConsumer;
20class AudioSupplier;
21class VideoSupplier;
22
23
24class NodeManager : public PlaybackManager {
25public:
26								NodeManager();
27	virtual						~NodeManager();
28
29	// must be implemented in derived classes
30	virtual	VideoTarget*		CreateVideoTarget() = 0;
31	virtual	VideoSupplier*		CreateVideoSupplier() = 0;
32	virtual	AudioSupplier*		CreateAudioSupplier() = 0;
33
34	// NodeManager
35	enum {
36		AUDIO_AND_VIDEO	= 0,
37		VIDEO_ONLY,
38		AUDIO_ONLY
39	};
40
41			status_t			Init(BRect videoBounds, float videoFrameRate,
42									color_space preferredVideoFormat,
43									float audioFrameRate, uint32 audioChannels,
44									int32 loopingMode, bool loopingEnabled,
45									float speed, uint32 enabledNodes,
46									bool useOverlays);
47			status_t			InitCheck();
48								// only call this if the
49								// media_server has died!
50			status_t			CleanupNodes();
51
52			status_t			FormatChanged(BRect videoBounds,
53									float videoFrameRate,
54									color_space preferredVideoFormat,
55									float audioFrameRate, uint32 audioChannels,
56									uint32 enabledNodes,
57									bool useOverlays,
58									bool force = false);
59
60	virtual	void				SetPlayMode(int32 mode,
61									bool continuePlaying = true);
62
63	virtual	bigtime_t			RealTimeForTime(bigtime_t time) const;
64	virtual	bigtime_t			TimeForRealTime(bigtime_t time) const;
65
66	virtual	void				SetCurrentAudioTime(bigtime_t time);
67
68			void				SetVideoBounds(BRect bounds);
69	virtual	BRect				VideoBounds() const;
70
71			void				SetVideoTarget(VideoTarget* vcTarget);
72			VideoTarget*		GetVideoTarget() const;
73
74	virtual	void				SetVolume(float percent);
75
76			void				SetPeakListener(BHandler* handler);
77
78 private:
79			status_t			_SetUpNodes(color_space preferredVideoFormat,
80									uint32 enabledNodes, bool useOverlays,
81									float audioFrameRate,
82									uint32 audioChannels);
83			status_t			_SetUpVideoNodes(
84									color_space preferredVideoFormat,
85									bool useOverlays);
86			status_t			_SetUpAudioNodes(float audioFrameRate,
87									uint32 audioChannels);
88			status_t			_TearDownNodes(bool disconnect = true);
89			status_t			_StartNodes();
90			void				_StopNodes();
91
92private:
93	struct Connection {
94			Connection();
95
96			media_node			producer;
97			media_node			consumer;
98			media_source		source;
99			media_destination	destination;
100			media_format		format;
101			bool				connected;
102	};
103
104private:
105			BMediaRoster*		fMediaRoster;
106
107			// media nodes
108			AudioProducer*		fAudioProducer;
109			VideoConsumer*		fVideoConsumer;
110			VideoProducer*		fVideoProducer;
111			media_node			fTimeSource;
112
113			Connection			fAudioConnection;
114			Connection			fVideoConnection;
115
116			bigtime_t			fPerformanceTimeBase;
117
118			status_t			fStatus;
119			//
120			VideoTarget*		fVideoTarget;
121			AudioSupplier*		fAudioSupplier;
122			VideoSupplier*		fVideoSupplier;
123			BRect				fVideoBounds;
124
125			BHandler*			fPeakListener;
126};
127
128
129#endif	// NODE_MANAGER_H
130