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*", 42 B_BUFFER_PRODUCER | B_PHYSICAL_INPUT); 43 if (err != B_OK || info_count < 1) { 44 printf("Can't find live DVB node. Found %" B_PRId32 " nodes, error %08" B_PRIx32 " (%s)\n", 45 info_count, err, strerror(err)); 46 fDeviceCount = 0; 47 } else { 48 fDeviceCount = info_count; 49 for (int i = 0; i < fDeviceCount; i++) { 50 fDeviceInfo[i].node = info[i].node; 51 strcpy(fDeviceInfo[i].name, info[i].name); 52 } 53 } 54 } 55 56 57 DeviceRoster::~DeviceRoster() 58 { 59 } 60 61 62 int 63 DeviceRoster::DeviceCount() 64 { 65 return fDeviceCount; 66 } 67 68 69 const char * 70 DeviceRoster::DeviceName(int i) 71 { 72 ASSERT(i >= 0 && i < fDeviceCount); 73 return fDeviceInfo[i].name; 74 } 75 76 77 media_node 78 DeviceRoster::DeviceNode(int i) 79 { 80 ASSERT(i >= 0 && i < fDeviceCount); 81 return fDeviceInfo[i].node; 82 } 83 84 85 bool 86 DeviceRoster::IsRawAudioOutputFree(int i) 87 { 88 ASSERT(i >= 0 && i < fDeviceCount); 89 90 media_output output; 91 int32 count; 92 status_t err; 93 94 err = MediaRoster()->GetFreeOutputsFor(fDeviceInfo[i].node, &output, 1, 95 &count, B_MEDIA_RAW_AUDIO); 96 return (err == B_OK) && (count == 1); 97 } 98 99 100 bool 101 DeviceRoster::IsEncAudioOutputFree(int i) 102 { 103 ASSERT(i >= 0 && i < fDeviceCount); 104 105 media_output output; 106 int32 count; 107 status_t err; 108 109 err = MediaRoster()->GetFreeOutputsFor(fDeviceInfo[i].node, &output, 1, 110 &count, B_MEDIA_ENCODED_AUDIO); 111 return (err == B_OK) && (count == 1); 112 } 113 114 115 bool 116 DeviceRoster::IsRawVideoOutputFree(int i) 117 { 118 ASSERT(i >= 0 && i < fDeviceCount); 119 120 media_output output; 121 int32 count; 122 status_t err; 123 124 err = MediaRoster()->GetFreeOutputsFor(fDeviceInfo[i].node, &output, 1, 125 &count, B_MEDIA_RAW_VIDEO); 126 return (err == B_OK) && (count == 1); 127 } 128 129 130 bool 131 DeviceRoster::IsEncVideoOutputFree(int i) 132 { 133 ASSERT(i >= 0 && i < fDeviceCount); 134 135 media_output output; 136 int32 count; 137 status_t err; 138 139 err = MediaRoster()->GetFreeOutputsFor(fDeviceInfo[i].node, &output, 1, 140 &count, B_MEDIA_ENCODED_VIDEO); 141 return (err == B_OK) && (count == 1); 142 } 143 144 145 BMediaRoster * 146 DeviceRoster::MediaRoster() 147 { 148 return BMediaRoster::Roster(); 149 } 150 151