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