xref: /haiku/src/apps/tv/DeviceRoster.cpp (revision ed6250c95736c0b55da79d6e9dd01369532260c0)
1 /*
2  * Copyright (c) 2004-2007 Marcus Overhagen <marcus@overhagen.de>
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without restriction,
7  * including without limitation the rights to use, copy, modify,
8  * merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 #include "DeviceRoster.h"
26 
27 #include <stdio.h>
28 #include <string.h>
29 #include <Debug.h>
30 
31 
32 DeviceRoster *gDeviceRoster;
33 
34 
35 
36 DeviceRoster::DeviceRoster()
37 {
38 	live_node_info info[MAX_DEVICE_COUNT];
39 	int32 info_count = MAX_DEVICE_COUNT;
40 	status_t err;
41 	err = MediaRoster()->GetLiveNodes(info, &info_count, NULL, NULL, "DVB*", B_BUFFER_PRODUCER | B_PHYSICAL_INPUT);
42 	if (err != B_OK || info_count < 1) {
43 		printf("Can't find live DVB node. Found %ld nodes, error %08lx (%s)\n", info_count, err, strerror(err));
44 		fDeviceCount = 0;
45 	} else {
46 		fDeviceCount = info_count;
47 		for (int i = 0; i < fDeviceCount; i++) {
48 			fDeviceInfo[i].node = info[i].node;
49 			strcpy(fDeviceInfo[i].name, info[i].name);
50 		}
51 	}
52 }
53 
54 
55 DeviceRoster::~DeviceRoster()
56 {
57 }
58 
59 
60 int
61 DeviceRoster::DeviceCount()
62 {
63 	return fDeviceCount;
64 }
65 
66 
67 const char *
68 DeviceRoster::DeviceName(int i)
69 {
70 	ASSERT(i >= 0 && i < fDeviceCount);
71 	return fDeviceInfo[i].name;
72 }
73 
74 
75 media_node
76 DeviceRoster::DeviceNode(int i)
77 {
78 	ASSERT(i >= 0 && i < fDeviceCount);
79 	return fDeviceInfo[i].node;
80 }
81 
82 
83 bool
84 DeviceRoster::IsRawAudioOutputFree(int i)
85 {
86 	ASSERT(i >= 0 && i < fDeviceCount);
87 
88 	media_output	output;
89 	int32			count;
90 	status_t		err;
91 
92 	err = MediaRoster()->GetFreeOutputsFor(fDeviceInfo[i].node, &output, 1, &count, B_MEDIA_RAW_AUDIO);
93 	return (err == B_OK) && (count == 1);
94 }
95 
96 
97 bool
98 DeviceRoster::IsEncAudioOutputFree(int i)
99 {
100 	ASSERT(i >= 0 && i < fDeviceCount);
101 
102 	media_output	output;
103 	int32			count;
104 	status_t		err;
105 
106 	err = MediaRoster()->GetFreeOutputsFor(fDeviceInfo[i].node, &output, 1, &count, B_MEDIA_ENCODED_AUDIO);
107 	return (err == B_OK) && (count == 1);
108 }
109 
110 
111 bool
112 DeviceRoster::IsRawVideoOutputFree(int i)
113 {
114 	ASSERT(i >= 0 && i < fDeviceCount);
115 
116 	media_output	output;
117 	int32			count;
118 	status_t		err;
119 
120 	err = MediaRoster()->GetFreeOutputsFor(fDeviceInfo[i].node, &output, 1, &count, B_MEDIA_RAW_VIDEO);
121 	return (err == B_OK) && (count == 1);
122 }
123 
124 
125 bool
126 DeviceRoster::IsEncVideoOutputFree(int i)
127 {
128 	ASSERT(i >= 0 && i < fDeviceCount);
129 
130 	media_output	output;
131 	int32			count;
132 	status_t		err;
133 
134 	err = MediaRoster()->GetFreeOutputsFor(fDeviceInfo[i].node, &output, 1, &count, B_MEDIA_ENCODED_VIDEO);
135 	return (err == B_OK) && (count == 1);
136 }
137 
138 
139 BMediaRoster *
140 DeviceRoster::MediaRoster()
141 {
142 	return BMediaRoster::Roster();
143 }
144 
145